| 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). |
| 264 bool HostZoomSort(const content::HostZoomMap::ZoomLevelChange& a, |
| 265 const content::HostZoomMap::ZoomLevelChange& b) { |
| 266 return a.host == b.host ? a.scheme < b.scheme : a.host < b.host; |
| 267 } |
| 268 |
| 253 } // namespace | 269 } // namespace |
| 254 | 270 |
| 255 namespace options { | 271 namespace options { |
| 256 | 272 |
| 257 ContentSettingsHandler::MediaSettingsInfo::MediaSettingsInfo() | 273 ContentSettingsHandler::MediaSettingsInfo::MediaSettingsInfo() |
| 258 : flash_default_setting(CONTENT_SETTING_DEFAULT), | 274 : flash_default_setting(CONTENT_SETTING_DEFAULT), |
| 259 flash_settings_initialized(false), | 275 flash_settings_initialized(false), |
| 260 last_flash_refresh_request_id(0), | 276 last_flash_refresh_request_id(0), |
| 261 show_flash_default_link(false), | 277 show_flash_default_link(false), |
| 262 show_flash_exceptions_link(false), | 278 show_flash_exceptions_link(false), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 284 { "allowException", IDS_EXCEPTIONS_ALLOW_BUTTON }, | 300 { "allowException", IDS_EXCEPTIONS_ALLOW_BUTTON }, |
| 285 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, | 301 { "blockException", IDS_EXCEPTIONS_BLOCK_BUTTON }, |
| 286 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, | 302 { "sessionException", IDS_EXCEPTIONS_SESSION_ONLY_BUTTON }, |
| 287 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, | 303 { "askException", IDS_EXCEPTIONS_ASK_BUTTON }, |
| 288 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, | 304 { "otr_exceptions_explanation", IDS_EXCEPTIONS_OTR_LABEL }, |
| 289 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, | 305 { "addNewExceptionInstructions", IDS_EXCEPTIONS_ADD_NEW_INSTRUCTIONS }, |
| 290 { "manageExceptions", IDS_EXCEPTIONS_MANAGE }, | 306 { "manageExceptions", IDS_EXCEPTIONS_MANAGE }, |
| 291 { "manage_handlers", IDS_HANDLERS_MANAGE }, | 307 { "manage_handlers", IDS_HANDLERS_MANAGE }, |
| 292 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, | 308 { "exceptionPatternHeader", IDS_EXCEPTIONS_PATTERN_HEADER }, |
| 293 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, | 309 { "exceptionBehaviorHeader", IDS_EXCEPTIONS_ACTION_HEADER }, |
| 310 { "exceptionZoomHeader", IDS_EXCEPTIONS_ZOOM_HEADER }, |
| 294 { "embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST }, | 311 { "embeddedOnHost", IDS_EXCEPTIONS_GEOLOCATION_EMBEDDED_ON_HOST }, |
| 295 // Cookies filter. | 312 // Cookies filter. |
| 296 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, | 313 { "cookies_tab_label", IDS_COOKIES_TAB_LABEL }, |
| 297 { "cookies_header", IDS_COOKIES_HEADER }, | 314 { "cookies_header", IDS_COOKIES_HEADER }, |
| 298 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, | 315 { "cookies_allow", IDS_COOKIES_ALLOW_RADIO }, |
| 299 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, | 316 { "cookies_block", IDS_COOKIES_BLOCK_RADIO }, |
| 300 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, | 317 { "cookies_session_only", IDS_COOKIES_SESSION_ONLY_RADIO }, |
| 301 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, | 318 { "cookies_block_3rd_party", IDS_COOKIES_BLOCK_3RDPARTY_CHKBOX }, |
| 302 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, | 319 { "cookies_clear_when_close", IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX }, |
| 303 { "cookies_lso_clear_when_close", IDS_COOKIES_LSO_CLEAR_WHEN_CLOSE_CHKBOX }, | 320 { "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 }, | 410 IDS_AUTOMATIC_DOWNLOADS_ALLOW_RADIO }, |
| 394 { "multiple-automatic-downloads_ask", | 411 { "multiple-automatic-downloads_ask", |
| 395 IDS_AUTOMATIC_DOWNLOADS_ASK_RADIO }, | 412 IDS_AUTOMATIC_DOWNLOADS_ASK_RADIO }, |
| 396 { "multiple-automatic-downloads_block", | 413 { "multiple-automatic-downloads_block", |
| 397 IDS_AUTOMATIC_DOWNLOADS_BLOCK_RADIO }, | 414 IDS_AUTOMATIC_DOWNLOADS_BLOCK_RADIO }, |
| 398 // MIDI system exclusive messages | 415 // MIDI system exclusive messages |
| 399 { "midi-sysex_header", IDS_MIDI_SYSEX_TAB_LABEL }, | 416 { "midi-sysex_header", IDS_MIDI_SYSEX_TAB_LABEL }, |
| 400 { "midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO }, | 417 { "midiSysExAllow", IDS_MIDI_SYSEX_ALLOW_RADIO }, |
| 401 { "midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO }, | 418 { "midiSysExAsk", IDS_MIDI_SYSEX_ASK_RADIO }, |
| 402 { "midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO }, | 419 { "midiSysExBlock", IDS_MIDI_SYSEX_BLOCK_RADIO }, |
| 420 { "zoomlevels_header", IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL }, |
| 421 { "zoomLevelsManage", IDS_ZOOMLEVELS_MANAGE_BUTTON }, |
| 403 }; | 422 }; |
| 404 | 423 |
| 405 RegisterStrings(localized_strings, resources, arraysize(resources)); | 424 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 406 RegisterTitle(localized_strings, "contentSettingsPage", | 425 RegisterTitle(localized_strings, "contentSettingsPage", |
| 407 IDS_CONTENT_SETTINGS_TITLE); | 426 IDS_CONTENT_SETTINGS_TITLE); |
| 408 | 427 |
| 409 // Register titles for each of the individual settings whose exception | 428 // Register titles for each of the individual settings whose exception |
| 410 // dialogs will be processed by |ContentSettingsHandler|. | 429 // dialogs will be processed by |ContentSettingsHandler|. |
| 411 RegisterTitle(localized_strings, "cookies", | 430 RegisterTitle(localized_strings, "cookies", |
| 412 IDS_COOKIES_TAB_LABEL); | 431 IDS_COOKIES_TAB_LABEL); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 431 IDS_PROTECTED_CONTENT_TAB_LABEL); | 450 IDS_PROTECTED_CONTENT_TAB_LABEL); |
| 432 #endif | 451 #endif |
| 433 RegisterTitle(localized_strings, "media-stream", | 452 RegisterTitle(localized_strings, "media-stream", |
| 434 IDS_MEDIA_STREAM_TAB_LABEL); | 453 IDS_MEDIA_STREAM_TAB_LABEL); |
| 435 RegisterTitle(localized_strings, "ppapi-broker", | 454 RegisterTitle(localized_strings, "ppapi-broker", |
| 436 IDS_PPAPI_BROKER_TAB_LABEL); | 455 IDS_PPAPI_BROKER_TAB_LABEL); |
| 437 RegisterTitle(localized_strings, "multiple-automatic-downloads", | 456 RegisterTitle(localized_strings, "multiple-automatic-downloads", |
| 438 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL); | 457 IDS_AUTOMATIC_DOWNLOADS_TAB_LABEL); |
| 439 RegisterTitle(localized_strings, "midi-sysex", | 458 RegisterTitle(localized_strings, "midi-sysex", |
| 440 IDS_MIDI_SYSEX_TAB_LABEL); | 459 IDS_MIDI_SYSEX_TAB_LABEL); |
| 460 RegisterTitle(localized_strings, "zoomlevels", |
| 461 IDS_ZOOMLEVELS_HEADER_AND_TAB_LABEL); |
| 441 | 462 |
| 442 localized_strings->SetString( | 463 localized_strings->SetString( |
| 443 "exceptionsLearnMoreUrl", | 464 "exceptionsLearnMoreUrl", |
| 444 google_util::StringAppendGoogleLocaleParam( | 465 google_util::StringAppendGoogleLocaleParam( |
| 445 kExceptionsLearnMoreUrl)); | 466 kExceptionsLearnMoreUrl)); |
| 446 } | 467 } |
| 447 | 468 |
| 448 void ContentSettingsHandler::InitializeHandler() { | 469 void ContentSettingsHandler::InitializeHandler() { |
| 449 notification_registrar_.Add( | 470 notification_registrar_.Add( |
| 450 this, chrome::NOTIFICATION_PROFILE_CREATED, | 471 this, chrome::NOTIFICATION_PROFILE_CREATED, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 477 pref_change_registrar_.Add( | 498 pref_change_registrar_.Add( |
| 478 prefs::kVideoCaptureAllowed, | 499 prefs::kVideoCaptureAllowed, |
| 479 base::Bind(&ContentSettingsHandler::UpdateMediaSettingsView, | 500 base::Bind(&ContentSettingsHandler::UpdateMediaSettingsView, |
| 480 base::Unretained(this))); | 501 base::Unretained(this))); |
| 481 pref_change_registrar_.Add( | 502 pref_change_registrar_.Add( |
| 482 prefs::kEnableDRM, | 503 prefs::kEnableDRM, |
| 483 base::Bind( | 504 base::Bind( |
| 484 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, | 505 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, |
| 485 base::Unretained(this))); | 506 base::Unretained(this))); |
| 486 | 507 |
| 508 content::HostZoomMap* host_zoom_map = |
| 509 content::HostZoomMap::GetForBrowserContext(profile); |
| 510 host_zoom_map_subscription_ = |
| 511 host_zoom_map->AddZoomLevelChangedCallback( |
| 512 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged, |
| 513 base::Unretained(this))); |
| 514 |
| 487 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); | 515 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); |
| 488 } | 516 } |
| 489 | 517 |
| 490 void ContentSettingsHandler::InitializePage() { | 518 void ContentSettingsHandler::InitializePage() { |
| 491 media_settings_ = MediaSettingsInfo(); | 519 media_settings_ = MediaSettingsInfo(); |
| 492 RefreshFlashMediaSettings(); | 520 RefreshFlashMediaSettings(); |
| 493 | 521 |
| 494 UpdateHandlersEnabledRadios(); | 522 UpdateHandlersEnabledRadios(); |
| 495 UpdateAllExceptionsViewsFromModel(); | 523 UpdateAllExceptionsViewsFromModel(); |
| 496 UpdateProtectedContentExceptionsButton(); | 524 UpdateProtectedContentExceptionsButton(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 web_ui()->CallJavascriptFunction( | 696 web_ui()->CallJavascriptFunction( |
| 669 "ContentSettings.updateHandlersEnabledRadios", | 697 "ContentSettings.updateHandlersEnabledRadios", |
| 670 handlers_enabled); | 698 handlers_enabled); |
| 671 } | 699 } |
| 672 | 700 |
| 673 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { | 701 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
| 674 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 702 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
| 675 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 703 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| 676 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 704 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
| 677 } | 705 } |
| 706 // Zoom levels are not actually a content type so we need to handle them |
| 707 // separately. |
| 708 UpdateZoomLevelsExceptionsView(); |
| 678 } | 709 } |
| 679 | 710 |
| 680 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { | 711 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { |
| 681 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 712 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
| 682 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 713 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
| 683 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 714 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); |
| 684 } | 715 } |
| 685 } | 716 } |
| 686 | 717 |
| 687 void ContentSettingsHandler::UpdateExceptionsViewFromModel( | 718 void ContentSettingsHandler::UpdateExceptionsViewFromModel( |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 web_ui()->CallJavascriptFunction( | 980 web_ui()->CallJavascriptFunction( |
| 950 "ContentSettings.showExperimentalWebMIDISettings", | 981 "ContentSettings.showExperimentalWebMIDISettings", |
| 951 base::FundamentalValue(true)); | 982 base::FundamentalValue(true)); |
| 952 } | 983 } |
| 953 | 984 |
| 954 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 985 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 955 UpdateExceptionsViewFromHostContentSettingsMap( | 986 UpdateExceptionsViewFromHostContentSettingsMap( |
| 956 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 987 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 957 } | 988 } |
| 958 | 989 |
| 990 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() { |
| 991 base::ListValue zoom_levels_exceptions; |
| 992 |
| 993 content::HostZoomMap* host_zoom_map = |
| 994 content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui())); |
| 995 content::HostZoomMap::ZoomLevelVector zoom_levels( |
| 996 host_zoom_map->GetAllZoomLevels()); |
| 997 std::sort(zoom_levels.begin(), zoom_levels.end(), HostZoomSort); |
| 998 |
| 999 for (content::HostZoomMap::ZoomLevelVector::const_iterator i = |
| 1000 zoom_levels.begin(); |
| 1001 i != zoom_levels.end(); |
| 1002 ++i) { |
| 1003 scoped_ptr<base::DictionaryValue> exception(new base::DictionaryValue); |
| 1004 switch (i->mode) { |
| 1005 case content::HostZoomMap::ZOOM_CHANGED_FOR_HOST: |
| 1006 exception->SetString(kOrigin, i->host); |
| 1007 break; |
| 1008 case content::HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST: |
| 1009 exception->SetString( |
| 1010 kOrigin, i->scheme + content::kStandardSchemeSeparator + i->host); |
| 1011 break; |
| 1012 case content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM: |
| 1013 NOTREACHED(); |
| 1014 } |
| 1015 exception->SetString(kSetting, |
| 1016 ContentSettingToString(CONTENT_SETTING_DEFAULT)); |
| 1017 |
| 1018 // Calculate the zoom percent from the factor. Round up to the nearest whole |
| 1019 // number. |
| 1020 int zoom_percent = static_cast<int>( |
| 1021 content::ZoomLevelToZoomFactor(i->zoom_level) * 100 + 0.5); |
| 1022 exception->SetString( |
| 1023 kZoom, |
| 1024 l10n_util::GetStringFUTF16(IDS_ZOOM_PERCENT, |
| 1025 base::IntToString16(zoom_percent))); |
| 1026 exception->SetString(kSource, kPreferencesSource); |
| 1027 // Append the new entry to the list and map. |
| 1028 zoom_levels_exceptions.Append(exception.release()); |
| 1029 } |
| 1030 |
| 1031 base::StringValue type_string(kZoomContentType); |
| 1032 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", |
| 1033 type_string, zoom_levels_exceptions); |
| 1034 } |
| 1035 |
| 959 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 1036 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
| 960 ContentSettingsType type) { | 1037 ContentSettingsType type) { |
| 961 base::ListValue exceptions; | 1038 base::ListValue exceptions; |
| 962 GetExceptionsFromHostContentSettingsMap( | 1039 GetExceptionsFromHostContentSettingsMap( |
| 963 GetContentSettingsMap(), type, &exceptions); | 1040 GetContentSettingsMap(), type, &exceptions); |
| 964 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); | 1041 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); |
| 965 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, | 1042 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, |
| 966 exceptions); | 1043 exceptions); |
| 967 | 1044 |
| 968 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 1045 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 ContentSettingsPattern::FromString(pattern), | 1223 ContentSettingsPattern::FromString(pattern), |
| 1147 secondary_pattern.empty() | 1224 secondary_pattern.empty() |
| 1148 ? ContentSettingsPattern::Wildcard() | 1225 ? ContentSettingsPattern::Wildcard() |
| 1149 : ContentSettingsPattern::FromString(secondary_pattern), | 1226 : ContentSettingsPattern::FromString(secondary_pattern), |
| 1150 type, | 1227 type, |
| 1151 std::string(), | 1228 std::string(), |
| 1152 NULL); | 1229 NULL); |
| 1153 } | 1230 } |
| 1154 } | 1231 } |
| 1155 | 1232 |
| 1233 void ContentSettingsHandler::RemoveZoomLevelException( |
| 1234 const base::ListValue* args, size_t arg_index) { |
| 1235 std::string mode; |
| 1236 bool rv = args->GetString(arg_index++, &mode); |
| 1237 DCHECK(rv); |
| 1238 |
| 1239 std::string pattern; |
| 1240 rv = args->GetString(arg_index++, &pattern); |
| 1241 DCHECK(rv); |
| 1242 |
| 1243 content::HostZoomMap* host_zoom_map = |
| 1244 content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui())); |
| 1245 double default_level = host_zoom_map->GetDefaultZoomLevel(); |
| 1246 |
| 1247 std::string::size_type scheme_separator_position = |
| 1248 pattern.find(content::kStandardSchemeSeparator); |
| 1249 if (scheme_separator_position == std::string::npos) { |
| 1250 host_zoom_map->SetZoomLevelForHost(pattern, default_level); |
| 1251 } else { |
| 1252 std::string scheme = pattern.substr(0, scheme_separator_position); |
| 1253 std::string host = pattern.substr( |
| 1254 scheme_separator_position + strlen(content::kStandardSchemeSeparator)); |
| 1255 host_zoom_map->SetZoomLevelForHostAndScheme(scheme, host, default_level); |
| 1256 } |
| 1257 } |
| 1258 |
| 1156 void ContentSettingsHandler::RegisterMessages() { | 1259 void ContentSettingsHandler::RegisterMessages() { |
| 1157 web_ui()->RegisterMessageCallback("setContentFilter", | 1260 web_ui()->RegisterMessageCallback("setContentFilter", |
| 1158 base::Bind(&ContentSettingsHandler::SetContentFilter, | 1261 base::Bind(&ContentSettingsHandler::SetContentFilter, |
| 1159 base::Unretained(this))); | 1262 base::Unretained(this))); |
| 1160 web_ui()->RegisterMessageCallback("removeException", | 1263 web_ui()->RegisterMessageCallback("removeException", |
| 1161 base::Bind(&ContentSettingsHandler::RemoveException, | 1264 base::Bind(&ContentSettingsHandler::RemoveException, |
| 1162 base::Unretained(this))); | 1265 base::Unretained(this))); |
| 1163 web_ui()->RegisterMessageCallback("setException", | 1266 web_ui()->RegisterMessageCallback("setException", |
| 1164 base::Bind(&ContentSettingsHandler::SetException, | 1267 base::Bind(&ContentSettingsHandler::SetException, |
| 1165 base::Unretained(this))); | 1268 base::Unretained(this))); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 default: | 1376 default: |
| 1274 break; | 1377 break; |
| 1275 } | 1378 } |
| 1276 } | 1379 } |
| 1277 | 1380 |
| 1278 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { | 1381 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { |
| 1279 size_t arg_i = 0; | 1382 size_t arg_i = 0; |
| 1280 std::string type_string; | 1383 std::string type_string; |
| 1281 CHECK(args->GetString(arg_i++, &type_string)); | 1384 CHECK(args->GetString(arg_i++, &type_string)); |
| 1282 | 1385 |
| 1386 // Zoom levels are no actual content type so we need to handle them |
| 1387 // separately. They would not be recognized by |
| 1388 // ContentSettingsTypeFromGroupName. |
| 1389 if (type_string == kZoomContentType) { |
| 1390 RemoveZoomLevelException(args, arg_i); |
| 1391 return; |
| 1392 } |
| 1393 |
| 1283 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 1394 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); |
| 1284 switch (type) { | 1395 switch (type) { |
| 1285 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 1396 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 1286 RemoveNotificationException(args, arg_i); | 1397 RemoveNotificationException(args, arg_i); |
| 1287 break; | 1398 break; |
| 1288 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: | 1399 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
| 1289 RemoveMediaException(args, arg_i); | 1400 RemoveMediaException(args, arg_i); |
| 1290 break; | 1401 break; |
| 1291 default: | 1402 default: |
| 1292 RemoveExceptionFromHostContentSettingsMap(args, arg_i, type); | 1403 RemoveExceptionFromHostContentSettingsMap(args, arg_i, type); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 ShowFlashMediaLink(DEFAULT_SETTING, false); | 1502 ShowFlashMediaLink(DEFAULT_SETTING, false); |
| 1392 ShowFlashMediaLink(EXCEPTIONS, false); | 1503 ShowFlashMediaLink(EXCEPTIONS, false); |
| 1393 | 1504 |
| 1394 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 1505 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 1395 if (prefs->GetBoolean(prefs::kPepperFlashSettingsEnabled)) | 1506 if (prefs->GetBoolean(prefs::kPepperFlashSettingsEnabled)) |
| 1396 RefreshFlashMediaSettings(); | 1507 RefreshFlashMediaSettings(); |
| 1397 else | 1508 else |
| 1398 media_settings_.flash_settings_initialized = false; | 1509 media_settings_.flash_settings_initialized = false; |
| 1399 } | 1510 } |
| 1400 | 1511 |
| 1512 void ContentSettingsHandler::OnZoomLevelChanged( |
| 1513 const content::HostZoomMap::ZoomLevelChange& change) { |
| 1514 UpdateZoomLevelsExceptionsView(); |
| 1515 } |
| 1516 |
| 1401 void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) { | 1517 void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) { |
| 1402 bool& show_link = link_type == DEFAULT_SETTING ? | 1518 bool& show_link = link_type == DEFAULT_SETTING ? |
| 1403 media_settings_.show_flash_default_link : | 1519 media_settings_.show_flash_default_link : |
| 1404 media_settings_.show_flash_exceptions_link; | 1520 media_settings_.show_flash_exceptions_link; |
| 1405 if (show_link != show) { | 1521 if (show_link != show) { |
| 1406 web_ui()->CallJavascriptFunction( | 1522 web_ui()->CallJavascriptFunction( |
| 1407 link_type == DEFAULT_SETTING ? | 1523 link_type == DEFAULT_SETTING ? |
| 1408 "ContentSettings.showMediaPepperFlashDefaultLink" : | 1524 "ContentSettings.showMediaPepperFlashDefaultLink" : |
| 1409 "ContentSettings.showMediaPepperFlashExceptionsLink", | 1525 "ContentSettings.showMediaPepperFlashExceptionsLink", |
| 1410 base::FundamentalValue(show)); | 1526 base::FundamentalValue(show)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { | 1576 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { |
| 1461 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 1577 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 1462 // Exceptions apply only when the feature is enabled. | 1578 // Exceptions apply only when the feature is enabled. |
| 1463 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); | 1579 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); |
| 1464 web_ui()->CallJavascriptFunction( | 1580 web_ui()->CallJavascriptFunction( |
| 1465 "ContentSettings.enableProtectedContentExceptions", | 1581 "ContentSettings.enableProtectedContentExceptions", |
| 1466 base::FundamentalValue(enable_exceptions)); | 1582 base::FundamentalValue(enable_exceptions)); |
| 1467 } | 1583 } |
| 1468 | 1584 |
| 1469 } // namespace options | 1585 } // namespace options |
| OLD | NEW |