Merge pull request #9222 from alexstrat/add-os-process-id

Add OS pid to web-contents
This commit is contained in:
Kevin Sawicki 2017-05-15 13:28:47 -07:00 committed by GitHub
commit d79ac8d9c1
4 changed files with 27 additions and 0 deletions

View file

@ -41,6 +41,7 @@
#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/process/process_handle.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "brightray/browser/inspectable_web_contents.h" #include "brightray/browser/inspectable_web_contents.h"
@ -1007,6 +1008,11 @@ int WebContents::GetProcessID() const {
return web_contents()->GetRenderProcessHost()->GetID(); return web_contents()->GetRenderProcessHost()->GetID();
} }
int WebContents::GetOSProcessID() const {
auto process_handle = web_contents()->GetRenderProcessHost()->GetHandle();
return base::GetProcId(process_handle);
}
WebContents::Type WebContents::GetType() const { WebContents::Type WebContents::GetType() const {
return type_; return type_;
} }
@ -1754,6 +1760,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.MakeDestroyable() .MakeDestroyable()
.SetMethod("getId", &WebContents::GetID) .SetMethod("getId", &WebContents::GetID)
.SetMethod("getProcessId", &WebContents::GetProcessID) .SetMethod("getProcessId", &WebContents::GetProcessID)
.SetMethod("getOSProcessId", &WebContents::GetOSProcessID)
.SetMethod("equal", &WebContents::Equal) .SetMethod("equal", &WebContents::Equal)
.SetMethod("_loadURL", &WebContents::LoadURL) .SetMethod("_loadURL", &WebContents::LoadURL)
.SetMethod("downloadURL", &WebContents::DownloadURL) .SetMethod("downloadURL", &WebContents::DownloadURL)

View file

@ -83,6 +83,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
int64_t GetID() const; int64_t GetID() const;
int GetProcessID() const; int GetProcessID() const;
int GetOSProcessID() const;
Type GetType() const; Type GetType() const;
bool Equal(const WebContents* web_contents) const; bool Equal(const WebContents* web_contents) const;
void LoadURL(const GURL& url, const mate::Dictionary& options); void LoadURL(const GURL& url, const mate::Dictionary& options);

View file

@ -1289,6 +1289,10 @@ Setting the WebRTC IP handling policy allows you to control which IPs are
exposed via WebRTC. See [BrowserLeaks](https://browserleaks.com/webrtc) for exposed via WebRTC. See [BrowserLeaks](https://browserleaks.com/webrtc) for
more details. more details.
#### `contents.getOSProcessId()`
Returns `Integer` - The `pid` of the associated renderer process.
### Instance Properties ### Instance Properties
#### `contents.id` #### `contents.id`

View file

@ -324,6 +324,21 @@ describe('webContents module', function () {
}) })
}) })
describe('getOSProcessId()', function () {
it('returns a valid procress id', function () {
// load URL otherwise getOSProcessId() returns 0
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
const specWebContents = w.webContents
let pid = null
assert.doesNotThrow(function () {
pid = specWebContents.getOSProcessId()
})
assert(typeof pid === 'number', 'is a number')
assert(pid > 0, 'superior to 0')
})
})
describe('zoom api', () => { describe('zoom api', () => {
const zoomScheme = remote.getGlobal('zoomScheme') const zoomScheme = remote.getGlobal('zoomScheme')
const hostZoomMap = { const hostZoomMap = {