Use RenderProcessPreferences for non-remote web contents

This commit is contained in:
Kevin Sawicki 2016-06-13 17:01:13 -07:00
parent 9223019af8
commit f25c1f864b
5 changed files with 16 additions and 12 deletions

View file

@ -4,6 +4,7 @@
#include "atom/browser/api/atom_api_render_process_preferences.h" #include "atom/browser/api/atom_api_render_process_preferences.h"
#include "atom/browser/api/atom_api_web_contents.h"
#include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_client.h"
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include "atom/browser/window_list.h" #include "atom/browser/window_list.h"
@ -19,18 +20,15 @@ namespace api {
namespace { namespace {
bool IsBrowserWindow(content::RenderProcessHost* process) { bool IsWebContents(v8::Isolate* isolate, content::RenderProcessHost* process) {
content::WebContents* web_contents = content::WebContents* web_contents =
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())-> static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->
GetWebContentsFromProcessID(process->GetID()); GetWebContentsFromProcessID(process->GetID());
if (!web_contents) if (!web_contents)
return false; return false;
NativeWindow* window = NativeWindow::FromWebContents(web_contents); auto api_web_contents = WebContents::CreateFrom(isolate, web_contents);
if (!window) return !api_web_contents->IsRemote();
return false;
return true;
} }
} // namespace } // namespace
@ -63,10 +61,11 @@ void RenderProcessPreferences::BuildPrototype(
// static // static
mate::Handle<RenderProcessPreferences> mate::Handle<RenderProcessPreferences>
RenderProcessPreferences::ForAllBrowserWindow(v8::Isolate* isolate) { RenderProcessPreferences::ForAllWebContents(v8::Isolate* isolate) {
return mate::CreateHandle( return mate::CreateHandle(
isolate, isolate,
new RenderProcessPreferences(isolate, base::Bind(&IsBrowserWindow))); new RenderProcessPreferences(isolate,
base::Bind(&IsWebContents, isolate)));
} }
} // namespace api } // namespace api
@ -78,8 +77,8 @@ namespace {
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused, void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) { v8::Local<v8::Context> context, void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports); mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("forAllBrowserWindow", dict.SetMethod("forAllWebContents",
&atom::api::RenderProcessPreferences::ForAllBrowserWindow); &atom::api::RenderProcessPreferences::ForAllWebContents);
} }
} // namespace } // namespace

View file

@ -17,7 +17,7 @@ class RenderProcessPreferences
: public mate::Wrappable<RenderProcessPreferences> { : public mate::Wrappable<RenderProcessPreferences> {
public: public:
static mate::Handle<RenderProcessPreferences> static mate::Handle<RenderProcessPreferences>
ForAllBrowserWindow(v8::Isolate* isolate); ForAllWebContents(v8::Isolate* isolate);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> prototype); v8::Local<v8::ObjectTemplate> prototype);

View file

@ -1197,6 +1197,10 @@ bool WebContents::IsGuest() const {
return type_ == WEB_VIEW; return type_ == WEB_VIEW;
} }
bool WebContents::IsRemote() const {
return type_ == REMOTE;
}
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) { v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
WebContentsPreferences* web_preferences = WebContentsPreferences* web_preferences =
WebContentsPreferences::FromWebContents(web_contents()); WebContentsPreferences::FromWebContents(web_contents());

View file

@ -139,6 +139,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Methods for creating <webview>. // Methods for creating <webview>.
void SetSize(const SetSizeParams& params); void SetSize(const SetSizeParams& params);
bool IsGuest() const; bool IsGuest() const;
bool IsRemote() const;
// Callback triggered on permission response. // Callback triggered on permission response.
void OnEnterFullscreenModeForTab(content::WebContents* source, void OnEnterFullscreenModeForTab(content::WebContents* source,

View file

@ -1,6 +1,6 @@
const {app, ipcMain, session, webContents, BrowserWindow} = require('electron') const {app, ipcMain, session, webContents, BrowserWindow} = require('electron')
const {getAllWebContents} = process.atomBinding('web_contents') const {getAllWebContents} = process.atomBinding('web_contents')
const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllBrowserWindow() const renderProcessPreferences = process.atomBinding('render_process_preferences').forAllWebContents()
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')