Skip to content

Commit fde26ec

Browse files
committed
Make browser aware of other instances. Part of both nwjs#61 and nwjs#64.
Relying on chrohime/build_chromium@e39ee1a.
1 parent 6b10d4a commit fde26ec

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

nw.gypi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,26 @@
5050
'<(DEPTH)/chrome/browser/platform_util_mac.mm',
5151
'<(DEPTH)/chrome/browser/platform_util_win.cc',
5252
'<(DEPTH)/chrome/browser/platform_util.h',
53+
'<(DEPTH)/chrome/browser/process_singleton_linux.cc',
54+
'<(DEPTH)/chrome/browser/process_singleton_mac.cc',
55+
'<(DEPTH)/chrome/browser/process_singleton_win.cc',
56+
'<(DEPTH)/chrome/browser/process_singleton.h',
5357
'<(DEPTH)/chrome/browser/status_icons/status_icon.cc',
5458
'<(DEPTH)/chrome/browser/status_icons/status_icon.h',
5559
'<(DEPTH)/chrome/browser/status_icons/status_icon_observer.h',
5660
'<(DEPTH)/chrome/browser/status_icons/status_tray.cc',
5761
'<(DEPTH)/chrome/browser/status_icons/status_tray.h',
5862
'<(DEPTH)/chrome/browser/ui/base_window.h',
59-
'<(DEPTH)/chrome/browser/ui/gtk/gtk_window_util.h',
6063
'<(DEPTH)/chrome/browser/ui/gtk/gtk_window_util.cc',
64+
'<(DEPTH)/chrome/browser/ui/gtk/gtk_window_util.h',
6165
'<(DEPTH)/chrome/browser/ui/views/status_icons/status_icon_win.cc',
6266
'<(DEPTH)/chrome/browser/ui/views/status_icons/status_icon_win.h',
6367
'<(DEPTH)/chrome/browser/ui/views/status_icons/status_tray_win.cc',
6468
'<(DEPTH)/chrome/browser/ui/views/status_icons/status_tray_win.h',
69+
'<(DEPTH)/chrome/common/chrome_constants.cc',
70+
'<(DEPTH)/chrome/common/chrome_constants.h',
71+
'<(DEPTH)/chrome/common/chrome_switches.cc',
72+
'<(DEPTH)/chrome/common/chrome_switches.h',
6573
'<(DEPTH)/chrome/common/extensions/draggable_region.cc',
6674
'<(DEPTH)/chrome/common/extensions/draggable_region.h',
6775
'<(DEPTH)/chrome/common/zip.cc',

src/shell_browser_main_parts.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "content/nw/src/shell_browser_main_parts.h"
2222

23+
#include "base/bind.h"
2324
#include "base/command_line.h"
2425
#include "base/string_number_conversions.h"
2526
#include "base/threading/thread_restrictions.h"
@@ -95,6 +96,15 @@ void ShellBrowserMainParts::Init() {
9596
off_the_record_browser_context_.reset(
9697
new ShellBrowserContext(true, package()));
9798

99+
// OS X automatically handles multi process issue for us, so we don't need
100+
// to check for other instances of node-webkit on Mac.
101+
#if !defined(MAC_OSX)
102+
process_singleton_.reset(new ProcessSingleton(browser_context_->GetPath()));
103+
process_singleton_->NotifyOtherProcessOrCreate(
104+
base::Bind(&ShellBrowserMainParts::ProcessSingletonNotificationCallback,
105+
base::Unretained(this)));
106+
#endif
107+
98108
net::NetModule::SetResourceProvider(PlatformResourceProvider);
99109

100110
int port = 0;
@@ -121,4 +131,11 @@ void ShellBrowserMainParts::Init() {
121131
NULL);
122132
}
123133

134+
bool ShellBrowserMainParts::ProcessSingletonNotificationCallback(
135+
const CommandLine& command_line,
136+
const FilePath& current_directory) {
137+
LOG(ERROR) << "ProcessSingletonNotificationCallback";
138+
return false;
139+
}
140+
124141
} // namespace content

src/shell_browser_main_parts.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "base/basictypes.h"
99
#include "base/memory/scoped_ptr.h"
10+
#include "chrome/browser/process_singleton.h"
1011
#include "content/public/browser/browser_main_parts.h"
1112

1213
namespace base {
@@ -17,6 +18,9 @@ namespace nw {
1718
class Package;
1819
}
1920

21+
class CommandLine;
22+
class FilePath;
23+
2024
namespace content {
2125

2226
class ShellBrowserContext;
@@ -46,10 +50,15 @@ class ShellBrowserMainParts : public BrowserMainParts {
4650
nw::Package* package() { return package_.get(); }
4751

4852
private:
53+
bool ProcessSingletonNotificationCallback(const CommandLine& command_line,
54+
const FilePath& current_directory);
55+
4956
scoped_ptr<ShellBrowserContext> browser_context_;
5057
scoped_ptr<ShellBrowserContext> off_the_record_browser_context_;
5158
scoped_ptr<nw::Package> package_;
5259

60+
scoped_ptr<ProcessSingleton> process_singleton_;
61+
5362
// For running content_browsertests.
5463
const MainFunctionParams& parameters_;
5564
bool run_message_loop_;

0 commit comments

Comments
 (0)