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 } | |
18 | 16 |
19 virtual void UpdateFromTabContents(const TabContents* tab_contents) { | 17 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 } | |
30 | 18 |
31 private: | 19 private: |
32 static const int kBlockedIconIDs[]; | 20 static const int kBlockedIconIDs[]; |
33 static const int kTooltipIDs[]; | 21 static const int kTooltipIDs[]; |
34 | |
35 }; | 22 }; |
36 | 23 |
37 ContentSettingImageModel::ContentSettingImageModel( | 24 class ContentSettingGeolocationImageModel : public ContentSettingImageModel { |
38 ContentSettingsType content_settings_type) | 25 public: |
39 : content_settings_type_(content_settings_type), | 26 ContentSettingGeolocationImageModel(); |
40 is_visible_(false), | |
41 icon_(0) { | |
42 } | |
43 | 27 |
44 // static | 28 virtual void UpdateFromTabContents(const TabContents* tab_contents); |
45 ContentSettingImageModel* ContentSettingImageModel:: | 29 }; |
46 CreateContentSettingImageModel(ContentSettingsType content_settings_type) { | |
47 return new ContentSettingBlockedImageModel(content_settings_type); | |
48 } | |
49 | 30 |
50 const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { | 31 const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { |
51 IDR_BLOCKED_COOKIES, | 32 IDR_BLOCKED_COOKIES, |
52 IDR_BLOCKED_IMAGES, | 33 IDR_BLOCKED_IMAGES, |
53 IDR_BLOCKED_JAVASCRIPT, | 34 IDR_BLOCKED_JAVASCRIPT, |
54 IDR_BLOCKED_PLUGINS, | 35 IDR_BLOCKED_PLUGINS, |
55 IDR_BLOCKED_POPUPS, | 36 IDR_BLOCKED_POPUPS, |
56 }; | 37 }; |
57 | 38 |
58 const int ContentSettingBlockedImageModel::kTooltipIDs[] = { | 39 const int ContentSettingBlockedImageModel::kTooltipIDs[] = { |
59 IDS_BLOCKED_COOKIES_TITLE, | 40 IDS_BLOCKED_COOKIES_TITLE, |
60 IDS_BLOCKED_IMAGES_TITLE, | 41 IDS_BLOCKED_IMAGES_TITLE, |
61 IDS_BLOCKED_JAVASCRIPT_TITLE, | 42 IDS_BLOCKED_JAVASCRIPT_TITLE, |
62 IDS_BLOCKED_PLUGINS_TITLE, | 43 IDS_BLOCKED_PLUGINS_TITLE, |
63 IDS_BLOCKED_POPUPS_TOOLTIP, | 44 IDS_BLOCKED_POPUPS_TOOLTIP, |
64 }; | 45 }; |
| 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_icon(kBlockedIconIDs[get_content_settings_type()]); |
| 58 set_tooltip( |
| 59 l10n_util::GetStringUTF8(kTooltipIDs[get_content_settings_type()])); |
| 60 set_visible(true); |
| 61 } else { |
| 62 set_visible(false); |
| 63 } |
| 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 bool is_content_blocked = tab_contents->IsContentBlocked( |
| 83 CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 84 set_icon(is_content_blocked ? |
| 85 IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON : |
| 86 IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON); |
| 87 std::string tooltip; |
| 88 if (settings.size() == 1) { |
| 89 tooltip = l10n_util::GetStringFUTF8( |
| 90 is_content_blocked ? |
| 91 IDS_GEOLOCATION_BLOCKED_TOOLTIP : |
| 92 IDS_GEOLOCATION_ALLOWED_TOOLTIP, |
| 93 UTF8ToUTF16(settings.begin()->first)); |
| 94 } else { |
| 95 tooltip = l10n_util::GetStringUTF8( |
| 96 is_content_blocked ? |
| 97 IDS_GEOLOCATION_MULTIPLE_BLOCKED_TOOLTIP : |
| 98 IDS_GEOLOCATION_MULTIPLE_ALLOWED_TOOLTIP); |
| 99 |
| 100 } |
| 101 set_tooltip(tooltip); |
| 102 set_visible(true); |
| 103 } |
| 104 |
| 105 ContentSettingImageModel::ContentSettingImageModel( |
| 106 ContentSettingsType content_settings_type) |
| 107 : content_settings_type_(content_settings_type), |
| 108 is_visible_(false), |
| 109 icon_(0) { |
| 110 } |
| 111 |
| 112 // static |
| 113 ContentSettingImageModel* ContentSettingImageModel:: |
| 114 CreateContentSettingImageModel(ContentSettingsType content_settings_type) { |
| 115 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 116 return new ContentSettingGeolocationImageModel(); |
| 117 return new ContentSettingBlockedImageModel(content_settings_type); |
| 118 } |
OLD | NEW |