mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 08:45:46 +00:00
Bug 1579444 - Remove offline storage usage prompt r=johannh
Differential Revision: https://phabricator.services.mozilla.com/D46075 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
e5a686340a
commit
d2f8bed096
@ -14,10 +14,6 @@ const { ActorChild } = ChromeUtils.import(
|
||||
"resource://gre/modules/ActorChild.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
E10SUtils: "resource://gre/modules/E10SUtils.jsm",
|
||||
});
|
||||
|
||||
class OfflineAppsChild extends ActorChild {
|
||||
constructor(dispatcher) {
|
||||
super(dispatcher);
|
||||
@ -26,15 +22,9 @@ class OfflineAppsChild extends ActorChild {
|
||||
this._docIdMap = new Map();
|
||||
|
||||
this._docManifestSet = new Set();
|
||||
|
||||
this._observerAdded = false;
|
||||
}
|
||||
|
||||
registerWindow(aWindow) {
|
||||
if (!this._observerAdded) {
|
||||
this._observerAdded = true;
|
||||
Services.obs.addObserver(this, "offline-cache-update-completed", true);
|
||||
}
|
||||
let manifestURI = this._getManifestURI(aWindow);
|
||||
this._docManifestSet.add(manifestURI.spec);
|
||||
}
|
||||
@ -97,19 +87,6 @@ class OfflineAppsChild extends ActorChild {
|
||||
this._docIdMap.delete(aMessage.data.docId);
|
||||
}
|
||||
}
|
||||
|
||||
observe(aSubject, aTopic, aState) {
|
||||
if (aTopic == "offline-cache-update-completed") {
|
||||
let cacheUpdate = aSubject.QueryInterface(Ci.nsIOfflineCacheUpdate);
|
||||
let uri = cacheUpdate.manifestURI;
|
||||
if (uri && this._docManifestSet.has(uri.spec)) {
|
||||
this.mm.sendAsyncMessage("OfflineApps:CheckUsage", {
|
||||
uri: uri.spec,
|
||||
principal: E10SUtils.serializePrincipal(cacheUpdate.loadingPrincipal),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OfflineAppsChild.prototype.QueryInterface = ChromeUtils.generateQI([
|
||||
|
@ -1979,10 +1979,6 @@ var gBrowserInit = {
|
||||
// until all of its dependencies are handled.
|
||||
Services.appShell.hiddenDOMWindow;
|
||||
|
||||
// We need to set the OfflineApps message listeners up before we
|
||||
// load homepages, which might need them.
|
||||
OfflineApps.init();
|
||||
|
||||
gBrowser.addEventListener(
|
||||
"InsecureLoginFormsStateChange",
|
||||
function() {
|
||||
@ -7933,115 +7929,6 @@ var BrowserOffline = {
|
||||
},
|
||||
};
|
||||
|
||||
var OfflineApps = {
|
||||
warnUsage(browser, principal, host) {
|
||||
if (!browser) {
|
||||
return;
|
||||
}
|
||||
|
||||
let mainAction = {
|
||||
label: gNavigatorBundle.getString("offlineApps.manageUsage"),
|
||||
accessKey: gNavigatorBundle.getString("offlineApps.manageUsageAccessKey"),
|
||||
callback: this.manage,
|
||||
};
|
||||
|
||||
let warnQuotaKB = Services.prefs.getIntPref("offline-apps.quota.warn");
|
||||
// This message shows the quota in MB, and so we divide the quota (in kb) by 1024.
|
||||
let message = gNavigatorBundle.getFormattedString("offlineApps.usage", [
|
||||
host,
|
||||
warnQuotaKB / 1024,
|
||||
]);
|
||||
|
||||
let anchorID = "indexedDB-notification-icon";
|
||||
let options = {
|
||||
persistent: true,
|
||||
hideClose: true,
|
||||
};
|
||||
PopupNotifications.show(
|
||||
browser,
|
||||
"offline-app-usage",
|
||||
message,
|
||||
anchorID,
|
||||
mainAction,
|
||||
null,
|
||||
options
|
||||
);
|
||||
|
||||
// Now that we've warned once, prevent the warning from showing up
|
||||
// again.
|
||||
Services.perms.addFromPrincipal(
|
||||
principal,
|
||||
"offline-app",
|
||||
Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN
|
||||
);
|
||||
},
|
||||
|
||||
// XXX: duplicated in preferences/advanced.js
|
||||
_getOfflineAppUsage(host, groups) {
|
||||
let cacheService = Cc[
|
||||
"@mozilla.org/network/application-cache-service;1"
|
||||
].getService(Ci.nsIApplicationCacheService);
|
||||
if (!groups) {
|
||||
try {
|
||||
groups = cacheService.getGroups();
|
||||
} catch (ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
let usage = 0;
|
||||
for (let group of groups) {
|
||||
let uri = Services.io.newURI(group);
|
||||
if (uri.asciiHost == host) {
|
||||
let cache = cacheService.getActiveCache(group);
|
||||
usage += cache.usage;
|
||||
}
|
||||
}
|
||||
|
||||
return usage;
|
||||
},
|
||||
|
||||
_usedMoreThanWarnQuota(principal, asciiHost) {
|
||||
// if the user has already allowed excessive usage, don't bother checking
|
||||
if (
|
||||
Services.perms.testExactPermissionFromPrincipal(
|
||||
principal,
|
||||
"offline-app"
|
||||
) != Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN
|
||||
) {
|
||||
let usageBytes = this._getOfflineAppUsage(asciiHost);
|
||||
let warnQuotaKB = Services.prefs.getIntPref("offline-apps.quota.warn");
|
||||
// The pref is in kb, the usage we get is in bytes, so multiply the quota
|
||||
// to compare correctly:
|
||||
if (usageBytes >= warnQuotaKB * 1024) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
manage() {
|
||||
openPreferences("panePrivacy");
|
||||
},
|
||||
|
||||
receiveMessage(msg) {
|
||||
if (msg.name !== "OfflineApps:CheckUsage") {
|
||||
return;
|
||||
}
|
||||
let uri = makeURI(msg.data.uri);
|
||||
let principal = E10SUtils.deserializePrincipal(msg.data.principal);
|
||||
if (this._usedMoreThanWarnQuota(principal, uri.asciiHost)) {
|
||||
this.warnUsage(msg.target, principal, uri.host);
|
||||
}
|
||||
},
|
||||
|
||||
init() {
|
||||
let mm = window.messageManager;
|
||||
mm.addMessageListener("OfflineApps:CheckUsage", this);
|
||||
},
|
||||
};
|
||||
|
||||
var IndexedDBPromptHelper = {
|
||||
_permissionsPrompt: "indexedDB-permissions-prompt",
|
||||
_permissionsResponse: "indexedDB-permissions-response",
|
||||
|
@ -302,14 +302,6 @@ tags = clipboard
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_new_http_window_opened_from_file_tab.js]
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_offlineQuotaNotification.js]
|
||||
support-files = offlineQuotaNotification.cacheManifest offlineQuotaNotification.html
|
||||
skip-if = true # Bug 1579444
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_gZipOfflineChild.js]
|
||||
skip-if = true # Bug 1579444
|
||||
support-files = test_offline_gzip.html gZipOfflineChild.cacheManifest gZipOfflineChild.cacheManifest^headers^ gZipOfflineChild.html gZipOfflineChild.html^headers^
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_page_style_menu.js]
|
||||
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
|
||||
[browser_page_style_menu_update.js]
|
||||
|
@ -1,92 +0,0 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/browser/base/content/test/general/test_offline_gzip.html";
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
// Clean up after ourself
|
||||
let uri = Services.io.newURI(URL);
|
||||
let principal = Services.scriptSecurityManager.createContentPrincipal(
|
||||
uri,
|
||||
{}
|
||||
);
|
||||
Services.perms.removeFromPrincipal(principal, "offline-app");
|
||||
});
|
||||
|
||||
//
|
||||
// Handle "message" events which are posted from the iframe upon
|
||||
// offline cache events.
|
||||
//
|
||||
function contentTask() {
|
||||
const { clearInterval, setInterval } = ChromeUtils.import(
|
||||
"resource://gre/modules/Timer.jsm"
|
||||
);
|
||||
|
||||
let resolve;
|
||||
let promise = new Promise(r => {
|
||||
resolve = r;
|
||||
});
|
||||
|
||||
var cacheCount = 0;
|
||||
var intervalID = 0;
|
||||
|
||||
function handleMessageEvents(event) {
|
||||
cacheCount++;
|
||||
switch (cacheCount) {
|
||||
case 1:
|
||||
// This is the initial caching off offline data.
|
||||
is(event.data, "oncache", "Child was successfully cached.");
|
||||
// Reload the frame; this will generate an error message
|
||||
// in the case of bug 501422.
|
||||
event.source.location.reload();
|
||||
// Use setInterval to repeatedly call a function which
|
||||
// checks that one of two things has occurred: either
|
||||
// the offline cache is udpated (which means our iframe
|
||||
// successfully reloaded), or the string "error" appears
|
||||
// in the iframe, as in the case of bug 501422.
|
||||
intervalID = setInterval(function() {
|
||||
// Sometimes document.body may not exist, and trying to access
|
||||
// it will throw an exception, so handle this case.
|
||||
try {
|
||||
var bodyInnerHTML = event.source.document.body.innerHTML;
|
||||
} catch (e) {
|
||||
bodyInnerHTML = "";
|
||||
}
|
||||
if (cacheCount == 2 || bodyInnerHTML.includes("error")) {
|
||||
clearInterval(intervalID);
|
||||
is(cacheCount, 2, "frame not reloaded successfully");
|
||||
if (cacheCount != 2) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
break;
|
||||
case 2:
|
||||
is(event.data, "onupdate", "Child was successfully updated.");
|
||||
clearInterval(intervalID);
|
||||
resolve();
|
||||
break;
|
||||
default:
|
||||
// how'd we get here?
|
||||
ok(false, "cacheCount not 1 or 2");
|
||||
}
|
||||
}
|
||||
|
||||
content.addEventListener("message", handleMessageEvents);
|
||||
return promise;
|
||||
}
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
// Open a new tab.
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
|
||||
registerCleanupFunction(() => gBrowser.removeCurrentTab());
|
||||
|
||||
BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
|
||||
ContentTask.spawn(gBrowser.selectedBrowser, null, contentTask).then(finish);
|
||||
});
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
// Test offline quota warnings - must be run as a mochitest-browser test or
|
||||
// else the test runner gets in the way of notifications due to bug 857897.
|
||||
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/browser/base/content/test/general/offlineQuotaNotification.html";
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
// Clean up after ourself
|
||||
let uri = Services.io.newURI(URL);
|
||||
let principal = Services.scriptSecurityManager.createContentPrincipal(
|
||||
uri,
|
||||
{}
|
||||
);
|
||||
Services.perms.removeFromPrincipal(principal, "offline-app");
|
||||
Services.prefs.clearUserPref("offline-apps.quota.warn");
|
||||
let { OfflineAppCacheHelper } = ChromeUtils.import(
|
||||
"resource://gre/modules/offlineAppCache.jsm"
|
||||
);
|
||||
OfflineAppCacheHelper.clear();
|
||||
});
|
||||
|
||||
// Same as the other one, but for in-content preferences
|
||||
function checkInContentPreferences(win) {
|
||||
let doc = win.document;
|
||||
let sel = doc.getElementById("categories").selectedItems[0].id;
|
||||
is(
|
||||
gBrowser.currentURI.spec,
|
||||
"about:preferences#privacy",
|
||||
"about:preferences loaded"
|
||||
);
|
||||
is(sel, "category-privacy", "Privacy pane was selected");
|
||||
// all good, we are done.
|
||||
win.close();
|
||||
finish();
|
||||
}
|
||||
|
||||
async function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let notificationShown = promiseNotification();
|
||||
|
||||
// Open a new tab.
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL);
|
||||
registerCleanupFunction(() => gBrowser.removeCurrentTab());
|
||||
|
||||
// Wait for the tab to load.
|
||||
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
info("Loaded page, adding onCached handler");
|
||||
// Need a promise to keep track of when we've added our handler.
|
||||
let mm = gBrowser.selectedBrowser.messageManager;
|
||||
let onCachedAttached = BrowserTestUtils.waitForMessage(
|
||||
mm,
|
||||
"Test:OnCachedAttached"
|
||||
);
|
||||
let gotCached = ContentTask.spawn(
|
||||
gBrowser.selectedBrowser,
|
||||
null,
|
||||
async function() {
|
||||
return new Promise(resolve => {
|
||||
content.window.applicationCache.oncached = function() {
|
||||
setTimeout(resolve, 0);
|
||||
};
|
||||
sendAsyncMessage("Test:OnCachedAttached");
|
||||
});
|
||||
}
|
||||
);
|
||||
gotCached.then(async function() {
|
||||
// We got cached - now we should have provoked the quota warning.
|
||||
await notificationShown;
|
||||
let notification = PopupNotifications.getNotification("offline-app-usage");
|
||||
ok(notification, "have offline-app-usage notification");
|
||||
// select the default action - this should cause the preferences
|
||||
// tab to open - which we track via an "Initialized" event.
|
||||
PopupNotifications.panel.firstElementChild.button.click();
|
||||
let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
|
||||
newTabBrowser.addEventListener(
|
||||
"Initialized",
|
||||
function() {
|
||||
executeSoon(function() {
|
||||
checkInContentPreferences(newTabBrowser.contentWindow);
|
||||
});
|
||||
},
|
||||
{ capture: true, once: true }
|
||||
);
|
||||
});
|
||||
onCachedAttached.then(function() {
|
||||
Services.prefs.setIntPref("offline-apps.quota.warn", 1);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseNotification() {
|
||||
return new Promise(resolve => {
|
||||
PopupNotifications.panel.addEventListener(
|
||||
"popupshown",
|
||||
function() {
|
||||
resolve();
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
});
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
CACHE MANIFEST
|
||||
gZipOfflineChild.html
|
@ -1 +0,0 @@
|
||||
Content-Type: text/cache-manifest
|
Binary file not shown.
@ -1,2 +0,0 @@
|
||||
Content-Type: text/html
|
||||
Content-Encoding: gzip
|
@ -1,7 +0,0 @@
|
||||
CACHE MANIFEST
|
||||
# Any copyright is dedicated to the Public Domain.
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
# store a "large" file so an "over quota warning" will be issued - any file
|
||||
# larger than 1kb and in '_BROWSER_FILES' should be right...
|
||||
title_test.svg
|
@ -1,9 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html manifest="offlineQuotaNotification.cacheManifest">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test offline app quota notification</title>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
</head>
|
||||
</html>
|
@ -1,21 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=501422
|
||||
|
||||
When content which was transported over the network with
|
||||
Content-Type: gzip is added to the offline
|
||||
cache, it can be fetched from the cache successfully.
|
||||
-->
|
||||
<head>
|
||||
<title>Test gzipped offline resources</title>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<p id="display">
|
||||
<iframe name="testFrame" src="gZipOfflineChild.html"></iframe>
|
||||
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -437,10 +437,6 @@ offlineApps.allowStoring.accesskey=A
|
||||
offlineApps.dontAllow.label=Don’t Allow
|
||||
offlineApps.dontAllow.accesskey=n
|
||||
|
||||
offlineApps.usage=This website (%S) is now storing more than %SMB of data on your computer for offline use.
|
||||
offlineApps.manageUsage=Show settings
|
||||
offlineApps.manageUsageAccessKey=S
|
||||
|
||||
# Canvas permission prompt
|
||||
# LOCALIZATION NOTE (canvas.siteprompt): %S is hostname
|
||||
canvas.siteprompt=Will you allow %S to use your HTML5 canvas image data? This may be used to uniquely identify your computer.
|
||||
|
@ -80,7 +80,6 @@ pref("image.cache.size", 1048576); // bytes
|
||||
/* offline cache prefs */
|
||||
pref("browser.offline-apps.notify", true);
|
||||
pref("browser.cache.offline.capacity", 5120); // kilobytes
|
||||
pref("offline-apps.quota.warn", 1024); // kilobytes
|
||||
|
||||
// Automatically shrink-to-fit image documents.
|
||||
pref("browser.enable_automatic_image_resizing", true);
|
||||
|
@ -227,10 +227,6 @@ pref("browser.cache.offline.insecure.enable", false);
|
||||
// offline cache capacity in kilobytes
|
||||
pref("browser.cache.offline.capacity", 512000);
|
||||
|
||||
// the user should be warned if offline app disk usage exceeds this amount
|
||||
// (in kilobytes)
|
||||
pref("offline-apps.quota.warn", 51200);
|
||||
|
||||
// Don't show "Open with" option on download dialog if true.
|
||||
pref("browser.download.forbid_open_with", false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user