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

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

Issue 2552343005: [HBD] Remove radio buttons from the Plugins Blocked Omnibox popup. (Closed)
Patch Set: remove unneeded variable Created 4 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (delegate()) 186 if (delegate())
187 delegate()->ShowContentSettingsPage(content_type()); 187 delegate()->ShowContentSettingsPage(content_type());
188 188
189 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) { 189 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) {
190 content_settings::RecordPluginsAction( 190 content_settings::RecordPluginsAction(
191 content_settings::PLUGINS_ACTION_CLICKED_MANAGE_PLUGIN_BLOCKING); 191 content_settings::PLUGINS_ACTION_CLICKED_MANAGE_PLUGIN_BLOCKING);
192 } 192 }
193 } 193 }
194 194
195 void ContentSettingSimpleBubbleModel::SetCustomLink() { 195 void ContentSettingSimpleBubbleModel::SetCustomLink() {
196 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS) {
197 HostContentSettingsMap* map =
198 HostContentSettingsMapFactory::GetForProfile(profile());
199 GURL url = web_contents()->GetURL();
200 std::unique_ptr<base::Value> value = map->GetWebsiteSetting(
201 url, url, content_type(), std::string(), nullptr);
202 ContentSetting setting =
203 content_settings::ValueToContentSetting(value.get());
204
205 // When Flash has been hidden from the plugin list, it is impossible to
206 // dynamically load all the plugins on the page.
207 if (setting == CONTENT_SETTING_BLOCK &&
208 PluginUtils::ShouldPreferHtmlOverPlugins(map)) {
209 return;
210 }
211
212 set_custom_link(l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL));
213 return;
214 }
215
216 static const ContentSettingsTypeIdEntry kCustomIDs[] = { 196 static const ContentSettingsTypeIdEntry kCustomIDs[] = {
217 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO}, 197 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO},
218 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON}, 198 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON},
219 }; 199 };
220 int custom_link_id = 200 int custom_link_id =
221 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type()); 201 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type());
222 if (custom_link_id) 202 if (custom_link_id)
223 set_custom_link(l10n_util::GetStringUTF8(custom_link_id)); 203 set_custom_link(l10n_util::GetStringUTF8(custom_link_id));
224 } 204 }
225 205
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } else { 329 } else {
350 radio_block_label = l10n_util::GetStringUTF8( 330 radio_block_label = l10n_util::GetStringUTF8(
351 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs), 331 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs),
352 content_type())); 332 content_type()));
353 } 333 }
354 334
355 radio_group.radio_items.push_back(radio_allow_label); 335 radio_group.radio_items.push_back(radio_allow_label);
356 radio_group.radio_items.push_back(radio_block_label); 336 radio_group.radio_items.push_back(radio_block_label);
357 ContentSetting setting; 337 ContentSetting setting;
358 SettingSource setting_source = SETTING_SOURCE_NONE; 338 SettingSource setting_source = SETTING_SOURCE_NONE;
359 bool setting_is_wildcard = false;
360 339
361 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { 340 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) {
362 content_settings::CookieSettings* cookie_settings = 341 content_settings::CookieSettings* cookie_settings =
363 CookieSettingsFactory::GetForProfile(profile()).get(); 342 CookieSettingsFactory::GetForProfile(profile()).get();
364 cookie_settings->GetCookieSetting(url, url, &setting_source, nullptr, 343 cookie_settings->GetCookieSetting(url, url, &setting_source, nullptr,
365 &setting); 344 &setting);
366 } else { 345 } else {
367 SettingInfo info; 346 SettingInfo info;
368 HostContentSettingsMap* map = 347 HostContentSettingsMap* map =
369 HostContentSettingsMapFactory::GetForProfile(profile()); 348 HostContentSettingsMapFactory::GetForProfile(profile());
370 std::unique_ptr<base::Value> value = 349 std::unique_ptr<base::Value> value =
371 map->GetWebsiteSetting(url, url, content_type(), std::string(), &info); 350 map->GetWebsiteSetting(url, url, content_type(), std::string(), &info);
372 setting = content_settings::ValueToContentSetting(value.get()); 351 setting = content_settings::ValueToContentSetting(value.get());
373 setting_source = info.source; 352 setting_source = info.source;
374 setting_is_wildcard =
375 info.primary_pattern == ContentSettingsPattern::Wildcard() &&
376 info.secondary_pattern == ContentSettingsPattern::Wildcard();
377 } 353 }
378 354
379 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && 355 if (setting == CONTENT_SETTING_ALLOW) {
380 setting == CONTENT_SETTING_ALLOW &&
381 setting_is_wildcard) {
382 // In the corner case of unrecognized plugins (which are now blocked by
383 // default) we indicate the blocked state in the UI and allow the user to
384 // whitelist.
385 radio_group.default_item = 1;
386 } else if (setting == CONTENT_SETTING_ALLOW) {
387 radio_group.default_item = kAllowButtonIndex; 356 radio_group.default_item = kAllowButtonIndex;
388 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. 357 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|.
389 } else { 358 } else {
390 radio_group.default_item = 1; 359 radio_group.default_item = 1;
391 block_setting_ = setting; 360 block_setting_ = setting;
392 } 361 }
393 362
394 set_setting_is_managed(setting_source != SETTING_SOURCE_USER &&
395 setting != CONTENT_SETTING_ASK);
396
397 // When Flash has been hidden from the plugin list, it is impossible to
398 // dynamically load all the plugins on the page. Then the radio group would
399 // appear to do nothing. The user must go to Content Settings to enable Flash.
400 bool flash_hidden_from_plugin_list =
401 content_type() == CONTENT_SETTINGS_TYPE_PLUGINS &&
402 setting == CONTENT_SETTING_BLOCK &&
403 PluginUtils::ShouldPreferHtmlOverPlugins(
404 HostContentSettingsMapFactory::GetForProfile(profile()));
405
406 const auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); 363 const auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
407 // Prevent creation of content settings for illegal urls like about:blank 364 // Prevent creation of content settings for illegal urls like about:blank
408 bool is_valid = map->CanSetNarrowestContentSetting(url, url, content_type()); 365 bool is_valid = map->CanSetNarrowestContentSetting(url, url, content_type());
409 366
410 set_radio_group_enabled(is_valid && setting_source == SETTING_SOURCE_USER && 367 set_radio_group_enabled(is_valid && setting_source == SETTING_SOURCE_USER);
411 !flash_hidden_from_plugin_list);
412 368
413 selected_item_ = radio_group.default_item; 369 selected_item_ = radio_group.default_item;
414 set_radio_group(radio_group); 370 set_radio_group(radio_group);
415 } 371 }
416 372
417 void ContentSettingSingleRadioGroup::SetNarrowestContentSetting( 373 void ContentSettingSingleRadioGroup::SetNarrowestContentSetting(
418 ContentSetting setting) { 374 ContentSetting setting) {
419 if (!profile()) 375 if (!profile())
420 return; 376 return;
421 377
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 content::NotificationService::current()->Notify( 426 content::NotificationService::current()->Notify(
471 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, 427 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN,
472 content::Source<TabSpecificContentSettings>( 428 content::Source<TabSpecificContentSettings>(
473 TabSpecificContentSettings::FromWebContents(web_contents())), 429 TabSpecificContentSettings::FromWebContents(web_contents())),
474 content::NotificationService::NoDetails()); 430 content::NotificationService::NoDetails());
475 delegate()->ShowCollectedCookiesDialog(web_contents()); 431 delegate()->ShowCollectedCookiesDialog(web_contents());
476 } 432 }
477 433
478 // ContentSettingPluginBubbleModel --------------------------------------------- 434 // ContentSettingPluginBubbleModel ---------------------------------------------
479 435
480 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { 436 class ContentSettingPluginBubbleModel : public ContentSettingSimpleBubbleModel {
481 public: 437 public:
482 ContentSettingPluginBubbleModel(Delegate* delegate, 438 ContentSettingPluginBubbleModel(Delegate* delegate,
483 WebContents* web_contents, 439 WebContents* web_contents,
484 Profile* profile); 440 Profile* profile);
485 441
486 ~ContentSettingPluginBubbleModel() override;
487
488 private: 442 private:
489 void OnLearnMoreLinkClicked() override; 443 void OnLearnMoreLinkClicked() override;
490 void OnCustomLinkClicked() override; 444 void OnCustomLinkClicked() override;
491 445
492 void RunPluginsOnPage(); 446 void RunPluginsOnPage();
493 447
494 DISALLOW_COPY_AND_ASSIGN(ContentSettingPluginBubbleModel); 448 DISALLOW_COPY_AND_ASSIGN(ContentSettingPluginBubbleModel);
495 }; 449 };
496 450
497 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( 451 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel(
498 Delegate* delegate, 452 Delegate* delegate,
499 WebContents* web_contents, 453 WebContents* web_contents,
500 Profile* profile) 454 Profile* profile)
501 : ContentSettingSingleRadioGroup(delegate, 455 : ContentSettingSimpleBubbleModel(delegate,
502 web_contents, 456 web_contents,
503 profile, 457 profile,
504 CONTENT_SETTINGS_TYPE_PLUGINS) { 458 CONTENT_SETTINGS_TYPE_PLUGINS) {
505 // Disable the "Run all plugins this time" link if the setting is managed and 459 SettingInfo info;
506 // can't be controlled by the user or if the user already clicked on the link 460 HostContentSettingsMap* map =
507 // and ran all plugins. 461 HostContentSettingsMapFactory::GetForProfile(profile);
508 set_custom_link_enabled(!setting_is_managed() && 462 GURL url = web_contents->GetURL();
509 web_contents && 463 std::unique_ptr<base::Value> value =
510 TabSpecificContentSettings::FromWebContents( 464 map->GetWebsiteSetting(url, url, content_type(), std::string(), &info);
511 web_contents)->load_plugins_link_enabled()); 465 ContentSetting setting = content_settings::ValueToContentSetting(value.get());
466
467 // If the setting is not managed by the user, hide the "Manage..." link.
468 if (info.source != SETTING_SOURCE_USER)
469 set_manage_text(std::string());
470
471 // The user cannot manually run Flash on the BLOCK setting when either holds:
472 // - The setting is from Policy. User cannot override admin intent.
473 // - HTML By Default is on - Flash has been hidden from the plugin list, so
474 // it's impossible to dynamically run the nonexistent plugin.
475 bool run_blocked = setting == CONTENT_SETTING_BLOCK &&
476 (info.source != SETTING_SOURCE_USER ||
477 PluginUtils::ShouldPreferHtmlOverPlugins(map));
478
479 if (!run_blocked) {
480 set_custom_link(l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL));
481 // Disable the "Run all plugins this time" link if the user already clicked
482 // on the link and ran all plugins.
483 set_custom_link_enabled(
484 web_contents &&
485 TabSpecificContentSettings::FromWebContents(web_contents)
486 ->load_plugins_link_enabled());
487 }
488
512 // Build blocked plugin list. 489 // Build blocked plugin list.
513 if (web_contents) { 490 if (web_contents) {
514 TabSpecificContentSettings* content_settings = 491 TabSpecificContentSettings* content_settings =
515 TabSpecificContentSettings::FromWebContents(web_contents); 492 TabSpecificContentSettings::FromWebContents(web_contents);
516 493
517 const std::vector<base::string16>& blocked_plugins = 494 const std::vector<base::string16>& blocked_plugins =
518 content_settings->blocked_plugin_names(); 495 content_settings->blocked_plugin_names();
519 for (const base::string16& blocked_plugin : blocked_plugins) { 496 for (const base::string16& blocked_plugin : blocked_plugins) {
520 ListItem plugin_item( 497 ListItem plugin_item(
521 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 498 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
522 IDR_BLOCKED_PLUGINS), 499 IDR_BLOCKED_PLUGINS),
523 base::UTF16ToUTF8(blocked_plugin), false, 0); 500 base::UTF16ToUTF8(blocked_plugin), false, 0);
524 add_list_item(plugin_item); 501 add_list_item(plugin_item);
525 } 502 }
526 } 503 }
527 504
528 set_learn_more_link(l10n_util::GetStringUTF8(IDS_LEARN_MORE)); 505 set_learn_more_link(l10n_util::GetStringUTF8(IDS_LEARN_MORE));
529 506
530 content_settings::RecordPluginsAction( 507 content_settings::RecordPluginsAction(
531 content_settings::PLUGINS_ACTION_DISPLAYED_BUBBLE); 508 content_settings::PLUGINS_ACTION_DISPLAYED_BUBBLE);
532 } 509 }
533 510
534 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() {
535 // If the user elected to allow all plugins then run plugins at this time.
536 if (settings_changed() && selected_item() == kAllowButtonIndex) {
537 content_settings::RecordPluginsAction(
538 content_settings::
539 PLUGINS_ACTION_CLICKED_ALWAYS_ALLOW_PLUGINS_ON_ORIGIN);
540 rappor::SampleDomainAndRegistryFromGURL(
541 rappor_service(), "ContentSettings.Plugins.AddedAllowException",
542 web_contents()->GetLastCommittedURL());
543
544 RunPluginsOnPage();
545 }
546 }
547
548 void ContentSettingPluginBubbleModel::OnLearnMoreLinkClicked() { 511 void ContentSettingPluginBubbleModel::OnLearnMoreLinkClicked() {
549 if (delegate()) 512 if (delegate())
550 delegate()->ShowLearnMorePage(CONTENT_SETTINGS_TYPE_PLUGINS); 513 delegate()->ShowLearnMorePage(CONTENT_SETTINGS_TYPE_PLUGINS);
551 514
552 content_settings::RecordPluginsAction( 515 content_settings::RecordPluginsAction(
553 content_settings::PLUGINS_ACTION_CLICKED_LEARN_MORE); 516 content_settings::PLUGINS_ACTION_CLICKED_LEARN_MORE);
554 } 517 }
555 518
556 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { 519 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() {
557 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); 520 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble"));
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 NOTREACHED() << "No bubble for the content type " << content_type << "."; 1371 NOTREACHED() << "No bubble for the content type " << content_type << ".";
1409 return nullptr; 1372 return nullptr;
1410 } 1373 }
1411 1374
1412 ContentSettingBubbleModel::ContentSettingBubbleModel(Delegate* delegate, 1375 ContentSettingBubbleModel::ContentSettingBubbleModel(Delegate* delegate,
1413 WebContents* web_contents, 1376 WebContents* web_contents,
1414 Profile* profile) 1377 Profile* profile)
1415 : web_contents_(web_contents), 1378 : web_contents_(web_contents),
1416 profile_(profile), 1379 profile_(profile),
1417 delegate_(delegate), 1380 delegate_(delegate),
1418 setting_is_managed_(false),
1419 rappor_service_(g_browser_process->rappor_service()) { 1381 rappor_service_(g_browser_process->rappor_service()) {
1420 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 1382 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1421 content::Source<WebContents>(web_contents)); 1383 content::Source<WebContents>(web_contents));
1422 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 1384 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
1423 content::Source<Profile>(profile_)); 1385 content::Source<Profile>(profile_));
1424 } 1386 }
1425 1387
1426 ContentSettingBubbleModel::~ContentSettingBubbleModel() { 1388 ContentSettingBubbleModel::~ContentSettingBubbleModel() {
1427 } 1389 }
1428 1390
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 ContentSettingMediaStreamBubbleModel* 1437 ContentSettingMediaStreamBubbleModel*
1476 ContentSettingBubbleModel::AsMediaStreamBubbleModel() { 1438 ContentSettingBubbleModel::AsMediaStreamBubbleModel() {
1477 // In general, bubble models might not inherit from the media bubble model. 1439 // In general, bubble models might not inherit from the media bubble model.
1478 return nullptr; 1440 return nullptr;
1479 } 1441 }
1480 1442
1481 ContentSettingSubresourceFilterBubbleModel* 1443 ContentSettingSubresourceFilterBubbleModel*
1482 ContentSettingBubbleModel::AsSubresourceFilterBubbleModel() { 1444 ContentSettingBubbleModel::AsSubresourceFilterBubbleModel() {
1483 return nullptr; 1445 return nullptr;
1484 } 1446 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698