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

Side by Side Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 7831075: Delegating the "are images allowed" decision to renderer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Test build fixes. Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/webui/options/content_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/content_settings/content_settings_details.h" 17 #include "chrome/browser/content_settings/content_settings_details.h"
18 #include "chrome/browser/content_settings/content_settings_utils.h" 18 #include "chrome/browser/content_settings/content_settings_utils.h"
19 #include "chrome/browser/content_settings/host_content_settings_map.h" 19 #include "chrome/browser/content_settings/host_content_settings_map.h"
20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
21 #include "chrome/browser/notifications/desktop_notification_service.h" 21 #include "chrome/browser/notifications/desktop_notification_service.h"
22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/content_settings.h"
27 #include "chrome/common/content_settings_pattern.h" 28 #include "chrome/common/content_settings_pattern.h"
28 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "content/browser/tab_contents/tab_contents.h" 31 #include "content/browser/tab_contents/tab_contents.h"
31 #include "content/common/notification_service.h" 32 #include "content/common/notification_service.h"
32 #include "content/common/notification_source.h" 33 #include "content/common/notification_source.h"
33 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
34 #include "content/public/common/content_switches.h" 35 #include "content/public/common/content_switches.h"
35 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
36 #include "grit/locale_settings.h" 37 #include "grit/locale_settings.h"
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 default: 464 default:
464 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 465 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
465 break; 466 break;
466 } 467 }
467 } 468 }
468 469
469 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { 470 void ContentSettingsHandler::UpdateGeolocationExceptionsView() {
470 Profile* profile = Profile::FromWebUI(web_ui_); 471 Profile* profile = Profile::FromWebUI(web_ui_);
471 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 472 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
472 473
473 HostContentSettingsMap::SettingsForOneType all_settings; 474 ContentSettingsForOneType all_settings;
474 map->GetSettingsForOneType( 475 map->GetSettingsForOneType(
475 CONTENT_SETTINGS_TYPE_GEOLOCATION, 476 CONTENT_SETTINGS_TYPE_GEOLOCATION,
476 std::string(), 477 std::string(),
477 &all_settings); 478 &all_settings);
478 479
479 // Group geolocation settings by primary_pattern. 480 // Group geolocation settings by primary_pattern.
480 AllPatternsSettings all_patterns_settings; 481 AllPatternsSettings all_patterns_settings;
481 for (HostContentSettingsMap::SettingsForOneType::iterator i = 482 for (ContentSettingsForOneType::iterator i =
482 all_settings.begin(); 483 all_settings.begin();
483 i != all_settings.end(); 484 i != all_settings.end();
484 ++i) { 485 ++i) {
485 all_patterns_settings[i->a][i->b] = i->c; 486 all_patterns_settings[i->primary_pattern][i->secondary_pattern] = i->setting ;
486 } 487 }
487 488
488 ListValue exceptions; 489 ListValue exceptions;
489 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); 490 for (AllPatternsSettings::iterator i = all_patterns_settings.begin();
490 i != all_patterns_settings.end(); 491 i != all_patterns_settings.end();
491 ++i) { 492 ++i) {
492 const ContentSettingsPattern& primary_pattern = i->first; 493 const ContentSettingsPattern& primary_pattern = i->first;
493 const OnePatternSettings& one_settings = i->second; 494 const OnePatternSettings& one_settings = i->second;
494 495
495 OnePatternSettings::const_iterator parent = 496 OnePatternSettings::const_iterator parent =
(...skipping 27 matching lines...) Expand all
523 // This is mainly here to keep this function ideologically parallel to 524 // This is mainly here to keep this function ideologically parallel to
524 // UpdateExceptionsViewFromHostContentSettingsMap(). 525 // UpdateExceptionsViewFromHostContentSettingsMap().
525 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); 526 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
526 } 527 }
527 528
528 void ContentSettingsHandler::UpdateNotificationExceptionsView() { 529 void ContentSettingsHandler::UpdateNotificationExceptionsView() {
529 Profile* profile = Profile::FromWebUI(web_ui_); 530 Profile* profile = Profile::FromWebUI(web_ui_);
530 DesktopNotificationService* service = 531 DesktopNotificationService* service =
531 DesktopNotificationServiceFactory::GetForProfile(profile); 532 DesktopNotificationServiceFactory::GetForProfile(profile);
532 533
533 HostContentSettingsMap::SettingsForOneType settings; 534 ContentSettingsForOneType settings;
534 service->GetNotificationsSettings(&settings); 535 service->GetNotificationsSettings(&settings);
535 536
536 ListValue exceptions; 537 ListValue exceptions;
537 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = 538 for (ContentSettingsForOneType::const_iterator i =
538 settings.begin(); 539 settings.begin();
539 i != settings.end(); 540 i != settings.end();
540 ++i) { 541 ++i) {
541 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i);
542 exceptions.Append( 542 exceptions.Append(
543 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); 543 GetNotificationExceptionForPage(i->primary_pattern, i->setting,
544 i->source));
544 } 545 }
545 546
546 StringValue type_string( 547 StringValue type_string(
547 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); 548 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
548 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", 549 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions",
549 type_string, exceptions); 550 type_string, exceptions);
550 551
551 // This is mainly here to keep this function ideologically parallel to 552 // This is mainly here to keep this function ideologically parallel to
552 // UpdateExceptionsViewFromHostContentSettingsMap(). 553 // UpdateExceptionsViewFromHostContentSettingsMap().
553 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 554 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
554 } 555 }
555 556
556 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( 557 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap(
557 ContentSettingsType type) { 558 ContentSettingsType type) {
558 HostContentSettingsMap::SettingsForOneType entries; 559 ContentSettingsForOneType entries;
559 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); 560 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries);
560 561
561 ListValue exceptions; 562 ListValue exceptions;
562 for (size_t i = 0; i < entries.size(); ++i) { 563 for (size_t i = 0; i < entries.size(); ++i) {
563 // The content settings UI does not support secondary content settings 564 // The content settings UI does not support secondary content settings
564 // pattern yet. For content settings set through the content settings UI the 565 // pattern yet. For content settings set through the content settings UI the
565 // secondary pattern is by default a wildcard pattern. Hence users are not 566 // secondary pattern is by default a wildcard pattern. Hence users are not
566 // able to modify content settings with a secondary pattern other than the 567 // able to modify content settings with a secondary pattern other than the
567 // wildcard pattern. So only show settings that the user is able to modify. 568 // wildcard pattern. So only show settings that the user is able to modify.
568 // TODO(bauerb): Support a read-only view for those patterns. 569 // TODO(bauerb): Support a read-only view for those patterns.
569 if (entries[i].b == ContentSettingsPattern::Wildcard()) { 570 if (entries[i].secondary_pattern == ContentSettingsPattern::Wildcard()) {
570 exceptions.Append( 571 exceptions.Append(
571 GetExceptionForPage(entries[i].a, entries[i].c, entries[i].d)); 572 GetExceptionForPage(entries[i].primary_pattern, entries[i].setting,
573 entries[i].source));
572 } else { 574 } else {
573 LOG(ERROR) << "Secondary content settings patterns are not " 575 LOG(ERROR) << "Secondary content settings patterns are not "
574 << "supported by the content settings UI"; 576 << "supported by the content settings UI";
575 } 577 }
576 } 578 }
577 579
578 StringValue type_string(ContentSettingsTypeToGroupName(type)); 580 StringValue type_string(ContentSettingsTypeToGroupName(type));
579 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", type_string, 581 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", type_string,
580 exceptions); 582 exceptions);
581 583
582 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 584 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
583 585
584 // The default may also have changed (we won't get a separate notification). 586 // The default may also have changed (we won't get a separate notification).
585 // If it hasn't changed, this call will be harmless. 587 // If it hasn't changed, this call will be harmless.
586 UpdateSettingDefaultFromModel(type); 588 UpdateSettingDefaultFromModel(type);
587 } 589 }
588 590
589 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( 591 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap(
590 ContentSettingsType type) { 592 ContentSettingsType type) {
591 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); 593 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap();
592 if (!otr_settings_map) 594 if (!otr_settings_map)
593 return; 595 return;
594 596
595 HostContentSettingsMap::SettingsForOneType otr_entries; 597 ContentSettingsForOneType otr_entries;
596 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); 598 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries);
597 599
598 ListValue otr_exceptions; 600 ListValue otr_exceptions;
599 for (size_t i = 0; i < otr_entries.size(); ++i) { 601 for (size_t i = 0; i < otr_entries.size(); ++i) {
600 // Off-the-record HostContentSettingsMap contains incognito content settings 602 // Off-the-record HostContentSettingsMap contains incognito content settings
601 // as well as normal content settings. Here, we use the incongnito settings 603 // as well as normal content settings. Here, we use the incongnito settings
602 // only. 604 // only.
603 if (!otr_entries[i].e) 605 if (!otr_entries[i].incognito)
604 continue; 606 continue;
605 // The content settings UI does not support secondary content settings 607 // The content settings UI does not support secondary content settings
606 // pattern yet. For content settings set through the content settings UI the 608 // pattern yet. For content settings set through the content settings UI the
607 // secondary pattern is by default a wildcard pattern. Hence users are not 609 // secondary pattern is by default a wildcard pattern. Hence users are not
608 // able to modify content settings with a secondary pattern other than the 610 // able to modify content settings with a secondary pattern other than the
609 // wildcard pattern. So only show settings that the user is able to modify. 611 // wildcard pattern. So only show settings that the user is able to modify.
610 // TODO(bauerb): Support a read-only view for those patterns. 612 // TODO(bauerb): Support a read-only view for those patterns.
611 if (otr_entries[i].b == ContentSettingsPattern::Wildcard()) { 613 if (otr_entries[i].secondary_pattern ==
614 ContentSettingsPattern::Wildcard()) {
612 otr_exceptions.Append( 615 otr_exceptions.Append(
613 GetExceptionForPage(otr_entries[i].a, 616 GetExceptionForPage(otr_entries[i].primary_pattern,
614 otr_entries[i].c, 617 otr_entries[i].setting,
615 otr_entries[i].d)); 618 otr_entries[i].source));
616 } else { 619 } else {
617 LOG(ERROR) << "Secondary content settings patterns are not " 620 LOG(ERROR) << "Secondary content settings patterns are not "
618 << "supported by the content settings UI"; 621 << "supported by the content settings UI";
619 } 622 }
620 } 623 }
621 624
622 StringValue type_string(ContentSettingsTypeToGroupName(type)); 625 StringValue type_string(ContentSettingsTypeToGroupName(type));
623 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions", 626 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions",
624 type_string, otr_exceptions); 627 type_string, otr_exceptions);
625 } 628 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); 800 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry();
798 } 801 }
799 802
800 HostContentSettingsMap* 803 HostContentSettingsMap*
801 ContentSettingsHandler::GetOTRContentSettingsMap() { 804 ContentSettingsHandler::GetOTRContentSettingsMap() {
802 Profile* profile = Profile::FromWebUI(web_ui_); 805 Profile* profile = Profile::FromWebUI(web_ui_);
803 if (profile->HasOffTheRecordProfile()) 806 if (profile->HasOffTheRecordProfile())
804 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 807 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
805 return NULL; 808 return NULL;
806 } 809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698