diff options
-rw-r--r-- | chrome/browser/browser.cc | 1 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 35 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.h | 4 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_context.cc | 27 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_context.h | 10 | ||||
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.cc | 9 | ||||
-rw-r--r-- | chrome/browser/net/sqlite_persistent_cookie_store.h | 4 | ||||
-rw-r--r-- | chrome/browser/options_util.cc | 1 | ||||
-rw-r--r-- | chrome/browser/views/options/cookie_filter_page_view.cc | 14 | ||||
-rw-r--r-- | chrome/browser/views/options/cookie_filter_page_view.h | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 | ||||
-rw-r--r-- | webkit/database/database_tracker.cc | 46 | ||||
-rw-r--r-- | webkit/database/database_tracker.h | 3 |
14 files changed, 151 insertions, 12 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index e683ca8..ad5e597 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1370,6 +1370,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kHomePage, ASCIIToWide(chrome::kChromeUINewTabURL)); prefs->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true); + prefs->RegisterBooleanPref(prefs::kClearSiteDataOnExit, false); prefs->RegisterBooleanPref(prefs::kShowHomeButton, false); #if defined(OS_MACOSX) // This really belongs in platform code, but there's no good place to diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index a63f6a4..f58357b 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -21,11 +21,13 @@ #include "chrome/browser/download/save_file_manager.h" #include "chrome/browser/google_url_tracker.h" #include "chrome/browser/icon_manager.h" +#include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h" +#include "chrome/browser/net/sqlite_persistent_cookie_store.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/profile_manager.h" @@ -33,12 +35,15 @@ #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/common/child_process_host.h" +#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" #include "ipc/ipc_logging.h" +#include "webkit/database/database_tracker.h" #if defined(OS_WIN) #include "views/focus/view_storage.h" @@ -88,6 +93,12 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) } BrowserProcessImpl::~BrowserProcessImpl() { + FilePath profile_path; + bool clear_local_state_on_exit; + + // Store the profile path for clearing local state data on exit. + clear_local_state_on_exit = ShouldClearLocalState(&profile_path); + // Delete the AutomationProviderList before NotificationService, // since it may try to unregister notifications // Both NotificationService and AutomationProvider are singleton instances in @@ -153,6 +164,11 @@ BrowserProcessImpl::~BrowserProcessImpl() { // SaveFileManager and SessionService. file_thread_.reset(); + // At this point, no render process exist, so it's safe to access local + // state data such as cookies, database, or local storage. + if (clear_local_state_on_exit) + ClearLocalState(profile_path); + // With the file_thread_ flushed, we can release any icon resources. icon_manager_.reset(); @@ -232,6 +248,25 @@ printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { return print_job_manager_.get(); } +void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) { + SQLitePersistentCookieStore::ClearLocalState(profile_path.Append( + chrome::kCookieFilename)); + DOMStorageContext::ClearLocalState(profile_path, chrome::kExtensionScheme); + webkit_database::DatabaseTracker::ClearLocalState(profile_path, + chrome::kExtensionScheme); + // TODO(jochen): clear app cache local state. +} + +bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) { + FilePath user_data_dir; + Profile* profile; + + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); + profile = profile_manager_->GetDefaultProfile(user_data_dir); + *profile_path = profile->GetPath(); + return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit); +} + void BrowserProcessImpl::CreateResourceDispatcherHost() { DCHECK(!created_resource_dispatcher_host_ && resource_dispatcher_host_.get() == NULL); diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index e5c83e1..ec03c2f 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -26,6 +26,7 @@ #endif class CommandLine; +class FilePath; class NotificationService; // Real implementation of BrowserProcess that creates and returns the services. @@ -212,6 +213,9 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { #endif private: + void ClearLocalState(const FilePath& profile_path); + bool ShouldClearLocalState(FilePath* profile_path); + void CreateResourceDispatcherHost(); void CreatePrefService(); void CreateMetricsService(); diff --git a/chrome/browser/in_process_webkit/dom_storage_context.cc b/chrome/browser/in_process_webkit/dom_storage_context.cc index c19b6cf..4156576 100644 --- a/chrome/browser/in_process_webkit/dom_storage_context.cc +++ b/chrome/browser/in_process_webkit/dom_storage_context.cc @@ -1,17 +1,21 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #include "chrome/browser/in_process_webkit/dom_storage_context.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/string_util.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/in_process_webkit/dom_storage_area.h" #include "chrome/browser/in_process_webkit/dom_storage_namespace.h" #include "chrome/browser/in_process_webkit/webkit_context.h" #include "chrome/common/dom_storage_common.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "webkit/glue/glue_util.h" +#include "webkit/glue/webkit_glue.h" const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = FILE_PATH_LITERAL("Local Storage"); @@ -236,3 +240,20 @@ void DOMStorageContext::CompleteCloningSessionStorage( if (existing_namespace) context->RegisterStorageNamespace(existing_namespace->Copy(clone_id)); } + +// static +void DOMStorageContext::ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skip) { + file_util::FileEnumerator file_enumerator(profile_path.Append( + kLocalStorageDirectory), false, file_util::FileEnumerator::FILES); + for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); + file_path = file_enumerator.Next()) { + if (file_path.Extension() == kLocalStorageExtension) { + scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( + WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( + webkit_glue::FilePathToWebString(file_path.BaseName()))); + if (!EqualsASCII(web_security_origin->protocol(), url_scheme_to_be_skip)) + file_util::Delete(file_path, false); + } + } +} diff --git a/chrome/browser/in_process_webkit/dom_storage_context.h b/chrome/browser/in_process_webkit/dom_storage_context.h index 4981c07..49e3712 100644 --- a/chrome/browser/in_process_webkit/dom_storage_context.h +++ b/chrome/browser/in_process_webkit/dom_storage_context.h @@ -1,6 +1,6 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ #define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ @@ -78,6 +78,10 @@ class DOMStorageContext { // The local storage file extension. static const FilePath::CharType kLocalStorageExtension[]; + // Delete all non-extension local storage files. + static void ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skipped); + private: // Get the local storage instance. The object is owned by this class. DOMStorageNamespace* CreateLocalStorage(); diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.cc b/chrome/browser/net/sqlite_persistent_cookie_store.cc index 0216b40..a098c44 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.cc +++ b/chrome/browser/net/sqlite_persistent_cookie_store.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,6 +9,7 @@ #include "app/sql/statement.h" #include "app/sql/transaction.h" #include "base/basictypes.h" +#include "base/file_util.h" #include "base/logging.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" @@ -444,3 +445,9 @@ void SQLitePersistentCookieStore::DeleteCookie( if (backend_.get()) backend_->DeleteCookie(cc); } + +// static +void SQLitePersistentCookieStore::ClearLocalState( + const FilePath& path) { + file_util::Delete(path, false); +} diff --git a/chrome/browser/net/sqlite_persistent_cookie_store.h b/chrome/browser/net/sqlite_persistent_cookie_store.h index e687f02..9b12ee4 100644 --- a/chrome/browser/net/sqlite_persistent_cookie_store.h +++ b/chrome/browser/net/sqlite_persistent_cookie_store.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,6 +32,8 @@ class SQLitePersistentCookieStore const net::CookieMonster::CanonicalCookie&); virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie&); + static void ClearLocalState(const FilePath& path); + private: class Backend; diff --git a/chrome/browser/options_util.cc b/chrome/browser/options_util.cc index 9ef6f60..77c9fa6 100644 --- a/chrome/browser/options_util.cc +++ b/chrome/browser/options_util.cc @@ -23,6 +23,7 @@ void OptionsUtil::ResetToDefaults(Profile* profile) { const wchar_t* kUserPrefs[] = { prefs::kAcceptLanguages, prefs::kAlternateErrorPagesEnabled, + prefs::kClearSiteDataOnExit, prefs::kCookieBehavior, prefs::kDefaultCharset, prefs::kDnsPrefetchingEnabled, diff --git a/chrome/browser/views/options/cookie_filter_page_view.cc b/chrome/browser/views/options/cookie_filter_page_view.cc index a7ec450..835282f 100644 --- a/chrome/browser/views/options/cookie_filter_page_view.cc +++ b/chrome/browser/views/options/cookie_filter_page_view.cc @@ -14,6 +14,7 @@ #include "chrome/browser/views/options/cookies_view.h" #include "chrome/browser/views/options/exceptions_view.h" #include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "views/controls/button/checkbox.h" @@ -32,6 +33,8 @@ CookieFilterPageView::CookieFilterPageView(Profile* profile) clear_on_close_check_(NULL), show_cookies_button_(NULL), OptionsPageView(profile) { + clear_site_data_on_exit_.Init(prefs::kClearSiteDataOnExit, + profile->GetPrefs(), NULL); } CookieFilterPageView::~CookieFilterPageView() { @@ -128,8 +131,6 @@ void CookieFilterPageView::InitControlLayout() { l10n_util::GetString(IDS_COOKIES_CLEAR_WHEN_CLOSE_CHKBOX)); clear_on_close_check_->set_listener(this); - // TODO(pkasting): Set clear-on-close checkbox to be checked or not. - layout->StartRow(0, single_column_set_id); layout->AddView(clear_on_close_check_); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); @@ -151,6 +152,13 @@ void CookieFilterPageView::InitControlLayout() { GridLayout::FILL); } +void CookieFilterPageView::NotifyPrefChanged(const std::wstring* pref_name) { + if (!pref_name || *pref_name == prefs::kClearSiteDataOnExit) { + clear_on_close_check_->SetChecked( + clear_site_data_on_exit_.GetValue()); + } +} + /////////////////////////////////////////////////////////////////////////////// // CookieFilterPageView, views::ButtonListener implementation: @@ -173,7 +181,7 @@ void CookieFilterPageView::ButtonPressed( } else if (sender == block_3rdparty_check_) { settings_map->SetBlockThirdPartyCookies(block_3rdparty_check_->checked()); } else if (sender == clear_on_close_check_) { - // TODO(pkasting): Set clear-on-close setting. + clear_site_data_on_exit_.SetValue(clear_on_close_check_->checked()); } else { DCHECK_EQ(sender, show_cookies_button_); UserMetricsRecordAction("Options_ShowCookies", NULL); diff --git a/chrome/browser/views/options/cookie_filter_page_view.h b/chrome/browser/views/options/cookie_filter_page_view.h index 812e1dd..d2129f0 100644 --- a/chrome/browser/views/options/cookie_filter_page_view.h +++ b/chrome/browser/views/options/cookie_filter_page_view.h @@ -33,6 +33,7 @@ class CookieFilterPageView : public OptionsPageView, private: // OptionsPageView implementation: virtual void InitControlLayout(); + virtual void NotifyPrefChanged(const std::wstring* pref_name); // views::ButtonListener implementation: virtual void ButtonPressed(views::Button* sender, const views::Event& event); @@ -50,6 +51,9 @@ class CookieFilterPageView : public OptionsPageView, views::Checkbox* clear_on_close_check_; views::NativeButton* show_cookies_button_; + // Clear locally stored site data on exit pref. + BooleanPrefMember clear_site_data_on_exit_; + DISALLOW_COPY_AND_ASSIGN(CookieFilterPageView); }; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 39fdb86..45ca3a1 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -309,6 +309,10 @@ const wchar_t kPerHostContentSettings[] = L"profile.per_host_content_settings"; // regardless of other content settings. const wchar_t kBlockThirdPartyCookies[] = L"profile.block_third_party_cookies"; +// Boolean that is true when all locally stored site data (e.g. cookies, local +// storage, etc..) should be deleted on exit. +const wchar_t kClearSiteDataOnExit[] = L"profile.clear_site_data_on_exit"; + // Dictionary that maps hostnames to zoom levels. Hosts not in this pref will // be displayed at the default zoom level. const wchar_t kPerHostZoomLevels[] = L"profile.per_host_zoom_levels"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index da24ab0..2c8cfc0 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -121,6 +121,7 @@ extern const wchar_t kDesktopNotificationDeniedOrigins[]; extern const wchar_t kDefaultContentSettings[]; extern const wchar_t kPerHostContentSettings[]; extern const wchar_t kBlockThirdPartyCookies[]; +extern const wchar_t kClearSiteDataOnExit[]; extern const wchar_t kPerHostZoomLevels[]; extern const wchar_t kAutoFillInfoBarShown[]; extern const wchar_t kAutoFillEnabled[]; diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc index 01c3052..489122e 100644 --- a/webkit/database/database_tracker.cc +++ b/webkit/database/database_tracker.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,8 +14,11 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/string_util.h" +#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "webkit/database/databases_table.h" #include "webkit/database/quota_table.h" +#include "webkit/glue/webkit_glue.h" namespace webkit_database { @@ -331,4 +334,45 @@ int64 DatabaseTracker::UpdateCachedDatabaseFileSize( return new_size; } +// static +void DatabaseTracker::ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skipped) { + FilePath db_dir = profile_path.Append(FilePath(kDatabaseDirectoryName)); + FilePath db_tracker = db_dir.Append(FilePath(kTrackerDatabaseFileName)); + if (file_util::DirectoryExists(db_dir) && + file_util::PathExists(db_tracker)) { + scoped_ptr<sql::Connection> db_(new sql::Connection); + if (!db_->Open(db_tracker) || + !db_->DoesTableExist("Databases")) { + db_->Close(); + file_util::Delete(db_dir, true); + return; + } else { + sql::Statement delete_statement(db_->GetCachedStatement( + SQL_FROM_HERE, "DELETE FROM Databases WHERE origin NOT LIKE ?")); + std::string filter(url_scheme_to_be_skipped); + filter += "_%"; + delete_statement.BindString(0, filter); + if (!delete_statement.Run()) { + db_->Close(); + file_util::Delete(db_dir, true); + return; + } + } + } + file_util::FileEnumerator file_enumerator(db_dir, false, + file_util::FileEnumerator::DIRECTORIES); + for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); + file_path = file_enumerator.Next()) { + if (file_path.BaseName() != FilePath(kTrackerDatabaseFileName)) { + scoped_ptr<WebKit::WebSecurityOrigin> web_security_origin( + WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( + webkit_glue::FilePathToWebString(file_path.BaseName()))); + if (!EqualsASCII(web_security_origin->protocol(), + url_scheme_to_be_skipped)) + file_util::Delete(file_path, true); + } + } +} + } // namespace webkit_database diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h index f3f6041..4375a35 100644 --- a/webkit/database/database_tracker.h +++ b/webkit/database/database_tracker.h @@ -116,6 +116,9 @@ class DatabaseTracker const string16& database_name); bool DeleteOrigin(const string16& origin_identifier); + static void ClearLocalState(const FilePath& profile_path, + const char* url_scheme_to_be_skipped); + private: // Need this here to allow RefCountedThreadSafe to call ~DatabaseTracker(). friend class base::RefCountedThreadSafe<DatabaseTracker>; |