OLD | NEW |
---|---|
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 <map> | 8 #include <map> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_number_conversions.h" | |
14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/content_settings/content_settings_details.h" | 20 #include "chrome/browser/content_settings/content_settings_details.h" |
19 #include "chrome/browser/content_settings/content_settings_utils.h" | 21 #include "chrome/browser/content_settings/content_settings_utils.h" |
20 #include "chrome/browser/content_settings/host_content_settings_map.h" | 22 #include "chrome/browser/content_settings/host_content_settings_map.h" |
21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 23 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
22 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 24 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 25 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 26 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
25 #include "chrome/browser/google/google_util.h" | 27 #include "chrome/browser/google/google_util.h" |
26 #include "chrome/browser/notifications/desktop_notification_service.h" | 28 #include "chrome/browser/notifications/desktop_notification_service.h" |
27 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 29 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
28 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/ui/browser_list.h" | 31 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/content_settings.h" | 33 #include "chrome/common/content_settings.h" |
32 #include "chrome/common/content_settings_pattern.h" | 34 #include "chrome/common/content_settings_pattern.h" |
33 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 35 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
36 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
38 #include "content/public/browser/notification_types.h" | 40 #include "content/public/browser/notification_types.h" |
39 #include "content/public/browser/user_metrics.h" | 41 #include "content/public/browser/user_metrics.h" |
40 #include "content/public/browser/web_ui.h" | 42 #include "content/public/browser/web_ui.h" |
41 #include "content/public/common/content_switches.h" | 43 #include "content/public/common/content_switches.h" |
44 #include "content/public/common/page_zoom.h" | |
45 #include "content/public/common/url_constants.h" | |
42 #include "extensions/common/extension_set.h" | 46 #include "extensions/common/extension_set.h" |
43 #include "extensions/common/permissions/api_permission.h" | 47 #include "extensions/common/permissions/api_permission.h" |
44 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
45 #include "grit/locale_settings.h" | 49 #include "grit/locale_settings.h" |
46 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
47 | 51 |
48 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
49 #include "chrome/browser/chromeos/login/user_manager.h" | 53 #include "chrome/browser/chromeos/login/user_manager.h" |
50 #endif | 54 #endif |
51 | 55 |
(...skipping 24 matching lines...) Expand all Loading... | |
76 "https://support.google.com/chrome/?p=settings_manage_exceptions"; | 80 "https://support.google.com/chrome/?p=settings_manage_exceptions"; |
77 | 81 |
78 const char* kSetting = "setting"; | 82 const char* kSetting = "setting"; |
79 const char* kOrigin = "origin"; | 83 const char* kOrigin = "origin"; |
80 const char* kSource = "source"; | 84 const char* kSource = "source"; |
81 const char* kAppName = "appName"; | 85 const char* kAppName = "appName"; |
82 const char* kAppId = "appId"; | 86 const char* kAppId = "appId"; |
83 const char* kEmbeddingOrigin = "embeddingOrigin"; | 87 const char* kEmbeddingOrigin = "embeddingOrigin"; |
84 const char* kPreferencesSource = "preference"; | 88 const char* kPreferencesSource = "preference"; |
85 const char* kVideoSetting = "video"; | 89 const char* kVideoSetting = "video"; |
90 const char* kZoom = "zoom"; | |
86 | 91 |
87 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { | 92 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { |
88 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, | 93 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, |
89 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, | 94 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, |
90 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, | 95 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, |
91 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, | 96 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, |
92 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, | 97 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, |
93 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, | 98 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, |
94 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, | 99 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, |
95 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, | 100 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, |
96 {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, | 101 {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, |
97 {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, | 102 {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, |
98 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "register-protocol-handler"}, | 103 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, "register-protocol-handler"}, |
99 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream"}, | 104 {CONTENT_SETTINGS_TYPE_MEDIASTREAM, "media-stream"}, |
100 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"}, | 105 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "media-stream-mic"}, |
101 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"}, | 106 {CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "media-stream-camera"}, |
102 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"}, | 107 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, "ppapi-broker"}, |
103 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "multiple-automatic-downloads"}, | 108 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, "multiple-automatic-downloads"}, |
104 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"}, | 109 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, "midi-sysex"}, |
105 #if defined(OS_CHROMEOS) | 110 #if defined(OS_CHROMEOS) |
106 {CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, "protectedContent"}, | 111 {CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, "protectedContent"}, |
107 #endif | 112 #endif |
108 }; | 113 }; |
109 | 114 |
115 // A pseudo content type. We use it to display data like a content setting even | |
116 // though it is not a real content setting. | |
117 const char* kZoomContentType = "zoomlevels"; | |
118 | |
110 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | 119 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { |
111 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 120 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { |
112 if (name == kContentSettingsTypeGroupNames[i].name) | 121 if (name == kContentSettingsTypeGroupNames[i].name) |
113 return kContentSettingsTypeGroupNames[i].type; | 122 return kContentSettingsTypeGroupNames[i].type; |
114 } | 123 } |
115 | 124 |
116 NOTREACHED() << name << " is not a recognized content settings type."; | 125 NOTREACHED() << name << " is not a recognized content settings type."; |
117 return CONTENT_SETTINGS_TYPE_DEFAULT; | 126 return CONTENT_SETTINGS_TYPE_DEFAULT; |
118 } | 127 } |
119 | 128 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 // Retrieve the launch URL. | 252 // Retrieve the launch URL. |
244 GURL launch_url = | 253 GURL launch_url = |
245 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); | 254 extensions::AppLaunchInfo::GetLaunchWebURL(extension->get()); |
246 // Skip adding the launch URL if it is part of the web extent. | 255 // Skip adding the launch URL if it is part of the web extent. |
247 if (web_extent.MatchesURL(launch_url)) | 256 if (web_extent.MatchesURL(launch_url)) |
248 continue; | 257 continue; |
249 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions); | 258 AddExceptionForHostedApp(launch_url.spec(), *extension->get(), exceptions); |
250 } | 259 } |
251 } | 260 } |
252 | 261 |
262 // Sort ZoomLevelChanges by host and scheme | |
263 // (a.com < http://a.com < https://a.com < b.com) | |
Dan Beam
2014/03/15 15:28:51
nit: punctuation
battre
2014/03/17 23:00:19
Done.
| |
264 bool ZoomLevelChangeLessThan(const content::HostZoomMap::ZoomLevelChange& a, | |
Dan Beam
2014/03/15 15:28:51
nit: ZoomHostSort
battre
2014/03/17 23:00:19
Done.
| |
265 const content::HostZoomMap::ZoomLevelChange& b) { | |
266 if (a.host < b.host) | |
267 return true; | |
268 if (a.host > b.host) | |
269 return false; | |
270 return a.scheme < b.scheme; | |
Dan Beam
2014/03/15 15:28:51
nit:
return a.host == b.host ? a.scheme < b.schem
battre
2014/03/17 23:00:19
Done.
| |
271 } | |
272 | |
253 } // namespace | 273 } // namespace |
254 | 274 |
255 namespace options { | 275 namespace options { |
256 | 276 |
257 ContentSettingsHandler::MediaSettingsInfo::MediaSettingsInfo() | 277 ContentSettingsHandler::MediaSettingsInfo::MediaSettingsInfo() |
258 : flash_default_setting(CONTENT_SETTING_DEFAULT), | 278 : flash_default_setting(CONTENT_SETTING_DEFAULT), |
259 flash_settings_initialized(false), | 279 flash_settings_initialized(false), |
260 last_flash_refresh_request_id(0), | 280 last_flash_refresh_request_id(0), |
261 show_flash_default_link(false), | 281 show_flash_default_link(false), |
262 show_flash_exceptions_link(false), | 282 show_flash_exceptions_link(false), |
(...skipping 21 matching lines...) Expand all Loading... | |
284 { "allowException", IDS_EXCEPTIONS_ALLOW_BUTTON }, | 304 { "allowException", IDS_EXCEPTIONS_ALLOW_BUTTON }, |
285 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, | 305 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, |
286 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, | 306 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, |
287 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, | 307 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, |
288 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, | 308 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, |
289 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, | 309 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, |
290 { "manageExceptions", IDS_EXCEPTIONS_MANAGE }, | 310 { "manageExceptions", IDS_EXCEPTIONS_MANAGE }, |
291 { "manage_handlers", IDS_HANDLERS_MANAGE }, | 311 { "manage_handlers", IDS_HANDLERS_MANAGE }, |
292 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, | 312 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, |
293 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, | 313 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, |
314 { "exceptionZoomHeader", IDS_EXCEPTIONS_ZOOM_HEADER }, | |
294 { "embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST }, | 315 { "embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST }, |
295 // Cookies filter. | 316 // Cookies filter. |
296 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, | 317 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, |
297 { "cookies_header", IDS_COOKIES_HEADER }, | 318 { "cookies_header", IDS_COOKIES_HEADER }, |
298 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, | 319 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, |
299 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, | 320 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, |
300 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, | 321 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, |
301 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, | 322 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, |
302 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, | 323 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, |
303 { "cookies_lso_clear_when_close", IDS_COOKIES_LSO_CLEAR_WHEN_CLOSE_CHKBOX }, | 324 { "cookies_lso_clear_when_close", IDS_COOKIES_LSO_CLEAR_WHEN_CLOSE_CHKBOX }, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 IDS_AUTOMATIC_DOWNLOADS_ALLOW_RADIO }, | 414 IDS_AUTOMATIC_DOWNLOADS_ALLOW_RADIO }, |
394 { "multiple-automatic-downloads_ask", | 415 { "multiple-automatic-downloads_ask", |
395 IDS_AUTOMATIC_DOWNLOADS_ASK_RADIO }, | 416 IDS_AUTOMATIC_DOWNLOADS_ASK_RADIO }, |
396 { "multiple-automatic-downloads_block", | 417 { "multiple-automatic-downloads_block", |
397 IDS_AUTOMATIC_DOWNLOADS_BLOCK_RADIO }, | 418 IDS_AUTOMATIC_DOWNLOADS_BLOCK_RADIO }, |
398 // MIDI system exclusive messages | 419 // MIDI system exclusive messages |
399 { "midi-sysex_header", IDS_MIDI_SYSEX_TAB_LABEL }, | 420 { "midi-sysex_header", IDS_MIDI_SYSEX_TAB_LABEL }, |
400 { "midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO }, | 421 { "midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO }, |
401 { "midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO }, | 422 { "midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO }, |
402 { "midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO }, | 423 { "midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO }, |
424 { "zoomlevels_header", IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL }, | |
425 { "zoomLevelsManage", IDS_ZOOMLEVELS_MANAGE_BUTTON }, | |
403 }; | 426 }; |
404 | 427 |
405 RegisterStrings(localized_strings, resources, arraysize(resources)); | 428 RegisterStrings(localized_strings, resources, arraysize(resources)); |
406 RegisterTitle(localized_strings, "contentSettingsPage", | 429 RegisterTitle(localized_strings, "contentSettingsPage", |
407 IDS_CONTENT_SETTINGS_TITLE); | 430 IDS_CONTENT_SETTINGS_TITLE); |
408 | 431 |
409 // Register titles for each of the individual settings whose exception | 432 // Register titles for each of the individual settings whose exception |
410 // dialogs will be processed by |ContentSettingsHandler|. | 433 // dialogs will be processed by |ContentSettingsHandler|. |
411 RegisterTitle(localized_strings, "cookies", | 434 RegisterTitle(localized_strings, "cookies", |
412 IDS_COOKIES_TAB_LABEL); | 435 IDS_COOKIES_TAB_LABEL); |
(...skipping 18 matching lines...) Expand all Loading... | |
431 IDS_PROTECTED_CONTENT_TAB_LABEL); | 454 IDS_PROTECTED_CONTENT_TAB_LABEL); |
432 #endif | 455 #endif |
433 RegisterTitle(localized_strings, "media-stream", | 456 RegisterTitle(localized_strings, "media-stream", |
434 IDS_MEDIA_STREAM_TAB_LABEL); | 457 IDS_MEDIA_STREAM_TAB_LABEL); |
435 RegisterTitle(localized_strings, "ppapi-broker", | 458 RegisterTitle(localized_strings, "ppapi-broker", |
436 IDS_PPAPI_BROKER_TAB_LABEL); | 459 IDS_PPAPI_BROKER_TAB_LABEL); |
437 RegisterTitle(localized_strings, "multiple-automatic-downloads", | 460 RegisterTitle(localized_strings, "multiple-automatic-downloads", |
438 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL); | 461 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL); |
439 RegisterTitle(localized_strings, "midi-sysex", | 462 RegisterTitle(localized_strings, "midi-sysex", |
440 IDS_MIDI_SYSEX_TAB_LABEL); | 463 IDS_MIDI_SYSEX_TAB_LABEL); |
464 RegisterTitle(localized_strings, "zoomlevels", | |
465 IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL); | |
441 | 466 |
442 localized_strings->SetBoolean("newContentSettings", | 467 localized_strings->SetBoolean("newContentSettings", |
443 CommandLine::ForCurrentProcess()->HasSwitch(switches::kContentSettings2)); | 468 CommandLine::ForCurrentProcess()->HasSwitch(switches::kContentSettings2)); |
444 localized_strings->SetString( | 469 localized_strings->SetString( |
445 "exceptionsLearnMoreUrl", | 470 "exceptionsLearnMoreUrl", |
446 google_util::StringAppendGoogleLocaleParam( | 471 google_util::StringAppendGoogleLocaleParam( |
447 kExceptionsLearnMoreUrl)); | 472 kExceptionsLearnMoreUrl)); |
448 } | 473 } |
449 | 474 |
450 void ContentSettingsHandler::InitializeHandler() { | 475 void ContentSettingsHandler::InitializeHandler() { |
(...skipping 28 matching lines...) Expand all Loading... | |
479 pref_change_registrar_.Add( | 504 pref_change_registrar_.Add( |
480 prefs::kVideoCaptureAllowed, | 505 prefs::kVideoCaptureAllowed, |
481 base::Bind(&ContentSettingsHandler::UpdateMediaSettingsView, | 506 base::Bind(&ContentSettingsHandler::UpdateMediaSettingsView, |
482 base::Unretained(this))); | 507 base::Unretained(this))); |
483 pref_change_registrar_.Add( | 508 pref_change_registrar_.Add( |
484 prefs::kEnableDRM, | 509 prefs::kEnableDRM, |
485 base::Bind( | 510 base::Bind( |
486 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, | 511 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, |
487 base::Unretained(this))); | 512 base::Unretained(this))); |
488 | 513 |
514 content::HostZoomMap* host_zoom_map = | |
515 content::HostZoomMap::GetForBrowserContext(profile); | |
516 host_zoom_map_subscription_ = | |
517 host_zoom_map->AddZoomLevelChangedCallback( | |
518 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, | |
519 base::Unretained(this))); | |
520 | |
489 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); | 521 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); |
490 } | 522 } |
491 | 523 |
492 void ContentSettingsHandler::InitializePage() { | 524 void ContentSettingsHandler::InitializePage() { |
493 media_settings_ = MediaSettingsInfo(); | 525 media_settings_ = MediaSettingsInfo(); |
494 RefreshFlashMediaSettings(); | 526 RefreshFlashMediaSettings(); |
495 | 527 |
496 UpdateHandlersEnabledRadios(); | 528 UpdateHandlersEnabledRadios(); |
497 UpdateAllExceptionsViewsFromModel(); | 529 UpdateAllExceptionsViewsFromModel(); |
498 UpdateProtectedContentExceptionsButton(); | 530 UpdateProtectedContentExceptionsButton(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 web_ui()->CallJavascriptFunction( | 702 web_ui()->CallJavascriptFunction( |
671 "ContentSettings.updateHandlersEnabledRadios", | 703 "ContentSettings.updateHandlersEnabledRadios", |
672 handlers_enabled); | 704 handlers_enabled); |
673 } | 705 } |
674 | 706 |
675 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { | 707 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
676 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 708 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
677 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 709 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
678 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 710 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
679 } | 711 } |
712 // Zoom levels are no actual content type so we need to handle them | |
713 // separately. | |
Dan Beam
2014/03/15 15:28:51
nit: are not actually a content type,
battre
2014/03/17 23:00:19
Done.
| |
714 UpdateZoomLevelsExceptionsView(); | |
680 } | 715 } |
681 | 716 |
682 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { | 717 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { |
683 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 718 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
684 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 719 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
685 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 720 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
686 } | 721 } |
687 } | 722 } |
688 | 723 |
689 void ContentSettingsHandler::UpdateExceptionsViewFromModel( | 724 void ContentSettingsHandler::UpdateExceptionsViewFromModel( |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 web_ui()->CallJavascriptFunction( | 986 web_ui()->CallJavascriptFunction( |
952 "ContentSettings.showExperimentalWebMIDISettings", | 987 "ContentSettings.showExperimentalWebMIDISettings", |
953 base::FundamentalValue(true)); | 988 base::FundamentalValue(true)); |
954 } | 989 } |
955 | 990 |
956 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 991 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
957 UpdateExceptionsViewFromHostContentSettingsMap( | 992 UpdateExceptionsViewFromHostContentSettingsMap( |
958 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 993 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
959 } | 994 } |
960 | 995 |
996 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { | |
997 base::ListValue zoom_levels_exceptions; | |
998 | |
999 content::HostZoomMap* host_zoom_map = | |
1000 content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui())); | |
1001 content::HostZoomMap::ZoomLevelVector zoom_levels( | |
1002 host_zoom_map->GetAllZoomLevels()); | |
1003 std::sort(zoom_levels.begin(), zoom_levels.end(), ZoomLevelChangeLessThan); | |
1004 | |
1005 for (content::HostZoomMap::ZoomLevelVector::const_iterator i = | |
1006 zoom_levels.begin(); | |
1007 i != zoom_levels.end(); | |
1008 ++i) { | |
1009 base::DictionaryValue* exception = new base::DictionaryValue(); | |
Dan Beam
2014/03/15 15:28:51
nit: scoped_ptr + release() later
battre
2014/03/17 23:00:19
Done.
| |
1010 switch (i->mode) { | |
1011 case content::HostZoomMap::ZOOM_CHANGED_FOR_HOST: | |
1012 exception->SetString(kOrigin, i->host); | |
1013 break; | |
1014 case content::HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST: | |
1015 exception->SetString( | |
1016 kOrigin, i->scheme + content::kStandardSchemeSeparator + i->host); | |
1017 break; | |
1018 case content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM: | |
1019 NOTREACHED(); | |
1020 } | |
1021 exception->SetString(kSetting, | |
1022 ContentSettingToString(CONTENT_SETTING_DEFAULT)); | |
1023 | |
1024 // Calculate the zoom percent from the factor. Round up to the nearest whole | |
1025 // number. | |
1026 int zoom_percent = static_cast<int>( | |
1027 content::ZoomLevelToZoomFactor(i->zoom_level) * 100 + 0.5); | |
Dan Beam
2014/03/15 15:28:51
This is mildly cryptic but I didn't know std::roun
battre
2014/03/17 23:00:19
Ok, I'll leave it as it is.
| |
1028 exception->SetString( | |
1029 kZoom, | |
1030 l10n_util::GetStringFUTF16(IDS_ZOOM_PERCENT, | |
1031 base::IntToString16(zoom_percent))); | |
1032 exception->SetString(kSource, kPreferencesSource); | |
1033 // Append the new entry to the list and map. | |
1034 zoom_levels_exceptions.Append(exception); | |
1035 } | |
1036 | |
1037 base::StringValue type_string(kZoomContentType); | |
1038 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", | |
1039 type_string, zoom_levels_exceptions); | |
1040 } | |
1041 | |
961 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 1042 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
962 ContentSettingsType type) { | 1043 ContentSettingsType type) { |
963 base::ListValue exceptions; | 1044 base::ListValue exceptions; |
964 GetExceptionsFromHostContentSettingsMap( | 1045 GetExceptionsFromHostContentSettingsMap( |
965 GetContentSettingsMap(), type, &exceptions); | 1046 GetContentSettingsMap(), type, &exceptions); |
966 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); | 1047 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); |
967 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, | 1048 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, |
968 exceptions); | 1049 exceptions); |
969 | 1050 |
970 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 1051 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 ContentSettingsPattern::FromString(pattern), | 1229 ContentSettingsPattern::FromString(pattern), |
1149 secondary_pattern.empty() | 1230 secondary_pattern.empty() |
1150 ? ContentSettingsPattern::Wildcard() | 1231 ? ContentSettingsPattern::Wildcard() |
1151 : ContentSettingsPattern::FromString(secondary_pattern), | 1232 : ContentSettingsPattern::FromString(secondary_pattern), |
1152 type, | 1233 type, |
1153 std::string(), | 1234 std::string(), |
1154 NULL); | 1235 NULL); |
1155 } | 1236 } |
1156 } | 1237 } |
1157 | 1238 |
1239 void ContentSettingsHandler::RemoveZoomLevelException( | |
1240 const base::ListValue* args, size_t arg_index) { | |
1241 std::string mode; | |
1242 bool rv = args->GetString(arg_index++, &mode); | |
Dan Beam
2014/03/15 15:28:51
Can you just make this arg_index?
battre
2014/03/17 23:00:19
I could, but I think I would rather keep consisten
Dan Beam
2014/03/18 00:10:34
the existing code is:
1) silly
2) local to this fi
| |
1243 DCHECK(rv); | |
1244 | |
1245 std::string pattern; | |
1246 rv = args->GetString(arg_index++, &pattern); | |
Dan Beam
2014/03/15 15:28:51
and arg_index + 1
battre
2014/03/17 23:00:19
see above.
| |
1247 DCHECK(rv); | |
1248 | |
1249 content::HostZoomMap* host_zoom_map = | |
1250 content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui())); | |
1251 double default_level = host_zoom_map->GetDefaultZoomLevel(); | |
1252 | |
1253 std::string::size_type scheme_separator_position = | |
1254 pattern.find(content::kStandardSchemeSeparator); | |
1255 if (scheme_separator_position == std::string::npos) { | |
1256 host_zoom_map->SetZoomLevelForHost(pattern, default_level); | |
1257 } else { | |
1258 std::string scheme = pattern.substr(0, scheme_separator_position); | |
1259 std::string host = pattern.substr( | |
1260 scheme_separator_position + strlen(content::kStandardSchemeSeparator)); | |
1261 host_zoom_map->SetZoomLevelForHostAndScheme(scheme, host, default_level); | |
1262 } | |
1263 } | |
1264 | |
1158 void ContentSettingsHandler::RegisterMessages() { | 1265 void ContentSettingsHandler::RegisterMessages() { |
1159 web_ui()->RegisterMessageCallback("setContentFilter", | 1266 web_ui()->RegisterMessageCallback("setContentFilter", |
1160 base::Bind(&ContentSettingsHandler::SetContentFilter, | 1267 base::Bind(&ContentSettingsHandler::SetContentFilter, |
1161 base::Unretained(this))); | 1268 base::Unretained(this))); |
1162 web_ui()->RegisterMessageCallback("removeException", | 1269 web_ui()->RegisterMessageCallback("removeException", |
1163 base::Bind(&ContentSettingsHandler::RemoveException, | 1270 base::Bind(&ContentSettingsHandler::RemoveException, |
1164 base::Unretained(this))); | 1271 base::Unretained(this))); |
1165 web_ui()->RegisterMessageCallback("setException", | 1272 web_ui()->RegisterMessageCallback("setException", |
1166 base::Bind(&ContentSettingsHandler::SetException, | 1273 base::Bind(&ContentSettingsHandler::SetException, |
1167 base::Unretained(this))); | 1274 base::Unretained(this))); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 default: | 1382 default: |
1276 break; | 1383 break; |
1277 } | 1384 } |
1278 } | 1385 } |
1279 | 1386 |
1280 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { | 1387 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { |
1281 size_t arg_i = 0; | 1388 size_t arg_i = 0; |
1282 std::string type_string; | 1389 std::string type_string; |
1283 CHECK(args->GetString(arg_i++, &type_string)); | 1390 CHECK(args->GetString(arg_i++, &type_string)); |
1284 | 1391 |
1392 // Zoom levels are no actual content type so we need to handle them | |
1393 // separately. They would not be recognized by | |
1394 // ContentSettingsTypeFromGroupName. | |
1395 if (type_string == kZoomContentType) { | |
1396 RemoveZoomLevelException(args, arg_i); | |
1397 return; | |
1398 } | |
1399 | |
1285 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 1400 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
1286 switch (type) { | 1401 switch (type) { |
1287 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 1402 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
1288 RemoveNotificationException(args, arg_i); | 1403 RemoveNotificationException(args, arg_i); |
1289 break; | 1404 break; |
1290 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 1405 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
1291 RemoveMediaException(args, arg_i); | 1406 RemoveMediaException(args, arg_i); |
1292 break; | 1407 break; |
1293 default: | 1408 default: |
1294 RemoveExceptionFromHostContentSettingsMap(args, arg_i, type); | 1409 RemoveExceptionFromHostContentSettingsMap(args, arg_i, type); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 ShowFlashMediaLink(DEFAULT_SETTING, false); | 1508 ShowFlashMediaLink(DEFAULT_SETTING, false); |
1394 ShowFlashMediaLink(EXCEPTIONS, false); | 1509 ShowFlashMediaLink(EXCEPTIONS, false); |
1395 | 1510 |
1396 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 1511 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
1397 if (prefs->GetBoolean(prefs::kPepperFlashSettingsEnabled)) | 1512 if (prefs->GetBoolean(prefs::kPepperFlashSettingsEnabled)) |
1398 RefreshFlashMediaSettings(); | 1513 RefreshFlashMediaSettings(); |
1399 else | 1514 else |
1400 media_settings_.flash_settings_initialized = false; | 1515 media_settings_.flash_settings_initialized = false; |
1401 } | 1516 } |
1402 | 1517 |
1518 void ContentSettingsHandler::OnZoomLevelChanged( | |
1519 const content::HostZoomMap::ZoomLevelChange& change) { | |
1520 UpdateZoomLevelsExceptionsView(); | |
1521 } | |
1522 | |
1403 void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) { | 1523 void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) { |
1404 bool& show_link = link_type == DEFAULT_SETTING ? | 1524 bool& show_link = link_type == DEFAULT_SETTING ? |
1405 media_settings_.show_flash_default_link : | 1525 media_settings_.show_flash_default_link : |
1406 media_settings_.show_flash_exceptions_link; | 1526 media_settings_.show_flash_exceptions_link; |
1407 if (show_link != show) { | 1527 if (show_link != show) { |
1408 web_ui()->CallJavascriptFunction( | 1528 web_ui()->CallJavascriptFunction( |
1409 link_type == DEFAULT_SETTING ? | 1529 link_type == DEFAULT_SETTING ? |
1410 "ContentSettings.showMediaPepperFlashDefaultLink" : | 1530 "ContentSettings.showMediaPepperFlashDefaultLink" : |
1411 "ContentSettings.showMediaPepperFlashExceptionsLink", | 1531 "ContentSettings.showMediaPepperFlashExceptionsLink", |
1412 base::FundamentalValue(show)); | 1532 base::FundamentalValue(show)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { | 1582 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { |
1463 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 1583 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
1464 // Exceptions apply only when the feature is enabled. | 1584 // Exceptions apply only when the feature is enabled. |
1465 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1585 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
1466 web_ui()->CallJavascriptFunction( | 1586 web_ui()->CallJavascriptFunction( |
1467 "ContentSettings.enableProtectedContentExceptions", | 1587 "ContentSettings.enableProtectedContentExceptions", |
1468 base::FundamentalValue(enable_exceptions)); | 1588 base::FundamentalValue(enable_exceptions)); |
1469 } | 1589 } |
1470 | 1590 |
1471 } // namespace options | 1591 } // namespace options |
OLD | NEW |