blob: d654b01eb8063d4fc3978d12313b80eb9b8452c8 [file] [log] [blame]
Jinsuk Kime8e40672019-03-14 09:45:301// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Andrew Grieve4a42c22e2019-06-24 16:14:295#include "chrome/android/chrome_jni_headers/InterceptNavigationDelegateImpl_jni.h"
Jinsuk Kime8e40672019-03-14 09:45:306#include "components/navigation_interception/intercept_navigation_delegate.h"
7#include "components/navigation_interception/navigation_params.h"
8#include "content/public/browser/browser_thread.h"
9#include "content/public/browser/web_contents.h"
Jinsuk Kime8e40672019-03-14 09:45:3010#include "net/base/escape.h"
11
12namespace {
13
14using navigation_interception::InterceptNavigationDelegate;
15using navigation_interception::NavigationParams;
16
17class ChromeInterceptNavigationDelegate : public InterceptNavigationDelegate {
18 public:
19 ChromeInterceptNavigationDelegate(JNIEnv* env, jobject jdelegate)
20 : InterceptNavigationDelegate(env, jdelegate) {}
21
22 bool ShouldIgnoreNavigation(
23 const NavigationParams& navigation_params) override {
24 NavigationParams chrome_navigation_params(navigation_params);
25 chrome_navigation_params.url() =
26 GURL(net::EscapeExternalHandlerValue(navigation_params.url().spec()));
27 return InterceptNavigationDelegate::ShouldIgnoreNavigation(
28 chrome_navigation_params);
29 }
30};
31
32} // namespace
33
34static void JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents(
35 JNIEnv* env,
36 const base::android::JavaParamRef<jobject>& jdelegate,
37 const base::android::JavaParamRef<jobject>& jweb_contents) {
38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
39 content::WebContents* web_contents =
40 content::WebContents::FromJavaWebContents(jweb_contents);
41 InterceptNavigationDelegate::Associate(
42 web_contents,
43 std::make_unique<ChromeInterceptNavigationDelegate>(env, jdelegate));
44}