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

Side by Side Diff: chrome/browser/download/download_request_limiter.cc

Issue 13609002: fix a problem that android cannot download files with basic authentication (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 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 "chrome/browser/download/download_request_limiter.h" 5 #include "chrome/browser/download/download_request_limiter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/download/download_request_infobar_delegate.h" 9 #include "chrome/browser/download/download_request_infobar_delegate.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 DownloadRequestLimiter::GetDownloadStatus(WebContents* web_contents) { 221 DownloadRequestLimiter::GetDownloadStatus(WebContents* web_contents) {
222 TabDownloadState* state = GetDownloadState(web_contents, NULL, false); 222 TabDownloadState* state = GetDownloadState(web_contents, NULL, false);
223 return state ? state->download_status() : ALLOW_ONE_DOWNLOAD; 223 return state ? state->download_status() : ALLOW_ONE_DOWNLOAD;
224 } 224 }
225 225
226 void DownloadRequestLimiter::CanDownloadOnIOThread( 226 void DownloadRequestLimiter::CanDownloadOnIOThread(
227 int render_process_host_id, 227 int render_process_host_id,
228 int render_view_id, 228 int render_view_id,
229 int request_id, 229 int request_id,
230 const std::string& request_method, 230 const std::string& request_method,
231 bool has_auth,
231 const Callback& callback) { 232 const Callback& callback) {
232 // This is invoked on the IO thread. Schedule the task to run on the UI 233 // This is invoked on the IO thread. Schedule the task to run on the UI
233 // thread so that we can query UI state. 234 // thread so that we can query UI state.
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
235 BrowserThread::PostTask( 236 BrowserThread::PostTask(
236 BrowserThread::UI, FROM_HERE, 237 BrowserThread::UI, FROM_HERE,
237 base::Bind(&DownloadRequestLimiter::CanDownload, this, 238 base::Bind(&DownloadRequestLimiter::CanDownload, this,
238 render_process_host_id, render_view_id, request_id, 239 render_process_host_id, render_view_id, request_id,
239 request_method, callback)); 240 request_method, has_auth, callback));
240 } 241 }
241 242
242 DownloadRequestLimiter::TabDownloadState* 243 DownloadRequestLimiter::TabDownloadState*
243 DownloadRequestLimiter::GetDownloadState( 244 DownloadRequestLimiter::GetDownloadState(
244 WebContents* web_contents, 245 WebContents* web_contents,
245 WebContents* originating_web_contents, 246 WebContents* originating_web_contents,
246 bool create) { 247 bool create) {
247 DCHECK(web_contents); 248 DCHECK(web_contents);
248 StateMap::iterator i = state_map_.find(web_contents); 249 StateMap::iterator i = state_map_.find(web_contents);
249 if (i != state_map_.end()) 250 if (i != state_map_.end())
250 return i->second; 251 return i->second;
251 252
252 if (!create) 253 if (!create)
253 return NULL; 254 return NULL;
254 255
255 TabDownloadState* state = 256 TabDownloadState* state =
256 new TabDownloadState(this, web_contents, originating_web_contents); 257 new TabDownloadState(this, web_contents, originating_web_contents);
257 state_map_[web_contents] = state; 258 state_map_[web_contents] = state;
258 return state; 259 return state;
259 } 260 }
260 261
261 void DownloadRequestLimiter::CanDownload(int render_process_host_id, 262 void DownloadRequestLimiter::CanDownload(int render_process_host_id,
262 int render_view_id, 263 int render_view_id,
263 int request_id, 264 int request_id,
264 const std::string& request_method, 265 const std::string& request_method,
266 bool has_auth,
265 const Callback& callback) { 267 const Callback& callback) {
266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
267 269
268 WebContents* originating_contents = 270 WebContents* originating_contents =
269 tab_util::GetWebContentsByID(render_process_host_id, render_view_id); 271 tab_util::GetWebContentsByID(render_process_host_id, render_view_id);
270 if (!originating_contents) { 272 if (!originating_contents) {
271 // The WebContents was closed, don't allow the download. 273 // The WebContents was closed, don't allow the download.
272 ScheduleNotification(callback, false); 274 ScheduleNotification(callback, false);
273 return; 275 return;
274 } 276 }
275 277
276 CanDownloadImpl( 278 CanDownloadImpl(
277 originating_contents, 279 originating_contents,
278 request_id, 280 request_id,
279 request_method, 281 request_method,
282 has_auth,
280 callback); 283 callback);
281 } 284 }
282 285
283 void DownloadRequestLimiter::CanDownloadImpl(WebContents* originating_contents, 286 void DownloadRequestLimiter::CanDownloadImpl(WebContents* originating_contents,
284 int request_id, 287 int request_id,
285 const std::string& request_method, 288 const std::string& request_method,
289 bool has_auth,
286 const Callback& callback) { 290 const Callback& callback) {
287 DCHECK(originating_contents); 291 DCHECK(originating_contents);
288 292
289 // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order 293 // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order
290 // to cancel the download operation in chrome and let the host browser 294 // to cancel the download operation in chrome and let the host browser
291 // take care of it. 295 // take care of it.
292 if (originating_contents->GetDelegate() && 296 if (originating_contents->GetDelegate() &&
293 !originating_contents->GetDelegate()->CanDownload( 297 !originating_contents->GetDelegate()->CanDownload(
294 originating_contents->GetRenderViewHost(), 298 originating_contents->GetRenderViewHost(),
295 request_id, 299 request_id,
296 request_method)) { 300 request_method,
301 has_auth)) {
297 ScheduleNotification(callback, false); 302 ScheduleNotification(callback, false);
298 return; 303 return;
299 } 304 }
300 305
301 // If the tab requesting the download is a constrained popup that is not 306 // If the tab requesting the download is a constrained popup that is not
302 // shown, treat the request as if it came from the parent. 307 // shown, treat the request as if it came from the parent.
303 WebContents* effective_contents = originating_contents; 308 WebContents* effective_contents = originating_contents;
304 BlockedContentTabHelper* blocked_content_tab_helper = 309 BlockedContentTabHelper* blocked_content_tab_helper =
305 BlockedContentTabHelper::FromWebContents(originating_contents); 310 BlockedContentTabHelper::FromWebContents(originating_contents);
306 if (blocked_content_tab_helper && 311 if (blocked_content_tab_helper &&
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 bool allow) { 348 bool allow) {
344 BrowserThread::PostTask( 349 BrowserThread::PostTask(
345 BrowserThread::IO, FROM_HERE, base::Bind(callback, allow)); 350 BrowserThread::IO, FROM_HERE, base::Bind(callback, allow));
346 } 351 }
347 352
348 void DownloadRequestLimiter::Remove(TabDownloadState* state) { 353 void DownloadRequestLimiter::Remove(TabDownloadState* state) {
349 DCHECK(ContainsKey(state_map_, state->web_contents())); 354 DCHECK(ContainsKey(state_map_, state->web_contents()));
350 state_map_.erase(state->web_contents()); 355 state_map_.erase(state->web_contents());
351 delete state; 356 delete state;
352 } 357 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698