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

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

Issue 7328018: Migrate default geolocation content setting to host content settings map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/content_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/content_settings_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 NotificationService::AllSources()); 285 NotificationService::AllSources());
286 notification_registrar_.Add( 286 notification_registrar_.Add(
287 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, 287 this, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
288 NotificationService::AllSources()); 288 NotificationService::AllSources());
289 notification_registrar_.Add( 289 notification_registrar_.Add(
290 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, 290 this, chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED,
291 NotificationService::AllSources()); 291 NotificationService::AllSources());
292 292
293 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 293 PrefService* prefs = web_ui_->GetProfile()->GetPrefs();
294 pref_change_registrar_.Init(prefs); 294 pref_change_registrar_.Init(prefs);
295 pref_change_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
296 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this); 295 pref_change_registrar_.Add(prefs::kGeolocationContentSettings, this);
297 } 296 }
298 297
299 void ContentSettingsHandler::Observe(int type, 298 void ContentSettingsHandler::Observe(int type,
300 const NotificationSource& source, 299 const NotificationSource& source,
301 const NotificationDetails& details) { 300 const NotificationDetails& details) {
302 switch (type) { 301 switch (type) {
303 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 302 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
304 Profile* profile = static_cast<Source<Profile> >(source).ptr(); 303 Profile* profile = static_cast<Source<Profile> >(source).ptr();
305 if (profile->IsOffTheRecord()) { 304 if (profile->IsOffTheRecord()) {
(...skipping 15 matching lines...) Expand all
321 // TODO(estade): we pretend update_all() is always true. 320 // TODO(estade): we pretend update_all() is always true.
322 if (settings_details->update_all_types()) 321 if (settings_details->update_all_types())
323 UpdateAllExceptionsViewsFromModel(); 322 UpdateAllExceptionsViewsFromModel();
324 else 323 else
325 UpdateExceptionsViewFromModel(settings_details->type()); 324 UpdateExceptionsViewFromModel(settings_details->type());
326 break; 325 break;
327 } 326 }
328 327
329 case chrome::NOTIFICATION_PREF_CHANGED: { 328 case chrome::NOTIFICATION_PREF_CHANGED: {
330 const std::string& pref_name = *Details<std::string>(details).ptr(); 329 const std::string& pref_name = *Details<std::string>(details).ptr();
331 if (pref_name == prefs::kGeolocationDefaultContentSetting) 330 if (pref_name == prefs::kGeolocationContentSettings)
332 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION);
333 else if (pref_name == prefs::kGeolocationContentSettings)
334 UpdateGeolocationExceptionsView(); 331 UpdateGeolocationExceptionsView();
335 break; 332 break;
336 } 333 }
337 334
338 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { 335 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_DEFAULT_CHANGED: {
339 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 336 UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
340 break; 337 break;
341 } 338 }
342 339
343 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { 340 case chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED: {
(...skipping 19 matching lines...) Expand all
363 filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed", 360 filter_settings.SetBoolean(ContentSettingsTypeToGroupName(type) + ".managed",
364 GetDefaultSettingManagedFromModel(type)); 361 GetDefaultSettingManagedFromModel(type));
365 362
366 web_ui_->CallJavascriptFunction( 363 web_ui_->CallJavascriptFunction(
367 "ContentSettings.setContentFilterSettingsValue", filter_settings); 364 "ContentSettings.setContentFilterSettingsValue", filter_settings);
368 } 365 }
369 366
370 std::string ContentSettingsHandler::GetSettingDefaultFromModel( 367 std::string ContentSettingsHandler::GetSettingDefaultFromModel(
371 ContentSettingsType type) { 368 ContentSettingsType type) {
372 ContentSetting default_setting; 369 ContentSetting default_setting;
373 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 370 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
374 default_setting = web_ui_->GetProfile()->
375 GetGeolocationContentSettingsMap()->GetDefaultContentSetting();
376 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
377 default_setting = DesktopNotificationServiceFactory::GetForProfile( 371 default_setting = DesktopNotificationServiceFactory::GetForProfile(
378 web_ui_->GetProfile())->GetDefaultContentSetting(); 372 web_ui_->GetProfile())->GetDefaultContentSetting();
379 } else { 373 } else {
380 default_setting = GetContentSettingsMap()->GetDefaultContentSetting(type); 374 default_setting = web_ui_->GetProfile()->
375 GetHostContentSettingsMap()->GetDefaultContentSetting(type);
381 } 376 }
382 377
383 return ContentSettingToString(default_setting); 378 return ContentSettingToString(default_setting);
384 } 379 }
385 380
386 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel( 381 bool ContentSettingsHandler::GetDefaultSettingManagedFromModel(
387 ContentSettingsType type) { 382 ContentSettingsType type) {
388 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 383 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
389 return web_ui_->GetProfile()->
390 GetGeolocationContentSettingsMap()->IsDefaultContentSettingManaged();
391 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
392 return DesktopNotificationServiceFactory::GetForProfile( 384 return DesktopNotificationServiceFactory::GetForProfile(
393 web_ui_->GetProfile())->IsDefaultContentSettingManaged(); 385 web_ui_->GetProfile())->IsDefaultContentSettingManaged();
394 } else { 386 } else {
395 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type); 387 return GetContentSettingsMap()->IsDefaultContentSettingManaged(type);
396 } 388 }
397 } 389 }
398 390
399 void ContentSettingsHandler::UpdateHandlersEnabledRadios() { 391 void ContentSettingsHandler::UpdateHandlersEnabledRadios() {
400 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER) 392 #if defined(ENABLE_REGISTER_PROTOCOL_HANDLER)
401 DCHECK(web_ui_); 393 DCHECK(web_ui_);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 DCHECK_EQ(2U, args->GetSize()); 572 DCHECK_EQ(2U, args->GetSize());
581 std::string group, setting; 573 std::string group, setting;
582 if (!(args->GetString(0, &group) && 574 if (!(args->GetString(0, &group) &&
583 args->GetString(1, &setting))) { 575 args->GetString(1, &setting))) {
584 NOTREACHED(); 576 NOTREACHED();
585 return; 577 return;
586 } 578 }
587 579
588 ContentSetting default_setting = ContentSettingFromString(setting); 580 ContentSetting default_setting = ContentSettingFromString(setting);
589 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group); 581 ContentSettingsType content_type = ContentSettingsTypeFromGroupName(group);
590 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 582 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
591 web_ui_->GetProfile()->GetGeolocationContentSettingsMap()->
592 SetDefaultContentSetting(default_setting);
593 } else if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
594 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())-> 583 DesktopNotificationServiceFactory::GetForProfile(web_ui_->GetProfile())->
595 SetDefaultContentSetting(default_setting); 584 SetDefaultContentSetting(default_setting);
596 } else { 585 } else {
597 GetContentSettingsMap()-> 586 GetContentSettingsMap()->
598 SetDefaultContentSetting(content_type, default_setting); 587 SetDefaultContentSetting(content_type, default_setting);
599 } 588 }
600 } 589 }
601 590
602 void ContentSettingsHandler::RemoveException(const ListValue* args) { 591 void ContentSettingsHandler::RemoveException(const ListValue* args) {
603 size_t arg_i = 0; 592 size_t arg_i = 0;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 return web_ui_->GetProfile()->GetProtocolHandlerRegistry(); 725 return web_ui_->GetProfile()->GetProtocolHandlerRegistry();
737 } 726 }
738 727
739 HostContentSettingsMap* 728 HostContentSettingsMap*
740 ContentSettingsHandler::GetOTRContentSettingsMap() { 729 ContentSettingsHandler::GetOTRContentSettingsMap() {
741 Profile* profile = web_ui_->GetProfile(); 730 Profile* profile = web_ui_->GetProfile();
742 if (profile->HasOffTheRecordProfile()) 731 if (profile->HasOffTheRecordProfile())
743 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap(); 732 return profile->GetOffTheRecordProfile()->GetHostContentSettingsMap();
744 return NULL; 733 return NULL;
745 } 734 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698