Skip to content

Commit

Permalink
#16 TypeError: window.NetExport is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed Jan 8, 2015
1 parent 9a2aa52 commit d096cbc
Showing 1 changed file with 68 additions and 55 deletions.
123 changes: 68 additions & 55 deletions chrome/content/netexport/automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,73 @@ Firebug.NetExport.Automation = extend(Firebug.Module,
Firebug.NetMonitor.NetCacheReader.autoFetch = true;

HttpObserver.register();

// Expose "NetExport variable into all current contexts.
Firebug.connection.eachContext(context => {
this.exposeToContent(context.window);
});
},

exposeToContent: function(win)
{
if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; expose to content");

var token = Firebug.getPref(prefDomain, "secretToken");
if (token == "")
return;

var functions =
{
triggerExport: function()
{
if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; user triggered export");

HttpObserver.onPageLoaded(win);
},

clear: function()
{
var context = TabWatcher.getContextByWindow(win);
if (context)
Firebug.NetMonitor.clear(context);
}
};

var props = {};
var protectedFunctions = {};
var protect = function(f)
{
return function(t)
{
if (t !== token)
{
if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; invalid token");

throw {
name: "Invalid security token",
message: "The provided security token is incorrect"
};
}

var args = Array.prototype.slice.call(arguments, 1);
return f.apply(this, args);
};
};

for (var f in functions)
{
props[f] = "r";
protectedFunctions[f] = protect(functions[f]);
}

if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; helper functions exported to window");

protectedFunctions.__exposedProps__ = props;

This comment has been minimized.

Copy link
@simonlindholm

simonlindholm Jan 8, 2015

Member

FWIW, __exposedProps__ is quite deprecated now, one should rather use something like:

var protectedFunctions = XPCNativeWrapper.unwrap(Cu.createObjectIn(win));
for (var p in functions)
    protectedFunctions[p] = protect(functions[p]);
Cu.makeObjectPropsNormal(protectedFunctions);
win.wrappedJSObject.NetExport = protectedFunctions;

This comment has been minimized.

Copy link
@janodvarko

janodvarko Jan 9, 2015

Author Member

Yep, agree, reported here #17

Honza

win.wrappedJSObject.NetExport = protectedFunctions;
},

deactivate: function()
Expand Down Expand Up @@ -304,61 +371,7 @@ Firebug.NetExport.PageLoadObserver.prototype =

insertHelperFunctions: function(win)
{
var token = Firebug.getPref(prefDomain, "secretToken");
if (token == "")
return;

var functions =
{
triggerExport: function()
{
if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; user triggered export");

HttpObserver.onPageLoaded(win);
},

clear: function()
{
var context = TabWatcher.getContextByWindow(win);
if (context)
Firebug.NetMonitor.clear(context);
}
};

var props = {};
var protectedFunctions = {};
var protect = function(f)
{
return function(t)
{
if (t !== token)
{
if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; invalid token");

throw {
name: "Invalid security token",
message: "The provided security token is incorrect"
};
}

var args = Array.prototype.slice.call(arguments, 1);
return f.apply(this, args);
};
};

for (var f in functions)
{
props[f] = "r";
protectedFunctions[f] = protect(functions[f]);
}

if (FBTrace.DBG_NETEXPORT)
FBTrace.sysout("netexport.Automation; helper functions exported to window");

protectedFunctions.__exposedProps__ = props;
win.wrappedJSObject.NetExport = protectedFunctions;
Firebug.NetExport.Automation.exposeToContent(win);
},

// Wait for all event that must be fired before the window is loaded.
Expand Down

0 comments on commit d096cbc

Please sign in to comment.