| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/content_setting_image_model.h" | 5 #include "chrome/browser/content_setting_image_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 11 | 11 |
| 12 class ContentSettingBlockedImageModel : public ContentSettingImageModel { | 12 class ContentSettingBlockedImageModel : public ContentSettingImageModel { |
| 13 public: | 13 public: |
| 14 explicit ContentSettingBlockedImageModel( | 14 explicit ContentSettingBlockedImageModel( |
| 15 ContentSettingsType content_settings_type); | 15 ContentSettingsType content_settings_type) |
| 16 : ContentSettingImageModel(content_settings_type) { |
| 17 } |
| 16 | 18 |
| 17 virtual void UpdateFromTabContents(const TabContents* tab_contents); | 19 virtual void UpdateFromTabContents(const TabContents* tab_contents) { |
| 20 if (tab_contents && |
| 21 tab_contents->IsContentBlocked(get_content_settings_type())) { |
| 22 set_icon(kBlockedIconIDs[get_content_settings_type()]); |
| 23 set_tooltip( |
| 24 l10n_util::GetStringUTF8(kTooltipIDs[get_content_settings_type()])); |
| 25 set_visible(true); |
| 26 } else { |
| 27 set_visible(false); |
| 28 } |
| 29 } |
| 18 | 30 |
| 19 private: | 31 private: |
| 20 static const int kBlockedIconIDs[]; | 32 static const int kBlockedIconIDs[]; |
| 21 static const int kTooltipIDs[]; | 33 static const int kTooltipIDs[]; |
| 34 |
| 22 }; | 35 }; |
| 23 | 36 |
| 24 class ContentSettingGeolocationImageModel : public ContentSettingImageModel { | 37 ContentSettingImageModel::ContentSettingImageModel( |
| 25 public: | 38 ContentSettingsType content_settings_type) |
| 26 ContentSettingGeolocationImageModel(); | 39 : content_settings_type_(content_settings_type), |
| 40 is_visible_(false), |
| 41 icon_(0) { |
| 42 } |
| 27 | 43 |
| 28 virtual void UpdateFromTabContents(const TabContents* tab_contents); | 44 // static |
| 29 }; | 45 ContentSettingImageModel* ContentSettingImageModel:: |
| 46 CreateContentSettingImageModel(ContentSettingsType content_settings_type) { |
| 47 return new ContentSettingBlockedImageModel(content_settings_type); |
| 48 } |
| 30 | 49 |
| 31 const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { | 50 const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { |
| 32 IDR_BLOCKED_COOKIES, | 51 IDR_BLOCKED_COOKIES, |
| 33 IDR_BLOCKED_IMAGES, | 52 IDR_BLOCKED_IMAGES, |
| 34 IDR_BLOCKED_JAVASCRIPT, | 53 IDR_BLOCKED_JAVASCRIPT, |
| 35 IDR_BLOCKED_PLUGINS, | 54 IDR_BLOCKED_PLUGINS, |
| 36 IDR_BLOCKED_POPUPS, | 55 IDR_BLOCKED_POPUPS, |
| 37 }; | 56 }; |
| 38 | 57 |
| 39 const int ContentSettingBlockedImageModel::kTooltipIDs[] = { | 58 const int ContentSettingBlockedImageModel::kTooltipIDs[] = { |
| 40 IDS_BLOCKED_COOKIES_TITLE, | 59 IDS_BLOCKED_COOKIES_TITLE, |
| 41 IDS_BLOCKED_IMAGES_TITLE, | 60 IDS_BLOCKED_IMAGES_TITLE, |
| 42 IDS_BLOCKED_JAVASCRIPT_TITLE, | 61 IDS_BLOCKED_JAVASCRIPT_TITLE, |
| 43 IDS_BLOCKED_PLUGINS_TITLE, | 62 IDS_BLOCKED_PLUGINS_TITLE, |
| 44 IDS_BLOCKED_POPUPS_TOOLTIP, | 63 IDS_BLOCKED_POPUPS_TOOLTIP, |
| 45 }; | 64 }; |
| 46 | |
| 47 | |
| 48 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( | |
| 49 ContentSettingsType content_settings_type) | |
| 50 : ContentSettingImageModel(content_settings_type) { | |
| 51 } | |
| 52 | |
| 53 void ContentSettingBlockedImageModel::UpdateFromTabContents( | |
| 54 const TabContents* tab_contents) { | |
| 55 if (!tab_contents || | |
| 56 !tab_contents->IsContentBlocked(get_content_settings_type())) { | |
| 57 set_visible(false); | |
| 58 return; | |
| 59 } | |
| 60 set_icon(kBlockedIconIDs[get_content_settings_type()]); | |
| 61 set_tooltip( | |
| 62 l10n_util::GetStringUTF8(kTooltipIDs[get_content_settings_type()])); | |
| 63 set_visible(true); | |
| 64 } | |
| 65 | |
| 66 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() | |
| 67 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { | |
| 68 } | |
| 69 | |
| 70 void ContentSettingGeolocationImageModel::UpdateFromTabContents( | |
| 71 const TabContents* tab_contents) { | |
| 72 if (!tab_contents) { | |
| 73 set_visible(false); | |
| 74 return; | |
| 75 } | |
| 76 const TabContents::GeolocationContentSettings& settings = | |
| 77 tab_contents->geolocation_content_settings(); | |
| 78 if (settings.empty()) { | |
| 79 set_visible(false); | |
| 80 return; | |
| 81 } | |
| 82 set_visible(true); | |
| 83 // If any embedded site has access the allowed icon takes priority over the | |
| 84 // blocked icon. | |
| 85 for (TabContents::GeolocationContentSettings::const_iterator it = | |
| 86 settings.begin(); it != settings.end(); ++it ) { | |
| 87 if (it->second == CONTENT_SETTING_ALLOW) { | |
| 88 set_icon(IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON); | |
| 89 set_tooltip(l10n_util::GetStringUTF8(IDS_GEOLOCATION_ALLOWED_TOOLTIP)); | |
| 90 return; | |
| 91 } | |
| 92 } | |
| 93 set_icon(IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON); | |
| 94 set_tooltip(l10n_util::GetStringUTF8(IDS_GEOLOCATION_BLOCKED_TOOLTIP)); | |
| 95 } | |
| 96 | |
| 97 ContentSettingImageModel::ContentSettingImageModel( | |
| 98 ContentSettingsType content_settings_type) | |
| 99 : content_settings_type_(content_settings_type), | |
| 100 is_visible_(false), | |
| 101 icon_(0) { | |
| 102 } | |
| 103 | |
| 104 // static | |
| 105 ContentSettingImageModel* | |
| 106 ContentSettingImageModel::CreateContentSettingImageModel( | |
| 107 ContentSettingsType content_settings_type) { | |
| 108 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) | |
| 109 return new ContentSettingGeolocationImageModel(); | |
| 110 return new ContentSettingBlockedImageModel(content_settings_type); | |
| 111 } | |
| OLD | NEW |