From f6ccacf550e6b39b9dc1fa8a5cb4ddd58647479f Mon Sep 17 00:00:00 2001 From: Deathamns Date: Sat, 14 Mar 2015 19:51:49 +0100 Subject: [PATCH] Firefox,Safari: vAPI.localStorage --- platform/firefox/vapi-common.js | 41 ++++++++++++++++++++++----------- platform/safari/vapi-common.js | 13 ++++------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index 30cac6036..28b25d6d9 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -29,6 +29,13 @@ 'use strict'; +/******************************************************************************/ + +const {Services} = Components.utils.import( + 'resource://gre/modules/Services.jsm', + null +); + self.vAPI = self.vAPI || {}; /******************************************************************************/ @@ -58,9 +65,8 @@ vAPI.download = function(details) { /******************************************************************************/ vAPI.insertHTML = (function() { - const {classes: Cc, interfaces: Ci} = Components; - const parser = Cc['@mozilla.org/parserutils;1'].getService(Ci.nsIParserUtils); - const io = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService); + const parser = Components.classes['@mozilla.org/parserutils;1'] + .getService(Components.interfaces.nsIParserUtils); return function(node, html) { while ( node.firstChild ) { @@ -71,7 +77,7 @@ vAPI.insertHTML = (function() { html, parser.SanitizerAllowStyle, false, - io.newURI(document.baseURI, null, null), + Services.io.newURI(document.baseURI, null, null), document.documentElement )); }; @@ -86,9 +92,9 @@ vAPI.getURL = function(path) { /******************************************************************************/ vAPI.i18n = (function() { - var stringBundle = Components.classes['@mozilla.org/intl/stringbundle;1'] - .getService(Components.interfaces.nsIStringBundleService) - .createBundle('chrome://' + location.host + '/locale/messages.properties'); + var stringBundle = Services.strings.createBundle( + 'chrome://' + location.host + '/locale/messages.properties' + ); return function(s) { try { @@ -114,12 +120,21 @@ vAPI.closePopup = function() { // This storage is optional, but it is nice to have, for a more polished user // experience. -vAPI.localStorage = { - key: function(){}, - getItem: function(){}, - setItem: function(){}, - removeItem: function(){} -}; +Object.defineProperty(vAPI, 'localStorage', { + get: function() { + if ( this._localStorage ) { + return this._localStorage; + } + + this._localStorage = Services.domStorageManager.getLocalStorageForPrincipal( + Services.scriptSecurityManager.getCodebasePrincipal( + Services.io.newURI('http://ublock.raymondhill.net/', null, null) + ), + '' + ); + return this._localStorage; + } +}); /******************************************************************************/ diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 25d09773d..8dde1c596 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -91,10 +91,10 @@ vAPI.getURL = function(path) { // First language is the default vAPI.i18nData = [ - 'en', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el','es', 'et', 'fa', 'fi', + 'en', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'es', 'et', 'fa', 'fi', 'fil', 'fr', 'he', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'ko', 'lt', 'lv', - 'mr', 'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sl', 'sq', 'sr', - 'sv', 'te', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW' + 'mr', 'nb', 'nl', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sl', 'sq', 'sr', + 'sv', 'te', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW' ]; vAPI.i18n = navigator.language; @@ -135,11 +135,6 @@ vAPI.closePopup = function() { // This storage is optional, but it is nice to have, for a more polished user // experience. -vAPI.localStorage = { - key: function(){}, - getItem: function(){}, - setItem: function(){}, - removeItem: function(){} -}; +vAPI.localStorage = window.localStorage; })();