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

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

Powered by Google App Engine
This is Rietveld 408576698