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

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: 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 struct ChooserTypeNameEntry {
Bernhard Bauer 2015/11/16 12:53:30 Move this into the anonymous namespace? I also wou
Reilly Grant (use Gerrit) 2015/11/16 22:18:27 It is necessary to define this type outside of the
Bernhard Bauer 2015/11/17 13:36:53 Oh, right! In that case, can you move it into the
Reilly Grant (use Gerrit) 2015/11/18 00:30:09 Done.
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 ScopedVector<base::ListValue> all_provider_exceptions;
Bernhard Bauer 2015/11/16 12:53:31 I think there is some code here that is shared wit
Reilly Grant (use Gerrit) 2015/11/16 22:18:27 I've rewritten the code in both places to avoid th
1137 all_provider_exceptions.resize(HostContentSettingsMap::NUM_PROVIDER_TYPES);
1138 for (auto& one_provider_exceptions : all_provider_exceptions)
1139 one_provider_exceptions = new base::ListValue();
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 base::ListValue* 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->Append(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
1172 // |requesting_origin| has been embedded.
1173 this_provider_exceptions->Append(GetChooserExceptionForPage(
1174 requesting_origin, requesting_origin, source, "", 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->Append(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 (const auto& one_provider_exceptions : all_provider_exceptions) {
1196 // Append |one_provider_exceptions| at the end of |exceptions|. ListValue
1197 // does not support concatenation, so we must append one item at a time.
1198 // Furthermore, ListValue::Remove is O(size) if we remove an item from the
1199 // beginning, so we need to remove them in the reverse order.
1200 ScopedVector<base::Value> reverse_helper;
Bernhard Bauer 2015/11/16 12:53:30 Also, this should use std::vector<scoped_ptr<>>. O
Reilly Grant (use Gerrit) 2015/11/16 22:18:27 Done.
1201 while (!one_provider_exceptions->empty()) {
1202 scoped_ptr<base::Value> exception;
1203 one_provider_exceptions->Remove(one_provider_exceptions->GetSize() - 1,
1204 &exception);
1205 reverse_helper.push_back(exception.Pass());
1206 }
1207 while (!reverse_helper.empty()) {
1208 ScopedVector<base::Value>::iterator back = reverse_helper.end() - 1;
1209 exceptions.Append(make_scoped_ptr(*back));
1210 reverse_helper.weak_erase(back);
1211 }
1212 }
1213
1214 base::StringValue type_string(chooser_type.name);
1215 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string,
1216 exceptions);
1217 }
1218
1035 void ContentSettingsHandler::AdjustZoomLevelsListForSigninPageIfNecessary( 1219 void ContentSettingsHandler::AdjustZoomLevelsListForSigninPageIfNecessary(
1036 content::HostZoomMap::ZoomLevelVector* zoom_levels) { 1220 content::HostZoomMap::ZoomLevelVector* zoom_levels) {
1037 if (switches::IsEnableWebviewBasedSignin()) 1221 if (switches::IsEnableWebviewBasedSignin())
1038 return; 1222 return;
1039 1223
1040 GURL signin_url(chrome::kChromeUIChromeSigninURL); 1224 GURL signin_url(chrome::kChromeUIChromeSigninURL);
1041 content::HostZoomMap* signin_host_zoom_map = 1225 content::HostZoomMap* signin_host_zoom_map =
1042 content::BrowserContext::GetStoragePartitionForSite( 1226 content::BrowserContext::GetStoragePartitionForSite(
1043 GetBrowserContext(web_ui()), signin_url)->GetHostZoomMap(); 1227 GetBrowserContext(web_ui()), signin_url)->GetHostZoomMap();
1044 1228
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } else { 1573 } else {
1390 host_zoom_map = 1574 host_zoom_map =
1391 content::BrowserContext::GetStoragePartitionForSite( 1575 content::BrowserContext::GetStoragePartitionForSite(
1392 GetBrowserContext(web_ui()), GURL(chrome::kChromeUIChromeSigninURL)) 1576 GetBrowserContext(web_ui()), GURL(chrome::kChromeUIChromeSigninURL))
1393 ->GetHostZoomMap(); 1577 ->GetHostZoomMap();
1394 } 1578 }
1395 double default_level = host_zoom_map->GetDefaultZoomLevel(); 1579 double default_level = host_zoom_map->GetDefaultZoomLevel();
1396 host_zoom_map->SetZoomLevelForHost(pattern, default_level); 1580 host_zoom_map->SetZoomLevelForHost(pattern, default_level);
1397 } 1581 }
1398 1582
1583 void ContentSettingsHandler::RemoveChooserException(
1584 const ChooserTypeNameEntry* chooser_type,
1585 const base::ListValue* args) {
1586 std::string mode;
1587 bool rv = args->GetString(1, &mode);
1588 DCHECK(rv);
1589
1590 std::string requesting_origin_string;
1591 rv = args->GetString(2, &requesting_origin_string);
1592 DCHECK(rv);
1593 GURL requesting_origin(requesting_origin_string);
1594 DCHECK(requesting_origin.is_valid());
1595
1596 std::string embedding_origin_string;
1597 rv = args->GetString(3, &embedding_origin_string);
1598 DCHECK(rv);
1599 GURL embedding_origin(embedding_origin_string);
1600 DCHECK(embedding_origin.is_valid());
1601
1602 const base::DictionaryValue* object;
Bernhard Bauer 2015/11/16 12:53:30 Initialize this to null? Otherwise you might end u
Reilly Grant (use Gerrit) 2015/11/16 22:18:27 Done.
1603 rv = args->GetDictionary(4, &object);
1604 DCHECK(rv);
1605
1606 Profile* profile = Profile::FromWebUI(web_ui());
1607 if (mode != "normal") {
Bernhard Bauer 2015/11/16 12:53:30 Braces are unnecessary.
Reilly Grant (use Gerrit) 2015/11/16 22:18:27 Done.
1608 profile = profile->GetOffTheRecordProfile();
1609 }
1610
1611 ChooserContextBase* chooser_context = chooser_type->get_context(profile);
1612 chooser_context->RevokeObjectPermission(requesting_origin, embedding_origin,
1613 *object);
1614 // TODO(reillyg): Record this in UMA or something.
1615 }
1616
1399 void ContentSettingsHandler::RegisterMessages() { 1617 void ContentSettingsHandler::RegisterMessages() {
1400 web_ui()->RegisterMessageCallback("setContentFilter", 1618 web_ui()->RegisterMessageCallback("setContentFilter",
1401 base::Bind(&ContentSettingsHandler::SetContentFilter, 1619 base::Bind(&ContentSettingsHandler::SetContentFilter,
1402 base::Unretained(this))); 1620 base::Unretained(this)));
1403 web_ui()->RegisterMessageCallback("removeException", 1621 web_ui()->RegisterMessageCallback("removeException",
1404 base::Bind(&ContentSettingsHandler::RemoveException, 1622 base::Bind(&ContentSettingsHandler::RemoveException,
1405 base::Unretained(this))); 1623 base::Unretained(this)));
1406 web_ui()->RegisterMessageCallback("setException", 1624 web_ui()->RegisterMessageCallback("setException",
1407 base::Bind(&ContentSettingsHandler::SetException, 1625 base::Bind(&ContentSettingsHandler::SetException,
1408 base::Unretained(this))); 1626 base::Unretained(this)));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 CHECK(args->GetString(0, &type_string)); 1671 CHECK(args->GetString(0, &type_string));
1454 1672
1455 // Zoom levels are no actual content type so we need to handle them 1673 // Zoom levels are no actual content type so we need to handle them
1456 // separately. They would not be recognized by 1674 // separately. They would not be recognized by
1457 // ContentSettingsTypeFromGroupName. 1675 // ContentSettingsTypeFromGroupName.
1458 if (type_string == kZoomContentType) { 1676 if (type_string == kZoomContentType) {
1459 RemoveZoomLevelException(args); 1677 RemoveZoomLevelException(args);
1460 return; 1678 return;
1461 } 1679 }
1462 1680
1681 const ChooserTypeNameEntry* chooser_type =
1682 ChooserTypeFromGroupName(type_string);
1683 if (chooser_type) {
1684 RemoveChooserException(chooser_type, args);
1685 return;
1686 }
1687
1463 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 1688 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1464 RemoveExceptionFromHostContentSettingsMap(args, type); 1689 RemoveExceptionFromHostContentSettingsMap(args, type);
1465 1690
1466 WebSiteSettingsUmaUtil::LogPermissionChange( 1691 WebSiteSettingsUmaUtil::LogPermissionChange(
1467 type, ContentSetting::CONTENT_SETTING_DEFAULT); 1692 type, ContentSetting::CONTENT_SETTING_DEFAULT);
1468 } 1693 }
1469 1694
1470 void ContentSettingsHandler::SetException(const base::ListValue* args) { 1695 void ContentSettingsHandler::SetException(const base::ListValue* args) {
1471 std::string type_string; 1696 std::string type_string;
1472 CHECK(args->GetString(0, &type_string)); 1697 CHECK(args->GetString(0, &type_string));
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 1904
1680 // Exceptions apply only when the feature is enabled. 1905 // Exceptions apply only when the feature is enabled.
1681 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui())); 1906 PrefService* prefs = user_prefs::UserPrefs::Get(GetBrowserContext(web_ui()));
1682 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1907 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1683 web_ui()->CallJavascriptFunction( 1908 web_ui()->CallJavascriptFunction(
1684 "ContentSettings.enableProtectedContentExceptions", 1909 "ContentSettings.enableProtectedContentExceptions",
1685 base::FundamentalValue(enable_exceptions)); 1910 base::FundamentalValue(enable_exceptions));
1686 } 1911 }
1687 1912
1688 } // namespace options 1913 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698