Commit 44b646ab authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

renderjs: remove addition of top url in not root Iframe Gadget

Altering base url in the iframe gadget resulted in loading resources not from
the gadget iframe url but from the root gadget url. This is a critical issue
when the iframe gadget comes from a different domain
parent 0b69ca97
...@@ -1034,9 +1034,6 @@ ...@@ -1034,9 +1034,6 @@
last_acquisition_gadget = new RenderJSGadget(); last_acquisition_gadget = new RenderJSGadget();
last_acquisition_gadget.__acquired_method_dict = { last_acquisition_gadget.__acquired_method_dict = {
getTopURL: function () {
return url;
},
reportServiceError: function (param_list) { reportServiceError: function (param_list) {
letsCrash(param_list[0]); letsCrash(param_list[0]);
} }
...@@ -1148,30 +1145,19 @@ ...@@ -1148,30 +1145,19 @@
}); });
return; return;
} }
// Get Top URL connection_ready = true;
return tmp_constructor.prototype.__aq_parent('getTopURL', []) notifyReady();
.then(function (topURL) { //the channel is ok
var base = document.createElement('base'); //so bind calls to renderJS method on the instance
base.href = topURL; embedded_channel.bind("methodCall", function (trans, v) {
base.target = "_top"; root_gadget[v[0]].apply(root_gadget, v[1])
document.head.appendChild(base); .then(function (g) {
connection_ready = true; trans.complete(g);
notifyReady(); }).fail(function (e) {
//the channel is ok trans.error(e.toString());
//so bind calls to renderJS method on the instance
embedded_channel.bind("methodCall", function (trans, v) {
root_gadget[v[0]].apply(root_gadget, v[1])
.then(function (g) {
trans.complete(g);
}).fail(function (e) {
trans.error(e.toString());
});
trans.delayReturn(true);
}); });
}) trans.delayReturn(true);
.fail(function (error) { });
throw error;
});
} }
}); });
......
...@@ -12,14 +12,6 @@ ...@@ -12,14 +12,6 @@
.declareService(function () { .declareService(function () {
service_started = true; service_started = true;
}) })
.declareMethod('getBaseHref', function () {
return document.querySelector('base')
.getAttribute('href');
})
.declareMethod('getBaseTarget', function () {
return document.querySelector('base')
.getAttribute('target');
})
.declareMethod('wasReadyCalled', function () { .declareMethod('wasReadyCalled', function () {
return ready_called; return ready_called;
}) })
......
...@@ -10,14 +10,6 @@ ...@@ -10,14 +10,6 @@
.declareService(function () { .declareService(function () {
service_started = true; service_started = true;
}) })
.declareMethod('getBaseHref', function () {
return document.querySelector('base')
.getAttribute('href');
})
.declareMethod('getBaseTarget', function () {
return document.querySelector('base')
.getAttribute('target');
})
.declareMethod('wasReadyCalled', function () { .declareMethod('wasReadyCalled', function () {
return ready_called; return ready_called;
}) })
......
...@@ -9,24 +9,14 @@ ...@@ -9,24 +9,14 @@
g.props.element = element; g.props.element = element;
}); });
}) })
.declareAcquiredMethod('getTopURL', 'getTopURL')
.declareAcquiredMethod('willFail', 'willFail') .declareAcquiredMethod('willFail', 'willFail')
.declareService(function () { .declareService(function () {
var context = this; var context = this;
return RSVP.all([ return RSVP.all([
context.checkTopUrl(),
context.checkAcquisitionError(), context.checkAcquisitionError(),
context.checkKlass() context.checkKlass()
]); ]);
}) })
.declareMethod('checkTopUrl', function () {
var g = this;
return g.getTopURL()
.push(function (top_url) {
g.props.element.querySelector('.getTopUrl')
.innerHTML = top_url;
});
})
.declareMethod('checkAcquisitionError', function () { .declareMethod('checkAcquisitionError', function () {
var g = this; var g = this;
return g.willFail() return g.willFail()
......
...@@ -3177,8 +3177,7 @@ ...@@ -3177,8 +3177,7 @@
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
html_url = 'https://example.org/files/qunittest/test123456.html', html_url = 'https://example.org/files/qunittest/test123456.html',
html_url2 = renderJS.getAbsoluteURL('./embedded.html', html_url2 = renderJS.getAbsoluteURL('./embedded.html',
window.location.href), window.location.href);
topURL = "http://example.org/topGadget";
this.server.respondWith("GET", html_url, [200, { this.server.respondWith("GET", html_url, [200, {
"Content-Type": "text/html" "Content-Type": "text/html"
...@@ -3192,10 +3191,6 @@ ...@@ -3192,10 +3191,6 @@
throw new renderJS.AcquisitionError("Can not handle " + method_name); throw new renderJS.AcquisitionError("Can not handle " + method_name);
}; };
gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
document.getElementById("qunit-fixture").textContent = ""; document.getElementById("qunit-fixture").textContent = "";
stop(); stop();
...@@ -3316,17 +3311,12 @@ ...@@ -3316,17 +3311,12 @@
test('Can take a scope options', function () { test('Can take a scope options', function () {
// Subclass RenderJSGadget to not pollute its namespace // Subclass RenderJSGadget to not pollute its namespace
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
url = "./embedded.html", url = "./embedded.html";
topURL = "http://example.org/topGadget";
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
document.getElementById("qunit-fixture").textContent = ""; document.getElementById("qunit-fixture").textContent = "";
gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
gadget.declareGadget(url, { gadget.declareGadget(url, {
sandbox: 'iframe', sandbox: 'iframe',
...@@ -3358,17 +3348,12 @@ ...@@ -3358,17 +3348,12 @@
port: parsed.port, port: parsed.port,
path: parsed.path}).toString(), path: parsed.path}).toString(),
gadget_path = "./embedded.html", gadget_path = "./embedded.html",
absolute_path = parent_path + "embedded.html", absolute_path = parent_path + "embedded.html";
topURL = "http://example.org/topGadget";
document.getElementById("qunit-fixture").textContent = ""; document.getElementById("qunit-fixture").textContent = "";
parent_gadget.__sub_gadget_dict = {}; parent_gadget.__sub_gadget_dict = {};
parent_gadget.__path = parent_path; parent_gadget.__path = parent_path;
parent_gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
parent_gadget.declareGadget(gadget_path, { parent_gadget.declareGadget(gadget_path, {
sandbox: 'iframe', sandbox: 'iframe',
...@@ -3377,8 +3362,6 @@ ...@@ -3377,8 +3362,6 @@
.then(function (new_gadget) { .then(function (new_gadget) {
equal(new_gadget.__path, absolute_path); equal(new_gadget.__path, absolute_path);
equal(Object.keys(new_gadget.__acquired_method_dict).length, 1); equal(Object.keys(new_gadget.__acquired_method_dict).length, 1);
equal(typeof new_gadget.__acquired_method_dict.getTopURL,
'function');
ok(new_gadget instanceof RenderJSIframeGadget); ok(new_gadget instanceof RenderJSIframeGadget);
equal( equal(
new_gadget.__element.innerHTML, new_gadget.__element.innerHTML,
...@@ -3394,15 +3377,11 @@ ...@@ -3394,15 +3377,11 @@
test('Initialize sub_gadget_dict private property', function () { test('Initialize sub_gadget_dict private property', function () {
// Check that declare gadget returns the gadget // Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
url = "./embedded.html", url = "./embedded.html";
topURL = "http://example.org/topGadget";
document.getElementById("qunit-fixture").textContent = ""; document.getElementById("qunit-fixture").textContent = "";
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
gadget.declareGadget(url, { gadget.declareGadget(url, {
...@@ -3422,8 +3401,7 @@ ...@@ -3422,8 +3401,7 @@
// Check that declare gadget returns the gadget // Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
acquire_called = false, acquire_called = false,
url = "./embedded.html", url = "./embedded.html";
topURL = "http://example.org/topGadget";
gadget.__aq_parent = function (method_name, argument_list) { gadget.__aq_parent = function (method_name, argument_list) {
acquire_called = true; acquire_called = true;
...@@ -3440,9 +3418,6 @@ ...@@ -3440,9 +3418,6 @@
}; };
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
gadget.declareGadget(url, { gadget.declareGadget(url, {
...@@ -3557,18 +3532,6 @@ ...@@ -3557,18 +3532,6 @@
"acquireMethodRequestedWithAcquisitionError", "acquireMethodRequestedWithAcquisitionError",
error error
); );
})
.push(function () {
return new_gadget.getBaseHref();
})
.push(function (href) {
equal(href, topURL);
})
.push(function () {
return new_gadget.getBaseTarget();
})
.push(function (target) {
equal(target, "_top");
}); });
}) })
.fail(function (error) { .fail(function (error) {
...@@ -3583,8 +3546,7 @@ ...@@ -3583,8 +3546,7 @@
// Check that declare gadget returns the gadget // Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
acquire_called = false, acquire_called = false,
url = "./embedded.html", url = "./embedded.html";
topURL = "http://example.org/topGadget";
function readyMessageDelay(e) { function readyMessageDelay(e) {
var now, var now,
...@@ -3617,9 +3579,6 @@ ...@@ -3617,9 +3579,6 @@
}; };
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
gadget.declareGadget(url, { gadget.declareGadget(url, {
...@@ -3734,18 +3693,6 @@ ...@@ -3734,18 +3693,6 @@
"acquireMethodRequestedWithAcquisitionError", "acquireMethodRequestedWithAcquisitionError",
error error
); );
})
.push(function () {
return new_gadget.getBaseHref();
})
.push(function (href) {
equal(href, topURL);
})
.push(function () {
return new_gadget.getBaseTarget();
})
.push(function (target) {
equal(target, "_top");
}); });
}) })
.fail(function (error) { .fail(function (error) {
...@@ -3761,8 +3708,7 @@ ...@@ -3761,8 +3708,7 @@
// Check that declare gadget returns the gadget // Check that declare gadget returns the gadget
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
acquire_called = false, acquire_called = false,
url = "./embedded_heavy.html", url = "./embedded_heavy.html";
topURL = "http://example.org/topGadget";
gadget.__aq_parent = function (method_name, argument_list) { gadget.__aq_parent = function (method_name, argument_list) {
acquire_called = true; acquire_called = true;
...@@ -3779,9 +3725,6 @@ ...@@ -3779,9 +3725,6 @@
}; };
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
gadget.declareGadget(url, { gadget.declareGadget(url, {
...@@ -3896,18 +3839,6 @@ ...@@ -3896,18 +3839,6 @@
"acquireMethodRequestedWithAcquisitionError", "acquireMethodRequestedWithAcquisitionError",
error error
); );
})
.push(function () {
return new_gadget.getBaseHref();
})
.push(function (href) {
equal(href, topURL);
})
.push(function () {
return new_gadget.getBaseTarget();
})
.push(function (target) {
equal(target, "_top");
}); });
}) })
.fail(function (error) { .fail(function (error) {
...@@ -3923,11 +3854,6 @@ ...@@ -3923,11 +3854,6 @@
var gadget = new RenderJSGadget(), var gadget = new RenderJSGadget(),
url = "./embedded_fail.html"; url = "./embedded_fail.html";
gadget.__acquired_method_dict = {
getTopURL: function () {
return "http://example.org/topGadget";
}
};
stop(); stop();
gadget.declareGadget(url, { gadget.declareGadget(url, {
sandbox: 'iframe', sandbox: 'iframe',
...@@ -3950,7 +3876,6 @@ ...@@ -3950,7 +3876,6 @@
test('dataurl provide an iframed gadget as callback parameter', function () { test('dataurl provide an iframed gadget as callback parameter', function () {
// Check that declare gadget returns the gadget // Check that declare gadget returns the gadget
var parent_gadget = new RenderJSGadget(), var parent_gadget = new RenderJSGadget(),
topURL = "https://example.org/topGadget",
parsed = URI.parse(window.location.href), parsed = URI.parse(window.location.href),
parent_path = URI.build({protocol: parsed.protocol, parent_path = URI.build({protocol: parsed.protocol,
hostname: parsed.hostname, hostname: parsed.hostname,
...@@ -3986,10 +3911,6 @@ ...@@ -3986,10 +3911,6 @@
parent_gadget.__sub_gadget_dict = {}; parent_gadget.__sub_gadget_dict = {};
parent_gadget.__path = parent_path; parent_gadget.__path = parent_path;
parent_gadget.__acquired_method_dict = {
getTopURL: function () {return topURL; }
};
stop(); stop();
return new RSVP.Queue() return new RSVP.Queue()
.then(function () { .then(function () {
...@@ -4113,7 +4034,6 @@ ...@@ -4113,7 +4034,6 @@
test('Check that the root gadget is cleanly implemented', function () { test('Check that the root gadget is cleanly implemented', function () {
var parsed = URI.parse(window.location.href), var parsed = URI.parse(window.location.href),
getTopURLCalled = false,
parent_path = URI.build({protocol: parsed.protocol, parent_path = URI.build({protocol: parsed.protocol,
hostname: parsed.hostname, hostname: parsed.hostname,
port: parsed.port, port: parsed.port,
...@@ -4130,16 +4050,6 @@ ...@@ -4130,16 +4050,6 @@
root_gadget_path_without_hash = window.location.href; root_gadget_path_without_hash = window.location.href;
} }
root_gadget_klass
.declareAcquiredMethod('getTopURL', 'getTopURL')
.allowPublicAcquisition('getTopURL', function () {
getTopURLCalled = true;
this.getTopURL().then(function (topURL) {
equal(topURL, this.__path);
});
return this.getTopURL();
});
stop(); stop();
root_gadget_defer.promise root_gadget_defer.promise
.then(function (root_gadget) { .then(function (root_gadget) {
...@@ -4147,7 +4057,6 @@ ...@@ -4147,7 +4057,6 @@
equal(root_gadget.__path, equal(root_gadget.__path,
root_gadget_path_without_hash); root_gadget_path_without_hash);
equal(typeof root_gadget.__acquired_method_dict, 'object'); equal(typeof root_gadget.__acquired_method_dict, 'object');
equal(Object.keys(root_gadget.__acquired_method_dict).length, 1);
equal(root_gadget.__title, document.title); equal(root_gadget.__title, document.title);
deepEqual(root_gadget.__interface_list, []); deepEqual(root_gadget.__interface_list, []);
deepEqual(root_gadget.__required_css_list, deepEqual(root_gadget.__required_css_list,
...@@ -4199,25 +4108,11 @@ ...@@ -4199,25 +4108,11 @@
deepEqual(root_gadget.__sub_gadget_dict, {}); deepEqual(root_gadget.__sub_gadget_dict, {});
deepEqual(root_gadget_klass.__service_list, []); deepEqual(root_gadget_klass.__service_list, []);
return new RSVP.Queue() return new RSVP.Queue()
.push(function () {
return root_gadget.getTopURL().then(function (topURL) {
equal(topURL, root_gadget.__path);
});
})
.push(function () { .push(function () {
return root_gadget.declareGadget("./embedded.html", { return root_gadget.declareGadget("./embedded.html", {
sandbox: 'iframe', sandbox: 'iframe',
element: document.querySelector('#qunit-fixture') element: document.querySelector('#qunit-fixture')
}) })
.then(function (new_gadget) {
return new_gadget.__aq_parent('getTopURL', []);
})
.then(function (topURL) {
equal(topURL, root_gadget.__path);
})
.then(function () {
ok(getTopURLCalled);
})
.fail(function (e) { .fail(function (e) {
ok(false, e); ok(false, e);
}); });
...@@ -4254,12 +4149,9 @@ ...@@ -4254,12 +4149,9 @@
return RSVP.delay(900) return RSVP.delay(900)
.then(function () { .then(function () {
var iframe = document.getElementById('renderjsIframe'), var iframe = document.getElementById('renderjsIframe'),
url_div = iframe.contentWindow.document.querySelector('.getTopUrl'),
acquisition_div = iframe.contentWindow. acquisition_div = iframe.contentWindow.
document.querySelector('.acquisitionError'), document.querySelector('.acquisitionError'),
klass_div = iframe.contentWindow.document.querySelector('.klass'); klass_div = iframe.contentWindow.document.querySelector('.klass');
equal(url_div.innerHTML,
new URL('not_declared_gadget.html', window.location).href);
equal(acquisition_div.innerHTML, equal(acquisition_div.innerHTML,
"AcquisitionError: No gadget provides willFail"); "AcquisitionError: No gadget provides willFail");
equal(klass_div.innerHTML, equal(klass_div.innerHTML,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment