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

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 {
51 IDR_BLOCKED_COOKIES, 43
52 IDR_BLOCKED_IMAGES, 44 struct ContentSettingsTypeIdEntry {
53 IDR_BLOCKED_JAVASCRIPT, 45 ContentSettingsType type;
54 IDR_BLOCKED_PLUGINS, 46 int id;
55 IDR_BLOCKED_POPUPS,
56 }; 47 };
57 48
58 const int ContentSettingBlockedImageModel::kAccessedIconIDs[] = { 49 int GetIdForContentType(const ContentSettingsTypeIdEntry* entries,
59 IDR_ACCESSED_COOKIES, 50 size_t num_entries,
60 0, 51 ContentSettingsType type) {
61 0, 52 for (size_t i = 0; i < num_entries; ++i) {
62 0, 53 if (entries[i].type == type)
63 0, 54 return entries[i].id;
64 }; 55 }
56 return 0;
57 }
65 58
66 const int ContentSettingBlockedImageModel::kBlockedExplanatoryTextIDs[] = { 59 } // 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 60
99 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel( 61 ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
100 ContentSettingsType content_settings_type) 62 ContentSettingsType content_settings_type)
101 : ContentSettingImageModel(content_settings_type) { 63 : ContentSettingImageModel(content_settings_type) {
102 } 64 }
103 65
104 void ContentSettingBlockedImageModel::UpdateFromWebContents( 66 void ContentSettingBlockedImageModel::UpdateFromWebContents(
105 WebContents* web_contents) { 67 WebContents* web_contents) {
106 set_visible(false); 68 set_visible(false);
107 if (!web_contents) 69 if (!web_contents)
108 return; 70 return;
109 71
110 const int* icon_ids = kBlockedIconIDs; 72 static const ContentSettingsTypeIdEntry kBlockedIconIDs[] = {
111 const int* tooltip_ids = kBlockedTooltipIDs; 73 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_BLOCKED_COOKIES},
112 const int* explanatory_string_ids = kBlockedExplanatoryTextIDs; 74 {CONTENT_SETTINGS_TYPE_IMAGES, IDR_BLOCKED_IMAGES},
75 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDR_BLOCKED_JAVASCRIPT},
76 {CONTENT_SETTINGS_TYPE_PLUGINS, IDR_BLOCKED_PLUGINS},
77 {CONTENT_SETTINGS_TYPE_POPUPS, IDR_BLOCKED_POPUPS},
78 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDR_OMNIBOX_HTTPS_INVALID},
79 };
80 static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = {
81 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
82 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
83 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
84 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
85 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TOOLTIP},
86 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
87 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
88 };
89 static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = {
90 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT},
91 };
92
93 ContentSettingsType type = get_content_settings_type();
94 int icon_id = GetIdForContentType(
95 kBlockedIconIDs, arraysize(kBlockedIconIDs), type);
96 int tooltip_id = GetIdForContentType(
97 kBlockedTooltipIDs, arraysize(kBlockedTooltipIDs), type);
98 int explanation_id = GetIdForContentType(
99 kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type);
100
113 // If a content type is blocked by default and was accessed, display the 101 // If a content type is blocked by default and was accessed, display the
114 // accessed icon. 102 // accessed icon.
115 TabContents* tab_contents = TabContents::FromWebContents(web_contents); 103 TabContents* tab_contents = TabContents::FromWebContents(web_contents);
116 TabSpecificContentSettings* content_settings = 104 TabSpecificContentSettings* content_settings =
117 tab_contents->content_settings(); 105 tab_contents->content_settings();
118 if (!content_settings->IsContentBlocked(get_content_settings_type())) { 106 if (!content_settings->IsContentBlocked(get_content_settings_type())) {
119 if (!content_settings->IsContentAccessed(get_content_settings_type()) || 107 if (!content_settings->IsContentAccessed(get_content_settings_type()) ||
120 (tab_contents->profile()->GetHostContentSettingsMap()-> 108 (tab_contents->profile()->GetHostContentSettingsMap()->
121 GetDefaultContentSetting(get_content_settings_type(), NULL) != 109 GetDefaultContentSetting(get_content_settings_type(), NULL) !=
122 CONTENT_SETTING_BLOCK)) 110 CONTENT_SETTING_BLOCK))
123 return; 111 return;
124 icon_ids = kAccessedIconIDs; 112 static const ContentSettingsTypeIdEntry kAccessedIconIDs[] = {
125 tooltip_ids = kAccessedTooltipIDs; 113 {CONTENT_SETTINGS_TYPE_COOKIES, IDR_ACCESSED_COOKIES},
126 explanatory_string_ids = kAccessedExplanatoryTextIDs; 114 };
115 static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = {
116 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
117 };
118 icon_id = GetIdForContentType(
119 kAccessedIconIDs, arraysize(kAccessedIconIDs), type);
120 tooltip_id = GetIdForContentType(
121 kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type);
122 explanation_id = 0;
127 } 123 }
128 set_visible(true); 124 set_visible(true);
129 set_icon(icon_ids[get_content_settings_type()]); 125 set_icon(icon_id);
130 set_explanatory_string_id( 126 set_explanatory_string_id(explanation_id);
131 explanatory_string_ids[get_content_settings_type()]); 127 set_tooltip(l10n_util::GetStringUTF8(tooltip_id));
132 set_tooltip(
133 l10n_util::GetStringUTF8(tooltip_ids[get_content_settings_type()]));
134 } 128 }
135 129
136 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel() 130 ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel()
137 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) { 131 : ContentSettingImageModel(CONTENT_SETTINGS_TYPE_GEOLOCATION) {
138 } 132 }
139 133
140 void ContentSettingGeolocationImageModel::UpdateFromWebContents( 134 void ContentSettingGeolocationImageModel::UpdateFromWebContents(
141 WebContents* web_contents) { 135 WebContents* web_contents) {
142 set_visible(false); 136 set_visible(false);
143 if (!web_contents) 137 if (!web_contents)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 ContentSettingsType content_settings_type) { 180 ContentSettingsType content_settings_type) {
187 switch (content_settings_type) { 181 switch (content_settings_type) {
188 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 182 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
189 return new ContentSettingGeolocationImageModel(); 183 return new ContentSettingGeolocationImageModel();
190 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 184 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
191 return new ContentSettingNotificationsImageModel(); 185 return new ContentSettingNotificationsImageModel();
192 default: 186 default:
193 return new ContentSettingBlockedImageModel(content_settings_type); 187 return new ContentSettingBlockedImageModel(content_settings_type);
194 } 188 }
195 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698