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

Side by Side Diff: chrome/browser/ui/webui/options/content_settings_handler.cc

Issue 197523002: Show Zoom Levels as content settings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 6 years, 9 months 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 | Annotate | Revision Log
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 <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
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
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
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
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
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->SetBoolean("newContentSettings", 463 localized_strings->SetBoolean("newContentSettings",
443 CommandLine::ForCurrentProcess()->HasSwitch(switches::kContentSettings2)); 464 CommandLine::ForCurrentProcess()->HasSwitch(switches::kContentSettings2));
444 localized_strings->SetString( 465 localized_strings->SetString(
445 "exceptionsLearnMoreUrl", 466 "exceptionsLearnMoreUrl",
446 google_util::StringAppendGoogleLocaleParam( 467 google_util::StringAppendGoogleLocaleParam(
447 kExceptionsLearnMoreUrl)); 468 kExceptionsLearnMoreUrl));
448 } 469 }
449 470
450 void ContentSettingsHandler::InitializeHandler() { 471 void ContentSettingsHandler::InitializeHandler() {
(...skipping 28 matching lines...) Expand all
479 pref_change_registrar_.Add( 500 pref_change_registrar_.Add(
480 prefs::kVideoCaptureAllowed, 501 prefs::kVideoCaptureAllowed,
481 base::Bind(&ContentSettingsHandler::UpdateMediaSettingsView, 502 base::Bind(&ContentSettingsHandler::UpdateMediaSettingsView,
482 base::Unretained(this))); 503 base::Unretained(this)));
483 pref_change_registrar_.Add( 504 pref_change_registrar_.Add(
484 prefs::kEnableDRM, 505 prefs::kEnableDRM,
485 base::Bind( 506 base::Bind(
486 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton, 507 &ContentSettingsHandler::UpdateProtectedContentExceptionsButton,
487 base::Unretained(this))); 508 base::Unretained(this)));
488 509
510 content::HostZoomMap* host_zoom_map =
511 content::HostZoomMap::GetForBrowserContext(profile);
512 host_zoom_map_subscription_ =
513 host_zoom_map->AddZoomLevelChangedCallback(
514 base::Bind(&ContentSettingsHandler::OnZoomLevelChanged,
515 base::Unretained(this)));
516
489 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); 517 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile));
490 } 518 }
491 519
492 void ContentSettingsHandler::InitializePage() { 520 void ContentSettingsHandler::InitializePage() {
493 media_settings_ = MediaSettingsInfo(); 521 media_settings_ = MediaSettingsInfo();
494 RefreshFlashMediaSettings(); 522 RefreshFlashMediaSettings();
495 523
496 UpdateHandlersEnabledRadios(); 524 UpdateHandlersEnabledRadios();
497 UpdateAllExceptionsViewsFromModel(); 525 UpdateAllExceptionsViewsFromModel();
498 UpdateProtectedContentExceptionsButton(); 526 UpdateProtectedContentExceptionsButton();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 web_ui()->CallJavascriptFunction( 698 web_ui()->CallJavascriptFunction(
671 "ContentSettings.updateHandlersEnabledRadios", 699 "ContentSettings.updateHandlersEnabledRadios",
672 handlers_enabled); 700 handlers_enabled);
673 } 701 }
674 702
675 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { 703 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() {
676 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; 704 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
677 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { 705 type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
678 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); 706 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type));
679 } 707 }
708 // Zoom levels are not actually a content type so we need to handle them
709 // separately.
710 UpdateZoomLevelsExceptionsView();
680 } 711 }
681 712
682 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { 713 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() {
683 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; 714 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1;
684 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { 715 type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
685 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); 716 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type));
686 } 717 }
687 } 718 }
688 719
689 void ContentSettingsHandler::UpdateExceptionsViewFromModel( 720 void ContentSettingsHandler::UpdateExceptionsViewFromModel(
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 web_ui()->CallJavascriptFunction( 982 web_ui()->CallJavascriptFunction(
952 "ContentSettings.showExperimentalWebMIDISettings", 983 "ContentSettings.showExperimentalWebMIDISettings",
953 base::FundamentalValue(true)); 984 base::FundamentalValue(true));
954 } 985 }
955 986
956 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 987 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
957 UpdateExceptionsViewFromHostContentSettingsMap( 988 UpdateExceptionsViewFromHostContentSettingsMap(
958 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 989 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
959 } 990 }
960 991
992 void ContentSettingsHandler::UpdateZoomLevelsExceptionsView() {
993 base::ListValue zoom_levels_exceptions;
994
995 content::HostZoomMap* host_zoom_map =
996 content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui()));
997 content::HostZoomMap::ZoomLevelVector zoom_levels(
998 host_zoom_map->GetAllZoomLevels());
999 std::sort(zoom_levels.begin(), zoom_levels.end(), HostZoomSort);
1000
1001 for (content::HostZoomMap::ZoomLevelVector::const_iterator i =
1002 zoom_levels.begin();
1003 i != zoom_levels.end();
1004 ++i) {
1005 scoped_ptr<base::DictionaryValue> exception(new base::DictionaryValue);
1006 switch (i->mode) {
1007 case content::HostZoomMap::ZOOM_CHANGED_FOR_HOST:
1008 exception->SetString(kOrigin, i->host);
1009 break;
1010 case content::HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST:
1011 exception->SetString(
1012 kOrigin, i->scheme + content::kStandardSchemeSeparator + i->host);
1013 break;
1014 case content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM:
1015 NOTREACHED();
1016 }
1017 exception->SetString(kSetting,
1018 ContentSettingToString(CONTENT_SETTING_DEFAULT));
1019
1020 // Calculate the zoom percent from the factor. Round up to the nearest whole
1021 // number.
1022 int zoom_percent = static_cast<int>(
1023 content::ZoomLevelToZoomFactor(i->zoom_level) * 100 + 0.5);
1024 exception->SetString(
1025 kZoom,
1026 l10n_util::GetStringFUTF16(IDS_ZOOM_PERCENT,
1027 base::IntToString16(zoom_percent)));
1028 exception->SetString(kSource, kPreferencesSource);
1029 // Append the new entry to the list and map.
1030 zoom_levels_exceptions.Append(exception.release());
1031 }
1032
1033 base::StringValue type_string(kZoomContentType);
1034 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions",
1035 type_string, zoom_levels_exceptions);
1036 }
1037
961 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( 1038 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap(
962 ContentSettingsType type) { 1039 ContentSettingsType type) {
963 base::ListValue exceptions; 1040 base::ListValue exceptions;
964 GetExceptionsFromHostContentSettingsMap( 1041 GetExceptionsFromHostContentSettingsMap(
965 GetContentSettingsMap(), type, &exceptions); 1042 GetContentSettingsMap(), type, &exceptions);
966 base::StringValue type_string(ContentSettingsTypeToGroupName(type)); 1043 base::StringValue type_string(ContentSettingsTypeToGroupName(type));
967 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string, 1044 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", type_string,
968 exceptions); 1045 exceptions);
969 1046
970 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); 1047 UpdateExceptionsViewFromOTRHostContentSettingsMap(type);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 ContentSettingsPattern::FromString(pattern), 1225 ContentSettingsPattern::FromString(pattern),
1149 secondary_pattern.empty() 1226 secondary_pattern.empty()
1150 ? ContentSettingsPattern::Wildcard() 1227 ? ContentSettingsPattern::Wildcard()
1151 : ContentSettingsPattern::FromString(secondary_pattern), 1228 : ContentSettingsPattern::FromString(secondary_pattern),
1152 type, 1229 type,
1153 std::string(), 1230 std::string(),
1154 NULL); 1231 NULL);
1155 } 1232 }
1156 } 1233 }
1157 1234
1235 void ContentSettingsHandler::RemoveZoomLevelException(
1236 const base::ListValue* args, size_t arg_index) {
1237 std::string mode;
1238 bool rv = args->GetString(arg_index++, &mode);
1239 DCHECK(rv);
1240
1241 std::string pattern;
1242 rv = args->GetString(arg_index++, &pattern);
1243 DCHECK(rv);
1244
1245 content::HostZoomMap* host_zoom_map =
1246 content::HostZoomMap::GetForBrowserContext(Profile::FromWebUI(web_ui()));
1247 double default_level = host_zoom_map->GetDefaultZoomLevel();
1248
1249 std::string::size_type scheme_separator_position =
1250 pattern.find(content::kStandardSchemeSeparator);
1251 if (scheme_separator_position == std::string::npos) {
1252 host_zoom_map->SetZoomLevelForHost(pattern, default_level);
1253 } else {
1254 std::string scheme = pattern.substr(0, scheme_separator_position);
1255 std::string host = pattern.substr(
1256 scheme_separator_position + strlen(content::kStandardSchemeSeparator));
1257 host_zoom_map->SetZoomLevelForHostAndScheme(scheme, host, default_level);
1258 }
1259 }
1260
1158 void ContentSettingsHandler::RegisterMessages() { 1261 void ContentSettingsHandler::RegisterMessages() {
1159 web_ui()->RegisterMessageCallback("setContentFilter", 1262 web_ui()->RegisterMessageCallback("setContentFilter",
1160 base::Bind(&ContentSettingsHandler::SetContentFilter, 1263 base::Bind(&ContentSettingsHandler::SetContentFilter,
1161 base::Unretained(this))); 1264 base::Unretained(this)));
1162 web_ui()->RegisterMessageCallback("removeException", 1265 web_ui()->RegisterMessageCallback("removeException",
1163 base::Bind(&ContentSettingsHandler::RemoveException, 1266 base::Bind(&ContentSettingsHandler::RemoveException,
1164 base::Unretained(this))); 1267 base::Unretained(this)));
1165 web_ui()->RegisterMessageCallback("setException", 1268 web_ui()->RegisterMessageCallback("setException",
1166 base::Bind(&ContentSettingsHandler::SetException, 1269 base::Bind(&ContentSettingsHandler::SetException,
1167 base::Unretained(this))); 1270 base::Unretained(this)));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 default: 1378 default:
1276 break; 1379 break;
1277 } 1380 }
1278 } 1381 }
1279 1382
1280 void ContentSettingsHandler::RemoveException(const base::ListValue* args) { 1383 void ContentSettingsHandler::RemoveException(const base::ListValue* args) {
1281 size_t arg_i = 0; 1384 size_t arg_i = 0;
1282 std::string type_string; 1385 std::string type_string;
1283 CHECK(args->GetString(arg_i++, &type_string)); 1386 CHECK(args->GetString(arg_i++, &type_string));
1284 1387
1388 // Zoom levels are no actual content type so we need to handle them
1389 // separately. They would not be recognized by
1390 // ContentSettingsTypeFromGroupName.
1391 if (type_string == kZoomContentType) {
1392 RemoveZoomLevelException(args, arg_i);
1393 return;
1394 }
1395
1285 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); 1396 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string);
1286 switch (type) { 1397 switch (type) {
1287 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 1398 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
1288 RemoveNotificationException(args, arg_i); 1399 RemoveNotificationException(args, arg_i);
1289 break; 1400 break;
1290 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: 1401 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
1291 RemoveMediaException(args, arg_i); 1402 RemoveMediaException(args, arg_i);
1292 break; 1403 break;
1293 default: 1404 default:
1294 RemoveExceptionFromHostContentSettingsMap(args, arg_i, type); 1405 RemoveExceptionFromHostContentSettingsMap(args, arg_i, type);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 ShowFlashMediaLink(DEFAULT_SETTING, false); 1504 ShowFlashMediaLink(DEFAULT_SETTING, false);
1394 ShowFlashMediaLink(EXCEPTIONS, false); 1505 ShowFlashMediaLink(EXCEPTIONS, false);
1395 1506
1396 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 1507 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1397 if (prefs->GetBoolean(prefs::kPepperFlashSettingsEnabled)) 1508 if (prefs->GetBoolean(prefs::kPepperFlashSettingsEnabled))
1398 RefreshFlashMediaSettings(); 1509 RefreshFlashMediaSettings();
1399 else 1510 else
1400 media_settings_.flash_settings_initialized = false; 1511 media_settings_.flash_settings_initialized = false;
1401 } 1512 }
1402 1513
1514 void ContentSettingsHandler::OnZoomLevelChanged(
1515 const content::HostZoomMap::ZoomLevelChange& change) {
1516 UpdateZoomLevelsExceptionsView();
1517 }
1518
1403 void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) { 1519 void ContentSettingsHandler::ShowFlashMediaLink(LinkType link_type, bool show) {
1404 bool& show_link = link_type == DEFAULT_SETTING ? 1520 bool& show_link = link_type == DEFAULT_SETTING ?
1405 media_settings_.show_flash_default_link : 1521 media_settings_.show_flash_default_link :
1406 media_settings_.show_flash_exceptions_link; 1522 media_settings_.show_flash_exceptions_link;
1407 if (show_link != show) { 1523 if (show_link != show) {
1408 web_ui()->CallJavascriptFunction( 1524 web_ui()->CallJavascriptFunction(
1409 link_type == DEFAULT_SETTING ? 1525 link_type == DEFAULT_SETTING ?
1410 "ContentSettings.showMediaPepperFlashDefaultLink" : 1526 "ContentSettings.showMediaPepperFlashDefaultLink" :
1411 "ContentSettings.showMediaPepperFlashExceptionsLink", 1527 "ContentSettings.showMediaPepperFlashExceptionsLink",
1412 base::FundamentalValue(show)); 1528 base::FundamentalValue(show));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() { 1578 void ContentSettingsHandler::UpdateProtectedContentExceptionsButton() {
1463 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 1579 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
1464 // Exceptions apply only when the feature is enabled. 1580 // Exceptions apply only when the feature is enabled.
1465 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM); 1581 bool enable_exceptions = prefs->GetBoolean(prefs::kEnableDRM);
1466 web_ui()->CallJavascriptFunction( 1582 web_ui()->CallJavascriptFunction(
1467 "ContentSettings.enableProtectedContentExceptions", 1583 "ContentSettings.enableProtectedContentExceptions",
1468 base::FundamentalValue(enable_exceptions)); 1584 base::FundamentalValue(enable_exceptions));
1469 } 1585 }
1470 1586
1471 } // namespace options 1587 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698