From d267f979b75f98c0f1a8ec5c4cad819babd6643e Mon Sep 17 00:00:00 2001 From: 1akshat1 Date: Tue, 13 Jul 2021 16:21:33 -0400 Subject: [PATCH] feat: continue-activity event is extended to support webpageURL property (#30042) Co-authored-by: Akshat Malik Co-authored-by: Jeremy Rose --- docs/api/app.md | 2 ++ shell/browser/api/electron_api_app.cc | 5 +++-- shell/browser/api/electron_api_app.h | 3 ++- shell/browser/browser.h | 3 ++- shell/browser/browser_mac.mm | 5 +++-- shell/browser/browser_observer.h | 3 ++- shell/browser/mac/electron_application_delegate.mm | 5 ++++- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 453966639a15..370ee386626d 100755 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -161,6 +161,8 @@ Returns: [`NSUserActivity.activityType`][activity-type]. * `userInfo` unknown - Contains app-specific state stored by the activity on another device. +* `details` Object + * `webpageURL` String (optional) - A string identifying the URL of the webpage accessed by the activity on another device, if available. Emitted during [Handoff][handoff] when an activity from a different device wants to be resumed. You should call `event.preventDefault()` if you want to handle diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index 52a121c957b1..fcbf8ab7e5d2 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -716,8 +716,9 @@ void App::OnDidFailToContinueUserActivity(const std::string& type, void App::OnContinueUserActivity(bool* prevent_default, const std::string& type, - const base::DictionaryValue& user_info) { - if (Emit("continue-activity", type, user_info)) { + const base::DictionaryValue& user_info, + const base::DictionaryValue& details) { + if (Emit("continue-activity", type, user_info, details)) { *prevent_default = true; } } diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index 9dd1face6a2f..485f0132a6ef 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -102,7 +102,8 @@ class App : public ElectronBrowserClient::Delegate, const std::string& error) override; void OnContinueUserActivity(bool* prevent_default, const std::string& type, - const base::DictionaryValue& user_info) override; + const base::DictionaryValue& user_info, + const base::DictionaryValue& details) override; void OnUserActivityWasContinued( const std::string& type, const base::DictionaryValue& user_info) override; diff --git a/shell/browser/browser.h b/shell/browser/browser.h index 187690261132..fdd47951ca84 100755 --- a/shell/browser/browser.h +++ b/shell/browser/browser.h @@ -187,7 +187,8 @@ class Browser : public WindowListObserver { // Resumes an activity via hand-off. bool ContinueUserActivity(const std::string& type, - base::DictionaryValue user_info); + base::DictionaryValue user_info, + base::DictionaryValue details); // Indicates that an activity was continued on another device. void UserActivityWasContinued(const std::string& type, diff --git a/shell/browser/browser_mac.mm b/shell/browser/browser_mac.mm index e955a4c98a87..9908f2bedf3f 100644 --- a/shell/browser/browser_mac.mm +++ b/shell/browser/browser_mac.mm @@ -277,10 +277,11 @@ void Browser::DidFailToContinueUserActivity(const std::string& type, } bool Browser::ContinueUserActivity(const std::string& type, - base::DictionaryValue user_info) { + base::DictionaryValue user_info, + base::DictionaryValue details) { bool prevent_default = false; for (BrowserObserver& observer : observers_) - observer.OnContinueUserActivity(&prevent_default, type, user_info); + observer.OnContinueUserActivity(&prevent_default, type, user_info, details); return prevent_default; } diff --git a/shell/browser/browser_observer.h b/shell/browser/browser_observer.h index c21259353006..5b33821c2e15 100644 --- a/shell/browser/browser_observer.h +++ b/shell/browser/browser_observer.h @@ -70,7 +70,8 @@ class BrowserObserver : public base::CheckedObserver { // The browser wants to resume a user activity via handoff. (macOS only) virtual void OnContinueUserActivity(bool* prevent_default, const std::string& type, - const base::DictionaryValue& user_info) {} + const base::DictionaryValue& user_info, + const base::DictionaryValue& details) {} // The browser wants to notify that an user activity was resumed. (macOS only) virtual void OnUserActivityWasContinued( const std::string& type, diff --git a/shell/browser/mac/electron_application_delegate.mm b/shell/browser/mac/electron_application_delegate.mm index ceded50f9a5d..138400d625a8 100644 --- a/shell/browser/mac/electron_application_delegate.mm +++ b/shell/browser/mac/electron_application_delegate.mm @@ -154,13 +154,16 @@ static NSDictionary* UNNotificationResponseToNSDictionary( #endif restorationHandler { std::string activity_type(base::SysNSStringToUTF8(userActivity.activityType)); + NSURL* url = userActivity.webpageURL; + NSDictionary* details = url ? @{@"webpageURL" : [url absoluteString]} : @{}; if (!userActivity.userInfo) return NO; electron::Browser* browser = electron::Browser::Get(); return browser->ContinueUserActivity( activity_type, - electron::NSDictionaryToDictionaryValue(userActivity.userInfo)) + electron::NSDictionaryToDictionaryValue(userActivity.userInfo), + electron::NSDictionaryToDictionaryValue(details)) ? YES : NO; }