Move node integration from RenderViewObserver to RendererClient.
This commit is contained in:
parent
02d94c8b2e
commit
df0094b6cb
6 changed files with 54 additions and 57 deletions
|
@ -4,9 +4,6 @@
|
|||
|
||||
#include "renderer/api/atom_renderer_bindings.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "common/v8/native_type_conversions.h"
|
||||
#include "content/public/renderer/render_view.h"
|
||||
#include "third_party/WebKit/public/web/WebFrame.h"
|
||||
|
@ -14,9 +11,7 @@
|
|||
|
||||
#include "common/v8/node_common.h"
|
||||
|
||||
using content::RenderView;
|
||||
using content::V8ValueConverter;
|
||||
using WebKit::WebFrame;
|
||||
|
||||
namespace atom {
|
||||
|
||||
|
@ -32,14 +27,13 @@ v8::Handle<v8::Object> GetProcessObject(v8::Handle<v8::Context> context) {
|
|||
|
||||
} // namespace
|
||||
|
||||
AtomRendererBindings::AtomRendererBindings(RenderView* render_view)
|
||||
: render_view_(render_view) {
|
||||
AtomRendererBindings::AtomRendererBindings() {
|
||||
}
|
||||
|
||||
AtomRendererBindings::~AtomRendererBindings() {
|
||||
}
|
||||
|
||||
void AtomRendererBindings::BindToFrame(WebFrame* frame) {
|
||||
void AtomRendererBindings::BindToFrame(WebKit::WebFrame* frame) {
|
||||
v8::HandleScope handle_scope(node_isolate);
|
||||
|
||||
v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
|
||||
|
@ -47,19 +41,19 @@ void AtomRendererBindings::BindToFrame(WebFrame* frame) {
|
|||
return;
|
||||
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
AtomBindings::BindTo(GetProcessObject(context));
|
||||
}
|
||||
|
||||
void AtomRendererBindings::OnBrowserMessage(const string16& channel,
|
||||
void AtomRendererBindings::OnBrowserMessage(content::RenderView* render_view,
|
||||
const string16& channel,
|
||||
const base::ListValue& args) {
|
||||
if (!render_view_->GetWebView())
|
||||
if (!render_view->GetWebView())
|
||||
return;
|
||||
|
||||
v8::HandleScope handle_scope(node_isolate);
|
||||
|
||||
v8::Local<v8::Context> context =
|
||||
render_view_->GetWebView()->mainFrame()->mainWorldScriptContext();
|
||||
render_view->GetWebView()->mainFrame()->mainWorldScriptContext();
|
||||
if (context.IsEmpty())
|
||||
return;
|
||||
|
||||
|
|
|
@ -25,19 +25,18 @@ namespace atom {
|
|||
|
||||
class AtomRendererBindings : public AtomBindings {
|
||||
public:
|
||||
explicit AtomRendererBindings(content::RenderView* render_view);
|
||||
AtomRendererBindings();
|
||||
virtual ~AtomRendererBindings();
|
||||
|
||||
// Call BindTo for process object of the frame.
|
||||
void BindToFrame(WebKit::WebFrame* frame);
|
||||
|
||||
// Dispatch messages from browser.
|
||||
void OnBrowserMessage(const string16& channel,
|
||||
void OnBrowserMessage(content::RenderView* render_view,
|
||||
const string16& channel,
|
||||
const base::ListValue& args);
|
||||
|
||||
private:
|
||||
content::RenderView* render_view_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomRendererBindings);
|
||||
};
|
||||
|
||||
|
|
|
@ -5,12 +5,11 @@
|
|||
#include "renderer/atom_render_view_observer.h"
|
||||
|
||||
#include "common/api/api_messages.h"
|
||||
#include "common/node_bindings.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "renderer/api/atom_renderer_bindings.h"
|
||||
#include "renderer/atom_renderer_client.h"
|
||||
#include "third_party/WebKit/public/web/WebDocument.h"
|
||||
#include "third_party/WebKit/public/web/WebDraggableRegion.h"
|
||||
#include "third_party/WebKit/public/web/WebDocument.h"
|
||||
#include "third_party/WebKit/public/web/WebFrame.h"
|
||||
|
||||
#include "common/v8/node_common.h"
|
||||
|
@ -23,36 +22,12 @@ AtomRenderViewObserver::AtomRenderViewObserver(
|
|||
content::RenderView* render_view,
|
||||
AtomRendererClient* renderer_client)
|
||||
: content::RenderViewObserver(render_view),
|
||||
atom_bindings_(new AtomRendererBindings(render_view)),
|
||||
renderer_client_(renderer_client) {
|
||||
}
|
||||
|
||||
AtomRenderViewObserver::~AtomRenderViewObserver() {
|
||||
}
|
||||
|
||||
void AtomRenderViewObserver::DidClearWindowObject(WebFrame* frame) {
|
||||
// Get the context.
|
||||
v8::HandleScope handle_scope(node_isolate);
|
||||
v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
|
||||
if (context.IsEmpty())
|
||||
return;
|
||||
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
// Check the existance of process object to prevent duplicate initialization.
|
||||
if (context->Global()->Has(v8::String::New("process")))
|
||||
return;
|
||||
|
||||
// Give the node loop a run to make sure everything is ready.
|
||||
renderer_client_->node_bindings()->RunMessageLoop();
|
||||
|
||||
// Setup node environment for each window.
|
||||
renderer_client_->node_bindings()->CreateEnvironment(context);
|
||||
|
||||
// Add atom-shell extended APIs.
|
||||
atom_bindings()->BindToFrame(frame);
|
||||
}
|
||||
|
||||
void AtomRenderViewObserver::DraggableRegionsChanged(WebKit::WebFrame* frame) {
|
||||
WebKit::WebVector<WebKit::WebDraggableRegion> webregions =
|
||||
frame->document().draggableRegions();
|
||||
|
@ -78,7 +53,8 @@ bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) {
|
|||
|
||||
void AtomRenderViewObserver::OnBrowserMessage(const string16& channel,
|
||||
const base::ListValue& args) {
|
||||
atom_bindings()->OnBrowserMessage(channel, args);
|
||||
renderer_client_->atom_bindings()->OnBrowserMessage(
|
||||
render_view(), channel, args);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#ifndef ATOM_RENDERER_ATOM_RENDER_VIEW_OBSERVER_
|
||||
#define ATOM_RENDERER_ATOM_RENDER_VIEW_OBSERVER_
|
||||
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "content/public/renderer/render_view_observer.h"
|
||||
|
||||
namespace base {
|
||||
|
@ -14,21 +13,16 @@ class ListValue;
|
|||
|
||||
namespace atom {
|
||||
|
||||
class AtomRendererBindings;
|
||||
class AtomRendererClient;
|
||||
|
||||
class AtomRenderViewObserver : content::RenderViewObserver {
|
||||
class AtomRenderViewObserver : public content::RenderViewObserver {
|
||||
public:
|
||||
explicit AtomRenderViewObserver(content::RenderView* render_view,
|
||||
AtomRendererClient* renderer_client);
|
||||
|
||||
AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); }
|
||||
|
||||
protected:
|
||||
virtual ~AtomRenderViewObserver();
|
||||
|
||||
virtual void DidClearWindowObject(WebKit::WebFrame*) OVERRIDE;
|
||||
|
||||
private:
|
||||
// content::RenderViewObserver implementation.
|
||||
virtual void DraggableRegionsChanged(WebKit::WebFrame* frame) OVERRIDE;
|
||||
|
@ -37,8 +31,6 @@ class AtomRenderViewObserver : content::RenderViewObserver {
|
|||
void OnBrowserMessage(const string16& channel,
|
||||
const base::ListValue& args);
|
||||
|
||||
scoped_ptr<AtomRendererBindings> atom_bindings_;
|
||||
|
||||
// Weak reference to renderer client.
|
||||
AtomRendererClient* renderer_client_;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "renderer/atom_renderer_client.h"
|
||||
|
||||
#include "common/node_bindings.h"
|
||||
#include "renderer/api/atom_renderer_bindings.h"
|
||||
#include "renderer/atom_render_view_observer.h"
|
||||
|
||||
#include "common/v8/node_common.h"
|
||||
|
@ -12,7 +13,8 @@
|
|||
namespace atom {
|
||||
|
||||
AtomRendererClient::AtomRendererClient()
|
||||
: node_bindings_(NodeBindings::Create(false)) {
|
||||
: node_bindings_(NodeBindings::Create(false)),
|
||||
atom_bindings_(new AtomRendererBindings) {
|
||||
}
|
||||
|
||||
AtomRendererClient::~AtomRendererClient() {
|
||||
|
@ -35,4 +37,29 @@ void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
|
|||
new AtomRenderViewObserver(render_view, this);
|
||||
}
|
||||
|
||||
void AtomRendererClient::DidCreateScriptContext(WebKit::WebFrame* frame,
|
||||
v8::Handle<v8::Context> context,
|
||||
int extension_group,
|
||||
int world_id) {
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
// Check the existance of process object to prevent duplicate initialization.
|
||||
if (context->Global()->Has(v8::String::New("process")))
|
||||
return;
|
||||
|
||||
// Give the node loop a run to make sure everything is ready.
|
||||
node_bindings_->RunMessageLoop();
|
||||
|
||||
// Setup node environment for each window.
|
||||
node_bindings_->CreateEnvironment(context);
|
||||
|
||||
// Add atom-shell extended APIs.
|
||||
atom_bindings_->BindToFrame(frame);
|
||||
}
|
||||
|
||||
void AtomRendererClient::WillReleaseScriptContext(WebKit::WebFrame* frame,
|
||||
v8::Handle<v8::Context>,
|
||||
int world_id) {
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_RENDERER_ATOM_RENDERER_CLIENT_
|
||||
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_
|
||||
#ifndef ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||
#define ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||
|
||||
#include "content/public/renderer/content_renderer_client.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class AtomRendererBindings;
|
||||
class NodeBindings;
|
||||
|
||||
class AtomRendererClient : public content::ContentRendererClient {
|
||||
|
@ -16,17 +17,25 @@ class AtomRendererClient : public content::ContentRendererClient {
|
|||
AtomRendererClient();
|
||||
virtual ~AtomRendererClient();
|
||||
|
||||
NodeBindings* node_bindings() const { return node_bindings_.get(); }
|
||||
AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); }
|
||||
|
||||
private:
|
||||
virtual void RenderThreadStarted() OVERRIDE;
|
||||
virtual void RenderViewCreated(content::RenderView*) OVERRIDE;
|
||||
virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
|
||||
v8::Handle<v8::Context> context,
|
||||
int extension_group,
|
||||
int world_id) OVERRIDE;
|
||||
virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
|
||||
v8::Handle<v8::Context>,
|
||||
int world_id) OVERRIDE;
|
||||
|
||||
scoped_ptr<NodeBindings> node_bindings_;
|
||||
scoped_ptr<AtomRendererBindings> atom_bindings_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomRendererClient);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_RENDERER_ATOM_RENDERER_CLIENT_
|
||||
#endif // ATOM_RENDERER_ATOM_RENDERER_CLIENT_H_
|
||||
|
|
Loading…
Reference in a new issue