GeckoView 中有 shouldOverrideUrlLoading 吗?

我对在 Android WebView 中使用 shouldOverrideUrlLoading 方法非常熟悉,并且在一些项目中使用过它。我有一个需要 Mozilla 的 GeckoView 而不是标准 WebView 的新项目,但我似乎找不到覆盖 url 的方法(以防止用户从最初加载的网站中跟踪某些链接)。有没有这样的方法存在?


我已经使用以下说明将 GeckoView 嵌入到我的项目中:https ://wiki.mozilla.org/Mobile/GeckoView并且网站渲染得很好。


我试图模拟的 Android WebView 代码如下所示:


browser.setWebViewClient(new WebViewClient() {

  public boolean shouldOverrideUrlLoading(WebView view, String url) {

    Uri uri = Uri.parse(url);

    if (url.startsWith("https://www.example.com/")) {

      return false;

    }

    return true;

  }

});

GeckoView 中是否有类似的方法?


呼啦一阵风
浏览 153回答 1
1回答

qq_笑_17

我认为您正在寻找的是在navigationDelegate#OnLoadRequestprivate fun createNavigationDelegate() = object : GeckoSession.NavigationDelegate {&nbsp; &nbsp; override fun onLoadRequest(session: GeckoSession, request: GeckoSession.NavigationDelegate.LoadRequest): GeckoResult<AllowOrDeny> {&nbsp; &nbsp; &nbsp; &nbsp; return if (request.uri.startsWith("https://www.example.com/")) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GeckoResult.fromValue(AllowOrDeny.DENY)&nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GeckoResult.fromValue(AllowOrDeny.ALLOW)&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}private fun setupGeckoView() {&nbsp; &nbsp; geckoView = findViewById(R.id.geckoview)&nbsp; &nbsp; val runtime = GeckoRuntime.create(this)&nbsp; &nbsp; geckoSession.open(runtime)&nbsp; &nbsp; geckoView.setSession(geckoSession)&nbsp; &nbsp; geckoSession.loadUri(INITIAL_URL)&nbsp; &nbsp; geckoSession.navigationDelegate = createNavigationDelegate()}如果您有任何其他问题,您也可以在他们的GitHub 存储库上打开一个问题。您可能感兴趣的另一个项目是Mozilla Android Components。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java