Last active
June 22, 2018 10:01
-
-
Save daleharvey/f859f8785a1d752f82f8bd3c414c726b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daleharvey@DESKTOP-UELI0OF ~/src/gecko-dev | |
$ git diff HEAD~1 | |
diff --git a/browser/base/content/browser-pageActions.js b/browser/base/content/browser-pageActions.js | |
index 47beadd53c..d030c1e31c 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,13 @@ BrowserPageActions.shareURL = { | |
.getService(Ci.nsIMacSharingService); | |
}, | |
+ onCommand(event, buttonNode) { | |
+// let windowsUIUtils = Cc["@mozilla.org/windows-ui-utils;1"] | |
+// .getService(Ci.nsIWindowUIUtils); | |
+ console.log('!!!SHARING!!!'); | |
+ 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..099c51dd52 100644 | |
--- a/widget/windows/WindowsUIUtils.cpp | |
+++ b/widget/windows/WindowsUIUtils.cpp | |
@@ -22,6 +22,27 @@ | |
#include "nsString.h" | |
#include "nsIWidget.h" | |
+#include <wrl/client.h> | |
+#include <wrl/event.h> | |
+#include <wrl/wrappers/corewrappers.h> | |
+#include <windows.applicationmodel.datatransfer.h> | |
+#include <tchar.h> | |
+#include <roapi.h> | |
+#include <ShObjIdl.h> | |
+#include <commctrl.h> | |
+#include <shlwapi.h> | |
+#include <ole2.h> | |
+ | |
+#include "mozilla/Logging.h" | |
+using mozilla::LogLevel; | |
+static mozilla::LazyLogModule sLogger("example_logger"); | |
+ | |
+namespace WRL = Microsoft::WRL; | |
+namespace AWF = ABI::Windows::Foundation; | |
+namespace DT = ABI::Windows::ApplicationModel::DataTransfer; | |
+ | |
+using Microsoft::WRL::Wrappers::HStringReference; | |
+ | |
/* mingw currently doesn't support windows.ui.viewmanagement.h, so we disable it until it's fixed. */ | |
#ifndef __MINGW32__ | |
@@ -90,6 +111,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 +213,51 @@ WindowsUIUtils::UpdateTabletModeState() | |
return NS_OK; | |
} | |
+ | |
+NS_IMETHODIMP | |
+WindowsUIUtils::ShareUrl() | |
+{ | |
+#ifndef __MINGW32__ | |
+ if (!IsWin10OrLater()) { | |
+ return NS_OK; | |
+ } | |
+ | |
+ MOZ_LOG(sLogger, LogLevel::Info, ("Sharing URL!")); | |
+ printf("Sharing URL !"); | |
+ | |
+ HWND hwnd = GetForegroundWindow(); | |
+ WRL::ComPtr<IDataTransferManagerInterop> dtmInterop; | |
+ WRL::ComPtr<DT::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 = WRL::Callback < ITypedEventHandler<DT::DataTransferManager*, DT::DataRequestedEventArgs* >> ( | |
+ [&](DT::IDataTransferManager*, DT::IDataRequestedEventArgs* pArgs) -> HRESULT | |
+ { | |
+ printf("Asking for data"); | |
+ WRL::ComPtr<DT::IDataRequest> spDataRequest; | |
+ pArgs->get_Request(&spDataRequest); | |
+ // Create Sharing data | |
+ WRL::ComPtr<DT::IDataPackage> spDataPackage; | |
+ spDataRequest->get_Data(&spDataPackage); | |
+ WRL::ComPtr<DT::IDataPackagePropertySet> spDataPacakgeProperties; | |
+ spDataPackage->get_Properties(&spDataPacakgeProperties); | |
+ spDataPacakgeProperties->put_Title(Wrappers::HStringReference(L"Sample win32 app").Get()); | |
+ spDataPacakgeProperties->put_Description(Wrappers::HStringReference(L"Hello...world !!!").Get()); | |
+ spDataPackage->SetText(Wrappers::HStringReference(L"Say hello!").Get()); | |
+ | |
+ printf("Asked for data"); | |
+ return S_OK; | |
+ }); | |
+ | |
+ dtm->add_DataRequested(callback.Get(), &dataRequestedToken); | |
+ dtmInterop->ShowShareUIForWindow(hwnd); | |
+ | |
+#endif | |
+ | |
+ return NS_OK; | |
+} | |
daleharvey@DESKTOP-UELI0OF ~/src/gecko-dev | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment