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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 | 85 |
86 void UpdateFromWebContents(WebContents* web_contents) override; | 86 void UpdateFromWebContents(WebContents* web_contents) override; |
87 }; | 87 }; |
88 | 88 |
89 class ContentSettingMIDISysExImageModel | 89 class ContentSettingMIDISysExImageModel |
90 : public ContentSettingSimpleImageModel { | 90 : public ContentSettingSimpleImageModel { |
91 public: | 91 public: |
92 ContentSettingMIDISysExImageModel(); | 92 ContentSettingMIDISysExImageModel(); |
93 | 93 |
94 void UpdateFromWebContents(WebContents* web_contents) override; | 94 void UpdateFromWebContents(WebContents* web_contents) override; |
95 | 95 |
Peter Kasting
2017/02/15 01:14:00
Nit: Don't remove this
| |
96 private: | 96 private: |
97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); | 97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
98 }; | 98 }; |
99 | 99 |
100 namespace { | 100 namespace { |
101 | 101 |
102 struct ContentSettingsImageDetails { | 102 struct ContentSettingsImageDetails { |
103 ContentSettingsType type; | 103 ContentSettingsType type; |
104 gfx::VectorIconId icon_id; | 104 gfx::VectorIconId icon_id; |
105 int blocked_tooltip_id; | 105 int blocked_tooltip_id; |
(...skipping 14 matching lines...) Expand all Loading... | |
120 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, | 120 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, |
121 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, | 121 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, |
122 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, | 122 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, |
123 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, | 123 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, |
124 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 124 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
125 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 125 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
126 gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE, | 126 gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE, |
127 IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE}, | 127 IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE}, |
128 }; | 128 }; |
129 | 129 |
130 // The ordering of the models here influences the order in which icons are | |
131 // shown in the omnibox. | |
132 constexpr ContentSettingsType kContentTypeIconOrder[] = { | |
133 CONTENT_SETTINGS_TYPE_COOKIES, | |
134 CONTENT_SETTINGS_TYPE_IMAGES, | |
135 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
136 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
137 CONTENT_SETTINGS_TYPE_PLUGINS, | |
138 CONTENT_SETTINGS_TYPE_POPUPS, | |
139 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
140 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | |
141 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, | |
142 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, // Note: also does camera. | |
Peter Kasting
2017/02/13 23:10:50
Tiny nit: Since the actual icon this currently use
kylix_rd
2017/02/14 15:20:43
Done.
| |
143 CONTENT_SETTINGS_TYPE_DECEPTIVE_CONTENT, | |
144 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
145 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | |
146 }; | |
147 | |
130 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { | 148 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { |
131 for (const ContentSettingsImageDetails& image_details : kImageDetails) { | 149 for (const ContentSettingsImageDetails& image_details : kImageDetails) { |
132 if (image_details.type == type) | 150 if (image_details.type == type) |
133 return &image_details; | 151 return &image_details; |
134 } | 152 } |
135 return nullptr; | 153 return nullptr; |
136 } | 154 } |
137 | 155 |
138 } // namespace | 156 } // namespace |
139 | 157 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 ContentSettingImageModel::ContentSettingImageModel() | 536 ContentSettingImageModel::ContentSettingImageModel() |
519 : is_visible_(false), | 537 : is_visible_(false), |
520 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 538 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
521 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 539 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
522 explanatory_string_id_(0) {} | 540 explanatory_string_id_(0) {} |
523 | 541 |
524 // static | 542 // static |
525 std::vector<std::unique_ptr<ContentSettingImageModel>> | 543 std::vector<std::unique_ptr<ContentSettingImageModel>> |
526 ContentSettingImageModel::GenerateContentSettingImageModels() { | 544 ContentSettingImageModel::GenerateContentSettingImageModels() { |
527 std::vector<std::unique_ptr<ContentSettingImageModel>> result; | 545 std::vector<std::unique_ptr<ContentSettingImageModel>> result; |
546 std::unique_ptr<ContentSettingImageModel> model; | |
528 | 547 |
529 // The ordering of the models here influences the order in which icons are | 548 for (auto icon : kContentTypeIconOrder) { |
530 // shown in the omnibox. | 549 switch (icon) { |
531 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 550 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
532 CONTENT_SETTINGS_TYPE_COOKIES)); | 551 model = base::MakeUnique<ContentSettingGeolocationImageModel>(); |
533 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 552 break; |
534 CONTENT_SETTINGS_TYPE_IMAGES)); | 553 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
535 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 554 model = base::MakeUnique<ContentSettingRPHImageModel>(); |
536 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 555 break; |
537 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 556 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
538 CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); | 557 model = base::MakeUnique<ContentSettingMediaImageModel>(); |
539 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 558 break; |
540 CONTENT_SETTINGS_TYPE_PLUGINS)); | 559 case CONTENT_SETTINGS_TYPE_DECEPTIVE_CONTENT: |
541 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 560 model = base::MakeUnique<ContentSettingSubresourceFilterImageModel>(); |
542 CONTENT_SETTINGS_TYPE_POPUPS)); | 561 break; |
543 result.push_back(base::MakeUnique<ContentSettingGeolocationImageModel>()); | 562 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
544 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 563 model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
545 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 564 break; |
546 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); | 565 default: |
547 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); | 566 // All other content settings types use ContentSettingBlockedImageModel. |
548 result.push_back( | 567 model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); |
549 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); | 568 break; |
550 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 569 } |
551 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); | 570 result.push_back(std::move(model)); |
552 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); | 571 } |
572 return result; | |
573 } | |
553 | 574 |
554 return result; | 575 // static |
576 size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting( | |
577 ContentSettingsType content_type) { | |
578 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
579 content_type = CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC; | |
580 for (size_t i = 0; i < arraysize(kContentTypeIconOrder); ++i) | |
Peter Kasting
2017/02/13 23:10:50
Nit: {} since body is more than one physical line
kylix_rd
2017/02/14 15:20:43
Done.
| |
581 if (content_type == kContentTypeIconOrder[i]) | |
582 return i; | |
583 NOTREACHED(); | |
584 return arraysize(kContentTypeIconOrder); | |
555 } | 585 } |
556 | 586 |
557 #if defined(OS_MACOSX) | 587 #if defined(OS_MACOSX) |
558 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 588 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
559 content::WebContents* web_contents) { | 589 content::WebContents* web_contents) { |
560 gfx::VectorIconId old_icon = icon_id_; | 590 gfx::VectorIconId old_icon = icon_id_; |
561 gfx::VectorIconId old_badge_icon = icon_badge_id_; | 591 gfx::VectorIconId old_badge_icon = icon_badge_id_; |
562 UpdateFromWebContents(web_contents); | 592 UpdateFromWebContents(web_contents); |
563 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; | 593 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; |
564 } | 594 } |
565 #endif | 595 #endif |
OLD | NEW |