Index: chrome/browser/ui/cocoa/clear_browsing_data_controller.mm |
diff --git a/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm b/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm |
index c0c927e3c93ab50a47631d29aa22c72f8c0de1f5..bf403b4f92c33719348838f77cf4747f6c592752 100644 |
--- a/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm |
+++ b/chrome/browser/ui/cocoa/clear_browsing_data_controller.mm |
@@ -8,13 +8,16 @@ |
#include "base/lazy_instance.h" |
#include "base/mac_util.h" |
#include "base/scoped_nsobject.h" |
+#include "chrome/browser/browser_process.h" |
#include "chrome/browser/browsing_data_remover.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/common/pref_names.h" |
+#include "chrome/common/notification_details.h" |
#include "grit/locale_settings.h" |
+#include "grit/generated_resources.h" |
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
NSString* const kClearBrowsingDataControllerDidDelete = |
@@ -37,6 +40,40 @@ class ClearBrowsingObserver : public BrowsingDataRemover::Observer { |
ClearBrowsingDataController* controller_; |
}; |
+namespace clear_browsing_data_controller_internal { |
+ |
+// A C++ class registered for changes in preferences. |
+class PrefObserverBridge : public NotificationObserver { |
+ public: |
+ PrefObserverBridge(id controller) |
+ : controller_(controller) {} |
+ |
+ virtual ~PrefObserverBridge() {} |
+ |
+ virtual void Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ if (type == NotificationType::PREF_CHANGED) { |
+ const std::string& pref = *(Details<std::string>(details).ptr()); |
+ if (pref == prefs::kClearPluginLSODataEnabled) { |
+ [controller_ willChangeValueForKey:@"clearLSODataEnabled"]; |
+ [controller_ didChangeValueForKey:@"clearLSODataEnabled"]; |
+ [controller_ willChangeValueForKey:@"clearLSODataChecked"]; |
+ [controller_ didChangeValueForKey:@"clearLSODataChecked"]; |
+ [controller_ willChangeValueForKey:@"clearLSODataMessage"]; |
+ [controller_ didChangeValueForKey:@"clearLSODataMessage"]; |
+ } |
+ } else { |
+ NOTREACHED(); |
+ } |
+ } |
+ |
+ private: |
+ id controller_; // weak, owns us |
+}; |
+ |
+} // namespace clear_browsing_data_controller_internal |
+ |
namespace { |
typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; |
@@ -53,10 +90,30 @@ static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
@synthesize emptyCache = emptyCache_; |
@synthesize deleteCookies = deleteCookies_; |
@synthesize clearSavedPasswords = clearSavedPasswords_; |
+@synthesize clearLSOData = clearLSOData_; |
@synthesize clearFormData = clearFormData_; |
@synthesize timePeriod = timePeriod_; |
@synthesize isClearing = isClearing_; |
+- (BOOL)clearLSODataChecked { |
+ return clearLSOData_ && clearLSODataEnabled_.GetValue(); |
+} |
+ |
+- (void)setClearLSODataChecked:(BOOL)value { |
+ DCHECK(clearLSODataEnabled_.GetValue()); |
+ clearLSOData_ = value; |
+} |
+ |
+- (BOOL)clearLSODataEnabled { |
+ return clearLSODataEnabled_.GetValue(); |
+} |
+ |
+- (NSString*)clearLSODataMessage { |
+ if (self.clearLSODataEnabled) |
+ return nil; |
+ return l10n_util::GetNSString(IDS_LSO_CLEAR_MESSAGE); |
+} |
+ |
+ (void)showClearBrowsingDialogForProfile:(Profile*)profile { |
ClearBrowsingDataController* controller = |
[ClearBrowsingDataController controllerForProfile:profile]; |
@@ -104,6 +161,15 @@ static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
profile_ = profile; |
observer_.reset(new ClearBrowsingObserver(self)); |
+ PrefService* prefs = g_browser_process->local_state(); |
+ // In unit tests |local_state()| can be NULL. |
+ if (!prefs) |
+ prefs = profile->GetPrefs(); |
+ prefObserver_.reset( |
+ new clear_browsing_data_controller_internal::PrefObserverBridge(self)); |
+ clearLSODataEnabled_.Init(prefs::kClearPluginLSODataEnabled, |
+ prefs, |
+ prefObserver_.get()); |
[self initFromPrefs]; |
} |
return self; |
@@ -166,6 +232,8 @@ static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
removeMask |= BrowsingDataRemover::REMOVE_COOKIES; |
if (clearSavedPasswords_) |
removeMask |= BrowsingDataRemover::REMOVE_PASSWORDS; |
+ if (self.clearLSOData) |
+ removeMask |= BrowsingDataRemover::REMOVE_LSO_DATA; |
if (clearFormData_) |
removeMask |= BrowsingDataRemover::REMOVE_FORM_DATA; |
return removeMask; |
@@ -228,6 +296,7 @@ static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
[self setEmptyCache:prefs->GetBoolean(prefs::kDeleteCache)]; |
[self setDeleteCookies:prefs->GetBoolean(prefs::kDeleteCookies)]; |
[self setClearSavedPasswords:prefs->GetBoolean(prefs::kDeletePasswords)]; |
+ [self setClearLSOData:prefs->GetBoolean(prefs::kDeleteLSOData)]; |
[self setClearFormData:prefs->GetBoolean(prefs::kDeleteFormData)]; |
[self setTimePeriod:prefs->GetInteger(prefs::kDeleteTimePeriod)]; |
} |
@@ -242,6 +311,7 @@ static base::LazyInstance<ProfileControllerMap> g_profile_controller_map( |
prefs->SetBoolean(prefs::kDeleteCache, [self emptyCache]); |
prefs->SetBoolean(prefs::kDeleteCookies, [self deleteCookies]); |
prefs->SetBoolean(prefs::kDeletePasswords, [self clearSavedPasswords]); |
+ prefs->SetBoolean(prefs::kDeleteLSOData, [self clearLSOData]); |
prefs->SetBoolean(prefs::kDeleteFormData, [self clearFormData]); |
prefs->SetInteger(prefs::kDeleteTimePeriod, [self timePeriod]); |
} |