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" |
| (...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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 return gfx::Image( | 513 return gfx::Image( |
| 515 gfx::CreateVectorIconWithBadge(icon_id_, 16, icon_color, icon_badge_id_)); | 514 gfx::CreateVectorIconWithBadge(icon_id_, 16, icon_color, icon_badge_id_)); |
| 516 } | 515 } |
| 517 | 516 |
| 518 ContentSettingImageModel::ContentSettingImageModel() | 517 ContentSettingImageModel::ContentSettingImageModel() |
| 519 : is_visible_(false), | 518 : is_visible_(false), |
| 520 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 519 icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 521 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 520 icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 522 explanatory_string_id_(0) {} | 521 explanatory_string_id_(0) {} |
| 523 | 522 |
| 523 // The ordering of the models here influences the order in which icons are | |
| 524 // shown in the omnibox. | |
| 525 static constexpr ContentSettingsType content_types[] = { | |
|
tapted
2017/02/07 01:23:31
nit: Might be your C roots showing again ;). It's
Peter Kasting
2017/02/07 01:34:06
Don't generalize too hard -- see e.g. https://grou
| |
| 526 CONTENT_SETTINGS_TYPE_COOKIES, | |
| 527 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 528 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | |
| 529 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | |
| 530 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 531 CONTENT_SETTINGS_TYPE_POPUPS, | |
| 532 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
| 533 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | |
| 534 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, | |
| 535 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
| 536 CONTENT_SETTINGS_TYPE_DEFAULT, | |
|
tapted
2017/02/07 01:23:31
This at least needs a comment, but.. although I us
kylix_rd
2017/02/07 18:25:21
I started down this path, but it's going to requir
| |
| 537 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
| 538 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | |
| 539 }; | |
| 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; |
| 528 | 545 |
| 529 // The ordering of the models here influences the order in which icons are | 546 for (auto content_type : content_types) { |
|
tapted
2017/02/07 01:23:31
(with the above, my preference would be auto -> in
| |
| 530 // shown in the omnibox. | 547 switch (content_type) { |
| 531 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 548 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 532 CONTENT_SETTINGS_TYPE_COOKIES)); | 549 result.push_back( |
| 533 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 550 base::MakeUnique<ContentSettingGeolocationImageModel>()); |
| 534 CONTENT_SETTINGS_TYPE_IMAGES)); | 551 break; |
| 535 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 552 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
| 536 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 553 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); |
| 537 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 554 break; |
| 538 CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); | 555 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| 539 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 556 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); |
| 540 CONTENT_SETTINGS_TYPE_PLUGINS)); | 557 break; |
| 541 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 558 case CONTENT_SETTINGS_TYPE_DEFAULT: |
| 542 CONTENT_SETTINGS_TYPE_POPUPS)); | 559 result.push_back( |
| 543 result.push_back(base::MakeUnique<ContentSettingGeolocationImageModel>()); | 560 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); |
| 544 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 561 break; |
| 545 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 562 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 546 result.push_back(base::MakeUnique<ContentSettingRPHImageModel>()); | 563 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); |
| 547 result.push_back(base::MakeUnique<ContentSettingMediaImageModel>()); | 564 break; |
| 548 result.push_back( | 565 default: |
| 549 base::MakeUnique<ContentSettingSubresourceFilterImageModel>()); | 566 result.push_back( |
|
tapted
2017/02/07 01:23:31
Comment here, e.g.
// All other content settings
kylix_rd
2017/02/07 18:25:21
Done.
| |
| 550 result.push_back(base::MakeUnique<ContentSettingBlockedImageModel>( | 567 base::MakeUnique<ContentSettingBlockedImageModel>(content_type)); |
| 551 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS)); | 568 break; |
| 552 result.push_back(base::MakeUnique<ContentSettingMIDISysExImageModel>()); | 569 } |
| 570 } | |
| 571 return result; | |
| 572 } | |
| 553 | 573 |
| 554 return result; | 574 // static |
| 575 size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting( | |
|
tapted
2017/02/07 01:23:31
I would actually just expose kContentTypeIconOrder
kylix_rd
2017/02/07 18:25:21
Hmmm... I think keeping it internal and private is
tapted
2017/02/08 00:31:49
Although this is likely true, I've never seen it u
| |
| 576 ContentSettingsType content_type) { | |
| 577 size_t result = 0; | |
| 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(content_types); ++i) { | |
| 581 if (content_type == content_types[i]) | |
| 582 return result; | |
| 583 ++result; | |
| 584 } | |
| 585 NOTREACHED(); | |
| 586 return ARRAYSIZE(content_types); | |
|
tapted
2017/02/07 01:23:31
ARRAYSIZE -> arraysize (I'm not sure where ARRAYSI
kylix_rd
2017/02/07 18:25:21
Done.
| |
| 555 } | 587 } |
| 556 | 588 |
| 557 #if defined(OS_MACOSX) | 589 #if defined(OS_MACOSX) |
| 558 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 590 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
| 559 content::WebContents* web_contents) { | 591 content::WebContents* web_contents) { |
| 560 gfx::VectorIconId old_icon = icon_id_; | 592 gfx::VectorIconId old_icon = icon_id_; |
| 561 gfx::VectorIconId old_badge_icon = icon_badge_id_; | 593 gfx::VectorIconId old_badge_icon = icon_badge_id_; |
| 562 UpdateFromWebContents(web_contents); | 594 UpdateFromWebContents(web_contents); |
| 563 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; | 595 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; |
| 564 } | 596 } |
| 565 #endif | 597 #endif |
| OLD | NEW |