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

Side by Side Diff: chrome/browser/ui/cocoa/clear_browsing_data_controller.mm

Issue 5964008: Add UI to the Clear Browsing Data dialog to remove Flash LSO data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: linux compile fix Created 10 years 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) 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:@"clearLSODataCheckbox"];
62 [controller_ didChangeValueForKey:@"clearLSODataCheckbox"];
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)clearLSODataCheckbox {
99 return clearLSOData_ && clearLSODataEnabled_.GetValue();
100 }
101
102 - (void)setClearLSODataCheckbox:(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
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 prefObserver_.reset(
165 new clear_browsing_data_controller_internal::PrefObserverBridge(self));
166 clearLSODataEnabled_.Init(prefs::kClearPluginLSODataEnabled,
167 g_browser_process->local_state(),
168 prefObserver_.get());
107 [self initFromPrefs]; 169 [self initFromPrefs];
108 } 170 }
109 return self; 171 return self;
110 } 172 }
111 173
112 - (void)dealloc { 174 - (void)dealloc {
113 if (remover_) { 175 if (remover_) {
114 // We were destroyed while clearing history was in progress. This can only 176 // 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 177 // 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). 178 // 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
159 if (clearBrowsingHistory_) 221 if (clearBrowsingHistory_)
160 removeMask |= BrowsingDataRemover::REMOVE_HISTORY; 222 removeMask |= BrowsingDataRemover::REMOVE_HISTORY;
161 if (clearDownloadHistory_) 223 if (clearDownloadHistory_)
162 removeMask |= BrowsingDataRemover::REMOVE_DOWNLOADS; 224 removeMask |= BrowsingDataRemover::REMOVE_DOWNLOADS;
163 if (emptyCache_) 225 if (emptyCache_)
164 removeMask |= BrowsingDataRemover::REMOVE_CACHE; 226 removeMask |= BrowsingDataRemover::REMOVE_CACHE;
165 if (deleteCookies_) 227 if (deleteCookies_)
166 removeMask |= BrowsingDataRemover::REMOVE_COOKIES; 228 removeMask |= BrowsingDataRemover::REMOVE_COOKIES;
167 if (clearSavedPasswords_) 229 if (clearSavedPasswords_)
168 removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS; 230 removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS;
231 if (self.clearLSOData)
232 removeMask |= BrowsingDataRemover::REMOVE_LSO_DATA;
169 if (clearFormData_) 233 if (clearFormData_)
170 removeMask |= BrowsingDataRemover::REMOVE_FORM_DATA; 234 removeMask |= BrowsingDataRemover::REMOVE_FORM_DATA;
171 return removeMask; 235 return removeMask;
172 } 236 }
173 237
174 // Called when the user clicks the "clear" button. Do the work and persist 238 // 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 239 // 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. 240 // 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. 241 // While we're working, dim the buttons so the user can't click them.
178 - (IBAction)clearData:(id)sender { 242 - (IBAction)clearData:(id)sender {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Initialize the bools from prefs using the setters to be KVO-compliant. 285 // Initialize the bools from prefs using the setters to be KVO-compliant.
222 - (void)initFromPrefs { 286 - (void)initFromPrefs {
223 PrefService* prefs = profile_->GetPrefs(); 287 PrefService* prefs = profile_->GetPrefs();
224 [self setClearBrowsingHistory: 288 [self setClearBrowsingHistory:
225 prefs->GetBoolean(prefs::kDeleteBrowsingHistory)]; 289 prefs->GetBoolean(prefs::kDeleteBrowsingHistory)];
226 [self setClearDownloadHistory: 290 [self setClearDownloadHistory:
227 prefs->GetBoolean(prefs::kDeleteDownloadHistory)]; 291 prefs->GetBoolean(prefs::kDeleteDownloadHistory)];
228 [self setEmptyCache:prefs->GetBoolean(prefs::kDeleteCache)]; 292 [self setEmptyCache:prefs->GetBoolean(prefs::kDeleteCache)];
229 [self setDeleteCookies:prefs->GetBoolean(prefs::kDeleteCookies)]; 293 [self setDeleteCookies:prefs->GetBoolean(prefs::kDeleteCookies)];
230 [self setClearSavedPasswords:prefs->GetBoolean(prefs::kDeletePasswords)]; 294 [self setClearSavedPasswords:prefs->GetBoolean(prefs::kDeletePasswords)];
295 [self setClearLSOData:prefs->GetBoolean(prefs::kDeleteLSOData)];
231 [self setClearFormData:prefs->GetBoolean(prefs::kDeleteFormData)]; 296 [self setClearFormData:prefs->GetBoolean(prefs::kDeleteFormData)];
232 [self setTimePeriod:prefs->GetInteger(prefs::kDeleteTimePeriod)]; 297 [self setTimePeriod:prefs->GetInteger(prefs::kDeleteTimePeriod)];
233 } 298 }
234 299
235 // Save the checkbox values to the preferences. 300 // Save the checkbox values to the preferences.
236 - (void)persistToPrefs { 301 - (void)persistToPrefs {
237 PrefService* prefs = profile_->GetPrefs(); 302 PrefService* prefs = profile_->GetPrefs();
238 prefs->SetBoolean(prefs::kDeleteBrowsingHistory, 303 prefs->SetBoolean(prefs::kDeleteBrowsingHistory,
239 [self clearBrowsingHistory]); 304 [self clearBrowsingHistory]);
240 prefs->SetBoolean(prefs::kDeleteDownloadHistory, 305 prefs->SetBoolean(prefs::kDeleteDownloadHistory,
241 [self clearDownloadHistory]); 306 [self clearDownloadHistory]);
242 prefs->SetBoolean(prefs::kDeleteCache, [self emptyCache]); 307 prefs->SetBoolean(prefs::kDeleteCache, [self emptyCache]);
243 prefs->SetBoolean(prefs::kDeleteCookies, [self deleteCookies]); 308 prefs->SetBoolean(prefs::kDeleteCookies, [self deleteCookies]);
244 prefs->SetBoolean(prefs::kDeletePasswords, [self clearSavedPasswords]); 309 prefs->SetBoolean(prefs::kDeletePasswords, [self clearSavedPasswords]);
310 prefs->SetBoolean(prefs::kDeleteLSOData, [self clearLSOData]);
245 prefs->SetBoolean(prefs::kDeleteFormData, [self clearFormData]); 311 prefs->SetBoolean(prefs::kDeleteFormData, [self clearFormData]);
246 prefs->SetInteger(prefs::kDeleteTimePeriod, [self timePeriod]); 312 prefs->SetInteger(prefs::kDeleteTimePeriod, [self timePeriod]);
247 } 313 }
248 314
249 // Called when the data remover object is done with its work. Close the window. 315 // 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. 316 // The remover will delete itself. End the modal session at this point.
251 - (void)dataRemoverDidFinish { 317 - (void)dataRemoverDidFinish {
252 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 318 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
253 int removeMask = [self removeMask]; 319 int removeMask = [self removeMask];
254 NSDictionary* userInfo = 320 NSDictionary* userInfo =
255 [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:removeMask] 321 [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:removeMask]
256 forKey:kClearBrowsingDataControllerRemoveMask]; 322 forKey:kClearBrowsingDataControllerRemoveMask];
257 [center postNotificationName:kClearBrowsingDataControllerDidDelete 323 [center postNotificationName:kClearBrowsingDataControllerDidDelete
258 object:self 324 object:self
259 userInfo:userInfo]; 325 userInfo:userInfo];
260 326
261 [self closeDialog]; 327 [self closeDialog];
262 [[self window] orderOut:self]; 328 [[self window] orderOut:self];
263 [self setIsClearing:NO]; 329 [self setIsClearing:NO];
264 remover_ = NULL; 330 remover_ = NULL;
265 } 331 }
266 332
267 @end 333 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698