| 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 | |
| 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 kContentTypeIconOrder[] = { |
| 132 CONTENT_SETTINGS_TYPE_COOKIES, |
| 133 CONTENT_SETTINGS_TYPE_IMAGES, |
| 134 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 135 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 136 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 137 CONTENT_SETTINGS_TYPE_POPUPS, |
| 138 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 139 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
| 140 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, |
| 141 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, // Note: also handles mic. |
| 142 CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, |
| 143 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 144 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 145 }; |
| 146 |
| 130 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { | 147 const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { |
| 131 for (const ContentSettingsImageDetails& image_details : kImageDetails) { | 148 for (const ContentSettingsImageDetails& image_details : kImageDetails) { |
| 132 if (image_details.type == type) | 149 if (image_details.type == type) |
| 133 return &image_details; | 150 return &image_details; |
| 134 } | 151 } |
| 135 return nullptr; | 152 return nullptr; |
| 136 } | 153 } |
| 137 | 154 |
| 138 } // namespace | 155 } // namespace |
| 139 | 156 |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 ContentSettingImageModel::ContentSettingImageModel() | 535 ContentSettingImageModel::ContentSettingImageModel() |
| 519 : is_visible_(false), | 536 : is_visible_(false), |
| 520 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 537 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 521 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 538 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 522 explanatory_string_id_(0) {} | 539 explanatory_string_id_(0) {} |
| 523 | 540 |
| 524 // static | 541 // static |
| 525 std::vector<std::unique_ptr<ContentSettingImageModel>> | 542 std::vector<std::unique_ptr<ContentSettingImageModel>> |
| 526 ContentSettingImageModel::GenerateContentSettingImageModels() { | 543 ContentSettingImageModel::GenerateContentSettingImageModels() { |
| 527 std::vector<std::unique_ptr<ContentSettingImageModel>> result; | 544 std::vector<std::unique_ptr<ContentSettingImageModel>> result; |
| 545 std::unique_ptr<ContentSettingImageModel> model; |
| 528 | 546 |
| 529 // The ordering of the models here influences the order in which icons are | 547 for (auto icon : kContentTypeIconOrder) { |
| 530 // shown in the omnibox. | 548 switch (icon) { |
| 531 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 549 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 532 CONTENT_SETTINGS_TYPE_COOKIES)); | 550 model = base::MakeUnique<ContentSettingGeolocationImageModel>(); |
| 533 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 551 break; |
| 534 CONTENT_SETTINGS_TYPE_IMAGES)); | 552 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
| 535 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 553 model = base::MakeUnique<ContentSettingRPHImageModel>(); |
| 536 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 554 break; |
| 537 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 555 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 538 CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); | 556 model = base::MakeUnique<ContentSettingMediaImageModel>(); |
| 539 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 557 break; |
| 540 CONTENT_SETTINGS_TYPE_PLUGINS)); | 558 case CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER: |
| 541 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 559 model = base::MakeUnique<ContentSettingSubresourceFilterImageModel>(); |
| 542 CONTENT_SETTINGS_TYPE_POPUPS)); | 560 break; |
| 543 result.push_back(base::MakeUnique<ContentSettingGeolocationImageModel>()); | 561 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 544 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 562 model = base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
| 545 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 563 break; |
| 546 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); | 564 default: |
| 547 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); | 565 // All other content settings types use ContentSettingBlockedImageModel. |
| 548 result.push_back( | 566 model = base::MakeUnique<ContentSettingBlockedImageModel>(icon); |
| 549 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); | 567 break; |
| 550 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 568 } |
| 551 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); | 569 result.push_back(std::move(model)); |
| 552 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); | 570 } |
| 571 return result; |
| 572 } |
| 553 | 573 |
| 554 return result; | 574 // static |
| 575 size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting( |
| 576 ContentSettingsType content_type) { |
| 577 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
| 578 content_type = CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; |
| 579 for (size_t i = 0; i < arraysize(kContentTypeIconOrder); ++i) { |
| 580 if (content_type == kContentTypeIconOrder[i]) |
| 581 return i; |
| 582 } |
| 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 |