Index: safari/ext/content.js |
diff --git a/safari/ext/content.js b/safari/ext/content.js |
index 4ae9aab446d12cfdc4da443d5e3e1b4704ee854f..05c615408b15b9d9db11f0d9fa61b455f628b7c0 100644 |
--- a/safari/ext/content.js |
+++ b/safari/ext/content.js |
@@ -135,249 +135,6 @@ |
/* Background page */ |
- var backgroundPageProxy = { |
- objects: [], |
- callbacks: [], |
- |
- send: function(message) |
- { |
- message.category = "proxy"; |
- message.documentId = documentId; |
- |
- return safari.self.tab.canLoad(beforeLoadEvent, message); |
- }, |
- checkResult: function(result) |
- { |
- if (!result.succeed) |
- throw result.error; |
- }, |
- deserializeResult: function(result) |
- { |
- this.checkResult(result); |
- return this.deserialize(result.result); |
- }, |
- serialize: function(obj, memo) |
- { |
- if (typeof obj == "object" && obj != null || typeof obj == "function") |
- { |
- if ("__proxyObjectId" in obj) |
- return {type: "hosted", objectId: obj.__proxyObjectId}; |
- |
- if (typeof obj == "function") |
- { |
- var callbackId; |
- if ("__proxyCallbackId" in obj) |
- callbackId = obj.__proxyCallbackId; |
- else |
- { |
- callbackId = this.callbacks.push(obj) - 1; |
- Object.defineProperty(obj, "__proxyCallbackId", {value: callbackId}); |
- } |
- |
- return {type: "callback", callbackId: callbackId, |
- documentId: documentId}; |
- } |
- |
- if (obj.constructor != Date && obj.constructor != RegExp) |
- { |
- if (!memo) |
- memo = {specs: [], objects: []}; |
- |
- var idx = memo.objects.indexOf(obj); |
- if (idx != -1) |
- return memo.specs[idx]; |
- |
- var spec = {}; |
- memo.specs.push(spec); |
- memo.objects.push(obj); |
- |
- if (obj.constructor == Array) |
- { |
- spec.type = "array"; |
- spec.items = []; |
- |
- for (var i = 0; i < obj.length; i++) |
- spec.items.push(this.serialize(obj[i], memo)); |
- } |
- else |
- { |
- spec.type = "object"; |
- spec.properties = {}; |
- |
- for (var k in obj) |
- spec.properties[k] = this.serialize(obj[k], memo); |
- } |
- |
- return spec; |
- } |
- } |
- |
- return {type: "value", value: obj}; |
- }, |
- deserializeSequence: function(specs, array, memo) |
- { |
- if (!array) |
- array = []; |
- |
- if (!memo) |
- memo = {specs: [], arrays: []}; |
- |
- for (var i = 0; i < specs.length; i++) |
- array.push(this.deserialize(specs[i], memo)); |
- |
- return array; |
- }, |
- deserialize: function(spec, memo) |
- { |
- switch (spec.type) |
- { |
- case "value": |
- return spec.value; |
- case "object": |
- return this.getObject(spec.objectId); |
- case "array": |
- if (!memo) |
- memo = {specs: [], arrays: []}; |
- |
- var idx = memo.specs.indexOf(spec); |
- if (idx != -1) |
- return memo.arrays[idx]; |
- |
- var array = []; |
- memo.specs.push(spec); |
- memo.arrays.push(array); |
- |
- return this.deserializeSequence(spec.items, array, memo); |
- } |
- }, |
- getProperty: function(objectId, property) |
- { |
- return this.deserializeResult( |
- this.send( |
- { |
- type: "getProperty", |
- objectId: objectId, |
- property: property |
- }) |
- ); |
- }, |
- createProperty: function(property, enumerable) |
- { |
- var proxy = this; |
- return { |
- get: function() |
- { |
- return proxy.getProperty(this.__proxyObjectId, property); |
- }, |
- set: function(value) |
- { |
- proxy.checkResult( |
- proxy.send( |
- { |
- type: "setProperty", |
- objectId: this.__proxyObjectId, |
- property: property, |
- value: proxy.serialize(value) |
- }) |
- ); |
- }, |
- enumerable: enumerable, |
- configurable: true |
- }; |
- }, |
- createFunction: function(objectId) |
- { |
- var proxy = this; |
- return function() |
- { |
- return proxy.deserializeResult( |
- proxy.send( |
- { |
- type: "callFunction", |
- functionId: objectId, |
- contextId: this.__proxyObjectId, |
- args: Array.prototype.map.call( |
- arguments, |
- proxy.serialize.bind(proxy) |
- ) |
- }) |
- ); |
- }; |
- }, |
- handleCallback: function(message) |
- { |
- this.callbacks[message.callbackId].apply( |
- this.getObject(message.contextId), |
- this.deserializeSequence(message.args) |
- ); |
- }, |
- getObject: function(objectId) |
- { |
- var objectInfo = this.send({ |
- type: "inspectObject", |
- objectId: objectId |
- }); |
- |
- var obj = this.objects[objectId]; |
- if (obj) |
- Object.getOwnPropertyNames(obj).forEach(function(prop) { delete obj[prop]; }); |
- else |
- { |
- if (objectInfo.isFunction) |
- obj = this.createFunction(objectId); |
- else |
- obj = {}; |
- |
- this.objects[objectId] = obj; |
- Object.defineProperty(obj, "__proxyObjectId", {value: objectId}); |
- } |
- |
- var excluded = []; |
- var included = []; |
- if ("prototypeOf" in objectInfo) |
- { |
- var prototype = window[objectInfo.prototypeOf].prototype; |
- |
- excluded = Object.getOwnPropertyNames(prototype); |
- included = ["constructor"]; |
- |
- obj.__proto__ = prototype; |
- } |
- else |
- { |
- if (objectInfo.isFunction) |
- { |
- excluded = Object.getOwnPropertyNames(function() {}); |
- included = ["prototype"]; |
- } |
- |
- if ("prototypeId" in objectInfo) |
- obj.__proto__ = this.getObject(objectInfo.prototypeId); |
- else |
- obj.__proto__ = null; |
- } |
- |
- for (var property in objectInfo.properties) |
- { |
- if (excluded.indexOf(property) == -1 || included.indexOf(property) != -1) |
- { |
- var desc = Object.getOwnPropertyDescriptor(obj, property); |
- |
- if (!desc || desc.configurable) |
- { |
- Object.defineProperty(obj, property, this.createProperty( |
- property, objectInfo.properties[property].enumerable |
- )); |
- } |
- else if (desc.writable) |
- obj[property] = this.getProperty(objectId, property); |
- } |
- } |
- |
- return obj; |
- } |
- }; |
- |
ext.backgroundPage = { |
sendMessage: function(message, responseCallback) |
{ |
@@ -394,10 +151,6 @@ |
payload: message |
} |
); |
- }, |
- getWindow: function() |
- { |
- return backgroundPageProxy.getObject(0); |
} |
}; |
@@ -425,9 +178,6 @@ |
case "response": |
messageProxy.handleResponse(event.message); |
break; |
- case "proxyCallback": |
- backgroundPageProxy.handleCallback(event.message); |
- break; |
} |
} |
}); |