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

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

Issue 24228003: Upstream ShouldOverrideUrlLoading changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added a test Created 7 years 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
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 <string> 7 #include <string>
8 8
9 #include "android_webview/browser/aw_contents_io_thread_client.h" 9 #include "android_webview/browser/aw_contents_io_thread_client.h"
10 #include "android_webview/browser/aw_login_delegate.h" 10 #include "android_webview/browser/aw_login_delegate.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 IoThreadClientThrottle(int child_id, 60 IoThreadClientThrottle(int child_id,
61 int route_id, 61 int route_id,
62 net::URLRequest* request); 62 net::URLRequest* request);
63 virtual ~IoThreadClientThrottle(); 63 virtual ~IoThreadClientThrottle();
64 64
65 // From content::ResourceThrottle 65 // From content::ResourceThrottle
66 virtual void WillStartRequest(bool* defer) OVERRIDE; 66 virtual void WillStartRequest(bool* defer) OVERRIDE;
67 virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE; 67 virtual void WillRedirectRequest(const GURL& new_url, bool* defer) OVERRIDE;
68 virtual const char* GetNameForLogging() const OVERRIDE; 68 virtual const char* GetNameForLogging() const OVERRIDE;
69 69
70 bool MaybeDeferRequest(bool* defer);
71 void OnIoThreadClientReady(int new_child_id, int new_route_id); 70 void OnIoThreadClientReady(int new_child_id, int new_route_id);
72 bool MaybeBlockRequest(); 71 bool MaybeBlockRequest();
73 bool ShouldBlockRequest(); 72 bool ShouldBlockRequest();
74 int get_child_id() const { return child_id_; } 73 int get_child_id() const { return child_id_; }
75 int get_route_id() const { return route_id_; } 74 int get_route_id() const { return route_id_; }
76 75
77 private: 76 private:
78 int child_id_; 77 int child_id_;
79 int route_id_; 78 int route_id_;
80 net::URLRequest* request_; 79 net::URLRequest* request_;
81 }; 80 };
82 81
83 IoThreadClientThrottle::IoThreadClientThrottle(int child_id, 82 IoThreadClientThrottle::IoThreadClientThrottle(int child_id,
84 int route_id, 83 int route_id,
85 net::URLRequest* request) 84 net::URLRequest* request)
86 : child_id_(child_id), 85 : child_id_(child_id),
87 route_id_(route_id), 86 route_id_(route_id),
88 request_(request) { } 87 request_(request) { }
89 88
90 IoThreadClientThrottle::~IoThreadClientThrottle() { 89 IoThreadClientThrottle::~IoThreadClientThrottle() {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
92 g_webview_resource_dispatcher_host_delegate.Get(). 91 g_webview_resource_dispatcher_host_delegate.Get().
93 RemovePendingThrottleOnIoThread(this); 92 RemovePendingThrottleOnIoThread(this);
94 } 93 }
95 94
95 const char* IoThreadClientThrottle::GetNameForLogging() const {
96 return "IoThreadClientThrottle";
97 }
98
96 void IoThreadClientThrottle::WillStartRequest(bool* defer) { 99 void IoThreadClientThrottle::WillStartRequest(bool* defer) {
97 // TODO(sgurun): This block can be removed when crbug.com/277937 is fixed. 100 // TODO(sgurun): This block can be removed when crbug.com/277937 is fixed.
98 if (route_id_ < 1) { 101 if (route_id_ < 1) {
99 // OPTIONS is used for preflighted requests which are generated internally. 102 // OPTIONS is used for preflighted requests which are generated internally.
100 DCHECK_EQ("OPTIONS", request_->method()); 103 DCHECK_EQ("OPTIONS", request_->method());
101 return; 104 return;
102 } 105 }
103 DCHECK(child_id_); 106 DCHECK(child_id_);
104 if (!MaybeDeferRequest(defer)) {
105 MaybeBlockRequest();
106 }
107 }
108
109 void IoThreadClientThrottle::WillRedirectRequest(const GURL& new_url,
110 bool* defer) {
111 WillStartRequest(defer);
112 }
113
114 const char* IoThreadClientThrottle::GetNameForLogging() const {
115 return "IoThreadClientThrottle";
116 }
117
118 bool IoThreadClientThrottle::MaybeDeferRequest(bool* defer) {
119 *defer = false; 107 *defer = false;
120 108
121 // Defer all requests of a pop up that is still not associated with Java 109 // Defer all requests of a pop up that is still not associated with Java
122 // client so that the client will get a chance to override requests. 110 // client so that the client will get a chance to override requests.
123 scoped_ptr<AwContentsIoThreadClient> io_client = 111 scoped_ptr<AwContentsIoThreadClient> io_client =
124 AwContentsIoThreadClient::FromID(child_id_, route_id_); 112 AwContentsIoThreadClient::FromID(child_id_, route_id_);
125 if (io_client && io_client->PendingAssociation()) { 113 if (io_client && io_client->PendingAssociation()) {
126 *defer = true; 114 *defer = true;
127 AwResourceDispatcherHostDelegate::AddPendingThrottle( 115 AwResourceDispatcherHostDelegate::AddPendingThrottle(
128 child_id_, route_id_, this); 116 child_id_, route_id_, this);
117 } else {
118 MaybeBlockRequest();
129 } 119 }
130 return *defer; 120 }
121
122 void IoThreadClientThrottle::WillRedirectRequest(const GURL& new_url,
123 bool* defer) {
124 WillStartRequest(defer);
boliu 2013/12/06 20:28:23 This can skip the if (io_client && io_client->Pend
sgurun-gerrit only 2013/12/07 00:11:07 Sorry, not sure I understand.
boliu 2013/12/07 01:22:18 I meant if (io_client && io_client->PendingAssocia
131 } 125 }
132 126
133 void IoThreadClientThrottle::OnIoThreadClientReady(int new_child_id, 127 void IoThreadClientThrottle::OnIoThreadClientReady(int new_child_id,
134 int new_route_id) { 128 int new_route_id) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
136 130
137 if (!MaybeBlockRequest()) { 131 if (!MaybeBlockRequest()) {
138 controller()->Resume(); 132 controller()->Resume();
139 } 133 }
140 } 134 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 203 }
210 204
211 void AwResourceDispatcherHostDelegate::RequestBeginning( 205 void AwResourceDispatcherHostDelegate::RequestBeginning(
212 net::URLRequest* request, 206 net::URLRequest* request,
213 content::ResourceContext* resource_context, 207 content::ResourceContext* resource_context,
214 appcache::AppCacheService* appcache_service, 208 appcache::AppCacheService* appcache_service,
215 ResourceType::Type resource_type, 209 ResourceType::Type resource_type,
216 int child_id, 210 int child_id,
217 int route_id, 211 int route_id,
218 ScopedVector<content::ResourceThrottle>* throttles) { 212 ScopedVector<content::ResourceThrottle>* throttles) {
219 // If io_client is NULL, then the browser side objects have already been
220 // destroyed, so do not do anything to the request. Conversely if the
221 // request relates to a not-yet-created popup window, then the client will
222 // be non-NULL but PopupPendingAssociation() will be set.
223 scoped_ptr<AwContentsIoThreadClient> io_client =
224 AwContentsIoThreadClient::FromID(child_id, route_id);
225 if (!io_client)
226 return;
227 213
214 // We always push the throttles here. Checking the existence of io_client
215 // is racy when a popup window is created. That is because RequestBeginning
216 // is called whether or not requests are blocked via BlockRequestForRoute()
217 // however io_client may or may not be ready at the time depending on whether
218 // webcontents is created.
228 throttles->push_back(new IoThreadClientThrottle( 219 throttles->push_back(new IoThreadClientThrottle(
229 child_id, route_id, request)); 220 child_id, route_id, request));
boliu 2013/12/06 20:28:23 Trying to make sure requests of webviews that alre
sgurun-gerrit only 2013/12/07 00:11:07 Yes this logic is pretty delicate. The CTS that I
230 221
231 bool allow_intercepting = 222 // We allow intercepting only navigations within main frames. This
boliu 2013/12/06 20:28:23 How about this (assuming I understood the code cor
sgurun-gerrit only 2013/12/07 00:11:07 But it is not only used for onPageStarted anymore.
boliu 2013/12/07 01:22:18 How about We add InterceptNavigationDelegate thro
232 // We allow intercepting navigations within subframes, but only if the 223 // is used to post onPageStarted. We handle shouldOverrideUrlLoading
233 // scheme other than http or https. This is because the embedder 224 // via a sync IPC.
234 // can't distinguish main frame and subframe callbacks (which could lead 225 if (resource_type == ResourceType::MAIN_FRAME)
235 // to broken content if the embedder decides to not ignore the main frame
236 // navigation, but ignores the subframe navigation).
237 // The reason this is supported at all is that certain JavaScript-based
238 // frameworks use iframe navigation as a form of communication with the
239 // embedder.
240 (resource_type == ResourceType::MAIN_FRAME ||
241 (resource_type == ResourceType::SUB_FRAME &&
242 !request->url().SchemeIs(content::kHttpScheme) &&
243 !request->url().SchemeIs(content::kHttpsScheme)));
244 if (allow_intercepting) {
245 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( 226 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor(
246 request)); 227 request));
247 }
248 } 228 }
249 229
250 void AwResourceDispatcherHostDelegate::DownloadStarting( 230 void AwResourceDispatcherHostDelegate::DownloadStarting(
251 net::URLRequest* request, 231 net::URLRequest* request,
252 content::ResourceContext* resource_context, 232 content::ResourceContext* resource_context,
253 int child_id, 233 int child_id,
254 int route_id, 234 int route_id,
255 int request_id, 235 int request_id,
256 bool is_content_initiated, 236 bool is_content_initiated,
257 bool must_download, 237 bool must_download,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 ChildRouteIDPair(new_child_id, new_route_id)); 386 ChildRouteIDPair(new_child_id, new_route_id));
407 387
408 if (it != pending_throttles_.end()) { 388 if (it != pending_throttles_.end()) {
409 IoThreadClientThrottle* throttle = it->second; 389 IoThreadClientThrottle* throttle = it->second;
410 throttle->OnIoThreadClientReady(new_child_id, new_route_id); 390 throttle->OnIoThreadClientReady(new_child_id, new_route_id);
411 pending_throttles_.erase(it); 391 pending_throttles_.erase(it);
412 } 392 }
413 } 393 }
414 394
415 } // namespace android_webview 395 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698