Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_image_model.cc

Issue 2458453002: [sensors] Add Permission guard to the generic sensor apis.
Patch Set: Mikhail+alex comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 bool allowed = 508 bool allowed =
496 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); 509 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED);
497 set_icon_by_vector_id(gfx::VectorIconId::MIDI, 510 set_icon_by_vector_id(gfx::VectorIconId::MIDI,
498 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE 511 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE
499 : gfx::VectorIconId::BLOCKED_BADGE); 512 : gfx::VectorIconId::BLOCKED_BADGE);
500 set_tooltip(l10n_util::GetStringUTF16(allowed 513 set_tooltip(l10n_util::GetStringUTF16(allowed
501 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP 514 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP
502 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); 515 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP));
503 } 516 }
504 517
518 // Sensors ------------------------------------------------------------------
519
520 ContentSettingSensorImageModel::ContentSettingSensorImageModel()
521 : ContentSettingSimpleImageModel(CONTENT_SETTINGS_TYPE_SENSORS) {}
522
523 void ContentSettingSensorImageModel::UpdateFromWebContents(
524 WebContents* web_contents) {
525 set_visible(false);
526 if (!web_contents)
527 return;
528 TabSpecificContentSettings* content_settings =
529 TabSpecificContentSettings::FromWebContents(web_contents);
530 if (!content_settings)
531 return;
532 // TODO(riju): when UMA is ready
533 /*
534 const ContentSettingsUsagesState& usages_state =
535 content_settings->sensors_usages_state();
536 if (usages_state.state_map().empty())
537 return;
538 */
539 set_visible(true);
540
541 // If any embedded site has access the allowed icon takes priority over the
542 // blocked icon.
543 unsigned int state_flags = 0;
544 // usages_state.GetDetailedInfo(nullptr, &state_flags);
545 bool allowed =
546 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED);
547 set_icon_by_vector_id(gfx::VectorIconId::MIDI, // TODO(riju)
548 allowed ? gfx::VectorIconId::VECTOR_ICON_NONE
549 : gfx::VectorIconId::BLOCKED_BADGE);
550 set_tooltip(l10n_util::GetStringUTF16(allowed ? IDS_SENSORS_ALLOWED_TOOLTIP
551 : IDS_SENSORS_BLOCKED_TOOLTIP));
552 }
553
505 // Base class ------------------------------------------------------------------ 554 // Base class ------------------------------------------------------------------
506 555
507 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { 556 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const {
508 #if defined(OS_MACOSX) 557 #if defined(OS_MACOSX)
509 SkColor icon_color = nearby_text_color; 558 SkColor icon_color = nearby_text_color;
510 #else 559 #else
511 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); 560 SkColor icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color);
512 #endif 561 #endif
513 562
514 return gfx::Image( 563 return gfx::Image(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 605
557 #if defined(OS_MACOSX) 606 #if defined(OS_MACOSX)
558 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( 607 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged(
559 content::WebContents* web_contents) { 608 content::WebContents* web_contents) {
560 gfx::VectorIconId old_icon = icon_id_; 609 gfx::VectorIconId old_icon = icon_id_;
561 gfx::VectorIconId old_badge_icon = icon_badge_id_; 610 gfx::VectorIconId old_badge_icon = icon_badge_id_;
562 UpdateFromWebContents(web_contents); 611 UpdateFromWebContents(web_contents);
563 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_; 612 return old_icon != icon_id_ && old_badge_icon != icon_badge_id_;
564 } 613 }
565 #endif 614 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698