forked from mirrors/gecko-dev
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:
parent
af84bcf3df
commit
caed406d12
3 changed files with 54 additions and 2 deletions
|
|
@ -7,7 +7,9 @@ const { XPCOMUtils } = ChromeUtils.import(
|
||||||
);
|
);
|
||||||
|
|
||||||
class SharePicker {
|
class SharePicker {
|
||||||
constructor() {}
|
constructor() {
|
||||||
|
this._initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
get classDescription() {
|
get classDescription() {
|
||||||
return "Web Share Picker";
|
return "Web Share Picker";
|
||||||
|
|
@ -25,6 +27,25 @@ class SharePicker {
|
||||||
return ChromeUtils.generateQI([Ci.nsISharePicker]);
|
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.
|
* The data being shared by the Document.
|
||||||
*
|
*
|
||||||
|
|
@ -49,6 +70,12 @@ class SharePicker {
|
||||||
throw new DOMException("Not supported.", "AbortError");
|
throw new DOMException("Not supported.", "AbortError");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns mozIDOMWindowProxy
|
||||||
|
*/
|
||||||
|
get openerWindow() {
|
||||||
|
return this._openerWindow;
|
||||||
|
}
|
||||||
__init() {}
|
__init() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -357,12 +357,24 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvShare(
|
||||||
// Widget Layer handoff...
|
// Widget Layer handoff...
|
||||||
nsCOMPtr<nsISharePicker> sharePicker =
|
nsCOMPtr<nsISharePicker> sharePicker =
|
||||||
do_GetService("@mozilla.org/sharepicker;1");
|
do_GetService("@mozilla.org/sharepicker;1");
|
||||||
|
|
||||||
if (!sharePicker) {
|
if (!sharePicker) {
|
||||||
aResolver(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
aResolver(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||||
return IPC_OK();
|
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...
|
// And finally share the data...
|
||||||
RefPtr<Promise> promise;
|
RefPtr<Promise> promise;
|
||||||
nsresult rv = sharePicker->Share(aData.title(), aData.text(), aData.url(),
|
nsresult rv = sharePicker->Share(aData.title(), aData.text(), aData.url(),
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,22 @@
|
||||||
|
|
||||||
interface nsIURI;
|
interface nsIURI;
|
||||||
|
|
||||||
|
interface mozIDOMWindowProxy;
|
||||||
|
|
||||||
[scriptable, uuid(1201d357-8417-4926-a694-e6408fbedcf8)]
|
[scriptable, uuid(1201d357-8417-4926-a694-e6408fbedcf8)]
|
||||||
interface nsISharePicker : nsISupports
|
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:
|
* XPCOM Analog of navigator.share() as per:
|
||||||
* https://w3c.github.io/web-share/#share-method
|
* https://w3c.github.io/web-share/#share-method
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue