diff options
33 files changed, 266 insertions, 168 deletions
diff --git a/android_webview/Android.mk b/android_webview/Android.mk index 8c424ed..c24fab7 100644 --- a/android_webview/Android.mk +++ b/android_webview/Android.mk @@ -29,7 +29,8 @@ LOCAL_SRC_FILES += \ # browser components LOCAL_SRC_FILES += \ $(call all-java-files-under, ../chrome/browser/component/web_contents_delegate_android/java/src) \ - $(call all-java-files-under, ../chrome/browser/component/navigation_interception/java/src) \ + $(call all-java-files-under, \ + ../content/components/navigation_interception/java/src) \ # TODO(mkosiba): Remove chromium_chrome dep once required browser # components are in (replace it with contentview). diff --git a/android_webview/DEPS b/android_webview/DEPS index 2ae1b78..29747ce 100644 --- a/android_webview/DEPS +++ b/android_webview/DEPS @@ -1,14 +1,14 @@ # Please include joth@ and (joi@ or erikwright@) on the review for any changes # to DEPS files under android_webview/ -# With the exception of chrome/browser/component, do not add any includes under -# chrome/ anywhere in android_webview. +# Do not add any includes under chrome/ anywhere in android_webview. include_rules = [ # lib is the top-level target, and must remain a leaf in the dependency tree. "-android_webview/lib", - "+chrome/browser/component", + "!chrome/browser/component", + "+content/components", "+content/public/common", "+jni", "+net", diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index e0e66f0..99f1e05 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -29,8 +29,8 @@ 'type': 'static_library', 'dependencies': [ '../content/content.gyp:content', + '../content/content.gyp:navigation_interception', '../android_webview/native/webview_native.gyp:webview_native', - '../chrome/browser/component/components.gyp:navigation_interception', '../chrome/browser/component/components.gyp:web_contents_delegate_android', '../chrome/browser/component/components.gyp:browser_component_jni_headers', '../ui/ui.gyp:ui_resources', @@ -105,7 +105,7 @@ 'type': 'none', 'dependencies': [ '../content/content.gyp:content_java', - '../chrome/browser/component/components.gyp:navigation_interception_java', + '../content/content.gyp:navigation_interception_java', '../chrome/browser/component/components.gyp:web_contents_delegate_android_java', '../ui/ui.gyp:ui_java', ], @@ -120,11 +120,11 @@ 'type': 'none', 'dependencies': [ '../base/base.gyp:base_java', - '../chrome/browser/component/components.gyp:navigation_interception_java', '../chrome/browser/component/components.gyp:web_contents_delegate_android_java', '../chrome/chrome_resources.gyp:packed_extra_resources', '../chrome/chrome_resources.gyp:packed_resources', '../content/content.gyp:content_java', + '../content/content.gyp:navigation_interception_java', '../media/media.gyp:media_java', '../net/net.gyp:net_java', '../ui/ui.gyp:ui_java', diff --git a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc index 387c3b9..c04a00f 100644 --- a/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc +++ b/android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc @@ -9,7 +9,7 @@ #include "android_webview/common/url_constants.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" -#include "chrome/browser/component/navigation_interception/intercept_navigation_delegate.h" +#include "content/components/navigation_interception/intercept_navigation_delegate.h" #include "content/public/browser/resource_controller.h" #include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/resource_dispatcher_host_login_delegate.h" @@ -18,7 +18,7 @@ #include "net/base/load_flags.h" #include "net/url_request/url_request.h" -using navigation_interception::InterceptNavigationDelegate; +using content::InterceptNavigationDelegate; namespace { diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 800f160..3c018d5 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -20,11 +20,11 @@ import android.webkit.ValueCallback; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.base.ThreadUtils; -import org.chromium.chrome.browser.component.navigation_interception.InterceptNavigationDelegate; import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.LoadUrlParams; import org.chromium.content.browser.NavigationHistory; import org.chromium.content.common.CleanupReference; +import org.chromium.content.components.navigation_interception.InterceptNavigationDelegate; import org.chromium.net.X509Util; import org.chromium.ui.gfx.NativeWindow; diff --git a/android_webview/native/android_webview_jni_registrar.cc b/android_webview/native/android_webview_jni_registrar.cc index beb2fd8..5c29e22 100644 --- a/android_webview/native/android_webview_jni_registrar.cc +++ b/android_webview/native/android_webview_jni_registrar.cc @@ -15,14 +15,14 @@ #include "android_webview/native/js_result_handler.h" #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" -#include "chrome/browser/component/navigation_interception/component_jni_registrar.h" #include "chrome/browser/component/web_contents_delegate_android/component_jni_registrar.h" +#include "content/components/navigation_interception/component_jni_registrar.h" namespace android_webview { static base::android::RegistrationMethod kWebViewRegisteredMethods[] = { // Register JNI for components we depend on. - { "navigation_interception", navigation_interception::RegisterJni }, + { "navigation_interception", content::RegisterNavigationInterceptionJni }, { "web_contents_delegate_android", web_contents_delegate_android::RegisterJni }, // Register JNI for android_webview classes. diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 9da03b3..1419646 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -16,7 +16,7 @@ #include "base/bind.h" #include "base/callback.h" #include "base/supports_user_data.h" -#include "chrome/browser/component/navigation_interception/intercept_navigation_delegate.h" +#include "content/components/navigation_interception/intercept_navigation_delegate.h" #include "content/public/browser/android/content_view_core.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cert_store.h" @@ -36,8 +36,8 @@ using base::android::ScopedJavaGlobalRef; using base::android::ScopedJavaLocalRef; using content::BrowserThread; using content::ContentViewCore; +using content::InterceptNavigationDelegate; using content::WebContents; -using navigation_interception::InterceptNavigationDelegate; extern "C" { static AwGLDrawFunction GLDrawFunction; diff --git a/build/android/findbugs_filter/findbugs_known_bugs.txt b/build/android/findbugs_filter/findbugs_known_bugs.txt index 412f4cc..c352517 100644 --- a/build/android/findbugs_filter/findbugs_known_bugs.txt +++ b/build/android/findbugs_filter/findbugs_known_bugs.txt @@ -50,6 +50,7 @@ M B Nm: The class name org.chromium.android_webview.test.R$attr doesn't start wi M B Nm: The class name org.chromium.android_webview.test.R$drawable doesn't start with an upper case letter At R.java M B Nm: The class name org.chromium.android_webview.test.R$raw doesn't start with an upper case letter At R.java M B Nm: The class name org.chromium.android_webview.test.R$string doesn't start with an upper case letter At R.java +M B Nm: The class name org.chromium.chrome.browser.component.navigation_interception.InterceptNavigationDelegate shadows the simple name of implemented interface org.chromium.content.components.navigation_interception.InterceptNavigationDelegate In InterceptNavigationDelegate.java M B Nm: The class name org.chromium.chrome.testshell.Manifest$permission doesn't start with an upper case letter At Manifest.java M B Nm: The class name org.chromium.chrome.testshell.R$attr doesn't start with an upper case letter At R.java M B Nm: The class name org.chromium.chrome.testshell.R$dimen doesn't start with an upper case letter At R.java diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 943e63a..1d31852 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+chrome/installer", "+chrome/tools/profiles", # For history unit tests. "+chromeos", + "+content/components", "+content/public/browser", "+device", "+google/cacheinvalidation", # Sync invalidation API protobuf files. diff --git a/chrome/browser/android/chrome_jni_registrar.cc b/chrome/browser/android/chrome_jni_registrar.cc index b82c6cc..7466ce3 100644 --- a/chrome/browser/android/chrome_jni_registrar.cc +++ b/chrome/browser/android/chrome_jni_registrar.cc @@ -12,12 +12,12 @@ #include "chrome/browser/android/intent_helper.h" #include "chrome/browser/android/process_utils.h" #include "chrome/browser/android/provider/chrome_browser_provider.h" -#include "chrome/browser/component/navigation_interception/component_jni_registrar.h" #include "chrome/browser/component/web_contents_delegate_android/component_jni_registrar.h" #include "chrome/browser/history/android/sqlite_cursor.h" #include "chrome/browser/ui/android/autofill/autofill_external_delegate.h" #include "chrome/browser/ui/android/chrome_http_auth_handler.h" #include "chrome/browser/ui/android/javascript_app_modal_dialog_android.h" +#include "content/components/navigation_interception/component_jni_registrar.h" namespace chrome { namespace android { @@ -38,7 +38,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = { JavascriptAppModalDialogAndroid::RegisterJavascriptAppModalDialog }, { "ProcessUtils", RegisterProcessUtils }, { "SqliteCursor", SQLiteCursor::RegisterSqliteCursor }, - { "navigation_interception", navigation_interception::RegisterJni }, + { "navigation_interception", content::RegisterNavigationInterceptionJni }, }; bool RegisterJni(JNIEnv* env) { diff --git a/chrome/browser/component/components.gyp b/chrome/browser/component/components.gyp index 8fab5f9..bfa967a 100644 --- a/chrome/browser/component/components.gyp +++ b/chrome/browser/component/components.gyp @@ -15,9 +15,13 @@ { 'target_name': 'browser_component_jni_headers', 'type': 'none', + 'dependencies': [ + # TODO(jknotten) Remove this dependency once external deps have + # been updated to refer directly to the below. + '../../../content/content.gyp:navigation_interception_jni_headers' + ], 'sources': [ 'web_contents_delegate_android/java/src/org/chromium/chrome/browser/component/web_contents_delegate_android/WebContentsDelegateAndroid.java', - 'navigation_interception/java/src/org/chromium/chrome/browser/component/navigation_interception/InterceptNavigationDelegate.java', ], 'variables': { 'jni_gen_dir': 'chrome/browser_component', diff --git a/chrome/browser/component/navigation_interception/component_jni_registrar.h b/chrome/browser/component/navigation_interception/component_jni_registrar.h deleted file mode 100644 index adbe66a..0000000 --- a/chrome/browser/component/navigation_interception/component_jni_registrar.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_COMPONENT_JNI_REGISTRAR_H_ -#define CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_COMPONENT_JNI_REGISTRAR_H_ - -#include <jni.h> - -namespace navigation_interception { - -// Register all JNI bindings necessary for the navigation_interception -// component. -bool RegisterJni(JNIEnv* env); - -} // namespace navigation_interception - -#endif // CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_COMPONENT_JNI_REGISTRAR_H_ diff --git a/chrome/browser/component/navigation_interception/intercept_navigation_delegate.h b/chrome/browser/component/navigation_interception/intercept_navigation_delegate.h index cc1f0d3..bf382b3 100644 --- a/chrome/browser/component/navigation_interception/intercept_navigation_delegate.h +++ b/chrome/browser/component/navigation_interception/intercept_navigation_delegate.h @@ -5,61 +5,15 @@ #ifndef CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ #define CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ -#include "base/android/jni_helper.h" -#include "base/memory/scoped_ptr.h" -#include "base/supports_user_data.h" +#include "content/components/navigation_interception/intercept_navigation_delegate.h" -class GURL; - -namespace content { -class ResourceThrottle; -class WebContents; -} - -namespace net { -class URLRequest; -} +// TODO(jknotten): Remove this header once external dependencies are using the +// header at the above new location. namespace navigation_interception { -// Native side of the InterceptNavigationDelegate Java interface. -// This is used to create a InterceptNavigationResourceThrottle that calls the -// Java interface method to determine whether a navigation should be ignored or -// not. -// To us this class: -// 1) the Java-side interface implementation must be associated (via the -// Associate method) with a WebContents for which URLRequests are to be -// intercepted, -// 2) the ResourceThrottle obtained via CreateThrottleFor must be associated -// with the URLRequests in the ResourceDispatcherHostDelegate -// implementation. -class InterceptNavigationDelegate : public base::SupportsUserData::Data { - public: - InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate); - virtual ~InterceptNavigationDelegate(); - - // Associates the InterceptNavigationDelegate with a WebContents using the - // SupportsUserData mechanism. - // As implied by the use of scoped_ptr, the WebContents will assume ownership - // of |delegate|. - static void Associate(content::WebContents* web_contents, - scoped_ptr<InterceptNavigationDelegate> delegate); - // Gets the InterceptNavigationDelegate associated with the WebContents, - // can be null. - static InterceptNavigationDelegate* Get(content::WebContents* web_contents); - - // Creates a InterceptNavigationResourceThrottle that will direct all - // callbacks to the InterceptNavigationDelegate. - static content::ResourceThrottle* CreateThrottleFor( - net::URLRequest* request); - - virtual bool ShouldIgnoreNavigation(const GURL& url, - bool has_user_gesture); - private: - JavaObjectWeakGlobalRef weak_jdelegate_; -}; - -bool RegisterInterceptNavigationDelegate(JNIEnv* env); +using content::InterceptNavigationDelegate; +using content::RegisterInterceptNavigationDelegate; } // namespace navigation_interception diff --git a/chrome/browser/component/navigation_interception/java/src/org/chromium/chrome/browser/component/navigation_interception/InterceptNavigationDelegate.java b/chrome/browser/component/navigation_interception/java/src/org/chromium/chrome/browser/component/navigation_interception/InterceptNavigationDelegate.java index 91a28f3..617ca83 100644 --- a/chrome/browser/component/navigation_interception/java/src/org/chromium/chrome/browser/component/navigation_interception/InterceptNavigationDelegate.java +++ b/chrome/browser/component/navigation_interception/java/src/org/chromium/chrome/browser/component/navigation_interception/InterceptNavigationDelegate.java @@ -4,18 +4,9 @@ package org.chromium.chrome.browser.component.navigation_interception; -import org.chromium.base.CalledByNative; +// TODO(jknotten): Remove this file once external dependencies are using +// org.chromium.content.components.navigation_interception.InterceptNavigationDelegate -public interface InterceptNavigationDelegate { - /** - * This method is called for every top-level navigation within the associated WebContents. - * The method allows the embedder to ignore navigations. This is used on Android to 'convert' - * certain navigations to Intents to 3rd party applications. - * - * @param url the target url of the navigation. - * @param isUserGestrue true if the navigation was initiated by the user. - * @return true if the navigation should be ignored. - */ - @CalledByNative - boolean shouldIgnoreNavigation(String url, boolean isUserGestrue); -} +public interface InterceptNavigationDelegate extends + org.chromium.content.components.navigation_interception.InterceptNavigationDelegate { +}
\ No newline at end of file diff --git a/chrome/browser/component/navigation_interception/navigation_interception.gypi b/chrome/browser/component/navigation_interception/navigation_interception.gypi index af9de6e..fe22754 100644 --- a/chrome/browser/component/navigation_interception/navigation_interception.gypi +++ b/chrome/browser/component/navigation_interception/navigation_interception.gypi @@ -3,42 +3,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -{ - 'targets': [ - { - 'target_name': 'navigation_interception', - 'type': 'static_library', - 'dependencies': [ - '../../../base/base.gyp:base', - '../../../content/content.gyp:content_browser', - '../../../content/content.gyp:content_common', - '../../../net/net.gyp:net', - ], - 'include_dirs': [ - '../../../..', - '../../../../skia/config', - '<(SHARED_INTERMEDIATE_DIR)/chrome/browser_component', +# TODO(jknotten): Remove this file once external dependencies have changed to +# use the new location of this component at +# content/components/navigation_interception. - ], - 'sources': [ - 'intercept_navigation_resource_throttle.cc', - 'intercept_navigation_resource_throttle.h', - ], - 'conditions': [ - ['OS=="android"', { - 'dependencies': [ - 'browser_component_jni_headers', - ], - 'sources': [ - 'component_jni_registrar.cc', - 'component_jni_registrar.h', - 'intercept_navigation_delegate.cc', - 'intercept_navigation_delegate.h', - ], - }], - ], - }, - ], +{ 'conditions': [ ['OS=="android"', { 'targets': [ @@ -46,13 +15,8 @@ 'target_name': 'navigation_interception_java', 'type': 'none', 'dependencies': [ - '../../../base/base.gyp:base', + '../../../content/content.gyp:navigation_interception_java', ], - 'variables': { - 'package_name': 'navigation_interception', - 'java_in_dir': 'java', - }, - 'includes': [ '../../../../build/java.gypi' ], }, ], }], diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc index f6b5a8b..c0c8b70 100644 --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc @@ -46,7 +46,7 @@ #include "third_party/protobuf/src/google/protobuf/repeated_field.h" #if defined(OS_ANDROID) -#include "chrome/browser/component/navigation_interception/intercept_navigation_delegate.h" +#include "content/components/navigation_interception/intercept_navigation_delegate.h" #endif // TODO(oshima): Enable this for other platforms. @@ -144,7 +144,7 @@ void ChromeResourceDispatcherHostDelegate::RequestBeginning( #if defined(OS_ANDROID) if (!is_prerendering && resource_type == ResourceType::MAIN_FRAME) { throttles->push_back( - navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( + content::InterceptNavigationDelegate::CreateThrottleFor( request)); } #endif diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 801221f..16e4709 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1050,8 +1050,8 @@ 'type': 'none', 'dependencies': [ '../base/base.gyp:base', - '../chrome/browser/component/components.gyp:navigation_interception_java', '../chrome/browser/component/components.gyp:web_contents_delegate_android_java', + '../content/content.gyp:navigation_interception_java', '../content/content.gyp:content_java', '../ui/ui.gyp:ui_java', ], diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 263308d..fd68490 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2160,13 +2160,13 @@ ['OS != "ios"', { 'dependencies': [ 'autofill_regexes', - 'browser/component/components.gyp:navigation_interception', 'browser/performance_monitor/performance_monitor.gyp:performance_monitor', 'browser_extensions', 'common/extensions/api/api.gyp:api', 'debugger', 'installer_util', 'sync_file_system_proto', + '../content/content.gyp:navigation_interception', '../net/net.gyp:net_with_v8', '../ppapi/ppapi_internal.gyp:ppapi_ipc', # For PpapiMsg_LoadPlugin '../printing/printing.gyp:printing', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 17d0d16..ccfb8ff 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1284,7 +1284,6 @@ 'browser/chromeos/version_loader_unittest.cc', 'browser/chromeos/web_socket_proxy_helper_unittest.cc', 'browser/command_updater_unittest.cc', - 'browser/component/navigation_interception/intercept_navigation_resource_throttle_unittest.cc', 'browser/component_updater/component_updater_interceptor.cc', 'browser/component_updater/component_updater_interceptor.h', 'browser/component_updater/test/component_installers_unittest.cc', diff --git a/content/OWNERS b/content/OWNERS index 95b7e9c..e93e04d 100644 --- a/content/OWNERS +++ b/content/OWNERS @@ -4,5 +4,8 @@ creis@chromium.org darin@chromium.org jam@chromium.org piman@chromium.org +per-file content_components_navigation_interception.gypi=jknotten@chromium.org +per-file content_components_navigation_interception.gypi=joth@chromium.org +per-file content_components_navigation_interception.gypi=mkosiba@chromium.org per-file content_jni.gypi=bulach@chromium.org per-file content_jni.gypi=yfriedman@chromium.org diff --git a/content/components/navigation_interception/DEPS b/content/components/navigation_interception/DEPS new file mode 100644 index 0000000..8ff1d13 --- /dev/null +++ b/content/components/navigation_interception/DEPS @@ -0,0 +1,13 @@ +include_rules = [ + "+content/public", + "+net/url_request", + + # For generated JNI includes + "+jni", +] + +specific_include_rules = { + '.*_(a-z)+test\.cc': [ + "+testing", + ], +} diff --git a/content/components/navigation_interception/OWNERS b/content/components/navigation_interception/OWNERS new file mode 100644 index 0000000..d7b0401 --- /dev/null +++ b/content/components/navigation_interception/OWNERS @@ -0,0 +1,3 @@ +jknotten@chromium.org +joth@chromium.org +mkosiba@chromium.org diff --git a/chrome/browser/component/navigation_interception/component_jni_registrar.cc b/content/components/navigation_interception/component_jni_registrar.cc index 21dd29a..fe7fa56 100644 --- a/chrome/browser/component/navigation_interception/component_jni_registrar.cc +++ b/content/components/navigation_interception/component_jni_registrar.cc @@ -2,21 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/component/navigation_interception/component_jni_registrar.h" +#include "content/components/navigation_interception/component_jni_registrar.h" #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" -#include "chrome/browser/component/navigation_interception/intercept_navigation_delegate.h" +#include "content/components/navigation_interception/intercept_navigation_delegate.h" -namespace navigation_interception { +namespace content { static base::android::RegistrationMethod kComponentRegisteredMethods[] = { { "InterceptNavigationDelegate", RegisterInterceptNavigationDelegate }, }; -bool RegisterJni(JNIEnv* env) { +bool RegisterNavigationInterceptionJni(JNIEnv* env) { return RegisterNativeMethods(env, kComponentRegisteredMethods, arraysize(kComponentRegisteredMethods)); } -} // namespace navigation_interception +} // namespace content diff --git a/content/components/navigation_interception/component_jni_registrar.h b/content/components/navigation_interception/component_jni_registrar.h new file mode 100644 index 0000000..62ead61 --- /dev/null +++ b/content/components/navigation_interception/component_jni_registrar.h @@ -0,0 +1,18 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_COMPONENT_JNI_REGISTRAR_H_ +#define CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_COMPONENT_JNI_REGISTRAR_H_ + +#include <jni.h> + +namespace content { + +// Register all JNI bindings necessary for the navigation_interception +// component. +bool RegisterNavigationInterceptionJni(JNIEnv* env); + +} // namespace content + +#endif // CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_COMPONENT_JNI_REGISTRAR_H_ diff --git a/chrome/browser/component/navigation_interception/intercept_navigation_delegate.cc b/content/components/navigation_interception/intercept_navigation_delegate.cc index 3b934fa..6609a36 100644 --- a/chrome/browser/component/navigation_interception/intercept_navigation_delegate.cc +++ b/content/components/navigation_interception/intercept_navigation_delegate.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/component/navigation_interception/intercept_navigation_delegate.h" +#include "content/components/navigation_interception/intercept_navigation_delegate.h" #include "base/android/jni_android.h" #include "base/android/jni_string.h" #include "base/callback.h" -#include "chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.h" +#include "content/components/navigation_interception/intercept_navigation_resource_throttle.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" @@ -21,7 +21,7 @@ using content::BrowserThread; using content::RenderViewHost; using content::WebContents; -namespace navigation_interception { +namespace content { namespace { @@ -106,4 +106,4 @@ bool RegisterInterceptNavigationDelegate(JNIEnv* env) { return RegisterNativesImpl(env); } -} // namespace navigation_interception +} // namespace content diff --git a/content/components/navigation_interception/intercept_navigation_delegate.h b/content/components/navigation_interception/intercept_navigation_delegate.h new file mode 100644 index 0000000..94f6582 --- /dev/null +++ b/content/components/navigation_interception/intercept_navigation_delegate.h @@ -0,0 +1,66 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ +#define CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ + +#include "base/android/jni_helper.h" +#include "base/memory/scoped_ptr.h" +#include "base/supports_user_data.h" + +class GURL; + +namespace content { +class ResourceThrottle; +class WebContents; +} + +namespace net { +class URLRequest; +} + +namespace content { + +// Native side of the InterceptNavigationDelegate Java interface. +// This is used to create a InterceptNavigationResourceThrottle that calls the +// Java interface method to determine whether a navigation should be ignored or +// not. +// To us this class: +// 1) the Java-side interface implementation must be associated (via the +// Associate method) with a WebContents for which URLRequests are to be +// intercepted, +// 2) the ResourceThrottle obtained via CreateThrottleFor must be associated +// with the URLRequests in the ResourceDispatcherHostDelegate +// implementation. +class InterceptNavigationDelegate : public base::SupportsUserData::Data { + public: + InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate); + virtual ~InterceptNavigationDelegate(); + + // Associates the InterceptNavigationDelegate with a WebContents using the + // SupportsUserData mechanism. + // As implied by the use of scoped_ptr, the WebContents will assume ownership + // of |delegate|. + static void Associate(content::WebContents* web_contents, + scoped_ptr<InterceptNavigationDelegate> delegate); + // Gets the InterceptNavigationDelegate associated with the WebContents, + // can be null. + static InterceptNavigationDelegate* Get(content::WebContents* web_contents); + + // Creates a InterceptNavigationResourceThrottle that will direct all + // callbacks to the InterceptNavigationDelegate. + static content::ResourceThrottle* CreateThrottleFor( + net::URLRequest* request); + + virtual bool ShouldIgnoreNavigation(const GURL& url, + bool has_user_gesture); + private: + JavaObjectWeakGlobalRef weak_jdelegate_; +}; + +bool RegisterInterceptNavigationDelegate(JNIEnv* env); + +} // namespace content + +#endif // CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ diff --git a/chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.cc b/content/components/navigation_interception/intercept_navigation_resource_throttle.cc index 3310175..579d373 100644 --- a/chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.cc +++ b/content/components/navigation_interception/intercept_navigation_resource_throttle.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.h" +#include "content/components/navigation_interception/intercept_navigation_resource_throttle.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" @@ -19,7 +19,7 @@ using content::Referrer; using content::RenderViewHost; using content::ResourceRequestInfo; -namespace navigation_interception { +namespace content { namespace { @@ -119,4 +119,4 @@ void InterceptNavigationResourceThrottle::OnResultObtained( } } -} // namespace navigation_interception +} // namespace content diff --git a/chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.h b/content/components/navigation_interception/intercept_navigation_resource_throttle.h index b807663..742f696 100644 --- a/chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.h +++ b/content/components/navigation_interception/intercept_navigation_resource_throttle.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_RESOURCE_THROTTLE_H_ -#define CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_RESOURCE_THROTTLE_H_ +#ifndef CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_RESOURCE_THROTTLE_H_ +#define CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_RESOURCE_THROTTLE_H_ #include <string> @@ -22,7 +22,7 @@ namespace net { class URLRequest; } -namespace navigation_interception { +namespace content { // This class allows the provider of the Callback to selectively ignore top // level navigations. @@ -54,6 +54,6 @@ class InterceptNavigationResourceThrottle : public content::ResourceThrottle { DISALLOW_COPY_AND_ASSIGN(InterceptNavigationResourceThrottle); }; -} // namespace navigation_interception +} // namespace content -#endif // CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_RESOURCE_THROTTLE_H_ +#endif // CONTENT_COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_RESOURCE_THROTTLE_H_ diff --git a/chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle_unittest.cc b/content/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc index f26053a..ccbb3a6 100644 --- a/chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle_unittest.cc +++ b/content/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc @@ -7,8 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/component/navigation_interception/intercept_navigation_resource_throttle.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "content/components/navigation_interception/intercept_navigation_resource_throttle.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/resource_controller.h" @@ -20,12 +19,12 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/test/mock_resource_context.h" #include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_renderer_host.h" #include "net/url_request/url_request.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" using namespace content; -using namespace navigation_interception; using namespace ::testing; namespace { @@ -138,7 +137,7 @@ class TestIOThreadState { // InterceptNavigationResourceThrottleTest ------------------------------------ class InterceptNavigationResourceThrottleTest - : public ChromeRenderViewHostTestHarness { + : public RenderViewHostTestHarness { public: InterceptNavigationResourceThrottleTest() : mock_callback_receiver_(new MockInterceptCallbackReceiver()), @@ -148,7 +147,7 @@ class InterceptNavigationResourceThrottleTest } virtual void SetUp() OVERRIDE { - ChromeRenderViewHostTestHarness::SetUp(); + RenderViewHostTestHarness::SetUp(); io_thread_.StartIOThread(); } diff --git a/content/components/navigation_interception/java/src/org/chromium/content/components/navigation_interception/InterceptNavigationDelegate.java b/content/components/navigation_interception/java/src/org/chromium/content/components/navigation_interception/InterceptNavigationDelegate.java new file mode 100644 index 0000000..a14281f --- /dev/null +++ b/content/components/navigation_interception/java/src/org/chromium/content/components/navigation_interception/InterceptNavigationDelegate.java @@ -0,0 +1,21 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.content.components.navigation_interception; + +import org.chromium.base.CalledByNative; + +public interface InterceptNavigationDelegate { + /** + * This method is called for every top-level navigation within the associated WebContents. + * The method allows the embedder to ignore navigations. This is used on Android to 'convert' + * certain navigations to Intents to 3rd party applications. + * + * @param url the target url of the navigation. + * @param isUserGestrue true if the navigation was initiated by the user. + * @return true if the navigation should be ignored. + */ + @CalledByNative + boolean shouldIgnoreNavigation(String url, boolean isUserGestrue); +} diff --git a/content/content.gyp b/content/content.gyp index 046293d..9961de2 100644 --- a/content/content.gyp +++ b/content/content.gyp @@ -33,6 +33,7 @@ ['OS != "ios"', { 'includes': [ '../build/win_precompile.gypi', + 'content_components_navigation_interception.gypi', 'content_shell.gypi', ], }], diff --git a/content/content_components_navigation_interception.gypi b/content/content_components_navigation_interception.gypi new file mode 100644 index 0000000..54a1602 --- /dev/null +++ b/content/content_components_navigation_interception.gypi @@ -0,0 +1,75 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'targets': [ + { + 'target_name': 'navigation_interception', + 'type': 'static_library', + 'defines!': ['CONTENT_IMPLEMENTATION'], + 'dependencies': [ + '../base/base.gyp:base', + '../net/net.gyp:net', + 'content_browser', + 'content_common', + ], + 'include_dirs': [ + '..', + '../skia/config', + '<(SHARED_INTERMEDIATE_DIR)/navigation_interception', + + ], + 'sources': [ + 'components/navigation_interception/intercept_navigation_resource_throttle.cc', + 'components/navigation_interception/intercept_navigation_resource_throttle.h', + ], + 'conditions': [ + ['OS=="android"', { + 'dependencies': [ + 'navigation_interception_jni_headers', + ], + 'sources': [ + 'components/navigation_interception/component_jni_registrar.cc', + 'components/navigation_interception/component_jni_registrar.h', + 'components/navigation_interception/intercept_navigation_delegate.cc', + 'components/navigation_interception/intercept_navigation_delegate.h', + ], + }], + ], + }, + ], + 'conditions': [ + ['OS=="android"', { + 'targets': [ + { + 'target_name': 'navigation_interception_java', + 'type': 'none', + 'dependencies': [ + '../base/base.gyp:base', + ], + 'variables': { + 'package_name': 'navigation_interception', + 'java_in_dir': 'components/navigation_interception/java', + # TODO(jknotten): Remove once external dependencies have been + # updated to use the interface in its new package. + 'additional_src_dirs' : ['../chrome/browser/component/navigation_interception/java'] + }, + 'includes': [ '../build/java.gypi' ], + }, + { + 'target_name': 'navigation_interception_jni_headers', + 'type': 'none', + 'sources': [ + 'components/navigation_interception/java/src/org/chromium/content/components/navigation_interception/InterceptNavigationDelegate.java', + ], + 'variables': { + 'jni_gen_dir': 'navigation_interception', + }, + 'includes': [ '../build/jni_generator.gypi' ], + }, + ], + }], + ], +} diff --git a/content/content_tests.gypi b/content/content_tests.gypi index c87b945..03270e6 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -349,6 +349,7 @@ 'common/sandbox_mac_unittest_helper.h', 'common/sandbox_mac_unittest_helper.mm', 'common/sandbox_mac_system_access_unittest.mm', + 'components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc', 'gpu/gpu_info_collector_unittest.cc', 'gpu/gpu_info_collector_unittest_win.cc', 'renderer/active_notification_tracker_unittest.cc', @@ -487,6 +488,7 @@ 'content_plugin', 'content_renderer', 'content_resources.gyp:content_resources', + 'navigation_interception', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../gpu/gpu.gyp:gpu_unittest_utils', '../ipc/ipc.gyp:test_support_ipc', |