Implement a "continue-activity" event on app for resuming from hand-off.

This commit is contained in:
Charlie Hess 2016-04-29 17:36:04 -07:00
parent 6df4bb176d
commit c20acb0361
5 changed files with 27 additions and 0 deletions

View file

@ -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<std::string, std::string>& user_info) {
*handled = Emit("continue-activity", type, user_info);
}
void App::OnLogin(LoginHandler* login_handler) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());

View file

@ -6,6 +6,7 @@
#define ATOM_BROWSER_API_ATOM_API_APP_H_
#include <string>
#include <map>
#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<std::string, std::string>& user_info) override;
// content::ContentBrowserClient:
void AllowCertificateError(

View file

@ -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<std::string, std::string>& 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());
}

View file

@ -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<std::string, std::string>& user_info);
// Resumes an activity via hand-off.
bool ContinueUserActivity(const std::string& type, const std::map<std::string, std::string>& user_info);
// Bounce the dock icon.
enum BounceType {
BOUNCE_CRITICAL = 0,

View file

@ -6,6 +6,7 @@
#define ATOM_BROWSER_BROWSER_OBSERVER_H_
#include <string>
#include <map>
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<std::string, std::string>& user_info) {}
protected:
virtual ~BrowserObserver() {}
};