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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
96 private: | 96 private: |
97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); | 97 DISALLOW_COPY_AND_ASSIGN(ContentSettingMIDISysExImageModel); |
98 }; | 98 }; |
99 | 99 |
| 100 class ContentSettingSensorImageModel : public ContentSettingSimpleImageModel { |
| 101 public: |
| 102 ContentSettingSensorImageModel(); |
| 103 |
| 104 void UpdateFromWebContents(WebContents* web_contents) override; |
| 105 |
| 106 private: |
| 107 DISALLOW_COPY_AND_ASSIGN(ContentSettingSensorImageModel); |
| 108 }; |
| 109 |
100 namespace { | 110 namespace { |
101 | 111 |
102 struct ContentSettingsImageDetails { | 112 struct ContentSettingsImageDetails { |
103 ContentSettingsType type; | 113 ContentSettingsType type; |
104 gfx::VectorIconId icon_id; | 114 gfx::VectorIconId icon_id; |
105 int blocked_tooltip_id; | 115 int blocked_tooltip_id; |
106 int blocked_explanatory_text_id; | 116 int blocked_explanatory_text_id; |
107 int accessed_tooltip_id; | 117 int accessed_tooltip_id; |
108 }; | 118 }; |
109 | 119 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 ContentSettingsType content_settings_type) { | 195 ContentSettingsType content_settings_type) { |
186 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | 196 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
187 return base::MakeUnique<ContentSettingGeolocationImageModel>(); | 197 return base::MakeUnique<ContentSettingGeolocationImageModel>(); |
188 | 198 |
189 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) | 199 if (content_settings_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) |
190 return base::MakeUnique<ContentSettingRPHImageModel>(); | 200 return base::MakeUnique<ContentSettingRPHImageModel>(); |
191 | 201 |
192 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) | 202 if (content_settings_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) |
193 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); | 203 return base::MakeUnique<ContentSettingMIDISysExImageModel>(); |
194 | 204 |
| 205 if (content_settings_type == CONTENT_SETTINGS_TYPE_SENSORS) |
| 206 return base::MakeUnique<ContentSettingSensorImageModel>(); |
| 207 |
195 return base::MakeUnique<ContentSettingBlockedImageModel>( | 208 return base::MakeUnique<ContentSettingBlockedImageModel>( |
196 content_settings_type); | 209 content_settings_type); |
197 } | 210 } |
198 | 211 |
199 // Generic blocked content settings -------------------------------------------- | 212 // Generic blocked content settings -------------------------------------------- |
200 | 213 |
201 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( | 214 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( |
202 ContentSettingsType content_type) | 215 ContentSettingsType content_type) |
203 : ContentSettingSimpleImageModel(content_type) { | 216 : ContentSettingSimpleImageModel(content_type) { |
204 } | 217 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 bool allowed = | 506 bool allowed = |
494 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 507 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
495 set_icon_by_vector_id(gfx::VectorIconId::MIDI, | 508 set_icon_by_vector_id(gfx::VectorIconId::MIDI, |
496 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE | 509 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE |
497 : gfx::VectorIconId::BLOCKED_BADGE); | 510 : gfx::VectorIconId::BLOCKED_BADGE); |
498 set_tooltip(l10n_util::GetStringUTF16(allowed | 511 set_tooltip(l10n_util::GetStringUTF16(allowed |
499 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP | 512 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP |
500 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 513 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
501 } | 514 } |
502 | 515 |
| 516 // Sensors ------------------------------------------------------------------ |
| 517 |
| 518 ContentSettingSensorImageModel::ContentSettingSensorImageModel() |
| 519 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_SENSORS) {} |
| 520 |
| 521 void ContentSettingSensorImageModel::UpdateFromWebContents( |
| 522 WebContents* web_contents) { |
| 523 set_visible(false); |
| 524 if (!web_contents) |
| 525 return; |
| 526 TabSpecificContentSettings* content_settings = |
| 527 TabSpecificContentSettings::FromWebContents(web_contents); |
| 528 if (!content_settings) |
| 529 return; |
| 530 // TODO(riju): when UMA is ready |
| 531 /* |
| 532 const ContentSettingsUsagesState& usages_state = |
| 533 content_settings->sensors_usages_state(); |
| 534 if (usages_state.state_map().empty()) |
| 535 return; |
| 536 */ |
| 537 set_visible(true); |
| 538 |
| 539 // If any embedded site has access the allowed icon takes priority over the |
| 540 // blocked icon. |
| 541 unsigned int state_flags = 0; |
| 542 // usages_state.GetDetailedInfo(nullptr, &state_flags); |
| 543 bool allowed = |
| 544 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 545 set_icon_by_vector_id(gfx::VectorIconId::MIDI, // TODO(riju) |
| 546 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE |
| 547 : gfx::VectorIconId::BLOCKED_BADGE); |
| 548 set_tooltip(l10n_util::GetStringUTF16(allowed ? IDS_SENSORS_ALLOWED_TOOLTIP |
| 549 : IDS_SENSORS_BLOCKED_TOOLTIP)); |
| 550 } |
| 551 |
503 // Base class ------------------------------------------------------------------ | 552 // Base class ------------------------------------------------------------------ |
504 | 553 |
505 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { | 554 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { |
506 #if defined(OS_MACOSX) | 555 #if defined(OS_MACOSX) |
507 SkColor icon_color = nearby_text_color; | 556 SkColor icon_color = nearby_text_color; |
508 #else | 557 #else |
509 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); | 558 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); |
510 #endif | 559 #endif |
511 | 560 |
512 return gfx::Image( | 561 return gfx::Image( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 | 603 |
555 #if defined(OS_MACOSX) | 604 #if defined(OS_MACOSX) |
556 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( | 605 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
557 content::WebContents* web_contents) { | 606 content::WebContents* web_contents) { |
558 gfx::VectorIconId old_icon = icon_id_; | 607 gfx::VectorIconId old_icon = icon_id_; |
559 gfx::VectorIconId old_badge_icon = icon_badge_id_; | 608 gfx::VectorIconId old_badge_icon = icon_badge_id_; |
560 UpdateFromWebContents(web_contents); | 609 UpdateFromWebContents(web_contents); |
561 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; | 610 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; |
562 } | 611 } |
563 #endif | 612 #endif |
OLD | NEW |