From a35f15e9cefdb0bc6f61a0d61562e329827082e4 Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Thu, 17 Nov 2011 09:03:45 -0800 Subject: [PATCH] moved back to fragment-identifier based communication for the relay-frame name, should address #590 and #596 --- resources/static/dialog/resources/channel.js | 14 ++++++++------ resources/static/include.js | 7 ++++--- .../test/qunit/resources/channel_unit_test.js | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/resources/static/dialog/resources/channel.js b/resources/static/dialog/resources/channel.js index 5e51e0e21..d3fc6b59b 100644 --- a/resources/static/dialog/resources/channel.js +++ b/resources/static/dialog/resources/channel.js @@ -55,19 +55,21 @@ var win = window, nav = navigator, onCompleteCallback, - WINDOW_NAME_REGEXP= "^_mozid_signin_(.*)"; + _relayWindow = null; function getRelayName() { - var result = win.name.match(WINDOW_NAME_REGEXP); - if (result) - return result[1]; + var name = win.location.hash.substring(1); + win.location.hash = ""; + if (name.length > 1) + return name; else return null; } function getRelayWindow() { - var frameWindow = win.opener.frames[getRelayName()]; - return frameWindow; + if (!_relayWindow) + _relayWindow = win.opener.frames[getRelayName()]; + return _relayWindow; } function setupNativeChannel(controller) { diff --git a/resources/static/include.js b/resources/static/include.js index 7e98a8ee8..ac8b01f5a 100644 --- a/resources/static/include.js +++ b/resources/static/include.js @@ -651,7 +651,7 @@ function _get_relayframe_id() { var randomString = ''; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - for (var i=0; i < 4; i++) { + for (var i=0; i < 8; i++) { randomString += possible.charAt(Math.floor(Math.random() * possible.length)); } return randomString; @@ -777,7 +777,7 @@ }); // open the window now that all else is ready - w = _open_window(ipServer + "/sign_in", relay_iframe.getAttribute('name')); + w = _open_window(ipServer + "/sign_in#" + relay_iframe.getAttribute('name')); // if the RP window closes, close the dialog as well. _attach_event(window, 'unload', cleanup); @@ -831,7 +831,8 @@ var setup_relay_iframe = function() { if (document.body) { var frameid = _get_relayframe_id(); - relay_iframe = _open_relayframe("browserid_relay_" + frameid); + // removed browserid_relay_ prefix, cause why? + relay_iframe = _open_relayframe(frameid); relay_chan = Channel.build({ window: relay_iframe.contentWindow, origin: ipServer, diff --git a/resources/static/test/qunit/resources/channel_unit_test.js b/resources/static/test/qunit/resources/channel_unit_test.js index 321ed02b2..94c860247 100644 --- a/resources/static/test/qunit/resources/channel_unit_test.js +++ b/resources/static/test/qunit/resources/channel_unit_test.js @@ -43,13 +43,13 @@ steal.then("/dialog/resources/channel", function() { // Mock in the window object as well as the frame relay var winMock = { - name : "_mozid_signin_browserid_relay_1234", location: { - href: "browserid.org/sign_in" + href: "browserid.org/sign_in#1234", + hash: "#1234" }, opener: { frames: { - browserid_relay_1234: { + "1234": { BrowserID: { Relay: { registerClient: function(methods) { @@ -136,7 +136,7 @@ steal.then("/dialog/resources/channel", function() { test("IFRAME channel with error on open", function() { var winMockWithoutRelay = $.extend(true, {}, winMock); - delete winMockWithoutRelay.opener.frames.browserid_relay_1234; + delete winMockWithoutRelay.opener.frames['1234']; channel.init({ window: winMockWithoutRelay, -- GitLab