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

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

Issue 1428002: Mac: Add geolocation content setting. (Closed)
Patch Set: Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #import "chrome/browser/cocoa/content_settings_dialog_controller.h" 5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_window.h" 12 #include "chrome/browser/browser_window.h"
13 #import "chrome/browser/cocoa/content_exceptions_window_controller.h" 13 #import "chrome/browser/cocoa/content_exceptions_window_controller.h"
14 #import "chrome/browser/cocoa/cookies_window_controller.h" 14 #import "chrome/browser/cocoa/cookies_window_controller.h"
15 #import "chrome/browser/geolocation/geolocation_content_settings_map.h"
15 #import "chrome/browser/host_content_settings_map.h" 16 #import "chrome/browser/host_content_settings_map.h"
16 #include "chrome/browser/pref_service.h" 17 #include "chrome/browser/pref_service.h"
17 #include "chrome/browser/profile.h" 18 #include "chrome/browser/profile.h"
18 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "grit/locale_settings.h" 22 #include "grit/locale_settings.h"
22 23
23 24
24 namespace { 25 namespace {
25 26
26 // Index of the "enabled" and "disabled" radio group settings in all tabs except 27 // Index of the "enabled" and "disabled" radio group settings in all tabs except
27 // for the cookies tab. 28 // for the cookies tab.
28 const NSInteger kEnabledIndex = 0; 29 const NSInteger kEnabledIndex = 0;
29 const NSInteger kDisabledIndex = 1; 30 const NSInteger kDisabledIndex = 1;
30 31
31 // Indices of the various cookie settings in the cookie radio group. 32 // Indices of the various cookie settings in the cookie radio group.
32 const NSInteger kCookieEnabledIndex = 0; 33 const NSInteger kCookieEnabledIndex = 0;
33 const NSInteger kCookieAskIndex = 1; 34 const NSInteger kCookieAskIndex = 1;
34 const NSInteger kCookieDisabledIndex = 2; 35 const NSInteger kCookieDisabledIndex = 2;
35 36
36 // Stores the currently visible content settings dialog, if any. 37 // Stores the currently visible content settings dialog, if any.
37 ContentSettingsDialogController* g_instance = nil; 38 ContentSettingsDialogController* g_instance = nil;
38 39
40 // Indices of the various geolocation settings in the geolocation radio group.
41 const NSInteger kGeolocationEnabledIndex = 0;
42 const NSInteger kGeolocationAskIndex = 1;
43 const NSInteger kGeolocationDisabledIndex = 2;
44
39 } // namespace 45 } // namespace
40 46
41 47
42 @interface ContentSettingsDialogController(Private) 48 @interface ContentSettingsDialogController(Private)
43 - (id)initWithProfile:(Profile*)profile; 49 - (id)initWithProfile:(Profile*)profile;
44 - (void)selectTab:(ContentSettingsType)settingsType; 50 - (void)selectTab:(ContentSettingsType)settingsType;
45 - (void)showExceptionsForType:(ContentSettingsType)settingsType; 51 - (void)showExceptionsForType:(ContentSettingsType)settingsType;
46 52
47 // Properties that the radio groups and checkboxes are bound to. 53 // Properties that the radio groups and checkboxes are bound to.
48 @property(assign, nonatomic) NSInteger cookieSettingIndex; 54 @property(assign, nonatomic) NSInteger cookieSettingIndex;
49 @property(assign, nonatomic) BOOL blockThirdPartyCookies; 55 @property(assign, nonatomic) BOOL blockThirdPartyCookies;
50 @property(assign, nonatomic) BOOL clearSiteDataOnExit; 56 @property(assign, nonatomic) BOOL clearSiteDataOnExit;
51 @property(assign, nonatomic) NSInteger imagesEnabledIndex; 57 @property(assign, nonatomic) NSInteger imagesEnabledIndex;
52 @property(assign, nonatomic) NSInteger javaScriptEnabledIndex; 58 @property(assign, nonatomic) NSInteger javaScriptEnabledIndex;
53 @property(assign, nonatomic) NSInteger popupsEnabledIndex; 59 @property(assign, nonatomic) NSInteger popupsEnabledIndex;
54 @property(assign, nonatomic) NSInteger pluginsEnabledIndex; 60 @property(assign, nonatomic) NSInteger pluginsEnabledIndex;
61 @property(assign, nonatomic) NSInteger geolocationSettingIndex;
62
55 @end 63 @end
56 64
57 namespace ContentSettingsDialogControllerInternal { 65 namespace ContentSettingsDialogControllerInternal {
58 66
59 // A C++ class registered for changes in preferences. 67 // A C++ class registered for changes in preferences.
60 class PrefObserverBridge : public NotificationObserver { 68 class PrefObserverBridge : public NotificationObserver {
61 public: 69 public:
62 PrefObserverBridge(ContentSettingsDialogController* controller) 70 PrefObserverBridge(ContentSettingsDialogController* controller)
63 : controller_(controller) {} 71 : controller_(controller) {}
64 72
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 259 }
252 260
253 - (IBAction)showPluginsExceptions:(id)sender { 261 - (IBAction)showPluginsExceptions:(id)sender {
254 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_PLUGINS]; 262 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_PLUGINS];
255 } 263 }
256 264
257 - (IBAction)showPopupsExceptions:(id)sender { 265 - (IBAction)showPopupsExceptions:(id)sender {
258 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_POPUPS]; 266 [self showExceptionsForType:CONTENT_SETTINGS_TYPE_POPUPS];
259 } 267 }
260 268
269 - (IBAction)showGeolocationExceptions:(id)sender {
270 // TODO(thakis): Implement.
271 NOTIMPLEMENTED();
272 }
273
261 - (void)showExceptionsForType:(ContentSettingsType)settingsType { 274 - (void)showExceptionsForType:(ContentSettingsType)settingsType {
262 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); 275 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
263 [ContentExceptionsWindowController showForType:settingsType 276 [ContentExceptionsWindowController showForType:settingsType
264 settingsMap:settingsMap]; 277 settingsMap:settingsMap];
265 } 278 }
266 279
267 - (void)setImagesEnabledIndex:(NSInteger)value { 280 - (void)setImagesEnabledIndex:(NSInteger)value {
268 ContentSetting setting = value == kEnabledIndex ? 281 ContentSetting setting = value == kEnabledIndex ?
269 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 282 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
270 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( 283 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 330 }
318 331
319 - (NSInteger)popupsEnabledIndex { 332 - (NSInteger)popupsEnabledIndex {
320 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); 333 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap();
321 bool enabled = 334 bool enabled =
322 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS) == 335 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS) ==
323 CONTENT_SETTING_ALLOW; 336 CONTENT_SETTING_ALLOW;
324 return enabled ? kEnabledIndex : kDisabledIndex; 337 return enabled ? kEnabledIndex : kDisabledIndex;
325 } 338 }
326 339
340 - (void)setGeolocationSettingIndex:(NSInteger)value {
341 ContentSetting setting = CONTENT_SETTING_DEFAULT;
342 switch (value) {
343 case kGeolocationEnabledIndex: setting = CONTENT_SETTING_ALLOW; break;
344 case kGeolocationAskIndex: setting = CONTENT_SETTING_ASK; break;
345 case kGeolocationDisabledIndex: setting = CONTENT_SETTING_BLOCK; break;
346 default:
347 NOTREACHED();
348 }
349 profile_->GetGeolocationContentSettingsMap()->SetDefaultContentSetting(
350 setting);
351 }
352
353 - (NSInteger)geolocationSettingIndex {
354 ContentSetting setting =
355 profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting();
356 switch (setting) {
357 case CONTENT_SETTING_ALLOW: return kGeolocationEnabledIndex;
358 case CONTENT_SETTING_ASK: return kGeolocationAskIndex;
359 case CONTENT_SETTING_BLOCK: return kGeolocationDisabledIndex;
360 default:
viettrungluu 2010/03/26 20:50:18 Is ContentSetting an enum? Does the compiler warn
Nico 2010/03/26 20:54:10 Yes.
361 NOTREACHED();
362 return kGeolocationAskIndex;
363 }
364 }
365
327 @end 366 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698