Skip to content

Commit

Permalink
Bug 758357 - Only show prompt after 50mb of quota was reached. r=sicking
Browse files Browse the repository at this point in the history
  • Loading branch information
benturner committed Jul 5, 2012
1 parent 86c257d commit d602b23
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 81 deletions.
19 changes: 12 additions & 7 deletions browser/base/content/pageinfo/pageInfo.xul
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,23 @@
<label class="permissionLabel" id="permIndexedDBLabel"
value="&permIndexedDB;" control="indexedDBRadioGroup"/>
<hbox role="group" aria-labelledby="permIndexedDBLabel">
<checkbox id="indexedDBDef" command="cmd_indexedDBDef" label="&permAskAlways;"/>
<checkbox id="indexedDBDef" command="cmd_indexedDBDef" label="&permUseDefault;"/>
<spacer flex="1"/>
<vbox pack="center">
<label id="indexedDBStatus" control="indexedDBClear"/>
</vbox>
<button id="indexedDBClear" label="&permClearStorage;"
accesskey="&permClearStorage.accesskey;" onclick="onIndexedDBClear();"/>
<radiogroup id="indexedDBRadioGroup" orient="horizontal">
<radio id="indexedDB#1" command="cmd_indexedDBToggle" label="&permAllow;"/>
<!-- Ask and Allow are purposefully reversed here! -->
<radio id="indexedDB#1" command="cmd_indexedDBToggle" label="&permAskAlways;"/>
<radio id="indexedDB#0" command="cmd_indexedDBToggle" label="&permAllow;"/>
<radio id="indexedDB#2" command="cmd_indexedDBToggle" label="&permBlock;"/>
</radiogroup>
</hbox>
<hbox>
<spacer flex="1"/>
<vbox pack="center">
<label id="indexedDBStatus" control="indexedDBClear" hidden="true"/>
</vbox>
<button id="indexedDBClear" label="&permClearStorage;" hidden="true"
accesskey="&permClearStorage.accesskey;" onclick="onIndexedDBClear();"/>
</hbox>
</vbox>
<vbox class="permission" id="permPluginsRow">
<label class="permissionLabel" id="permPluginsLabel"
Expand Down
9 changes: 3 additions & 6 deletions browser/base/content/pageinfo/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var gPermObj = {
},
indexedDB: function getIndexedDBDefaultPermissions()
{
return BLOCK;
return UNKNOWN;
},
plugins: function getPluginsDefaultPermissions()
{
Expand Down Expand Up @@ -149,9 +149,6 @@ function onCheckboxClick(aPartId)
var checkbox = document.getElementById(aPartId + "Def");
if (checkbox.checked) {
permissionManager.remove(gPermURI.host, aPartId);
if (aPartId == "indexedDB") {
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
}
command.setAttribute("disabled", "true");
var perm = gPermObj[aPartId]();
setRadioState(aPartId, perm);
Expand All @@ -171,7 +168,8 @@ function onRadioClick(aPartId)
var id = radioGroup.selectedItem.id;
var permission = id.split('#')[1];
permissionManager.add(gPermURI, aPartId, permission);
if (aPartId == "indexedDB" && permission == BLOCK) {
if (aPartId == "indexedDB" &&
(permission == ALLOW || permission == BLOCK)) {
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
}
if (aPartId == "fullscreen" && permission == UNKNOWN) {
Expand Down Expand Up @@ -207,7 +205,6 @@ function onIndexedDBClear()

var permissionManager = Components.classes[PERMISSION_CONTRACTID]
.getService(nsIPermissionManager);
permissionManager.remove(gPermURI.host, "indexedDB");
permissionManager.remove(gPermURI.host, "indexedDB-unlimited");
initIndexedDBRow();
}
Expand Down
12 changes: 0 additions & 12 deletions dom/file/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var testGenerator = testSteps();

function runTest()
{
allowIndexedDB();
allowUnlimitedQuota();

SimpleTest.waitForExplicitFinish();
Expand All @@ -27,7 +26,6 @@ function runTest()
function finishTest()
{
resetUnlimitedQuota();
resetIndexedDB();

SimpleTest.executeSoon(function() {
testGenerator.close();
Expand Down Expand Up @@ -90,16 +88,6 @@ function removePermission(type, url)
SpecialPowers.removePermission(type, url);
}

function allowIndexedDB(url)
{
addPermission("indexedDB", true, url);
}

function resetIndexedDB(url)
{
removePermission("indexedDB", url);
}

function allowUnlimitedQuota(url)
{
addPermission("indexedDB-unlimited", true, url);
Expand Down
62 changes: 44 additions & 18 deletions dom/indexedDB/CheckPermissionsHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
#define TOPIC_PERMISSIONS_PROMPT "indexedDB-permissions-prompt"
#define TOPIC_PERMISSIONS_RESPONSE "indexedDB-permissions-response"

// This is a little confusing, but our default behavior (UNKNOWN_ACTION) is to
// allow access without a prompt. If the "indexedDB" permission is set to
// ALLOW_ACTION then we will issue a prompt before allowing access. Otherwise
// (DENY_ACTION) we deny access.
#define PERMISSION_ALLOWED nsIPermissionManager::UNKNOWN_ACTION
#define PERMISSION_DENIED nsIPermissionManager::DENY_ACTION
#define PERMISSION_PROMPT nsIPermissionManager::ALLOW_ACTION

using namespace mozilla;
USING_INDEXEDDB_NAMESPACE
using namespace mozilla::services;
Expand All @@ -43,40 +51,41 @@ GetIndexedDBPermissions(const nsACString& aASCIIOrigin,
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

if (!Preferences::GetBool(PREF_INDEXEDDB_ENABLED)) {
return nsIPermissionManager::DENY_ACTION;
return PERMISSION_DENIED;
}

// No window here means chrome access
// No window here means chrome access.
if (!aWindow) {
return nsIPermissionManager::ALLOW_ACTION;
return PERMISSION_ALLOWED;
}

nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(aWindow));
NS_ENSURE_TRUE(sop, nsIPermissionManager::DENY_ACTION);

if (nsContentUtils::IsSystemPrincipal(sop->GetPrincipal())) {
return nsIPermissionManager::ALLOW_ACTION;
return PERMISSION_ALLOWED;
}

nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
if (loadContext && loadContext->UsePrivateBrowsing()) {
// TODO Support private browsing indexedDB?
return nsIPermissionManager::DENY_ACTION;
NS_WARNING("IndexedDB may not be used while in private browsing mode!");
return PERMISSION_DENIED;
}

nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aASCIIOrigin);
NS_ENSURE_SUCCESS(rv, nsIPermissionManager::DENY_ACTION);
NS_ENSURE_SUCCESS(rv, PERMISSION_DENIED);

nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_TRUE(permissionManager, nsIPermissionManager::DENY_ACTION);
NS_ENSURE_TRUE(permissionManager, PERMISSION_DENIED);

PRUint32 permission;
rv = permissionManager->TestPermission(uri, PERMISSION_INDEXEDDB,
&permission);
NS_ENSURE_SUCCESS(rv, nsIPermissionManager::DENY_ACTION);
NS_ENSURE_SUCCESS(rv, PERMISSION_DENIED);

return permission;
}
Expand All @@ -102,23 +111,22 @@ CheckPermissionsHelper::Run()
// process (if we are in the child process, we have already
// set the permission when the prompt was shown in the parent, as
// we cannot set the permission from the child).
if (permission != nsIPermissionManager::UNKNOWN_ACTION &&
XRE_GetProcessType() == GeckoProcessType_Default) {
if (permission != PERMISSION_PROMPT &&
IndexedDatabaseManager::IsMainProcess()) {
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), mASCIIOrigin);
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_STATE(permissionManager);

rv = permissionManager->Add(uri, PERMISSION_INDEXEDDB, permission,
nsIPermissionManager::EXPIRE_NEVER, 0);
NS_ENSURE_SUCCESS(rv, rv);
}
}
else if (permission == nsIPermissionManager::UNKNOWN_ACTION &&
mPromptAllowed) {
else if (permission == PERMISSION_PROMPT && mPromptAllowed) {
nsCOMPtr<nsIObserverService> obs = GetObserverService();
rv = obs->NotifyObservers(static_cast<nsIRunnable*>(this),
TOPIC_PERMISSIONS_PROMPT, nsnull);
Expand All @@ -133,15 +141,15 @@ CheckPermissionsHelper::Run()
nsCOMPtr<nsIDOMWindow> window;
window.swap(mWindow);

if (permission == nsIPermissionManager::ALLOW_ACTION) {
if (permission == PERMISSION_ALLOWED) {
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
NS_ASSERTION(mgr, "This should never be null!");

return helper->Dispatch(mgr->IOThread());
}

NS_ASSERTION(permission == nsIPermissionManager::UNKNOWN_ACTION ||
permission == nsIPermissionManager::DENY_ACTION,
NS_ASSERTION(permission == PERMISSION_PROMPT ||
permission == PERMISSION_DENIED,
"Unknown permission!");

helper->SetError(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
Expand Down Expand Up @@ -178,9 +186,27 @@ CheckPermissionsHelper::Observe(nsISupports* aSubject,
mHasPrompted = true;

nsresult rv;
mPromptResult = nsDependentString(aData).ToInteger(&rv);
PRUint32 promptResult = nsDependentString(aData).ToInteger(&rv);
NS_ENSURE_SUCCESS(rv, rv);

// Have to convert the permission we got from the user to our weird reversed
// permission type.
switch (promptResult) {
case nsIPermissionManager::ALLOW_ACTION:
mPromptResult = PERMISSION_ALLOWED;
break;
case nsIPermissionManager::DENY_ACTION:
mPromptResult = PERMISSION_DENIED;
break;
case nsIPermissionManager::UNKNOWN_ACTION:
mPromptResult = PERMISSION_PROMPT;
break;

default:
NS_NOTREACHED("Unknown permission type!");
mPromptResult = PERMISSION_DENIED;
}

rv = NS_DispatchToCurrentThread(this);
NS_ENSURE_SUCCESS(rv, rv);

Expand Down
6 changes: 3 additions & 3 deletions dom/indexedDB/test/browser_forgetThisSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function test()
{
waitForExplicitFinish();
// Avoids the prompt
setPermission(testPageURL1, "indexedDB");
setPermission(testPageURL2, "indexedDB");
setPermission(testPageURL1, "indexedDB", "unknown");
setPermission(testPageURL2, "indexedDB", "unknown");
executeSoon(test1);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ function test3()
Components.classes["@mozilla.org/privatebrowsing;1"]
.getService(Components.interfaces.nsIPrivateBrowsingService)
.removeDataFromDomain(domains[1]);
setPermission(testPageURL4, "indexedDB");
setPermission(testPageURL4, "indexedDB", "unknown");
executeSoon(test4);
}

Expand Down
7 changes: 4 additions & 3 deletions dom/indexedDB/test/browser_permissionsPromptAllow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const notificationID = "indexedDB-permissions-prompt";
function test()
{
waitForExplicitFinish();
removePermission(testPageURL, "indexedDB");
// We want a prompt.
setPermission(testPageURL, "indexedDB", "allow");
executeSoon(test1);
}

Expand All @@ -27,7 +28,7 @@ function test1()
"First database creation was successful");
ok(!exception, "No exception");
is(getPermission(testPageURL, "indexedDB"),
Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
Components.interfaces.nsIPermissionManager.UNKNOWN_ACTION,
"Correct permission set");
gBrowser.removeCurrentTab();
executeSoon(test2);
Expand Down Expand Up @@ -63,7 +64,7 @@ function test2()
"First database creation was successful");
ok(!exception, "No exception");
is(getPermission(testPageURL, "indexedDB"),
Components.interfaces.nsIPermissionManager.ALLOW_ACTION,
Components.interfaces.nsIPermissionManager.UNKNOWN_ACTION,
"Correct permission set");
gBrowser.removeCurrentTab();
unregisterAllPopupEventHandlers();
Expand Down
3 changes: 2 additions & 1 deletion dom/indexedDB/test/browser_permissionsPromptDeny.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const notificationID = "indexedDB-permissions-prompt";
function test()
{
waitForExplicitFinish();
removePermission(testPageURL, "indexedDB");
// We want the prompt.
setPermission(testPageURL, "indexedDB", "allow");
executeSoon(test1);
}

Expand Down
2 changes: 0 additions & 2 deletions dom/indexedDB/test/browser_privateBrowsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const notificationID = "indexedDB-permissions-prompt";
function test()
{
waitForExplicitFinish();
// Avoids the actual prompt
setPermission(testPageURL, "indexedDB");
executeSoon(test1);
}

Expand Down
3 changes: 1 addition & 2 deletions dom/indexedDB/test/browser_quotaPromptAllow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function test()
{
waitForExplicitFinish();
requestLongerTimeout(10);
setPermission(testPageURL, "indexedDB");
removePermission(testPageURL, "indexedDB-unlimited");
Services.prefs.setIntPref("dom.indexedDB.warningQuota", 2);
executeSoon(test1);
Expand Down Expand Up @@ -43,7 +42,7 @@ function test1()
"Correct permission set");
gBrowser.removeCurrentTab();
unregisterAllPopupEventHandlers();
executeSoon(test2);
executeSoon(finish);
});
executeSoon(function() { dispatchEvent("indexedDB-done"); });
}
Expand Down
1 change: 0 additions & 1 deletion dom/indexedDB/test/browser_quotaPromptDatabases.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function test()
{
waitForExplicitFinish();
requestLongerTimeout(10);
setPermission(testPageURL, "indexedDB");
removePermission(testPageURL, "indexedDB-unlimited");
Services.prefs.setIntPref("dom.indexedDB.warningQuota", 2);
executeSoon(test1);
Expand Down
1 change: 0 additions & 1 deletion dom/indexedDB/test/browser_quotaPromptDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function test()
{
waitForExplicitFinish();
requestLongerTimeout(10);
setPermission(testPageURL, "indexedDB");
removePermission(testPageURL, "indexedDB-unlimited");
Services.prefs.setIntPref("dom.indexedDB.warningQuota", 2);
executeSoon(test1);
Expand Down
1 change: 0 additions & 1 deletion dom/indexedDB/test/browser_quotaPromptDeny.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function test()
{
waitForExplicitFinish();
requestLongerTimeout(10);
setPermission(testPageURL, "indexedDB");
removePermission(testPageURL, "indexedDB-unlimited");
Services.prefs.setIntPref("dom.indexedDB.warningQuota", 2);
executeSoon(test1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
};

function testSteps() {
window.parent.SpecialPowers.addPermission("indexedDB", true, document);

let request = indexedDB.open(window.location.pathname, 1);
request.onsuccess = unexpectedSuccessHandler;
request.onerror = grabEventAndContinueHandler;
Expand Down
2 changes: 0 additions & 2 deletions dom/indexedDB/test/event_propagation_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@
}

function testSteps() {
window.parent.SpecialPowers.addPermission("indexedDB", true, document);

let request = indexedDB.open(window.location.pathname, 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
Expand Down
2 changes: 0 additions & 2 deletions dom/indexedDB/test/exceptions_in_events_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
};

function testSteps() {
window.parent.SpecialPowers.addPermission("indexedDB", true, document);

// Test 1: Throwing an exception in an upgradeneeded handler should
// abort the versionchange transaction and fire an error at the request.
let request = indexedDB.open(window.location.pathname, 1);
Expand Down
Loading

0 comments on commit d602b23

Please sign in to comment.