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 | |
Peter Kasting
2017/02/08 01:00:03
Nit: Don't remove this
kylix_rd
2017/02/10 22:47:48
Done.
| |
96 private: | 95 private: |
97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); | 96 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
98 }; | 97 }; |
99 | 98 |
100 namespace { | 99 namespace { |
101 | 100 |
102 struct ContentSettingsImageDetails { | 101 struct ContentSettingsImageDetails { |
103 ContentSettingsType type; | 102 ContentSettingsType type; |
104 gfx::VectorIconId icon_id; | 103 gfx::VectorIconId icon_id; |
105 int blocked_tooltip_id; | 104 int blocked_tooltip_id; |
(...skipping 14 matching lines...) Expand all Loading... | |
120 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, | 119 IDS_BLOCKED_POPUPS_TOOLTIP, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT, 0}, |
121 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, | 120 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, gfx::VectorIconId::MIXED_CONTENT, |
122 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, | 121 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT, 0, 0}, |
123 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, | 122 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, gfx::VectorIconId::EXTENSION, |
124 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 123 IDS_BLOCKED_PPAPI_BROKER_TITLE, 0, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
125 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 124 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
126 gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE, | 125 gfx::VectorIconId::FILE_DOWNLOAD, IDS_BLOCKED_DOWNLOAD_TITLE, |
127 IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE}, | 126 IDS_BLOCKED_DOWNLOADS_EXPLANATION, IDS_ALLOWED_DOWNLOAD_TITLE}, |
128 }; | 127 }; |
129 | 128 |
129 // The ordering of the models here influences the order in which icons are | |
130 // shown in the omnibox. | |
131 constexpr ContentSettingsType kDeceptiveContentModelId = | |
132 static_cast<ContentSettingsType>( | |
133 static_cast<int>(CONTENT_SETTINGS_TYPE_DEFAULT) - 1); | |
Peter Kasting
2017/02/08 01:00:03
This seems dangerous, because it's easy to reorder
| |
134 constexpr ContentSettingsType kContentTypeIconOrder[] = { | |
135 CONTENT_SETTINGS_TYPE_COOKIES, | |
136 CONTENT_SETTINGS_TYPE_IMAGES, | |
137 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
138 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
139 CONTENT_SETTINGS_TYPE_PLUGINS, | |
140 CONTENT_SETTINGS_TYPE_POPUPS, | |
141 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
142 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | |
143 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, | |
144 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, // Note: also does camera. | |
145 kDeceptiveContentModelId, | |
146 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
147 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | |
148 }; | |
149 | |
130 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { | 150 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { |
131 for (const ContentSettingsImageDetails& image_details : kImageDetails) { | 151 for (const ContentSettingsImageDetails& image_details : kImageDetails) { |
132 if (image_details.type == type) | 152 if (image_details.type == type) |
133 return &image_details; | 153 return &image_details; |
134 } | 154 } |
135 return nullptr; | 155 return nullptr; |
136 } | 156 } |
137 | 157 |
138 } // namespace | 158 } // namespace |
139 | 159 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 : is_visible_(false), | 539 : is_visible_(false), |
520 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 540 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
521 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 541 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
522 explanatory_string_id_(0) {} | 542 explanatory_string_id_(0) {} |
523 | 543 |
524 // static | 544 // static |
525 std::vector<std::unique_ptr<ContentSettingImageModel>> | 545 std::vector<std::unique_ptr<ContentSettingImageModel>> |
526 ContentSettingImageModel::GenerateContentSettingImageModels() { | 546 ContentSettingImageModel::GenerateContentSettingImageModels() { |
527 std::vector<std::unique_ptr<ContentSettingImageModel>> result; | 547 std::vector<std::unique_ptr<ContentSettingImageModel>> result; |
528 | 548 |
529 // The ordering of the models here influences the order in which icons are | 549 for (auto icon : kContentTypeIconOrder) { |
530 // shown in the omnibox. | 550 switch (icon) { |
531 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 551 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
532 CONTENT_SETTINGS_TYPE_COOKIES)); | 552 result.push_back( |
Peter Kasting
2017/02/08 01:00:03
Nit: Might make sense to do:
std::unique_ptr<
kylix_rd
2017/02/10 22:47:48
Done.
| |
533 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 553 base::MakeUnique<ContentSettingGeolocationImageModel>()); |
534 CONTENT_SETTINGS_TYPE_IMAGES)); | 554 break; |
535 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 555 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
536 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 556 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); |
537 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 557 break; |
538 CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); | 558 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
539 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 559 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); |
540 CONTENT_SETTINGS_TYPE_PLUGINS)); | 560 break; |
541 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 561 case kDeceptiveContentModelId: |
542 CONTENT_SETTINGS_TYPE_POPUPS)); | 562 result.push_back( |
543 result.push_back(base::MakeUnique<ContentSettingGeolocationImageModel>()); | 563 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); |
544 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 564 break; |
545 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 565 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
546 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); | 566 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); |
547 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); | 567 break; |
548 result.push_back( | 568 default: |
549 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); | 569 // All other content settins types use ContentSettingBlockedImageModel |
tapted
2017/02/08 00:31:49
settins -> settings (and full stop at end)
| |
550 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 570 result.push_back( |
551 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); | 571 base::MakeUnique<ContentSettingBlockedImageModel>(icon)); |
tapted
2017/02/08 00:31:49
my preference would be a static cast here. Casting
Peter Kasting
2017/02/08 01:00:03
Casting what? |icon| is already of the type the C
tapted
2017/02/08 01:20:19
An option would be to declare kContentTypeIconOrde
Peter Kasting
2017/02/08 01:26:19
I think we're OK if the new value is -2 -- that wo
kylix_rd
2017/02/10 22:47:48
Done. Added value to the enum.
| |
552 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); | 572 break; |
573 } | |
574 } | |
575 return result; | |
576 } | |
553 | 577 |
554 return result; | 578 // static |
579 size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting( | |
580 ContentSettingsType content_type) { | |
581 size_t result = 0; | |
Peter Kasting
2017/02/08 01:00:03
Why does this temp exist? Why not just return |i|
kylix_rd
2017/02/10 22:47:48
Done.
| |
582 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
583 content_type = CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC; | |
584 for (size_t i = 0; i < arraysize(kContentTypeIconOrder); ++i) { | |
585 if (content_type == kContentTypeIconOrder[i]) | |
586 return result; | |
587 ++result; | |
588 } | |
589 NOTREACHED(); | |
590 return arraysize(kContentTypeIconOrder); | |
555 } | 591 } |
556 | 592 |
557 #if defined(OS_MACOSX) | 593 #if defined(OS_MACOSX) |
558 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 594 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
559 content::WebContents* web_contents) { | 595 content::WebContents* web_contents) { |
560 gfx::VectorIconId old_icon = icon_id_; | 596 gfx::VectorIconId old_icon = icon_id_; |
561 gfx::VectorIconId old_badge_icon = icon_badge_id_; | 597 gfx::VectorIconId old_badge_icon = icon_badge_id_; |
562 UpdateFromWebContents(web_contents); | 598 UpdateFromWebContents(web_contents); |
563 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; | 599 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; |
564 } | 600 } |
565 #endif | 601 #endif |
OLD | NEW |