Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1297)

Unified Diff: content/browser/renderer_host/intercept_navigation_resource_throttle_impl.cc

Issue 10310124: Implement a ResourceThrottle for URL overriding in Chrome on Android. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed chromeos build issue + rebase Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/intercept_navigation_resource_throttle_impl.cc
diff --git a/content/browser/renderer_host/intercept_navigation_resource_throttle_impl.cc b/content/browser/renderer_host/intercept_navigation_resource_throttle_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ffdd96f9b5336f61db71ccbb0e6df212a90910d
--- /dev/null
+++ b/content/browser/renderer_host/intercept_navigation_resource_throttle_impl.cc
@@ -0,0 +1,138 @@
+// 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.
+
+#include "content/browser/renderer_host/intercept_navigation_resource_throttle_impl.h"
+
+#include "base/callback.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/child_process_security_policy.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/resource_request_info.h"
+#include "content/public/browser/resource_throttle_controller.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/common/referrer.h"
+#include "net/url_request/url_request.h"
+
+using content::BrowserThread;
+using content::ChildProcessSecurityPolicy;
+using content::InterceptNavigationResourceThrottle;
+using content::Referrer;
+using content::RenderViewHost;
+using content::ResourceRequestInfo;
+using content::WebContents;
+using content::WebContentsDelegate;
+
+namespace {
+
+void CheckShouldIgnoreNavigationOnUIThread(
+ int render_process_id,
+ int render_view_id,
+ const GURL& url,
+ const Referrer& referrer,
+ bool is_content_initiated,
+ base::Callback<void(bool)> callback) {
+
+ RenderViewHost* rvh =
+ RenderViewHost::FromID(render_process_id, render_view_id);
+ WebContents* web_contents =
+ rvh ? WebContents::FromRenderViewHost(rvh) : NULL;
+ WebContentsDelegate* web_contents_delegate =
+ web_contents ? web_contents->GetDelegate() : NULL;
+
+ GURL validated_url(url);
+ RenderViewHost::FilterURL(
+ rvh->GetProcess()->GetID(),
+ false,
+ &validated_url);
+
+ bool should_ignore_navigation = false;
+ if (web_contents_delegate) {
+ should_ignore_navigation = web_contents_delegate->ShouldIgnoreNavigation(
+ web_contents, validated_url, referrer, is_content_initiated);
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(callback, should_ignore_navigation));
+}
+
+} // namespace
+
+///////////////////////////////////////////////////////////////////////////////
+// InterceptNavigationResourceThrottle, public:
+
+// static
+InterceptNavigationResourceThrottle*
+InterceptNavigationResourceThrottle::Create(net::URLRequest* request) {
+ return new InterceptNavigationResourceThrottleImpl(request);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+InterceptNavigationResourceThrottleImpl::
+ InterceptNavigationResourceThrottleImpl(net::URLRequest* request)
+ : request_(request),
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+}
+
+InterceptNavigationResourceThrottleImpl::
+ ~InterceptNavigationResourceThrottleImpl() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+}
+
+void InterceptNavigationResourceThrottleImpl::WillStartRequest(bool* defer) {
+ *defer = ShouldDeferRequestForURL(request_->url());
+}
+
+void InterceptNavigationResourceThrottleImpl::WillRedirectRequest(
+ const GURL& new_url,
+ bool* defer) {
+ *defer = ShouldDeferRequestForURL(new_url);
+}
+
+bool InterceptNavigationResourceThrottleImpl::ShouldDeferRequestForURL(
+ const GURL& url) {
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
+ if (!info)
+ return false;
+
+ int render_process_id, render_view_id;
+ if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) {
+ return false;
+ }
+
+ // This class should only be instantiated for top level frame requests.
+ DCHECK(info->IsMainFrame());
+
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(
+ &CheckShouldIgnoreNavigationOnUIThread,
+ render_process_id,
+ render_view_id,
+ url,
+ Referrer(GURL(request_->referrer()), info->GetReferrerPolicy()),
+ info->HasUserGesture(),
+ base::Bind(
+ &InterceptNavigationResourceThrottleImpl::OnResultObtained,
+ weak_ptr_factory_.GetWeakPtr())));
+ return true;
joth 2012/06/13 22:32:49 maybe: // Defer request, while we wait for the UI
mkosiba (inactive) 2012/06/15 11:05:36 Done.
+}
+
+void InterceptNavigationResourceThrottleImpl::OnResultObtained(
+ bool should_ignore_navigation) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (should_ignore_navigation) {
+ // TODO: Cancel() results in a CANCELLED status but what we really want is
joth 2012/06/13 22:32:49 TODO(mkosiba)
mkosiba (inactive) 2012/06/15 11:05:36 Done.
+ // a HANDLED_EXTERNALLY status.
+ controller()->Cancel();
+ } else {
+ controller()->Resume();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698