Index: chrome/browser/ui/content_settings/content_setting_image_model.cc |
diff --git a/chrome/browser/ui/content_settings/content_setting_image_model.cc b/chrome/browser/ui/content_settings/content_setting_image_model.cc |
index 67c44465abfd31978bf5cd47343c499572aaebb2..7f7088929ab0af8d1994a5fe601d75232b6e27a0 100644 |
--- a/chrome/browser/ui/content_settings/content_setting_image_model.cc |
+++ b/chrome/browser/ui/content_settings/content_setting_image_model.cc |
@@ -8,8 +8,10 @@ |
#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
#include "build/build_config.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
#include "chrome/browser/content_settings/tab_specific_content_settings.h" |
+#include "chrome/browser/download/download_request_limiter.h" |
#include "chrome/browser/plugins/plugin_utils.h" |
#include "chrome/browser/prerender/prerender_manager.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -36,6 +38,7 @@ using content::WebContents; |
// ContentSettingGeolocationImageModel - geolocation |
// ContentSettingRPHImageModel - protocol handlers |
// ContentSettingMIDISysExImageModel - midi sysex |
+// ContentSettingDownloadsImageModel - automatic downloads |
// ContentSettingMediaImageModel - media |
// ContentSettingSubresourceFilterImageModel - deceptive content |
@@ -96,6 +99,17 @@ class ContentSettingMIDISysExImageModel |
DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
}; |
+class ContentSettingDownloadsImageModel |
+ : public ContentSettingSimpleImageModel { |
+ public: |
+ ContentSettingDownloadsImageModel(); |
+ |
+ void UpdateFromWebContents(WebContents* web_contents) override; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel); |
+}; |
+ |
namespace { |
struct ContentSettingsImageDetails { |
@@ -121,9 +135,6 @@ const ContentSettingsImageDetails kImageDetails[] = { |
IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, |
{CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, |
IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
- {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
- gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE, |
- IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE}, |
}; |
// The ordering of the models here influences the order in which icons are |
@@ -209,6 +220,9 @@ ContentSettingSimpleImageModel::CreateForContentTypeForTesting( |
if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) |
return base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
+ if (content_settings_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) |
+ return base::MakeUnique<ContentSettingDownloadsImageModel>(); |
+ |
return base::MakeUnique<ContentSettingBlockedImageModel>( |
content_settings_type); |
} |
@@ -519,6 +533,46 @@ void ContentSettingMIDISysExImageModel::UpdateFromWebContents( |
: IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
} |
+// Automatic downloads --------------------------------------------------------- |
+ |
+ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel() |
+ : ContentSettingSimpleImageModel( |
+ CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {} |
+ |
+void ContentSettingDownloadsImageModel::UpdateFromWebContents( |
+ WebContents* web_contents) { |
+ set_visible(false); |
+ if (!web_contents) |
+ return; |
+ |
+ DownloadRequestLimiter* download_request_limiter = |
+ g_browser_process->download_request_limiter(); |
+ |
+ // DownloadRequestLimiter can be absent in unit_tests. |
+ if (!download_request_limiter) |
+ return; |
alshabalin
2017/02/28 10:31:31
Also added this check for the sake of unit_tests w
|
+ |
+ switch (download_request_limiter->GetDownloadStatus(web_contents)) { |
+ case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS: |
+ set_visible(true); |
+ set_icon_by_vector_id(gfx::VectorIconId::FILE_DOWNLOAD, |
+ gfx::VectorIconId::VECTOR_ICON_NONE); |
+ set_explanatory_string_id(0); |
+ set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE)); |
+ return; |
+ case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED: |
+ set_visible(true); |
+ set_icon_by_vector_id(gfx::VectorIconId::FILE_DOWNLOAD, |
+ gfx::VectorIconId::BLOCKED_BADGE); |
+ set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION); |
+ set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE)); |
+ return; |
+ default: |
+ // No need to show icon otherwise. |
+ return; |
+ } |
+} |
+ |
// Base class ------------------------------------------------------------------ |
gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { |
@@ -561,6 +615,9 @@ ContentSettingImageModel::GenerateContentSettingImageModels() { |
case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
break; |
+ case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: |
+ model = base::MakeUnique<ContentSettingDownloadsImageModel>(); |
+ break; |
default: |
// All other content settings types use ContentSettingBlockedImageModel. |
model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); |