Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: safari/ext/content.js

Issue 5670052883857408: Fixed properties defined on prototype in Safari background page proxy (Closed)
Patch Set: Adressed comments Created Nov. 29, 2013, 10:29 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/content.js
===================================================================
--- a/safari/ext/content.js
+++ b/safari/ext/content.js
@@ -21,15 +21,17 @@
/* Background page proxy */
+
+ var beforeLoadEvent = document.createEvent("Event");
+ beforeLoadEvent.initEvent("beforeload");
+
var proxy = {
objects: [],
callbacks: [],
send: function(message)
{
- var evt = document.createEvent("Event");
- evt.initEvent("beforeload");
- return safari.self.tab.canLoad(evt, {type: "proxy", payload: message});
+ return safari.self.tab.canLoad(beforeLoadEvent, {type: "proxy", payload: message});
},
checkResult: function(result)
{
@@ -43,7 +45,7 @@
},
serialize: function(obj, memo)
{
- var objectId = this.objects.indexOf(obj);
+ var objectId = this.getObjectId(obj);
if (objectId != -1)
return {type: "hosted", objectId: objectId};
@@ -55,15 +57,19 @@
{
callbackId = this.callbacks.push(obj) - 1;
- safari.self.addEventListener("message", function(event)
+ if (callbackId == 0)
Wladimir Palant 2014/01/15 16:21:01 This is non-obvious and needs a short explanation
{
- if (event.name == "proxyCallback")
- if (event.message.callbackId == callbackId)
- obj.apply(
- this.getObject(event.message.contextId),
- this.deserializeSequence(event.message.args)
- );
- }.bind(this));
+ safari.self.addEventListener("message", function(event)
+ {
+ if (event.name == "proxyCallback")
+ {
+ this.callbacks[event.message.callbackId].apply(
+ this.getObject(event.message.contextId),
+ this.deserializeSequence(event.message.args)
+ );
+ }
+ }.bind(this));
+ }
}
return {type: "callback", callbackId: callbackId};
@@ -201,7 +207,8 @@
);
};
},
- getObject: function(objectId) {
+ getObject: function(objectId)
+ {
var objectInfo = this.send({
type: "inspectObject",
objectId: objectId
@@ -233,7 +240,10 @@
else
{
if (objectInfo.isFunction)
+ {
ignored = Object.getOwnPropertyNames(function() {});
+ ignored.splice(ignored.indexOf("prototype"), 1);
+ }
else
ignored = [];
@@ -244,13 +254,19 @@
}
for (var property in objectInfo.properties)
- if (ignored.indexOf(property) == -1)
+ {
+ if (ignored.indexOf(property) != -1)
+ continue;
+
+ if (!Object.hasOwnProperty(obj, property) || Object.getOwnPropertyDescriptor(obj, property).configurable)
+ {
Object.defineProperty(obj, property, this.createProperty(
property, objectInfo.properties[property].enumerable
));
-
- if (objectInfo.isFunction)
- obj.prototype = this.getProperty(objectId, "prototype");
+ }
+ else
+ obj[property] = this.getProperty(objectId, property);
+ }
return obj;
}
@@ -263,24 +279,24 @@
{
var type;
- switch(event.target.nodeName)
+ switch(event.target.localName)
{
- case "FRAME":
- case "IFRAME":
+ case "frame":
+ case "iframe":
type = "frame";
break;
- case "IMG":
+ case "img":
type = "image";
break;
- case "OBJECT":
- case "EMBED":
+ case "object":
+ case "embed":
type = "object";
break;
- case "SCRIPT":
+ case "script":
type = "script";
break;
- case "LINK":
- if (/(^|\s)stylesheet($|\s)/i.test(event.target.rel))
+ case "link":
+ if (/\bstylesheet\b/i.test(event.target.rel))
{
type = "stylesheet";
break;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld