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 "chrome/browser/content_settings/tab_specific_content_settings.h" | 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 8 #include "chrome/browser/prerender/prerender_manager.h" | 8 #include "chrome/browser/prerender/prerender_manager.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/content_settings/core/browser/host_content_settings_map.h" | 11 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/material_design/material_design_controller.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | |
| 17 | |
| 18 #if !defined(OS_MACOSX) | |
| 19 #include "ui/gfx/paint_vector_icon.h" | |
| 20 #include "ui/gfx/vector_icons_public2.h" | |
| 21 #include "ui/native_theme/common_theme.h" | |
| 22 #include "ui/native_theme/native_theme.h" | |
| 23 #endif | |
| 15 | 24 |
| 16 using content::WebContents; | 25 using content::WebContents; |
| 17 | 26 |
| 27 namespace { | |
| 28 | |
| 29 bool IsMaterial() { | |
|
tdanderson
2015/08/27 13:25:23
This function shouldn't be necessary. IsModeMateri
Evan Stade
2015/08/27 15:49:48
tldr, this fn should be renamed to UseVectorGraphi
| |
| 30 #if defined(OS_MACOSX) | |
| 31 return false; | |
| 32 #else | |
| 33 return ui::MaterialDesignController::IsModeMaterial(); | |
| 34 #endif | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 18 class ContentSettingBlockedImageModel : public ContentSettingImageModel { | 39 class ContentSettingBlockedImageModel : public ContentSettingImageModel { |
| 19 public: | 40 public: |
| 20 explicit ContentSettingBlockedImageModel( | 41 explicit ContentSettingBlockedImageModel( |
| 21 ContentSettingsType content_settings_type); | 42 ContentSettingsType content_settings_type); |
| 22 | 43 |
| 23 void UpdateFromWebContents(WebContents* web_contents) override; | 44 void UpdateFromWebContents(WebContents* web_contents) override; |
| 24 }; | 45 }; |
| 25 | 46 |
| 26 class ContentSettingGeolocationImageModel : public ContentSettingImageModel { | 47 class ContentSettingGeolocationImageModel : public ContentSettingImageModel { |
| 27 public: | 48 public: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 ContentSettingsType content_settings_type) | 103 ContentSettingsType content_settings_type) |
| 83 : ContentSettingImageModel(content_settings_type) { | 104 : ContentSettingImageModel(content_settings_type) { |
| 84 } | 105 } |
| 85 | 106 |
| 86 void ContentSettingBlockedImageModel::UpdateFromWebContents( | 107 void ContentSettingBlockedImageModel::UpdateFromWebContents( |
| 87 WebContents* web_contents) { | 108 WebContents* web_contents) { |
| 88 set_visible(false); | 109 set_visible(false); |
| 89 if (!web_contents) | 110 if (!web_contents) |
| 90 return; | 111 return; |
| 91 | 112 |
| 113 ContentSettingsType type = get_content_settings_type(); | |
| 92 static const ContentSettingsTypeIdEntry kBlockedIconIDs[] = { | 114 static const ContentSettingsTypeIdEntry kBlockedIconIDs[] = { |
| 93 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_BLOCKED_COOKIES}, | 115 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_BLOCKED_COOKIES}, |
| 94 {CONTENT_SETTINGS_TYPE_IMAGES, IDR_BLOCKED_IMAGES}, | 116 {CONTENT_SETTINGS_TYPE_IMAGES, IDR_BLOCKED_IMAGES}, |
| 95 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDR_BLOCKED_JAVASCRIPT}, | 117 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDR_BLOCKED_JAVASCRIPT}, |
| 96 {CONTENT_SETTINGS_TYPE_PLUGINS, IDR_BLOCKED_PLUGINS}, | 118 {CONTENT_SETTINGS_TYPE_PLUGINS, IDR_BLOCKED_PLUGINS}, |
| 97 {CONTENT_SETTINGS_TYPE_POPUPS, IDR_BLOCKED_POPUPS}, | 119 {CONTENT_SETTINGS_TYPE_POPUPS, IDR_BLOCKED_POPUPS}, |
| 98 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDR_BLOCKED_MIXED_CONTENT}, | 120 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDR_BLOCKED_MIXED_CONTENT}, |
| 99 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, | 121 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, |
| 100 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_BLOCKED_DOWNLOADS}, | 122 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_BLOCKED_DOWNLOADS}, |
| 101 }; | 123 }; |
| 124 int icon_id = | |
| 125 GetIdForContentType(kBlockedIconIDs, arraysize(kBlockedIconIDs), type); | |
| 126 | |
| 127 #if !defined(OS_MACOSX) | |
| 128 gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 129 switch (type) { | |
| 130 case CONTENT_SETTINGS_TYPE_COOKIES: | |
| 131 vector_icon_id = gfx::VectorIconId::COOKIE; | |
| 132 break; | |
| 133 case CONTENT_SETTINGS_TYPE_IMAGES: | |
| 134 vector_icon_id = gfx::VectorIconId::IMAGE; | |
| 135 break; | |
| 136 case CONTENT_SETTINGS_TYPE_JAVASCRIPT: | |
| 137 vector_icon_id = gfx::VectorIconId::CODE; | |
| 138 break; | |
| 139 case CONTENT_SETTINGS_TYPE_PLUGINS: | |
| 140 vector_icon_id = gfx::VectorIconId::EXTENSION; | |
| 141 break; | |
| 142 case CONTENT_SETTINGS_TYPE_POPUPS: | |
| 143 vector_icon_id = gfx::VectorIconId::WEB; | |
| 144 break; | |
| 145 case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: | |
| 146 vector_icon_id = gfx::VectorIconId::MIXED_CONTENT; | |
| 147 break; | |
| 148 // TODO(estade): change this one? | |
| 149 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: | |
| 150 vector_icon_id = gfx::VectorIconId::EXTENSION; | |
| 151 break; | |
| 152 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: | |
| 153 vector_icon_id = gfx::VectorIconId::FILE_DOWNLOAD; | |
| 154 break; | |
| 155 default: | |
| 156 NOTREACHED(); | |
| 157 } | |
| 158 #endif | |
| 159 | |
| 102 static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = { | 160 static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = { |
| 103 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, | 161 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
| 104 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, | 162 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
| 105 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, | 163 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, |
| 106 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, | 164 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, |
| 107 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TOOLTIP}, | 165 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TOOLTIP}, |
| 108 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | 166 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
| 109 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, | 167 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, |
| 110 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_TITLE}, | 168 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_TITLE}, |
| 111 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, | 169 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, |
| 112 }; | 170 }; |
| 171 int tooltip_id = GetIdForContentType(kBlockedTooltipIDs, | |
| 172 arraysize(kBlockedTooltipIDs), type); | |
| 173 | |
| 113 static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = { | 174 static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = { |
| 114 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT}, | 175 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT}, |
| 115 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT}, | 176 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT}, |
| 116 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 177 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 117 IDS_BLOCKED_DOWNLOADS_EXPLANATION}, | 178 IDS_BLOCKED_DOWNLOADS_EXPLANATION}, |
| 118 }; | 179 }; |
| 119 | |
| 120 ContentSettingsType type = get_content_settings_type(); | |
| 121 int icon_id = GetIdForContentType( | |
| 122 kBlockedIconIDs, arraysize(kBlockedIconIDs), type); | |
| 123 int tooltip_id = GetIdForContentType( | |
| 124 kBlockedTooltipIDs, arraysize(kBlockedTooltipIDs), type); | |
| 125 int explanation_id = GetIdForContentType( | 180 int explanation_id = GetIdForContentType( |
| 126 kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type); | 181 kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type); |
| 127 | 182 |
| 128 // For plugins, don't show the animated explanation unless the plugin was | 183 // For plugins, don't show the animated explanation unless the plugin was |
| 129 // blocked despite the user's content settings being set to allow it (e.g. | 184 // blocked despite the user's content settings being set to allow it (e.g. |
| 130 // due to auto-blocking NPAPI plugins). | 185 // due to auto-blocking NPAPI plugins). |
| 131 Profile* profile = | 186 Profile* profile = |
| 132 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 187 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 133 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 188 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 134 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 189 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 152 // blocked by default. | 207 // blocked by default. |
| 153 if (type == CONTENT_SETTINGS_TYPE_COOKIES && | 208 if (type == CONTENT_SETTINGS_TYPE_COOKIES && |
| 154 (map->GetDefaultContentSetting(type, NULL) != CONTENT_SETTING_BLOCK)) | 209 (map->GetDefaultContentSetting(type, NULL) != CONTENT_SETTING_BLOCK)) |
| 155 return; | 210 return; |
| 156 | 211 |
| 157 static const ContentSettingsTypeIdEntry kAccessedIconIDs[] = { | 212 static const ContentSettingsTypeIdEntry kAccessedIconIDs[] = { |
| 158 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_ACCESSED_COOKIES}, | 213 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_ACCESSED_COOKIES}, |
| 159 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, | 214 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, |
| 160 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_ALLOWED_DOWNLOADS}, | 215 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_ALLOWED_DOWNLOADS}, |
| 161 }; | 216 }; |
| 217 icon_id = GetIdForContentType(kAccessedIconIDs, arraysize(kAccessedIconIDs), | |
| 218 type); | |
| 162 static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = { | 219 static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = { |
| 163 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, | 220 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, |
| 164 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 221 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
| 165 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, | 222 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, |
| 166 }; | 223 }; |
| 167 icon_id = GetIdForContentType( | |
| 168 kAccessedIconIDs, arraysize(kAccessedIconIDs), type); | |
| 169 tooltip_id = GetIdForContentType( | 224 tooltip_id = GetIdForContentType( |
| 170 kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type); | 225 kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type); |
| 171 explanation_id = 0; | 226 explanation_id = 0; |
| 172 } | 227 } |
| 173 set_visible(true); | 228 set_visible(true); |
| 174 DCHECK(icon_id); | 229 if (!IsMaterial()) { |
| 175 set_icon(icon_id); | 230 DCHECK(icon_id); |
| 231 SetIconByResourceId(icon_id); | |
| 232 #if !defined(OS_MACOSX) | |
| 233 } else { | |
| 234 DCHECK(gfx::VectorIconId::VECTOR_ICON_NONE != vector_icon_id); | |
| 235 SetIconByVectorId(vector_icon_id, content_settings->IsContentBlocked(type)); | |
| 236 #endif | |
| 237 } | |
| 176 set_explanatory_string_id(explanation_id); | 238 set_explanatory_string_id(explanation_id); |
| 177 DCHECK(tooltip_id); | 239 DCHECK(tooltip_id); |
| 178 set_tooltip(l10n_util::GetStringUTF8(tooltip_id)); | 240 set_tooltip(l10n_util::GetStringUTF8(tooltip_id)); |
| 179 } | 241 } |
| 180 | 242 |
| 181 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() | 243 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() |
| 182 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 244 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 183 } | 245 } |
| 184 | 246 |
| 185 void ContentSettingGeolocationImageModel::UpdateFromWebContents( | 247 void ContentSettingGeolocationImageModel::UpdateFromWebContents( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 196 if (usages_state.state_map().empty()) | 258 if (usages_state.state_map().empty()) |
| 197 return; | 259 return; |
| 198 set_visible(true); | 260 set_visible(true); |
| 199 | 261 |
| 200 // If any embedded site has access the allowed icon takes priority over the | 262 // If any embedded site has access the allowed icon takes priority over the |
| 201 // blocked icon. | 263 // blocked icon. |
| 202 unsigned int state_flags = 0; | 264 unsigned int state_flags = 0; |
| 203 usages_state.GetDetailedInfo(NULL, &state_flags); | 265 usages_state.GetDetailedInfo(NULL, &state_flags); |
| 204 bool allowed = | 266 bool allowed = |
| 205 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 267 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 206 set_icon(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); | 268 if (!IsMaterial()) |
| 269 SetIconByResourceId(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); | |
| 270 #if !defined(OS_MACOSX) | |
| 271 else | |
| 272 SetIconByVectorId(gfx::VectorIconId::MY_LOCATION, !allowed); | |
| 273 #endif | |
| 207 set_tooltip(l10n_util::GetStringUTF8(allowed ? | 274 set_tooltip(l10n_util::GetStringUTF8(allowed ? |
| 208 IDS_GEOLOCATION_ALLOWED_TOOLTIP : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); | 275 IDS_GEOLOCATION_ALLOWED_TOOLTIP : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); |
| 209 } | 276 } |
| 210 | 277 |
| 211 ContentSettingMediaImageModel::ContentSettingMediaImageModel( | 278 ContentSettingMediaImageModel::ContentSettingMediaImageModel( |
| 212 ContentSettingsType type) | 279 ContentSettingsType type) |
| 213 : ContentSettingImageModel(type) { | 280 : ContentSettingImageModel(type) { |
| 214 } | 281 } |
| 215 | 282 |
| 216 void ContentSettingMediaImageModel::UpdateFromWebContents( | 283 void ContentSettingMediaImageModel::UpdateFromWebContents( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) | 320 if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) |
| 254 return; | 321 return; |
| 255 | 322 |
| 256 bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; | 323 bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; |
| 257 bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; | 324 bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; |
| 258 DCHECK(is_mic || is_cam); | 325 DCHECK(is_mic || is_cam); |
| 259 | 326 |
| 260 int id = IDS_CAMERA_BLOCKED; | 327 int id = IDS_CAMERA_BLOCKED; |
| 261 if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | | 328 if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 262 TabSpecificContentSettings::CAMERA_BLOCKED)) { | 329 TabSpecificContentSettings::CAMERA_BLOCKED)) { |
| 263 set_icon(IDR_BLOCKED_CAMERA); | 330 if (IsMaterial()) |
| 331 SetIconByResourceId(IDR_BLOCKED_CAMERA); | |
| 332 #if !defined(OS_MACOSX) | |
| 333 else | |
| 334 SetIconByVectorId(gfx::VectorIconId::VIDEOCAM, true); | |
| 335 #endif | |
| 264 if (is_mic) | 336 if (is_mic) |
| 265 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; | 337 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; |
| 266 } else { | 338 } else { |
| 267 set_icon(IDR_ALLOWED_CAMERA); | 339 if (IsMaterial()) |
| 340 SetIconByResourceId(IDR_ALLOWED_CAMERA); | |
| 341 #if !defined(OS_MACOSX) | |
| 342 else | |
| 343 SetIconByVectorId(gfx::VectorIconId::VIDEOCAM, false); | |
| 344 #endif | |
| 268 id = IDS_CAMERA_ACCESSED; | 345 id = IDS_CAMERA_ACCESSED; |
| 269 if (is_mic) | 346 if (is_mic) |
| 270 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; | 347 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; |
| 271 } | 348 } |
| 272 set_tooltip(l10n_util::GetStringUTF8(id)); | 349 set_tooltip(l10n_util::GetStringUTF8(id)); |
| 273 set_visible(true); | 350 set_visible(true); |
| 274 } | 351 } |
| 275 | 352 |
| 276 ContentSettingRPHImageModel::ContentSettingRPHImageModel() | 353 ContentSettingRPHImageModel::ContentSettingRPHImageModel() |
| 277 : ContentSettingImageModel( | 354 : ContentSettingImageModel( |
| 278 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 355 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 279 set_icon(IDR_REGISTER_PROTOCOL_HANDLER); | 356 // TODO(estade): get an MD icon for this one. |
| 357 SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); | |
| 280 set_tooltip(l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); | 358 set_tooltip(l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); |
| 281 } | 359 } |
| 282 | 360 |
| 283 void ContentSettingRPHImageModel::UpdateFromWebContents( | 361 void ContentSettingRPHImageModel::UpdateFromWebContents( |
| 284 WebContents* web_contents) { | 362 WebContents* web_contents) { |
| 285 set_visible(false); | 363 set_visible(false); |
| 286 if (!web_contents) | 364 if (!web_contents) |
| 287 return; | 365 return; |
| 288 | 366 |
| 289 TabSpecificContentSettings* content_settings = | 367 TabSpecificContentSettings* content_settings = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 if (usages_state.state_map().empty()) | 402 if (usages_state.state_map().empty()) |
| 325 return; | 403 return; |
| 326 set_visible(true); | 404 set_visible(true); |
| 327 | 405 |
| 328 // If any embedded site has access the allowed icon takes priority over the | 406 // If any embedded site has access the allowed icon takes priority over the |
| 329 // blocked icon. | 407 // blocked icon. |
| 330 unsigned int state_flags = 0; | 408 unsigned int state_flags = 0; |
| 331 usages_state.GetDetailedInfo(NULL, &state_flags); | 409 usages_state.GetDetailedInfo(NULL, &state_flags); |
| 332 bool allowed = | 410 bool allowed = |
| 333 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 411 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 334 set_icon(allowed ? IDR_ALLOWED_MIDI_SYSEX : IDR_BLOCKED_MIDI_SYSEX); | 412 #if defined(OS_MACOSX) |
| 413 SetIconByResourceId(allowed ? IDR_ALLOWED_MIDI_SYSEX | |
| 414 : IDR_BLOCKED_MIDI_SYSEX); | |
| 415 #else | |
| 416 SetIconByVectorId(gfx::VectorIconId::MIDI, !allowed); | |
| 417 #endif | |
| 335 set_tooltip(l10n_util::GetStringUTF8(allowed ? | 418 set_tooltip(l10n_util::GetStringUTF8(allowed ? |
| 336 IDS_MIDI_SYSEX_ALLOWED_TOOLTIP : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 419 IDS_MIDI_SYSEX_ALLOWED_TOOLTIP : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
| 337 } | 420 } |
| 338 | 421 |
| 339 ContentSettingImageModel::ContentSettingImageModel( | 422 ContentSettingImageModel::ContentSettingImageModel( |
| 340 ContentSettingsType content_settings_type) | 423 ContentSettingsType content_settings_type) |
| 341 : content_settings_type_(content_settings_type), | 424 : content_settings_type_(content_settings_type), |
| 342 is_visible_(false), | 425 is_visible_(false), |
| 343 icon_(0), | 426 icon_id_(0), |
| 344 explanatory_string_id_(0) { | 427 explanatory_string_id_(0) { |
| 345 } | 428 } |
| 346 | 429 |
| 347 // static | 430 // static |
| 348 ContentSettingImageModel* | 431 ContentSettingImageModel* |
| 349 ContentSettingImageModel::CreateContentSettingImageModel( | 432 ContentSettingImageModel::CreateContentSettingImageModel( |
| 350 ContentSettingsType content_settings_type) { | 433 ContentSettingsType content_settings_type) { |
| 351 switch (content_settings_type) { | 434 switch (content_settings_type) { |
| 352 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 435 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 353 return new ContentSettingGeolocationImageModel(); | 436 return new ContentSettingGeolocationImageModel(); |
| 354 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 437 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 355 return new ContentSettingNotificationsImageModel(); | 438 return new ContentSettingNotificationsImageModel(); |
| 356 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: | 439 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
| 357 return new ContentSettingRPHImageModel(); | 440 return new ContentSettingRPHImageModel(); |
| 358 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 441 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
| 359 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | 442 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| 360 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 443 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 361 return new ContentSettingMediaImageModel(content_settings_type); | 444 return new ContentSettingMediaImageModel(content_settings_type); |
| 362 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 445 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 363 return new ContentSettingMIDISysExImageModel(); | 446 return new ContentSettingMIDISysExImageModel(); |
| 364 default: | 447 default: |
| 365 return new ContentSettingBlockedImageModel(content_settings_type); | 448 return new ContentSettingBlockedImageModel(content_settings_type); |
| 366 } | 449 } |
| 367 } | 450 } |
| 451 | |
| 452 void ContentSettingImageModel::SetIconByResourceId(int id) { | |
| 453 icon_id_ = id; | |
| 454 icon_ = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); | |
| 455 } | |
| 456 | |
| 457 #if !defined(OS_MACOSX) | |
| 458 void ContentSettingImageModel::SetIconByVectorId(gfx::VectorIconId id, | |
| 459 bool blocked) { | |
| 460 SkColor icon_color; | |
| 461 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_ChromeIconGrey, | |
| 462 &icon_color); | |
| 463 icon_ = gfx::Image(gfx::CreateVectorIconWithBadge( | |
| 464 id, 16, icon_color, blocked ? gfx::VectorIconId::BLOCKED_BADGE | |
| 465 : gfx::VectorIconId::VECTOR_ICON_NONE)); | |
| 466 } | |
| 467 #endif | |
| OLD | NEW |