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

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

Issue 1447813002: Add USB devices to the content settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@get_all_objects
Patch Set: Addressed more of bauerb@'s comments. Created 5 years, 1 month 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/webui/options/content_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
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/logging.h" 14 #include "base/logging.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
23 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" 23 #include "chrome/browser/content_settings/web_site_settings_uma_util.h"
24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 24 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
25 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 25 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
26 #include "chrome/browser/extensions/extension_special_storage_policy.h" 26 #include "chrome/browser/extensions/extension_special_storage_policy.h"
27 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 27 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
28 #include "chrome/browser/permissions/chooser_context_base.h"
28 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/browser_list.h" 30 #include "chrome/browser/ui/browser_list.h"
31 #include "chrome/browser/usb/usb_chooser_context.h"
32 #include "chrome/browser/usb/usb_chooser_context_factory.h"
30 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 34 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
32 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h" 36 #include "chrome/common/url_constants.h"
34 #include "chrome/grit/generated_resources.h" 37 #include "chrome/grit/generated_resources.h"
35 #include "chrome/grit/locale_settings.h" 38 #include "chrome/grit/locale_settings.h"
36 #include "components/content_settings/core/browser/content_settings_details.h" 39 #include "components/content_settings/core/browser/content_settings_details.h"
37 #include "components/content_settings/core/browser/content_settings_utils.h" 40 #include "components/content_settings/core/browser/content_settings_utils.h"
38 #include "components/content_settings/core/browser/host_content_settings_map.h" 41 #include "components/content_settings/core/browser/host_content_settings_map.h"
39 #include "components/content_settings/core/browser/plugins_field_trial.h" 42 #include "components/content_settings/core/browser/plugins_field_trial.h"
(...skipping 22 matching lines...) Expand all
62 65
63 #if defined(OS_CHROMEOS) 66 #if defined(OS_CHROMEOS)
64 #include "components/user_manager/user_manager.h" 67 #include "components/user_manager/user_manager.h"
65 #endif 68 #endif
66 69
67 using base::UserMetricsAction; 70 using base::UserMetricsAction;
68 using content_settings::ContentSettingToString; 71 using content_settings::ContentSettingToString;
69 using content_settings::ContentSettingFromString; 72 using content_settings::ContentSettingFromString;
70 using extensions::APIPermission; 73 using extensions::APIPermission;
71 74
75 namespace options {
76
77 // This struct is declared early so that it can used by functions below.
78 struct ContentSettingsHandler::ChooserTypeNameEntry {
79 ContentSettingsType type;
80 ChooserContextBase* (*get_context)(Profile*);
81 const char* name;
82 const char* ui_name_key;
83 };
84
72 namespace { 85 namespace {
73 86
74 struct ContentSettingWithExceptions { 87 struct ContentSettingWithExceptions {
75 ContentSettingWithExceptions(bool otr, UserMetricsAction action) 88 ContentSettingWithExceptions(bool otr, UserMetricsAction action)
76 : has_otr_exceptions(otr), uma(action) {} 89 : has_otr_exceptions(otr), uma(action) {}
77 bool has_otr_exceptions; 90 bool has_otr_exceptions;
78 UserMetricsAction uma; 91 UserMetricsAction uma;
79 }; 92 };
80 93
81 struct ContentSettingsTypeNameEntry { 94 struct ContentSettingsTypeNameEntry {
82 ContentSettingsType type; 95 ContentSettingsType type;
83 const char* name; 96 const char* name;
84 }; 97 };
85 98
86 // Maps from a secondary pattern to a setting. 99 // Maps from a secondary pattern to a setting.
87 typedef std::map<ContentSettingsPattern, ContentSetting> 100 typedef std::map<ContentSettingsPattern, ContentSetting>
88 OnePatternSettings; 101 OnePatternSettings;
89 // Maps from a primary pattern/source pair to a OnePatternSettings. All the 102 // Maps from a primary pattern/source pair to a OnePatternSettings. All the
90 // mappings in OnePatternSettings share the given primary pattern and source. 103 // mappings in OnePatternSettings share the given primary pattern and source.
91 typedef std::map<std::pair<ContentSettingsPattern, std::string>, 104 typedef std::map<std::pair<ContentSettingsPattern, std::string>,
92 OnePatternSettings> 105 OnePatternSettings>
93 AllPatternsSettings; 106 AllPatternsSettings;
94 107
108 // Maps from the UI string to the object it represents (for sorting purposes).
109 typedef std::multimap<std::string, const base::DictionaryValue*> SortedObjects;
110 // Maps from a secondary URL to the set of objects it has permission to access.
111 typedef std::map<GURL, SortedObjects> OneOriginObjects;
112 // Maps from a primary URL/source pair to a OneOriginObjects. All the mappings
113 // in OneOriginObjects share the given primary URL and source.
114 typedef std::map<std::pair<GURL, std::string>, OneOriginObjects>
115 AllOriginObjects;
116
95 // The AppFilter is used in AddExceptionsGrantedByHostedApps() to choose 117 // The AppFilter is used in AddExceptionsGrantedByHostedApps() to choose
96 // extensions which should have their extent displayed. 118 // extensions which should have their extent displayed.
97 typedef bool (*AppFilter)(const extensions::Extension& app, 119 typedef bool (*AppFilter)(const extensions::Extension& app,
98 content::BrowserContext* profile); 120 content::BrowserContext* profile);
99 121
100 const char kExceptionsLearnMoreUrl[] = 122 const char kExceptionsLearnMoreUrl[] =
101 "https://support.google.com/chrome/?p=settings_manage_exceptions"; 123 "https://support.google.com/chrome/?p=settings_manage_exceptions";
102 124
103 const char kSetting[] = "setting"; 125 const char kSetting[] = "setting";
104 const char kOrigin[] = "origin"; 126 const char kOrigin[] = "origin";
105 const char kPolicyProviderId[] = "policy"; 127 const char kPolicyProviderId[] = "policy";
106 const char kSource[] = "source"; 128 const char kSource[] = "source";
107 const char kAppName[] = "appName"; 129 const char kAppName[] = "appName";
108 const char kAppId[] = "appId"; 130 const char kAppId[] = "appId";
109 const char kEmbeddingOrigin[] = "embeddingOrigin"; 131 const char kEmbeddingOrigin[] = "embeddingOrigin";
110 const char kPreferencesSource[] = "preference"; 132 const char kPreferencesSource[] = "preference";
111 const char kZoom[] = "zoom"; 133 const char kZoom[] = "zoom";
134 const char kObject[] = "object";
135 const char kObjectName[] = "objectName";
112 136
113 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { 137 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
114 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, 138 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"},
115 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, 139 {CONTENT_SETTINGS_TYPE_IMAGES, "images"},
116 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, 140 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"},
117 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, 141 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"},
118 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, 142 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"},
119 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, 143 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"},
120 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, 144 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"},
121 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, 145 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"},
122 {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, 146 {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"},
123 {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, 147 {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"},
124 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "register-protocol-handler"}, 148 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "register-protocol-handler"},
125 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"}, 149 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"},
126 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"}, 150 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"},
127 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"}, 151 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"},
128 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "multiple-automatic-downloads"}, 152 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "multiple-automatic-downloads"},
129 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"}, 153 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"},
130 {CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging"}, 154 {CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, "push-messaging"},
131 {CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, "ssl-cert-decisions"}, 155 {CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, "ssl-cert-decisions"},
132 #if defined(OS_CHROMEOS) 156 #if defined(OS_CHROMEOS)
133 {CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, "protectedContent"}, 157 {CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, "protectedContent"},
134 #endif 158 #endif
135 }; 159 };
136 160
161 ChooserContextBase* GetUsbChooserContext(Profile* profile) {
162 return UsbChooserContextFactory::GetForProfile(profile);
163 }
164
165 const ContentSettingsHandler::ChooserTypeNameEntry kChooserTypeGroupNames[] = {
166 {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext,
167 "usb-devices", "name"},
168 };
169
137 // A pseudo content type. We use it to display data like a content setting even 170 // A pseudo content type. We use it to display data like a content setting even
138 // though it is not a real content setting. 171 // though it is not a real content setting.
139 const char kZoomContentType[] = "zoomlevels"; 172 const char kZoomContentType[] = "zoomlevels";
140 173
141 // Maps from a content settings type to a content setting with exceptions 174 // Maps from a content settings type to a content setting with exceptions
142 // struct. 175 // struct.
143 typedef std::map<ContentSettingsType, ContentSettingWithExceptions> 176 typedef std::map<ContentSettingsType, ContentSettingWithExceptions>
144 ExceptionsInfoMap; 177 ExceptionsInfoMap;
145 178
146 const ExceptionsInfoMap& GetExceptionsInfoMap() { 179 const ExceptionsInfoMap& GetExceptionsInfoMap() {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { 273 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) {
241 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { 274 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) {
242 if (name == kContentSettingsTypeGroupNames[i].name) 275 if (name == kContentSettingsTypeGroupNames[i].name)
243 return kContentSettingsTypeGroupNames[i].type; 276 return kContentSettingsTypeGroupNames[i].type;
244 } 277 }
245 278
246 NOTREACHED() << name << " is not a recognized content settings type."; 279 NOTREACHED() << name << " is not a recognized content settings type.";
247 return CONTENT_SETTINGS_TYPE_DEFAULT; 280 return CONTENT_SETTINGS_TYPE_DEFAULT;
248 } 281 }
249 282
283 const ContentSettingsHandler::ChooserTypeNameEntry* ChooserTypeFromGroupName(
284 const std::string& name) {
285 for (const auto& chooser_type : kChooserTypeGroupNames) {
286 if (chooser_type.name == name)
287 return &chooser_type;
288 }
289 return nullptr;
290 }
291
250 // Create a DictionaryValue* that will act as a data source for a single row 292 // Create a DictionaryValue* that will act as a data source for a single row
251 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies). 293 // in a HostContentSettingsMap-controlled exceptions table (e.g., cookies).
252 scoped_ptr<base::DictionaryValue> GetExceptionForPage( 294 scoped_ptr<base::DictionaryValue> GetExceptionForPage(
253 const ContentSettingsPattern& pattern, 295 const ContentSettingsPattern& pattern,
254 const ContentSettingsPattern& secondary_pattern, 296 const ContentSettingsPattern& secondary_pattern,
255 const ContentSetting& setting, 297 const ContentSetting& setting,
256 const std::string& provider_name) { 298 const std::string& provider_name) {
257 base::DictionaryValue* exception = new base::DictionaryValue(); 299 base::DictionaryValue* exception = new base::DictionaryValue();
258 exception->SetString(kOrigin, pattern.ToString()); 300 exception->SetString(kOrigin, pattern.ToString());
259 exception->SetString(kEmbeddingOrigin, 301 exception->SetString(kEmbeddingOrigin,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 content_settings::ContentSettingToString(setting); 347 content_settings::ContentSettingToString(setting);
306 DCHECK(!setting_string.empty()); 348 DCHECK(!setting_string.empty());
307 349
308 exception->SetString(kSetting, setting_string); 350 exception->SetString(kSetting, setting_string);
309 exception->SetString(kOrigin, primary_pattern.ToString()); 351 exception->SetString(kOrigin, primary_pattern.ToString());
310 exception->SetString(kEmbeddingOrigin, embedding_origin); 352 exception->SetString(kEmbeddingOrigin, embedding_origin);
311 exception->SetString(kSource, provider_name); 353 exception->SetString(kSource, provider_name);
312 return make_scoped_ptr(exception); 354 return make_scoped_ptr(exception);
313 } 355 }
314 356
357 // Create a DictionaryValue* that will act as a data source for a single row
358 // in a chooser permission exceptions table.
359 scoped_ptr<base::DictionaryValue> GetChooserExceptionForPage(
360 const GURL& requesting_origin,
361 const GURL& embedding_origin,
362 const std::string& provider_name,
363 const std::string& name,
364 const base::DictionaryValue* object) {
365 scoped_ptr<base::DictionaryValue> exception(new base::DictionaryValue());
366
367 std::string setting_string =
368 content_settings::ContentSettingToString(CONTENT_SETTING_DEFAULT);
369 DCHECK(!setting_string.empty());
370
371 exception->SetString(kSetting, setting_string);
372 exception->SetString(kOrigin, requesting_origin.spec());
373 exception->SetString(kEmbeddingOrigin, embedding_origin.spec());
374 exception->SetString(kSource, provider_name);
375 if (object) {
376 exception->SetString(kObjectName, name);
377 exception->Set(kObject, object->CreateDeepCopy());
378 }
379 return exception.Pass();
380 }
381
315 // Returns true whenever the |extension| is hosted and has |permission|. 382 // Returns true whenever the |extension| is hosted and has |permission|.
316 // Must have the AppFilter signature. 383 // Must have the AppFilter signature.
317 template <APIPermission::ID permission> 384 template <APIPermission::ID permission>
318 bool HostedAppHasPermission(const extensions::Extension& extension, 385 bool HostedAppHasPermission(const extensions::Extension& extension,
319 content::BrowserContext* /* context */) { 386 content::BrowserContext* /* context */) {
320 return extension.is_hosted_app() && 387 return extension.is_hosted_app() &&
321 extension.permissions_data()->HasAPIPermission(permission); 388 extension.permissions_data()->HasAPIPermission(permission);
322 } 389 }
323 390
324 // Add an "Allow"-entry to the list of |exceptions| for a |url_pattern| from 391 // Add an "Allow"-entry to the list of |exceptions| for a |url_pattern| from
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); 431 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get());
365 // Skip adding the launch URL if it is part of the web extent. 432 // Skip adding the launch URL if it is part of the web extent.
366 if (web_extent.MatchesURL(launch_url)) 433 if (web_extent.MatchesURL(launch_url))
367 continue; 434 continue;
368 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions); 435 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions);
369 } 436 }
370 } 437 }
371 438
372 } // namespace 439 } // namespace
373 440
374 namespace options {
375
376 ContentSettingsHandler::MediaSettingsInfo::MediaSettingsInfo() { 441 ContentSettingsHandler::MediaSettingsInfo::MediaSettingsInfo() {
377 } 442 }
378 443
379 ContentSettingsHandler::MediaSettingsInfo::~MediaSettingsInfo() { 444 ContentSettingsHandler::MediaSettingsInfo::~MediaSettingsInfo() {
380 } 445 }
381 446
382 ContentSettingsHandler::MediaSettingsInfo::ForFlash::ForFlash() 447 ContentSettingsHandler::MediaSettingsInfo::ForFlash::ForFlash()
383 : default_setting(CONTENT_SETTING_DEFAULT), 448 : default_setting(CONTENT_SETTING_DEFAULT),
384 initialized(false), 449 initialized(false),
385 last_refresh_request_id(0) { 450 last_refresh_request_id(0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 {"blockException", IDS_EXCEPTIONS_BLOCK_BUTTON}, 497 {"blockException", IDS_EXCEPTIONS_BLOCK_BUTTON},
433 {"sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON}, 498 {"sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON},
434 {"detectException", IDS_EXCEPTIONS_DETECT_IMPORTANT_CONTENT_BUTTON}, 499 {"detectException", IDS_EXCEPTIONS_DETECT_IMPORTANT_CONTENT_BUTTON},
435 {"askException", IDS_EXCEPTIONS_ASK_BUTTON}, 500 {"askException", IDS_EXCEPTIONS_ASK_BUTTON},
436 {"otrExceptionsExplanation", IDS_EXCEPTIONS_OTR_LABEL}, 501 {"otrExceptionsExplanation", IDS_EXCEPTIONS_OTR_LABEL},
437 {"addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS}, 502 {"addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS},
438 {"manageExceptions", IDS_EXCEPTIONS_MANAGE}, 503 {"manageExceptions", IDS_EXCEPTIONS_MANAGE},
439 {"manageHandlers", IDS_HANDLERS_MANAGE}, 504 {"manageHandlers", IDS_HANDLERS_MANAGE},
440 {"exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER}, 505 {"exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER},
441 {"exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER}, 506 {"exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER},
507 {"exceptionUsbDeviceHeader", IDS_EXCEPTIONS_USB_DEVICE_HEADER},
442 {"exceptionZoomHeader", IDS_EXCEPTIONS_ZOOM_HEADER}, 508 {"exceptionZoomHeader", IDS_EXCEPTIONS_ZOOM_HEADER},
443 {"embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST}, 509 {"embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST},
444 // Cookies filter. 510 // Cookies filter.
445 {"cookiesTabLabel", IDS_COOKIES_TAB_LABEL}, 511 {"cookiesTabLabel", IDS_COOKIES_TAB_LABEL},
446 {"cookiesHeader", IDS_COOKIES_HEADER}, 512 {"cookiesHeader", IDS_COOKIES_HEADER},
447 {"cookiesAllow", IDS_COOKIES_ALLOW_RADIO}, 513 {"cookiesAllow", IDS_COOKIES_ALLOW_RADIO},
448 {"cookiesBlock", IDS_COOKIES_BLOCK_RADIO}, 514 {"cookiesBlock", IDS_COOKIES_BLOCK_RADIO},
449 {"cookiesSessionOnly", IDS_COOKIES_SESSION_ONLY_RADIO}, 515 {"cookiesSessionOnly", IDS_COOKIES_SESSION_ONLY_RADIO},
450 {"cookiesBlock3rdParty", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX}, 516 {"cookiesBlock3rdParty", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX},
451 {"cookiesShowCookies", IDS_COOKIES_SHOW_COOKIES_BUTTON}, 517 {"cookiesShowCookies", IDS_COOKIES_SHOW_COOKIES_BUTTON},
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // MIDI system exclusive messages 609 // MIDI system exclusive messages
544 {"midiSysexHeader", IDS_MIDI_SYSEX_TAB_LABEL}, 610 {"midiSysexHeader", IDS_MIDI_SYSEX_TAB_LABEL},
545 {"midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO}, 611 {"midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO},
546 {"midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO}, 612 {"midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO},
547 {"midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO}, 613 {"midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO},
548 // Push messaging strings 614 // Push messaging strings
549 {"pushMessagingHeader", IDS_PUSH_MESSAGES_TAB_LABEL}, 615 {"pushMessagingHeader", IDS_PUSH_MESSAGES_TAB_LABEL},
550 {"pushMessagingAllow", IDS_PUSH_MESSSAGING_ALLOW_RADIO}, 616 {"pushMessagingAllow", IDS_PUSH_MESSSAGING_ALLOW_RADIO},
551 {"pushMessagingAsk", IDS_PUSH_MESSSAGING_ASK_RADIO}, 617 {"pushMessagingAsk", IDS_PUSH_MESSSAGING_ASK_RADIO},
552 {"pushMessagingBlock", IDS_PUSH_MESSSAGING_BLOCK_RADIO}, 618 {"pushMessagingBlock", IDS_PUSH_MESSSAGING_BLOCK_RADIO},
619 {"usbDevicesHeader", IDS_USB_DEVICES_HEADER_AND_TAB_LABEL},
620 {"usbDevicesManage", IDS_USB_DEVICES_MANAGE_BUTTON},
553 {"zoomlevelsHeader", IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL}, 621 {"zoomlevelsHeader", IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL},
554 {"zoomLevelsManage", IDS_ZOOMLEVELS_MANAGE_BUTTON}, 622 {"zoomLevelsManage", IDS_ZOOMLEVELS_MANAGE_BUTTON},
555 }; 623 };
556 624
557 RegisterStrings(localized_strings, resources, arraysize(resources)); 625 RegisterStrings(localized_strings, resources, arraysize(resources));
558 626
559 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 627 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
560 const base::Value* default_pref = prefs->GetDefaultPrefValue( 628 const base::Value* default_pref = prefs->GetDefaultPrefValue(
561 content_settings::WebsiteSettingsRegistry::GetInstance() 629 content_settings::WebsiteSettingsRegistry::GetInstance()
562 ->Get(CONTENT_SETTINGS_TYPE_PLUGINS) 630 ->Get(CONTENT_SETTINGS_TYPE_PLUGINS)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 RegisterTitle(localized_strings, "media-stream-mic", 665 RegisterTitle(localized_strings, "media-stream-mic",
598 IDS_MEDIA_STREAM_MIC_TAB_LABEL); 666 IDS_MEDIA_STREAM_MIC_TAB_LABEL);
599 RegisterTitle(localized_strings, "media-stream-camera", 667 RegisterTitle(localized_strings, "media-stream-camera",
600 IDS_MEDIA_STREAM_CAMERA_TAB_LABEL); 668 IDS_MEDIA_STREAM_CAMERA_TAB_LABEL);
601 RegisterTitle(localized_strings, "ppapi-broker", 669 RegisterTitle(localized_strings, "ppapi-broker",
602 IDS_PPAPI_BROKER_TAB_LABEL); 670 IDS_PPAPI_BROKER_TAB_LABEL);
603 RegisterTitle(localized_strings, "multiple-automatic-downloads", 671 RegisterTitle(localized_strings, "multiple-automatic-downloads",
604 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL); 672 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL);
605 RegisterTitle(localized_strings, "midi-sysex", 673 RegisterTitle(localized_strings, "midi-sysex",
606 IDS_MIDI_SYSEX_TAB_LABEL); 674 IDS_MIDI_SYSEX_TAB_LABEL);
675 RegisterTitle(localized_strings, "usb-devices",
676 IDS_USB_DEVICES_HEADER_AND_TAB_LABEL);
607 RegisterTitle(localized_strings, "zoomlevels", 677 RegisterTitle(localized_strings, "zoomlevels",
608 IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL); 678 IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL);
609 679
610 localized_strings->SetString("exceptionsLearnMoreUrl", 680 localized_strings->SetString("exceptionsLearnMoreUrl",
611 kExceptionsLearnMoreUrl); 681 kExceptionsLearnMoreUrl);
612 } 682 }
613 683
614 void ContentSettingsHandler::InitializeHandler() { 684 void ContentSettingsHandler::InitializeHandler() {
615 notification_registrar_.Add( 685 notification_registrar_.Add(
616 this, chrome::NOTIFICATION_PROFILE_CREATED, 686 this, chrome::NOTIFICATION_PROFILE_CREATED,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 observer_.Add(map); 762 observer_.Add(map);
693 } 763 }
694 } 764 }
695 765
696 void ContentSettingsHandler::InitializePage() { 766 void ContentSettingsHandler::InitializePage() {
697 media_settings_.reset(new MediaSettingsInfo()); 767 media_settings_.reset(new MediaSettingsInfo());
698 RefreshFlashMediaSettings(); 768 RefreshFlashMediaSettings();
699 769
700 UpdateHandlersEnabledRadios(); 770 UpdateHandlersEnabledRadios();
701 UpdateAllExceptionsViewsFromModel(); 771 UpdateAllExceptionsViewsFromModel();
772 UpdateAllChooserExceptionsViewsFromModel();
702 UpdateProtectedContentExceptionsButton(); 773 UpdateProtectedContentExceptionsButton();
703 } 774 }
704 775
705 void ContentSettingsHandler::OnContentSettingChanged( 776 void ContentSettingsHandler::OnContentSettingChanged(
706 const ContentSettingsPattern& primary_pattern, 777 const ContentSettingsPattern& primary_pattern,
707 const ContentSettingsPattern& secondary_pattern, 778 const ContentSettingsPattern& secondary_pattern,
708 ContentSettingsType content_type, 779 ContentSettingsType content_type,
709 std::string resource_identifier) { 780 std::string resource_identifier) {
710 const ContentSettingsDetails details( 781 const ContentSettingsDetails details(
711 primary_pattern, secondary_pattern, content_type, resource_identifier); 782 primary_pattern, secondary_pattern, content_type, resource_identifier);
712 // TODO(estade): we pretend update_all() is always true. 783 // TODO(estade): we pretend update_all() is always true.
713 if (details.update_all_types()) { 784 if (details.update_all_types()) {
714 UpdateAllExceptionsViewsFromModel(); 785 UpdateAllExceptionsViewsFromModel();
786 UpdateAllChooserExceptionsViewsFromModel();
715 } else { 787 } else {
716 if (ContainsKey(GetExceptionsInfoMap(), details.type())) 788 if (ContainsKey(GetExceptionsInfoMap(), details.type()))
717 UpdateExceptionsViewFromModel(details.type()); 789 UpdateExceptionsViewFromModel(details.type());
790 for (const ChooserTypeNameEntry& chooser_type : kChooserTypeGroupNames) {
791 if (chooser_type.type == details.type()) {
792 UpdateChooserExceptionsViewFromModel(chooser_type);
793 break;
794 }
795 }
718 } 796 }
719 } 797 }
720 798
721 void ContentSettingsHandler::Observe( 799 void ContentSettingsHandler::Observe(
722 int type, 800 int type,
723 const content::NotificationSource& source, 801 const content::NotificationSource& source,
724 const content::NotificationDetails& details) { 802 const content::NotificationDetails& details) {
725 switch (type) { 803 switch (type) {
726 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 804 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
727 Profile* profile = content::Source<Profile>(source).ptr(); 805 Profile* profile = content::Source<Profile>(source).ptr();
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 settings.exceptions_initialized = true; 1103 settings.exceptions_initialized = true;
1026 UpdateFlashMediaLinksVisibility(type); 1104 UpdateFlashMediaLinksVisibility(type);
1027 } 1105 }
1028 1106
1029 void ContentSettingsHandler::UpdateMIDISysExExceptionsView() { 1107 void ContentSettingsHandler::UpdateMIDISysExExceptionsView() {
1030 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 1108 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
1031 UpdateExceptionsViewFromHostContentSettingsMap( 1109 UpdateExceptionsViewFromHostContentSettingsMap(
1032 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 1110 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
1033 } 1111 }
1034 1112
1113 void ContentSettingsHandler::UpdateAllChooserExceptionsViewsFromModel() {
1114 for (const ChooserTypeNameEntry& chooser_type : kChooserTypeGroupNames)
1115 UpdateChooserExceptionsViewFromModel(chooser_type);
1116 }
1117
1118 void ContentSettingsHandler::UpdateChooserExceptionsViewFromModel(
1119 const ChooserTypeNameEntry& chooser_type) {
1120 ChooserContextBase* chooser_context =
1121 chooser_type.get_context(Profile::FromWebUI(web_ui()));
1122 std::vector<scoped_ptr<ChosenObjectPattern>> objects =
1123 chooser_context->GetAllGrantedObjects();
1124 AllOriginObjects all_origin_objects;
1125 for (const scoped_ptr<ChosenObjectPattern>& object : objects) {
1126 std::string name;
1127 bool found = object->object.GetString(chooser_type.ui_name_key, &name);
1128 DCHECK(found);
1129 // It is safe for this structure to hold references into |objects| because
1130 // they are both destroyed at the end of this function.
1131 all_origin_objects[make_pair(object->requesting_origin,
1132 object->source)][object->embedding_origin]
1133 .insert(make_pair(name, &object->object));
1134 }
1135
1136 // Keep the exceptions sorted by provider so they will be displayed in
1137 // precedence order.
1138 std::vector<scoped_ptr<base::DictionaryValue>>
1139 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES];
1140
1141 for (const auto& all_origin_objects_entry : all_origin_objects) {
1142 const GURL& requesting_origin = all_origin_objects_entry.first.first;
1143 const std::string& source = all_origin_objects_entry.first.second;
1144 const OneOriginObjects& one_origin_objects =
1145 all_origin_objects_entry.second;
1146
1147 auto& this_provider_exceptions = all_provider_exceptions
1148 [HostContentSettingsMap::GetProviderTypeFromSource(source)];
1149
1150 // Add entries for any non-embedded origins.
1151 bool has_embedded_entries = false;
1152 for (const auto& one_origin_objects_entry : one_origin_objects) {
1153 const GURL& embedding_origin = one_origin_objects_entry.first;
1154 const SortedObjects& sorted_objects = one_origin_objects_entry.second;
1155
1156 // Skip the embedded settings which will be added below.
1157 if (requesting_origin != embedding_origin) {
1158 has_embedded_entries = true;
1159 continue;
1160 }
1161
1162 for (const auto& sorted_objects_entry : sorted_objects) {
1163 this_provider_exceptions.push_back(GetChooserExceptionForPage(
1164 requesting_origin, embedding_origin, source,
1165 sorted_objects_entry.first, sorted_objects_entry.second));
1166 }
1167 }
1168
1169 if (has_embedded_entries) {
1170 // Add a "parent" entry that simply acts as a heading for all entries
1171 // where |requesting_origin| has been embedded.
1172 this_provider_exceptions.push_back(
1173 GetChooserExceptionForPage(requesting_origin, requesting_origin,
1174 source, std::string(), nullptr));
1175
1176 // Add the "children" for any embedded settings.
1177 for (const auto& one_origin_objects_entry : one_origin_objects) {
1178 const GURL& embedding_origin = one_origin_objects_entry.first;
1179 const SortedObjects& sorted_objects = one_origin_objects_entry.second;
1180
1181 // Skip the non-embedded setting which we already added above.
1182 if (requesting_origin == embedding_origin)
1183 continue;
1184
1185 for (const auto& sorted_objects_entry : sorted_objects) {
1186 this_provider_exceptions.push_back(GetChooserExceptionForPage(
1187 requesting_origin, embedding_origin, source,
1188 sorted_objects_entry.first, sorted_objects_entry.second));
1189 }
1190 }
1191 }
1192 }
1193
1194 base::ListValue exceptions;
1195 for (auto& one_provider_exceptions : all_provider_exceptions) {
1196 for (auto& exception : one_provider_exceptions)
1197 exceptions.Append(exception.Pass());
1198 }
1199
1200 base::StringValue type_string(chooser_type.name);
1201 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string,
1202 exceptions);
1203 }
1204
1035 void ContentSettingsHandler::AdjustZoomLevelsListForSigninPageIfNecessary( 1205 void ContentSettingsHandler::AdjustZoomLevelsListForSigninPageIfNecessary(
1036 content::HostZoomMap::ZoomLevelVector* zoom_levels) { 1206 content::HostZoomMap::ZoomLevelVector* zoom_levels) {
1037 if (switches::IsEnableWebviewBasedSignin()) 1207 if (switches::IsEnableWebviewBasedSignin())
1038 return; 1208 return;
1039 1209
1040 GURL signin_url(chrome::kChromeUIChromeSigninURL); 1210 GURL signin_url(chrome::kChromeUIChromeSigninURL);
1041 content::HostZoomMap* signin_host_zoom_map = 1211 content::HostZoomMap* signin_host_zoom_map =
1042 content::BrowserContext::GetStoragePartitionForSite( 1212 content::BrowserContext::GetStoragePartitionForSite(
1043 GetBrowserContext(web_ui()), signin_url)->GetHostZoomMap(); 1213 GetBrowserContext(web_ui()), signin_url)->GetHostZoomMap();
1044 1214
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); 1339 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap();
1170 if (!otr_settings_map) 1340 if (!otr_settings_map)
1171 return; 1341 return;
1172 base::ListValue exceptions; 1342 base::ListValue exceptions;
1173 GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, &exceptions); 1343 GetExceptionsFromHostContentSettingsMap(otr_settings_map, type, &exceptions);
1174 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); 1344 base::StringValue type_string(ContentSettingsTypeToGroupName(type));
1175 web_ui()->CallJavascriptFunction("ContentSettings.setOTRExceptions", 1345 web_ui()->CallJavascriptFunction("ContentSettings.setOTRExceptions",
1176 type_string, exceptions); 1346 type_string, exceptions);
1177 } 1347 }
1178 1348
1179 scoped_ptr<base::ListValue> ContentSettingsHandler::GetPolicyAllowedUrls( 1349 void ContentSettingsHandler::GetPolicyAllowedUrls(
1180 ContentSettingsType type) { 1350 ContentSettingsType type,
1351 std::vector<scoped_ptr<base::DictionaryValue>>* exceptions) {
1181 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || 1352 DCHECK(type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC ||
1182 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 1353 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
1183 1354
1184 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 1355 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1185 const base::ListValue* policy_urls = prefs->GetList( 1356 const base::ListValue* policy_urls = prefs->GetList(
1186 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC 1357 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
1187 ? prefs::kAudioCaptureAllowedUrls 1358 ? prefs::kAudioCaptureAllowedUrls
1188 : prefs::kVideoCaptureAllowedUrls); 1359 : prefs::kVideoCaptureAllowedUrls);
1189 1360
1190 // Convert the URLs to |ContentSettingsPattern|s. Ignore any invalid ones. 1361 // Convert the URLs to |ContentSettingsPattern|s. Ignore any invalid ones.
1191 std::vector<ContentSettingsPattern> patterns; 1362 std::vector<ContentSettingsPattern> patterns;
1192 for (const base::Value* entry : *policy_urls) { 1363 for (const base::Value* entry : *policy_urls) {
1193 std::string url; 1364 std::string url;
1194 bool valid_string = entry->GetAsString(&url); 1365 bool valid_string = entry->GetAsString(&url);
1195 if (!valid_string) 1366 if (!valid_string)
1196 continue; 1367 continue;
1197 1368
1198 ContentSettingsPattern pattern = ContentSettingsPattern::FromString(url); 1369 ContentSettingsPattern pattern = ContentSettingsPattern::FromString(url);
1199 if (!pattern.IsValid()) 1370 if (!pattern.IsValid())
1200 continue; 1371 continue;
1201 1372
1202 patterns.push_back(pattern); 1373 patterns.push_back(pattern);
1203 } 1374 }
1204 1375
1205 // The patterns are shown in the UI in a reverse order defined by 1376 // The patterns are shown in the UI in a reverse order defined by
1206 // |ContentSettingsPattern::operator<|. 1377 // |ContentSettingsPattern::operator<|.
1207 std::sort( 1378 std::sort(
1208 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>()); 1379 patterns.begin(), patterns.end(), std::greater<ContentSettingsPattern>());
1209 1380
1210 scoped_ptr<base::ListValue> exceptions(new base::ListValue());
1211 for (const ContentSettingsPattern& pattern : patterns) { 1381 for (const ContentSettingsPattern& pattern : patterns) {
1212 exceptions->Append(GetExceptionForPage( 1382 exceptions->push_back(GetExceptionForPage(pattern, ContentSettingsPattern(),
1213 pattern, 1383 CONTENT_SETTING_ALLOW,
1214 ContentSettingsPattern(), 1384 kPolicyProviderId));
1215 CONTENT_SETTING_ALLOW,
1216 kPolicyProviderId));
1217 } 1385 }
1218
1219 return exceptions.Pass();
1220 } 1386 }
1221 1387
1222 void ContentSettingsHandler::GetExceptionsFromHostContentSettingsMap( 1388 void ContentSettingsHandler::GetExceptionsFromHostContentSettingsMap(
1223 const HostContentSettingsMap* map, 1389 const HostContentSettingsMap* map,
1224 ContentSettingsType type, 1390 ContentSettingsType type,
1225 base::ListValue* exceptions) { 1391 base::ListValue* exceptions) {
1226 ContentSettingsForOneType entries; 1392 ContentSettingsForOneType entries;
1227 map->GetSettingsForOneType(type, std::string(), &entries); 1393 map->GetSettingsForOneType(type, std::string(), &entries);
1228 // Group settings by primary_pattern. 1394 // Group settings by primary_pattern.
1229 AllPatternsSettings all_patterns_settings; 1395 AllPatternsSettings all_patterns_settings;
(...skipping 11 matching lines...) Expand all
1241 // only. 1407 // only.
1242 if (map->is_off_the_record() && !i->incognito) 1408 if (map->is_off_the_record() && !i->incognito)
1243 continue; 1409 continue;
1244 1410
1245 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)] 1411 all_patterns_settings[std::make_pair(i->primary_pattern, i->source)]
1246 [i->secondary_pattern] = i->setting; 1412 [i->secondary_pattern] = i->setting;
1247 } 1413 }
1248 1414
1249 // Keep the exceptions sorted by provider so they will be displayed in 1415 // Keep the exceptions sorted by provider so they will be displayed in
1250 // precedence order. 1416 // precedence order.
1251 ScopedVector<base::ListValue> all_provider_exceptions; 1417 std::vector<scoped_ptr<base::DictionaryValue>>
1252 all_provider_exceptions.resize(HostContentSettingsMap::NUM_PROVIDER_TYPES); 1418 all_provider_exceptions[HostContentSettingsMap::NUM_PROVIDER_TYPES];
1253 for (auto& one_provider_exceptions : all_provider_exceptions)
1254 one_provider_exceptions = new base::ListValue();
1255 1419
1256 // |all_patterns_settings| is sorted from the lowest precedence pattern to 1420 // |all_patterns_settings| is sorted from the lowest precedence pattern to
1257 // the highest (see operator< in ContentSettingsPattern), so traverse it in 1421 // the highest (see operator< in ContentSettingsPattern), so traverse it in
1258 // reverse to show the patterns with the highest precedence (the more specific 1422 // reverse to show the patterns with the highest precedence (the more specific
1259 // ones) on the top. 1423 // ones) on the top.
1260 for (AllPatternsSettings::reverse_iterator i = all_patterns_settings.rbegin(); 1424 for (AllPatternsSettings::reverse_iterator i = all_patterns_settings.rbegin();
1261 i != all_patterns_settings.rend(); 1425 i != all_patterns_settings.rend();
1262 ++i) { 1426 ++i) {
1263 const ContentSettingsPattern& primary_pattern = i->first.first; 1427 const ContentSettingsPattern& primary_pattern = i->first.first;
1264 const OnePatternSettings& one_settings = i->second; 1428 const OnePatternSettings& one_settings = i->second;
1265 1429
1266 // The "parent" entry either has an identical primary and secondary pattern, 1430 // The "parent" entry either has an identical primary and secondary pattern,
1267 // or has a wildcard secondary. The two cases are indistinguishable in the 1431 // or has a wildcard secondary. The two cases are indistinguishable in the
1268 // UI. 1432 // UI.
1269 OnePatternSettings::const_iterator parent = 1433 OnePatternSettings::const_iterator parent =
1270 one_settings.find(primary_pattern); 1434 one_settings.find(primary_pattern);
1271 if (parent == one_settings.end()) 1435 if (parent == one_settings.end())
1272 parent = one_settings.find(ContentSettingsPattern::Wildcard()); 1436 parent = one_settings.find(ContentSettingsPattern::Wildcard());
1273 1437
1274 const std::string& source = i->first.second; 1438 const std::string& source = i->first.second;
1275 base::ListValue* this_provider_exceptions = 1439 auto& this_provider_exceptions = all_provider_exceptions
1276 all_provider_exceptions[ 1440 [HostContentSettingsMap::GetProviderTypeFromSource(source)];
1277 HostContentSettingsMap::GetProviderTypeFromSource(source)];
1278 1441
1279 // Add the "parent" entry for the non-embedded setting. 1442 // Add the "parent" entry for the non-embedded setting.
1280 ContentSetting parent_setting = 1443 ContentSetting parent_setting =
1281 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second; 1444 parent == one_settings.end() ? CONTENT_SETTING_DEFAULT : parent->second;
1282 const ContentSettingsPattern& secondary_pattern = 1445 const ContentSettingsPattern& secondary_pattern =
1283 parent == one_settings.end() ? primary_pattern : parent->first; 1446 parent == one_settings.end() ? primary_pattern : parent->first;
1284 this_provider_exceptions->Append(GetExceptionForPage(primary_pattern, 1447 this_provider_exceptions.push_back(GetExceptionForPage(
1285 secondary_pattern, 1448 primary_pattern, secondary_pattern, parent_setting, source));
1286 parent_setting,
1287 source));
1288 1449
1289 // Add the "children" for any embedded settings. 1450 // Add the "children" for any embedded settings.
1290 for (OnePatternSettings::const_iterator j = one_settings.begin(); 1451 for (OnePatternSettings::const_iterator j = one_settings.begin();
1291 j != one_settings.end(); ++j) { 1452 j != one_settings.end(); ++j) {
1292 // Skip the non-embedded setting which we already added above. 1453 // Skip the non-embedded setting which we already added above.
1293 if (j == parent) 1454 if (j == parent)
1294 continue; 1455 continue;
1295 1456
1296 ContentSetting content_setting = j->second; 1457 ContentSetting content_setting = j->second;
1297 this_provider_exceptions->Append(GetExceptionForPage( 1458 this_provider_exceptions.push_back(GetExceptionForPage(
1298 primary_pattern, 1459 primary_pattern, j->first, content_setting, source));
1299 j->first,
1300 content_setting,
1301 source));
1302 } 1460 }
1303 } 1461 }
1304 1462
1305 // For camera and microphone, we do not have policy exceptions, but we do have 1463 // For camera and microphone, we do not have policy exceptions, but we do have
1306 // the policy-set allowed URLs, which should be displayed in the same manner. 1464 // the policy-set allowed URLs, which should be displayed in the same manner.
1307 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || 1465 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC ||
1308 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 1466 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
1309 base::ListValue* policy_exceptions = all_provider_exceptions[ 1467 auto& policy_exceptions = all_provider_exceptions
1310 HostContentSettingsMap::GetProviderTypeFromSource(kPolicyProviderId)]; 1468 [HostContentSettingsMap::GetProviderTypeFromSource(kPolicyProviderId)];
1311 DCHECK(policy_exceptions->empty()); 1469 DCHECK(policy_exceptions.empty());
1312 policy_exceptions->Swap(GetPolicyAllowedUrls(type).get()); 1470 GetPolicyAllowedUrls(type, &policy_exceptions);
1313 } 1471 }
1314 1472
1315 for (const auto& one_provider_exceptions : all_provider_exceptions) { 1473 for (auto& one_provider_exceptions : all_provider_exceptions) {
1316 // Append |one_provider_exceptions| at the end of |exceptions|. ListValue 1474 for (auto& exception : one_provider_exceptions)
1317 // does not support concatenation, so we must append one item at a time. 1475 exceptions->Append(exception.Pass());
1318 // Furthermore, ListValue::Remove is O(size) if we remove an item from the
1319 // beginning, so we need to remove them in the reverse order.
1320 ScopedVector<base::Value> reverse_helper;
1321 while (!one_provider_exceptions->empty()) {
1322 scoped_ptr<base::Value> exception;
1323 one_provider_exceptions->Remove(
1324 one_provider_exceptions->GetSize() - 1, &exception);
1325 reverse_helper.push_back(exception.Pass());
1326 }
1327 while (!reverse_helper.empty()) {
1328 ScopedVector<base::Value>::iterator back = reverse_helper.end() - 1;
1329 exceptions->Append(make_scoped_ptr(*back));
1330 reverse_helper.weak_erase(back);
1331 }
1332 } 1476 }
1333 } 1477 }
1334 1478
1335 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap( 1479 void ContentSettingsHandler::RemoveExceptionFromHostContentSettingsMap(
1336 const base::ListValue* args, 1480 const base::ListValue* args,
1337 ContentSettingsType type) { 1481 ContentSettingsType type) {
1338 std::string mode; 1482 std::string mode;
1339 bool rv = args->GetString(1, &mode); 1483 bool rv = args->GetString(1, &mode);
1340 DCHECK(rv); 1484 DCHECK(rv);
1341 1485
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } else { 1533 } else {
1390 host_zoom_map = 1534 host_zoom_map =
1391 content::BrowserContext::GetStoragePartitionForSite( 1535 content::BrowserContext::GetStoragePartitionForSite(
1392 GetBrowserContext(web_ui()), GURL(chrome::kChromeUIChromeSigninURL)) 1536 GetBrowserContext(web_ui()), GURL(chrome::kChromeUIChromeSigninURL))
1393 ->GetHostZoomMap(); 1537 ->GetHostZoomMap();
1394 } 1538 }
1395 double default_level = host_zoom_map->GetDefaultZoomLevel(); 1539 double default_level = host_zoom_map->GetDefaultZoomLevel();
1396 host_zoom_map->SetZoomLevelForHost(pattern, default_level); 1540 host_zoom_map->SetZoomLevelForHost(pattern, default_level);
1397 } 1541 }
1398 1542
1543 void ContentSettingsHandler::RemoveChooserException(
1544 const ChooserTypeNameEntry* chooser_type,
1545 const base::ListValue* args) {
1546 std::string mode;
1547 bool rv = args->GetString(1, &mode);
1548 DCHECK(rv);
1549
1550 std::string requesting_origin_string;
1551 rv = args->GetString(2, &requesting_origin_string);
1552 DCHECK(rv);
1553 GURL requesting_origin(requesting_origin_string);
1554 DCHECK(requesting_origin.is_valid());
1555
1556 std::string embedding_origin_string;
1557 rv = args->GetString(3, &embedding_origin_string);
1558 DCHECK(rv);
1559 GURL embedding_origin(embedding_origin_string);
1560 DCHECK(embedding_origin.is_valid());
1561
1562 const base::DictionaryValue* object = nullptr;
1563 rv = args->GetDictionary(4, &object);
1564 DCHECK(rv);
1565
1566 Profile* profile = Profile::FromWebUI(web_ui());
1567 if (mode != "normal")
1568 profile = profile->GetOffTheRecordProfile();
1569
1570 ChooserContextBase* chooser_context = chooser_type->get_context(profile);
1571 chooser_context->RevokeObjectPermission(requesting_origin, embedding_origin,
1572 *object);
1573 // TODO(reillyg): Create metrics for revocations. crbug.com/556845
1574 }
1575
1399 void ContentSettingsHandler::RegisterMessages() { 1576 void ContentSettingsHandler::RegisterMessages() {
1400 web_ui()->RegisterMessageCallback("setContentFilter", 1577 web_ui()->RegisterMessageCallback("setContentFilter",
1401 base::Bind(&ContentSettingsHandler::SetContentFilter, 1578 base::Bind(&ContentSettingsHandler::SetContentFilter,
1402 base::Unretained(this))); 1579 base::Unretained(this)));
1403 web_ui()->RegisterMessageCallback("removeException", 1580 web_ui()->RegisterMessageCallback("removeException",
1404 base::Bind(&ContentSettingsHandler::RemoveException, 1581 base::Bind(&ContentSettingsHandler::RemoveException,
1405 base::Unretained(this))); 1582 base::Unretained(this)));
1406 web_ui()->RegisterMessageCallback("setException", 1583 web_ui()->RegisterMessageCallback("setException",
1407 base::Bind(&ContentSettingsHandler::SetException, 1584 base::Bind(&ContentSettingsHandler::SetException,
1408 base::Unretained(this))); 1585 base::Unretained(this)));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 CHECK(args->GetString(0, &type_string)); 1630 CHECK(args->GetString(0, &type_string));
1454 1631
1455 // Zoom levels are no actual content type so we need to handle them 1632 // Zoom levels are no actual content type so we need to handle them
1456 // separately. They would not be recognized by 1633 // separately. They would not be recognized by
1457 // ContentSettingsTypeFromGroupName. 1634 // ContentSettingsTypeFromGroupName.
1458 if (type_string == kZoomContentType) { 1635 if (type_string == kZoomContentType) {
1459 RemoveZoomLevelException(args); 1636 RemoveZoomLevelException(args);
1460 return; 1637 return;
1461 } 1638 }
1462 1639
1640 const ChooserTypeNameEntry* chooser_type =
1641 ChooserTypeFromGroupName(type_string);
1642 if (chooser_type) {
1643 RemoveChooserException(chooser_type, args);
1644 return;
1645 }
1646
1463 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 1647 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1464 RemoveExceptionFromHostContentSettingsMap(args, type); 1648 RemoveExceptionFromHostContentSettingsMap(args, type);
1465 1649
1466 WebSiteSettingsUmaUtil::LogPermissionChange( 1650 WebSiteSettingsUmaUtil::LogPermissionChange(
1467 type, ContentSetting::CONTENT_SETTING_DEFAULT); 1651 type, ContentSetting::CONTENT_SETTING_DEFAULT);
1468 } 1652 }
1469 1653
1470 void ContentSettingsHandler::SetException(const base::ListValue* args) { 1654 void ContentSettingsHandler::SetException(const base::ListValue* args) {
1471 std::string type_string; 1655 std::string type_string;
1472 CHECK(args->GetString(0, &type_string)); 1656 CHECK(args->GetString(0, &type_string));
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 1863
1680 // Exceptions apply only when the feature is enabled. 1864 // Exceptions apply only when the feature is enabled.
1681 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 1865 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
1682 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1866 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1683 web_ui()->CallJavascriptFunction( 1867 web_ui()->CallJavascriptFunction(
1684 "ContentSettings.enableProtectedContentExceptions", 1868 "ContentSettings.enableProtectedContentExceptions",
1685 base::FundamentalValue(enable_exceptions)); 1869 base::FundamentalValue(enable_exceptions));
1686 } 1870 }
1687 1871
1688 } // namespace options 1872 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698