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

Side by Side Diff: chrome/browser/ui/cocoa/options/content_settings_dialog_controller.mm

Issue 6621076: [Mac] Remove native/Cocoa preferences. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase switch removal Created 9 years, 9 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
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/options/content_settings_dialog_controller.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/command_line.h"
10 #include "base/mac/mac_util.h"
11 #import "chrome/browser/content_settings/content_settings_details.h"
12 #import "chrome/browser/content_settings/host_content_settings_map.h"
13 #import "chrome/browser/geolocation/geolocation_content_settings_map.h"
14 #import "chrome/browser/geolocation/geolocation_exceptions_table_model.h"
15 #import "chrome/browser/notifications/desktop_notification_service.h"
16 #import "chrome/browser/notifications/notification_exceptions_table_model.h"
17 #include "chrome/browser/plugin_exceptions_table_model.h"
18 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_window.h"
22 #import "chrome/browser/ui/cocoa/l10n_util.h"
23 #import "chrome/browser/ui/cocoa/content_settings/simple_content_exceptions_wind ow_controller.h"
24 #import "chrome/browser/ui/cocoa/options/content_exceptions_window_controller.h"
25 #import "chrome/browser/ui/cocoa/options/cookies_window_controller.h"
26 #import "chrome/browser/ui/cocoa/tab_view_picker_table.h"
27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/notification_service.h"
29 #include "chrome/common/pref_names.h"
30 #include "chrome/common/url_constants.h"
31 #include "grit/locale_settings.h"
32 #include "grit/generated_resources.h"
33 #include "ui/base/l10n/l10n_util.h"
34
35 namespace {
36
37 // Stores the currently visible content settings dialog, if any.
38 ContentSettingsDialogController* g_instance = nil;
39
40 } // namespace
41
42
43 @interface ContentSettingsDialogController(Private)
44 - (id)initWithProfile:(Profile*)profile;
45 - (void)selectTab:(ContentSettingsType)settingsType;
46 - (void)showExceptionsForType:(ContentSettingsType)settingsType;
47
48 // Callback when preferences are changed. |prefName| is the name of the
49 // pref that has changed.
50 - (void)prefChanged:(const std::string&)prefName;
51
52 // Callback when content settings are changed.
53 - (void)contentSettingsChanged:(ContentSettingsDetails*)details;
54
55 @end
56
57 namespace ContentSettingsDialogControllerInternal {
58
59 // A C++ class registered for changes in preferences.
60 class PrefObserverBridge : public NotificationObserver {
61 public:
62 PrefObserverBridge(ContentSettingsDialogController* controller)
63 : controller_(controller), disabled_(false) {}
64
65 virtual ~PrefObserverBridge() {}
66
67 virtual void Observe(NotificationType type,
68 const NotificationSource& source,
69 const NotificationDetails& details) {
70 if (disabled_)
71 return;
72
73 // This is currently used by most notifications.
74 if (type == NotificationType::PREF_CHANGED) {
75 std::string* detail = Details<std::string>(details).ptr();
76 if (detail)
77 [controller_ prefChanged:*detail];
78 }
79
80 // This is sent when the "is managed" state changes.
81 // TODO(markusheintz): Move all content settings to this notification.
82 if (type == NotificationType::CONTENT_SETTINGS_CHANGED) {
83 ContentSettingsDetails* settings_details =
84 Details<ContentSettingsDetails>(details).ptr();
85 [controller_ contentSettingsChanged:settings_details];
86 }
87 }
88
89 void SetDisabled(bool disabled) {
90 disabled_ = disabled;
91 }
92
93 private:
94 ContentSettingsDialogController* controller_; // weak, owns us
95 bool disabled_; // true if notifications should be ignored.
96 };
97
98 // A C++ utility class to disable notifications for PrefsObserverBridge.
99 // The intended usage is to create this on the stack.
100 class PrefObserverDisabler {
101 public:
102 PrefObserverDisabler(PrefObserverBridge *bridge) : bridge_(bridge) {
103 bridge_->SetDisabled(true);
104 }
105
106 ~PrefObserverDisabler() {
107 bridge_->SetDisabled(false);
108 }
109
110 private:
111 PrefObserverBridge *bridge_;
112 };
113
114 } // ContentSettingsDialogControllerInternal
115
116 @implementation ContentSettingsDialogController
117
118 + (id)showContentSettingsForType:(ContentSettingsType)settingsType
119 profile:(Profile*)profile {
120 profile = profile->GetOriginalProfile();
121 if (!g_instance)
122 g_instance = [[self alloc] initWithProfile:profile];
123
124 // The code doesn't expect multiple profiles. Check that support for that
125 // hasn't been added.
126 DCHECK(g_instance->profile_ == profile);
127
128 // Select desired tab.
129 if (settingsType == CONTENT_SETTINGS_TYPE_DEFAULT) {
130 // Remember the last visited page from local state.
131 int value = g_instance->lastSelectedTab_.GetValue();
132 if (value >= 0 && value < CONTENT_SETTINGS_NUM_TYPES)
133 settingsType = static_cast<ContentSettingsType>(value);
134 if (settingsType == CONTENT_SETTINGS_TYPE_DEFAULT)
135 settingsType = CONTENT_SETTINGS_TYPE_COOKIES;
136 }
137 // TODO(thakis): Autosave window pos.
138
139 [g_instance selectTab:settingsType];
140 [g_instance showWindow:nil];
141 [g_instance closeExceptionsSheet];
142 return g_instance;
143 }
144
145 - (id)initWithProfile:(Profile*)profile {
146 DCHECK(profile);
147 NSString* nibpath =
148 [base::mac::MainAppBundle() pathForResource:@"ContentSettings"
149 ofType:@"nib"];
150 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
151 profile_ = profile;
152
153 observer_.reset(
154 new ContentSettingsDialogControllerInternal::PrefObserverBridge(self));
155 clearSiteDataOnExit_.Init(prefs::kClearSiteDataOnExit,
156 profile_->GetPrefs(), observer_.get());
157
158 // Manually observe notifications for preferences that are grouped in
159 // the HostContentSettingsMap or GeolocationContentSettingsMap.
160 PrefService* prefs = profile_->GetPrefs();
161 registrar_.Init(prefs);
162 registrar_.Add(prefs::kBlockThirdPartyCookies, observer_.get());
163 registrar_.Add(prefs::kBlockNonsandboxedPlugins, observer_.get());
164 registrar_.Add(prefs::kDefaultContentSettings, observer_.get());
165 registrar_.Add(prefs::kGeolocationDefaultContentSetting, observer_.get());
166
167 // We don't need to observe changes in this value.
168 lastSelectedTab_.Init(prefs::kContentSettingsWindowLastTabIndex,
169 profile_->GetPrefs(), NULL);
170 }
171 return self;
172 }
173
174 - (void)closeExceptionsSheet {
175 NSWindow* attachedSheet = [[self window] attachedSheet];
176 if (attachedSheet) {
177 [NSApp endSheet:attachedSheet];
178 }
179 }
180
181 - (void)awakeFromNib {
182 DCHECK([self window]);
183 DCHECK(tabView_);
184 DCHECK(tabViewPicker_);
185 DCHECK_EQ(self, [[self window] delegate]);
186
187 // Adapt views to potentially long localized strings.
188 CGFloat windowDelta = 0;
189 for (NSTabViewItem* tab in [tabView_ tabViewItems]) {
190 NSArray* subviews = [[tab view] subviews];
191 windowDelta = MAX(windowDelta,
192 cocoa_l10n_util::VerticallyReflowGroup(subviews));
193
194 for (NSView* view in subviews) {
195 // Since the tab pane is in a horizontal resizer in IB, it's convenient
196 // to give all the subviews flexible width so that their sizes are
197 // autoupdated in IB. However, in chrome, the subviews shouldn't have
198 // flexible widths as this looks weird.
199 [view setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
200 }
201 }
202
203 NSString* label =
204 l10n_util::GetNSStringWithFixup(IDS_CONTENT_SETTINGS_FEATURES_LABEL);
205 label = [label stringByReplacingOccurrencesOfString:@":" withString:@""];
206 [tabViewPicker_ setHeading:label];
207
208 if (!CommandLine::ForCurrentProcess()->HasSwitch(
209 switches::kEnableClickToPlay)) {
210 // The |pluginsEnabledIndex| property is bound to the selected *tag*,
211 // so we don't have to worry about index shifts when removing a row
212 // from the matrix.
213 [pluginDefaultSettingMatrix_ removeRow:kPluginsAskIndex];
214 NSArray* siblingViews = [[pluginDefaultSettingMatrix_ superview] subviews];
215 for (NSView* view in siblingViews) {
216 NSRect frame = [view frame];
217 if (frame.origin.y < [pluginDefaultSettingMatrix_ frame].origin.y) {
218 frame.origin.y +=
219 ([pluginDefaultSettingMatrix_ cellSize].height +
220 [pluginDefaultSettingMatrix_ intercellSpacing].height);
221 [view setFrame:frame];
222 }
223 }
224 }
225
226 NSRect frame = [[self window] frame];
227 frame.origin.y -= windowDelta;
228 frame.size.height += windowDelta;
229 [[self window] setFrame:frame display:NO];
230 }
231
232 // NSWindowDelegate method.
233 - (void)windowWillClose:(NSNotification*)notification {
234 [self autorelease];
235 g_instance = nil;
236 }
237
238 - (void)selectTab:(ContentSettingsType)settingsType {
239 [self window]; // Make sure the nib file is loaded.
240 DCHECK(tabView_);
241 [tabView_ selectTabViewItemAtIndex:settingsType];
242 }
243
244 // NSTabViewDelegate method.
245 - (void) tabView:(NSTabView*)tabView
246 didSelectTabViewItem:(NSTabViewItem*)tabViewItem {
247 DCHECK_EQ(tabView_, tabView);
248 NSInteger index = [tabView indexOfTabViewItem:tabViewItem];
249 DCHECK_GT(index, CONTENT_SETTINGS_TYPE_DEFAULT);
250 DCHECK_LT(index, CONTENT_SETTINGS_NUM_TYPES);
251 if (index > CONTENT_SETTINGS_TYPE_DEFAULT &&
252 index < CONTENT_SETTINGS_NUM_TYPES)
253 lastSelectedTab_.SetValue(index);
254 }
255
256 // Let esc close the window.
257 - (void)cancel:(id)sender {
258 [self close];
259 }
260
261 - (void)setCookieSettingIndex:(NSInteger)value {
262 ContentSetting setting = CONTENT_SETTING_DEFAULT;
263 switch (value) {
264 case kCookieEnabledIndex: setting = CONTENT_SETTING_ALLOW; break;
265 case kCookieDisabledIndex: setting = CONTENT_SETTING_BLOCK; break;
266 default:
267 NOTREACHED();
268 }
269 ContentSettingsDialogControllerInternal::PrefObserverDisabler
270 disabler(observer_.get());
271 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
272 CONTENT_SETTINGS_TYPE_COOKIES,
273 setting);
274 }
275
276 - (NSInteger)cookieSettingIndex {
277 switch (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting(
278 CONTENT_SETTINGS_TYPE_COOKIES)) {
279 case CONTENT_SETTING_ALLOW: return kCookieEnabledIndex;
280 case CONTENT_SETTING_BLOCK: return kCookieDisabledIndex;
281 default:
282 NOTREACHED();
283 return kCookieEnabledIndex;
284 }
285 }
286
287 - (BOOL)cookieSettingsManaged {
288 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged(
289 CONTENT_SETTINGS_TYPE_COOKIES);
290 }
291
292 - (BOOL)blockThirdPartyCookies {
293 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
294 return settingsMap->BlockThirdPartyCookies();
295 }
296
297 - (void)setBlockThirdPartyCookies:(BOOL)value {
298 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
299 ContentSettingsDialogControllerInternal::PrefObserverDisabler
300 disabler(observer_.get());
301 settingsMap->SetBlockThirdPartyCookies(value);
302 }
303
304 - (BOOL)blockThirdPartyCookiesManaged {
305 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
306 return settingsMap->IsBlockThirdPartyCookiesManaged();
307 }
308
309 - (BOOL)clearSiteDataOnExitManaged {
310 return clearSiteDataOnExit_.IsManaged();
311 }
312
313 - (BOOL)clearSiteDataOnExit {
314 return clearSiteDataOnExit_.GetValue();
315 }
316
317 - (void)setClearSiteDataOnExit:(BOOL)value {
318 ContentSettingsDialogControllerInternal::PrefObserverDisabler
319 disabler(observer_.get());
320 clearSiteDataOnExit_.SetValue(value);
321 }
322
323 // Shows the cookies controller.
324 - (IBAction)showCookies:(id)sender {
325 // The cookie controller will autorelease itself when it's closed.
326 BrowsingDataDatabaseHelper* databaseHelper =
327 new BrowsingDataDatabaseHelper(profile_);
328 BrowsingDataLocalStorageHelper* storageHelper =
329 new BrowsingDataLocalStorageHelper(profile_);
330 BrowsingDataAppCacheHelper* appcacheHelper =
331 new BrowsingDataAppCacheHelper(profile_);
332 BrowsingDataIndexedDBHelper* indexedDBHelper =
333 BrowsingDataIndexedDBHelper::Create(profile_);
334 CookiesWindowController* controller =
335 [[CookiesWindowController alloc] initWithProfile:profile_
336 databaseHelper:databaseHelper
337 storageHelper:storageHelper
338 appcacheHelper:appcacheHelper
339 indexedDBHelper:indexedDBHelper];
340 [controller attachSheetTo:[self window]];
341 }
342
343 // Called when the user clicks the "Flash Player storage settings" button.
344 - (IBAction)openFlashPlayerSettings:(id)sender {
345 Browser* browser = Browser::Create(profile_);
346 browser->OpenURL(GURL(l10n_util::GetStringUTF8(IDS_FLASH_STORAGE_URL)),
347 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
348 browser->window()->Show();
349 }
350
351 // Called when the user clicks the "Disable individual plug-ins..." button.
352 - (IBAction)openPluginsPage:(id)sender {
353 Browser* browser = Browser::Create(profile_);
354 browser->OpenURL(GURL(chrome::kChromeUIPluginsURL),
355 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
356 browser->window()->Show();
357 }
358
359 - (IBAction)showCookieExceptions:(id)sender {
360 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_COOKIES];
361 }
362
363 - (IBAction)showImagesExceptions:(id)sender {
364 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_IMAGES];
365 }
366
367 - (IBAction)showJavaScriptExceptions:(id)sender {
368 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_JAVASCRIPT];
369 }
370
371 - (IBAction)showPluginsExceptions:(id)sender {
372 if (CommandLine::ForCurrentProcess()->HasSwitch(
373 switches::kEnableResourceContentSettings)) {
374 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
375 HostContentSettingsMap* offTheRecordSettingsMap =
376 profile_->HasOffTheRecordProfile() ?
377 profile_->GetOffTheRecordProfile()->GetHostContentSettingsMap() :
378 NULL;
379 PluginExceptionsTableModel* model =
380 new PluginExceptionsTableModel(settingsMap, offTheRecordSettingsMap);
381 model->LoadSettings();
382 [[SimpleContentExceptionsWindowController controllerWithTableModel:model]
383 attachSheetTo:[self window]];
384 } else {
385 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_PLUGINS];
386 }
387 }
388
389 - (IBAction)showPopupsExceptions:(id)sender {
390 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_POPUPS];
391 }
392
393 - (IBAction)showGeolocationExceptions:(id)sender {
394 GeolocationContentSettingsMap* settingsMap =
395 profile_->GetGeolocationContentSettingsMap();
396 GeolocationExceptionsTableModel* model = // Freed by window controller.
397 new GeolocationExceptionsTableModel(settingsMap);
398 [[SimpleContentExceptionsWindowController controllerWithTableModel:model]
399 attachSheetTo:[self window]];
400 }
401
402 - (IBAction)showNotificationsExceptions:(id)sender {
403 DesktopNotificationService* service =
404 profile_->GetDesktopNotificationService();
405 NotificationExceptionsTableModel* model = // Freed by window controller.
406 new NotificationExceptionsTableModel(service);
407 [[SimpleContentExceptionsWindowController controllerWithTableModel:model]
408 attachSheetTo:[self window]];
409 }
410
411 - (void)showExceptionsForType:(ContentSettingsType)settingsType {
412 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
413 HostContentSettingsMap* offTheRecordSettingsMap =
414 profile_->HasOffTheRecordProfile() ?
415 profile_->GetOffTheRecordProfile()->GetHostContentSettingsMap() :
416 NULL;
417 [[ContentExceptionsWindowController controllerForType:settingsType
418 settingsMap:settingsMap
419 otrSettingsMap:offTheRecordSettingsMap]
420 attachSheetTo:[self window]];
421 }
422
423 - (void)setImagesEnabledIndex:(NSInteger)value {
424 ContentSetting setting = value == kContentSettingsEnabledIndex ?
425 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
426 ContentSettingsDialogControllerInternal::PrefObserverDisabler
427 disabler(observer_.get());
428 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
429 CONTENT_SETTINGS_TYPE_IMAGES, setting);
430 }
431
432 - (NSInteger)imagesEnabledIndex {
433 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
434 bool enabled =
435 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES) ==
436 CONTENT_SETTING_ALLOW;
437 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex;
438 }
439
440 - (BOOL)imagesSettingsManaged {
441 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged(
442 CONTENT_SETTINGS_TYPE_IMAGES);
443 }
444
445 - (void)setJavaScriptEnabledIndex:(NSInteger)value {
446 ContentSetting setting = value == kContentSettingsEnabledIndex ?
447 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
448 ContentSettingsDialogControllerInternal::PrefObserverDisabler
449 disabler(observer_.get());
450 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
451 CONTENT_SETTINGS_TYPE_JAVASCRIPT, setting);
452 }
453
454 - (NSInteger)javaScriptEnabledIndex {
455 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
456 bool enabled =
457 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT) ==
458 CONTENT_SETTING_ALLOW;
459 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex;
460 }
461
462 - (BOOL)javaScriptSettingsManaged {
463 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged(
464 CONTENT_SETTINGS_TYPE_JAVASCRIPT);
465 }
466
467 - (void)setPluginsEnabledIndex:(NSInteger)value {
468 ContentSetting setting = CONTENT_SETTING_DEFAULT;
469 switch (value) {
470 case kPluginsAllowIndex:
471 setting = CONTENT_SETTING_ALLOW;
472 break;
473 case kPluginsAskIndex:
474 setting = CONTENT_SETTING_ASK;
475 break;
476 case kPluginsBlockIndex:
477 setting = CONTENT_SETTING_BLOCK;
478 break;
479 default:
480 NOTREACHED();
481 }
482 ContentSettingsDialogControllerInternal::PrefObserverDisabler
483 disabler(observer_.get());
484 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
485 CONTENT_SETTINGS_TYPE_PLUGINS, setting);
486 }
487
488 - (NSInteger)pluginsEnabledIndex {
489 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap();
490 ContentSetting setting =
491 map->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS);
492 switch (setting) {
493 case CONTENT_SETTING_ALLOW:
494 return kPluginsAllowIndex;
495 case CONTENT_SETTING_ASK:
496 if (CommandLine::ForCurrentProcess()->HasSwitch(
497 switches::kEnableClickToPlay))
498 return kPluginsAskIndex;
499 // Fall through to the next case.
500 case CONTENT_SETTING_BLOCK:
501 return kPluginsBlockIndex;
502 default:
503 NOTREACHED();
504 return kPluginsAllowIndex;
505 }
506 }
507
508 - (BOOL)pluginsSettingsManaged {
509 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged(
510 CONTENT_SETTINGS_TYPE_PLUGINS);
511 }
512
513 - (void)setPopupsEnabledIndex:(NSInteger)value {
514 ContentSetting setting = value == kContentSettingsEnabledIndex ?
515 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
516 ContentSettingsDialogControllerInternal::PrefObserverDisabler
517 disabler(observer_.get());
518 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
519 CONTENT_SETTINGS_TYPE_POPUPS, setting);
520 }
521
522 - (NSInteger)popupsEnabledIndex {
523 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
524 bool enabled =
525 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS) ==
526 CONTENT_SETTING_ALLOW;
527 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex;
528 }
529
530 - (BOOL)popupsSettingsManaged {
531 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged(
532 CONTENT_SETTINGS_TYPE_POPUPS);
533 }
534
535 - (void)setGeolocationSettingIndex:(NSInteger)value {
536 ContentSetting setting = CONTENT_SETTING_DEFAULT;
537 switch (value) {
538 case kGeolocationEnabledIndex: setting = CONTENT_SETTING_ALLOW; break;
539 case kGeolocationAskIndex: setting = CONTENT_SETTING_ASK; break;
540 case kGeolocationDisabledIndex: setting = CONTENT_SETTING_BLOCK; break;
541 default:
542 NOTREACHED();
543 }
544 ContentSettingsDialogControllerInternal::PrefObserverDisabler
545 disabler(observer_.get());
546 profile_->GetGeolocationContentSettingsMap()->SetDefaultContentSetting(
547 setting);
548 }
549
550 - (NSInteger)geolocationSettingIndex {
551 ContentSetting setting =
552 profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting();
553 switch (setting) {
554 case CONTENT_SETTING_ALLOW: return kGeolocationEnabledIndex;
555 case CONTENT_SETTING_ASK: return kGeolocationAskIndex;
556 case CONTENT_SETTING_BLOCK: return kGeolocationDisabledIndex;
557 default:
558 NOTREACHED();
559 return kGeolocationAskIndex;
560 }
561 }
562
563 - (void)setNotificationsSettingIndex:(NSInteger)value {
564 ContentSetting setting = CONTENT_SETTING_DEFAULT;
565 switch (value) {
566 case kNotificationsEnabledIndex: setting = CONTENT_SETTING_ALLOW; break;
567 case kNotificationsAskIndex: setting = CONTENT_SETTING_ASK; break;
568 case kNotificationsDisabledIndex: setting = CONTENT_SETTING_BLOCK; break;
569 default:
570 NOTREACHED();
571 }
572 ContentSettingsDialogControllerInternal::PrefObserverDisabler
573 disabler(observer_.get());
574 profile_->GetDesktopNotificationService()->SetDefaultContentSetting(
575 setting);
576 }
577
578 - (NSInteger)notificationsSettingIndex {
579 ContentSetting setting =
580 profile_->GetDesktopNotificationService()->GetDefaultContentSetting();
581 switch (setting) {
582 case CONTENT_SETTING_ALLOW: return kNotificationsEnabledIndex;
583 case CONTENT_SETTING_ASK: return kNotificationsAskIndex;
584 case CONTENT_SETTING_BLOCK: return kNotificationsDisabledIndex;
585 default:
586 NOTREACHED();
587 return kGeolocationAskIndex;
588 }
589 }
590
591 // Callback when preferences are changed. |prefName| is the name of the
592 // pref that has changed and should not be NULL.
593 - (void)prefChanged:(const std::string&)prefName {
594 if (prefName == prefs::kClearSiteDataOnExit) {
595 [self willChangeValueForKey:@"clearSiteDataOnExit"];
596 [self didChangeValueForKey:@"clearSiteDataOnExit"];
597 [self willChangeValueForKey:@"clearSiteDataOnExitManaged"];
598 [self didChangeValueForKey:@"clearSiteDataOnExitManaged"];
599 }
600 if (prefName == prefs::kBlockThirdPartyCookies) {
601 [self willChangeValueForKey:@"blockThirdPartyCookies"];
602 [self didChangeValueForKey:@"blockThirdPartyCookies"];
603 [self willChangeValueForKey:@"blockThirdPartyCookiesManaged"];
604 [self didChangeValueForKey:@"blockThirdPartyCookiesManaged"];
605 }
606 if (prefName == prefs::kBlockNonsandboxedPlugins) {
607 [self willChangeValueForKey:@"pluginsEnabledIndex"];
608 [self didChangeValueForKey:@"pluginsEnabledIndex"];
609 }
610 if (prefName == prefs::kDefaultContentSettings) {
611 // We don't know exactly which setting has changed, so we'll tickle all
612 // of the properties that apply to kDefaultContentSettings. This will
613 // keep the UI up-to-date.
614 [self willChangeValueForKey:@"cookieSettingIndex"];
615 [self didChangeValueForKey:@"cookieSettingIndex"];
616 [self willChangeValueForKey:@"imagesEnabledIndex"];
617 [self didChangeValueForKey:@"imagesEnabledIndex"];
618 [self willChangeValueForKey:@"javaScriptEnabledIndex"];
619 [self didChangeValueForKey:@"javaScriptEnabledIndex"];
620 [self willChangeValueForKey:@"pluginsEnabledIndex"];
621 [self didChangeValueForKey:@"pluginsEnabledIndex"];
622 [self willChangeValueForKey:@"popupsEnabledIndex"];
623 [self didChangeValueForKey:@"popupsEnabledIndex"];
624
625 // Updates the "Enable" state of the radio groups and the exception buttons.
626 [self willChangeValueForKey:@"cookieSettingsManaged"];
627 [self didChangeValueForKey:@"cookieSettingsManaged"];
628 [self willChangeValueForKey:@"imagesSettingsManaged"];
629 [self didChangeValueForKey:@"imagesSettingsManaged"];
630 [self willChangeValueForKey:@"javaScriptSettingsManaged"];
631 [self didChangeValueForKey:@"javaScriptSettingsManaged"];
632 [self willChangeValueForKey:@"pluginsSettingsManaged"];
633 [self didChangeValueForKey:@"pluginsSettingsManaged"];
634 [self willChangeValueForKey:@"popupsSettingsManaged"];
635 [self didChangeValueForKey:@"popupsSettingsManaged"];
636 }
637 if (prefName == prefs::kGeolocationDefaultContentSetting) {
638 [self willChangeValueForKey:@"geolocationSettingIndex"];
639 [self didChangeValueForKey:@"geolocationSettingIndex"];
640 }
641 if (prefName == prefs::kDesktopNotificationDefaultContentSetting) {
642 [self willChangeValueForKey:@"notificationsSettingIndex"];
643 [self didChangeValueForKey:@"notificationsSettingIndex"];
644 }
645 }
646
647 - (void)contentSettingsChanged:(ContentSettingsDetails*)details {
648 [self prefChanged:prefs::kBlockNonsandboxedPlugins];
649 [self prefChanged:prefs::kDefaultContentSettings];
650 }
651
652 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698