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/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/app/vector_icons/vector_icons.h" | 11 #include "chrome/app/vector_icons/vector_icons.h" |
| 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 15 #include "chrome/browser/download/download_request_limiter.h" |
14 #include "chrome/browser/plugins/plugin_utils.h" | 16 #include "chrome/browser/plugins/plugin_utils.h" |
15 #include "chrome/browser/prerender/prerender_manager.h" | 17 #include "chrome/browser/prerender/prerender_manager.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_features.h" | 19 #include "chrome/common/chrome_features.h" |
18 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_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/gfx/color_palette.h" | 25 #include "ui/gfx/color_palette.h" |
24 #include "ui/gfx/color_utils.h" | 26 #include "ui/gfx/color_utils.h" |
25 #include "ui/gfx/paint_vector_icon.h" | 27 #include "ui/gfx/paint_vector_icon.h" |
26 #include "ui/vector_icons/vector_icons.h" | 28 #include "ui/vector_icons/vector_icons.h" |
27 | 29 |
28 using content::WebContents; | 30 using content::WebContents; |
29 | 31 |
30 // The image models hierarchy: | 32 // The image models hierarchy: |
31 // | 33 // |
32 // ContentSettingImageModel - base class | 34 // ContentSettingImageModel - base class |
33 // ContentSettingSimpleImageModel - single content setting | 35 // ContentSettingSimpleImageModel - single content setting |
34 // ContentSettingBlockedImageModel - generic blocked setting | 36 // ContentSettingBlockedImageModel - generic blocked setting |
35 // ContentSettingGeolocationImageModel - geolocation | 37 // ContentSettingGeolocationImageModel - geolocation |
36 // ContentSettingRPHImageModel - protocol handlers | 38 // ContentSettingRPHImageModel - protocol handlers |
37 // ContentSettingMIDISysExImageModel - midi sysex | 39 // ContentSettingMIDISysExImageModel - midi sysex |
| 40 // ContentSettingDownloadsImageModel - automatic downloads |
38 // ContentSettingMediaImageModel - media | 41 // ContentSettingMediaImageModel - media |
39 // ContentSettingSubresourceFilterImageModel - deceptive content | 42 // ContentSettingSubresourceFilterImageModel - deceptive content |
40 | 43 |
41 class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { | 44 class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { |
42 public: | 45 public: |
43 explicit ContentSettingBlockedImageModel(ContentSettingsType content_type); | 46 explicit ContentSettingBlockedImageModel(ContentSettingsType content_type); |
44 | 47 |
45 void UpdateFromWebContents(WebContents* web_contents) override; | 48 void UpdateFromWebContents(WebContents* web_contents) override; |
46 | 49 |
47 private: | 50 private: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 class ContentSettingMIDISysExImageModel | 91 class ContentSettingMIDISysExImageModel |
89 : public ContentSettingSimpleImageModel { | 92 : public ContentSettingSimpleImageModel { |
90 public: | 93 public: |
91 ContentSettingMIDISysExImageModel(); | 94 ContentSettingMIDISysExImageModel(); |
92 | 95 |
93 void UpdateFromWebContents(WebContents* web_contents) override; | 96 void UpdateFromWebContents(WebContents* web_contents) override; |
94 private: | 97 private: |
95 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); | 98 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
96 }; | 99 }; |
97 | 100 |
| 101 class ContentSettingDownloadsImageModel |
| 102 : public ContentSettingSimpleImageModel { |
| 103 public: |
| 104 ContentSettingDownloadsImageModel(); |
| 105 |
| 106 void UpdateFromWebContents(WebContents* web_contents) override; |
| 107 |
| 108 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel); |
| 110 }; |
| 111 |
98 namespace { | 112 namespace { |
99 | 113 |
100 struct ContentSettingsImageDetails { | 114 struct ContentSettingsImageDetails { |
101 ContentSettingsType type; | 115 ContentSettingsType type; |
102 const gfx::VectorIcon& icon; | 116 const gfx::VectorIcon& icon; |
103 int blocked_tooltip_id; | 117 int blocked_tooltip_id; |
104 int blocked_explanatory_text_id; | 118 int blocked_explanatory_text_id; |
105 int accessed_tooltip_id; | 119 int accessed_tooltip_id; |
106 }; | 120 }; |
107 | 121 |
108 const ContentSettingsImageDetails kImageDetails[] = { | 122 const ContentSettingsImageDetails kImageDetails[] = { |
109 {CONTENT_SETTINGS_TYPE_COOKIES, kCookieIcon, IDS_BLOCKED_COOKIES_TITLE, 0, | 123 {CONTENT_SETTINGS_TYPE_COOKIES, kCookieIcon, IDS_BLOCKED_COOKIES_TITLE, 0, |
110 IDS_ACCESSED_COOKIES_TITLE}, | 124 IDS_ACCESSED_COOKIES_TITLE}, |
111 {CONTENT_SETTINGS_TYPE_IMAGES, kImageIcon, IDS_BLOCKED_IMAGES_TITLE, 0, 0}, | 125 {CONTENT_SETTINGS_TYPE_IMAGES, kImageIcon, IDS_BLOCKED_IMAGES_TITLE, 0, 0}, |
112 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, kCodeIcon, IDS_BLOCKED_JAVASCRIPT_TITLE, | 126 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, kCodeIcon, IDS_BLOCKED_JAVASCRIPT_TITLE, |
113 0, 0}, | 127 0, 0}, |
114 {CONTENT_SETTINGS_TYPE_PLUGINS, kExtensionIcon, IDS_BLOCKED_PLUGINS_MESSAGE, | 128 {CONTENT_SETTINGS_TYPE_PLUGINS, kExtensionIcon, IDS_BLOCKED_PLUGINS_MESSAGE, |
115 IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT, 0}, | 129 IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT, 0}, |
116 {CONTENT_SETTINGS_TYPE_POPUPS, kWebIcon, IDS_BLOCKED_POPUPS_TOOLTIP, | 130 {CONTENT_SETTINGS_TYPE_POPUPS, kWebIcon, IDS_BLOCKED_POPUPS_TOOLTIP, |
117 IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, | 131 IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, |
118 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, kMixedContentIcon, | 132 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, kMixedContentIcon, |
119 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, | 133 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, |
120 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, kExtensionIcon, | 134 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, kExtensionIcon, |
121 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 135 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
122 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, kFileDownloadIcon, | |
123 IDS_BLOCKED_DOWNLOAD_TITLE, IDS_BLOCKED_DOWNLOADS_EXPLANATION, | |
124 IDS_ALLOWED_DOWNLOAD_TITLE}, | |
125 }; | 136 }; |
126 | 137 |
127 // The ordering of the models here influences the order in which icons are | 138 // The ordering of the models here influences the order in which icons are |
128 // shown in the omnibox. | 139 // shown in the omnibox. |
129 constexpr ContentSettingsType kContentTypeIconOrder[] = { | 140 constexpr ContentSettingsType kContentTypeIconOrder[] = { |
130 CONTENT_SETTINGS_TYPE_COOKIES, | 141 CONTENT_SETTINGS_TYPE_COOKIES, |
131 CONTENT_SETTINGS_TYPE_IMAGES, | 142 CONTENT_SETTINGS_TYPE_IMAGES, |
132 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 143 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
133 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 144 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
134 CONTENT_SETTINGS_TYPE_PLUGINS, | 145 CONTENT_SETTINGS_TYPE_PLUGINS, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 ContentSettingsType content_settings_type) { | 211 ContentSettingsType content_settings_type) { |
201 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 212 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
202 return base::MakeUnique<ContentSettingGeolocationImageModel>(); | 213 return base::MakeUnique<ContentSettingGeolocationImageModel>(); |
203 | 214 |
204 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) | 215 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) |
205 return base::MakeUnique<ContentSettingRPHImageModel>(); | 216 return base::MakeUnique<ContentSettingRPHImageModel>(); |
206 | 217 |
207 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) | 218 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) |
208 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); | 219 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
209 | 220 |
| 221 if (content_settings_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) |
| 222 return base::MakeUnique<ContentSettingDownloadsImageModel>(); |
| 223 |
210 return base::MakeUnique<ContentSettingBlockedImageModel>( | 224 return base::MakeUnique<ContentSettingBlockedImageModel>( |
211 content_settings_type); | 225 content_settings_type); |
212 } | 226 } |
213 | 227 |
214 // Generic blocked content settings -------------------------------------------- | 228 // Generic blocked content settings -------------------------------------------- |
215 | 229 |
216 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( | 230 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( |
217 ContentSettingsType content_type) | 231 ContentSettingsType content_type) |
218 : ContentSettingSimpleImageModel(content_type) { | 232 : ContentSettingSimpleImageModel(content_type) { |
219 } | 233 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 unsigned int state_flags = 0; | 516 unsigned int state_flags = 0; |
503 usages_state.GetDetailedInfo(nullptr, &state_flags); | 517 usages_state.GetDetailedInfo(nullptr, &state_flags); |
504 bool allowed = | 518 bool allowed = |
505 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 519 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
506 set_icon(ui::kMidiIcon, allowed ? gfx::kNoneIcon : kBlockedBadgeIcon); | 520 set_icon(ui::kMidiIcon, allowed ? gfx::kNoneIcon : kBlockedBadgeIcon); |
507 set_tooltip(l10n_util::GetStringUTF16(allowed | 521 set_tooltip(l10n_util::GetStringUTF16(allowed |
508 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP | 522 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP |
509 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 523 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
510 } | 524 } |
511 | 525 |
| 526 // Automatic downloads --------------------------------------------------------- |
| 527 |
| 528 ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel() |
| 529 : ContentSettingSimpleImageModel( |
| 530 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {} |
| 531 |
| 532 void ContentSettingDownloadsImageModel::UpdateFromWebContents( |
| 533 WebContents* web_contents) { |
| 534 set_visible(false); |
| 535 if (!web_contents) |
| 536 return; |
| 537 |
| 538 DownloadRequestLimiter* download_request_limiter = |
| 539 g_browser_process->download_request_limiter(); |
| 540 |
| 541 // DownloadRequestLimiter can be absent in unit_tests. |
| 542 if (!download_request_limiter) |
| 543 return; |
| 544 |
| 545 switch (download_request_limiter->GetDownloadStatus(web_contents)) { |
| 546 case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS: |
| 547 set_visible(true); |
| 548 set_icon(kFileDownloadIcon, gfx::kNoneIcon); |
| 549 set_explanatory_string_id(0); |
| 550 set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE)); |
| 551 return; |
| 552 case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED: |
| 553 set_visible(true); |
| 554 set_icon(kFileDownloadIcon, kBlockedBadgeIcon); |
| 555 set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION); |
| 556 set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE)); |
| 557 return; |
| 558 default: |
| 559 // No need to show icon otherwise. |
| 560 return; |
| 561 } |
| 562 } |
| 563 |
512 // Base class ------------------------------------------------------------------ | 564 // Base class ------------------------------------------------------------------ |
513 | 565 |
514 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { | 566 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { |
515 #if defined(OS_MACOSX) | 567 #if defined(OS_MACOSX) |
516 SkColor icon_color = nearby_text_color; | 568 SkColor icon_color = nearby_text_color; |
517 #else | 569 #else |
518 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); | 570 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); |
519 #endif | 571 #endif |
520 | 572 |
521 return gfx::Image( | 573 return gfx::Image( |
(...skipping 22 matching lines...) Expand all Loading... |
544 break; | 596 break; |
545 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 597 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
546 model = base::MakeUnique<ContentSettingMediaImageModel>(); | 598 model = base::MakeUnique<ContentSettingMediaImageModel>(); |
547 break; | 599 break; |
548 case CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER: | 600 case CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER: |
549 model = base::MakeUnique<ContentSettingSubresourceFilterImageModel>(); | 601 model = base::MakeUnique<ContentSettingSubresourceFilterImageModel>(); |
550 break; | 602 break; |
551 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 603 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
552 model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); | 604 model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
553 break; | 605 break; |
| 606 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: |
| 607 model = base::MakeUnique<ContentSettingDownloadsImageModel>(); |
| 608 break; |
554 default: | 609 default: |
555 // All other content settings types use ContentSettingBlockedImageModel. | 610 // All other content settings types use ContentSettingBlockedImageModel. |
556 model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); | 611 model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); |
557 break; | 612 break; |
558 } | 613 } |
559 result.push_back(std::move(model)); | 614 result.push_back(std::move(model)); |
560 } | 615 } |
561 return result; | 616 return result; |
562 } | 617 } |
563 | 618 |
(...skipping 12 matching lines...) Expand all Loading... |
576 | 631 |
577 #if defined(OS_MACOSX) | 632 #if defined(OS_MACOSX) |
578 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 633 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
579 content::WebContents* web_contents) { | 634 content::WebContents* web_contents) { |
580 const gfx::VectorIcon* old_icon = icon_; | 635 const gfx::VectorIcon* old_icon = icon_; |
581 const gfx::VectorIcon* old_badge_icon = icon_badge_; | 636 const gfx::VectorIcon* old_badge_icon = icon_badge_; |
582 UpdateFromWebContents(web_contents); | 637 UpdateFromWebContents(web_contents); |
583 return old_icon != icon_ && old_badge_icon != icon_badge_; | 638 return old_icon != icon_ && old_badge_icon != icon_badge_; |
584 } | 639 } |
585 #endif | 640 #endif |
OLD | NEW |