Skip to content

Commit 21f098a

Browse files
committed
App 'reopen' event
1 parent 6659566 commit 21f098a

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

src/api/api_messages.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ IPC_MESSAGE_ROUTED1(ShellViewHostMsg_UpdateDraggableRegions,
9292
IPC_MESSAGE_CONTROL1(ShellViewMsg_Open,
9393
std::string /* file name */)
9494

95+
// Tell browser we have to reopen.
96+
IPC_MESSAGE_CONTROL0(ShellViewMsg_Reopen)
97+
9598
// clear cache on the renderer side
9699
IPC_MESSAGE_CONTROL0(ShellViewMsg_ClearCache)
97100

src/api/app/app.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ void App::EmitOpenEvent(const std::string& path) {
176176
}
177177
}
178178

179+
// static
180+
void App::EmitReopenEvent() {
181+
std::set<RenderProcessHost*> rphs;
182+
std::set<RenderProcessHost*>::iterator it;
183+
184+
GetRenderProcessHosts(rphs);
185+
for (it = rphs.begin(); it != rphs.end(); it++) {
186+
RenderProcessHost* rph = *it;
187+
DCHECK(rph != NULL);
188+
189+
rph->Send(new ShellViewMsg_Reopen());
190+
}
191+
}
192+
179193
void App::ClearCache(content::RenderProcessHost* render_process_host) {
180194
render_process_host->Send(new ShellViewMsg_ClearCache());
181195
nw::RemoveHttpDiskCache(render_process_host->GetBrowserContext(),

src/api/app/app.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class App {
5555
// Post "open" event.
5656
static void EmitOpenEvent(const std::string& path);
5757

58+
// Post "reopen" event.
59+
// (This event is received when the user clicked the icon in the Dock).
60+
static void EmitReopenEvent();
61+
5862
static void ClearCache(content::RenderProcessHost* render_view_host);
5963
private:
6064
App();

src/browser/app_controller_mac.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note {
6969
standard_menus.BuildWindowMenu();
7070
}
7171

72+
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication
73+
hasVisibleWindows:(BOOL)flag {
74+
api::App::EmitReopenEvent();
75+
return YES;
76+
}
77+
7278
@end

src/renderer/shell_render_process_observer.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ bool ShellRenderProcessObserver::OnControlMessageReceived(
5050
bool handled = true;
5151
IPC_BEGIN_MESSAGE_MAP(ShellRenderProcessObserver, message)
5252
IPC_MESSAGE_HANDLER(ShellViewMsg_Open, OnOpen)
53+
IPC_MESSAGE_HANDLER(ShellViewMsg_Reopen, OnReopen)
5354
IPC_MESSAGE_HANDLER(ShellViewMsg_ClearCache, OnClearCache)
5455
IPC_MESSAGE_UNHANDLED(handled = false)
5556
IPC_END_MESSAGE_MAP()
@@ -88,6 +89,25 @@ void ShellRenderProcessObserver::OnOpen(const std::string& path) {
8889
}
8990
}
9091

92+
void ShellRenderProcessObserver::OnReopen() {
93+
v8::HandleScope handle_scope;
94+
95+
// the App object is stored in process["_nw_app"].
96+
v8::Local<v8::Object> process = node::g_context->Global()->Get(
97+
node::process_symbol)->ToObject();
98+
v8::Local<v8::String> app_symbol = v8::String::NewSymbol("_nw_app");
99+
if (process->Has(app_symbol)) {
100+
// process["_nw_app"].emit(path).
101+
v8::Local<v8::Object> app = process->Get(app_symbol)->ToObject();
102+
v8::Local<v8::Function> emit = v8::Local<v8::Function>::Cast(
103+
app->Get(v8::String::New("emit")));
104+
v8::Local<v8::Value> argv[] = {
105+
v8::String::New("reopen")
106+
};
107+
emit->Call(app, 1, argv);
108+
}
109+
}
110+
91111
void ShellRenderProcessObserver::OnClearCache() {
92112
if (webkit_initialized_)
93113
WebKit::WebCache::clear();

src/renderer/shell_render_process_observer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ShellRenderProcessObserver : public RenderProcessObserver {
4040
virtual void WebKitInitialized() OVERRIDE;
4141
private:
4242
void OnOpen(const std::string& path);
43+
void OnReopen();
4344
void OnClearCache();
4445

4546
bool webkit_initialized_;

0 commit comments

Comments
 (0)