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

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

Powered by Google App Engine
This is Rietveld 408576698