mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Backed out changeset 2767ff221c92 (bug 871445)
This commit is contained in:
parent
b5521266d2
commit
0df0b6ee1a
@ -284,7 +284,6 @@ this.DOMApplicationRegistry = {
|
||||
// Create or Update the DataStore for this app
|
||||
this._readManifests([{ id: aId }], (function(aResult) {
|
||||
this.updateDataStore(this.webapps[aId].localId,
|
||||
this.webapps[aId].origin,
|
||||
this.webapps[aId].manifestURL,
|
||||
aResult[0].manifest);
|
||||
}).bind(this));
|
||||
@ -531,17 +530,12 @@ this.DOMApplicationRegistry = {
|
||||
}
|
||||
this.updateOfflineCacheForApp(id);
|
||||
this.updatePermissionsForApp(id);
|
||||
this.updateDataStoreForApp(id);
|
||||
}
|
||||
// Need to update the persisted list of apps since
|
||||
// installPreinstalledApp() removes the ones failing to install.
|
||||
this._saveApps();
|
||||
}
|
||||
|
||||
// DataStores must be initialized at startup.
|
||||
for (let id in this.webapps) {
|
||||
this.updateDataStoreForApp(id);
|
||||
}
|
||||
|
||||
this.registerAppsHandlers(runUpdate);
|
||||
}).bind(this);
|
||||
|
||||
@ -558,15 +552,14 @@ this.DOMApplicationRegistry = {
|
||||
}).bind(this));
|
||||
},
|
||||
|
||||
updateDataStore: function(aId, aOrigin, aManifestURL, aManifest) {
|
||||
updateDataStore: function(aId, aManifestURL, aManifest) {
|
||||
if ('datastores-owned' in aManifest) {
|
||||
for (let name in aManifest['datastores-owned']) {
|
||||
let readonly = "access" in aManifest['datastores-owned'][name]
|
||||
? aManifest['datastores-owned'][name].access == 'readonly'
|
||||
: false;
|
||||
|
||||
dataStoreService.installDataStore(aId, name, aOrigin, aManifestURL,
|
||||
readonly);
|
||||
dataStoreService.installDataStore(aId, name, aManifestURL, readonly);
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,8 +569,9 @@ this.DOMApplicationRegistry = {
|
||||
!aManifest['datastores-access'][name].readonly
|
||||
? false : true;
|
||||
|
||||
dataStoreService.installAccessDataStore(aId, name, aOrigin,
|
||||
aManifestURL, readonly);
|
||||
// The first release is always in readonly mode.
|
||||
dataStoreService.installAccessDataStore(aId, name, aManifestURL,
|
||||
/* readonly */ true);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1440,8 +1434,7 @@ this.DOMApplicationRegistry = {
|
||||
manifestURL: app.manifestURL },
|
||||
true);
|
||||
}
|
||||
this.updateDataStore(this.webapps[id].localId, app.origin,
|
||||
app.manifestURL, aData);
|
||||
this.updateDataStore(this.webapps[id].localId, app.manifestURL, aData);
|
||||
this.broadcastMessage("Webapps:PackageEvent",
|
||||
{ type: "applied",
|
||||
manifestURL: app.manifestURL,
|
||||
@ -1647,8 +1640,7 @@ this.DOMApplicationRegistry = {
|
||||
}, true);
|
||||
}
|
||||
|
||||
this.updateDataStore(this.webapps[id].localId, app.origin,
|
||||
app.manifestURL, app.manifest);
|
||||
this.updateDataStore(this.webapps[id].localId, app.manifestURL, app.manifest);
|
||||
|
||||
app.name = manifest.name;
|
||||
app.csp = manifest.csp || "";
|
||||
@ -2150,8 +2142,8 @@ this.DOMApplicationRegistry = {
|
||||
true);
|
||||
}
|
||||
|
||||
this.updateDataStore(this.webapps[aId].localId, appObject.origin,
|
||||
appObject.manifestURL, aManifest);
|
||||
this.updateDataStore(this.webapps[aId].localId, appObject.manifestURL,
|
||||
aManifest);
|
||||
|
||||
debug("About to fire Webapps:PackageEvent 'installed'");
|
||||
this.broadcastMessage("Webapps:PackageEvent",
|
||||
@ -2256,8 +2248,8 @@ this.DOMApplicationRegistry = {
|
||||
}).bind(this));
|
||||
}
|
||||
|
||||
this.updateDataStore(this.webapps[id].localId, this.webapps[id].origin,
|
||||
this.webapps[id].manifestURL, jsonManifest);
|
||||
this.updateDataStore(this.webapps[id].localId, this.webapps[id].manifestURL,
|
||||
jsonManifest);
|
||||
}
|
||||
|
||||
["installState", "downloadAvailable",
|
||||
|
@ -103,7 +103,7 @@ this.DataStore.prototype = {
|
||||
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||
if (wId == self._innerWindowID) {
|
||||
cpmm.removeMessageListener("DataStore:Changed:Return:OK", self);
|
||||
self._db.close();
|
||||
self._db.delete();
|
||||
}
|
||||
}, "inner-window-destroyed", false);
|
||||
|
||||
@ -278,18 +278,26 @@ this.DataStore.prototype = {
|
||||
retrieveRevisionId: function(aSuccessCb) {
|
||||
let self = this;
|
||||
this._db.revisionTxn(
|
||||
'readonly',
|
||||
'readwrite',
|
||||
function(aTxn, aRevisionStore) {
|
||||
debug("RetrieveRevisionId transaction success");
|
||||
|
||||
let request = aRevisionStore.openCursor(null, 'prev');
|
||||
request.onsuccess = function(aEvent) {
|
||||
let cursor = aEvent.target.result;
|
||||
if (cursor) {
|
||||
self._revisionId = cursor.value.revisionId;
|
||||
if (!cursor) {
|
||||
// If the revision doesn't exist, let's create the first one.
|
||||
self.addRevision(aRevisionStore, 0, REVISION_VOID,
|
||||
function(aRevisionId) {
|
||||
self._revisionId = aRevisionId;
|
||||
aSuccessCb();
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
aSuccessCb(self._revisionId);
|
||||
self._revisionId = cursor.value.revisionId;
|
||||
aSuccessCb();
|
||||
};
|
||||
}
|
||||
);
|
||||
@ -467,7 +475,7 @@ this.DataStore.prototype = {
|
||||
removedIds: {}
|
||||
};
|
||||
|
||||
let request = aStore.mozGetAll(IDBKeyRange.lowerBound(aInternalRevisionId, true));
|
||||
let request = aStore.mozGetAll(self._window.IDBKeyRange.lowerBound(aInternalRevisionId, true));
|
||||
request.onsuccess = function(aEvent) {
|
||||
for (let i = 0; i < aEvent.target.result.length; ++i) {
|
||||
let data = aEvent.target.result[i];
|
||||
|
@ -12,9 +12,6 @@ function debug(s) {
|
||||
//dump('DEBUG DataStoreChangeNotifier: ' + s + '\n');
|
||||
}
|
||||
|
||||
// DataStoreServiceInternal should not be converted into a lazy getter as it
|
||||
// runs code during initialization.
|
||||
Cu.import('resource://gre/modules/DataStoreServiceInternal.jsm');
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
|
@ -39,8 +39,8 @@ DataStoreDB.prototype = {
|
||||
store.createIndex(DATASTOREDB_REVISION_INDEX, 'revisionId', { unique: true });
|
||||
},
|
||||
|
||||
init: function(aOwner, aName) {
|
||||
let dbName = aName + '|' + aOwner;
|
||||
init: function(aOrigin, aName) {
|
||||
let dbName = aOrigin + '_' + aName;
|
||||
this.initDBHelper(dbName, DATASTOREDB_VERSION,
|
||||
[DATASTOREDB_OBJECTSTORE_NAME, DATASTOREDB_REVISION]);
|
||||
},
|
||||
|
@ -17,7 +17,6 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
Cu.import('resource://gre/modules/DataStore.jsm');
|
||||
Cu.import("resource://gre/modules/DataStoreDB.jsm");
|
||||
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
||||
@ -28,54 +27,37 @@ XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
||||
"@mozilla.org/parentprocessmessagemanager;1",
|
||||
"nsIMessageBroadcaster");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "permissionManager",
|
||||
"@mozilla.org/permissionmanager;1",
|
||||
"nsIPermissionManager");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "secMan",
|
||||
"@mozilla.org/scriptsecuritymanager;1",
|
||||
"nsIScriptSecurityManager");
|
||||
|
||||
/* DataStoreService */
|
||||
|
||||
const DATASTORESERVICE_CID = Components.ID('{d193d0e2-c677-4a7b-bb0a-19155b470f2e}');
|
||||
const REVISION_VOID = "void";
|
||||
|
||||
function DataStoreService() {
|
||||
debug('DataStoreService Constructor');
|
||||
|
||||
this.inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
||||
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
|
||||
if (this.inParent) {
|
||||
let obs = Services.obs;
|
||||
if (!obs) {
|
||||
debug("DataStore Error: observer-service is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
obs.addObserver(this, 'webapps-clear-data', false);
|
||||
let obs = Services.obs;
|
||||
if (!obs) {
|
||||
debug("DataStore Error: observer-service is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
let self = this;
|
||||
cpmm.addMessageListener("datastore-first-revision-created",
|
||||
function(aMsg) { self.receiveMessage(aMsg); });
|
||||
obs.addObserver(this, 'webapps-clear-data', false);
|
||||
|
||||
let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
||||
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
if (inParent) {
|
||||
ppmm.addMessageListener("DataStore:Get", this);
|
||||
}
|
||||
}
|
||||
|
||||
DataStoreService.prototype = {
|
||||
inParent: false,
|
||||
|
||||
// Hash of DataStores
|
||||
stores: {},
|
||||
accessStores: {},
|
||||
pendingRequests: {},
|
||||
|
||||
installDataStore: function(aAppId, aName, aOrigin, aOwner, aReadOnly) {
|
||||
installDataStore: function(aAppId, aName, aOwner, aReadOnly) {
|
||||
debug('installDataStore - appId: ' + aAppId + ', aName: ' +
|
||||
aName + ', aOrigin: ' + aOrigin + ', aOwner:' + aOwner +
|
||||
', aReadOnly: ' + aReadOnly);
|
||||
|
||||
this.checkIfInParent();
|
||||
aName + ', aOwner:' + aOwner + ', aReadOnly: ' +
|
||||
aReadOnly);
|
||||
|
||||
if (aName in this.stores && aAppId in this.stores[aName]) {
|
||||
debug('This should not happen');
|
||||
@ -86,21 +68,13 @@ DataStoreService.prototype = {
|
||||
this.stores[aName] = {};
|
||||
}
|
||||
|
||||
// A DataStore is enabled when it has a first valid revision.
|
||||
this.stores[aName][aAppId] = { origin: aOrigin, owner: aOwner,
|
||||
readOnly: aReadOnly, enabled: false };
|
||||
|
||||
this.addPermissions(aAppId, aName, aOrigin, aOwner, aReadOnly);
|
||||
|
||||
this.createFirstRevisionId(aAppId, aName, aOwner);
|
||||
this.stores[aName][aAppId] = { owner: aOwner, readOnly: aReadOnly };
|
||||
},
|
||||
|
||||
installAccessDataStore: function(aAppId, aName, aOrigin, aOwner, aReadOnly) {
|
||||
debug('installAccessDataStore - appId: ' + aAppId + ', aName: ' +
|
||||
aName + ', aOrigin: ' + aOrigin + ', aOwner:' + aOwner +
|
||||
', aReadOnly: ' + aReadOnly);
|
||||
|
||||
this.checkIfInParent();
|
||||
installAccessDataStore: function(aAppId, aName, aOwner, aReadOnly) {
|
||||
debug('installDataStore - appId: ' + aAppId + ', aName: ' +
|
||||
aName + ', aOwner:' + aOwner + ', aReadOnly: ' +
|
||||
aReadOnly);
|
||||
|
||||
if (aName in this.accessStores && aAppId in this.accessStores[aName]) {
|
||||
debug('This should not happen');
|
||||
@ -111,231 +85,56 @@ DataStoreService.prototype = {
|
||||
this.accessStores[aName] = {};
|
||||
}
|
||||
|
||||
this.accessStores[aName][aAppId] = { origin: aOrigin, owner: aOwner,
|
||||
readOnly: aReadOnly };
|
||||
this.addAccessPermissions(aAppId, aName, aOrigin, aOwner, aReadOnly);
|
||||
},
|
||||
|
||||
checkIfInParent: function() {
|
||||
if (!this.inParent) {
|
||||
throw "DataStore can execute this operation just in the parent process";
|
||||
}
|
||||
},
|
||||
|
||||
createFirstRevisionId: function(aAppId, aName, aOwner) {
|
||||
debug("createFirstRevisionId database: " + aName);
|
||||
|
||||
let self = this;
|
||||
let db = new DataStoreDB();
|
||||
db.init(aOwner, aName);
|
||||
db.revisionTxn(
|
||||
'readwrite',
|
||||
function(aTxn, aRevisionStore) {
|
||||
debug("createFirstRevisionId - transaction success");
|
||||
|
||||
let request = aRevisionStore.openCursor(null, 'prev');
|
||||
request.onsuccess = function(aEvent) {
|
||||
let cursor = aEvent.target.result;
|
||||
if (!cursor) {
|
||||
// If the revision doesn't exist, let's create the first one.
|
||||
db.addRevision(aRevisionStore, 0, REVISION_VOID, function() {
|
||||
debug("First revision created.");
|
||||
if (aName in self.stores && aAppId in self.stores[aName]) {
|
||||
self.stores[aName][aAppId].enabled = true;
|
||||
ppmm.broadcastAsyncMessage('datastore-first-revision-created',
|
||||
{ name: aName, owner: aOwner });
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
addPermissions: function(aAppId, aName, aOrigin, aOwner, aReadOnly) {
|
||||
// When a new DataStore is installed, the permissions must be set for the
|
||||
// owner app.
|
||||
let permission = "indexedDB-chrome-" + aName + '|' + aOwner;
|
||||
this.resetPermissions(aAppId, aOrigin, aOwner, permission, aReadOnly);
|
||||
|
||||
// For any app that wants to have access to this DataStore we add the
|
||||
// permissions.
|
||||
if (aName in this.accessStores) {
|
||||
for (let appId in this.accessStores[aName]) {
|
||||
// ReadOnly is decided by the owner first.
|
||||
let readOnly = aReadOnly || this.accessStores[aName][appId].readOnly;
|
||||
this.resetPermissions(appId, this.accessStores[aName][appId].origin,
|
||||
this.accessStores[aName][appId].owner,
|
||||
permission, readOnly);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addAccessPermissions: function(aAppId, aName, aOrigin, aOwner, aReadOnly) {
|
||||
// When an app wants to have access to a DataStore, the permissions must be
|
||||
// set.
|
||||
if (!(aName in this.stores)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let appId in this.stores[aName]) {
|
||||
let permission = "indexedDB-chrome-" + aName + '|' + this.stores[aName][appId].owner;
|
||||
// The ReadOnly is decied by the owenr first.
|
||||
let readOnly = this.stores[aName][appId].readOnly || aReadOnly;
|
||||
this.resetPermissions(aAppId, aOrigin, aOwner, permission, readOnly);
|
||||
}
|
||||
},
|
||||
|
||||
resetPermissions: function(aAppId, aOrigin, aOwner, aPermission, aReadOnly) {
|
||||
debug("ResetPermissions - appId: " + aAppId + " - origin: " + aOrigin +
|
||||
" - owner: " + aOwner + " - permissions: " + aPermission +
|
||||
" - readOnly: " + aReadOnly);
|
||||
|
||||
let uri = Services.io.newURI(aOrigin, null, null);
|
||||
let principal = secMan.getAppCodebasePrincipal(uri, aAppId, false);
|
||||
|
||||
let result = permissionManager.testExactPermissionFromPrincipal(principal,
|
||||
aPermission + '-write');
|
||||
|
||||
if (aReadOnly && result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||
debug("Write permission removed");
|
||||
permissionManager.removeFromPrincipal(principal, aPermission + '-write');
|
||||
} else if (!aReadOnly && result != Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||
debug("Write permission added");
|
||||
permissionManager.addFromPrincipal(principal, aPermission + '-write',
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
}
|
||||
|
||||
result = permissionManager.testExactPermissionFromPrincipal(principal,
|
||||
aPermission + '-read');
|
||||
if (result != Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||
debug("Read permission added");
|
||||
permissionManager.addFromPrincipal(principal, aPermission + '-read',
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
}
|
||||
|
||||
result = permissionManager.testExactPermissionFromPrincipal(principal, aPermission);
|
||||
if (result != Ci.nsIPermissionManager.ALLOW_ACTION) {
|
||||
debug("Generic permission added");
|
||||
permissionManager.addFromPrincipal(principal, aPermission,
|
||||
Ci.nsIPermissionManager.ALLOW_ACTION);
|
||||
}
|
||||
this.accessStores[aName][aAppId] = { owner: aOwner, readOnly: aReadOnly };
|
||||
},
|
||||
|
||||
getDataStores: function(aWindow, aName) {
|
||||
debug('getDataStores - aName: ' + aName);
|
||||
|
||||
let self = this;
|
||||
// This method can be called in the child so we need to send a request to
|
||||
// the parent and create DataStore object here.
|
||||
|
||||
return new aWindow.Promise(function(resolve, reject) {
|
||||
// If this request comes from the main process, we have access to the
|
||||
// window, so we can skip the ipc communication.
|
||||
if (self.inParent) {
|
||||
let stores = self.getDataStoresInfo(aName, aWindow.document.nodePrincipal.appId);
|
||||
self.getDataStoreCreate(aWindow, resolve, stores);
|
||||
} else {
|
||||
// This method can be called in the child so we need to send a request
|
||||
// to the parent and create DataStore object here.
|
||||
new DataStoreServiceChild(aWindow, aName, function(aStores) {
|
||||
debug("DataStoreServiceChild callback!");
|
||||
self.getDataStoreCreate(aWindow, resolve, aStores);
|
||||
});
|
||||
}
|
||||
new DataStoreServiceChild(aWindow, aName, resolve);
|
||||
});
|
||||
},
|
||||
|
||||
getDataStoresInfo: function(aName, aAppId) {
|
||||
debug('GetDataStoresInfo');
|
||||
receiveMessage: function(aMessage) {
|
||||
if (aMessage.name != 'DataStore:Get') {
|
||||
return;
|
||||
}
|
||||
|
||||
let msg = aMessage.data;
|
||||
|
||||
// This is a security issue and it will be fixed by Bug 916091
|
||||
let appId = msg.appId;
|
||||
|
||||
let results = [];
|
||||
|
||||
if (aName in this.stores) {
|
||||
if (aAppId in this.stores[aName]) {
|
||||
results.push({ name: aName,
|
||||
owner: this.stores[aName][aAppId].owner,
|
||||
readOnly: false,
|
||||
enabled: this.stores[aName][aAppId].enabled });
|
||||
if (msg.name in this.stores) {
|
||||
if (appId in this.stores[msg.name]) {
|
||||
results.push({ store: this.stores[msg.name][appId],
|
||||
readOnly: false });
|
||||
}
|
||||
|
||||
for (var i in this.stores[aName]) {
|
||||
if (i == aAppId) {
|
||||
for (var i in this.stores[msg.name]) {
|
||||
if (i == appId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let access = this.getDataStoreAccess(aName, aAppId);
|
||||
let access = this.getDataStoreAccess(msg.name, appId);
|
||||
if (!access) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let readOnly = this.stores[aName][i].readOnly || access.readOnly;
|
||||
results.push({ name: aName,
|
||||
owner: this.stores[aName][i].owner,
|
||||
readOnly: readOnly,
|
||||
enabled: this.stores[aName][i].enabled });
|
||||
let readOnly = this.stores[msg.name][i].readOnly || access.readOnly;
|
||||
results.push({ store: this.stores[msg.name][i],
|
||||
readOnly: readOnly });
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
},
|
||||
|
||||
getDataStoreCreate: function(aWindow, aResolve, aStores) {
|
||||
debug("GetDataStoreCreate");
|
||||
|
||||
let results = [];
|
||||
|
||||
if (!aStores.length) {
|
||||
aResolve(results);
|
||||
return;
|
||||
}
|
||||
|
||||
let pendingDataStores = [];
|
||||
|
||||
for (let i = 0; i < aStores.length; ++i) {
|
||||
if (!aStores[i].enabled) {
|
||||
pendingDataStores.push(aStores[i].owner);
|
||||
}
|
||||
}
|
||||
|
||||
if (!pendingDataStores.length) {
|
||||
this.getDataStoreResolve(aWindow, aResolve, aStores);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(aStores[0].name in this.pendingRequests)) {
|
||||
this.pendingRequests[aStores[0].name] = [];
|
||||
}
|
||||
|
||||
this.pendingRequests[aStores[0].name].push({ window: aWindow,
|
||||
resolve: aResolve,
|
||||
stores: aStores,
|
||||
pendingDataStores: pendingDataStores });
|
||||
},
|
||||
|
||||
getDataStoreResolve: function(aWindow, aResolve, aStores) {
|
||||
debug("GetDataStoreResolve");
|
||||
|
||||
let callbackPending = aStores.length;
|
||||
let results = [];
|
||||
|
||||
if (!callbackPending) {
|
||||
aResolve(results);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < aStores.length; ++i) {
|
||||
let obj = new DataStore(aWindow, aStores[i].name,
|
||||
aStores[i].owner, aStores[i].readOnly);
|
||||
let exposedObj = aWindow.DataStore._create(aWindow, obj);
|
||||
results.push(exposedObj);
|
||||
|
||||
obj.retrieveRevisionId(
|
||||
function() {
|
||||
--callbackPending;
|
||||
if (!callbackPending) {
|
||||
aResolve(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
msg.stores = results;
|
||||
aMessage.target.sendAsyncMessage("DataStore:Get:Return", msg);
|
||||
},
|
||||
|
||||
getDataStoreAccess: function(aName, aAppId) {
|
||||
@ -363,7 +162,6 @@ DataStoreService.prototype = {
|
||||
|
||||
for (let key in this.stores) {
|
||||
if (params.appId in this.stores[key]) {
|
||||
this.deleteDatabase(key, this.stores[key][params.appId].owner);
|
||||
delete this.stores[key][params.appId];
|
||||
}
|
||||
|
||||
@ -373,43 +171,6 @@ DataStoreService.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
deleteDatabase: function(aName, aOwner) {
|
||||
debug("delete database: " + aName);
|
||||
|
||||
let db = new DataStoreDB();
|
||||
db.init(aOwner, aName);
|
||||
db.delete();
|
||||
},
|
||||
|
||||
receiveMessage: function(aMsg) {
|
||||
debug("receiveMessage");
|
||||
let data = aMsg.json;
|
||||
|
||||
if (!(data.name in this.pendingRequests)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.pendingRequests[data.name].length;) {
|
||||
let pos = this.pendingRequests[data.name][i].pendingDataStores.indexOf(data.owner);
|
||||
if (pos != -1) {
|
||||
this.pendingRequests[data.name][i].pendingDataStores.splice(pos, 1);
|
||||
if (!this.pendingRequests[data.name][i].pendingDataStores.length) {
|
||||
this.getDataStoreResolve(this.pendingRequests[data.name][i].window,
|
||||
this.pendingRequests[data.name][i].resolve,
|
||||
this.pendingRequests[data.name][i].stores);
|
||||
this.pendingRequests[data.name].splice(i, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
if (!this.pendingRequests[data.name].length) {
|
||||
delete this.pendingRequests[data.name];
|
||||
}
|
||||
},
|
||||
|
||||
classID : DATASTORESERVICE_CID,
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDataStoreService,
|
||||
Ci.nsIObserver]),
|
||||
@ -423,17 +184,18 @@ DataStoreService.prototype = {
|
||||
|
||||
/* DataStoreServiceChild */
|
||||
|
||||
function DataStoreServiceChild(aWindow, aName, aCallback) {
|
||||
function DataStoreServiceChild(aWindow, aName, aResolve) {
|
||||
debug("DataStoreServiceChild created");
|
||||
this.init(aWindow, aName, aCallback);
|
||||
this.init(aWindow, aName, aResolve);
|
||||
}
|
||||
|
||||
DataStoreServiceChild.prototype = {
|
||||
__proto__: DOMRequestIpcHelper.prototype,
|
||||
|
||||
init: function(aWindow, aName, aCallback) {
|
||||
debug("DataStoreServiceChild init");
|
||||
this._callback = aCallback;
|
||||
init: function(aWindow, aName, aResolve) {
|
||||
this._window = aWindow;
|
||||
this._name = aName;
|
||||
this._resolve = aResolve;
|
||||
|
||||
this.initDOMRequestHelper(aWindow, [ "DataStore:Get:Return" ]);
|
||||
|
||||
@ -443,12 +205,35 @@ DataStoreServiceChild.prototype = {
|
||||
},
|
||||
|
||||
receiveMessage: function(aMessage) {
|
||||
debug("DataStoreServiceChild receiveMessage");
|
||||
if (aMessage.name != 'DataStore:Get:Return') {
|
||||
return;
|
||||
}
|
||||
let msg = aMessage.data;
|
||||
let self = this;
|
||||
|
||||
this._callback(aMessage.data.stores);
|
||||
let callbackPending = msg.stores.length;
|
||||
let results = [];
|
||||
|
||||
if (!callbackPending) {
|
||||
this._resolve(results);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < msg.stores.length; ++i) {
|
||||
let obj = new DataStore(this._window, this._name,
|
||||
msg.stores[i].owner, msg.stores[i].readOnly);
|
||||
let exposedObj = this._window.DataStore._create(this._window, obj);
|
||||
results.push(exposedObj);
|
||||
|
||||
obj.retrieveRevisionId(
|
||||
function() {
|
||||
--callbackPending;
|
||||
if (!callbackPending) {
|
||||
self._resolve(results);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,51 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict"
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"];
|
||||
|
||||
function debug(s) {
|
||||
// dump('DEBUG DataStoreServiceInternal: ' + s + '\n');
|
||||
}
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
||||
"@mozilla.org/parentprocessmessagemanager;1",
|
||||
"nsIMessageBroadcaster");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService",
|
||||
"@mozilla.org/datastore-service;1",
|
||||
"nsIDataStoreService");
|
||||
|
||||
this.DataStoreServiceInternal = {
|
||||
init: function() {
|
||||
debug("init");
|
||||
|
||||
let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
|
||||
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
if (inParent) {
|
||||
ppmm.addMessageListener("DataStore:Get", this);
|
||||
}
|
||||
},
|
||||
|
||||
receiveMessage: function(aMessage) {
|
||||
debug("receiveMessage");
|
||||
|
||||
if (aMessage.name != 'DataStore:Get') {
|
||||
return;
|
||||
}
|
||||
|
||||
let msg = aMessage.data;
|
||||
|
||||
// This is a security issue and it will be fixed by Bug 916091
|
||||
msg.stores = dataStoreService.getDataStoresInfo(msg.name, msg.appId);
|
||||
aMessage.target.sendAsyncMessage("DataStore:Get:Return", msg);
|
||||
}
|
||||
}
|
||||
|
||||
DataStoreServiceInternal.init();
|
@ -23,5 +23,4 @@ EXTRA_JS_MODULES += [
|
||||
'DataStore.jsm',
|
||||
'DataStoreChangeNotifier.jsm',
|
||||
'DataStoreDB.jsm',
|
||||
'DataStoreServiceInternal.jsm',
|
||||
]
|
||||
|
@ -7,29 +7,19 @@
|
||||
|
||||
interface nsIDOMWindow;
|
||||
|
||||
[scriptable, uuid(bd02d09c-41ab-47b7-9319-57aa8e5059b0)]
|
||||
[scriptable, uuid(d193d0e2-c677-4a7b-bb0a-19155b470f2e)]
|
||||
interface nsIDataStoreService : nsISupports
|
||||
{
|
||||
void installDataStore(in unsigned long appId,
|
||||
in DOMString name,
|
||||
in DOMString originURL,
|
||||
in DOMString manifestURL,
|
||||
in boolean readOnly);
|
||||
|
||||
void installAccessDataStore(in unsigned long appId,
|
||||
in DOMString name,
|
||||
in DOMString originURL,
|
||||
in DOMString manifestURL,
|
||||
in boolean readOnly);
|
||||
|
||||
nsISupports getDataStores(in nsIDOMWindow window,
|
||||
in DOMString name);
|
||||
|
||||
// This is an array of objects composed by:
|
||||
// - readOnly: boolean
|
||||
// - name: DOMString
|
||||
// - owner: DOMString
|
||||
// - enabled: true/false - true if this dataStore is ready to be used.
|
||||
jsval getDataStoresInfo(in DOMString name,
|
||||
in unsigned long appId);
|
||||
};
|
||||
|
@ -10,9 +10,7 @@
|
||||
<div id="container"></div>
|
||||
<script type="application/javascript;version=1.7">
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
@ -25,8 +23,7 @@
|
||||
{ "type": "embed-apps", "allow": 1, "context": document },
|
||||
{ "type": "webapps-manage", "allow": 1, "context": document }],
|
||||
function() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
|
||||
["dom.promise.enabled", true]]}, function() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true]]}, function() {
|
||||
gGenerator.next(); });
|
||||
});
|
||||
|
||||
@ -49,7 +46,6 @@
|
||||
}, cbError);
|
||||
yield undefined;
|
||||
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||
|
||||
SpecialPowers.autoConfirmAppInstall(continueTest);
|
||||
|
@ -84,7 +84,6 @@
|
||||
},
|
||||
|
||||
function() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||
runTest();
|
||||
},
|
||||
@ -118,10 +117,7 @@
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest();
|
||||
</script>
|
||||
|
@ -84,7 +84,6 @@
|
||||
},
|
||||
|
||||
function() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||
runTest();
|
||||
},
|
||||
@ -118,10 +117,7 @@
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest();
|
||||
</script>
|
||||
|
@ -129,7 +129,6 @@
|
||||
|
||||
// Enabling mozBrowser
|
||||
function() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
|
||||
},
|
||||
|
||||
@ -171,10 +170,7 @@
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest();
|
||||
</script>
|
||||
|
@ -88,7 +88,6 @@
|
||||
},
|
||||
|
||||
function() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||
runTest();
|
||||
},
|
||||
@ -122,10 +121,7 @@
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest();
|
||||
</script>
|
||||
|
@ -30,7 +30,6 @@
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
|
||||
|
||||
SpecialPowers.autoConfirmAppInstall(continueTest);
|
||||
@ -95,13 +94,11 @@
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true],
|
||||
["dom.datastore.enabled", true]]}, runTest);
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.promise.enabled", true]]}, function() {
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true]]}, runTest);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -94,7 +94,6 @@
|
||||
|
||||
// Enabling mozBrowser
|
||||
function() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
|
||||
},
|
||||
|
||||
@ -127,10 +126,7 @@
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
if (SpecialPowers.isMainProcess()) {
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
}
|
||||
|
||||
SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest();
|
||||
</script>
|
||||
|
@ -35,9 +35,5 @@
|
||||
"description": "Mochitests"
|
||||
}
|
||||
},
|
||||
"datastores-access" : {
|
||||
"foo" : { "readonly": false },
|
||||
"bar" : { "readonly": false }
|
||||
},
|
||||
"default_locale": "en-US"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user