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

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: changed a non-related line to keep chrome bots happy 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) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
97 // TODO(sgurun): This block can be removed when crbug.com/277937 is fixed. 101 // TODO(sgurun): This block can be removed when crbug.com/277937 is fixed.
98 if (route_id_ < 1) { 102 if (route_id_ < 1) {
99 // OPTIONS is used for preflighted requests which are generated internally. 103 // OPTIONS is used for preflighted requests which are generated internally.
100 DCHECK_EQ("OPTIONS", request_->method()); 104 DCHECK_EQ("OPTIONS", request_->method());
101 return; 105 return;
102 } 106 }
103 DCHECK(child_id_); 107 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; 108 *defer = false;
120 109
121 // Defer all requests of a pop up that is still not associated with Java 110 // 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. 111 // client so that the client will get a chance to override requests.
123 scoped_ptr<AwContentsIoThreadClient> io_client = 112 scoped_ptr<AwContentsIoThreadClient> io_client =
124 AwContentsIoThreadClient::FromID(child_id_, route_id_); 113 AwContentsIoThreadClient::FromID(child_id_, route_id_);
125 if (io_client && io_client->PendingAssociation()) { 114 if (io_client && io_client->PendingAssociation()) {
126 *defer = true; 115 *defer = true;
127 AwResourceDispatcherHostDelegate::AddPendingThrottle( 116 AwResourceDispatcherHostDelegate::AddPendingThrottle(
128 child_id_, route_id_, this); 117 child_id_, route_id_, this);
118 } else {
119 MaybeBlockRequest();
129 } 120 }
130 return *defer; 121 }
122
123 void IoThreadClientThrottle::WillRedirectRequest(const GURL& new_url,
124 bool* defer) {
125 WillStartRequest(defer);
131 } 126 }
132 127
133 void IoThreadClientThrottle::OnIoThreadClientReady(int new_child_id, 128 void IoThreadClientThrottle::OnIoThreadClientReady(int new_child_id,
134 int new_route_id) { 129 int new_route_id) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
136 131
137 if (!MaybeBlockRequest()) { 132 if (!MaybeBlockRequest()) {
138 controller()->Resume(); 133 controller()->Resume();
139 } 134 }
140 } 135 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 204 }
210 205
211 void AwResourceDispatcherHostDelegate::RequestBeginning( 206 void AwResourceDispatcherHostDelegate::RequestBeginning(
212 net::URLRequest* request, 207 net::URLRequest* request,
213 content::ResourceContext* resource_context, 208 content::ResourceContext* resource_context,
214 appcache::AppCacheService* appcache_service, 209 appcache::AppCacheService* appcache_service,
215 ResourceType::Type resource_type, 210 ResourceType::Type resource_type,
216 int child_id, 211 int child_id,
217 int route_id, 212 int route_id,
218 ScopedVector<content::ResourceThrottle>* throttles) { 213 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 214
215 // We always push the throttles here. Checking the existence of io_client
216 // is racy when a popup window is created. That is because RequestBeginning
217 // is called whether or not requests are blocked via BlockRequestForRoute()
218 // however io_client may or may not be ready at the time depending on whether
219 // webcontents is created.
228 throttles->push_back(new IoThreadClientThrottle( 220 throttles->push_back(new IoThreadClientThrottle(
229 child_id, route_id, request)); 221 child_id, route_id, request));
230 222
231 bool allow_intercepting = 223 // We allow intercepting only navigations within main frames. This
232 // We allow intercepting navigations within subframes, but only if the 224 // is used to post onPageStarted. We handle shouldOverrideUrlLoading
233 // scheme other than http or https. This is because the embedder 225 // via a sync IPC.
234 // can't distinguish main frame and subframe callbacks (which could lead 226 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( 227 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor(
246 request)); 228 request));
247 }
248 } 229 }
249 230
250 void AwResourceDispatcherHostDelegate::DownloadStarting( 231 void AwResourceDispatcherHostDelegate::DownloadStarting(
251 net::URLRequest* request, 232 net::URLRequest* request,
252 content::ResourceContext* resource_context, 233 content::ResourceContext* resource_context,
253 int child_id, 234 int child_id,
254 int route_id, 235 int route_id,
255 int request_id, 236 int request_id,
256 bool is_content_initiated, 237 bool is_content_initiated,
257 bool must_download, 238 bool must_download,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 ChildRouteIDPair(new_child_id, new_route_id)); 387 ChildRouteIDPair(new_child_id, new_route_id));
407 388
408 if (it != pending_throttles_.end()) { 389 if (it != pending_throttles_.end()) {
409 IoThreadClientThrottle* throttle = it->second; 390 IoThreadClientThrottle* throttle = it->second;
410 throttle->OnIoThreadClientReady(new_child_id, new_route_id); 391 throttle->OnIoThreadClientReady(new_child_id, new_route_id);
411 pending_throttles_.erase(it); 392 pending_throttles_.erase(it);
412 } 393 }
413 } 394 }
414 395
415 } // namespace android_webview 396 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/aw_contents_client_bridge_base.h ('k') | android_webview/common/render_view_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698