Skip to content

Commit

Permalink
Merge pull request #145 from hotwired/target-blank
Browse files Browse the repository at this point in the history
Allow all target="_blank" links to propose visits
  • Loading branch information
jayohms authored Feb 8, 2021
2 parents ee96d4d + 95ee001 commit 6c910d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package dev.hotwire.turbo.views

import android.net.Uri
import android.os.Message
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebView
import dev.hotwire.turbo.session.TurboSession
import dev.hotwire.turbo.util.toJson
import dev.hotwire.turbo.visit.TurboVisitOptions

open class TurboWebChromeClient(val session: TurboSession) : WebChromeClient() {
override fun onShowFileChooser(
Expand All @@ -17,4 +20,18 @@ open class TurboWebChromeClient(val session: TurboSession) : WebChromeClient() {
params = fileChooserParams
)
}

override fun onCreateWindow(webView: WebView, isDialog: Boolean, isUserGesture: Boolean, resultMsg: Message?): Boolean {
val message = webView.handler.obtainMessage()
webView.requestFocusNodeHref(message)

message.data.getString("url")?.let {
session.visitProposedToLocation(
location = it,
optionsJson = TurboVisitOptions().toJson()
)
}

return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ open class TurboWebView @JvmOverloads constructor(context: Context, attrs: Attri
init {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
settings.setSupportMultipleWindows(true)
layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
}

Expand Down

0 comments on commit 6c910d7

Please sign in to comment.