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..1dd298734b4d9b1ed4db3afe5a232ab51a4a9a52 100644 |
--- a/chrome/browser/ui/webui/options/website_settings_handler.cc |
+++ b/chrome/browser/ui/webui/options/website_settings_handler.cc |
@@ -4,10 +4,18 @@ |
#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/tab_contents/tab_contents_iterator.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 +61,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 +105,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 +183,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 +276,7 @@ void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { |
if (!origin.is_valid()) |
return; |
- GetInfoForOrigin(origin); |
+ GetInfoForOrigin(origin, true); |
} |
void WebsiteSettingsHandler::HandleSetOriginPermission( |
@@ -324,7 +344,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 +428,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 +455,41 @@ 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 (TabContentsIterator it; !it.done(); it.Next()) { |
+ if (it->GetLastCommittedURL().GetOrigin() == site_url && |
+ profile == Profile::FromBrowserContext(it->GetBrowserContext())) { |
Bernhard Bauer
2014/08/22 20:42:39
How does this interact with incognito?
Daniel Nishi
2014/08/22 21:45:25
Incognito isn't affected. I'm pretty sure it is be
Bernhard Bauer
2014/08/22 21:54:36
Yeah, I was more wondering whether that's somethin
Daniel Nishi
2014/08/22 22:12:47
I did a little experiment -- you can see OTR conte
Bernhard Bauer
2014/08/22 22:41:27
Yeah, I think so. We could probably mark them up d
|
+ it->Close(); |
Bernhard Bauer
2014/08/22 20:42:39
This closes the tabs completely, right? Is that th
Daniel Nishi
2014/08/22 21:45:25
Ooh. I didn't know about the Discard functionality
|
+ } |
+ } |
+} |
+ |
+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_ = NULL; |
Bernhard Bauer
2014/08/22 20:42:39
Is this assignment really necessary?
Daniel Nishi
2014/08/22 21:45:25
Hmm. I think I misunderstood a comment in the scop
|
+ local_storage_ = new BrowsingDataLocalStorageHelper(profile); |
+ |
+ local_storage_->StartFetching( |
+ base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
} // namespace options |