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

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

Issue 319553008: Updated Plugin bubble model to add "learn more" link and to appear with a sliding yellow thing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed typos Created 6 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
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 Delegate* delegate, 88 Delegate* delegate,
89 WebContents* web_contents, 89 WebContents* web_contents,
90 Profile* profile, 90 Profile* profile,
91 ContentSettingsType content_type) 91 ContentSettingsType content_type)
92 : ContentSettingBubbleModel(web_contents, profile, content_type), 92 : ContentSettingBubbleModel(web_contents, profile, content_type),
93 delegate_(delegate) { 93 delegate_(delegate) {
94 // Notifications do not have a bubble. 94 // Notifications do not have a bubble.
95 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 95 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
96 SetTitle(); 96 SetTitle();
97 SetManageLink(); 97 SetManageLink();
98 SetLearnMoreLink();
98 } 99 }
99 100
100 void ContentSettingTitleAndLinkModel::SetTitle() { 101 void ContentSettingTitleAndLinkModel::SetTitle() {
101 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { 102 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
102 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, 103 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
103 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, 104 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
104 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, 105 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
105 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, 106 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE},
106 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, 107 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
107 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, 108 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 }; 150 };
150 set_manage_link(l10n_util::GetStringUTF8( 151 set_manage_link(l10n_util::GetStringUTF8(
151 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); 152 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
152 } 153 }
153 154
154 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { 155 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() {
155 if (delegate_) 156 if (delegate_)
156 delegate_->ShowContentSettingsPage(content_type()); 157 delegate_->ShowContentSettingsPage(content_type());
157 } 158 }
158 159
160 void ContentSettingTitleAndLinkModel::SetLearnMoreLink() {
161 static const ContentSettingsTypeIdEntry kLearnMoreIDs[] = {
162 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_LEARN_MORE},
163 };
164 int learn_more_id =
165 GetIdForContentType(kLearnMoreIDs, arraysize(kLearnMoreIDs),
166 content_type());
167 if (learn_more_id)
168 set_learn_more_link(l10n_util::GetStringUTF8(learn_more_id));
169 }
170
171 void ContentSettingTitleAndLinkModel::OnLearnMoreLinkClicked() {
172 if (delegate_)
173 delegate_->ShowLearnMorePage(content_type());
174 }
175
159 class ContentSettingTitleLinkAndCustomModel 176 class ContentSettingTitleLinkAndCustomModel
160 : public ContentSettingTitleAndLinkModel { 177 : public ContentSettingTitleAndLinkModel {
161 public: 178 public:
162 ContentSettingTitleLinkAndCustomModel(Delegate* delegate, 179 ContentSettingTitleLinkAndCustomModel(Delegate* delegate,
163 WebContents* web_contents, 180 WebContents* web_contents,
164 Profile* profile, 181 Profile* profile,
165 ContentSettingsType content_type); 182 ContentSettingsType content_type);
166 virtual ~ContentSettingTitleLinkAndCustomModel() {} 183 virtual ~ContentSettingTitleLinkAndCustomModel() {}
167 184
168 private: 185 private:
169 void SetCustomLink(); 186 void SetCustomLink();
170 virtual void OnCustomLinkClicked() OVERRIDE {} 187 virtual void OnCustomLinkClicked() OVERRIDE {}
171 }; 188 };
172 189
173 ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel( 190 ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel(
174 Delegate* delegate, 191 Delegate* delegate,
175 WebContents* web_contents, 192 WebContents* web_contents,
176 Profile* profile, 193 Profile* profile,
177 ContentSettingsType content_type) 194 ContentSettingsType content_type)
178 : ContentSettingTitleAndLinkModel( 195 : ContentSettingTitleAndLinkModel(
179 delegate, web_contents, profile, content_type) { 196 delegate, web_contents, profile, content_type) {
180 SetCustomLink(); 197 SetCustomLink();
181 } 198 }
182 199
183 void ContentSettingTitleLinkAndCustomModel::SetCustomLink() { 200 void ContentSettingTitleLinkAndCustomModel::SetCustomLink() {
184 static const ContentSettingsTypeIdEntry kCustomIDs[] = { 201 static const ContentSettingsTypeIdEntry kCustomIDs[] = {
185 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO}, 202 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO},
186 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LOAD_ALL}, 203 // Deprecated because of the new NPAPI
204 // {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LOAD_ALL},
187 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON}, 205 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON},
188 }; 206 };
189 int custom_link_id = 207 int custom_link_id =
190 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type()); 208 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type());
191 if (custom_link_id) 209 if (custom_link_id)
192 set_custom_link(l10n_util::GetStringUTF8(custom_link_id)); 210 set_custom_link(l10n_util::GetStringUTF8(custom_link_id));
193 } 211 }
194 212
195 class ContentSettingSingleRadioGroup 213 class ContentSettingSingleRadioGroup
196 : public ContentSettingTitleLinkAndCustomModel { 214 : public ContentSettingTitleLinkAndCustomModel {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 DCHECK(!allowed || 278 DCHECK(!allowed ||
261 content_settings->IsContentAllowed(content_type())); 279 content_settings->IsContentAllowed(content_type()));
262 280
263 RadioGroup radio_group; 281 RadioGroup radio_group;
264 radio_group.url = url; 282 radio_group.url = url;
265 283
266 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { 284 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = {
267 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, 285 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
268 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, 286 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK},
269 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, 287 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK},
270 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, 288 // Todo(radhikabhar): Should be removed when the new NPAPI UI sets in
289 // {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL},
271 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, 290 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK},
272 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK}, 291 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK},
273 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_UNBLOCK}, 292 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_UNBLOCK},
274 }; 293 };
275 // Fields as for kBlockedAllowIDs, above. 294 // Fields as for kBlockedAllowIDs, above.
276 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = { 295 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = {
277 // TODO(bauerb): The string shouldn't be "unblock" (they weren't blocked). 296 // TODO(bauerb): The string shouldn't be "unblock" (they weren't blocked).
278 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, 297 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
279 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION}, 298 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION},
280 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_NO_ACTION}, 299 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_NO_ACTION},
(...skipping 11 matching lines...) Expand all
292 radio_allow_label = l10n_util::GetStringFUTF8( 311 radio_allow_label = l10n_util::GetStringFUTF8(
293 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs), 312 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs),
294 content_type()), 313 content_type()),
295 display_host); 314 display_host);
296 } 315 }
297 316
298 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = { 317 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = {
299 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, 318 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
300 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, 319 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION},
301 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, 320 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION},
302 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, 321 // Todo(radhikabhar): Should be removed when the new NPAPI UI sets in
322 // CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION},
303 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, 323 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION},
304 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION}, 324 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION},
305 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_NO_ACTION}, 325 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_NO_ACTION},
306 }; 326 };
307 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = { 327 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = {
308 // TODO(bauerb): The string should say "block". 328 // TODO(bauerb): The string should say "block".
309 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, 329 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
310 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK}, 330 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK},
311 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_BLOCK}, 331 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_BLOCK},
312 }; 332 };
313 333
314 std::string radio_block_label; 334 std::string radio_block_label;
315 if (allowed) { 335 if (allowed) {
316 int resource_id = GetIdForContentType(kAllowedBlockIDs, 336 int resource_id = GetIdForContentType(kAllowedBlockIDs,
317 arraysize(kAllowedBlockIDs), 337 arraysize(kAllowedBlockIDs),
318 content_type()); 338 content_type());
319 radio_block_label = (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) ? 339 radio_block_label = (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) ?
320 l10n_util::GetStringUTF8(resource_id) : 340 l10n_util::GetStringUTF8(resource_id) :
321 l10n_util::GetStringFUTF8(resource_id, display_host); 341 l10n_util::GetStringFUTF8(resource_id, display_host);
322 } else { 342 } else {
323 radio_block_label = l10n_util::GetStringUTF8( 343 radio_block_label = l10n_util::GetStringUTF8(
324 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs), 344 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs),
325 content_type())); 345 content_type()));
326 } 346 }
327 347
328 radio_group.radio_items.push_back(radio_allow_label); 348 radio_group.radio_items.push_back(radio_allow_label);
329 radio_group.radio_items.push_back(radio_block_label); 349 radio_group.radio_items.push_back(radio_block_label);
330 ContentSetting setting; 350 ContentSetting setting;
331 SettingSource setting_source = SETTING_SOURCE_NONE; 351 SettingSource setting_source = SETTING_SOURCE_NONE;
332 bool setting_is_wildcard = false; 352 // Todo(radhikabhar): Should be removed when the new NPAPI UI sets in
353 // bool setting_is_wildcard = false;
333 354
334 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { 355 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
335 CookieSettings* cookie_settings = 356 CookieSettings* cookie_settings =
336 CookieSettings::Factory::GetForProfile(profile()).get(); 357 CookieSettings::Factory::GetForProfile(profile()).get();
337 setting = cookie_settings->GetCookieSetting( 358 setting = cookie_settings->GetCookieSetting(
338 url, url, true, &setting_source); 359 url, url, true, &setting_source);
339 } else { 360 } else {
340 SettingInfo info; 361 SettingInfo info;
341 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 362 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
342 scoped_ptr<base::Value> value(map->GetWebsiteSetting( 363 scoped_ptr<base::Value> value(map->GetWebsiteSetting(
343 url, url, content_type(), std::string(), &info)); 364 url, url, content_type(), std::string(), &info));
344 setting = content_settings::ValueToContentSetting(value.get()); 365 setting = content_settings::ValueToContentSetting(value.get());
345 setting_source = info.source; 366 setting_source = info.source;
346 setting_is_wildcard = 367 // Todo(radhikabhar): Should be removed when the new NPAPI UI sets in
347 info.primary_pattern == ContentSettingsPattern::Wildcard() && 368 // setting_is_wildcard =
348 info.secondary_pattern == ContentSettingsPattern::Wildcard(); 369 // info.primary_pattern == ContentSettingsPattern::Wildcard() &&
370 // info.secondary_pattern == ContentSettingsPattern::Wildcard();
349 } 371 }
350 372
351 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && 373 if (setting == CONTENT_SETTING_ALLOW) {
352 setting == CONTENT_SETTING_ALLOW &&
353 setting_is_wildcard) {
354 // In the corner case of unrecognized plugins (which are now blocked by
355 // default) we indicate the blocked state in the UI and allow the user to
356 // whitelist.
357 radio_group.default_item = 1;
358 } else if (setting == CONTENT_SETTING_ALLOW) {
359 radio_group.default_item = kAllowButtonIndex; 374 radio_group.default_item = kAllowButtonIndex;
360 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. 375 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
361 } else { 376 } else {
362 radio_group.default_item = 1; 377 radio_group.default_item = 1;
363 block_setting_ = setting; 378 block_setting_ = setting;
364 } 379 }
365 380
366 set_setting_is_managed(setting_source != SETTING_SOURCE_USER); 381 set_setting_is_managed(setting_source != SETTING_SOURCE_USER);
367 if (setting_source != SETTING_SOURCE_USER) { 382 if (setting_source != SETTING_SOURCE_USER) {
368 set_radio_group_enabled(false); 383 set_radio_group_enabled(false);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 if (!web_contents()) 439 if (!web_contents())
425 return; 440 return;
426 content::NotificationService::current()->Notify( 441 content::NotificationService::current()->Notify(
427 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, 442 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
428 content::Source<TabSpecificContentSettings>( 443 content::Source<TabSpecificContentSettings>(
429 TabSpecificContentSettings::FromWebContents(web_contents())), 444 TabSpecificContentSettings::FromWebContents(web_contents())),
430 content::NotificationService::NoDetails()); 445 content::NotificationService::NoDetails());
431 delegate()->ShowCollectedCookiesDialog(web_contents()); 446 delegate()->ShowCollectedCookiesDialog(web_contents());
432 } 447 }
433 448
434 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { 449 class ContentSettingPluginBubbleModel : public ContentSettingTitleAndLinkModel {
435 public: 450 public:
436 ContentSettingPluginBubbleModel(Delegate* delegate, 451 ContentSettingPluginBubbleModel(Delegate* delegate,
437 WebContents* web_contents, 452 WebContents* web_contents,
438 Profile* profile, 453 Profile* profile,
439 ContentSettingsType content_type); 454 ContentSettingsType content_type);
440 455
441 virtual ~ContentSettingPluginBubbleModel(); 456 virtual ~ContentSettingPluginBubbleModel();
442 457
443 private: 458 private:
444 virtual void OnCustomLinkClicked() OVERRIDE; 459 void SetRadioGroup();
460 void SetLearnMoreLink();
461
462 // Cookie bubble implementation
463 virtual void OnRadioClicked(int radio_index) OVERRIDE;
464
465 // Function to load plugins
466 void OnRunPlugins();
467
468 bool settings_changed() const;
469 int selected_item() const { return selected_item_; }
470
471 ContentSetting block_setting_;
472 int selected_item_;
473 int kAllowOnceButtonIndex;
445 }; 474 };
446 475
447 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( 476 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel(
448 Delegate* delegate, 477 Delegate* delegate,
449 WebContents* web_contents, 478 WebContents* web_contents,
450 Profile* profile, 479 Profile* profile,
451 ContentSettingsType content_type) 480 ContentSettingsType content_type)
452 : ContentSettingSingleRadioGroup( 481 : ContentSettingTitleAndLinkModel(
453 delegate, web_contents, profile, content_type) { 482 delegate, web_contents, profile,content_type),
483 block_setting_(CONTENT_SETTING_BLOCK),
484 selected_item_(0),
485 kAllowOnceButtonIndex(1) {
454 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); 486 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS);
455 // Disable the "Run all plugins this time" link if the setting is managed and 487 SetRadioGroup();
456 // can't be controlled by the user or if the user already clicked on the link 488 // Todo(radhikabhar): Should be removed when the new NPAPI UI sets in
457 // and ran all plugins. 489 // set_custom_link_enabled(!setting_is_managed() &&
458 set_custom_link_enabled(!setting_is_managed() && 490 // web_contents &&
459 web_contents && 491 // TabSpecificContentSettings::FromWebContents(
460 TabSpecificContentSettings::FromWebContents( 492 // web_contents)->load_plugins_link_enabled())
461 web_contents)->load_plugins_link_enabled());
462 } 493 }
463 494
464 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { 495 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() {
496 // If the user elected to allow all plugins then run plugins at this time.
465 if (settings_changed()) { 497 if (settings_changed()) {
466 // If the user elected to allow all plugins then run plugins at this time. 498 ContentSetting setting;
467 if (selected_item() == kAllowButtonIndex) 499 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) {
468 OnCustomLinkClicked(); 500 if (selected_item_ == kAllowButtonIndex) {
501 setting = CONTENT_SETTING_ALLOW;
502 OnRunPlugins();
503 } else if (selected_item_ == kAllowOnceButtonIndex) {
504 setting = CONTENT_SETTING_DEFAULT;
505 OnRunPlugins();
506 } else {
507 setting = block_setting_;
508 }
509 TabSpecificContentSettings::FromWebContents(web_contents())->
510 set_plugin_bubble_setting(setting);
511 if (profile()) {
512 profile()->GetHostContentSettingsMap()->AddExceptionForURL(
513 bubble_content().radio_group.url,
514 bubble_content().radio_group.url,
515 content_type(),
516 setting);
517 }
518 }
469 } 519 }
470 } 520 }
471 521
472 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { 522 bool ContentSettingPluginBubbleModel::settings_changed() const {
523 return selected_item_ != bubble_content().radio_group.default_item;
524 }
525
526 void ContentSettingPluginBubbleModel::OnRadioClicked(int radio_index) {
527 selected_item_ = radio_index;
528 }
529
530 void ContentSettingPluginBubbleModel::SetRadioGroup() {
531 GURL url = web_contents()->GetURL();
532 TabSpecificContentSettings* content_settings =
533 TabSpecificContentSettings::FromWebContents(web_contents());
534 bool allowed =
535 !content_settings->IsContentBlocked(content_type());
536 DCHECK(!allowed ||
537 content_settings->IsContentAllowed(content_type()));
538 RadioGroup radio_group;
539 radio_group.url = url;
540
541 std::string radio_allow_label =
542 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_UNBLOCK_ALL);
543 std::string radio_allow_once_label =
544 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL);
545 std::string radio_block_label =
546 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_NO_ACTION);
547
548 radio_group.radio_items.push_back(radio_allow_label);
549 radio_group.radio_items.push_back(radio_allow_once_label);
550 radio_group.radio_items.push_back(radio_block_label);
551
552 ContentSetting setting;
553 SettingSource setting_source = SETTING_SOURCE_NONE;
554 bool setting_is_wildcard = false;
555 SettingInfo info;
556 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
557 scoped_ptr<base::Value> value(map->GetWebsiteSetting(
558 url, url, content_type(), std::string(), &info));
559 setting = content_settings->plugin_bubble_setting();
560 setting_source = info.source;
561 setting_is_wildcard =
562 info.primary_pattern == ContentSettingsPattern::Wildcard() &&
563 info.secondary_pattern == ContentSettingsPattern::Wildcard();
564
565 if (setting == CONTENT_SETTING_ALLOW &&
566 setting_is_wildcard) {
567 // In the corner case of unrecognized plugins (which are now blocked by
568 // default) we indicate the blocked state in the UI and allow the user to
569 // whitelist.
570 radio_group.default_item = 2;
571 } else if ( setting == CONTENT_SETTING_ALLOW) {
572 radio_group.default_item = kAllowButtonIndex;
573 } else if (setting == CONTENT_SETTING_DEFAULT) {
574 radio_group.default_item = kAllowOnceButtonIndex;
575 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
576 } else {
577 radio_group.default_item = 2;
578 block_setting_ = setting;
579 }
580
581 set_setting_is_managed(setting_source != SETTING_SOURCE_USER);
582 if (setting_source != SETTING_SOURCE_USER) {
583 set_radio_group_enabled(false);
584 } else {
585 set_radio_group_enabled(true);
586 }
587 selected_item_ = radio_group.default_item;
588 set_radio_group(radio_group);
589 }
590
591 void ContentSettingPluginBubbleModel::OnRunPlugins() {
473 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); 592 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
474 DCHECK(web_contents()); 593 DCHECK(web_contents());
475 #if defined(ENABLE_PLUGINS) 594 #if defined(ENABLE_PLUGINS)
476 // TODO(bauerb): We should send the identifiers of blocked plug-ins here. 595 // TODO(bauerb): We should send the identifiers of blocked plug-ins here.
477 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( 596 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
478 web_contents(), true, std::string()); 597 web_contents(), true, std::string());
479 #endif 598 #endif
480 set_custom_link_enabled(false); 599 // Todo(radhikabhar): Should be removed when the new NPAPI UI sets in
481 TabSpecificContentSettings::FromWebContents(web_contents())-> 600 // set_custom_link_enabled(false);
482 set_load_plugins_link_enabled(false); 601 // TabSpecificContentSettings::FromWebContents(web_contents())->
602 // set_load_plugins_link_enabled(false);
483 } 603 }
484 604
485 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { 605 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup {
486 public: 606 public:
487 ContentSettingPopupBubbleModel(Delegate* delegate, 607 ContentSettingPopupBubbleModel(Delegate* delegate,
488 WebContents* web_contents, 608 WebContents* web_contents,
489 Profile* profile, 609 Profile* profile,
490 ContentSettingsType content_type); 610 ContentSettingsType content_type);
491 virtual ~ContentSettingPopupBubbleModel() {} 611 virtual ~ContentSettingPopupBubbleModel() {}
492 612
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 1426 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
1307 DCHECK_EQ(web_contents_, 1427 DCHECK_EQ(web_contents_,
1308 content::Source<WebContents>(source).ptr()); 1428 content::Source<WebContents>(source).ptr());
1309 web_contents_ = NULL; 1429 web_contents_ = NULL;
1310 } else { 1430 } else {
1311 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 1431 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
1312 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 1432 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
1313 profile_ = NULL; 1433 profile_ = NULL;
1314 } 1434 }
1315 } 1435 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698