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