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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
const {app, ipcMain, session, webContents, BrowserWindow} = require('electron')
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 path = require('path')