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

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: More code review comments. Created 9 years, 3 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/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/content_settings/content_settings_details.h" 16 #include "chrome/browser/content_settings/content_settings_details.h"
17 #include "chrome/browser/content_settings/content_settings_provider.h"
17 #include "chrome/browser/content_settings/content_settings_utils.h" 18 #include "chrome/browser/content_settings/content_settings_utils.h"
18 #include "chrome/browser/content_settings/host_content_settings_map.h" 19 #include "chrome/browser/content_settings/host_content_settings_map.h"
19 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 20 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
20 #include "chrome/browser/notifications/desktop_notification_service.h" 21 #include "chrome/browser/notifications/desktop_notification_service.h"
21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
22 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/content_settings_pattern.h" 27 #include "chrome/common/content_settings_pattern.h"
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 default: 445 default:
445 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 446 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
446 break; 447 break;
447 } 448 }
448 } 449 }
449 450
450 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { 451 void ContentSettingsHandler::UpdateGeolocationExceptionsView() {
451 Profile* profile = Profile::FromWebUI(web_ui_); 452 Profile* profile = Profile::FromWebUI(web_ui_);
452 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 453 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
453 454
454 HostContentSettingsMap::SettingsForOneType all_settings; 455 ContentSettingsForOneType all_settings;
455 map->GetSettingsForOneType( 456 map->GetSettingsForOneType(
456 CONTENT_SETTINGS_TYPE_GEOLOCATION, 457 CONTENT_SETTINGS_TYPE_GEOLOCATION,
457 std::string(), 458 std::string(),
459 content_settings::ProviderInterface::Rule::LexicographicalSort,
458 &all_settings); 460 &all_settings);
459 461
460 // Group geolocation settings by primary_pattern. 462 // Group geolocation settings by primary_pattern.
461 AllPatternsSettings all_patterns_settings; 463 AllPatternsSettings all_patterns_settings;
462 for (HostContentSettingsMap::SettingsForOneType::iterator i = 464 for (ContentSettingsForOneType::iterator i =
463 all_settings.begin(); 465 all_settings.begin();
464 i != all_settings.end(); 466 i != all_settings.end();
465 ++i) { 467 ++i) {
466 all_patterns_settings[i->a][i->b] = i->c; 468 all_patterns_settings[i->a][i->b] = i->c;
467 } 469 }
468 470
469 ListValue exceptions; 471 ListValue exceptions;
470 for (AllPatternsSettings::iterator i = all_patterns_settings.begin(); 472 for (AllPatternsSettings::iterator i = all_patterns_settings.begin();
471 i != all_patterns_settings.end(); 473 i != all_patterns_settings.end();
472 ++i) { 474 ++i) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // This is mainly here to keep this function ideologically parallel to 506 // This is mainly here to keep this function ideologically parallel to
505 // UpdateExceptionsViewFromHostContentSettingsMap(). 507 // UpdateExceptionsViewFromHostContentSettingsMap().
506 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); 508 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
507 } 509 }
508 510
509 void ContentSettingsHandler::UpdateNotificationExceptionsView() { 511 void ContentSettingsHandler::UpdateNotificationExceptionsView() {
510 Profile* profile = Profile::FromWebUI(web_ui_); 512 Profile* profile = Profile::FromWebUI(web_ui_);
511 DesktopNotificationService* service = 513 DesktopNotificationService* service =
512 DesktopNotificationServiceFactory::GetForProfile(profile); 514 DesktopNotificationServiceFactory::GetForProfile(profile);
513 515
514 HostContentSettingsMap::SettingsForOneType settings; 516 ContentSettingsForOneType settings;
515 service->GetNotificationsSettings(&settings); 517 service->GetNotificationsSettings(&settings);
516 518
517 ListValue exceptions; 519 ListValue exceptions;
518 for (HostContentSettingsMap::SettingsForOneType::const_iterator i = 520 for (ContentSettingsForOneType::const_iterator i =
519 settings.begin(); 521 settings.begin();
520 i != settings.end(); 522 i != settings.end();
521 ++i) { 523 ++i) {
522 const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); 524 const ContentSettingPatternSourceTuple& tuple(*i);
523 exceptions.Append( 525 exceptions.Append(
524 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d)); 526 GetNotificationExceptionForPage(tuple.a, tuple.c, tuple.d));
525 } 527 }
526 528
527 StringValue type_string( 529 StringValue type_string(
528 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); 530 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
529 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions", 531 web_ui_->CallJavascriptFunction("ContentSettings.setExceptions",
530 type_string, exceptions); 532 type_string, exceptions);
531 533
532 // This is mainly here to keep this function ideologically parallel to 534 // This is mainly here to keep this function ideologically parallel to
533 // UpdateExceptionsViewFromHostContentSettingsMap(). 535 // UpdateExceptionsViewFromHostContentSettingsMap().
534 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 536 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
535 } 537 }
536 538
537 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( 539 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap(
538 ContentSettingsType type) { 540 ContentSettingsType type) {
539 HostContentSettingsMap::SettingsForOneType entries; 541 ContentSettingsForOneType entries;
540 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); 542 GetContentSettingsMap()->GetSettingsForOneType(
543 type, "",
544 content_settings::ProviderInterface::Rule::LexicographicalSort,
545 &entries);
541 546
542 ListValue exceptions; 547 ListValue exceptions;
543 for (size_t i = 0; i < entries.size(); ++i) { 548 for (size_t i = 0; i < entries.size(); ++i) {
544 // The content settings UI does not support secondary content settings 549 // The content settings UI does not support secondary content settings
545 // pattern yet. For content settings set through the content settings UI the 550 // pattern yet. For content settings set through the content settings UI the
546 // secondary pattern is by default a wildcard pattern. Hence users are not 551 // secondary pattern is by default a wildcard pattern. Hence users are not
547 // able to modify content settings with a secondary pattern other than the 552 // able to modify content settings with a secondary pattern other than the
548 // wildcard pattern. So only show settings that the user is able to modify. 553 // wildcard pattern. So only show settings that the user is able to modify.
549 if (entries[i].b == ContentSettingsPattern::Wildcard()) { 554 if (entries[i].b == ContentSettingsPattern::Wildcard()) {
550 exceptions.Append( 555 exceptions.Append(
(...skipping 14 matching lines...) Expand all
565 // If it hasn't changed, this call will be harmless. 570 // If it hasn't changed, this call will be harmless.
566 UpdateSettingDefaultFromModel(type); 571 UpdateSettingDefaultFromModel(type);
567 } 572 }
568 573
569 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( 574 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap(
570 ContentSettingsType type) { 575 ContentSettingsType type) {
571 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); 576 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap();
572 if (!otr_settings_map) 577 if (!otr_settings_map)
573 return; 578 return;
574 579
575 HostContentSettingsMap::SettingsForOneType otr_entries; 580 ContentSettingsForOneType otr_entries;
576 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); 581 otr_settings_map->GetSettingsForOneType(
582 type, "",
583 content_settings::ProviderInterface::Rule::LexicographicalSort,
584 &otr_entries);
577 585
578 ListValue otr_exceptions; 586 ListValue otr_exceptions;
579 for (size_t i = 0; i < otr_entries.size(); ++i) { 587 for (size_t i = 0; i < otr_entries.size(); ++i) {
580 otr_exceptions.Append(GetExceptionForPage(otr_entries[i].a, 588 otr_exceptions.Append(GetExceptionForPage(otr_entries[i].a,
581 otr_entries[i].c, 589 otr_entries[i].c,
582 otr_entries[i].d)); 590 otr_entries[i].d));
583 } 591 }
584 592
585 StringValue type_string(ContentSettingsTypeToGroupName(type)); 593 StringValue type_string(ContentSettingsTypeToGroupName(type));
586 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions", 594 web_ui_->CallJavascriptFunction("ContentSettings.setOTRExceptions",
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry(); 768 return Profile::FromWebUI(web_ui_)->GetProtocolHandlerRegistry();
761 } 769 }
762 770
763 HostContentSettingsMap* 771 HostContentSettingsMap*
764 ContentSettingsHandler::GetOTRContentSettingsMap() { 772 ContentSettingsHandler::GetOTRContentSettingsMap() {
765 Profile* profile = Profile::FromWebUI(web_ui_); 773 Profile* profile = Profile::FromWebUI(web_ui_);
766 if (profile->HasOffTheRecordProfile()) 774 if (profile->HasOffTheRecordProfile())
767 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 775 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
768 return NULL; 776 return NULL;
769 } 777 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698