OLD | NEW |
---|---|
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/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
12 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/tab_contents/tab_util.h" | 13 #include "chrome/browser/tab_contents/tab_util.h" |
14 #include "components/content_settings/core/browser/content_settings_details.h" | |
15 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
16 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_types.h" | |
23 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/resource_dispatcher_host.h" | 23 #include "content/public/browser/resource_dispatcher_host.h" |
25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
28 | 27 |
29 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
30 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 29 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
31 #else | 30 #else |
32 #include "chrome/browser/download/download_permission_request.h" | 31 #include "chrome/browser/download/download_permission_request.h" |
33 #include "chrome/browser/permissions/permission_request_manager.h" | 32 #include "chrome/browser/permissions/permission_request_manager.h" |
34 #endif | 33 #endif |
35 | 34 |
36 using content::BrowserThread; | 35 using content::BrowserThread; |
37 using content::NavigationController; | 36 using content::NavigationController; |
38 using content::NavigationEntry; | 37 using content::NavigationEntry; |
39 | 38 |
39 namespace { | |
40 | |
41 ContentSetting GetSettingFromStatus( | |
42 DownloadRequestLimiter::DownloadStatus status) { | |
43 switch (status) { | |
44 case DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD: | |
45 case DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD: | |
46 return CONTENT_SETTING_ASK; | |
47 case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS: | |
48 return CONTENT_SETTING_ALLOW; | |
49 case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED: | |
50 return CONTENT_SETTING_BLOCK; | |
51 default: | |
Bernhard Bauer
2017/02/16 13:08:14
Actually, the default isn't necessary if you have
alshabalin
2017/02/17 09:21:10
Good point, thank you. Done. However, I'm surprise
Bernhard Bauer
2017/02/17 10:51:22
Haha :-D Turns out, the dirty secret is that the c
| |
52 NOTREACHED(); | |
53 return CONTENT_SETTING_DEFAULT; | |
54 } | |
55 } | |
56 | |
57 DownloadRequestLimiter::DownloadStatus GetStatusFromSetting( | |
58 ContentSetting setting) { | |
59 switch (setting) { | |
60 case CONTENT_SETTING_ALLOW: | |
61 return DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS; | |
62 case CONTENT_SETTING_BLOCK: | |
63 return DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED; | |
64 case CONTENT_SETTING_DEFAULT: | |
65 case CONTENT_SETTING_ASK: | |
66 return DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD; | |
67 case CONTENT_SETTING_SESSION_ONLY: | |
68 case CONTENT_SETTING_NUM_SETTINGS: | |
69 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | |
70 NOTREACHED(); | |
71 return DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD; | |
72 } | |
73 } | |
74 | |
75 } // namespace | |
76 | |
40 // TabDownloadState ------------------------------------------------------------ | 77 // TabDownloadState ------------------------------------------------------------ |
41 | 78 |
42 DownloadRequestLimiter::TabDownloadState::TabDownloadState( | 79 DownloadRequestLimiter::TabDownloadState::TabDownloadState( |
43 DownloadRequestLimiter* host, | 80 DownloadRequestLimiter* host, |
44 content::WebContents* contents, | 81 content::WebContents* contents, |
45 content::WebContents* originating_web_contents) | 82 content::WebContents* originating_web_contents) |
46 : content::WebContentsObserver(contents), | 83 : content::WebContentsObserver(contents), |
47 web_contents_(contents), | 84 web_contents_(contents), |
48 host_(host), | 85 host_(host), |
49 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), | 86 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), |
50 download_count_(0), | 87 download_count_(0), |
88 observer_(this), | |
51 factory_(this) { | 89 factory_(this) { |
52 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 90 observer_.Add(GetContentSettings(contents)); |
53 content::Source<content::WebContents>(contents)); | |
54 NavigationEntry* last_entry = | 91 NavigationEntry* last_entry = |
55 originating_web_contents | 92 originating_web_contents |
56 ? originating_web_contents->GetController().GetLastCommittedEntry() | 93 ? originating_web_contents->GetController().GetLastCommittedEntry() |
57 : contents->GetController().GetLastCommittedEntry(); | 94 : contents->GetController().GetLastCommittedEntry(); |
58 if (last_entry) | 95 if (last_entry) |
59 initial_page_host_ = last_entry->GetURL().host(); | 96 initial_page_host_ = last_entry->GetURL().host(); |
60 } | 97 } |
61 | 98 |
62 DownloadRequestLimiter::TabDownloadState::~TabDownloadState() { | 99 DownloadRequestLimiter::TabDownloadState::~TabDownloadState() { |
63 // We should only be destroyed after the callbacks have been notified. | 100 // We should only be destroyed after the callbacks have been notified. |
64 DCHECK(callbacks_.empty()); | 101 DCHECK(callbacks_.empty()); |
65 | 102 |
66 // And we should have invalidated the back pointer. | 103 // And we should have invalidated the back pointer. |
67 DCHECK(!factory_.HasWeakPtrs()); | 104 DCHECK(!factory_.HasWeakPtrs()); |
68 } | 105 } |
69 | 106 |
107 void DownloadRequestLimiter::TabDownloadState::SetDownloadStatusAndNotify( | |
108 DownloadStatus status) { | |
109 SetDownloadStatusAndNotifyImpl(status, GetSettingFromStatus(status)); | |
110 } | |
111 | |
70 void DownloadRequestLimiter::TabDownloadState::DidStartNavigation( | 112 void DownloadRequestLimiter::TabDownloadState::DidStartNavigation( |
71 content::NavigationHandle* navigation_handle) { | 113 content::NavigationHandle* navigation_handle) { |
72 if (!navigation_handle->IsInMainFrame()) | 114 if (!navigation_handle->IsInMainFrame()) |
73 return; | 115 return; |
74 | 116 |
75 // If the navigation is renderer-initiated (but not user-initiated), ensure | 117 // If the navigation is renderer-initiated (but not user-initiated), ensure |
76 // that a prompting or blocking limiter state is not reset, so | 118 // that a prompting or blocking limiter state is not reset, so |
77 // window.location.href or meta refresh can't be abused to avoid the limiter. | 119 // window.location.href or meta refresh can't be abused to avoid the limiter. |
78 // User-initiated navigations will trigger DidGetUserInteraction, which resets | 120 // User-initiated navigations will trigger DidGetUserInteraction, which resets |
79 // the limiter before the navigation starts. | 121 // the limiter before the navigation starts. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 DownloadRequestLimiter::GetContentSettings(web_contents_); | 229 DownloadRequestLimiter::GetContentSettings(web_contents_); |
188 if (!settings) | 230 if (!settings) |
189 return; | 231 return; |
190 settings->SetContentSettingDefaultScope( | 232 settings->SetContentSettingDefaultScope( |
191 web_contents_->GetURL(), GURL(), | 233 web_contents_->GetURL(), GURL(), |
192 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), setting); | 234 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), setting); |
193 } | 235 } |
194 | 236 |
195 void DownloadRequestLimiter::TabDownloadState::Cancel() { | 237 void DownloadRequestLimiter::TabDownloadState::Cancel() { |
196 SetContentSetting(CONTENT_SETTING_BLOCK); | 238 SetContentSetting(CONTENT_SETTING_BLOCK); |
197 NotifyCallbacks(false); | 239 bool throttled = NotifyCallbacks(false); |
240 SetDownloadStatusAndNotify(throttled ? PROMPT_BEFORE_DOWNLOAD | |
241 : DOWNLOADS_NOT_ALLOWED); | |
198 } | 242 } |
199 | 243 |
200 void DownloadRequestLimiter::TabDownloadState::CancelOnce() { | 244 void DownloadRequestLimiter::TabDownloadState::CancelOnce() { |
201 NotifyCallbacks(false); | 245 bool throttled = NotifyCallbacks(false); |
246 SetDownloadStatusAndNotify(throttled ? PROMPT_BEFORE_DOWNLOAD | |
247 : DOWNLOADS_NOT_ALLOWED); | |
202 } | 248 } |
203 | 249 |
204 void DownloadRequestLimiter::TabDownloadState::Accept() { | 250 void DownloadRequestLimiter::TabDownloadState::Accept() { |
205 SetContentSetting(CONTENT_SETTING_ALLOW); | 251 SetContentSetting(CONTENT_SETTING_ALLOW); |
206 NotifyCallbacks(true); | 252 bool throttled = NotifyCallbacks(true); |
253 SetDownloadStatusAndNotify(throttled ? PROMPT_BEFORE_DOWNLOAD | |
254 : ALLOW_ALL_DOWNLOADS); | |
207 } | 255 } |
208 | 256 |
209 DownloadRequestLimiter::TabDownloadState::TabDownloadState() | 257 DownloadRequestLimiter::TabDownloadState::TabDownloadState() |
210 : web_contents_(NULL), | 258 : web_contents_(NULL), |
211 host_(NULL), | 259 host_(NULL), |
212 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), | 260 status_(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD), |
213 download_count_(0), | 261 download_count_(0), |
262 observer_(this), | |
214 factory_(this) {} | 263 factory_(this) {} |
215 | 264 |
216 bool DownloadRequestLimiter::TabDownloadState::is_showing_prompt() const { | 265 bool DownloadRequestLimiter::TabDownloadState::is_showing_prompt() const { |
217 return factory_.HasWeakPtrs(); | 266 return factory_.HasWeakPtrs(); |
218 } | 267 } |
219 | 268 |
220 void DownloadRequestLimiter::TabDownloadState::Observe( | 269 void DownloadRequestLimiter::TabDownloadState::OnContentSettingChanged( |
221 int type, | 270 const ContentSettingsPattern& primary_pattern, |
222 const content::NotificationSource& source, | 271 const ContentSettingsPattern& secondary_pattern, |
223 const content::NotificationDetails& details) { | 272 ContentSettingsType content_type, |
224 DCHECK_EQ(chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, type); | 273 std::string resource_identifier) { |
274 if (content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) | |
275 return; | |
276 | |
277 // Analogous to TabSpecificContentSettings::OnContentSettingChanged: | |
278 const ContentSettingsDetails details(primary_pattern, secondary_pattern, | |
279 content_type, resource_identifier); | |
280 const NavigationController& controller = web_contents()->GetController(); | |
281 | |
282 // The visible NavigationEntry is the URL in the URL field of a tab. | |
283 // Currently this should be matched by the |primary_pattern|. | |
284 NavigationEntry* entry = controller.GetVisibleEntry(); | |
285 GURL entry_url; | |
286 if (entry) | |
287 entry_url = entry->GetURL(); | |
288 if (!details.update_all() && !details.primary_pattern().Matches(entry_url)) | |
289 return; | |
225 | 290 |
226 // Content settings have been updated for our web contents, e.g. via the OIB | 291 // Content settings have been updated for our web contents, e.g. via the OIB |
227 // or the settings page. Check to see if the automatic downloads setting is | 292 // or the settings page. Check to see if the automatic downloads setting is |
228 // different to our internal state, and update the internal state to match if | 293 // different to our internal state, and update the internal state to match if |
229 // necessary. If there is no content setting persisted, then retain the | 294 // necessary. If there is no content setting persisted, then retain the |
230 // current state and do nothing. | 295 // current state and do nothing. |
231 // | 296 // |
232 // NotifyCallbacks is not called as this notification should be triggered when | 297 // NotifyCallbacks is not called as this notification should be triggered when |
233 // a download is not pending. | 298 // a download is not pending. |
234 content::WebContents* contents = | 299 // |
235 content::Source<content::WebContents>(source).ptr(); | |
236 DCHECK_EQ(contents, web_contents()); | |
237 | |
238 // Fetch the content settings map for this web contents, and extract the | 300 // Fetch the content settings map for this web contents, and extract the |
239 // automatic downloads permission value. | 301 // automatic downloads permission value. |
240 HostContentSettingsMap* content_settings = GetContentSettings(contents); | 302 HostContentSettingsMap* content_settings = GetContentSettings(web_contents()); |
241 if (!content_settings) | 303 if (!content_settings) |
242 return; | 304 return; |
243 | 305 |
244 ContentSetting setting = content_settings->GetContentSetting( | 306 ContentSetting setting = content_settings->GetContentSetting( |
245 contents->GetURL(), contents->GetURL(), | 307 web_contents()->GetURL(), web_contents()->GetURL(), |
246 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string()); | 308 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string()); |
247 | 309 |
248 // Update the internal state to match if necessary. | 310 // Update the internal state to match if necessary. |
249 switch (setting) { | 311 SetDownloadStatusAndNotifyImpl(GetStatusFromSetting(setting), setting); |
250 case CONTENT_SETTING_ALLOW: | |
251 set_download_status(ALLOW_ALL_DOWNLOADS); | |
252 break; | |
253 case CONTENT_SETTING_BLOCK: | |
254 set_download_status(DOWNLOADS_NOT_ALLOWED); | |
255 break; | |
256 case CONTENT_SETTING_ASK: | |
257 case CONTENT_SETTING_DEFAULT: | |
258 case CONTENT_SETTING_SESSION_ONLY: | |
259 set_download_status(PROMPT_BEFORE_DOWNLOAD); | |
260 break; | |
261 case CONTENT_SETTING_NUM_SETTINGS: | |
262 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | |
263 NOTREACHED(); | |
264 return; | |
265 } | |
266 } | 312 } |
267 | 313 |
268 void DownloadRequestLimiter::TabDownloadState::NotifyCallbacks(bool allow) { | 314 bool DownloadRequestLimiter::TabDownloadState::NotifyCallbacks(bool allow) { |
269 set_download_status(allow ? DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS | |
270 : DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); | |
271 std::vector<DownloadRequestLimiter::Callback> callbacks; | 315 std::vector<DownloadRequestLimiter::Callback> callbacks; |
272 bool change_status = false; | 316 bool throttled = false; |
273 | 317 |
274 // Selectively send first few notifications only if number of downloads exceed | 318 // Selectively send first few notifications only if number of downloads exceed |
275 // kMaxDownloadsAtOnce. In that case, we also retain the infobar instance and | 319 // kMaxDownloadsAtOnce. In that case, we also retain the infobar instance and |
276 // don't close it. If allow is false, we send all the notifications to cancel | 320 // don't close it. If allow is false, we send all the notifications to cancel |
277 // all remaining downloads and close the infobar. | 321 // all remaining downloads and close the infobar. |
278 if (!allow || (callbacks_.size() < kMaxDownloadsAtOnce)) { | 322 if (!allow || (callbacks_.size() < kMaxDownloadsAtOnce)) { |
279 // Null the generated weak pointer so we don't get notified again. | 323 // Null the generated weak pointer so we don't get notified again. |
280 factory_.InvalidateWeakPtrs(); | 324 factory_.InvalidateWeakPtrs(); |
281 callbacks.swap(callbacks_); | 325 callbacks.swap(callbacks_); |
282 } else { | 326 } else { |
283 std::vector<DownloadRequestLimiter::Callback>::iterator start, end; | 327 std::vector<DownloadRequestLimiter::Callback>::iterator start, end; |
284 start = callbacks_.begin(); | 328 start = callbacks_.begin(); |
285 end = callbacks_.begin() + kMaxDownloadsAtOnce; | 329 end = callbacks_.begin() + kMaxDownloadsAtOnce; |
286 callbacks.assign(start, end); | 330 callbacks.assign(start, end); |
287 callbacks_.erase(start, end); | 331 callbacks_.erase(start, end); |
288 change_status = true; | 332 throttled = true; |
289 } | 333 } |
290 | 334 |
291 for (const auto& callback : callbacks) { | 335 for (const auto& callback : callbacks) { |
292 // When callback runs, it can cause the WebContents to be destroyed. | 336 // When callback runs, it can cause the WebContents to be destroyed. |
293 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 337 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
294 base::Bind(callback, allow)); | 338 base::Bind(callback, allow)); |
295 } | 339 } |
296 | 340 |
297 if (change_status) | 341 return throttled; |
298 set_download_status(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD); | 342 } |
343 | |
344 void DownloadRequestLimiter::TabDownloadState::SetDownloadStatusAndNotifyImpl( | |
345 DownloadStatus status, | |
346 ContentSetting setting) { | |
347 ContentSetting last_setting = GetSettingFromStatus(status_); | |
348 status_ = status; | |
349 if (!web_contents()) | |
350 return; | |
351 if (last_setting == setting) | |
352 return; | |
353 content::NotificationService::current()->Notify( | |
354 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | |
355 content::Source<content::WebContents>(web_contents()), | |
356 content::NotificationService::NoDetails()); | |
299 } | 357 } |
300 | 358 |
301 // DownloadRequestLimiter ------------------------------------------------------ | 359 // DownloadRequestLimiter ------------------------------------------------------ |
302 | 360 |
303 HostContentSettingsMap* DownloadRequestLimiter::content_settings_ = NULL; | 361 HostContentSettingsMap* DownloadRequestLimiter::content_settings_ = NULL; |
304 | 362 |
305 void DownloadRequestLimiter::SetContentSettingsForTesting( | 363 void DownloadRequestLimiter::SetContentSettingsForTesting( |
306 HostContentSettingsMap* content_settings) { | 364 HostContentSettingsMap* content_settings) { |
307 content_settings_ = content_settings; | 365 content_settings_ = content_settings; |
308 } | 366 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 const Callback& callback) { | 457 const Callback& callback) { |
400 DCHECK(originating_contents); | 458 DCHECK(originating_contents); |
401 | 459 |
402 TabDownloadState* state = | 460 TabDownloadState* state = |
403 GetDownloadState(originating_contents, originating_contents, true); | 461 GetDownloadState(originating_contents, originating_contents, true); |
404 switch (state->download_status()) { | 462 switch (state->download_status()) { |
405 case ALLOW_ALL_DOWNLOADS: | 463 case ALLOW_ALL_DOWNLOADS: |
406 if (state->download_count() && | 464 if (state->download_count() && |
407 !(state->download_count() % | 465 !(state->download_count() % |
408 DownloadRequestLimiter::kMaxDownloadsAtOnce)) | 466 DownloadRequestLimiter::kMaxDownloadsAtOnce)) |
409 state->set_download_status(PROMPT_BEFORE_DOWNLOAD); | 467 state->SetDownloadStatusAndNotify(PROMPT_BEFORE_DOWNLOAD); |
410 callback.Run(true); | 468 callback.Run(true); |
411 state->increment_download_count(); | 469 state->increment_download_count(); |
412 break; | 470 break; |
413 | 471 |
414 case ALLOW_ONE_DOWNLOAD: | 472 case ALLOW_ONE_DOWNLOAD: |
415 state->set_download_status(PROMPT_BEFORE_DOWNLOAD); | 473 state->SetDownloadStatusAndNotify(PROMPT_BEFORE_DOWNLOAD); |
416 callback.Run(true); | 474 callback.Run(true); |
417 state->increment_download_count(); | 475 state->increment_download_count(); |
418 break; | 476 break; |
419 | 477 |
420 case DOWNLOADS_NOT_ALLOWED: | 478 case DOWNLOADS_NOT_ALLOWED: |
421 callback.Run(false); | 479 callback.Run(false); |
422 break; | 480 break; |
423 | 481 |
424 case PROMPT_BEFORE_DOWNLOAD: { | 482 case PROMPT_BEFORE_DOWNLOAD: { |
425 HostContentSettingsMap* content_settings = | 483 HostContentSettingsMap* content_settings = |
426 GetContentSettings(originating_contents); | 484 GetContentSettings(originating_contents); |
427 ContentSetting setting = CONTENT_SETTING_ASK; | 485 ContentSetting setting = CONTENT_SETTING_ASK; |
428 if (content_settings) | 486 if (content_settings) |
429 setting = content_settings->GetContentSetting( | 487 setting = content_settings->GetContentSetting( |
430 originating_contents->GetURL(), originating_contents->GetURL(), | 488 originating_contents->GetURL(), originating_contents->GetURL(), |
431 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string()); | 489 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string()); |
432 switch (setting) { | 490 switch (setting) { |
433 case CONTENT_SETTING_ALLOW: { | 491 case CONTENT_SETTING_ALLOW: { |
434 TabSpecificContentSettings* settings = | 492 state->SetDownloadStatusAndNotify(ALLOW_ALL_DOWNLOADS); |
435 TabSpecificContentSettings::FromWebContents(originating_contents); | |
436 if (settings) | |
437 settings->SetDownloadsBlocked(false); | |
438 callback.Run(true); | 493 callback.Run(true); |
439 state->increment_download_count(); | 494 state->increment_download_count(); |
440 return; | 495 return; |
441 } | 496 } |
442 case CONTENT_SETTING_BLOCK: { | 497 case CONTENT_SETTING_BLOCK: { |
443 TabSpecificContentSettings* settings = | 498 state->SetDownloadStatusAndNotify(DOWNLOADS_NOT_ALLOWED); |
444 TabSpecificContentSettings::FromWebContents(originating_contents); | |
445 if (settings) | |
446 settings->SetDownloadsBlocked(true); | |
447 callback.Run(false); | 499 callback.Run(false); |
448 return; | 500 return; |
449 } | 501 } |
450 case CONTENT_SETTING_DEFAULT: | 502 case CONTENT_SETTING_DEFAULT: |
451 case CONTENT_SETTING_ASK: | 503 case CONTENT_SETTING_ASK: |
452 case CONTENT_SETTING_SESSION_ONLY: | |
453 state->PromptUserForDownload(callback); | 504 state->PromptUserForDownload(callback); |
454 state->increment_download_count(); | 505 state->increment_download_count(); |
455 break; | 506 break; |
507 case CONTENT_SETTING_SESSION_ONLY: | |
456 case CONTENT_SETTING_NUM_SETTINGS: | 508 case CONTENT_SETTING_NUM_SETTINGS: |
457 default: | 509 default: |
458 NOTREACHED(); | 510 NOTREACHED(); |
459 return; | 511 return; |
460 } | 512 } |
461 break; | 513 break; |
462 } | 514 } |
463 | 515 |
464 default: | 516 default: |
465 NOTREACHED(); | 517 NOTREACHED(); |
466 } | 518 } |
467 } | 519 } |
468 | 520 |
469 void DownloadRequestLimiter::Remove(TabDownloadState* state, | 521 void DownloadRequestLimiter::Remove(TabDownloadState* state, |
470 content::WebContents* contents) { | 522 content::WebContents* contents) { |
471 DCHECK(base::ContainsKey(state_map_, contents)); | 523 DCHECK(base::ContainsKey(state_map_, contents)); |
472 state_map_.erase(contents); | 524 state_map_.erase(contents); |
473 delete state; | 525 delete state; |
474 } | 526 } |
OLD | NEW |