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

Side by Side Diff: android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc

Issue 11348075: [Android WebView] AwContentsClient.shouldCreate window callback part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" 5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h"
6 6
7 #include "android_webview/browser/aw_login_delegate.h" 7 #include "android_webview/browser/aw_login_delegate.h"
8 #include "android_webview/browser/aw_contents_io_thread_client.h" 8 #include "android_webview/browser/aw_contents_io_thread_client.h"
9 #include "android_webview/common/url_constants.h" 9 #include "android_webview/common/url_constants.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "content/components/navigation_interception/intercept_navigation_delega te.h" 12 #include "content/components/navigation_interception/intercept_navigation_delega te.h"
13 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/resource_controller.h" 14 #include "content/public/browser/resource_controller.h"
14 #include "content/public/browser/resource_dispatcher_host.h" 15 #include "content/public/browser/resource_dispatcher_host.h"
15 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 16 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
16 #include "content/public/browser/resource_throttle.h" 17 #include "content/public/browser/resource_throttle.h"
17 #include "content/public/common/url_constants.h" 18 #include "content/public/common/url_constants.h"
18 #include "net/base/load_flags.h" 19 #include "net/base/load_flags.h"
19 #include "net/url_request/url_request.h" 20 #include "net/url_request/url_request.h"
20 21
21 using content::InterceptNavigationDelegate; 22 using content::InterceptNavigationDelegate;
22 23
23 namespace { 24 namespace {
24 25
25 using android_webview::AwContentsIoThreadClient; 26 using android_webview::AwContentsIoThreadClient;
27 using content::BrowserThread;
26 28
27 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> 29 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate>
28 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; 30 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER;
29 31
30 void SetOnlyAllowLoadFromCache( 32 void SetOnlyAllowLoadFromCache(
31 net::URLRequest* request) { 33 net::URLRequest* request) {
32 int load_flags = request->load_flags(); 34 int load_flags = request->load_flags();
33 load_flags &= ~(net::LOAD_BYPASS_CACHE & 35 load_flags &= ~(net::LOAD_BYPASS_CACHE &
34 net::LOAD_VALIDATE_CACHE & 36 net::LOAD_VALIDATE_CACHE &
35 net::LOAD_PREFERRING_CACHE); 37 net::LOAD_PREFERRING_CACHE);
(...skipping 16 matching lines...) Expand all
52 return AwContentsIoThreadClient::FromID(child_id_, route_id_); 54 return AwContentsIoThreadClient::FromID(child_id_, route_id_);
53 } 55 }
54 56
55 private: 57 private:
56 int child_id_; 58 int child_id_;
57 int route_id_; 59 int route_id_;
58 net::URLRequest* request_; 60 net::URLRequest* request_;
59 }; 61 };
60 62
61 void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) { 63 void MaybeCancelResourceThrottle::WillStartRequest(bool* defer) {
62 // If there is no IO thread client set at this point, use a 64 DCHECK(GetIoThreadClient());
63 // restrictive policy. This can happen for blocked popup
64 // windows for example.
65 // TODO(benm): Revert this to a DCHECK when the we support
66 // pop up windows being created in the WebView, as at that
67 // time we should always have an IoThreadClient at this
68 // point (i.e., the one associated with the new popup).
69 if (!GetIoThreadClient()) {
70 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
71 return;
72 }
73 65
74 // Part of implementation of WebSettings.allowContentAccess. 66 // Part of implementation of WebSettings.allowContentAccess.
75 if (request_->url().SchemeIs(android_webview::kContentScheme) && 67 if (request_->url().SchemeIs(android_webview::kContentScheme) &&
76 GetIoThreadClient()->ShouldBlockContentUrls()) { 68 GetIoThreadClient()->ShouldBlockContentUrls()) {
77 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 69 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
78 return; 70 return;
79 } 71 }
80 72
81 // Part of implementation of WebSettings.allowFileAccess. 73 // Part of implementation of WebSettings.allowFileAccess.
82 if (request_->url().SchemeIsFile() && 74 if (request_->url().SchemeIsFile() &&
(...skipping 10 matching lines...) Expand all
93 85
94 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) { 86 if (GetIoThreadClient()->ShouldBlockNetworkLoads()) {
95 if (request_->url().SchemeIs(chrome::kFtpScheme)) { 87 if (request_->url().SchemeIs(chrome::kFtpScheme)) {
96 controller()->CancelWithError(net::ERR_ACCESS_DENIED); 88 controller()->CancelWithError(net::ERR_ACCESS_DENIED);
97 return; 89 return;
98 } 90 }
99 SetOnlyAllowLoadFromCache(request_); 91 SetOnlyAllowLoadFromCache(request_);
100 } 92 }
101 } 93 }
102 94
95 class DeferUntilIoThreadClientReadyThrottle
96 : public content::ResourceThrottle,
97 public AwContentsIoThreadClient::ReadyObserver {
98 public:
99 DeferUntilIoThreadClientReadyThrottle(int child_id, int route_id)
100 : child_id_(child_id),
101 route_id_(route_id),
102 resumed_(false) {
103 }
104
105 virtual ~DeferUntilIoThreadClientReadyThrottle() {
106 AwContentsIoThreadClient::RemoveReadyObserver(this);
107 }
108
109 virtual void WillStartRequest(bool* defer) OVERRIDE {
110 MaybeDeferRequest(defer);
111 }
112
113 virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE {
114 MaybeDeferRequest(defer);
115 }
116
117 void MaybeDeferRequest(bool* defer) {
118 if (!AwContentsIoThreadClient::FromID(child_id_, route_id_)) {
119 *defer = true;
120 AwContentsIoThreadClient::AddReadyObserver(this);
121 } else {
122 *defer = false;
123 }
124 }
125
126 void OnIoThreadClientReady(int new_child_id, int new_route_id) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
128 // If we've now got the IoThreadClient that we were waiting on,
129 // resume the request.
130 if (!resumed_ && new_child_id == child_id_ && new_route_id == route_id_) {
mkosiba (inactive) 2012/11/16 12:28:32 it seems like this is a good place to run all of t
benm (inactive) 2012/11/16 12:36:31 IoThreadClientThrottle maybe? With a class commen
131 controller()->Resume();
132 resumed_ = true;
133 }
134 }
135
136 private:
137 int child_id_;
138 int route_id_;
139 bool resumed_;
140 };
141
103 } // namespace 142 } // namespace
104 143
105 namespace android_webview { 144 namespace android_webview {
106 145
107 // static 146 // static
108 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() { 147 void AwResourceDispatcherHostDelegate::ResourceDispatcherHostCreated() {
109 content::ResourceDispatcherHost::Get()->SetDelegate( 148 content::ResourceDispatcherHost::Get()->SetDelegate(
110 &g_webview_resource_dispatcher_host_delegate.Get()); 149 &g_webview_resource_dispatcher_host_delegate.Get());
111 } 150 }
112 151
113 AwResourceDispatcherHostDelegate::AwResourceDispatcherHostDelegate() 152 AwResourceDispatcherHostDelegate::AwResourceDispatcherHostDelegate()
114 : content::ResourceDispatcherHostDelegate() { 153 : content::ResourceDispatcherHostDelegate() {
115 } 154 }
116 155
117 AwResourceDispatcherHostDelegate::~AwResourceDispatcherHostDelegate() { 156 AwResourceDispatcherHostDelegate::~AwResourceDispatcherHostDelegate() {
118 } 157 }
119 158
120 void AwResourceDispatcherHostDelegate::RequestBeginning( 159 void AwResourceDispatcherHostDelegate::RequestBeginning(
121 net::URLRequest* request, 160 net::URLRequest* request,
122 content::ResourceContext* resource_context, 161 content::ResourceContext* resource_context,
123 appcache::AppCacheService* appcache_service, 162 appcache::AppCacheService* appcache_service,
124 ResourceType::Type resource_type, 163 ResourceType::Type resource_type,
125 int child_id, 164 int child_id,
126 int route_id, 165 int route_id,
127 bool is_continuation_of_transferred_request, 166 bool is_continuation_of_transferred_request,
128 ScopedVector<content::ResourceThrottle>* throttles) { 167 ScopedVector<content::ResourceThrottle>* throttles) {
129 168
169 // If there's no IoClient yet, then we need to defer until there is one.
170 if (!AwContentsIoThreadClient::FromID(child_id, route_id)) {
171 throttles->push_back(new DeferUntilIoThreadClientReadyThrottle(
172 child_id, route_id));
173 }
174
130 throttles->push_back(new MaybeCancelResourceThrottle( 175 throttles->push_back(new MaybeCancelResourceThrottle(
131 child_id, route_id, request)); 176 child_id, route_id, request));
132 177
133 if (resource_type == ResourceType::MAIN_FRAME) { 178 if (resource_type == ResourceType::MAIN_FRAME) {
134 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( 179 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor(
135 request)); 180 request));
136 } 181 }
137 } 182 }
138 183
139 bool AwResourceDispatcherHostDelegate::AcceptAuthRequest( 184 bool AwResourceDispatcherHostDelegate::AcceptAuthRequest(
(...skipping 12 matching lines...) Expand all
152 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url, 197 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(const GURL& url,
153 int child_id, 198 int child_id,
154 int route_id) { 199 int route_id) {
155 // The AwURLRequestJobFactory implementation should ensure this method never 200 // The AwURLRequestJobFactory implementation should ensure this method never
156 // gets called. 201 // gets called.
157 NOTREACHED(); 202 NOTREACHED();
158 return false; 203 return false;
159 } 204 }
160 205
161 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698