You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/01/14 02:57:00 UTC
git commit: CB-5025 Don't escape/decode undefined|null values +WP7
Updated Branches:
refs/heads/master af726e211 -> 37e4565a9
CB-5025 Don't escape/decode undefined|null values +WP7
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/37e4565a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/37e4565a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/37e4565a
Branch: refs/heads/master
Commit: 37e4565a9d6edfee847d650a822adfa64bcc743c
Parents: af726e2
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Jan 13 17:55:06 2014 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Jan 13 17:55:06 2014 -0800
----------------------------------------------------------------------
wp7/template/cordovalib/DOMStorageHelper.cs | 34 +++--
wp7/template/cordovalib/DOMStorageProxy.cs | 155 -----------------------
2 files changed, 20 insertions(+), 169 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/37e4565a/wp7/template/cordovalib/DOMStorageHelper.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/DOMStorageHelper.cs b/wp7/template/cordovalib/DOMStorageHelper.cs
index 59389c6..5f16c78 100644
--- a/wp7/template/cordovalib/DOMStorageHelper.cs
+++ b/wp7/template/cordovalib/DOMStorageHelper.cs
@@ -1,15 +1,15 @@
/*
- 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.
+ 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.
*/
using System;
@@ -149,7 +149,14 @@ if (!docDomain || docDomain.length === 0) {
var retVal = null;
if (this.keys.indexOf(key) > -1) {
window.external.Notify('DOMStorage/' + this._type + '/get/' + key);
- retVal = window.unescape(decodeURIComponent(this._result));
+ retVal = this._result;
+ if(retVal) {
+ retVal = window.unescape(decodeURIComponent(retVal));
+ }
+ else {
+ window.external.Notify('DOMStorage/' + this._type + '/remove/' + key);
+ delete this[key];
+ }
this._result = null;
}
return retVal;
@@ -203,8 +210,7 @@ if (!docDomain || docDomain.length === 0) {
Browser.InvokeScript("execScript", new string[] { script });
}
-
-
+
public bool HandleCommand(string commandStr)
{
string[] split = commandStr.Split('/');
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/37e4565a/wp7/template/cordovalib/DOMStorageProxy.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/DOMStorageProxy.cs b/wp7/template/cordovalib/DOMStorageProxy.cs
deleted file mode 100644
index 59ca4e6..0000000
--- a/wp7/template/cordovalib/DOMStorageProxy.cs
+++ /dev/null
@@ -1,155 +0,0 @@
-using Microsoft.Phone.Controls;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace WPCordovaClassLib.CordovaLib
-{
- class DOMStorageProxy
- {
- private WebBrowser webBrowser;
-
- public DOMStorageProxy(ref WebBrowser browser)
- {
- this.webBrowser = browser;
- browser.ScriptNotify += browser_ScriptNotify;
- }
-
- public void InjectScript()
- {
- var script = @"(function(win, doc) {
-var docDomain = null;
-try {
- docDomain = doc.domain;
-} catch (err) {}
-
-if (!docDomain || docDomain.length === 0) {
- var DOMStorage = function(type) {
- if (type == 'sessionStorage') {
- this._type = type;
- }
- Object.defineProperty(this, 'length', {
- configurable: true,
- get: function() {
- return this.getLength();
- }
- });
- };
- DOMStorage.prototype = {
- _type: 'localStorage',
- _result: null,
- keys: null,
- onResult: function(key, valueStr) {
- if (!this.keys) {
- this.keys = [];
- }
- this._result = valueStr;
- },
- onKeysChanged: function(jsonKeys) {
- this.keys = JSON.parse(jsonKeys);
- var key;
- for (var n = 0, len = this.keys.length; n < len; n++) {
- key = this.keys[n];
- if (!this.hasOwnProperty(key)) {
- Object.defineProperty(this, key, {
- configurable: true,
- get: function() {
- return this.getItem(key);
- },
- set: function(val) {
- return this.setItem(key, val);
- }
- });
- }
- }
- },
- initialize: function() {
- window.external.Notify('DOMStorage/' + this._type + '/load/keys');
- },
- getLength: function() {
- if (!this.keys) {
- this.initialize();
- }
- return this.keys.length;
- },
- key: function(n) {
- if (!this.keys) {
- this.initialize();
- }
- if (n >= this.keys.length) {
- return null;
- } else {
- return this.keys[n];
- }
- },
- getItem: function(key) {
- if (!this.keys) {
- this.initialize();
- }
- var retVal = null;
- if (this.keys.indexOf(key) > -1) {
- window.external.Notify('DOMStorage/' + this._type + '/get/' + key);
- retVal = window.unescape(decodeURIComponent(this._result));
- this._result = null;
- }
- return retVal;
- },
- setItem: function(key, value) {
- if (!this.keys) {
- this.initialize();
- }
- window.external.Notify('DOMStorage/' + this._type + '/set/' + key + '/' + encodeURIComponent(window.escape(value)));
- },
- removeItem: function(key) {
- if (!this.keys) {
- this.initialize();
- }
- var index = this.keys.indexOf(key);
- if (index > -1) {
- this.keys.splice(index, 1);
- window.external.Notify('DOMStorage/' + this._type + '/remove/' + key);
- delete this[key];
- }
- },
- clear: function() {
- if (!this.keys) {
- this.initialize();
- }
- for (var n = 0, len = this.keys.length; n < len; n++) {
- delete this[this.keys[n]];
- }
- this.keys = [];
- window.external.Notify('DOMStorage/' + this._type + '/clear/');
- }
- };
- if (typeof window.localStorage === 'undefined') {
- Object.defineProperty(window, 'localStorage', {
- writable: false,
- configurable: false,
- value: new DOMStorage('localStorage')
- });
- window.localStorage.initialize();
- }
- if (typeof window.sessionStorage === 'undefined') {
- Object.defineProperty(window, 'sessionStorage', {
- writable: false,
- configurable: false,
- value: new DOMStorage('sessionStorage')
- });
- window.sessionStorage.initialize();
- }
-}
-})(window, document);";
-
- webBrowser.InvokeScript("execScript", new string[] { script });
-
- }
-
- void browser_ScriptNotify(object sender, NotifyEventArgs e)
- {
-
- }
- }
-}