Commit 6edc5a8f authored by Panos Astithas's avatar Panos Astithas
Browse files

Bug 1085391 - Support Yosemite Handoff 'web browsing' activity type. r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D8665

--HG--
extra : moz-landing-system : lando
parent 3faf6a18
......@@ -221,6 +221,10 @@
</array>
<key>CFBundleVersion</key>
<string>%MAC_BUNDLE_VERSION%</string>
<key>NSUserActivityTypes</key>
<array>
<string>NSUserActivityTypeBrowsingWeb</string>
</array>
<key>NSAppleScriptEnabled</key>
<true/>
<key>LSApplicationCategoryType</key>
......
......@@ -345,30 +345,9 @@ ProcessPendingGetURLAppleEvents()
if (isGetURLEvent ||
([event eventClass] == 'WWW!' && [event eventID] == 'OURL')) {
NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSURL* url = [NSURL URLWithString:urlString];
// don't open chrome URLs
NSString* schemeString = [[NSURL URLWithString:urlString] scheme];
if (!schemeString ||
[schemeString compare:@"chrome"
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [schemeString length])] == NSOrderedSame) {
return;
}
// Add the URL to any command line we're currently setting up.
if (CommandLineServiceMac::AddURLToCurrentCommandLine([urlString UTF8String]))
return;
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
nsCOMPtr<nsIFile> workingDir;
nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
if (NS_FAILED(rv))
return;
const char *argv[3] = {nullptr, "-url", [urlString UTF8String]};
rv = cmdLine->Init(3, argv, workingDir, nsICommandLine::STATE_REMOTE_EXPLICIT);
if (NS_FAILED(rv))
return;
rv = cmdLine->Run();
[self openURL:url];
}
else if ([event eventClass] == kCoreEventClass && [event eventID] == kAEOpenDocuments) {
NSAppleEventDescriptor* fileListDescriptor = [event paramDescriptorForKeyword:keyDirectObject];
......@@ -392,4 +371,60 @@ ProcessPendingGetURLAppleEvents()
}
}
- (BOOL)application:(NSApplication*)application
willContinueUserActivityWithType:(NSString*)userActivityType
{
return [userActivityType isEqualToString:NSUserActivityTypeBrowsingWeb];
}
- (BOOL)application:(NSApplication*)application
continueUserActivity:(NSUserActivity*)userActivity
restorationHandler:(void (^)(NSArray*))restorationHandler
{
if (![userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
return NO;
}
return [self openURL:userActivity.webpageURL];
}
- (void)application:(NSApplication*)application
didFailToContinueUserActivityWithType:(NSString*)userActivityType
error:(NSError*)error
{
NSLog(@"Failed to continue user activity %@: %@", userActivityType, error);
}
- (BOOL)openURL:(NSURL*)url
{
if (!url || !url.scheme || [url.scheme caseInsensitiveCompare:@"chrome"] == NSOrderedSame) {
return NO;
}
const char* const urlString = [[url absoluteString] UTF8String];
// Add the URL to any command line we're currently setting up.
if (CommandLineServiceMac::AddURLToCurrentCommandLine(urlString)) {
return NO;
}
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
nsCOMPtr<nsIFile> workingDir;
nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR,
getter_AddRefs(workingDir));
if (NS_FAILED(rv)) {
return NO;
}
const char* argv[3] = {nullptr, "-url", urlString};
rv = cmdLine->Init(3, argv, workingDir, nsICommandLine::STATE_REMOTE_EXPLICIT);
if (NS_FAILED(rv)) {
return NO;
}
rv = cmdLine->Run();
if (NS_FAILED(rv)) {
return NO;
}
return YES;
}
@end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment