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

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

Issue 1369002: Re-attempt at http://codereview.chromium.org/1344002... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/content_setting_bubble_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_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 }
OLDNEW
« no previous file with comments | « chrome/browser/content_setting_bubble_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698