We're developing a Javascript SDK which is used by embedded applications (injected in my site as IFRAMEs) to help them use some resources like loading some dialogs: e.g. an authorization dialog or a share box(like Facebook).
Our SDK is using easyXDM to work more or less like this:
HTML Page
----------------------------------------------------------------------------------------------------------------------------
| http / https: www.mysite.com/embedded-app/
| (Some JS classes)
|
|- - - - - | ------------------------------------------------------------------------------------------------------------------
|- - - - - | (IFRAME)
|- - - - - | https: // www.some-embedded-app-domain.com/page.html
|- - - - - | (loads and instantiates the SDK from "http/https:www.mysite.com/sdk.js that uses easyXDM)
|- - - - - |
|- - - - - | - - - - - |---------------------------------------------------------------------------------------------------
|- - - - - | - - - - - | (IFRAME injected by easyXDM)
|- - - - - | - - - - - | http / https: www.mysite.com/embedded_provider.html
|- - - - - | - - - - - | (Communication with window.top to talk to use those wndow.top JS classes)
|- - - - - | - - - - - |
|- - - - - | - - - - - |
|- - - - - | - - - - - |
|- - - - - | - - - - - |
My site can be loaded both using http/https, but the embedded application must be served using always HTTPS. In order to allow the inner iframe injected by easyXDM to communicate with my site, the host and protocol must match in both urls, otherwise a same origin policy violation will arise.
Problem: how would I tell the code from the SDK, which is loaded from an external app URL, that the outer windows (my site) is using http or https, to render the embedded_provider.html using the same protocol and thus allowing JS communication between both of them?
The only solution I can think of is to inform the embedded app somehow that we're currently browsing from http / https, and then it can instantiate it properly (using a flag use_https or so), but I'd prefer to not force the App to know the protocol we are using.
Do you know any other alternative?
Thanks!