Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daleharvey/ef84258cf33fc84605617084b4fdd618 to your computer and use it in GitHub Desktop.
Save daleharvey/ef84258cf33fc84605617084b4fdd618 to your computer and use it in GitHub Desktop.
diff --git a/browser/base/content/browser-pageActions.js b/browser/base/content/browser-pageActions.js
index 47beadd53c..b49df6d29f 100644
--- a/browser/base/content/browser-pageActions.js
+++ b/browser/base/content/browser-pageActions.js
@@ -1263,6 +1263,10 @@ BrowserPageActions.addSearchEngine = {
},
};
+XPCOMUtils.defineLazyServiceGetters(this, {
+ WindowsUIUtils: ["@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils"]
+})
+
// share URL
BrowserPageActions.shareURL = {
// Attach sharingService here so tests can override the implementation
@@ -1271,6 +1275,10 @@ BrowserPageActions.shareURL = {
.getService(Ci.nsIMacSharingService);
},
+ onCommand(event, buttonNode) {
+ WindowsUIUtils.shareUrl();
+ },
+
onShowingInPanel(buttonNode) {
this._cached = false;
},
diff --git a/browser/modules/PageActions.jsm b/browser/modules/PageActions.jsm
index ff21ef45f4..f07466557f 100644
--- a/browser/modules/PageActions.jsm
+++ b/browser/modules/PageActions.jsm
@@ -1187,6 +1187,21 @@ if (AppConstants.platform == "macosx") {
});
}
+if (AppConstants.platform == "win") {
+ gBuiltInActions.push(
+ // Share URL
+ {
+ id: "shareURL",
+ title: "shareURL-title",
+ onPlacedInPanel(buttonNode) {
+ browserPageActions(buttonNode).shareURL.onPlacedInPanel(buttonNode);
+ },
+ onCommand(event, buttonNode) {
+ browserPageActions(buttonNode).shareURL.onCommand(event, buttonNode);
+ },
+ });
+}
+
/**
* Gets a BrowserPageActions object in a browser window.
*
diff --git a/browser/themes/windows/browser.css b/browser/themes/windows/browser.css
index 7b02e76b18..59bdb10fce 100644
--- a/browser/themes/windows/browser.css
+++ b/browser/themes/windows/browser.css
@@ -582,6 +582,10 @@ html|*.urlbar-input:-moz-lwtheme::placeholder,
color: GrayText;
}
+#pageAction-panel-shareURL {
+ list-style-image: url("chrome://browser/skin/share.svg");
+}
+
%include ../shared/urlbarSearchSuggestionsNotification.inc.css
#search-container {
@@ -1114,4 +1118,3 @@ panel[touchmode] .PanelUI-subView #appMenu-zoom-controls > .subviewbutton-iconic
padding-top: .9167em;
padding-bottom: .9167em;
}
-
diff --git a/browser/themes/windows/jar.mn b/browser/themes/windows/jar.mn
index 150d922487..bbe1f7512e 100644
--- a/browser/themes/windows/jar.mn
+++ b/browser/themes/windows/jar.mn
@@ -49,6 +49,7 @@ browser.jar:
* skin/classic/browser/preferences/in-content/preferences.css (preferences/in-content/preferences.css)
* skin/classic/browser/preferences/in-content/dialog.css (preferences/in-content/dialog.css)
skin/classic/browser/preferences/applications.css (preferences/applications.css)
+ skin/classic/browser/share.svg (share.svg)
skin/classic/browser/tabbrowser/tabDragIndicator.png (tabbrowser/tabDragIndicator.png)
skin/classic/browser/window-controls/close.svg (window-controls/close.svg)
skin/classic/browser/window-controls/close-highcontrast.svg (window-controls/close-highcontrast.svg)
diff --git a/browser/themes/windows/share.svg b/browser/themes/windows/share.svg
new file mode 100644
index 0000000000..3d5c2fe86f
--- /dev/null
+++ b/browser/themes/windows/share.svg
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16">
+ <path fill="context-fill" d="M 15.707 4.293 l -4 -4 a 1 1 0 0 0 -1.414 1.414 L 12.585 4 H 11 a 7.008 7.008 0 0 0 -7 7 a 1 1 0 0 0 2 0 a 5.006 5.006 0 0 1 5 -5 h 1.585 l -2.293 2.293 a 1 1 0 1 0 1.414 1.414 l 4 -4 a 1 1 0 0 0 0.001 -1.414 Z" />
+ <path fill="context-fill" d="M 13 11 a 1 1 0 0 0 -1 1 v 1 a 1 1 0 0 1 -1 1 H 3 a 1 1 0 0 1 -1 -1 V 6 a 1 1 0 0 1 1 -1 h 1 a 1 1 0 0 0 0 -2 H 3 a 3 3 0 0 0 -3 3 v 7 a 3 3 0 0 0 3 3 h 8 a 3 3 0 0 0 3 -3 v -1 a 1 1 0 0 0 -1 -1 Z" />
+</svg>
diff --git a/widget/nsIWindowsUIUtils.idl b/widget/nsIWindowsUIUtils.idl
index 331562a672..cb341fd49b 100644
--- a/widget/nsIWindowsUIUtils.idl
+++ b/widget/nsIWindowsUIUtils.idl
@@ -6,7 +6,6 @@
#include "nsISupports.idl"
-
[scriptable, uuid(aa8a0ecf-96a1-418c-b80e-f24ae18bbedc)]
interface nsIWindowsUIUtils : nsISupports
{
@@ -20,5 +19,9 @@ interface nsIWindowsUIUtils : nsISupports
* Update the tablet mode state
*/
void updateTabletModeState();
-};
+ /**
+ * Share URL
+ */
+ void shareUrl();
+};
diff --git a/widget/windows/WindowsUIUtils.cpp b/widget/windows/WindowsUIUtils.cpp
index 4d916d25cf..d8f50c198f 100644
--- a/widget/windows/WindowsUIUtils.cpp
+++ b/widget/windows/WindowsUIUtils.cpp
@@ -35,6 +35,7 @@ using namespace ABI::Windows::UI::ViewManagement;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::ApplicationModel::DataTransfer;
/* All of this is win10 stuff and we're compiling against win81 headers
* for now, so we may need to do some legwork: */
@@ -90,6 +91,20 @@ public:
};
#endif
+#ifndef IDataTransferManagerInterop
+
+typedef interface IDataTransferManagerInterop IDataTransferManagerInterop;
+
+MIDL_INTERFACE("3A3DCD6C-3EAB-43DC-BCDE-45671CE800C8")
+IDataTransferManagerInterop : public IUnknown
+{
+public:
+ virtual HRESULT STDMETHODCALLTYPE GetForWindow(HWND appWindow, REFIID riid, void **dataTransferManager) = 0;
+ virtual HRESULT STDMETHODCALLTYPE ShowShareUIForWindow(HWND appWindow) = 0;
+};
+
+#endif
+
#endif
WindowsUIUtils::WindowsUIUtils() :
@@ -178,3 +193,45 @@ WindowsUIUtils::UpdateTabletModeState()
return NS_OK;
}
+
+NS_IMETHODIMP
+WindowsUIUtils::ShareUrl()
+{
+#ifndef __MINGW32__
+ if (!IsWin10OrLater()) {
+ return NS_OK;
+ }
+
+ HWND hwnd = GetForegroundWindow();
+
+ ComPtr<IDataTransferManagerInterop> dtmInterop;
+ ComPtr<IDataTransferManager> dtm;
+
+ EventRegistrationToken dataRequestedToken;
+ RoGetActivationFactory(HStringReference(
+ RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager)
+ .Get(), IID_PPV_ARGS(&dtmInterop));
+ dtmInterop->GetForWindow(hwnd, IID_PPV_ARGS(&dtm));
+
+ auto callback = Callback < ITypedEventHandler<DataTransferManager*, DataRequestedEventArgs* >> (
+ [&](IDataTransferManager*, IDataRequestedEventArgs* pArgs) -> HRESULT
+ {
+ ComPtr<IDataRequest> spDataRequest;
+ pArgs->get_Request(&spDataRequest);
+ ComPtr<IDataPackage> spDataPackage;
+ spDataRequest->get_Data(&spDataPackage);
+ ComPtr<IDataPackagePropertySet> spDataPacakgeProperties;
+ spDataPackage->get_Properties(&spDataPacakgeProperties);
+ spDataPacakgeProperties->put_Title(HStringReference(L"Sample win32 app").Get());
+ spDataPacakgeProperties->put_Description(HStringReference(L"Hello...world !!!").Get());
+ spDataPackage->SetText(HStringReference(L"Say hello!").Get());
+ return S_OK;
+ });
+
+ dtm->add_DataRequested(callback.Get(), &dataRequestedToken);
+ dtmInterop->ShowShareUIForWindow(hwnd);
+
+#endif
+
+ return NS_OK;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment