diff options
author | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 21:16:45 +0000 |
---|---|---|
committer | jknotten@chromium.org <jknotten@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 21:16:45 +0000 |
commit | 645ecce69cbc86dd40d9ce2091b5d2cb5c809718 (patch) | |
tree | 120e932a240c3e0a6f08ef33672cbf497f666ae7 | |
parent | ec93074f1f9b171b999df87c56a2882e5054bb4a (diff) | |
download | chromium_src-645ecce69cbc86dd40d9ce2091b5d2cb5c809718.zip chromium_src-645ecce69cbc86dd40d9ce2091b5d2cb5c809718.tar.gz chromium_src-645ecce69cbc86dd40d9ce2091b5d2cb5c809718.tar.bz2 |
Make page transition type to InterceptNavigationResourceThrottlethrottle
The intercept navigation resource throttle needs to be able to
inspect the page transition type associated with a request, as
different behaviour may be desired depending on it. For example,
in Chrome on Android, we do not want to intercept requests
resulting from backwards / forwards history navigation.
BUG=164194
Review URL: https://chromiumcodereview.appspot.com/11415252
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171312 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 55 insertions, 31 deletions
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 19f3f52..48758aa 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -221,7 +221,8 @@ public class AwContents { } @Override - public boolean shouldIgnoreNavigation(String url, boolean isPost, boolean hasUserGestrue) { + public boolean shouldIgnoreNavigation(String url, boolean isPost, boolean hasUserGesture, + int pageTransition) { boolean ignoreNavigation = false; if (mLastLoadUrlAddress != null && mLastLoadUrlAddress.equals(url)) { // Support the case where the user clicks on a link that takes them back to the diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc index 1092d23..8d19c7f 100644 --- a/content/browser/download/download_resource_handler.cc +++ b/content/browser/download/download_resource_handler.cc @@ -138,7 +138,7 @@ bool DownloadResourceHandler::OnResponseStarted( scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo( base::Time::Now(), content_length_, request_->net_log(), request_info->HasUserGesture(), - request_info->transition_type())); + request_info->GetPageTransition())); // Create the ByteStream for sending data to the download sink. scoped_ptr<ByteStreamReader> stream_reader; diff --git a/content/browser/loader/resource_request_info_impl.cc b/content/browser/loader/resource_request_info_impl.cc index 3a614e9..3c5fc49 100644 --- a/content/browser/loader/resource_request_info_impl.cc +++ b/content/browser/loader/resource_request_info_impl.cc @@ -164,6 +164,10 @@ WebKit::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const { return referrer_policy_; } +PageTransition ResourceRequestInfoImpl::GetPageTransition() const { + return transition_type_; +} + bool ResourceRequestInfoImpl::HasUserGesture() const { return has_user_gesture_; } diff --git a/content/browser/loader/resource_request_info_impl.h b/content/browser/loader/resource_request_info_impl.h index e35005a..b8e505f 100644 --- a/content/browser/loader/resource_request_info_impl.h +++ b/content/browser/loader/resource_request_info_impl.h @@ -12,7 +12,6 @@ #include "base/memory/scoped_ptr.h" #include "base/supports_user_data.h" #include "content/public/browser/resource_request_info.h" -#include "content/public/common/page_transition_types.h" #include "content/public/common/process_type.h" #include "content/public/common/referrer.h" #include "net/base/load_states.h" @@ -72,6 +71,7 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, virtual int64 GetParentFrameID() const OVERRIDE; virtual ResourceType::Type GetResourceType() const OVERRIDE; virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const OVERRIDE; + virtual PageTransition GetPageTransition() const OVERRIDE; virtual bool HasUserGesture() const OVERRIDE; virtual bool WasIgnoredByHandler() const OVERRIDE; virtual bool GetAssociatedRenderView(int* render_process_id, @@ -111,8 +111,6 @@ class ResourceRequestInfoImpl : public ResourceRequestInfo, bool is_download() const { return is_download_; } void set_is_download(bool download) { is_download_ = download; } - PageTransition transition_type() const { return transition_type_; } - void set_was_ignored_by_handler(bool value) { was_ignored_by_handler_ = value; } diff --git a/content/components/navigation_interception/intercept_navigation_delegate.cc b/content/components/navigation_interception/intercept_navigation_delegate.cc index 0eb25f78..17f7324 100644 --- a/content/components/navigation_interception/intercept_navigation_delegate.cc +++ b/content/components/navigation_interception/intercept_navigation_delegate.cc @@ -32,7 +32,8 @@ bool CheckIfShouldIgnoreNavigationOnUIThread(RenderViewHost* source, const GURL& url, const content::Referrer& referrer, bool is_post, - bool has_user_gesture) { + bool has_user_gesture, + PageTransition transition_type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(source); @@ -45,7 +46,7 @@ bool CheckIfShouldIgnoreNavigationOnUIThread(RenderViewHost* source, return false; return intercept_navigation_delegate->ShouldIgnoreNavigation( - url, is_post, has_user_gesture); + url, is_post, has_user_gesture, transition_type); } } // namespace @@ -83,7 +84,8 @@ InterceptNavigationDelegate::~InterceptNavigationDelegate() { bool InterceptNavigationDelegate::ShouldIgnoreNavigation( const GURL& url, bool is_post, - bool has_user_gesture) { + bool has_user_gesture, + PageTransition transition_type) { if (!url.is_valid()) return false; @@ -100,7 +102,8 @@ bool InterceptNavigationDelegate::ShouldIgnoreNavigation( jdelegate.obj(), jstring_url.obj(), is_post, - has_user_gesture); + has_user_gesture, + transition_type); } // Register native methods. diff --git a/content/components/navigation_interception/intercept_navigation_delegate.h b/content/components/navigation_interception/intercept_navigation_delegate.h index a80efa3..ab60a68 100644 --- a/content/components/navigation_interception/intercept_navigation_delegate.h +++ b/content/components/navigation_interception/intercept_navigation_delegate.h @@ -8,6 +8,7 @@ #include "base/android/jni_helper.h" #include "base/memory/scoped_ptr.h" #include "base/supports_user_data.h" +#include "content/public/common/page_transition_types.h" class GURL; @@ -55,7 +56,8 @@ class InterceptNavigationDelegate : public base::SupportsUserData::Data { virtual bool ShouldIgnoreNavigation(const GURL& url, bool is_post, - bool has_user_gesture); + bool has_user_gesture, + PageTransition transition_type); private: JavaObjectWeakGlobalRef weak_jdelegate_; }; diff --git a/content/components/navigation_interception/intercept_navigation_resource_throttle.cc b/content/components/navigation_interception/intercept_navigation_resource_throttle.cc index 68a67e2c..daf93a6 100644 --- a/content/components/navigation_interception/intercept_navigation_resource_throttle.cc +++ b/content/components/navigation_interception/intercept_navigation_resource_throttle.cc @@ -10,6 +10,7 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/resource_request_info.h" #include "content/public/browser/resource_controller.h" +#include "content/public/common/page_transition_types.h" #include "content/public/common/referrer.h" #include "net/url_request/url_request.h" @@ -24,12 +25,13 @@ namespace content { namespace { struct ShouldIgnoreCallbackParams { - int render_process_id; - int render_view_id; - GURL url; - Referrer referrer; - bool has_user_gesture; - bool is_post; + int render_process_id; + int render_view_id; + GURL url; + Referrer referrer; + bool has_user_gesture; + bool is_post; + PageTransition transition_type; }; void CheckIfShouldIgnoreNavigationOnUIThread( @@ -51,7 +53,8 @@ void CheckIfShouldIgnoreNavigationOnUIThread( validated_url, params.referrer, params.is_post, - params.has_user_gesture); + params.has_user_gesture, + params.transition_type); } BrowserThread::PostTask( @@ -102,6 +105,7 @@ bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation( info->GetReferrerPolicy()); params.has_user_gesture = info->HasUserGesture(); params.is_post = request_->method() == "POST"; + params.transition_type = info->GetPageTransition(); BrowserThread::PostTask( BrowserThread::UI, diff --git a/content/components/navigation_interception/intercept_navigation_resource_throttle.h b/content/components/navigation_interception/intercept_navigation_resource_throttle.h index 90d7883..cbff601 100644 --- a/content/components/navigation_interception/intercept_navigation_resource_throttle.h +++ b/content/components/navigation_interception/intercept_navigation_resource_throttle.h @@ -10,6 +10,7 @@ #include "base/callback.h" #include "base/memory/weak_ptr.h" #include "content/public/browser/resource_throttle.h" +#include "content/public/common/page_transition_types.h" class GURL; @@ -29,10 +30,11 @@ namespace content { class InterceptNavigationResourceThrottle : public content::ResourceThrottle { public: typedef base::Callback<bool(content::RenderViewHost* /* source */, - const GURL& /*url*/, + const GURL& /* url */, const content::Referrer& /*referrer*/, - bool /*is_post*/, - bool /*has_user_gesture*/)> + bool /* is_post */, + bool /* has_user_gesture */, + PageTransition /* page transition type */)> CheckOnUIThreadCallback; InterceptNavigationResourceThrottle( diff --git a/content/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc b/content/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc index d7cf936..a7a11b9 100644 --- a/content/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc +++ b/content/components/navigation_interception/intercept_navigation_resource_throttle_unittest.cc @@ -17,6 +17,7 @@ #include "content/public/browser/resource_throttle.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_delegate.h" +#include "content/public/common/page_transition_types.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" @@ -45,11 +46,12 @@ void ContinueTestCase() { class MockInterceptCallbackReceiver { public: - MOCK_METHOD5(ShouldIgnoreNavigation, bool(RenderViewHost* source, + MOCK_METHOD6(ShouldIgnoreNavigation, bool(RenderViewHost* source, const GURL& url, const content::Referrer& referrer, bool is_post, - bool has_user_gesture)); + bool has_user_gesture, + PageTransition page_transition)); }; // MockResourceController ----------------------------------------------------- @@ -201,10 +203,10 @@ class InterceptNavigationResourceThrottleTest bool* defer) { ON_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(_, _, _, _, _)) + ShouldIgnoreNavigation(_, _, _, _, _, _)) .WillByDefault(Return(callback_action == IgnoreNavigation)); EXPECT_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(rvh(), Eq(GURL(kTestUrl)), _, _, _)) + ShouldIgnoreNavigation(rvh(), Eq(GURL(kTestUrl)), _, _, _, _)) .Times(1); BrowserThread::PostTask( @@ -276,7 +278,7 @@ TEST_F(InterceptNavigationResourceThrottleTest, base::Unretained(this))); EXPECT_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(_, _, _, _, _)) + ShouldIgnoreNavigation(_, _, _, _, _, _)) .Times(0); BrowserThread::PostTask( @@ -331,10 +333,10 @@ TEST_F(InterceptNavigationResourceThrottleTest, bool defer = false; ON_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _)) + ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _, _)) .WillByDefault(Return(false)); EXPECT_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _)) + ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, _, _, _)) .Times(1); BrowserThread::PostTask( @@ -359,7 +361,8 @@ TEST_F(InterceptNavigationResourceThrottleTest, bool defer = false; EXPECT_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, false, _)) + ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, false, _, + _)) .WillOnce(Return(false)); BrowserThread::PostTask( @@ -384,7 +387,8 @@ TEST_F(InterceptNavigationResourceThrottleTest, bool defer = false; EXPECT_CALL(*mock_callback_receiver_, - ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, true, _)) + ShouldIgnoreNavigation(_, Ne(GURL(kUnsafeTestUrl)), _, true, _, + _)) .WillOnce(Return(false)); BrowserThread::PostTask( 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 index c95e72c..973ee27 100644 --- 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 @@ -14,9 +14,11 @@ public interface InterceptNavigationDelegate { * * @param url the target url of the navigation. * @param isPost true if the the navigation method is "POST". - * @param isUserGestrue true if the navigation was initiated by the user. + * @param isUserGesture true if the navigation was initiated by the user. + * @param pageTransition is the page transition type (e.g. link / typed). * @return true if the navigation should be ignored. */ @CalledByNative - boolean shouldIgnoreNavigation(String url, boolean isPost, boolean isUserGestrue); + boolean shouldIgnoreNavigation(String url, boolean isPost, boolean isUserGesture, + int pageTransition); } diff --git a/content/public/browser/resource_request_info.h b/content/public/browser/resource_request_info.h index 3f50c03..cc41e95 100644 --- a/content/public/browser/resource_request_info.h +++ b/content/public/browser/resource_request_info.h @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "content/common/content_export.h" +#include "content/public/common/page_transition_types.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h" #include "webkit/glue/resource_type.h" @@ -80,6 +81,9 @@ class ResourceRequestInfo { // Returns the associated referrer policy. virtual WebKit::WebReferrerPolicy GetReferrerPolicy() const = 0; + // Returns the associated page transition type. + virtual PageTransition GetPageTransition() const = 0; + // True if the request was initiated by a user action (like a tap to follow // a link). virtual bool HasUserGesture() const = 0; |