diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /widget/cocoa/nsMacUserActivityUpdater.mm | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | widget/cocoa/nsMacUserActivityUpdater.mm | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/widget/cocoa/nsMacUserActivityUpdater.mm b/widget/cocoa/nsMacUserActivityUpdater.mm new file mode 100644 index 0000000000..cc80e1259b --- /dev/null +++ b/widget/cocoa/nsMacUserActivityUpdater.mm @@ -0,0 +1,64 @@ +/* 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/. */ + +#import <Cocoa/Cocoa.h> + +#include "nsMacUserActivityUpdater.h" + +#include "nsCocoaUtils.h" +#include "nsIBaseWindow.h" +#include "gfxPlatform.h" + +NS_IMPL_ISUPPORTS(nsMacUserActivityUpdater, nsIMacUserActivityUpdater) + +NS_IMETHODIMP +nsMacUserActivityUpdater::UpdateLocation(const nsAString& aPageUrl, const nsAString& aPageTitle, + nsIBaseWindow* aWindow) { + NS_OBJC_BEGIN_TRY_BLOCK_RETURN; + if (gfxPlatform::IsHeadless()) { + // In headless mode, Handoff will fail since there is no Cocoa window. + return NS_OK; + } + + BaseWindow* cocoaWin = nsMacUserActivityUpdater::GetCocoaWindow(aWindow); + if (!cocoaWin) { + return NS_ERROR_FAILURE; + } + + NSURL* pageUrl = nsCocoaUtils::ToNSURL(aPageUrl); + if (!pageUrl || + (![pageUrl.scheme isEqualToString:@"https"] && ![pageUrl.scheme isEqualToString:@"http"])) { + [cocoaWin.userActivity invalidate]; + return NS_OK; + } + + NSString* pageTitle = nsCocoaUtils::ToNSString(aPageTitle); + if (!pageTitle) { + pageTitle = pageUrl.absoluteString; + } + + NSUserActivity* userActivity = + [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb]; + userActivity.webpageURL = pageUrl; + userActivity.title = pageTitle; + cocoaWin.userActivity = userActivity; + [userActivity release]; + + return NS_OK; + + NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE); +} + +BaseWindow* nsMacUserActivityUpdater::GetCocoaWindow(nsIBaseWindow* aWindow) { + nsCOMPtr<nsIWidget> widget = nullptr; + aWindow->GetMainWidget(getter_AddRefs(widget)); + if (!widget) { + return nil; + } + BaseWindow* cocoaWin = (BaseWindow*)widget->GetNativeData(NS_NATIVE_WINDOW); + if (!cocoaWin) { + return nil; + } + return cocoaWin; +} |