Bug 1588420 - Add init() to SharePicker.idl, which provides a means to get to browser parent r=droeh

Differential Revision: https://phabricator.services.mozilla.com/D49215

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Marcos Cáceres 2019-10-15 00:52:09 +00:00
parent af84bcf3df
commit caed406d12
3 changed files with 54 additions and 2 deletions

View file

@ -7,7 +7,9 @@ const { XPCOMUtils } = ChromeUtils.import(
);
class SharePicker {
constructor() {}
constructor() {
this._initialized = false;
}
get classDescription() {
return "Web Share Picker";
@ -25,6 +27,25 @@ class SharePicker {
return ChromeUtils.generateQI([Ci.nsISharePicker]);
}
/**
* Initializer.
*
* @param {nsIDOMWindow} openerWindow
*/
init(openerWindow) {
if (this._initialized) {
throw new Error("Unexpected re-initialization. This is not allowed.");
}
this._initialized = true;
if (openerWindow instanceof Ci.nsIDOMWindow === false) {
throw new TypeError("Expected nsIDOMWindow");
}
this._openerWindow = openerWindow;
}
/**
* The data being shared by the Document.
*
@ -49,6 +70,12 @@ class SharePicker {
throw new DOMException("Not supported.", "AbortError");
}
/**
* @returns mozIDOMWindowProxy
*/
get openerWindow() {
return this._openerWindow;
}
__init() {}
}

View file

@ -357,12 +357,24 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvShare(
// Widget Layer handoff...
nsCOMPtr<nsISharePicker> sharePicker =
do_GetService("@mozilla.org/sharepicker;1");
if (!sharePicker) {
aResolver(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return IPC_OK();
}
// Initialize the ShareWidget
RefPtr<BrowserParent> parent = GetBrowserParent();
if (NS_WARN_IF(!parent)) {
aResolver(NS_ERROR_FAILURE);
return IPC_OK();
}
nsCOMPtr<mozIDOMWindowProxy> openerWindow = parent->GetParentWindowOuter();
if (!openerWindow) {
aResolver(NS_ERROR_FAILURE);
return IPC_OK();
}
sharePicker->Init(openerWindow);
// And finally share the data...
RefPtr<Promise> promise;
nsresult rv = sharePicker->Share(aData.title(), aData.text(), aData.url(),

View file

@ -8,9 +8,22 @@
interface nsIURI;
interface mozIDOMWindowProxy;
[scriptable, uuid(1201d357-8417-4926-a694-e6408fbedcf8)]
interface nsISharePicker : nsISupports
{
/**
* Initialize the share picker widget.
* @param nsIDOMWindow openerWindow.
*/
void init(in mozIDOMWindowProxy openerWindow);
/**
* Returns the parent window this was initialized with.
*/
readonly attribute mozIDOMWindowProxy openerWindow;
/**
* XPCOM Analog of navigator.share() as per:
* https://w3c.github.io/web-share/#share-method