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

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

Issue 10577028: Move the mixed scripting infobar to a page action icon / content setting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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
OLDNEW
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/host_content_settings_map.h" 7 #include "chrome/browser/content_settings/host_content_settings_map.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/prerender/prerender_manager.h" 9 #include "chrome/browser/prerender/prerender_manager.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
15 #include "grit/theme_resources_standard.h" 15 #include "grit/theme_resources_standard.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 using content::WebContents; 18 using content::WebContents;
19 19
20 class ContentSettingBlockedImageModel : public ContentSettingImageModel { 20 class ContentSettingBlockedImageModel : public ContentSettingImageModel {
21 public: 21 public:
22 explicit ContentSettingBlockedImageModel( 22 explicit ContentSettingBlockedImageModel(
23 ContentSettingsType content_settings_type); 23 ContentSettingsType content_settings_type);
24 24
25 virtual void UpdateFromWebContents(WebContents* web_contents) OVERRIDE; 25 virtual void UpdateFromWebContents(WebContents* web_contents) OVERRIDE;
26
27 private:
28 static const int kAccessedIconIDs[];
29 static const int kBlockedIconIDs[];
30 static const int kBlockedExplanatoryTextIDs[];
31 static const int kAccessedExplanatoryTextIDs[];
32 static const int kAccessedTooltipIDs[];
33 static const int kBlockedTooltipIDs[];
34 }; 26 };
35 27
36 class ContentSettingGeolocationImageModel : public ContentSettingImageModel { 28 class ContentSettingGeolocationImageModel : public ContentSettingImageModel {
37 public: 29 public:
38 ContentSettingGeolocationImageModel(); 30 ContentSettingGeolocationImageModel();
39 31
40 virtual void UpdateFromWebContents(WebContents* web_contents) OVERRIDE; 32 virtual void UpdateFromWebContents(WebContents* web_contents) OVERRIDE;
41 }; 33 };
42 34
43 class ContentSettingNotificationsImageModel : public ContentSettingImageModel { 35 class ContentSettingNotificationsImageModel : public ContentSettingImageModel {
44 public: 36 public:
45 ContentSettingNotificationsImageModel(); 37 ContentSettingNotificationsImageModel();
46 38
47 virtual void UpdateFromWebContents(WebContents* web_contents) OVERRIDE; 39 virtual void UpdateFromWebContents(WebContents* web_contents) OVERRIDE;
48 }; 40 };
49 41
50 const int ContentSettingBlockedImageModel::kBlockedIconIDs[] = { 42 namespace {
Bernhard Bauer 2012/06/21 11:02:01 Nit: newline
51 IDR_BLOCKED_COOKIES, 43 struct ContentSettingsTypeIdEntry {
52 IDR_BLOCKED_IMAGES, 44 ContentSettingsType type;
53 IDR_BLOCKED_JAVASCRIPT, 45 int id;
54 IDR_BLOCKED_PLUGINS,
55 IDR_BLOCKED_POPUPS,
56 }; 46 };
57 47
58 const int ContentSettingBlockedImageModel::kAccessedIconIDs[] = { 48 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries,
59 IDR_ACCESSED_COOKIES, 49 size_t num_entries,
60 0, 50 ContentSettingsType type) {
61 0, 51 for (size_t i = 0; i < num_entries; ++i) {
62 0, 52 if (entries[i].type == type)
63 0, 53 return entries[i].id;
64 }; 54 }
55 return 0;
56 }
65 57
66 const int ContentSettingBlockedImageModel::kBlockedExplanatoryTextIDs[] = { 58 } // namespace
67 0,
68 0,
69 0,
70 0,
71 IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT,
72 };
73
74 const int ContentSettingBlockedImageModel::kAccessedExplanatoryTextIDs[] = {
75 0,
76 0,
77 0,
78 0,
79 0,
80 };
81
82
83 const int ContentSettingBlockedImageModel::kBlockedTooltipIDs[] = {
84 IDS_BLOCKED_COOKIES_TITLE,
85 IDS_BLOCKED_IMAGES_TITLE,
86 IDS_BLOCKED_JAVASCRIPT_TITLE,
87 IDS_BLOCKED_PLUGINS_MESSAGE,
88 IDS_BLOCKED_POPUPS_TOOLTIP,
89 };
90
91 const int ContentSettingBlockedImageModel::kAccessedTooltipIDs[] = {
92 IDS_ACCESSED_COOKIES_TITLE,
93 0,
94 0,
95 0,
96 0,
97 };
98 59
99 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( 60 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
100 ContentSettingsType content_settings_type) 61 ContentSettingsType content_settings_type)
101 : ContentSettingImageModel(content_settings_type) { 62 : ContentSettingImageModel(content_settings_type) {
102 } 63 }
103 64
104 void ContentSettingBlockedImageModel::UpdateFromWebContents( 65 void ContentSettingBlockedImageModel::UpdateFromWebContents(
105 WebContents* web_contents) { 66 WebContents* web_contents) {
106 set_visible(false); 67 set_visible(false);
107 if (!web_contents) 68 if (!web_contents)
108 return; 69 return;
109 70
110 const int* icon_ids = kBlockedIconIDs; 71 static const ContentSettingsTypeIdEntry kBlockedIconIDs[] = {
111 const int* tooltip_ids = kBlockedTooltipIDs; 72 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_BLOCKED_COOKIES},
112 const int* explanatory_string_ids = kBlockedExplanatoryTextIDs; 73 {CONTENT_SETTINGS_TYPE_IMAGES, IDR_BLOCKED_IMAGES},
74 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDR_BLOCKED_JAVASCRIPT},
75 {CONTENT_SETTINGS_TYPE_PLUGINS, IDR_BLOCKED_PLUGINS},
76 {CONTENT_SETTINGS_TYPE_POPUPS, IDR_BLOCKED_POPUPS},
77 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDR_OMNIBOX_HTTPS_INVALID},
78 };
79 static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = {
80 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
81 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
82 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
83 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
84 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TOOLTIP},
85 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
86 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
87 };
88 static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = {
89 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT},
90 };
91
92 ContentSettingsType type = get_content_settings_type();
93 int icon_id = GetIdForContentType(
94 kBlockedIconIDs, arraysize(kBlockedIconIDs), type);
95 int tooltip_id = GetIdForContentType(
96 kBlockedTooltipIDs, arraysize(kBlockedTooltipIDs), type);
97 int explanation_id = GetIdForContentType(
98 kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type);
99
113 // If a content type is blocked by default and was accessed, display the 100 // If a content type is blocked by default and was accessed, display the
114 // accessed icon. 101 // accessed icon.
115 TabContents* tab_contents = TabContents::FromWebContents(web_contents); 102 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
116 TabSpecificContentSettings* content_settings = 103 TabSpecificContentSettings* content_settings =
117 tab_contents->content_settings(); 104 tab_contents->content_settings();
118 if (!content_settings->IsContentBlocked(get_content_settings_type())) { 105 if (!content_settings->IsContentBlocked(get_content_settings_type())) {
119 if (!content_settings->IsContentAccessed(get_content_settings_type()) || 106 if (!content_settings->IsContentAccessed(get_content_settings_type()) ||
120 (tab_contents->profile()->GetHostContentSettingsMap()-> 107 (tab_contents->profile()->GetHostContentSettingsMap()->
121 GetDefaultContentSetting(get_content_settings_type(), NULL) != 108 GetDefaultContentSetting(get_content_settings_type(), NULL) !=
122 CONTENT_SETTING_BLOCK)) 109 CONTENT_SETTING_BLOCK))
123 return; 110 return;
124 icon_ids = kAccessedIconIDs; 111 static const ContentSettingsTypeIdEntry kAccessedIconIDs[] = {
125 tooltip_ids = kAccessedTooltipIDs; 112 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_ACCESSED_COOKIES},
126 explanatory_string_ids = kAccessedExplanatoryTextIDs; 113 };
114 static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = {
115 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
116 };
117 icon_id = GetIdForContentType(
118 kAccessedIconIDs, arraysize(kAccessedIconIDs), type);
119 tooltip_id = GetIdForContentType(
120 kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type);
121 explanation_id = 0;
127 } 122 }
128 set_visible(true); 123 set_visible(true);
129 set_icon(icon_ids[get_content_settings_type()]); 124 set_icon(icon_id);
130 set_explanatory_string_id( 125 set_explanatory_string_id(explanation_id);
131 explanatory_string_ids[get_content_settings_type()]); 126 set_tooltip(l10n_util::GetStringUTF8(tooltip_id));
132 set_tooltip(
133 l10n_util::GetStringUTF8(tooltip_ids[get_content_settings_type()]));
134 } 127 }
135 128
136 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() 129 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel()
137 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { 130 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) {
138 } 131 }
139 132
140 void ContentSettingGeolocationImageModel::UpdateFromWebContents( 133 void ContentSettingGeolocationImageModel::UpdateFromWebContents(
141 WebContents* web_contents) { 134 WebContents* web_contents) {
142 set_visible(false); 135 set_visible(false);
143 if (!web_contents) 136 if (!web_contents)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ContentSettingsType content_settings_type) { 179 ContentSettingsType content_settings_type) {
187 switch (content_settings_type) { 180 switch (content_settings_type) {
188 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 181 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
189 return new ContentSettingGeolocationImageModel(); 182 return new ContentSettingGeolocationImageModel();
190 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 183 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
191 return new ContentSettingNotificationsImageModel(); 184 return new ContentSettingNotificationsImageModel();
192 default: 185 default:
193 return new ContentSettingBlockedImageModel(content_settings_type); 186 return new ContentSettingBlockedImageModel(content_settings_type);
194 } 187 }
195 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698