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