Index: chrome/browser/ui/webui/options/website_settings_handler.cc |
diff --git a/chrome/browser/ui/webui/options/website_settings_handler.cc b/chrome/browser/ui/webui/options/website_settings_handler.cc |
index 0a7354e5f12bc0af1ed0cba0747ffdaac308183d..f154a3a6c368e9ffc0771c13cc9e0bfe2ff5aeb0 100644 |
--- a/chrome/browser/ui/webui/options/website_settings_handler.cc |
+++ b/chrome/browser/ui/webui/options/website_settings_handler.cc |
@@ -4,10 +4,19 @@ |
#include "chrome/browser/ui/webui/options/website_settings_handler.h" |
+#include "apps/app_window_registry.h" |
#include "chrome/browser/content_settings/content_settings_utils.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "content/public/browser/dom_storage_context.h" |
+#include "content/public/browser/storage_partition.h" |
+#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_ui.h" |
+#include "extensions/browser/extension_registry.h" |
+#include "extensions/common/constants.h" |
+#include "extensions/common/extension.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/l10n/time_format.h" |
@@ -53,6 +62,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( |
IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, |
{"websitesNotificationsDescription", |
IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, |
+ {"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON}, |
}; |
RegisterStrings(localized_strings, resources, arraysize(resources)); |
@@ -96,6 +106,16 @@ void WebsiteSettingsHandler::RegisterMessages() { |
"maybeShowEditPage", |
base::Bind(&WebsiteSettingsHandler::HandleMaybeShowEditPage, |
base::Unretained(this))); |
+ |
+ web_ui()->RegisterMessageCallback( |
+ "deleteLocalStorage", |
+ base::Bind(&WebsiteSettingsHandler::HandleDeleteLocalStorage, |
+ base::Unretained(this))); |
+ |
+ web_ui()->RegisterMessageCallback( |
+ "stopOrigin", |
+ base::Bind(&WebsiteSettingsHandler::HandleStopOrigin, |
+ base::Unretained(this))); |
} |
// content_settings::Observer implementation. |
@@ -164,7 +184,8 @@ void WebsiteSettingsHandler::HandleMaybeShowEditPage( |
void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list< |
BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) { |
local_storage_list_ = storage; |
- UpdateLocalStorage(); |
+ Update(); |
+ GetInfoForOrigin(last_site_, false); |
} |
void WebsiteSettingsHandler::Update() { |
@@ -256,7 +277,7 @@ void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { |
if (!origin.is_valid()) |
return; |
- GetInfoForOrigin(origin); |
+ GetInfoForOrigin(origin, true); |
} |
void WebsiteSettingsHandler::HandleSetOriginPermission( |
@@ -324,7 +345,19 @@ void WebsiteSettingsHandler::HandleSetOriginPermission( |
info); |
} |
-void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url) { |
+void WebsiteSettingsHandler::HandleDeleteLocalStorage( |
+ const base::ListValue* args) { |
+ DCHECK(!last_site_.is_empty()); |
+ DeleteLocalStorage(last_site_); |
+} |
+ |
+void WebsiteSettingsHandler::HandleStopOrigin(const base::ListValue* args) { |
+ DCHECK(!last_site_.is_empty()); |
+ StopOrigin(last_site_); |
+} |
+ |
+void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, |
+ bool show_page) { |
Profile* profile = Profile::FromWebUI(web_ui()); |
HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); |
@@ -396,8 +429,10 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url) { |
base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( |
IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); |
- web_ui()->CallJavascriptFunction( |
- "WebsiteSettingsEditor.populateOrigin", *storage_used, *permissions); |
+ web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin", |
+ *storage_used, |
+ *permissions, |
+ base::FundamentalValue(show_page)); |
} |
void WebsiteSettingsHandler::UpdateLocalStorage() { |
@@ -421,4 +456,49 @@ void WebsiteSettingsHandler::UpdateLocalStorage() { |
local_storage_map); |
} |
+void WebsiteSettingsHandler::StopOrigin(const GURL& site_url) { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ if (site_url.SchemeIs(extensions::kExtensionScheme)) { |
+ const extensions::Extension* extension = |
+ extensions::ExtensionRegistry::Get(profile) |
+ ->enabled_extensions() |
+ .GetHostedAppByURL(site_url); |
+ if (extension) { |
+ apps::AppWindowRegistry::Get(profile) |
+ ->CloseAllAppWindowsForApp(extension->id()); |
+ } |
+ } |
+ |
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
+ Browser* browser = *it; |
+ TabStripModel* model = browser->tab_strip_model(); |
+ for (int idx = 0; idx < model->count(); idx++) { |
+ content::WebContents* web_contents = model->GetWebContentsAt(idx); |
+ // Can't discard tabs that are already discarded or active or tabs that |
+ // belong to other profiles or other origins. |
+ if (model->IsTabDiscarded(idx) || (model->active_index() == idx) || |
+ web_contents->GetLastCommittedURL().GetOrigin() != site_url || |
+ profile != |
+ Profile::FromBrowserContext(web_contents->GetBrowserContext())) |
+ continue; |
Bernhard Bauer
2014/08/22 21:54:36
I would probably wrap this in braces, what with th
Daniel Nishi
2014/08/22 22:12:47
Split into two checks.
|
+ model->DiscardWebContentsAt(idx); |
+ } |
+ } |
+} |
+ |
+void WebsiteSettingsHandler::DeleteLocalStorage(const GURL& site_url) { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ content::DOMStorageContext* dom_storage_context_ = |
+ content::BrowserContext::GetDefaultStoragePartition(profile) |
+ ->GetDOMStorageContext(); |
+ dom_storage_context_->DeleteLocalStorage(site_url); |
+ |
+ // Load a new BrowsingDataLocalStorageHelper to update. |
+ local_storage_ = new BrowsingDataLocalStorageHelper(profile); |
+ |
+ local_storage_->StartFetching( |
+ base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
} // namespace options |