Jinsuk Kim | e8e4067 | 2019-03-14 09:45:30 | [diff] [blame] | 1 | // 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 Grieve | 4a42c22e | 2019-06-24 16:14:29 | [diff] [blame] | 5 | #include "chrome/android/chrome_jni_headers/InterceptNavigationDelegateImpl_jni.h" |
Jinsuk Kim | e8e4067 | 2019-03-14 09:45:30 | [diff] [blame] | 6 | #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 Kim | e8e4067 | 2019-03-14 09:45:30 | [diff] [blame] | 10 | #include "net/base/escape.h" |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | using navigation_interception::InterceptNavigationDelegate; |
| 15 | using navigation_interception::NavigationParams; |
| 16 | |
| 17 | class 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 | |
| 34 | static 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 | } |