From c20acb0361a4915e800d3e3281046f2199b383f9 Mon Sep 17 00:00:00 2001 From: Charlie Hess Date: Fri, 29 Apr 2016 17:36:04 -0700 Subject: [PATCH] Implement a "continue-activity" event on app for resuming from hand-off. --- atom/browser/api/atom_api_app.cc | 5 +++++ atom/browser/api/atom_api_app.h | 2 ++ atom/browser/browser.cc | 11 +++++++++++ atom/browser/browser.h | 3 +++ atom/browser/browser_observer.h | 6 ++++++ 5 files changed, 27 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 8e7d8c3034a..fb258e2f483 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -20,6 +20,7 @@ #include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/native_mate_converters/net_converter.h" #include "atom/common/native_mate_converters/value_converter.h" +#include "atom/common/native_mate_converters/string_map_converter.h" #include "atom/common/node_includes.h" #include "atom/common/options_switches.h" #include "base/command_line.h" @@ -249,6 +250,10 @@ void App::OnFinishLaunching() { Emit("ready"); } +void App::OnContinueUserActivity(bool* handled, const std::string& type, const std::map& user_info) { + *handled = Emit("continue-activity", type, user_info); +} + void App::OnLogin(LoginHandler* login_handler) { v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index c99d5df7793..882f05376ca 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -6,6 +6,7 @@ #define ATOM_BROWSER_API_ATOM_API_APP_H_ #include +#include #include "atom/browser/api/event_emitter.h" #include "atom/browser/atom_browser_client.h" @@ -71,6 +72,7 @@ class App : public AtomBrowserClient::Delegate, void OnWillFinishLaunching() override; void OnFinishLaunching() override; void OnLogin(LoginHandler* login_handler) override; + void OnContinueUserActivity(bool* handled, const std::string& type, const std::map& user_info) override; // content::ContentBrowserClient: void AllowCertificateError( diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 093209ef7c4..94f3948c4a6 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -137,6 +137,17 @@ void Browser::Activate(bool has_visible_windows) { OnActivate(has_visible_windows)); } +#if defined(OS_MACOSX) +bool Browser::ContinueUserActivity(const std::string& type, const std::map& user_info) { + bool handled = false; + FOR_EACH_OBSERVER(BrowserObserver, + observers_, + OnContinueUserActivity(&handled, type, user_info)); + + return handled; +} +#endif + void Browser::WillFinishLaunching() { FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); } diff --git a/atom/browser/browser.h b/atom/browser/browser.h index b0dd829ff4d..4fb140e79e8 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -96,6 +96,9 @@ class Browser : public WindowListObserver { // Creates an activity and sets it as the one currently in use. void SetUserActivity(const std::string& type, const std::map& user_info); + // Resumes an activity via hand-off. + bool ContinueUserActivity(const std::string& type, const std::map& user_info); + // Bounce the dock icon. enum BounceType { BOUNCE_CRITICAL = 0, diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index f6d76bc13fb..11346f36875 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -6,6 +6,7 @@ #define ATOM_BROWSER_BROWSER_OBSERVER_H_ #include +#include namespace atom { @@ -45,6 +46,11 @@ class BrowserObserver { // The browser requests HTTP login. virtual void OnLogin(LoginHandler* login_handler) {} + // The browser wants to resume a user activity via handoff. (OS X only) + virtual void OnContinueUserActivity(bool* handled, + const std::string& type, + const std::map& user_info) {} + protected: virtual ~BrowserObserver() {} };