diff --git a/src/zen/common/ZenCommonUtils.mjs b/src/zen/common/ZenCommonUtils.mjs index 9d05f17eb..42cfd9804 100644 --- a/src/zen/common/ZenCommonUtils.mjs +++ b/src/zen/common/ZenCommonUtils.mjs @@ -76,13 +76,17 @@ var gZenCommonActions = { if (Services.zen.canShare()) { button = { id: 'zen-copy-current-url-button', - command: () => + command: (event) => { + const buttonRect = event.target.getBoundingClientRect(); Services.zen.share( Services.io.newURI(currentUrl), - "", - "" - ) - } + '', + '', + buttonRect.left - buttonRect.width / 2, + buttonRect.top + buttonRect.height + ); + }, + }; } gZenUIManager.showToast('zen-copy-current-url-confirmation', { button }); } diff --git a/src/zen/toolkit/common/ZenCommonUtils.cpp b/src/zen/toolkit/common/ZenCommonUtils.cpp index 9be6bd014..12d82fb20 100644 --- a/src/zen/toolkit/common/ZenCommonUtils.cpp +++ b/src/zen/toolkit/common/ZenCommonUtils.cpp @@ -82,7 +82,7 @@ ZenCommonUtils::Share(nsIURI* url, const nsACString& title, if (!IsSharingSupported()) { return NS_OK; // We don't want to throw an error here } - *_retval = ShareInternal(aWindow, url, title, text, aX, aY); + ShareInternal(aWindow, url, title, text, aX, aY); return NS_OK; } @@ -92,7 +92,7 @@ void ZenCommonUtils::ShareInternal(nsCOMPtr& aWindow, nsIURI // aWindow is valid. #ifdef ZEN_CAN_SHARE_NATIVE ::nsZenNativeShareInternal(aWindow, url, title, text, aX, aY); -#else +#endif } auto ZenCommonUtils::IsSharingSupported() -> bool { diff --git a/src/zen/toolkit/common/cocoa/ZenShareInternal.mm b/src/zen/toolkit/common/cocoa/ZenShareInternal.mm index 8d4b8e538..166a088ca 100644 --- a/src/zen/toolkit/common/cocoa/ZenShareInternal.mm +++ b/src/zen/toolkit/common/cocoa/ZenShareInternal.mm @@ -3,23 +3,41 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ZenShareInternal.h" -#include "nsIWindowsUIUtils.h" +#include "nsCocoaUtils.h" + +extern mozilla::LazyLogModule gCocoaUtilsLog; +#undef LOG +#define LOG(...) MOZ_LOG(gCocoaUtilsLog, mozilla::LogLevel::Debug, (__VA_ARGS__)) #import #import -@interface nsZenNativeShareInternal : NSObject -- (void)ShowNativeDialog:(nsCOMPtr& aWindow, nsIURI* aUrl, - const nsACString& aTitle, const nsACString& aText, - uint32_t aX, uint32_t aY) { +auto nsZenNativeShareInternal::ShowNativeDialog( + nsCOMPtr& aWindow, nsIURI* aUrl, + const nsACString& aTitle, const nsACString& aText, + uint32_t aX, uint32_t aY) const + -> void { // Just use the URL since apple doesn't support sharing text // and title in the share dialog + nsAutoCString pageUrlAsStringTemp; + if (aUrl) { + nsresult rv = aUrl->GetSpec(pageUrlAsStringTemp); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + mozilla::Unused << rv; + } else { + pageUrlAsStringTemp.SetIsVoid(true); + } + NSURL* pageUrl = nsCocoaUtils::ToNSURL( + NS_ConvertUTF8toUTF16(pageUrlAsStringTemp) + ); + LOG("pageUrl: %s", pageUrlAsStringTemp.get()); + if (!pageUrl || (![pageUrl.scheme isEqualToString:@"https"] && + ![pageUrl.scheme isEqualToString:@"http"])) { + return; + } NSSharingServicePicker* sharingPicker = - [[NSSharingServicePicker alloc] initWithItems:@[ aUrl ]]; - sharingPicker.delegate = self; - sharingPicker.showRelativeToRect:NSMakeRect(aX, aY, 0, 0) - ofView:(NSView*)aWindow - preferredEdge:NSMinYEdge; + [[NSSharingServicePicker alloc] initWithItems:@[ pageUrl ]]; + // Create a rect for the sharing picker + NSRect rect = NSMakeRect(aX, aY, 0, 0); + [sharingPicker showRelativeToRect:rect]; } - -@end \ No newline at end of file diff --git a/src/zen/toolkit/common/moz.build b/src/zen/toolkit/common/moz.build index 88c1929fd..81c0ccf3f 100644 --- a/src/zen/toolkit/common/moz.build +++ b/src/zen/toolkit/common/moz.build @@ -5,7 +5,7 @@ XPIDL_SOURCES += [ EXPORTS.mozilla += [ "ZenCommonUtils.h", - "ZenShareInternal.h + "ZenShareInternal.h", ] SOURCES += [