Chromium Code Reviews

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

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

Powered by Google App Engine