From 6f669dd79b3ed7ad51658ef4f9b56fad834c2390 Mon Sep 17 00:00:00 2001 From: Mason Date: Wed, 19 Dec 2018 10:22:41 -0800 Subject: [PATCH 1/3] 7132 Updated singleton to address cors issue in toolshed frames --- client/galaxy/scripts/app/singleton.js | 24 +++++++++++----------- client/galaxy/scripts/layout/panel.js | 28 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/client/galaxy/scripts/app/singleton.js b/client/galaxy/scripts/app/singleton.js index bab784f2af9..3b711cfb382 100644 --- a/client/galaxy/scripts/app/singleton.js +++ b/client/galaxy/scripts/app/singleton.js @@ -4,12 +4,12 @@ import addLogging from "utils/add-logging"; import { GalaxyApp } from "./galaxy"; -// import { serverPath } from "utils/serverPath"; +import { serverPath } from "utils/serverPath"; -export function setGalaxyInstance(factory, atTop = true) { - // console.warn("setGalaxyInstance", serverPath()); +export function setGalaxyInstance(factory) { + console.warn("setGalaxyInstance", serverPath()); - let storage = getStorage(atTop); + let storage = getStorage(); let newInstance = factory(GalaxyApp); if (!(newInstance instanceof GalaxyApp)) { newInstance = new GalaxyApp(newInstance); @@ -19,7 +19,6 @@ export function setGalaxyInstance(factory, atTop = true) { } // Debugging frame property - // storage._galaxyInstance = new Proxy(newInstance, { // get(galaxy, prop) { // if (prop == "frame") { @@ -46,17 +45,18 @@ export function setGalaxyInstance(factory, atTop = true) { return storage._galaxyInstance; } -export function getGalaxyInstance(atTop = true) { - let storage = getStorage(atTop); +export function getGalaxyInstance() { + let storage = getStorage(); return storage._galaxyInstance; } -export function galaxyIsInitialized(atTop = true) { - let instance = getGalaxyInstance(atTop); +export function galaxyIsInitialized() { + let instance = getGalaxyInstance(); return instance !== null; } -export function getStorage(atTop = true) { - let storage = window !== window.top && atTop ? window.top : window; - return storage; +// Having a CORS issue in the toolshed iframe, store separate versions +// of galaxy in each window for the short-term +export function getStorage() { + return window; } diff --git a/client/galaxy/scripts/layout/panel.js b/client/galaxy/scripts/layout/panel.js index 705bc22418c..9cf37d14d3b 100644 --- a/client/galaxy/scripts/layout/panel.js +++ b/client/galaxy/scripts/layout/panel.js @@ -203,23 +203,29 @@ var CenterPanel = Backbone.View.extend({ this.setElement($(this.template())); this.$frame = this.$(".center-frame"); this.$panel = this.$(".center-panel"); - this.$frame.on("load", _.bind(this._iframeChangeHandler, this)); + this.$frame.on("load", this._iframeChangeHandler.bind(this)); }, /** Display iframe if its target url changes, hide center panel */ _iframeChangeHandler: function(ev) { var iframe = ev.currentTarget; var location = iframe.contentWindow && iframe.contentWindow.location; - if (location && location.host) { - $(iframe).show(); - this.$panel.empty().hide(); - var Galaxy = getGalaxyInstance(); - Galaxy.trigger("center-frame:load", { - fullpath: location.pathname + location.search + location.hash, - pathname: location.pathname, - search: location.search, - hash: location.hash - }); + var Galaxy = getGalaxyInstance(); + // Adding try/catch to manage a CORS error in toolshed. Accessing + // location.host is a CORS no-no + try { + if (location && location.host) { + $(iframe).show(); + this.$panel.empty().hide(); + Galaxy.trigger("center-frame:load", { + fullpath: "fullpath", + pathname: "pathname", + search: "search", + hash: "hash" + }); + } + } catch(err) { + console.warn("_iframeChangeHandler error", ev, location, Galaxy); } }, From 60146ec89be41aec9a8d6216e96908b9095e6054 Mon Sep 17 00:00:00 2001 From: Mason Date: Wed, 19 Dec 2018 14:14:14 -0800 Subject: [PATCH 2/3] Replaced test code with real code --- client/galaxy/scripts/layout/panel.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/galaxy/scripts/layout/panel.js b/client/galaxy/scripts/layout/panel.js index 9cf37d14d3b..8dcb2d189ca 100644 --- a/client/galaxy/scripts/layout/panel.js +++ b/client/galaxy/scripts/layout/panel.js @@ -218,10 +218,10 @@ var CenterPanel = Backbone.View.extend({ $(iframe).show(); this.$panel.empty().hide(); Galaxy.trigger("center-frame:load", { - fullpath: "fullpath", - pathname: "pathname", - search: "search", - hash: "hash" + fullpath: location.pathname + location.search + location.hash, + pathname: location.pathname, + search: location.search, + hash: location.hash }); } } catch(err) { From cf7f1b0745482c5e7cd75fa9d8e91e95124fcfac Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 20 Dec 2018 15:52:02 -0500 Subject: [PATCH 3/3] Client formatting. --- client/galaxy/scripts/layout/panel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/galaxy/scripts/layout/panel.js b/client/galaxy/scripts/layout/panel.js index 8dcb2d189ca..af891ca3bf5 100644 --- a/client/galaxy/scripts/layout/panel.js +++ b/client/galaxy/scripts/layout/panel.js @@ -224,7 +224,7 @@ var CenterPanel = Backbone.View.extend({ hash: location.hash }); } - } catch(err) { + } catch (err) { console.warn("_iframeChangeHandler error", ev, location, Galaxy); } },