From 22954fcfa5db8fefd08da369a1ac1992ba0d82a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Mon, 20 May 2013 10:20:19 -0700 Subject: [PATCH] Bug 872100 - app.clearBrowserData appears to not clear browser data immediately sr=mounir, r=jduell,ferjm --- dom/apps/src/Webapps.js | 23 +++++++++++++++++-- dom/apps/src/Webapps.jsm | 10 ++++---- .../apps/nsIDOMApplicationRegistry.idl | 9 +++++--- netwerk/ipc/NeckoParent.cpp | 3 ++- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/dom/apps/src/Webapps.js b/dom/apps/src/Webapps.js index 1e9fb96df4fa..7dddf16760d0 100644 --- a/dom/apps/src/Webapps.js +++ b/dom/apps/src/Webapps.js @@ -368,7 +368,8 @@ WebappsApplication.prototype = { "Webapps:CheckForUpdate:Return:OK", "Webapps:CheckForUpdate:Return:KO", "Webapps:Launch:Return:KO", - "Webapps:PackageEvent"]); + "Webapps:PackageEvent", + "Webapps:ClearBrowserData:Return"]); cpmm.sendAsyncMessage("Webapps:RegisterForMessages", ["Webapps:OfflineCache", @@ -464,11 +465,26 @@ WebappsApplication.prototype = { }, clearBrowserData: function() { + let request = this.createRequest(); let browserChild = BrowserElementPromptService.getBrowserElementChildForWindow(this._window); if (browserChild) { - browserChild.messageManager.sendAsyncMessage("Webapps:ClearBrowserData"); + browserChild.messageManager.sendAsyncMessage( + "Webapps:ClearBrowserData", + { manifestURL: this.manifestURL, + oid: this._id, + requestID: this.getRequestId(request) } + ); + } else { + let runnable = { + run: function run() { + Services.DOMRequest.fireError(request, "NO_CLEARABLE_BROWSER"); + } + } + Services.tm.currentThread.dispatch(runnable, + Ci.nsIThread.DISPATCH_NORMAL); } + return request; }, uninit: function() { @@ -590,6 +606,9 @@ WebappsApplication.prototype = { break; } break; + case "Webapps:ClearBrowserData:Return": + Services.DOMRequest.fireSuccess(req, null); + break; } }, diff --git a/dom/apps/src/Webapps.jsm b/dom/apps/src/Webapps.jsm index 3f32a8f15752..fcd30c9ad7d0 100644 --- a/dom/apps/src/Webapps.jsm +++ b/dom/apps/src/Webapps.jsm @@ -3015,7 +3015,7 @@ this.DOMApplicationRegistry = { }, - _notifyCategoryAndObservers: function(subject, topic, data) { + _notifyCategoryAndObservers: function(subject, topic, data, msg) { const serviceMarker = "service,"; // First create observers from the category manager. @@ -3064,6 +3064,8 @@ this.DOMApplicationRegistry = { observer.observe(subject, topic, data); } catch(e) { } }); + // Send back an answer to the child. + ppmm.broadcastAsyncMessage("Webapps:ClearBrowserData:Return", msg); }, registerBrowserElementParentForApp: function(bep, appId) { @@ -3080,18 +3082,18 @@ this.DOMApplicationRegistry = { receiveAppMessage: function(appId, message) { switch (message.name) { case "Webapps:ClearBrowserData": - this._clearPrivateData(appId, true); + this._clearPrivateData(appId, true, message.data); break; } }, - _clearPrivateData: function(appId, browserOnly) { + _clearPrivateData: function(appId, browserOnly, msg) { let subject = { appId: appId, browserOnly: browserOnly, QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams]) }; - this._notifyCategoryAndObservers(subject, "webapps-clear-data", null); + this._notifyCategoryAndObservers(subject, "webapps-clear-data", null, msg); } }; diff --git a/dom/interfaces/apps/nsIDOMApplicationRegistry.idl b/dom/interfaces/apps/nsIDOMApplicationRegistry.idl index ef55fc1d235c..0852c46ab96f 100644 --- a/dom/interfaces/apps/nsIDOMApplicationRegistry.idl +++ b/dom/interfaces/apps/nsIDOMApplicationRegistry.idl @@ -7,7 +7,7 @@ interface nsIDOMDOMRequest; -[scriptable, uuid(d33ee8a0-00e4-4669-b55d-f77fbee1153d)] +[scriptable, uuid(8bdeef38-e9cd-46f8-b8de-ed9e6b4d01ea)] interface mozIDOMApplication : nsISupports { readonly attribute jsval manifest; @@ -85,8 +85,11 @@ interface mozIDOMApplication : nsISupports /* startPoint will be used when several launch_path exists for an app */ nsIDOMDOMRequest launch([optional] in DOMString startPoint); - /* Clear data that has been collected through mozbrowser elements. */ - void clearBrowserData(); + /** + * Clear data that has been collected through mozbrowser elements. + * onsuccess will be called once data is actually cleared. + */ + nsIDOMDOMRequest clearBrowserData(); }; [scriptable, uuid(cf742022-5ba3-11e2-868f-03310341b006)] diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index 0bf17fd51d76..83ddb41db336 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -88,7 +88,8 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized, nsRefPtr tabParent = static_cast(aBrowser); *aAppId = tabParent->OwnOrContainingAppId(); - *aInBrowserElement = tabParent->IsBrowserElement(); + *aInBrowserElement = aSerialized.IsNotNull() ? aSerialized.mIsInBrowserElement + : tabParent->IsBrowserElement(); if (*aAppId == NECKO_UNKNOWN_APP_ID) { return "TabParent reports appId=NECKO_UNKNOWN_APP_ID!";