forked from mozilla/shumway
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements local storage for SharedObject.
- Loading branch information
1 parent
b00eb4b
commit b383502
Showing
7 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2015 Mozilla Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
var EXPORTED_SYMBOLS = ['SpecialStorageUtils']; | ||
|
||
Components.utils.import('resource://gre/modules/Services.jsm'); | ||
Components.utils.import('resource://gre/modules/Services.jsm'); | ||
|
||
var SpecialStorageUtils = { | ||
createWrappedSpecialStorage: function (sandbox, swfUrl, privateBrowsing) { | ||
// Creating internal localStorage object based on url and privateBrowsing setting. | ||
var uri = Services.io.newURI(swfUrl, null, null); | ||
var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"] | ||
.getService(Components.interfaces.nsIScriptSecurityManager) | ||
.getNoAppCodebasePrincipal(uri); | ||
var dsm = Components.classes["@mozilla.org/dom/localStorage-manager;1"] | ||
.getService(Components.interfaces.nsIDOMStorageManager); | ||
var storage = dsm.createStorage(null, principal, privateBrowsing); | ||
|
||
// We will return object created in the sandbox/content, with some exposed | ||
// properties/methods, so we can send data between wrapped object and | ||
// and sandbox/content. | ||
var wrapper = new sandbox.Object(); | ||
var waived = Components.utils.waiveXrays(wrapper); | ||
Object.defineProperties(waived, { | ||
getItem: { | ||
value: function (key) { | ||
return storage.getItem(key); | ||
} | ||
}, | ||
setItem: { | ||
value: function (key, value) { | ||
return storage.setItem(key, value); | ||
} | ||
}, | ||
removeItem: { | ||
value: function (key) { | ||
return storage.removeItem(key); | ||
} | ||
} | ||
}); | ||
return wrapper; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters