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/options2/content_settings_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/content_settings_handler2.h" |
6 | 6 |
7 #include <map> | |
8 #include <string> | |
9 #include <vector> | 7 #include <vector> |
10 | 8 |
11 #include "base/bind.h" | 9 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 11 #include "base/command_line.h" |
14 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 13 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/content_settings/content_settings_details.h" | 15 #include "chrome/browser/content_settings/content_settings_details.h" |
18 #include "chrome/browser/content_settings/content_settings_utils.h" | 16 #include "chrome/browser/content_settings/content_settings_utils.h" |
(...skipping 15 matching lines...) Expand all Loading... |
34 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
35 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
36 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
38 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
39 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
40 #include "content/public/browser/web_ui.h" | 38 #include "content/public/browser/web_ui.h" |
41 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
42 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
43 #include "grit/locale_settings.h" | 41 #include "grit/locale_settings.h" |
| 42 #include "net/base/net_util.h" |
44 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
45 | 44 |
46 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
47 #include "chrome/browser/chromeos/login/user_manager.h" | 46 #include "chrome/browser/chromeos/login/user_manager.h" |
48 #endif | 47 #endif |
49 | 48 |
50 using content::UserMetricsAction; | 49 using content::UserMetricsAction; |
51 | 50 |
52 namespace { | 51 namespace { |
53 | 52 |
54 struct ContentSettingsTypeNameEntry { | 53 enum ExContentSettingsTypeEnum { |
55 ContentSettingsType type; | 54 EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC = |
56 const char* name; | 55 CONTENT_SETTINGS_NUM_TYPES, |
| 56 EX_CONTENT_SETTINGS_NUM_TYPES |
57 }; | 57 }; |
58 | 58 |
59 typedef std::map<ContentSettingsPattern, ContentSetting> OnePatternSettings; | 59 typedef std::map<ContentSettingsPattern, ContentSetting> OnePatternSettings; |
60 typedef std::map<ContentSettingsPattern, OnePatternSettings> | 60 typedef std::map<ContentSettingsPattern, OnePatternSettings> |
61 AllPatternsSettings; | 61 AllPatternsSettings; |
62 | 62 |
63 const char* kDisplayPattern = "displayPattern"; | 63 const char* kDisplayPattern = "displayPattern"; |
64 const char* kSetting = "setting"; | 64 const char* kSetting = "setting"; |
65 const char* kOrigin = "origin"; | 65 const char* kOrigin = "origin"; |
66 const char* kSource = "source"; | 66 const char* kSource = "source"; |
67 const char* kAppName = "appName"; | 67 const char* kAppName = "appName"; |
68 const char* kAppId = "appId"; | 68 const char* kAppId = "appId"; |
69 const char* kEmbeddingOrigin = "embeddingOrigin"; | 69 const char* kEmbeddingOrigin = "embeddingOrigin"; |
70 | 70 const char* kDefaultProviderID = "default"; |
71 const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { | 71 const char* kPreferencesSource = "preferences"; |
72 {CONTENT_SETTINGS_TYPE_COOKIES, "cookies"}, | |
73 {CONTENT_SETTINGS_TYPE_IMAGES, "images"}, | |
74 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, "javascript"}, | |
75 {CONTENT_SETTINGS_TYPE_PLUGINS, "plugins"}, | |
76 {CONTENT_SETTINGS_TYPE_POPUPS, "popups"}, | |
77 {CONTENT_SETTINGS_TYPE_GEOLOCATION, "location"}, | |
78 {CONTENT_SETTINGS_TYPE_NOTIFICATIONS, "notifications"}, | |
79 {CONTENT_SETTINGS_TYPE_INTENTS, "intents"}, | |
80 {CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, "auto-select-certificate"}, | |
81 {CONTENT_SETTINGS_TYPE_FULLSCREEN, "fullscreen"}, | |
82 {CONTENT_SETTINGS_TYPE_MOUSELOCK, "mouselock"}, | |
83 }; | |
84 COMPILE_ASSERT(arraysize(kContentSettingsTypeGroupNames) == | |
85 CONTENT_SETTINGS_NUM_TYPES, | |
86 MISSING_CONTENT_SETTINGS_TYPE); | |
87 | |
88 ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { | |
89 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | |
90 if (name == kContentSettingsTypeGroupNames[i].name) | |
91 return kContentSettingsTypeGroupNames[i].type; | |
92 } | |
93 | |
94 NOTREACHED() << name << " is not a recognized content settings type."; | |
95 return CONTENT_SETTINGS_TYPE_DEFAULT; | |
96 } | |
97 | 72 |
98 std::string ContentSettingToString(ContentSetting setting) { | 73 std::string ContentSettingToString(ContentSetting setting) { |
99 switch (setting) { | 74 switch (setting) { |
100 case CONTENT_SETTING_ALLOW: | 75 case CONTENT_SETTING_ALLOW: |
101 return "allow"; | 76 return "allow"; |
102 case CONTENT_SETTING_ASK: | 77 case CONTENT_SETTING_ASK: |
103 return "ask"; | 78 return "ask"; |
104 case CONTENT_SETTING_BLOCK: | 79 case CONTENT_SETTING_BLOCK: |
105 return "block"; | 80 return "block"; |
106 case CONTENT_SETTING_SESSION_ONLY: | 81 case CONTENT_SETTING_SESSION_ONLY: |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 212 } |
238 // Retrieve the launch URL. | 213 // Retrieve the launch URL. |
239 std::string launch_url_string = (*extension)->launch_web_url(); | 214 std::string launch_url_string = (*extension)->launch_web_url(); |
240 GURL launch_url(launch_url_string); | 215 GURL launch_url(launch_url_string); |
241 // Skip adding the launch URL if it is part of the web extent. | 216 // Skip adding the launch URL if it is part of the web extent. |
242 if (web_extent.MatchesURL(launch_url)) continue; | 217 if (web_extent.MatchesURL(launch_url)) continue; |
243 AddExceptionForHostedApp(launch_url_string, **extension, exceptions); | 218 AddExceptionForHostedApp(launch_url_string, **extension, exceptions); |
244 } | 219 } |
245 } | 220 } |
246 | 221 |
| 222 ContentSetting FlashPermissionToContentSetting( |
| 223 PP_Flash_BrowserOperations_Permission permission) { |
| 224 switch (permission) { |
| 225 case PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT: |
| 226 return CONTENT_SETTING_DEFAULT; |
| 227 case PP_FLASH_BROWSEROPERATIONS_PERMISSION_ALLOW: |
| 228 return CONTENT_SETTING_ALLOW; |
| 229 case PP_FLASH_BROWSEROPERATIONS_PERMISSION_BLOCK: |
| 230 return CONTENT_SETTING_BLOCK; |
| 231 case PP_FLASH_BROWSEROPERATIONS_PERMISSION_ASK: |
| 232 return CONTENT_SETTING_ASK; |
| 233 default: |
| 234 NOTREACHED(); |
| 235 return CONTENT_SETTING_DEFAULT; |
| 236 } |
| 237 } |
| 238 |
| 239 PP_Flash_BrowserOperations_Permission FlashPermissionFromContentSetting( |
| 240 ContentSetting setting) { |
| 241 switch (setting) { |
| 242 case CONTENT_SETTING_DEFAULT: |
| 243 return PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT; |
| 244 case CONTENT_SETTING_ALLOW: |
| 245 return PP_FLASH_BROWSEROPERATIONS_PERMISSION_ALLOW; |
| 246 case CONTENT_SETTING_BLOCK: |
| 247 return PP_FLASH_BROWSEROPERATIONS_PERMISSION_BLOCK; |
| 248 case CONTENT_SETTING_ASK: |
| 249 return PP_FLASH_BROWSEROPERATIONS_PERMISSION_ASK; |
| 250 default: |
| 251 NOTREACHED(); |
| 252 return PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT; |
| 253 } |
| 254 } |
| 255 |
| 256 std::string CanonicalizeHost(const std::string& host) { |
| 257 url_canon::CanonHostInfo info; |
| 258 return net::CanonicalizeHost(host, &info); |
| 259 } |
| 260 |
| 261 bool IsValidHost(const std::string& host) { |
| 262 std::string canonicalized_host = CanonicalizeHost(host); |
| 263 return !canonicalized_host.empty(); |
| 264 } |
| 265 |
247 } // namespace | 266 } // namespace |
248 | 267 |
249 namespace options2 { | 268 namespace options2 { |
250 | 269 |
| 270 class ContentSettingsHandler::ExContentSettingsType { |
| 271 public: |
| 272 explicit ExContentSettingsType(int value) : value_(value) { |
| 273 DCHECK(value_ < EX_CONTENT_SETTINGS_NUM_TYPES); |
| 274 } |
| 275 explicit ExContentSettingsType(ContentSettingsType type) : value_(type) {} |
| 276 explicit ExContentSettingsType(ExContentSettingsTypeEnum type) |
| 277 : value_(type) {} |
| 278 |
| 279 bool IsExtraContentSettingsType() const { |
| 280 return value_ >= CONTENT_SETTINGS_NUM_TYPES; |
| 281 } |
| 282 |
| 283 operator int() const { return value_; } |
| 284 |
| 285 ContentSettingsType ToContentSettingsType() const { |
| 286 DCHECK(value_ < CONTENT_SETTINGS_NUM_TYPES); |
| 287 return static_cast<ContentSettingsType>(value_); |
| 288 } |
| 289 |
| 290 private: |
| 291 int value_; |
| 292 }; |
| 293 |
| 294 ContentSettingsHandler::CachedPepperFlashSettings::CachedPepperFlashSettings() |
| 295 : default_permission(PP_FLASH_BROWSEROPERATIONS_PERMISSION_BLOCK), |
| 296 initialized(false) { |
| 297 } |
| 298 |
| 299 ContentSettingsHandler::CachedPepperFlashSettings::~CachedPepperFlashSettings()
{ |
| 300 } |
| 301 |
| 302 struct ContentSettingsHandler::ExContentSettingsTypeNameEntry { |
| 303 ExContentSettingsType type; |
| 304 const char* name; |
| 305 }; |
| 306 |
| 307 const ContentSettingsHandler::ExContentSettingsTypeNameEntry |
| 308 ContentSettingsHandler::kExContentSettingsTypeGroupNames[] = { |
| 309 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_COOKIES), "cookies"}, |
| 310 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_IMAGES), "images"}, |
| 311 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_JAVASCRIPT), "javascript"}, |
| 312 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_PLUGINS), "plugins"}, |
| 313 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_POPUPS), "popups"}, |
| 314 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_GEOLOCATION), "location"}, |
| 315 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS), "notifications"}, |
| 316 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_INTENTS), "intents"}, |
| 317 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE), |
| 318 "auto-select-certificate"}, |
| 319 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_FULLSCREEN), "fullscreen"}, |
| 320 {ExContentSettingsType(CONTENT_SETTINGS_TYPE_MOUSELOCK), "mouselock"}, |
| 321 {ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC), |
| 322 "pepper-flash-cameramic"}, |
| 323 }; |
| 324 |
251 ContentSettingsHandler::ContentSettingsHandler() { | 325 ContentSettingsHandler::ContentSettingsHandler() { |
252 } | 326 } |
253 | 327 |
254 ContentSettingsHandler::~ContentSettingsHandler() { | 328 ContentSettingsHandler::~ContentSettingsHandler() { |
255 } | 329 } |
256 | 330 |
257 void ContentSettingsHandler::GetLocalizedValues( | 331 void ContentSettingsHandler::GetLocalizedValues( |
258 DictionaryValue* localized_strings) { | 332 DictionaryValue* localized_strings) { |
259 DCHECK(localized_strings); | 333 DCHECK(localized_strings); |
260 | 334 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 { "allowWebIntents", IDS_ALLOW_WEB_INTENTS }, | 395 { "allowWebIntents", IDS_ALLOW_WEB_INTENTS }, |
322 // Fullscreen filter. | 396 // Fullscreen filter. |
323 { "fullscreen_tab_label", IDS_FULLSCREEN_TAB_LABEL }, | 397 { "fullscreen_tab_label", IDS_FULLSCREEN_TAB_LABEL }, |
324 { "fullscreen_header", IDS_FULLSCREEN_HEADER }, | 398 { "fullscreen_header", IDS_FULLSCREEN_HEADER }, |
325 // Mouse Lock filter. | 399 // Mouse Lock filter. |
326 { "mouselock_tab_label", IDS_MOUSE_LOCK_TAB_LABEL }, | 400 { "mouselock_tab_label", IDS_MOUSE_LOCK_TAB_LABEL }, |
327 { "mouselock_header", IDS_MOUSE_LOCK_HEADER }, | 401 { "mouselock_header", IDS_MOUSE_LOCK_HEADER }, |
328 { "mouselock_allow", IDS_MOUSE_LOCK_ALLOW_RADIO }, | 402 { "mouselock_allow", IDS_MOUSE_LOCK_ALLOW_RADIO }, |
329 { "mouselock_ask", IDS_MOUSE_LOCK_ASK_RADIO }, | 403 { "mouselock_ask", IDS_MOUSE_LOCK_ASK_RADIO }, |
330 { "mouselock_block", IDS_MOUSE_LOCK_BLOCK_RADIO }, | 404 { "mouselock_block", IDS_MOUSE_LOCK_BLOCK_RADIO }, |
| 405 // Pepper Flash camera and microphone filter. |
| 406 { "pepperFlashCameramicTabLabel", IDS_PEPPER_FLASH_CAMERAMIC_TAB_LABEL }, |
| 407 // The header has to be named as <content_type_name>_header. |
| 408 { "pepper-flash-cameramic_header", IDS_PEPPER_FLASH_CAMERAMIC_HEADER }, |
| 409 { "pepperFlashCameramicAsk", IDS_PEPPER_FLASH_CAMERAMIC_ASK_RADIO }, |
| 410 { "pepperFlashCameramicBlock", IDS_PEPPER_FLASH_CAMERAMIC_BLOCK_RADIO }, |
331 #if defined(OS_CHROMEOS) | 411 #if defined(OS_CHROMEOS) |
332 // Protected Content filter | 412 // Protected Content filter |
333 { "protectedContentTabLabel", IDS_PROTECTED_CONTENT_TAB_LABEL }, | 413 { "protectedContentTabLabel", IDS_PROTECTED_CONTENT_TAB_LABEL }, |
334 { "protectedContentInfo", IDS_PROTECTED_CONTENT_INFO }, | 414 { "protectedContentInfo", IDS_PROTECTED_CONTENT_INFO }, |
335 { "protectedContentEnable", IDS_PROTECTED_CONTENT_ENABLE}, | 415 { "protectedContentEnable", IDS_PROTECTED_CONTENT_ENABLE}, |
336 #endif // defined(OS_CHROMEOS) | 416 #endif // defined(OS_CHROMEOS) |
337 }; | 417 }; |
338 | 418 |
339 RegisterStrings(localized_strings, resources, arraysize(resources)); | 419 RegisterStrings(localized_strings, resources, arraysize(resources)); |
340 RegisterTitle(localized_strings, "contentSettingsPage", | 420 RegisterTitle(localized_strings, "contentSettingsPage", |
(...skipping 12 matching lines...) Expand all Loading... |
353 RegisterTitle(localized_strings, "popups", | 433 RegisterTitle(localized_strings, "popups", |
354 IDS_POPUP_TAB_LABEL); | 434 IDS_POPUP_TAB_LABEL); |
355 RegisterTitle(localized_strings, "location", | 435 RegisterTitle(localized_strings, "location", |
356 IDS_GEOLOCATION_TAB_LABEL); | 436 IDS_GEOLOCATION_TAB_LABEL); |
357 RegisterTitle(localized_strings, "notifications", | 437 RegisterTitle(localized_strings, "notifications", |
358 IDS_NOTIFICATIONS_TAB_LABEL); | 438 IDS_NOTIFICATIONS_TAB_LABEL); |
359 RegisterTitle(localized_strings, "fullscreen", | 439 RegisterTitle(localized_strings, "fullscreen", |
360 IDS_FULLSCREEN_TAB_LABEL); | 440 IDS_FULLSCREEN_TAB_LABEL); |
361 RegisterTitle(localized_strings, "mouselock", | 441 RegisterTitle(localized_strings, "mouselock", |
362 IDS_MOUSE_LOCK_TAB_LABEL); | 442 IDS_MOUSE_LOCK_TAB_LABEL); |
| 443 RegisterTitle(localized_strings, "pepper-flash-cameramic", |
| 444 IDS_PEPPER_FLASH_CAMERAMIC_TAB_LABEL); |
363 | 445 |
364 Profile* profile = Profile::FromWebUI(web_ui()); | 446 Profile* profile = Profile::FromWebUI(web_ui()); |
365 localized_strings->SetBoolean( | 447 localized_strings->SetBoolean( |
366 "enable_web_intents", | 448 "enable_web_intents", |
367 web_intents::IsWebIntentsEnabledForProfile(profile)); | 449 web_intents::IsWebIntentsEnabledForProfile(profile)); |
368 // TODO(marja): clean up the options UI after the decision on the session | 450 // TODO(marja): clean up the options UI after the decision on the session |
369 // restore changes has stabilized. | 451 // restore changes has stabilized. |
370 localized_strings->SetBoolean( | 452 localized_strings->SetBoolean( |
371 "enable_restore_session_state", false); | 453 "enable_restore_session_state", false); |
372 } | 454 } |
(...skipping 13 matching lines...) Expand all Loading... |
386 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 468 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
387 content::NotificationService::AllSources()); | 469 content::NotificationService::AllSources()); |
388 Profile* profile = Profile::FromWebUI(web_ui()); | 470 Profile* profile = Profile::FromWebUI(web_ui()); |
389 notification_registrar_.Add( | 471 notification_registrar_.Add( |
390 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, | 472 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, |
391 content::Source<Profile>(profile)); | 473 content::Source<Profile>(profile)); |
392 | 474 |
393 PrefService* prefs = profile->GetPrefs(); | 475 PrefService* prefs = profile->GetPrefs(); |
394 pref_change_registrar_.Init(prefs); | 476 pref_change_registrar_.Init(prefs); |
395 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); | 477 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); |
| 478 pref_change_registrar_.Add(prefs::kPepperFlashSettingsEnabled, this); |
| 479 |
| 480 flash_settings_manager_.reset(new PepperFlashSettingsManager(this, profile)); |
396 } | 481 } |
397 | 482 |
398 void ContentSettingsHandler::InitializePage() { | 483 void ContentSettingsHandler::InitializePage() { |
399 UpdateHandlersEnabledRadios(); | 484 UpdateHandlersEnabledRadios(); |
400 UpdateAllExceptionsViewsFromModel(); | 485 UpdateAllExceptionsViewsFromModel(); |
| 486 |
| 487 flash_cameramic_settings_ = CachedPepperFlashSettings(); |
| 488 flash_settings_manager_->GetPermissionSettings( |
| 489 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC); |
401 } | 490 } |
402 | 491 |
403 void ContentSettingsHandler::Observe( | 492 void ContentSettingsHandler::Observe( |
404 int type, | 493 int type, |
405 const content::NotificationSource& source, | 494 const content::NotificationSource& source, |
406 const content::NotificationDetails& details) { | 495 const content::NotificationDetails& details) { |
407 switch (type) { | 496 switch (type) { |
408 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 497 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
409 if (content::Source<Profile>(source).ptr()->IsOffTheRecord()) { | 498 if (content::Source<Profile>(source).ptr()->IsOffTheRecord()) { |
410 web_ui()->CallJavascriptFunction( | 499 web_ui()->CallJavascriptFunction( |
(...skipping 13 matching lines...) Expand all Loading... |
424 HostContentSettingsMap* map = | 513 HostContentSettingsMap* map = |
425 content::Source<HostContentSettingsMap>(source).ptr(); | 514 content::Source<HostContentSettingsMap>(source).ptr(); |
426 if (map != GetContentSettingsMap() && | 515 if (map != GetContentSettingsMap() && |
427 map != GetOTRContentSettingsMap()) | 516 map != GetOTRContentSettingsMap()) |
428 break; | 517 break; |
429 | 518 |
430 const ContentSettingsDetails* settings_details = | 519 const ContentSettingsDetails* settings_details = |
431 content::Details<const ContentSettingsDetails>(details).ptr(); | 520 content::Details<const ContentSettingsDetails>(details).ptr(); |
432 | 521 |
433 // TODO(estade): we pretend update_all() is always true. | 522 // TODO(estade): we pretend update_all() is always true. |
434 if (settings_details->update_all_types()) | 523 if (settings_details->update_all_types()) { |
435 UpdateAllExceptionsViewsFromModel(); | 524 UpdateAllExceptionsViewsFromModel(); |
436 else | 525 } else { |
437 UpdateExceptionsViewFromModel(settings_details->type()); | 526 UpdateExceptionsViewFromModel( |
| 527 ExContentSettingsType(settings_details->type())); |
| 528 } |
438 break; | 529 break; |
439 } | 530 } |
440 | 531 |
441 case chrome::NOTIFICATION_PREF_CHANGED: { | 532 case chrome::NOTIFICATION_PREF_CHANGED: { |
442 const std::string& pref_name = | 533 const std::string& pref_name = |
443 *content::Details<std::string>(details).ptr(); | 534 *content::Details<std::string>(details).ptr(); |
444 if (pref_name == prefs::kGeolocationContentSettings) | 535 if (pref_name == prefs::kGeolocationContentSettings) { |
445 UpdateGeolocationExceptionsView(); | 536 UpdateGeolocationExceptionsView(); |
| 537 } else if (pref_name == prefs::kPepperFlashSettingsEnabled) { |
| 538 if (!flash_cameramic_settings_.initialized) { |
| 539 flash_settings_manager_->GetPermissionSettings( |
| 540 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC); |
| 541 } |
| 542 } |
| 543 |
446 break; | 544 break; |
447 } | 545 } |
448 | 546 |
449 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { | 547 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { |
450 UpdateNotificationExceptionsView(); | 548 UpdateNotificationExceptionsView(); |
451 break; | 549 break; |
452 } | 550 } |
453 | 551 |
454 case chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED: { | 552 case chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED: { |
455 UpdateHandlersEnabledRadios(); | 553 UpdateHandlersEnabledRadios(); |
456 break; | 554 break; |
457 } | 555 } |
458 | 556 |
459 default: | 557 default: |
460 OptionsPageUIHandler::Observe(type, source, details); | 558 OptionsPageUIHandler::Observe(type, source, details); |
461 } | 559 } |
462 } | 560 } |
463 | 561 |
| 562 void ContentSettingsHandler::OnGetPermissionSettingsCompleted( |
| 563 uint32 /* request_id */, |
| 564 bool success, |
| 565 PP_Flash_BrowserOperations_Permission default_permission, |
| 566 const ppapi::FlashSiteSettings& sites) { |
| 567 if (success && !flash_cameramic_settings_.initialized) { |
| 568 flash_cameramic_settings_.initialized = true; |
| 569 flash_cameramic_settings_.default_permission = default_permission; |
| 570 for (ppapi::FlashSiteSettings::const_iterator iter = sites.begin(); |
| 571 iter != sites.end(); ++iter) { |
| 572 if (IsValidHost(iter->site)) |
| 573 flash_cameramic_settings_.sites[iter->site] = iter->permission; |
| 574 } |
| 575 UpdateExceptionsViewFromModel( |
| 576 ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC)); |
| 577 |
| 578 web_ui()->CallJavascriptFunction( |
| 579 "ContentSettings.enablePepperFlashCameraMicSettings"); |
| 580 } |
| 581 } |
| 582 |
464 void ContentSettingsHandler::UpdateSettingDefaultFromModel( | 583 void ContentSettingsHandler::UpdateSettingDefaultFromModel( |
465 ContentSettingsType type) { | 584 const ExContentSettingsType& type) { |
466 DictionaryValue filter_settings; | 585 DictionaryValue filter_settings; |
467 std::string provider_id; | 586 std::string provider_id; |
468 filter_settings.SetString(ContentSettingsTypeToGroupName(type) + ".value", | |
469 GetSettingDefaultFromModel(type, &provider_id)); | |
470 filter_settings.SetString( | 587 filter_settings.SetString( |
471 ContentSettingsTypeToGroupName(type) + ".managedBy", | 588 ExContentSettingsTypeToGroupName(type) + ".value", |
472 provider_id); | 589 GetSettingDefaultFromModel(type, &provider_id)); |
| 590 filter_settings.SetString( |
| 591 ExContentSettingsTypeToGroupName(type) + ".managedBy", provider_id); |
473 | 592 |
474 web_ui()->CallJavascriptFunction( | 593 web_ui()->CallJavascriptFunction( |
475 "ContentSettings.setContentFilterSettingsValue", filter_settings); | 594 "ContentSettings.setContentFilterSettingsValue", filter_settings); |
476 web_ui()->CallJavascriptFunction( | 595 web_ui()->CallJavascriptFunction( |
477 "BrowserOptions.setContentFilterSettingsValue", filter_settings); | 596 "BrowserOptions.setContentFilterSettingsValue", filter_settings); |
478 } | 597 } |
479 | 598 |
480 std::string ContentSettingsHandler::GetSettingDefaultFromModel( | 599 std::string ContentSettingsHandler::GetSettingDefaultFromModel( |
481 ContentSettingsType type, std::string* provider_id) { | 600 const ExContentSettingsType& type, std::string* provider_id) { |
482 Profile* profile = Profile::FromWebUI(web_ui()); | 601 Profile* profile = Profile::FromWebUI(web_ui()); |
483 ContentSetting default_setting; | 602 ContentSetting default_setting; |
484 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 603 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
485 default_setting = | 604 default_setting = |
486 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 605 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
487 GetDefaultContentSetting(provider_id); | 606 GetDefaultContentSetting(provider_id); |
| 607 } else if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { |
| 608 default_setting = FlashPermissionToContentSetting( |
| 609 flash_cameramic_settings_.default_permission); |
| 610 *provider_id = kDefaultProviderID; |
488 } else { | 611 } else { |
489 default_setting = | 612 default_setting = |
490 profile->GetHostContentSettingsMap()-> | 613 profile->GetHostContentSettingsMap()-> |
491 GetDefaultContentSetting(type, provider_id); | 614 GetDefaultContentSetting(type.ToContentSettingsType(), provider_id); |
492 } | 615 } |
493 | 616 |
494 return ContentSettingToString(default_setting); | 617 return ContentSettingToString(default_setting); |
495 } | 618 } |
496 | 619 |
497 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { | 620 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { |
498 base::FundamentalValue handlers_enabled( | 621 base::FundamentalValue handlers_enabled( |
499 GetProtocolHandlerRegistry()->enabled()); | 622 GetProtocolHandlerRegistry()->enabled()); |
500 | 623 |
501 web_ui()->CallJavascriptFunction( | 624 web_ui()->CallJavascriptFunction( |
502 "ContentSettings.updateHandlersEnabledRadios", | 625 "ContentSettings.updateHandlersEnabledRadios", |
503 handlers_enabled); | 626 handlers_enabled); |
504 } | 627 } |
505 | 628 |
506 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { | 629 void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { |
507 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 630 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
508 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 631 type < EX_CONTENT_SETTINGS_NUM_TYPES; ++type) { |
509 // The content settings type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE | 632 // The content settings type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE |
510 // is supposed to be set by policy only. Hence there is no user facing UI | 633 // is supposed to be set by policy only. Hence there is no user facing UI |
511 // for this content type and we skip it here. | 634 // for this content type and we skip it here. |
512 if (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) | 635 if (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) |
513 continue; | 636 continue; |
514 UpdateExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 637 UpdateExceptionsViewFromModel(ExContentSettingsType(type)); |
515 } | 638 } |
516 } | 639 } |
517 | 640 |
518 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { | 641 void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { |
519 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; | 642 for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; |
520 type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 643 type < EX_CONTENT_SETTINGS_NUM_TYPES; ++type) { |
521 UpdateOTRExceptionsViewFromModel(static_cast<ContentSettingsType>(type)); | 644 UpdateOTRExceptionsViewFromModel(ExContentSettingsType(type)); |
522 } | 645 } |
523 } | 646 } |
524 | 647 |
525 void ContentSettingsHandler::UpdateExceptionsViewFromModel( | 648 void ContentSettingsHandler::UpdateExceptionsViewFromModel( |
526 ContentSettingsType type) { | 649 const ExContentSettingsType& type) { |
527 // Don't update intents settings at this point. | 650 // Don't update intents settings at this point. |
528 // Turn on when enable_web_intents_tag is enabled. | 651 // Turn on when enable_web_intents_tag is enabled. |
529 if (type == CONTENT_SETTINGS_TYPE_INTENTS) | 652 if (type == CONTENT_SETTINGS_TYPE_INTENTS) |
530 return; | 653 return; |
531 | 654 |
532 switch (type) { | 655 switch (type) { |
533 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 656 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
534 UpdateGeolocationExceptionsView(); | 657 UpdateGeolocationExceptionsView(); |
535 break; | 658 break; |
536 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 659 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
537 UpdateNotificationExceptionsView(); | 660 UpdateNotificationExceptionsView(); |
538 break; | 661 break; |
| 662 case EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC: |
| 663 UpdateFlashCameraMicExceptionsView(); |
| 664 break; |
539 default: | 665 default: |
540 UpdateExceptionsViewFromHostContentSettingsMap(type); | 666 UpdateExceptionsViewFromHostContentSettingsMap( |
| 667 type.ToContentSettingsType()); |
541 break; | 668 break; |
542 } | 669 } |
543 } | 670 } |
544 | 671 |
545 void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( | 672 void ContentSettingsHandler::UpdateOTRExceptionsViewFromModel( |
546 ContentSettingsType type) { | 673 const ExContentSettingsType& type) { |
547 switch (type) { | 674 switch (type) { |
548 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 675 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
549 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 676 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
550 case CONTENT_SETTINGS_TYPE_INTENTS: | 677 case CONTENT_SETTINGS_TYPE_INTENTS: |
551 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: | 678 case CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE: |
| 679 case EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC: |
552 break; | 680 break; |
553 default: | 681 default: |
554 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 682 UpdateExceptionsViewFromOTRHostContentSettingsMap( |
| 683 type.ToContentSettingsType()); |
555 break; | 684 break; |
556 } | 685 } |
557 } | 686 } |
558 | 687 |
559 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { | 688 void ContentSettingsHandler::UpdateGeolocationExceptionsView() { |
560 Profile* profile = Profile::FromWebUI(web_ui()); | 689 Profile* profile = Profile::FromWebUI(web_ui()); |
561 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 690 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
562 | 691 |
563 ContentSettingsForOneType all_settings; | 692 ContentSettingsForOneType all_settings; |
564 map->GetSettingsForOneType( | 693 map->GetSettingsForOneType( |
565 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 694 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
566 std::string(), | 695 std::string(), |
567 &all_settings); | 696 &all_settings); |
568 | 697 |
569 // Group geolocation settings by primary_pattern. | 698 // Group geolocation settings by primary_pattern. |
570 AllPatternsSettings all_patterns_settings; | 699 AllPatternsSettings all_patterns_settings; |
571 for (ContentSettingsForOneType::iterator i = | 700 for (ContentSettingsForOneType::iterator i = |
572 all_settings.begin(); | 701 all_settings.begin(); |
573 i != all_settings.end(); | 702 i != all_settings.end(); |
574 ++i) { | 703 ++i) { |
575 // Don't add default settings. | 704 // Don't add default settings. |
576 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 705 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
577 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 706 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
578 i->source != "preferences") { | 707 i->source != kPreferencesSource) { |
579 continue; | 708 continue; |
580 } | 709 } |
581 all_patterns_settings[i->primary_pattern][i->secondary_pattern] = | 710 all_patterns_settings[i->primary_pattern][i->secondary_pattern] = |
582 i->setting; | 711 i->setting; |
583 } | 712 } |
584 | 713 |
585 ListValue exceptions; | 714 ListValue exceptions; |
586 AddExceptionsGrantedByHostedApps( | 715 AddExceptionsGrantedByHostedApps( |
587 profile, ExtensionAPIPermission::kGeolocation, &exceptions); | 716 profile, ExtensionAPIPermission::kGeolocation, &exceptions); |
588 | 717 |
(...skipping 26 matching lines...) Expand all Loading... |
615 } | 744 } |
616 } | 745 } |
617 | 746 |
618 StringValue type_string( | 747 StringValue type_string( |
619 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 748 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
620 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", | 749 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", |
621 type_string, exceptions); | 750 type_string, exceptions); |
622 | 751 |
623 // This is mainly here to keep this function ideologically parallel to | 752 // This is mainly here to keep this function ideologically parallel to |
624 // UpdateExceptionsViewFromHostContentSettingsMap(). | 753 // UpdateExceptionsViewFromHostContentSettingsMap(). |
625 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 754 UpdateSettingDefaultFromModel( |
| 755 ExContentSettingsType(CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
626 } | 756 } |
627 | 757 |
628 void ContentSettingsHandler::UpdateNotificationExceptionsView() { | 758 void ContentSettingsHandler::UpdateNotificationExceptionsView() { |
629 Profile* profile = Profile::FromWebUI(web_ui()); | 759 Profile* profile = Profile::FromWebUI(web_ui()); |
630 DesktopNotificationService* service = | 760 DesktopNotificationService* service = |
631 DesktopNotificationServiceFactory::GetForProfile(profile); | 761 DesktopNotificationServiceFactory::GetForProfile(profile); |
632 | 762 |
633 ContentSettingsForOneType settings; | 763 ContentSettingsForOneType settings; |
634 service->GetNotificationsSettings(&settings); | 764 service->GetNotificationsSettings(&settings); |
635 | 765 |
636 ListValue exceptions; | 766 ListValue exceptions; |
637 AddExceptionsGrantedByHostedApps( | 767 AddExceptionsGrantedByHostedApps( |
638 profile, ExtensionAPIPermission::kNotification, &exceptions); | 768 profile, ExtensionAPIPermission::kNotification, &exceptions); |
639 | 769 |
640 for (ContentSettingsForOneType::const_iterator i = | 770 for (ContentSettingsForOneType::const_iterator i = |
641 settings.begin(); | 771 settings.begin(); |
642 i != settings.end(); | 772 i != settings.end(); |
643 ++i) { | 773 ++i) { |
644 // Don't add default settings. | 774 // Don't add default settings. |
645 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && | 775 if (i->primary_pattern == ContentSettingsPattern::Wildcard() && |
646 i->secondary_pattern == ContentSettingsPattern::Wildcard() && | 776 i->secondary_pattern == ContentSettingsPattern::Wildcard() && |
647 i->source != "preferences") { | 777 i->source != kPreferencesSource) { |
648 continue; | 778 continue; |
649 } | 779 } |
650 | 780 |
651 exceptions.Append( | 781 exceptions.Append( |
652 GetNotificationExceptionForPage(i->primary_pattern, i->setting, | 782 GetNotificationExceptionForPage(i->primary_pattern, i->setting, |
653 i->source)); | 783 i->source)); |
654 } | 784 } |
655 | 785 |
656 StringValue type_string( | 786 StringValue type_string( |
657 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 787 ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
658 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", | 788 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", |
659 type_string, exceptions); | 789 type_string, exceptions); |
660 | 790 |
661 // This is mainly here to keep this function ideologically parallel to | 791 // This is mainly here to keep this function ideologically parallel to |
662 // UpdateExceptionsViewFromHostContentSettingsMap(). | 792 // UpdateExceptionsViewFromHostContentSettingsMap(). |
663 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 793 UpdateSettingDefaultFromModel( |
| 794 ExContentSettingsType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 795 } |
| 796 |
| 797 void ContentSettingsHandler::UpdateFlashCameraMicExceptionsView() { |
| 798 ListValue exceptions; |
| 799 for (CachedPepperFlashSettings::SiteMap::iterator iter = |
| 800 flash_cameramic_settings_.sites.begin(); |
| 801 iter != flash_cameramic_settings_.sites.end(); ++iter) { |
| 802 DictionaryValue* exception = new DictionaryValue(); |
| 803 exception->SetString(kDisplayPattern, iter->first); |
| 804 exception->SetString( |
| 805 kSetting, |
| 806 ContentSettingToString(FlashPermissionToContentSetting(iter->second))); |
| 807 exception->SetString(kSource, kPreferencesSource); |
| 808 exceptions.Append(exception); |
| 809 } |
| 810 |
| 811 StringValue type_string(ExContentSettingsTypeToGroupName( |
| 812 ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC))); |
| 813 web_ui()->CallJavascriptFunction("ContentSettings.setExceptions", |
| 814 type_string, exceptions); |
| 815 |
| 816 UpdateSettingDefaultFromModel( |
| 817 ExContentSettingsType(EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC)); |
664 } | 818 } |
665 | 819 |
666 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( | 820 void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( |
667 ContentSettingsType type) { | 821 ContentSettingsType type) { |
668 ContentSettingsForOneType entries; | 822 ContentSettingsForOneType entries; |
669 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); | 823 GetContentSettingsMap()->GetSettingsForOneType(type, "", &entries); |
670 | 824 |
671 ListValue exceptions; | 825 ListValue exceptions; |
672 for (size_t i = 0; i < entries.size(); ++i) { | 826 for (size_t i = 0; i < entries.size(); ++i) { |
673 // Skip default settings from extensions and policy, and the default content | 827 // Skip default settings from extensions and policy, and the default content |
(...skipping 25 matching lines...) Expand all Loading... |
699 | 853 |
700 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); | 854 UpdateExceptionsViewFromOTRHostContentSettingsMap(type); |
701 | 855 |
702 // TODO(koz): The default for fullscreen is always 'ask'. | 856 // TODO(koz): The default for fullscreen is always 'ask'. |
703 // http://crbug.com/104683 | 857 // http://crbug.com/104683 |
704 if (type == CONTENT_SETTINGS_TYPE_FULLSCREEN) | 858 if (type == CONTENT_SETTINGS_TYPE_FULLSCREEN) |
705 return; | 859 return; |
706 | 860 |
707 // The default may also have changed (we won't get a separate notification). | 861 // The default may also have changed (we won't get a separate notification). |
708 // If it hasn't changed, this call will be harmless. | 862 // If it hasn't changed, this call will be harmless. |
709 UpdateSettingDefaultFromModel(type); | 863 UpdateSettingDefaultFromModel(ExContentSettingsType(type)); |
710 } | 864 } |
711 | 865 |
712 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( | 866 void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( |
713 ContentSettingsType type) { | 867 ContentSettingsType type) { |
714 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); | 868 const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); |
715 if (!otr_settings_map) | 869 if (!otr_settings_map) |
716 return; | 870 return; |
717 | 871 |
718 ContentSettingsForOneType otr_entries; | 872 ContentSettingsForOneType otr_entries; |
719 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); | 873 otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 void ContentSettingsHandler::SetContentFilter(const ListValue* args) { | 949 void ContentSettingsHandler::SetContentFilter(const ListValue* args) { |
796 DCHECK_EQ(2U, args->GetSize()); | 950 DCHECK_EQ(2U, args->GetSize()); |
797 std::string group, setting; | 951 std::string group, setting; |
798 if (!(args->GetString(0, &group) && | 952 if (!(args->GetString(0, &group) && |
799 args->GetString(1, &setting))) { | 953 args->GetString(1, &setting))) { |
800 NOTREACHED(); | 954 NOTREACHED(); |
801 return; | 955 return; |
802 } | 956 } |
803 | 957 |
804 ContentSetting default_setting = ContentSettingFromString(setting); | 958 ContentSetting default_setting = ContentSettingFromString(setting); |
805 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); | 959 ExContentSettingsType content_type = |
| 960 ExContentSettingsTypeFromGroupName(group); |
806 Profile* profile = Profile::FromWebUI(web_ui()); | 961 Profile* profile = Profile::FromWebUI(web_ui()); |
807 | 962 |
808 #if defined(OS_CHROMEOS) | 963 #if defined(OS_CHROMEOS) |
809 // ChromeOS special case : in Guest mode settings are opened in Incognito | 964 // ChromeOS special case : in Guest mode settings are opened in Incognito |
810 // mode, so we need original profile to actually modify settings. | 965 // mode, so we need original profile to actually modify settings. |
811 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) | 966 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) |
812 profile = profile->GetOriginalProfile(); | 967 profile = profile->GetOriginalProfile(); |
813 #endif | 968 #endif |
814 | 969 |
815 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 970 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
816 DesktopNotificationServiceFactory::GetForProfile(profile)-> | 971 DesktopNotificationServiceFactory::GetForProfile(profile)-> |
817 SetDefaultContentSetting(default_setting); | 972 SetDefaultContentSetting(default_setting); |
| 973 } else if (content_type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { |
| 974 flash_cameramic_settings_.default_permission = |
| 975 FlashPermissionFromContentSetting(default_setting); |
| 976 flash_settings_manager_->SetDefaultPermission( |
| 977 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC, |
| 978 flash_cameramic_settings_.default_permission, false); |
818 } else { | 979 } else { |
819 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); | 980 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
820 ApplyWhitelist(content_type, default_setting); | 981 ContentSettingsType converted_type = content_type.ToContentSettingsType(); |
821 map->SetDefaultContentSetting(content_type, default_setting); | 982 ApplyWhitelist(converted_type, default_setting); |
| 983 map->SetDefaultContentSetting(converted_type, default_setting); |
822 } | 984 } |
823 switch (content_type) { | 985 switch (content_type) { |
824 case CONTENT_SETTINGS_TYPE_COOKIES: | 986 case CONTENT_SETTINGS_TYPE_COOKIES: |
825 content::RecordAction( | 987 content::RecordAction( |
826 UserMetricsAction("Options_DefaultCookieSettingChanged")); | 988 UserMetricsAction("Options_DefaultCookieSettingChanged")); |
827 break; | 989 break; |
828 case CONTENT_SETTINGS_TYPE_IMAGES: | 990 case CONTENT_SETTINGS_TYPE_IMAGES: |
829 content::RecordAction( | 991 content::RecordAction( |
830 UserMetricsAction("Options_DefaultImagesSettingChanged")); | 992 UserMetricsAction("Options_DefaultImagesSettingChanged")); |
831 break; | 993 break; |
(...skipping 18 matching lines...) Expand all Loading... |
850 UserMetricsAction("Options_DefaultGeolocationSettingChanged")); | 1012 UserMetricsAction("Options_DefaultGeolocationSettingChanged")); |
851 break; | 1013 break; |
852 case CONTENT_SETTINGS_TYPE_INTENTS: | 1014 case CONTENT_SETTINGS_TYPE_INTENTS: |
853 content::RecordAction( | 1015 content::RecordAction( |
854 UserMetricsAction("Options_DefaultHandlersSettingChanged")); | 1016 UserMetricsAction("Options_DefaultHandlersSettingChanged")); |
855 break; | 1017 break; |
856 case CONTENT_SETTINGS_TYPE_MOUSELOCK: | 1018 case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
857 content::RecordAction( | 1019 content::RecordAction( |
858 UserMetricsAction("Options_DefaultMouseLockSettingChanged")); | 1020 UserMetricsAction("Options_DefaultMouseLockSettingChanged")); |
859 break; | 1021 break; |
| 1022 case EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC: |
| 1023 content::RecordAction( |
| 1024 UserMetricsAction("Options_DefaultFlashCameraMicSettingChanged")); |
| 1025 break; |
860 default: | 1026 default: |
861 break; | 1027 break; |
862 } | 1028 } |
863 } | 1029 } |
864 | 1030 |
865 void ContentSettingsHandler::RemoveException(const ListValue* args) { | 1031 void ContentSettingsHandler::RemoveException(const ListValue* args) { |
866 size_t arg_i = 0; | 1032 size_t arg_i = 0; |
867 std::string type_string; | 1033 std::string type_string; |
868 CHECK(args->GetString(arg_i++, &type_string)); | 1034 CHECK(args->GetString(arg_i++, &type_string)); |
869 | 1035 |
870 Profile* profile = Profile::FromWebUI(web_ui()); | 1036 Profile* profile = Profile::FromWebUI(web_ui()); |
871 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 1037 ExContentSettingsType type = ExContentSettingsTypeFromGroupName( |
| 1038 type_string); |
872 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 1039 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
873 std::string origin; | 1040 std::string origin; |
874 std::string embedding_origin; | 1041 std::string embedding_origin; |
875 bool rv = args->GetString(arg_i++, &origin); | 1042 bool rv = args->GetString(arg_i++, &origin); |
876 DCHECK(rv); | 1043 DCHECK(rv); |
877 rv = args->GetString(arg_i++, &embedding_origin); | 1044 rv = args->GetString(arg_i++, &embedding_origin); |
878 DCHECK(rv); | 1045 DCHECK(rv); |
879 | 1046 |
880 profile->GetHostContentSettingsMap()-> | 1047 profile->GetHostContentSettingsMap()-> |
881 SetContentSetting(ContentSettingsPattern::FromString(origin), | 1048 SetContentSetting(ContentSettingsPattern::FromString(origin), |
(...skipping 16 matching lines...) Expand all Loading... |
898 ClearSetting(ContentSettingsPattern::FromString(origin)); | 1065 ClearSetting(ContentSettingsPattern::FromString(origin)); |
899 } else { | 1066 } else { |
900 std::string mode; | 1067 std::string mode; |
901 bool rv = args->GetString(arg_i++, &mode); | 1068 bool rv = args->GetString(arg_i++, &mode); |
902 DCHECK(rv); | 1069 DCHECK(rv); |
903 | 1070 |
904 std::string pattern; | 1071 std::string pattern; |
905 rv = args->GetString(arg_i++, &pattern); | 1072 rv = args->GetString(arg_i++, &pattern); |
906 DCHECK(rv); | 1073 DCHECK(rv); |
907 | 1074 |
908 HostContentSettingsMap* settings_map = | 1075 if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { |
909 mode == "normal" ? GetContentSettingsMap() : | 1076 DCHECK_EQ(mode, "normal"); |
910 GetOTRContentSettingsMap(); | 1077 |
911 // The settings map could be null if the mode was OTR but the OTR profile | 1078 CachedPepperFlashSettings::SiteMap::iterator iter = |
912 // got destroyed before we received this message. | 1079 flash_cameramic_settings_.sites.find(pattern); |
913 if (settings_map) { | 1080 if (iter != flash_cameramic_settings_.sites.end()) { |
914 settings_map->SetContentSetting( | 1081 flash_cameramic_settings_.sites.erase(iter); |
915 ContentSettingsPattern::FromString(pattern), | 1082 ppapi::FlashSiteSettings site_settings(1, |
916 ContentSettingsPattern::Wildcard(), | 1083 ppapi::FlashSiteSetting( |
917 ContentSettingsTypeFromGroupName(type_string), | 1084 pattern, PP_FLASH_BROWSEROPERATIONS_PERMISSION_DEFAULT)); |
918 "", | 1085 flash_settings_manager_->SetSitePermission( |
919 CONTENT_SETTING_DEFAULT); | 1086 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC, |
| 1087 site_settings); |
| 1088 } else { |
| 1089 NOTREACHED(); |
| 1090 } |
| 1091 UpdateFlashCameraMicExceptionsView(); |
| 1092 } else { |
| 1093 HostContentSettingsMap* settings_map = |
| 1094 mode == "normal" ? GetContentSettingsMap() : |
| 1095 GetOTRContentSettingsMap(); |
| 1096 // The settings map could be null if the mode was OTR but the OTR profile |
| 1097 // got destroyed before we received this message. |
| 1098 if (settings_map) { |
| 1099 settings_map->SetContentSetting( |
| 1100 ContentSettingsPattern::FromString(pattern), |
| 1101 ContentSettingsPattern::Wildcard(), |
| 1102 type.ToContentSettingsType(), |
| 1103 "", |
| 1104 CONTENT_SETTING_DEFAULT); |
| 1105 } |
920 } | 1106 } |
921 } | 1107 } |
922 } | 1108 } |
923 | 1109 |
924 void ContentSettingsHandler::SetException(const ListValue* args) { | 1110 void ContentSettingsHandler::SetException(const ListValue* args) { |
925 size_t arg_i = 0; | 1111 size_t arg_i = 0; |
926 std::string type_string; | 1112 std::string type_string; |
927 CHECK(args->GetString(arg_i++, &type_string)); | 1113 CHECK(args->GetString(arg_i++, &type_string)); |
928 std::string mode; | 1114 std::string mode; |
929 CHECK(args->GetString(arg_i++, &mode)); | 1115 CHECK(args->GetString(arg_i++, &mode)); |
930 std::string pattern; | 1116 std::string pattern; |
931 CHECK(args->GetString(arg_i++, &pattern)); | 1117 CHECK(args->GetString(arg_i++, &pattern)); |
932 std::string setting; | 1118 std::string setting; |
933 CHECK(args->GetString(arg_i++, &setting)); | 1119 CHECK(args->GetString(arg_i++, &setting)); |
934 | 1120 |
935 ContentSettingsType type = ContentSettingsTypeFromGroupName(type_string); | 1121 ExContentSettingsType type = ExContentSettingsTypeFromGroupName(type_string); |
936 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || | 1122 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || |
937 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 1123 type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
938 NOTREACHED(); | 1124 NOTREACHED(); |
939 return; | 1125 } else if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { |
| 1126 DCHECK(IsValidHost(pattern)); |
| 1127 |
| 1128 if (flash_cameramic_settings_.sites.find(pattern) == |
| 1129 flash_cameramic_settings_.sites.end()) { |
| 1130 pattern = CanonicalizeHost(pattern); |
| 1131 } |
| 1132 PP_Flash_BrowserOperations_Permission permission = |
| 1133 FlashPermissionFromContentSetting(ContentSettingFromString(setting)); |
| 1134 flash_cameramic_settings_.sites[pattern] = permission; |
| 1135 ppapi::FlashSiteSettings |
| 1136 site_settings(1, ppapi::FlashSiteSetting(pattern, permission)); |
| 1137 flash_settings_manager_->SetSitePermission( |
| 1138 PP_FLASH_BROWSEROPERATIONS_SETTINGTYPE_CAMERAMIC, |
| 1139 site_settings); |
| 1140 UpdateFlashCameraMicExceptionsView(); |
| 1141 } else { |
| 1142 HostContentSettingsMap* settings_map = |
| 1143 mode == "normal" ? GetContentSettingsMap() : |
| 1144 GetOTRContentSettingsMap(); |
| 1145 |
| 1146 // The settings map could be null if the mode was OTR but the OTR profile |
| 1147 // got destroyed before we received this message. |
| 1148 if (!settings_map) |
| 1149 return; |
| 1150 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), |
| 1151 ContentSettingsPattern::Wildcard(), |
| 1152 type.ToContentSettingsType(), |
| 1153 "", |
| 1154 ContentSettingFromString(setting)); |
940 } | 1155 } |
941 | |
942 HostContentSettingsMap* settings_map = | |
943 mode == "normal" ? GetContentSettingsMap() : | |
944 GetOTRContentSettingsMap(); | |
945 | |
946 // The settings map could be null if the mode was OTR but the OTR profile | |
947 // got destroyed before we received this message. | |
948 if (!settings_map) | |
949 return; | |
950 settings_map->SetContentSetting(ContentSettingsPattern::FromString(pattern), | |
951 ContentSettingsPattern::Wildcard(), | |
952 type, | |
953 "", | |
954 ContentSettingFromString(setting)); | |
955 } | 1156 } |
956 | 1157 |
957 void ContentSettingsHandler::CheckExceptionPatternValidity( | 1158 void ContentSettingsHandler::CheckExceptionPatternValidity( |
958 const ListValue* args) { | 1159 const ListValue* args) { |
959 size_t arg_i = 0; | 1160 size_t arg_i = 0; |
960 Value* type; | 1161 std::string type_string; |
961 CHECK(args->Get(arg_i++, &type)); | 1162 CHECK(args->GetString(arg_i++, &type_string)); |
962 std::string mode_string; | 1163 std::string mode_string; |
963 CHECK(args->GetString(arg_i++, &mode_string)); | 1164 CHECK(args->GetString(arg_i++, &mode_string)); |
964 std::string pattern_string; | 1165 std::string pattern_string; |
965 CHECK(args->GetString(arg_i++, &pattern_string)); | 1166 CHECK(args->GetString(arg_i++, &pattern_string)); |
966 | 1167 |
967 ContentSettingsPattern pattern = | 1168 ExContentSettingsType type = ExContentSettingsTypeFromGroupName(type_string); |
968 ContentSettingsPattern::FromString(pattern_string); | 1169 bool is_valid = false; |
| 1170 if (type == EX_CONTENT_SETTINGS_TYPE_PEPPER_FLASH_CAMERAMIC) { |
| 1171 is_valid = IsValidHost(pattern_string); |
| 1172 } else { |
| 1173 ContentSettingsPattern pattern = |
| 1174 ContentSettingsPattern::FromString(pattern_string); |
| 1175 is_valid = pattern.IsValid(); |
| 1176 } |
969 | 1177 |
| 1178 scoped_ptr<Value> type_value(Value::CreateStringValue(type_string)); |
970 scoped_ptr<Value> mode_value(Value::CreateStringValue(mode_string)); | 1179 scoped_ptr<Value> mode_value(Value::CreateStringValue(mode_string)); |
971 scoped_ptr<Value> pattern_value(Value::CreateStringValue(pattern_string)); | 1180 scoped_ptr<Value> pattern_value(Value::CreateStringValue(pattern_string)); |
972 scoped_ptr<Value> valid_value(Value::CreateBooleanValue(pattern.IsValid())); | 1181 scoped_ptr<Value> valid_value(Value::CreateBooleanValue(is_valid)); |
973 | 1182 |
974 web_ui()->CallJavascriptFunction( | 1183 web_ui()->CallJavascriptFunction( |
975 "ContentSettings.patternValidityCheckComplete", | 1184 "ContentSettings.patternValidityCheckComplete", |
976 *type, | 1185 *type_value.get(), |
977 *mode_value.get(), | 1186 *mode_value.get(), |
978 *pattern_value.get(), | 1187 *pattern_value.get(), |
979 *valid_value.get()); | 1188 *valid_value.get()); |
980 } | 1189 } |
981 | 1190 |
982 // static | 1191 // static |
983 std::string ContentSettingsHandler::ContentSettingsTypeToGroupName( | 1192 std::string ContentSettingsHandler::ContentSettingsTypeToGroupName( |
984 ContentSettingsType type) { | 1193 ContentSettingsType type) { |
985 for (size_t i = 0; i < arraysize(kContentSettingsTypeGroupNames); ++i) { | 1194 return ExContentSettingsTypeToGroupName(ExContentSettingsType(type)); |
986 if (type == kContentSettingsTypeGroupNames[i].type) | |
987 return kContentSettingsTypeGroupNames[i].name; | |
988 } | |
989 | |
990 NOTREACHED(); | |
991 return std::string(); | |
992 } | 1195 } |
993 | 1196 |
994 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { | 1197 HostContentSettingsMap* ContentSettingsHandler::GetContentSettingsMap() { |
995 return Profile::FromWebUI(web_ui())->GetHostContentSettingsMap(); | 1198 return Profile::FromWebUI(web_ui())->GetHostContentSettingsMap(); |
996 } | 1199 } |
997 | 1200 |
998 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { | 1201 ProtocolHandlerRegistry* ContentSettingsHandler::GetProtocolHandlerRegistry() { |
999 return Profile::FromWebUI(web_ui())->GetProtocolHandlerRegistry(); | 1202 return Profile::FromWebUI(web_ui())->GetProtocolHandlerRegistry(); |
1000 } | 1203 } |
1001 | 1204 |
1002 HostContentSettingsMap* | 1205 HostContentSettingsMap* |
1003 ContentSettingsHandler::GetOTRContentSettingsMap() { | 1206 ContentSettingsHandler::GetOTRContentSettingsMap() { |
1004 Profile* profile = Profile::FromWebUI(web_ui()); | 1207 Profile* profile = Profile::FromWebUI(web_ui()); |
1005 if (profile->HasOffTheRecordProfile()) | 1208 if (profile->HasOffTheRecordProfile()) |
1006 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); | 1209 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); |
1007 return NULL; | 1210 return NULL; |
1008 } | 1211 } |
1009 | 1212 |
| 1213 // static |
| 1214 ContentSettingsHandler::ExContentSettingsType |
| 1215 ContentSettingsHandler::ExContentSettingsTypeFromGroupName( |
| 1216 const std::string& name) { |
| 1217 COMPILE_ASSERT(arraysize(kExContentSettingsTypeGroupNames) == |
| 1218 EX_CONTENT_SETTINGS_NUM_TYPES, |
| 1219 MISSING_CONTENT_SETTINGS_TYPE); |
| 1220 |
| 1221 for (size_t i = 0; i < arraysize(kExContentSettingsTypeGroupNames); ++i) { |
| 1222 if (name == kExContentSettingsTypeGroupNames[i].name) |
| 1223 return kExContentSettingsTypeGroupNames[i].type; |
| 1224 } |
| 1225 |
| 1226 NOTREACHED() << name << " is not a recognized content settings type."; |
| 1227 return ExContentSettingsType(CONTENT_SETTINGS_TYPE_DEFAULT); |
| 1228 } |
| 1229 |
| 1230 // static |
| 1231 std::string ContentSettingsHandler::ExContentSettingsTypeToGroupName( |
| 1232 const ExContentSettingsType& type) { |
| 1233 for (size_t i = 0; i < arraysize(kExContentSettingsTypeGroupNames); ++i) { |
| 1234 if (type == kExContentSettingsTypeGroupNames[i].type) |
| 1235 return kExContentSettingsTypeGroupNames[i].name; |
| 1236 } |
| 1237 |
| 1238 NOTREACHED(); |
| 1239 return std::string(); |
| 1240 } |
| 1241 |
1010 } // namespace options2 | 1242 } // namespace options2 |
OLD | NEW |