OLD | NEW |
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/ui/cocoa/clear_browsing_data_controller.h" | 5 #import "chrome/browser/ui/cocoa/clear_browsing_data_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
10 #include "base/scoped_nsobject.h" | 10 #include "base/scoped_nsobject.h" |
| 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/browsing_data_remover.h" | 12 #include "chrome/browser/browsing_data_remover.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/notification_details.h" |
17 #include "grit/locale_settings.h" | 19 #include "grit/locale_settings.h" |
| 20 #include "grit/generated_resources.h" |
18 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 21 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
19 | 22 |
20 NSString* const kClearBrowsingDataControllerDidDelete = | 23 NSString* const kClearBrowsingDataControllerDidDelete = |
21 @"kClearBrowsingDataControllerDidDelete"; | 24 @"kClearBrowsingDataControllerDidDelete"; |
22 NSString* const kClearBrowsingDataControllerRemoveMask = | 25 NSString* const kClearBrowsingDataControllerRemoveMask = |
23 @"kClearBrowsingDataControllerRemoveMask"; | 26 @"kClearBrowsingDataControllerRemoveMask"; |
24 | 27 |
25 @interface ClearBrowsingDataController(Private) | 28 @interface ClearBrowsingDataController(Private) |
26 - (void)initFromPrefs; | 29 - (void)initFromPrefs; |
27 - (void)persistToPrefs; | 30 - (void)persistToPrefs; |
28 - (void)dataRemoverDidFinish; | 31 - (void)dataRemoverDidFinish; |
29 @end | 32 @end |
30 | 33 |
31 class ClearBrowsingObserver : public BrowsingDataRemover::Observer { | 34 class ClearBrowsingObserver : public BrowsingDataRemover::Observer { |
32 public: | 35 public: |
33 ClearBrowsingObserver(ClearBrowsingDataController* controller) | 36 ClearBrowsingObserver(ClearBrowsingDataController* controller) |
34 : controller_(controller) { } | 37 : controller_(controller) { } |
35 void OnBrowsingDataRemoverDone() { [controller_ dataRemoverDidFinish]; } | 38 void OnBrowsingDataRemoverDone() { [controller_ dataRemoverDidFinish]; } |
36 private: | 39 private: |
37 ClearBrowsingDataController* controller_; | 40 ClearBrowsingDataController* controller_; |
38 }; | 41 }; |
39 | 42 |
| 43 namespace clear_browsing_data_controller_internal { |
| 44 |
| 45 // A C++ class registered for changes in preferences. |
| 46 class PrefObserverBridge : public NotificationObserver { |
| 47 public: |
| 48 PrefObserverBridge(id controller) |
| 49 : controller_(controller) {} |
| 50 |
| 51 virtual ~PrefObserverBridge() {} |
| 52 |
| 53 virtual void Observe(NotificationType type, |
| 54 const NotificationSource& source, |
| 55 const NotificationDetails& details) { |
| 56 if (type == NotificationType::PREF_CHANGED) { |
| 57 const std::string& pref = *(Details<std::string>(details).ptr()); |
| 58 if (pref == prefs::kClearPluginLSODataEnabled) { |
| 59 [controller_ willChangeValueForKey:@"clearLSODataEnabled"]; |
| 60 [controller_ didChangeValueForKey:@"clearLSODataEnabled"]; |
| 61 [controller_ willChangeValueForKey:@"clearLSODataChecked"]; |
| 62 [controller_ didChangeValueForKey:@"clearLSODataChecked"]; |
| 63 [controller_ willChangeValueForKey:@"clearLSODataMessage"]; |
| 64 [controller_ didChangeValueForKey:@"clearLSODataMessage"]; |
| 65 } |
| 66 } else { |
| 67 NOTREACHED(); |
| 68 } |
| 69 } |
| 70 |
| 71 private: |
| 72 id controller_; // weak, owns us |
| 73 }; |
| 74 |
| 75 } // namespace clear_browsing_data_controller_internal |
| 76 |
40 namespace { | 77 namespace { |
41 | 78 |
42 typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; | 79 typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; |
43 | 80 |
44 static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( | 81 static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
45 base::LINKER_INITIALIZED); | 82 base::LINKER_INITIALIZED); |
46 | 83 |
47 } // namespace | 84 } // namespace |
48 | 85 |
49 @implementation ClearBrowsingDataController | 86 @implementation ClearBrowsingDataController |
50 | 87 |
51 @synthesize clearBrowsingHistory = clearBrowsingHistory_; | 88 @synthesize clearBrowsingHistory = clearBrowsingHistory_; |
52 @synthesize clearDownloadHistory = clearDownloadHistory_; | 89 @synthesize clearDownloadHistory = clearDownloadHistory_; |
53 @synthesize emptyCache = emptyCache_; | 90 @synthesize emptyCache = emptyCache_; |
54 @synthesize deleteCookies = deleteCookies_; | 91 @synthesize deleteCookies = deleteCookies_; |
55 @synthesize clearSavedPasswords = clearSavedPasswords_; | 92 @synthesize clearSavedPasswords = clearSavedPasswords_; |
| 93 @synthesize clearLSOData = clearLSOData_; |
56 @synthesize clearFormData = clearFormData_; | 94 @synthesize clearFormData = clearFormData_; |
57 @synthesize timePeriod = timePeriod_; | 95 @synthesize timePeriod = timePeriod_; |
58 @synthesize isClearing = isClearing_; | 96 @synthesize isClearing = isClearing_; |
59 | 97 |
| 98 - (BOOL)clearLSODataChecked { |
| 99 return clearLSOData_ && clearLSODataEnabled_.GetValue(); |
| 100 } |
| 101 |
| 102 - (void)setClearLSODataChecked:(BOOL)value { |
| 103 DCHECK(clearLSODataEnabled_.GetValue()); |
| 104 clearLSOData_ = value; |
| 105 } |
| 106 |
| 107 - (BOOL)clearLSODataEnabled { |
| 108 return clearLSODataEnabled_.GetValue(); |
| 109 } |
| 110 |
| 111 - (NSString*)clearLSODataMessage { |
| 112 if (self.clearLSODataEnabled) |
| 113 return nil; |
| 114 return l10n_util::GetNSString(IDS_LSO_CLEAR_MESSAGE); |
| 115 } |
| 116 |
60 + (void)showClearBrowsingDialogForProfile:(Profile*)profile { | 117 + (void)showClearBrowsingDialogForProfile:(Profile*)profile { |
61 ClearBrowsingDataController* controller = | 118 ClearBrowsingDataController* controller = |
62 [ClearBrowsingDataController controllerForProfile:profile]; | 119 [ClearBrowsingDataController controllerForProfile:profile]; |
63 if (![controller isWindowLoaded]) { | 120 if (![controller isWindowLoaded]) { |
64 // This function needs to return instead of blocking, to match the windows | 121 // This function needs to return instead of blocking, to match the windows |
65 // api call. It caused problems when launching the dialog from the | 122 // api call. It caused problems when launching the dialog from the |
66 // DomUI history page. See bug and code review for more details. | 123 // DomUI history page. See bug and code review for more details. |
67 // http://crbug.com/37976 | 124 // http://crbug.com/37976 |
68 [controller performSelector:@selector(runModalDialog) | 125 [controller performSelector:@selector(runModalDialog) |
69 withObject:nil | 126 withObject:nil |
(...skipping 27 matching lines...) Expand all Loading... |
97 - (id)initWithProfile:(Profile*)profile { | 154 - (id)initWithProfile:(Profile*)profile { |
98 DCHECK(profile); | 155 DCHECK(profile); |
99 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we | 156 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we |
100 // can override it in a unit test. | 157 // can override it in a unit test. |
101 NSString *nibpath = [mac_util::MainAppBundle() | 158 NSString *nibpath = [mac_util::MainAppBundle() |
102 pathForResource:@"ClearBrowsingData" | 159 pathForResource:@"ClearBrowsingData" |
103 ofType:@"nib"]; | 160 ofType:@"nib"]; |
104 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 161 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
105 profile_ = profile; | 162 profile_ = profile; |
106 observer_.reset(new ClearBrowsingObserver(self)); | 163 observer_.reset(new ClearBrowsingObserver(self)); |
| 164 PrefService* prefs = g_browser_process->local_state(); |
| 165 // In unit tests |local_state()| can be NULL. |
| 166 if (!prefs) |
| 167 prefs = profile->GetPrefs(); |
| 168 prefObserver_.reset( |
| 169 new clear_browsing_data_controller_internal::PrefObserverBridge(self)); |
| 170 clearLSODataEnabled_.Init(prefs::kClearPluginLSODataEnabled, |
| 171 prefs, |
| 172 prefObserver_.get()); |
107 [self initFromPrefs]; | 173 [self initFromPrefs]; |
108 } | 174 } |
109 return self; | 175 return self; |
110 } | 176 } |
111 | 177 |
112 - (void)dealloc { | 178 - (void)dealloc { |
113 if (remover_) { | 179 if (remover_) { |
114 // We were destroyed while clearing history was in progress. This can only | 180 // We were destroyed while clearing history was in progress. This can only |
115 // occur during automated tests (normally the user can't close the dialog | 181 // occur during automated tests (normally the user can't close the dialog |
116 // while clearing is in progress as the dialog is modal and not closeable). | 182 // while clearing is in progress as the dialog is modal and not closeable). |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (clearBrowsingHistory_) | 225 if (clearBrowsingHistory_) |
160 removeMask |= BrowsingDataRemover::REMOVE_HISTORY; | 226 removeMask |= BrowsingDataRemover::REMOVE_HISTORY; |
161 if (clearDownloadHistory_) | 227 if (clearDownloadHistory_) |
162 removeMask |= BrowsingDataRemover::REMOVE_DOWNLOADS; | 228 removeMask |= BrowsingDataRemover::REMOVE_DOWNLOADS; |
163 if (emptyCache_) | 229 if (emptyCache_) |
164 removeMask |= BrowsingDataRemover::REMOVE_CACHE; | 230 removeMask |= BrowsingDataRemover::REMOVE_CACHE; |
165 if (deleteCookies_) | 231 if (deleteCookies_) |
166 removeMask |= BrowsingDataRemover::REMOVE_COOKIES; | 232 removeMask |= BrowsingDataRemover::REMOVE_COOKIES; |
167 if (clearSavedPasswords_) | 233 if (clearSavedPasswords_) |
168 removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS; | 234 removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS; |
| 235 if (self.clearLSOData) |
| 236 removeMask |= BrowsingDataRemover::REMOVE_LSO_DATA; |
169 if (clearFormData_) | 237 if (clearFormData_) |
170 removeMask |= BrowsingDataRemover::REMOVE_FORM_DATA; | 238 removeMask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
171 return removeMask; | 239 return removeMask; |
172 } | 240 } |
173 | 241 |
174 // Called when the user clicks the "clear" button. Do the work and persist | 242 // Called when the user clicks the "clear" button. Do the work and persist |
175 // the prefs for next time. We don't stop the modal session until we get | 243 // the prefs for next time. We don't stop the modal session until we get |
176 // the callback from the BrowsingDataRemover so the window stays on the screen. | 244 // the callback from the BrowsingDataRemover so the window stays on the screen. |
177 // While we're working, dim the buttons so the user can't click them. | 245 // While we're working, dim the buttons so the user can't click them. |
178 - (IBAction)clearData:(id)sender { | 246 - (IBAction)clearData:(id)sender { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // Initialize the bools from prefs using the setters to be KVO-compliant. | 289 // Initialize the bools from prefs using the setters to be KVO-compliant. |
222 - (void)initFromPrefs { | 290 - (void)initFromPrefs { |
223 PrefService* prefs = profile_->GetPrefs(); | 291 PrefService* prefs = profile_->GetPrefs(); |
224 [self setClearBrowsingHistory: | 292 [self setClearBrowsingHistory: |
225 prefs->GetBoolean(prefs::kDeleteBrowsingHistory)]; | 293 prefs->GetBoolean(prefs::kDeleteBrowsingHistory)]; |
226 [self setClearDownloadHistory: | 294 [self setClearDownloadHistory: |
227 prefs->GetBoolean(prefs::kDeleteDownloadHistory)]; | 295 prefs->GetBoolean(prefs::kDeleteDownloadHistory)]; |
228 [self setEmptyCache:prefs->GetBoolean(prefs::kDeleteCache)]; | 296 [self setEmptyCache:prefs->GetBoolean(prefs::kDeleteCache)]; |
229 [self setDeleteCookies:prefs->GetBoolean(prefs::kDeleteCookies)]; | 297 [self setDeleteCookies:prefs->GetBoolean(prefs::kDeleteCookies)]; |
230 [self setClearSavedPasswords:prefs->GetBoolean(prefs::kDeletePasswords)]; | 298 [self setClearSavedPasswords:prefs->GetBoolean(prefs::kDeletePasswords)]; |
| 299 [self setClearLSOData:prefs->GetBoolean(prefs::kDeleteLSOData)]; |
231 [self setClearFormData:prefs->GetBoolean(prefs::kDeleteFormData)]; | 300 [self setClearFormData:prefs->GetBoolean(prefs::kDeleteFormData)]; |
232 [self setTimePeriod:prefs->GetInteger(prefs::kDeleteTimePeriod)]; | 301 [self setTimePeriod:prefs->GetInteger(prefs::kDeleteTimePeriod)]; |
233 } | 302 } |
234 | 303 |
235 // Save the checkbox values to the preferences. | 304 // Save the checkbox values to the preferences. |
236 - (void)persistToPrefs { | 305 - (void)persistToPrefs { |
237 PrefService* prefs = profile_->GetPrefs(); | 306 PrefService* prefs = profile_->GetPrefs(); |
238 prefs->SetBoolean(prefs::kDeleteBrowsingHistory, | 307 prefs->SetBoolean(prefs::kDeleteBrowsingHistory, |
239 [self clearBrowsingHistory]); | 308 [self clearBrowsingHistory]); |
240 prefs->SetBoolean(prefs::kDeleteDownloadHistory, | 309 prefs->SetBoolean(prefs::kDeleteDownloadHistory, |
241 [self clearDownloadHistory]); | 310 [self clearDownloadHistory]); |
242 prefs->SetBoolean(prefs::kDeleteCache, [self emptyCache]); | 311 prefs->SetBoolean(prefs::kDeleteCache, [self emptyCache]); |
243 prefs->SetBoolean(prefs::kDeleteCookies, [self deleteCookies]); | 312 prefs->SetBoolean(prefs::kDeleteCookies, [self deleteCookies]); |
244 prefs->SetBoolean(prefs::kDeletePasswords, [self clearSavedPasswords]); | 313 prefs->SetBoolean(prefs::kDeletePasswords, [self clearSavedPasswords]); |
| 314 prefs->SetBoolean(prefs::kDeleteLSOData, [self clearLSOData]); |
245 prefs->SetBoolean(prefs::kDeleteFormData, [self clearFormData]); | 315 prefs->SetBoolean(prefs::kDeleteFormData, [self clearFormData]); |
246 prefs->SetInteger(prefs::kDeleteTimePeriod, [self timePeriod]); | 316 prefs->SetInteger(prefs::kDeleteTimePeriod, [self timePeriod]); |
247 } | 317 } |
248 | 318 |
249 // Called when the data remover object is done with its work. Close the window. | 319 // Called when the data remover object is done with its work. Close the window. |
250 // The remover will delete itself. End the modal session at this point. | 320 // The remover will delete itself. End the modal session at this point. |
251 - (void)dataRemoverDidFinish { | 321 - (void)dataRemoverDidFinish { |
252 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 322 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
253 int removeMask = [self removeMask]; | 323 int removeMask = [self removeMask]; |
254 NSDictionary* userInfo = | 324 NSDictionary* userInfo = |
255 [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:removeMask] | 325 [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:removeMask] |
256 forKey:kClearBrowsingDataControllerRemoveMask]; | 326 forKey:kClearBrowsingDataControllerRemoveMask]; |
257 [center postNotificationName:kClearBrowsingDataControllerDidDelete | 327 [center postNotificationName:kClearBrowsingDataControllerDidDelete |
258 object:self | 328 object:self |
259 userInfo:userInfo]; | 329 userInfo:userInfo]; |
260 | 330 |
261 [self closeDialog]; | 331 [self closeDialog]; |
262 [[self window] orderOut:self]; | 332 [[self window] orderOut:self]; |
263 [self setIsClearing:NO]; | 333 [self setIsClearing:NO]; |
264 remover_ = NULL; | 334 remover_ = NULL; |
265 } | 335 } |
266 | 336 |
267 @end | 337 @end |
OLD | NEW |