| 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 UseVectorGraphics() { |
| 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 // If we didn't find a vector icon ID we shouldn't have found an |
| 157 // asset ID either. |
| 158 DCHECK_EQ(0, icon_id); |
| 159 break; |
| 160 } |
| 161 #endif |
| 162 |
| 102 static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = { | 163 static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = { |
| 103 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, | 164 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
| 104 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, | 165 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
| 105 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, | 166 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, |
| 106 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, | 167 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, |
| 107 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TOOLTIP}, | 168 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TOOLTIP}, |
| 108 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | 169 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
| 109 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, | 170 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, |
| 110 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_TITLE}, | 171 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_TITLE}, |
| 111 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, | 172 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, |
| 112 }; | 173 }; |
| 174 int tooltip_id = GetIdForContentType(kBlockedTooltipIDs, |
| 175 arraysize(kBlockedTooltipIDs), type); |
| 176 |
| 113 static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = { | 177 static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = { |
| 114 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT}, | 178 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT}, |
| 115 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT}, | 179 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT}, |
| 116 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 180 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 117 IDS_BLOCKED_DOWNLOADS_EXPLANATION}, | 181 IDS_BLOCKED_DOWNLOADS_EXPLANATION}, |
| 118 }; | 182 }; |
| 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( | 183 int explanation_id = GetIdForContentType( |
| 126 kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type); | 184 kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type); |
| 127 | 185 |
| 128 // For plugins, don't show the animated explanation unless the plugin was | 186 // 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. | 187 // blocked despite the user's content settings being set to allow it (e.g. |
| 130 // due to auto-blocking NPAPI plugins). | 188 // due to auto-blocking NPAPI plugins). |
| 131 Profile* profile = | 189 Profile* profile = |
| 132 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 190 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 133 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 191 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
| 134 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | 192 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 152 // blocked by default. | 210 // blocked by default. |
| 153 if (type == CONTENT_SETTINGS_TYPE_COOKIES && | 211 if (type == CONTENT_SETTINGS_TYPE_COOKIES && |
| 154 (map->GetDefaultContentSetting(type, NULL) != CONTENT_SETTING_BLOCK)) | 212 (map->GetDefaultContentSetting(type, NULL) != CONTENT_SETTING_BLOCK)) |
| 155 return; | 213 return; |
| 156 | 214 |
| 157 static const ContentSettingsTypeIdEntry kAccessedIconIDs[] = { | 215 static const ContentSettingsTypeIdEntry kAccessedIconIDs[] = { |
| 158 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_ACCESSED_COOKIES}, | 216 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_ACCESSED_COOKIES}, |
| 159 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, | 217 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, |
| 160 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_ALLOWED_DOWNLOADS}, | 218 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_ALLOWED_DOWNLOADS}, |
| 161 }; | 219 }; |
| 220 icon_id = GetIdForContentType(kAccessedIconIDs, arraysize(kAccessedIconIDs), |
| 221 type); |
| 162 static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = { | 222 static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = { |
| 163 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, | 223 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, |
| 164 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, | 224 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, |
| 165 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, | 225 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, |
| 166 }; | 226 }; |
| 167 icon_id = GetIdForContentType( | |
| 168 kAccessedIconIDs, arraysize(kAccessedIconIDs), type); | |
| 169 tooltip_id = GetIdForContentType( | 227 tooltip_id = GetIdForContentType( |
| 170 kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type); | 228 kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type); |
| 171 explanation_id = 0; | 229 explanation_id = 0; |
| 172 } | 230 } |
| 173 set_visible(true); | 231 set_visible(true); |
| 174 DCHECK(icon_id); | 232 if (!UseVectorGraphics()) { |
| 175 set_icon(icon_id); | 233 DCHECK(icon_id); |
| 234 SetIconByResourceId(icon_id); |
| 235 #if !defined(OS_MACOSX) |
| 236 } else { |
| 237 DCHECK(gfx::VectorIconId::VECTOR_ICON_NONE != vector_icon_id); |
| 238 SetIconByVectorId(vector_icon_id, content_settings->IsContentBlocked(type)); |
| 239 #endif |
| 240 } |
| 176 set_explanatory_string_id(explanation_id); | 241 set_explanatory_string_id(explanation_id); |
| 177 DCHECK(tooltip_id); | 242 DCHECK(tooltip_id); |
| 178 set_tooltip(l10n_util::GetStringUTF8(tooltip_id)); | 243 set_tooltip(l10n_util::GetStringUTF8(tooltip_id)); |
| 179 } | 244 } |
| 180 | 245 |
| 181 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() | 246 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() |
| 182 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 247 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 183 } | 248 } |
| 184 | 249 |
| 185 void ContentSettingGeolocationImageModel::UpdateFromWebContents( | 250 void ContentSettingGeolocationImageModel::UpdateFromWebContents( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 if (usages_state.state_map().empty()) | 261 if (usages_state.state_map().empty()) |
| 197 return; | 262 return; |
| 198 set_visible(true); | 263 set_visible(true); |
| 199 | 264 |
| 200 // If any embedded site has access the allowed icon takes priority over the | 265 // If any embedded site has access the allowed icon takes priority over the |
| 201 // blocked icon. | 266 // blocked icon. |
| 202 unsigned int state_flags = 0; | 267 unsigned int state_flags = 0; |
| 203 usages_state.GetDetailedInfo(NULL, &state_flags); | 268 usages_state.GetDetailedInfo(NULL, &state_flags); |
| 204 bool allowed = | 269 bool allowed = |
| 205 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 270 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 206 set_icon(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); | 271 if (!UseVectorGraphics()) |
| 272 SetIconByResourceId(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); |
| 273 #if !defined(OS_MACOSX) |
| 274 else |
| 275 SetIconByVectorId(gfx::VectorIconId::MY_LOCATION, !allowed); |
| 276 #endif |
| 207 set_tooltip(l10n_util::GetStringUTF8(allowed ? | 277 set_tooltip(l10n_util::GetStringUTF8(allowed ? |
| 208 IDS_GEOLOCATION_ALLOWED_TOOLTIP : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); | 278 IDS_GEOLOCATION_ALLOWED_TOOLTIP : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); |
| 209 } | 279 } |
| 210 | 280 |
| 211 ContentSettingMediaImageModel::ContentSettingMediaImageModel( | 281 ContentSettingMediaImageModel::ContentSettingMediaImageModel( |
| 212 ContentSettingsType type) | 282 ContentSettingsType type) |
| 213 : ContentSettingImageModel(type) { | 283 : ContentSettingImageModel(type) { |
| 214 } | 284 } |
| 215 | 285 |
| 216 void ContentSettingMediaImageModel::UpdateFromWebContents( | 286 void ContentSettingMediaImageModel::UpdateFromWebContents( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) | 323 if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED) |
| 254 return; | 324 return; |
| 255 | 325 |
| 256 bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; | 326 bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; |
| 257 bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; | 327 bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; |
| 258 DCHECK(is_mic || is_cam); | 328 DCHECK(is_mic || is_cam); |
| 259 | 329 |
| 260 int id = IDS_CAMERA_BLOCKED; | 330 int id = IDS_CAMERA_BLOCKED; |
| 261 if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | | 331 if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 262 TabSpecificContentSettings::CAMERA_BLOCKED)) { | 332 TabSpecificContentSettings::CAMERA_BLOCKED)) { |
| 263 set_icon(IDR_BLOCKED_CAMERA); | 333 if (!UseVectorGraphics()) |
| 334 SetIconByResourceId(IDR_BLOCKED_CAMERA); |
| 335 #if !defined(OS_MACOSX) |
| 336 else |
| 337 SetIconByVectorId(gfx::VectorIconId::VIDEOCAM, true); |
| 338 #endif |
| 264 if (is_mic) | 339 if (is_mic) |
| 265 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; | 340 id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; |
| 266 } else { | 341 } else { |
| 267 set_icon(IDR_ALLOWED_CAMERA); | 342 if (!UseVectorGraphics()) |
| 343 SetIconByResourceId(IDR_ALLOWED_CAMERA); |
| 344 #if !defined(OS_MACOSX) |
| 345 else |
| 346 SetIconByVectorId(gfx::VectorIconId::VIDEOCAM, false); |
| 347 #endif |
| 268 id = IDS_CAMERA_ACCESSED; | 348 id = IDS_CAMERA_ACCESSED; |
| 269 if (is_mic) | 349 if (is_mic) |
| 270 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; | 350 id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; |
| 271 } | 351 } |
| 272 set_tooltip(l10n_util::GetStringUTF8(id)); | 352 set_tooltip(l10n_util::GetStringUTF8(id)); |
| 273 set_visible(true); | 353 set_visible(true); |
| 274 } | 354 } |
| 275 | 355 |
| 276 ContentSettingRPHImageModel::ContentSettingRPHImageModel() | 356 ContentSettingRPHImageModel::ContentSettingRPHImageModel() |
| 277 : ContentSettingImageModel( | 357 : ContentSettingImageModel( |
| 278 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | 358 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
| 279 set_icon(IDR_REGISTER_PROTOCOL_HANDLER); | 359 // TODO(estade): get an MD icon for this one. |
| 360 SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); |
| 280 set_tooltip(l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); | 361 set_tooltip(l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); |
| 281 } | 362 } |
| 282 | 363 |
| 283 void ContentSettingRPHImageModel::UpdateFromWebContents( | 364 void ContentSettingRPHImageModel::UpdateFromWebContents( |
| 284 WebContents* web_contents) { | 365 WebContents* web_contents) { |
| 285 set_visible(false); | 366 set_visible(false); |
| 286 if (!web_contents) | 367 if (!web_contents) |
| 287 return; | 368 return; |
| 288 | 369 |
| 289 TabSpecificContentSettings* content_settings = | 370 TabSpecificContentSettings* content_settings = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (usages_state.state_map().empty()) | 405 if (usages_state.state_map().empty()) |
| 325 return; | 406 return; |
| 326 set_visible(true); | 407 set_visible(true); |
| 327 | 408 |
| 328 // If any embedded site has access the allowed icon takes priority over the | 409 // If any embedded site has access the allowed icon takes priority over the |
| 329 // blocked icon. | 410 // blocked icon. |
| 330 unsigned int state_flags = 0; | 411 unsigned int state_flags = 0; |
| 331 usages_state.GetDetailedInfo(NULL, &state_flags); | 412 usages_state.GetDetailedInfo(NULL, &state_flags); |
| 332 bool allowed = | 413 bool allowed = |
| 333 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); | 414 !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); |
| 334 set_icon(allowed ? IDR_ALLOWED_MIDI_SYSEX : IDR_BLOCKED_MIDI_SYSEX); | 415 #if defined(OS_MACOSX) |
| 416 SetIconByResourceId(allowed ? IDR_ALLOWED_MIDI_SYSEX |
| 417 : IDR_BLOCKED_MIDI_SYSEX); |
| 418 #else |
| 419 SetIconByVectorId(gfx::VectorIconId::MIDI, !allowed); |
| 420 #endif |
| 335 set_tooltip(l10n_util::GetStringUTF8(allowed ? | 421 set_tooltip(l10n_util::GetStringUTF8(allowed ? |
| 336 IDS_MIDI_SYSEX_ALLOWED_TOOLTIP : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 422 IDS_MIDI_SYSEX_ALLOWED_TOOLTIP : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
| 337 } | 423 } |
| 338 | 424 |
| 339 ContentSettingImageModel::ContentSettingImageModel( | 425 ContentSettingImageModel::ContentSettingImageModel( |
| 340 ContentSettingsType content_settings_type) | 426 ContentSettingsType content_settings_type) |
| 341 : content_settings_type_(content_settings_type), | 427 : content_settings_type_(content_settings_type), |
| 342 is_visible_(false), | 428 is_visible_(false), |
| 343 icon_(0), | 429 icon_id_(0), |
| 344 explanatory_string_id_(0) { | 430 explanatory_string_id_(0) { |
| 345 } | 431 } |
| 346 | 432 |
| 347 // static | 433 // static |
| 348 ContentSettingImageModel* | 434 ContentSettingImageModel* |
| 349 ContentSettingImageModel::CreateContentSettingImageModel( | 435 ContentSettingImageModel::CreateContentSettingImageModel( |
| 350 ContentSettingsType content_settings_type) { | 436 ContentSettingsType content_settings_type) { |
| 351 switch (content_settings_type) { | 437 switch (content_settings_type) { |
| 352 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 438 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 353 return new ContentSettingGeolocationImageModel(); | 439 return new ContentSettingGeolocationImageModel(); |
| 354 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 440 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 355 return new ContentSettingNotificationsImageModel(); | 441 return new ContentSettingNotificationsImageModel(); |
| 356 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: | 442 case CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS: |
| 357 return new ContentSettingRPHImageModel(); | 443 return new ContentSettingRPHImageModel(); |
| 358 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 444 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
| 359 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | 445 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| 360 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | 446 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 361 return new ContentSettingMediaImageModel(content_settings_type); | 447 return new ContentSettingMediaImageModel(content_settings_type); |
| 362 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 448 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 363 return new ContentSettingMIDISysExImageModel(); | 449 return new ContentSettingMIDISysExImageModel(); |
| 364 default: | 450 default: |
| 365 return new ContentSettingBlockedImageModel(content_settings_type); | 451 return new ContentSettingBlockedImageModel(content_settings_type); |
| 366 } | 452 } |
| 367 } | 453 } |
| 454 |
| 455 void ContentSettingImageModel::SetIconByResourceId(int id) { |
| 456 icon_id_ = id; |
| 457 icon_ = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); |
| 458 } |
| 459 |
| 460 #if !defined(OS_MACOSX) |
| 461 void ContentSettingImageModel::SetIconByVectorId(gfx::VectorIconId id, |
| 462 bool blocked) { |
| 463 SkColor icon_color; |
| 464 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_ChromeIconGrey, |
| 465 &icon_color); |
| 466 icon_ = gfx::Image(gfx::CreateVectorIconWithBadge( |
| 467 id, 16, icon_color, blocked ? gfx::VectorIconId::BLOCKED_BADGE |
| 468 : gfx::VectorIconId::VECTOR_ICON_NONE)); |
| 469 } |
| 470 #endif |
| OLD | NEW |