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

Side by Side Diff: chrome/browser/ui/webui/options2/content_settings_handler2.cc

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

Powered by Google App Engine
This is Rietveld 408576698