Add remote.getCurrentWebContents API
authorCheng Zhao <zcbenz@gmail.com>
Mon, 11 May 2015 06:05:20 +0000 (14:05 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 11 May 2015 06:05:20 +0000 (14:05 +0800)
atom/browser/lib/rpc-server.coffee
atom/renderer/api/lib/remote.coffee
docs/api/remote.md

index 1703f1e..48d00e9 100644 (file)
@@ -107,6 +107,9 @@ ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, guestInstanceId) ->
   catch e
     event.returnValue = errorToMeta e
 
+ipc.on 'ATOM_BROWSER_CURRENT_WEB_CONTENTS', (event) ->
+  event.returnValue = valueToMeta event.sender, event.sender
+
 ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, id, args) ->
   try
     args = unwrapArgs event.sender, args
index 673a01c..5696784 100644 (file)
@@ -110,13 +110,20 @@ exports.require = (module) ->
   meta = ipc.sendSync 'ATOM_BROWSER_REQUIRE', module
   moduleCache[module] = metaToValue meta
 
-# Get current window object.
+# Get current BrowserWindow object.
 windowCache = null
 exports.getCurrentWindow = ->
   return windowCache if windowCache?
   meta = ipc.sendSync 'ATOM_BROWSER_CURRENT_WINDOW', process.guestInstanceId
   windowCache = metaToValue meta
 
+# Get current WebContents object.
+webContentsCache = null
+exports.getCurrentWebContents = ->
+  return webContentsCache if webContentsCache?
+  meta = ipc.sendSync 'ATOM_BROWSER_CURRENT_WEB_CONTENTS'
+  webContentsCache = metaToValue meta
+
 # Get a global object in browser.
 exports.getGlobal = (name) ->
   meta = ipc.sendSync 'ATOM_BROWSER_GLOBAL', name
index 77e76ea..89bbc1f 100644 (file)
@@ -138,6 +138,10 @@ Returns the object returned by `require(module)` in the main process.
 Returns the [BrowserWindow](browser-window.md) object which this web page
 belongs to.
 
+## remote.getCurrentWebContent()
+
+Returns the WebContents object of this web page.
+
 ## remote.getGlobal(name)
 
 * `name` String