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/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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 class ContentSettingMIDISysExImageModel | 92 class ContentSettingMIDISysExImageModel |
| 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 private: | 98 private: |
| 96 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); | 99 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
| 97 }; | 100 }; |
| 98 | 101 |
| 102 class ContentSettingDownloadsImageModel | |
| 103 : public ContentSettingSimpleImageModel { | |
| 104 public: | |
| 105 ContentSettingDownloadsImageModel(); | |
| 106 | |
| 107 void UpdateFromWebContents(WebContents* web_contents) override; | |
| 108 | |
| 109 private: | |
| 110 DISALLOW_COPY_AND_ASSIGN(ContentSettingDownloadsImageModel); | |
| 111 }; | |
| 112 | |
| 99 namespace { | 113 namespace { |
| 100 | 114 |
| 101 struct ContentSettingsImageDetails { | 115 struct ContentSettingsImageDetails { |
| 102 ContentSettingsType type; | 116 ContentSettingsType type; |
| 103 gfx::VectorIconId icon_id; | 117 gfx::VectorIconId icon_id; |
| 104 int blocked_tooltip_id; | 118 int blocked_tooltip_id; |
| 105 int blocked_explanatory_text_id; | 119 int blocked_explanatory_text_id; |
| 106 int accessed_tooltip_id; | 120 int accessed_tooltip_id; |
| 107 }; | 121 }; |
| 108 | 122 |
| 109 const ContentSettingsImageDetails kImageDetails[] = { | 123 const ContentSettingsImageDetails kImageDetails[] = { |
| 110 {CONTENT_SETTINGS_TYPE_COOKIES, gfx::VectorIconId::COOKIE, | 124 {CONTENT_SETTINGS_TYPE_COOKIES, gfx::VectorIconId::COOKIE, |
| 111 IDS_BLOCKED_COOKIES_TITLE, 0, IDS_ACCESSED_COOKIES_TITLE}, | 125 IDS_BLOCKED_COOKIES_TITLE, 0, IDS_ACCESSED_COOKIES_TITLE}, |
| 112 {CONTENT_SETTINGS_TYPE_IMAGES, gfx::VectorIconId::IMAGE, | 126 {CONTENT_SETTINGS_TYPE_IMAGES, gfx::VectorIconId::IMAGE, |
| 113 IDS_BLOCKED_IMAGES_TITLE, 0, 0}, | 127 IDS_BLOCKED_IMAGES_TITLE, 0, 0}, |
| 114 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, gfx::VectorIconId::CODE, | 128 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, gfx::VectorIconId::CODE, |
| 115 IDS_BLOCKED_JAVASCRIPT_TITLE, 0, 0}, | 129 IDS_BLOCKED_JAVASCRIPT_TITLE, 0, 0}, |
| 116 {CONTENT_SETTINGS_TYPE_PLUGINS, gfx::VectorIconId::EXTENSION, | 130 {CONTENT_SETTINGS_TYPE_PLUGINS, gfx::VectorIconId::EXTENSION, |
| 117 IDS_BLOCKED_PLUGINS_MESSAGE, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT, 0}, | 131 IDS_BLOCKED_PLUGINS_MESSAGE, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT, 0}, |
| 118 {CONTENT_SETTINGS_TYPE_POPUPS, gfx::VectorIconId::WEB, | 132 {CONTENT_SETTINGS_TYPE_POPUPS, gfx::VectorIconId::WEB, |
| 119 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, | 133 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, |
| 120 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, | 134 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, |
| 121 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, | 135 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, |
| 122 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, | 136 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, |
| 123 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 137 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
| 124 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
| 125 gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE, | |
| 126 IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE}, | |
| 127 }; | 138 }; |
| 128 | 139 |
| 129 // The ordering of the models here influences the order in which icons are | 140 // The ordering of the models here influences the order in which icons are |
| 130 // shown in the omnibox. | 141 // shown in the omnibox. |
| 131 constexpr ContentSettingsType kContentTypeIconOrder[] = { | 142 constexpr ContentSettingsType kContentTypeIconOrder[] = { |
| 132 CONTENT_SETTINGS_TYPE_COOKIES, | 143 CONTENT_SETTINGS_TYPE_COOKIES, |
| 133 CONTENT_SETTINGS_TYPE_IMAGES, | 144 CONTENT_SETTINGS_TYPE_IMAGES, |
| 134 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 145 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 135 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 146 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 136 CONTENT_SETTINGS_TYPE_PLUGINS, | 147 CONTENT_SETTINGS_TYPE_PLUGINS, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 ContentSettingsType content_settings_type) { | 213 ContentSettingsType content_settings_type) { |
| 203 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 214 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 204 return base::MakeUnique<ContentSettingGeolocationImageModel>(); | 215 return base::MakeUnique<ContentSettingGeolocationImageModel>(); |
| 205 | 216 |
| 206 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) | 217 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) |
| 207 return base::MakeUnique<ContentSettingRPHImageModel>(); | 218 return base::MakeUnique<ContentSettingRPHImageModel>(); |
| 208 | 219 |
| 209 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) | 220 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) |
| 210 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); | 221 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
| 211 | 222 |
| 223 if (content_settings_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) | |
| 224 return base::MakeUnique<ContentSettingDownloadsImageModel>(); | |
| 225 | |
| 212 return base::MakeUnique<ContentSettingBlockedImageModel>( | 226 return base::MakeUnique<ContentSettingBlockedImageModel>( |
| 213 content_settings_type); | 227 content_settings_type); |
| 214 } | 228 } |
| 215 | 229 |
| 216 // Generic blocked content settings -------------------------------------------- | 230 // Generic blocked content settings -------------------------------------------- |
| 217 | 231 |
| 218 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( | 232 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( |
| 219 ContentSettingsType content_type) | 233 ContentSettingsType content_type) |
| 220 : ContentSettingSimpleImageModel(content_type) { | 234 : ContentSettingSimpleImageModel(content_type) { |
| 221 } | 235 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 bool allowed = | 526 bool allowed = |
| 513 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 527 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 514 set_icon_by_vector_id(gfx::VectorIconId::MIDI, | 528 set_icon_by_vector_id(gfx::VectorIconId::MIDI, |
| 515 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE | 529 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE |
| 516 : gfx::VectorIconId::BLOCKED_BADGE); | 530 : gfx::VectorIconId::BLOCKED_BADGE); |
| 517 set_tooltip(l10n_util::GetStringUTF16(allowed | 531 set_tooltip(l10n_util::GetStringUTF16(allowed |
| 518 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP | 532 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP |
| 519 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 533 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
| 520 } | 534 } |
| 521 | 535 |
| 536 // Automatic downloads --------------------------------------------------------- | |
| 537 | |
| 538 ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel() | |
| 539 : ContentSettingSimpleImageModel( | |
| 540 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {} | |
| 541 | |
| 542 void ContentSettingDownloadsImageModel::UpdateFromWebContents( | |
| 543 WebContents* web_contents) { | |
| 544 set_visible(false); | |
| 545 if (!web_contents) | |
| 546 return; | |
| 547 | |
| 548 DownloadRequestLimiter* download_request_limiter = | |
| 549 g_browser_process->download_request_limiter(); | |
| 550 | |
| 551 // DownloadRequestLimiter can be absent in unit_tests. | |
| 552 if (!download_request_limiter) | |
| 553 return; | |
|
alshabalin
2017/02/28 10:31:31
Also added this check for the sake of unit_tests w
| |
| 554 | |
| 555 switch (download_request_limiter->GetDownloadStatus(web_contents)) { | |
| 556 case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS: | |
| 557 set_visible(true); | |
| 558 set_icon_by_vector_id(gfx::VectorIconId::FILE_DOWNLOAD, | |
| 559 gfx::VectorIconId::VECTOR_ICON_NONE); | |
| 560 set_explanatory_string_id(0); | |
| 561 set_tooltip(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE)); | |
| 562 return; | |
| 563 case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED: | |
| 564 set_visible(true); | |
| 565 set_icon_by_vector_id(gfx::VectorIconId::FILE_DOWNLOAD, | |
| 566 gfx::VectorIconId::BLOCKED_BADGE); | |
| 567 set_explanatory_string_id(IDS_BLOCKED_DOWNLOADS_EXPLANATION); | |
| 568 set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE)); | |
| 569 return; | |
| 570 default: | |
| 571 // No need to show icon otherwise. | |
| 572 return; | |
| 573 } | |
| 574 } | |
| 575 | |
| 522 // Base class ------------------------------------------------------------------ | 576 // Base class ------------------------------------------------------------------ |
| 523 | 577 |
| 524 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { | 578 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { |
| 525 #if defined(OS_MACOSX) | 579 #if defined(OS_MACOSX) |
| 526 SkColor icon_color = nearby_text_color; | 580 SkColor icon_color = nearby_text_color; |
| 527 #else | 581 #else |
| 528 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); | 582 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); |
| 529 #endif | 583 #endif |
| 530 | 584 |
| 531 return gfx::Image( | 585 return gfx::Image( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 554 break; | 608 break; |
| 555 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 609 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 556 model = base::MakeUnique<ContentSettingMediaImageModel>(); | 610 model = base::MakeUnique<ContentSettingMediaImageModel>(); |
| 557 break; | 611 break; |
| 558 case CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER: | 612 case CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER: |
| 559 model = base::MakeUnique<ContentSettingSubresourceFilterImageModel>(); | 613 model = base::MakeUnique<ContentSettingSubresourceFilterImageModel>(); |
| 560 break; | 614 break; |
| 561 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 615 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 562 model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); | 616 model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
| 563 break; | 617 break; |
| 618 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: | |
| 619 model = base::MakeUnique<ContentSettingDownloadsImageModel>(); | |
| 620 break; | |
| 564 default: | 621 default: |
| 565 // All other content settings types use ContentSettingBlockedImageModel. | 622 // All other content settings types use ContentSettingBlockedImageModel. |
| 566 model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); | 623 model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); |
| 567 break; | 624 break; |
| 568 } | 625 } |
| 569 result.push_back(std::move(model)); | 626 result.push_back(std::move(model)); |
| 570 } | 627 } |
| 571 return result; | 628 return result; |
| 572 } | 629 } |
| 573 | 630 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 586 | 643 |
| 587 #if defined(OS_MACOSX) | 644 #if defined(OS_MACOSX) |
| 588 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 645 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
| 589 content::WebContents* web_contents) { | 646 content::WebContents* web_contents) { |
| 590 gfx::VectorIconId old_icon = icon_id_; | 647 gfx::VectorIconId old_icon = icon_id_; |
| 591 gfx::VectorIconId old_badge_icon = icon_badge_id_; | 648 gfx::VectorIconId old_badge_icon = icon_badge_id_; |
| 592 UpdateFromWebContents(web_contents); | 649 UpdateFromWebContents(web_contents); |
| 593 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; | 650 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; |
| 594 } | 651 } |
| 595 #endif | 652 #endif |
| OLD | NEW |