Commit 0d938856 authored by dhnishi's avatar dhnishi Committed by Commit bot

Add a button to clear local storage for a given origin to Website Settings dialog.

Add functionality for button to stop origins on the Website Settings dialog.

BUG=372607

Review URL: https://codereview.chromium.org/493383004

Cr-Commit-Position: refs/heads/master@{#291578}
parent c1b04763
...@@ -7983,6 +7983,10 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -7983,6 +7983,10 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_WEBSITE_SETTINGS_STORAGE_USED" desc="The status text for how much local storage a website origin is using."> <message name="IDS_WEBSITE_SETTINGS_STORAGE_USED" desc="The status text for how much local storage a website origin is using.">
<ph name="USAGE">$1<ex>2.0 KB</ex></ph> stored data <ph name="USAGE">$1<ex>2.0 KB</ex></ph> stored data
</message> </message>
<message name="IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON" desc="The 'Clear' button in the Website Settings single site view dialog.">
Clear
</message>
<!-- Automatic updates --> <!-- Automatic updates -->
<if expr="is_macosx"> <if expr="is_macosx">
...@@ -12995,7 +12999,7 @@ Some features may be unavailable. Please check that the profile exists and you ...@@ -12995,7 +12999,7 @@ Some features may be unavailable. Please check that the profile exists and you
</message> </message>
<message name="IDS_DISALLOW_AUTOFILL_SYNC_CREDENTIAL_FOR_REAUTH" desc="The text for the choice to not allow autofilling for reauth pages in about:flags"> <message name="IDS_DISALLOW_AUTOFILL_SYNC_CREDENTIAL_FOR_REAUTH" desc="The text for the choice to not allow autofilling for reauth pages in about:flags">
Disallow for reauth Disallow for reauth
</message> </message>
<!-- Update Recommended dialog --> <!-- Update Recommended dialog -->
<if expr="not chromeos"> <if expr="not chromeos">
......
...@@ -64,8 +64,15 @@ ...@@ -64,8 +64,15 @@
-webkit-margin-start: 8px; -webkit-margin-start: 8px;
} }
.website-property { .website-property-area {
-webkit-margin-after: 22px; -webkit-margin-after: 22px;
align-items: center;
display: flex;
justify-content: space-between;
}
.website-property-button {
-webkit-margin-after: 9em;
} }
#website-title { #website-title {
......
...@@ -29,6 +29,10 @@ cr.define('options.WebsiteSettings', function() { ...@@ -29,6 +29,10 @@ cr.define('options.WebsiteSettings', function() {
initializePage: function() { initializePage: function() {
Page.prototype.initializePage.call(this); Page.prototype.initializePage.call(this);
$('website-settings-storage-delete-button').onclick = function(event) {
chrome.send('deleteLocalStorage');
};
$('websiteSettingsEditorCancelButton').onclick = $('websiteSettingsEditorCancelButton').onclick =
PageManager.closeOverlay.bind(PageManager); PageManager.closeOverlay.bind(PageManager);
...@@ -55,13 +59,14 @@ cr.define('options.WebsiteSettings', function() { ...@@ -55,13 +59,14 @@ cr.define('options.WebsiteSettings', function() {
/** /**
* Populates and displays the page with given origin information. * Populates and displays the page with given origin information.
* @param {string} local_storage A string describing the local storage use. * @param {string} localStorage A string describing the local storage use.
* @param {Object} permissions A dictionary of permissions to their * @param {Object} permissions A dictionary of permissions to their
* available and current settings, and if it is editable. * available and current settings, and if it is editable.
* @param {boolean} showPage If the page should raised.
* @private * @private
*/ */
populateOrigin_: function(local_storage, permissions) { populateOrigin_: function(localStorage, permissions, showPage) {
$('local-storage-title').textContent = local_storage; $('local-storage-title').textContent = localStorage;
for (var key in permissions) { for (var key in permissions) {
var selector = $(key + '-select-option'); var selector = $(key + '-select-option');
...@@ -77,7 +82,8 @@ cr.define('options.WebsiteSettings', function() { ...@@ -77,7 +82,8 @@ cr.define('options.WebsiteSettings', function() {
selector.originalValue = permissions[key].setting; selector.originalValue = permissions[key].setting;
selector.disabled = !permissions[key].editable; selector.disabled = !permissions[key].editable;
} }
PageManager.showPageByName('websiteEdit', false); if (showPage)
PageManager.showPageByName('websiteEdit', false);
}, },
updatePermissions: function() { updatePermissions: function() {
...@@ -91,9 +97,11 @@ cr.define('options.WebsiteSettings', function() { ...@@ -91,9 +97,11 @@ cr.define('options.WebsiteSettings', function() {
}, },
}; };
WebsiteSettingsEditor.populateOrigin = function(local_storage, permissions) { WebsiteSettingsEditor.populateOrigin = function(localStorage, permissions,
WebsiteSettingsEditor.getInstance().populateOrigin_(local_storage, showPage) {
permissions); WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage,
permissions,
showPage);
}; };
// Export // Export
......
...@@ -4,7 +4,11 @@ ...@@ -4,7 +4,11 @@
<div class="content-area"> <div class="content-area">
<div class="website-properties"> <div class="website-properties">
<h3 id="website-title" class="title favicon-cell weaktrl"></h3> <h3 id="website-title" class="title favicon-cell weaktrl"></h3>
<div id="local-storage-title" class="website-property"></div> <div class="website-property-area">
<div id="local-storage-title" class="website-property"></div>
<button id="website-settings-storage-delete-button"
class="website-permission-button" i18n-content="websitesButtonClear">
</div>
</div> </div>
<div class="website-column-headers"> <div class="website-column-headers">
<div class="website-header-controls"> <div class="website-header-controls">
......
...@@ -4,10 +4,20 @@ ...@@ -4,10 +4,20 @@
#include "chrome/browser/ui/webui/options/website_settings_handler.h" #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/content_settings_utils.h"
#include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_iterator.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 "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 "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h" #include "ui/base/l10n/time_format.h"
...@@ -53,6 +63,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( ...@@ -53,6 +63,7 @@ void WebsiteSettingsHandler::GetLocalizedValues(
IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION}, IDS_WEBSITE_SETTINGS_MEDIASTREAM_DESCRIPTION},
{"websitesNotificationsDescription", {"websitesNotificationsDescription",
IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION},
{"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON},
}; };
RegisterStrings(localized_strings, resources, arraysize(resources)); RegisterStrings(localized_strings, resources, arraysize(resources));
...@@ -96,6 +107,16 @@ void WebsiteSettingsHandler::RegisterMessages() { ...@@ -96,6 +107,16 @@ void WebsiteSettingsHandler::RegisterMessages() {
"maybeShowEditPage", "maybeShowEditPage",
base::Bind(&WebsiteSettingsHandler::HandleMaybeShowEditPage, base::Bind(&WebsiteSettingsHandler::HandleMaybeShowEditPage,
base::Unretained(this))); 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. // content_settings::Observer implementation.
...@@ -164,7 +185,8 @@ void WebsiteSettingsHandler::HandleMaybeShowEditPage( ...@@ -164,7 +185,8 @@ void WebsiteSettingsHandler::HandleMaybeShowEditPage(
void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list< void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list<
BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) { BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) {
local_storage_list_ = storage; local_storage_list_ = storage;
UpdateLocalStorage(); Update();
GetInfoForOrigin(last_site_, false);
} }
void WebsiteSettingsHandler::Update() { void WebsiteSettingsHandler::Update() {
...@@ -256,7 +278,7 @@ void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) { ...@@ -256,7 +278,7 @@ void WebsiteSettingsHandler::HandleGetOriginInfo(const base::ListValue* args) {
if (!origin.is_valid()) if (!origin.is_valid())
return; return;
GetInfoForOrigin(origin); GetInfoForOrigin(origin, true);
} }
void WebsiteSettingsHandler::HandleSetOriginPermission( void WebsiteSettingsHandler::HandleSetOriginPermission(
...@@ -324,7 +346,19 @@ void WebsiteSettingsHandler::HandleSetOriginPermission( ...@@ -324,7 +346,19 @@ void WebsiteSettingsHandler::HandleSetOriginPermission(
info); 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()); Profile* profile = Profile::FromWebUI(web_ui());
HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
...@@ -396,8 +430,10 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url) { ...@@ -396,8 +430,10 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url) {
base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16(
IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage)));
web_ui()->CallJavascriptFunction( web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin",
"WebsiteSettingsEditor.populateOrigin", *storage_used, *permissions); *storage_used,
*permissions,
base::FundamentalValue(show_page));
} }
void WebsiteSettingsHandler::UpdateLocalStorage() { void WebsiteSettingsHandler::UpdateLocalStorage() {
...@@ -421,4 +457,52 @@ void WebsiteSettingsHandler::UpdateLocalStorage() { ...@@ -421,4 +457,52 @@ void WebsiteSettingsHandler::UpdateLocalStorage() {
local_storage_map); 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.
if (model->IsTabDiscarded(idx) || (model->active_index() == idx))
continue;
// Don't discard tabs that belong to other profiles or other origins.
if (web_contents->GetLastCommittedURL().GetOrigin() != site_url ||
profile !=
Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
continue;
}
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 } // namespace options
...@@ -66,6 +66,13 @@ class WebsiteSettingsHandler : public content_settings::Observer, ...@@ -66,6 +66,13 @@ class WebsiteSettingsHandler : public content_settings::Observer,
// |args| is the URL. // |args| is the URL.
void HandleMaybeShowEditPage(const base::ListValue* args); void HandleMaybeShowEditPage(const base::ListValue* args);
// Deletes the local storage and repopulates the page.
void HandleDeleteLocalStorage(const base::ListValue* args);
// Closes all tabs and app windows which have the same origin as the selected
// page.
void HandleStopOrigin(const base::ListValue* args);
// Callback method to be invoked when fetching the data is complete. // Callback method to be invoked when fetching the data is complete.
void OnLocalStorageFetched(const LocalStorageList& storage); void OnLocalStorageFetched(const LocalStorageList& storage);
...@@ -77,9 +84,16 @@ class WebsiteSettingsHandler : public content_settings::Observer, ...@@ -77,9 +84,16 @@ class WebsiteSettingsHandler : public content_settings::Observer,
// and update the page. // and update the page.
void UpdateLocalStorage(); void UpdateLocalStorage();
// Kill all tabs and app windows which have the same origin as |site_url|.
void StopOrigin(const GURL& site_url);
// Delete all of the local storage for the |site_url|.
void DeleteLocalStorage(const GURL& site_url);
// Populates the single site edit view with the permissions and local storage // Populates the single site edit view with the permissions and local storage
// usage for a given |site_url|. // usage for a given |site_url|. If |show_page| is true, it raises a new
void GetInfoForOrigin(const GURL& site_url); // single site edit view.
void GetInfoForOrigin(const GURL& site_url, bool show_page);
// Updates the page with the last settings used. // Updates the page with the last settings used.
void Update(); void Update();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment