11# remote
22
33The ` remote ` module provides a simple way to do inter-process communication
4- between the renderer process and the browser process.
4+ between the renderer process and the main process.
55
66In atom-shell, only GUI-related modules are available in the renderer process.
7- Without the ` remote ` module, users who wanted to call a browser-side API in
7+ Without the ` remote ` module, users who wanted to call a main process API in
88the renderer process would have to explicitly send inter-process messages
9- to the browser process. With the ` remote ` module, users can invoke methods of
10- browser-side object without explicitly sending inter-process messages,
9+ to the main process. With the ` remote ` module, users can invoke methods of
10+ main process object without explicitly sending inter-process messages,
1111similar to Java's
1212[ RMI] ( http://en.wikipedia.org/wiki/Java_remote_method_invocation ) .
1313
@@ -23,43 +23,43 @@ win.loadUrl('https://github.com');
2323## Remote objects
2424
2525Each object (including functions) returned by the ` remote ` module represents an
26- object in the browser process (we call it a remote object or remote function).
26+ object in the main process (we call it a remote object or remote function).
2727When you invoke methods of a remote object, call a remote function, or create
2828a new object with the remote constructor (function), you are actually sending
2929synchronous inter-process messages.
3030
3131In the example above, both ` BrowserWindow ` and ` win ` were remote objects and
3232` new BrowserWindow ` didn't create a ` BrowserWindow ` object in the renderer process.
33- Instead, it created a ` BrowserWindow ` object in the browser process and returned the
33+ Instead, it created a ` BrowserWindow ` object in the main process and returned the
3434corresponding remote object in the renderer process, namely the ` win ` object.
3535
3636## Lifetime of remote objects
3737
3838Atom-shell makes sure that as long as the remote object in the renderer process
3939lives (in other words, has not been garbage collected), the corresponding object
40- in the browser process would never be released. When the remote object has been
41- garbage collected, the corresponding object in the browser process would be
40+ in the main process would never be released. When the remote object has been
41+ garbage collected, the corresponding object in the main process would be
4242dereferenced.
4343
4444If the remote object is leaked in renderer process (e.g. stored in a map but never
45- freed), the corresponding object in the browser process would also be leaked,
45+ freed), the corresponding object in the main process would also be leaked,
4646so you should be very careful not to leak remote objects.
4747
4848Primary value types like strings and numbers, however, are sent by copy.
4949
50- ## Passing callbacks to browser
50+ ## Passing callbacks to the main process
5151
52- Some APIs in the browser process accept callbacks, and it would be attempting to
52+ Some APIs in the main process accept callbacks, and it would be attempting to
5353pass callbacks when calling a remote function. The ` remote ` module does support
5454doing this, but you should also be extremely careful with this.
5555
56- First, in order to avoid deadlocks, the callbacks passed to the browser process
57- are called asynchronously, so you should not expect the browser process to
56+ First, in order to avoid deadlocks, the callbacks passed to the main process
57+ are called asynchronously, so you should not expect the main process to
5858get the return value of the passed callbacks.
5959
60- Second, the callbacks passed to the browser process will not get released
60+ Second, the callbacks passed to the main process will not get released
6161automatically after they are called. Instead, they will persistent until the
62- browser process garbage-collects them.
62+ main process garbage-collects them.
6363
6464For example, the following code seems innocent at first glance. It installs a
6565callback for the ` close ` event on a remote object:
@@ -71,19 +71,19 @@ remote.getCurrentWindow().on('close', function() {
7171});
7272```
7373
74- The problem is that the callback would be stored in the browser process until you
74+ The problem is that the callback would be stored in the main process until you
7575explicitly uninstall it! So each time you reload your window, the callback would
7676be installed again and previous callbacks would just leak. To make things
7777worse, since the context of previously installed callbacks have been released,
78- when the ` close ` event was emitted, exceptions would be raised in the browser process.
78+ when the ` close ` event was emitted, exceptions would be raised in the main process.
7979
8080Generally, unless you are clear what you are doing, you should always avoid
81- passing callbacks to the browser process.
81+ passing callbacks to the main process.
8282
8383## Remote buffer
8484
8585An instance of node's ` Buffer ` is an object, so when you get a ` Buffer ` from
86- the browser process, what you get is indeed a remote object (let's call it remote
86+ the main process, what you get is indeed a remote object (let's call it remote
8787buffer), and everything would just follow the rules of remote objects.
8888
8989However you should remember that although a remote buffer behaves like the real
@@ -110,7 +110,7 @@ in fact it was a remote buffer, and it was converted to string before it was
110110written to the file. Since ` buf ` contained binary data and could not be represented
111111by a UTF-8 encoded string, the written file was corrupted.
112112
113- The work-around is to write the ` buf ` in the browser process, where it is a real
113+ The work-around is to write the ` buf ` in the main process, where it is a real
114114` Buffer ` :
115115
116116``` javascript
@@ -131,7 +131,7 @@ too, and data corruption could happen when it contains binary data.
131131
132132* ` module ` String
133133
134- Returns the object returned by ` require(module) ` in the browser process.
134+ Returns the object returned by ` require(module) ` in the main process.
135135
136136## remote.getCurrentWindow()
137137
@@ -142,10 +142,10 @@ belongs to.
142142
143143* ` name ` String
144144
145- Returns the global variable of ` name ` (e.g. ` global[name] ` ) in the browser
145+ Returns the global variable of ` name ` (e.g. ` global[name] ` ) in the main
146146process.
147147
148148## remote.process
149149
150- Returns the ` process ` object in the browser process. This is the same as
150+ Returns the ` process ` object in the main process. This is the same as
151151` remote.getGlobal('process') ` , but gets cached.
0 commit comments