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

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

Issue 11488009: Add content settings page action for Pepper broker authorization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years 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_bubble_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/content_settings_utils.h" 8 #include "chrome/browser/content_settings/content_settings_utils.h"
9 #include "chrome/browser/content_settings/cookie_settings.h" 9 #include "chrome/browser/content_settings/cookie_settings.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 83
84 void ContentSettingTitleAndLinkModel::SetTitle() { 84 void ContentSettingTitleAndLinkModel::SetTitle() {
85 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { 85 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
86 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, 86 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
87 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, 87 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
88 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, 88 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
89 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, 89 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
90 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, 90 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
91 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, 91 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
92 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, 92 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
93 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
94 IDS_BLOCKED_PPAPI_BROKER_TITLE},
93 }; 95 };
94 // Fields as for kBlockedTitleIDs, above. 96 // Fields as for kBlockedTitleIDs, above.
95 static const ContentSettingsTypeIdEntry 97 static const ContentSettingsTypeIdEntry
96 kResourceSpecificBlockedTitleIDs[] = { 98 kResourceSpecificBlockedTitleIDs[] = {
97 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, 99 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE},
98 }; 100 };
99 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = { 101 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = {
100 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, 102 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
103 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE},
101 }; 104 };
102 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs; 105 const ContentSettingsTypeIdEntry *title_ids = kBlockedTitleIDs;
103 size_t num_title_ids = arraysize(kBlockedTitleIDs); 106 size_t num_title_ids = arraysize(kBlockedTitleIDs);
104 if (web_contents() && 107 if (web_contents() &&
105 TabSpecificContentSettings::FromWebContents( 108 TabSpecificContentSettings::FromWebContents(
106 web_contents())->IsContentAccessed(content_type()) && 109 web_contents())->IsContentAccessed(content_type()) &&
107 !TabSpecificContentSettings::FromWebContents( 110 !TabSpecificContentSettings::FromWebContents(
108 web_contents())->IsContentBlocked(content_type())) { 111 web_contents())->IsContentBlocked(content_type())) {
109 title_ids = kAccessedTitleIDs; 112 title_ids = kAccessedTitleIDs;
110 num_title_ids = arraysize(kAccessedTitleIDs); 113 num_title_ids = arraysize(kAccessedTitleIDs);
111 } else if (!bubble_content().resource_identifiers.empty()) { 114 } else if (!bubble_content().resource_identifiers.empty()) {
112 title_ids = kResourceSpecificBlockedTitleIDs; 115 title_ids = kResourceSpecificBlockedTitleIDs;
113 num_title_ids = arraysize(kResourceSpecificBlockedTitleIDs); 116 num_title_ids = arraysize(kResourceSpecificBlockedTitleIDs);
114 } 117 }
115 int title_id = 118 int title_id =
116 GetIdForContentType(title_ids, num_title_ids, content_type()); 119 GetIdForContentType(title_ids, num_title_ids, content_type());
117 if (title_id) 120 if (title_id)
118 set_title(l10n_util::GetStringUTF8(title_id)); 121 set_title(l10n_util::GetStringUTF8(title_id));
119 } 122 }
120 123
121 void ContentSettingTitleAndLinkModel::SetManageLink() { 124 void ContentSettingTitleAndLinkModel::SetManageLink() {
122 static const ContentSettingsTypeIdEntry kLinkIDs[] = { 125 static const ContentSettingsTypeIdEntry kLinkIDs[] = {
123 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, 126 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
124 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, 127 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
125 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, 128 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
126 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, 129 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK},
127 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, 130 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK},
128 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, 131 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK},
129 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, 132 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE},
130 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK} 133 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK},
134 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_PPAPI_BROKER_BUBBLE_MANAGE_LINK},
131 }; 135 };
132 set_manage_link(l10n_util::GetStringUTF8( 136 set_manage_link(l10n_util::GetStringUTF8(
133 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); 137 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
134 } 138 }
135 139
136 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { 140 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() {
137 if (delegate_) 141 if (delegate_)
138 delegate_->ShowContentSettingsPage(content_type()); 142 delegate_->ShowContentSettingsPage(content_type());
139 } 143 }
140 144
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 230 }
227 231
228 bool ContentSettingSingleRadioGroup::settings_changed() const { 232 bool ContentSettingSingleRadioGroup::settings_changed() const {
229 return selected_item_ != bubble_content().radio_group.default_item; 233 return selected_item_ != bubble_content().radio_group.default_item;
230 } 234 }
231 235
232 // Initialize the radio group by setting the appropriate labels for the 236 // Initialize the radio group by setting the appropriate labels for the
233 // content type and setting the default value based on the content setting. 237 // content type and setting the default value based on the content setting.
234 void ContentSettingSingleRadioGroup::SetRadioGroup() { 238 void ContentSettingSingleRadioGroup::SetRadioGroup() {
235 GURL url = web_contents()->GetURL(); 239 GURL url = web_contents()->GetURL();
236 string16 display_host_utf16; 240 string16 display_host;
237 net::AppendFormattedHost( 241 net::AppendFormattedHost(
238 url, 242 url,
239 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), 243 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
240 &display_host_utf16); 244 &display_host);
241 std::string display_host(UTF16ToUTF8(display_host_utf16));
242 245
243 if (display_host.empty()) 246 if (display_host.empty())
244 display_host = url.spec(); 247 display_host = ASCIIToUTF16(url.spec());
245 248
246 const std::set<std::string>& resources = 249 const std::set<std::string>& resources =
247 bubble_content().resource_identifiers; 250 bubble_content().resource_identifiers;
248 251
252 TabSpecificContentSettings* content_settings =
253 TabSpecificContentSettings::FromWebContents(web_contents());
254 bool allowed =
255 !content_settings->IsContentBlocked(content_type());
256 DCHECK(!allowed ||
257 content_settings->IsContentAccessed(content_type()));
258
249 RadioGroup radio_group; 259 RadioGroup radio_group;
250 radio_group.url = url; 260 radio_group.url = url;
251 261
252 static const ContentSettingsTypeIdEntry kAllowIDs[] = { 262 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = {
253 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, 263 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
254 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, 264 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK},
255 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, 265 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK},
256 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, 266 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL},
257 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, 267 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK},
268 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK},
258 }; 269 };
259 // Fields as for kAllowIDs, above. 270 // Fields as for kBlockedAllowIDs, above.
260 static const ContentSettingsTypeIdEntry kResourceSpecificAllowIDs[] = { 271 static const ContentSettingsTypeIdEntry kResourceSpecificBlockedAllowIDs[] = {
261 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK}, 272 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK},
262 }; 273 };
274 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = {
275 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION},
276 };
277
263 std::string radio_allow_label; 278 std::string radio_allow_label;
264 const ContentSettingsTypeIdEntry* allow_ids = resources.empty() ? 279 if (allowed) {
265 kAllowIDs : kResourceSpecificAllowIDs; 280 radio_allow_label = l10n_util::GetStringUTF8(
266 size_t num_allow_ids = resources.empty() ? 281 GetIdForContentType(kAllowedAllowIDs, arraysize(kAllowedAllowIDs),
267 arraysize(kAllowIDs) : arraysize(kResourceSpecificAllowIDs); 282 content_type()));
268 radio_allow_label = l10n_util::GetStringFUTF8( 283 } else if (resources.empty()) {
269 GetIdForContentType(allow_ids, num_allow_ids, content_type()), 284 radio_allow_label = l10n_util::GetStringFUTF8(
270 UTF8ToUTF16(display_host)); 285 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs),
286 content_type()),
287 display_host);
288 } else {
289 radio_allow_label = l10n_util::GetStringFUTF8(
290 GetIdForContentType(kResourceSpecificBlockedAllowIDs,
291 arraysize(kResourceSpecificBlockedAllowIDs),
292 content_type()),
293 display_host);
294 }
271 295
272 static const ContentSettingsTypeIdEntry kBlockIDs[] = { 296 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = {
273 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, 297 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
274 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, 298 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION},
275 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, 299 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION},
276 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, 300 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION},
277 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, 301 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION},
302 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION},
278 }; 303 };
304 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = {
305 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK},
306 };
307
279 std::string radio_block_label; 308 std::string radio_block_label;
280 radio_block_label = l10n_util::GetStringUTF8( 309 if (allowed) {
281 GetIdForContentType(kBlockIDs, arraysize(kBlockIDs), content_type())); 310 radio_block_label = l10n_util::GetStringFUTF8(
311 GetIdForContentType(kAllowedBlockIDs, arraysize(kAllowedBlockIDs),
312 content_type()),
313 display_host);
314 } else {
315 radio_block_label = l10n_util::GetStringUTF8(
316 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs),
317 content_type()));
318 }
282 319
283 radio_group.radio_items.push_back(radio_allow_label); 320 radio_group.radio_items.push_back(radio_allow_label);
284 radio_group.radio_items.push_back(radio_block_label); 321 radio_group.radio_items.push_back(radio_block_label);
285 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 322 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
286 CookieSettings* cookie_settings = 323 CookieSettings* cookie_settings =
287 CookieSettings::Factory::GetForProfile(profile()); 324 CookieSettings::Factory::GetForProfile(profile());
288 ContentSetting most_restrictive_setting; 325 ContentSetting most_restrictive_setting;
289 SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE; 326 SettingSource most_restrictive_setting_source = SETTING_SOURCE_NONE;
290 327
291 if (resources.empty()) { 328 if (resources.empty()) {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 855 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
819 DCHECK_EQ(web_contents_, 856 DCHECK_EQ(web_contents_,
820 content::Source<WebContents>(source).ptr()); 857 content::Source<WebContents>(source).ptr());
821 web_contents_ = NULL; 858 web_contents_ = NULL;
822 } else { 859 } else {
823 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 860 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
824 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 861 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
825 profile_ = NULL; 862 profile_ = NULL;
826 } 863 }
827 } 864 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698