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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_image_model.cc

Issue 2561673003: Handle per-tab AUTOMATIC_DOWNLOADS setting in DownloadRequestLimiter. (Closed)
Patch Set: Fix whitespace Created 3 years, 10 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
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/ui/content_settings/content_setting_image_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_image_model.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
14 #include "chrome/browser/download/download_request_limiter.h"
13 #include "chrome/browser/plugins/plugin_utils.h" 15 #include "chrome/browser/plugins/plugin_utils.h"
14 #include "chrome/browser/prerender/prerender_manager.h" 16 #include "chrome/browser/prerender/prerender_manager.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_features.h" 18 #include "chrome/common/chrome_features.h"
17 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
18 #include "chrome/grit/theme_resources.h" 20 #include "chrome/grit/theme_resources.h"
19 #include "components/content_settings/core/browser/host_content_settings_map.h" 21 #include "components/content_settings/core/browser/host_content_settings_map.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/material_design/material_design_controller.h" 24 #include "ui/base/material_design/material_design_controller.h"
23 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/gfx/color_palette.h" 26 #include "ui/gfx/color_palette.h"
25 #include "ui/gfx/color_utils.h" 27 #include "ui/gfx/color_utils.h"
26 #include "ui/gfx/paint_vector_icon.h" 28 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/gfx/vector_icons_public.h" 29 #include "ui/gfx/vector_icons_public.h"
28 30
29 using content::WebContents; 31 using content::WebContents;
30 32
31 // The image models hierarchy: 33 // The image models hierarchy:
32 // 34 //
33 // ContentSettingImageModel - base class 35 // ContentSettingImageModel - base class
34 // ContentSettingSimpleImageModel - single content setting 36 // ContentSettingSimpleImageModel - single content setting
35 // ContentSettingBlockedImageModel - generic blocked setting 37 // ContentSettingBlockedImageModel - generic blocked setting
36 // ContentSettingGeolocationImageModel - geolocation 38 // ContentSettingGeolocationImageModel - geolocation
37 // ContentSettingRPHImageModel - protocol handlers 39 // ContentSettingRPHImageModel - protocol handlers
38 // ContentSettingMIDISysExImageModel - midi sysex 40 // ContentSettingMIDISysExImageModel - midi sysex
41 // ContentSettingDownloadsImageModel - automatic downloads
39 // ContentSettingMediaImageModel - media 42 // ContentSettingMediaImageModel - media
40 // ContentSettingSubresourceFilterImageModel - deceptive content 43 // ContentSettingSubresourceFilterImageModel - deceptive content
41 44
42 class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { 45 class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel {
43 public: 46 public:
44 explicit ContentSettingBlockedImageModel(ContentSettingsType content_type); 47 explicit ContentSettingBlockedImageModel(ContentSettingsType content_type);
45 48
46 void UpdateFromWebContents(WebContents* web_contents) override; 49 void UpdateFromWebContents(WebContents* web_contents) override;
47 50
48 private: 51 private:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 : public ContentSettingSimpleImageModel { 93 : public ContentSettingSimpleImageModel {
91 public: 94 public:
92 ContentSettingMIDISysExImageModel(); 95 ContentSettingMIDISysExImageModel();
93 96
94 void UpdateFromWebContents(WebContents* web_contents) override; 97 void UpdateFromWebContents(WebContents* web_contents) override;
95 98
96 private: 99 private:
97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); 100 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel);
98 }; 101 };
99 102
103 class ContentSettingDownloadsImageModel
104 : public ContentSettingSimpleImageModel {
105 public:
106 ContentSettingDownloadsImageModel();
107
108 void UpdateFromWebContents(WebContents* web_contents) override;
109
110 private:
111 DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel);
112 };
113
100 namespace { 114 namespace {
101 115
102 struct ContentSettingsImageDetails { 116 struct ContentSettingsImageDetails {
103 ContentSettingsType type; 117 ContentSettingsType type;
104 gfx::VectorIconId icon_id; 118 gfx::VectorIconId icon_id;
105 int blocked_tooltip_id; 119 int blocked_tooltip_id;
106 int blocked_explanatory_text_id; 120 int blocked_explanatory_text_id;
107 int accessed_tooltip_id; 121 int accessed_tooltip_id;
108 }; 122 };
109 123
110 const ContentSettingsImageDetails kImageDetails[] = { 124 const ContentSettingsImageDetails kImageDetails[] = {
111 {CONTENT_SETTINGS_TYPE_COOKIES, gfx::VectorIconId::COOKIE, 125 {CONTENT_SETTINGS_TYPE_COOKIES, gfx::VectorIconId::COOKIE,
112 IDS_BLOCKED_COOKIES_TITLE, 0, IDS_ACCESSED_COOKIES_TITLE}, 126 IDS_BLOCKED_COOKIES_TITLE, 0, IDS_ACCESSED_COOKIES_TITLE},
113 {CONTENT_SETTINGS_TYPE_IMAGES, gfx::VectorIconId::IMAGE, 127 {CONTENT_SETTINGS_TYPE_IMAGES, gfx::VectorIconId::IMAGE,
114 IDS_BLOCKED_IMAGES_TITLE, 0, 0}, 128 IDS_BLOCKED_IMAGES_TITLE, 0, 0},
115 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, gfx::VectorIconId::CODE, 129 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, gfx::VectorIconId::CODE,
116 IDS_BLOCKED_JAVASCRIPT_TITLE, 0, 0}, 130 IDS_BLOCKED_JAVASCRIPT_TITLE, 0, 0},
117 {CONTENT_SETTINGS_TYPE_PLUGINS, gfx::VectorIconId::EXTENSION, 131 {CONTENT_SETTINGS_TYPE_PLUGINS, gfx::VectorIconId::EXTENSION,
118 IDS_BLOCKED_PLUGINS_MESSAGE, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT, 0}, 132 IDS_BLOCKED_PLUGINS_MESSAGE, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT, 0},
119 {CONTENT_SETTINGS_TYPE_POPUPS, gfx::VectorIconId::WEB, 133 {CONTENT_SETTINGS_TYPE_POPUPS, gfx::VectorIconId::WEB,
120 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, 134 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0},
121 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, 135 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT,
122 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, 136 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0},
123 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, 137 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION,
124 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, 138 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE},
125 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
126 gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE,
127 IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE},
128 }; 139 };
129 140
130 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { 141 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) {
131 for (const ContentSettingsImageDetails& image_details : kImageDetails) { 142 for (const ContentSettingsImageDetails& image_details : kImageDetails) {
132 if (image_details.type == type) 143 if (image_details.type == type)
133 return &image_details; 144 return &image_details;
134 } 145 }
135 return nullptr; 146 return nullptr;
136 } 147 }
137 148
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 ContentSettingsType content_settings_type) { 196 ContentSettingsType content_settings_type) {
186 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) 197 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
187 return base::MakeUnique<ContentSettingGeolocationImageModel>(); 198 return base::MakeUnique<ContentSettingGeolocationImageModel>();
188 199
189 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) 200 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS)
190 return base::MakeUnique<ContentSettingRPHImageModel>(); 201 return base::MakeUnique<ContentSettingRPHImageModel>();
191 202
192 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) 203 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX)
193 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); 204 return base::MakeUnique<ContentSettingMIDISysExImageModel>();
194 205
206 if (content_settings_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)
207 return base::MakeUnique<ContentSettingDownloadsImageModel>();
208
195 return base::MakeUnique<ContentSettingBlockedImageModel>( 209 return base::MakeUnique<ContentSettingBlockedImageModel>(
196 content_settings_type); 210 content_settings_type);
197 } 211 }
198 212
199 // Generic blocked content settings -------------------------------------------- 213 // Generic blocked content settings --------------------------------------------
200 214
201 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( 215 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
202 ContentSettingsType content_type) 216 ContentSettingsType content_type)
203 : ContentSettingSimpleImageModel(content_type) { 217 : ContentSettingSimpleImageModel(content_type) {
204 } 218 }
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 bool allowed = 509 bool allowed =
496 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); 510 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED);
497 set_icon_by_vector_id(gfx::VectorIconId::MIDI, 511 set_icon_by_vector_id(gfx::VectorIconId::MIDI,
498 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE 512 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE
499 : gfx::VectorIconId::BLOCKED_BADGE); 513 : gfx::VectorIconId::BLOCKED_BADGE);
500 set_tooltip(l10n_util::GetStringUTF16(allowed 514 set_tooltip(l10n_util::GetStringUTF16(allowed
501 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP 515 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP
502 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); 516 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP));
503 } 517 }
504 518
519 // Automatic downloads ---------------------------------------------------------
520
521 ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel()
522 : ContentSettingSimpleImageModel(
523 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {}
524
525 void ContentSettingDownloadsImageModel::UpdateFromWebContents(
526 WebContents* web_contents) {
527 set_visible(false);
528 if (!web_contents)
529 return;
530
531 switch (g_browser_process->download_request_limiter()->GetDownloadStatus(
532 web_contents)) {
533 case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS:
534 set_visible(true);
535 set_icon_by_vector_id(gfx::VectorIconId::FILE_DOWNLOAD,
536 gfx::VectorIconId::VECTOR_ICON_NONE);
537 set_explanatory_string_id(0);
538 set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE));
539 return;
540 case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED:
541 set_visible(true);
542 set_icon_by_vector_id(gfx::VectorIconId::FILE_DOWNLOAD,
543 gfx::VectorIconId::BLOCKED_BADGE);
544 set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION);
545 set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE));
546 return;
547 default:
548 // No need to show icon otherwise.
549 return;
550 }
551 }
552
505 // Base class ------------------------------------------------------------------ 553 // Base class ------------------------------------------------------------------
506 554
507 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { 555 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const {
508 #if defined(OS_MACOSX) 556 #if defined(OS_MACOSX)
509 SkColor icon_color = nearby_text_color; 557 SkColor icon_color = nearby_text_color;
510 #else 558 #else
511 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); 559 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color);
512 #endif 560 #endif
513 561
514 return gfx::Image( 562 return gfx::Image(
(...skipping 25 matching lines...) Expand all
540 CONTENT_SETTINGS_TYPE_PLUGINS)); 588 CONTENT_SETTINGS_TYPE_PLUGINS));
541 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( 589 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>(
542 CONTENT_SETTINGS_TYPE_POPUPS)); 590 CONTENT_SETTINGS_TYPE_POPUPS));
543 result.push_back(base::MakeUnique<ContentSettingGeolocationImageModel>()); 591 result.push_back(base::MakeUnique<ContentSettingGeolocationImageModel>());
544 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( 592 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>(
545 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); 593 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT));
546 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); 594 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>());
547 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); 595 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>());
548 result.push_back( 596 result.push_back(
549 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); 597 base::MakeUnique<ContentSettingSubresourceFilterImageModel>());
550 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( 598 result.push_back(base::MakeUnique<ContentSettingDownloadsImageModel>());
551 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS));
552 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); 599 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>());
553 600
554 return result; 601 return result;
555 } 602 }
556 603
557 #if defined(OS_MACOSX) 604 #if defined(OS_MACOSX)
558 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( 605 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged(
559 content::WebContents* web_contents) { 606 content::WebContents* web_contents) {
560 gfx::VectorIconId old_icon = icon_id_; 607 gfx::VectorIconId old_icon = icon_id_;
561 gfx::VectorIconId old_badge_icon = icon_badge_id_; 608 gfx::VectorIconId old_badge_icon = icon_badge_id_;
562 UpdateFromWebContents(web_contents); 609 UpdateFromWebContents(web_contents);
563 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; 610 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_;
564 } 611 }
565 #endif 612 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698