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