From a7c3bdbf5d51df8be9fea27e08b5134b8cb43c43 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 22 Apr 2013 16:27:34 +0800 Subject: [PATCH] Separate AtomBindings for renderer. --- atom.gyp | 2 ++ common/api/atom_bindings.cc | 17 ----------------- common/api/atom_bindings.h | 3 --- renderer/api/atom_renderer_bindings.cc | 34 ++++++++++++++++++++++++++++++++++ renderer/api/atom_renderer_bindings.h | 26 ++++++++++++++++++++++++++ renderer/atom_render_view_observer.cc | 2 +- renderer/atom_renderer_client.cc | 4 ++-- renderer/atom_renderer_client.h | 6 +++--- 8 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 renderer/api/atom_renderer_bindings.cc create mode 100644 renderer/api/atom_renderer_bindings.h diff --git a/atom.gyp b/atom.gyp index 0f3b3ed..8182e82 100644 --- a/atom.gyp +++ b/atom.gyp @@ -52,6 +52,8 @@ 'common/options_switches.h', 'common/v8_value_converter_impl.cc', 'common/v8_value_converter_impl.h', + 'renderer/api/atom_renderer_bindings.cc', + 'renderer/api/atom_renderer_bindings.h', 'renderer/atom_render_view_observer.cc', 'renderer/atom_render_view_observer.h', 'renderer/atom_renderer_client.cc', diff --git a/common/api/atom_bindings.cc b/common/api/atom_bindings.cc index 75f589e..bbaf0e5 100644 --- a/common/api/atom_bindings.cc +++ b/common/api/atom_bindings.cc @@ -5,7 +5,6 @@ #include "common/api/atom_bindings.h" #include "base/logging.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "vendor/node/src/node.h" namespace atom { @@ -72,20 +71,4 @@ v8::Handle AtomBindings::Binding(const v8::Arguments& args) { v8::String::New("No such module"))); } -void AtomBindings::BindToFrame(WebKit::WebFrame* frame) { - v8::HandleScope handle_scope; - - v8::Handle context = frame->mainWorldScriptContext(); - if (context.IsEmpty()) - return; - - v8::Context::Scope scope(context); - - v8::Handle process = - context->Global()->Get(v8::String::New("process"))->ToObject(); - DCHECK(!process.IsEmpty()); - - AtomBindings::BindTo(process); -} - } // namespace atom diff --git a/common/api/atom_bindings.h b/common/api/atom_bindings.h index e778fa5..fac8c2f 100644 --- a/common/api/atom_bindings.h +++ b/common/api/atom_bindings.h @@ -23,9 +23,6 @@ class AtomBindings { // load native code from atom-shell instead. virtual void BindTo(v8::Handle process); - // Call BindTo for process object of the frame. - void BindToFrame(WebKit::WebFrame* frame); - private: static v8::Handle Binding(const v8::Arguments& args); diff --git a/renderer/api/atom_renderer_bindings.cc b/renderer/api/atom_renderer_bindings.cc new file mode 100644 index 0000000..3b2a600 --- /dev/null +++ b/renderer/api/atom_renderer_bindings.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "renderer/api/atom_renderer_bindings.h" + +#include "base/logging.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" + +namespace atom { + +AtomRendererBindings::AtomRendererBindings() { +} + +AtomRendererBindings::~AtomRendererBindings() { +} + +void AtomRendererBindings::BindToFrame(WebKit::WebFrame* frame) { + v8::HandleScope handle_scope; + + v8::Handle context = frame->mainWorldScriptContext(); + if (context.IsEmpty()) + return; + + v8::Context::Scope scope(context); + + v8::Handle process = + context->Global()->Get(v8::String::New("process"))->ToObject(); + DCHECK(!process.IsEmpty()); + + AtomBindings::BindTo(process); +} + +} // namespace atom diff --git a/renderer/api/atom_renderer_bindings.h b/renderer/api/atom_renderer_bindings.h new file mode 100644 index 0000000..1c18d03 --- /dev/null +++ b/renderer/api/atom_renderer_bindings.h @@ -0,0 +1,26 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATOM_RENDERER_API_ATOM_RENDERER_BINDINGS_ +#define ATOM_RENDERER_API_ATOM_RENDERER_BINDINGS_ + +#include "common/api/atom_bindings.h" + +namespace atom { + +class AtomRendererBindings : public AtomBindings { + public: + AtomRendererBindings(); + virtual ~AtomRendererBindings(); + + // Call BindTo for process object of the frame. + void BindToFrame(WebKit::WebFrame* frame); + + private: + DISALLOW_COPY_AND_ASSIGN(AtomRendererBindings); +}; + +} // namespace atom + +#endif // ATOM_RENDERER_API_ATOM_BINDINGS_ diff --git a/renderer/atom_render_view_observer.cc b/renderer/atom_render_view_observer.cc index 615434c..e9e5fbe 100644 --- a/renderer/atom_render_view_observer.cc +++ b/renderer/atom_render_view_observer.cc @@ -7,8 +7,8 @@ #include #include -#include "common/api/atom_bindings.h" #include "common/node_bindings.h" +#include "renderer/api/atom_renderer_bindings.h" #include "renderer/atom_renderer_client.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "v8/include/v8.h" diff --git a/renderer/atom_renderer_client.cc b/renderer/atom_renderer_client.cc index 1029bdb..8e27865 100644 --- a/renderer/atom_renderer_client.cc +++ b/renderer/atom_renderer_client.cc @@ -4,8 +4,8 @@ #include "renderer/atom_renderer_client.h" -#include "common/api/atom_bindings.h" #include "common/node_bindings.h" +#include "renderer/api/atom_renderer_bindings.h" #include "renderer/atom_render_view_observer.h" #include "vendor/node/src/node_internals.h" @@ -16,7 +16,7 @@ extern void SetNodeContext(v8::Persistent context); namespace atom { AtomRendererClient::AtomRendererClient() - : atom_bindings_(new AtomBindings), + : atom_bindings_(new AtomRendererBindings), node_bindings_(NodeBindings::Create(false)) { } diff --git a/renderer/atom_renderer_client.h b/renderer/atom_renderer_client.h index 2cc0716..9ebd375 100644 --- a/renderer/atom_renderer_client.h +++ b/renderer/atom_renderer_client.h @@ -9,7 +9,7 @@ namespace atom { -class AtomBindings; +class AtomRendererBindings; class NodeBindings; class AtomRendererClient : public content::ContentRendererClient { @@ -17,14 +17,14 @@ class AtomRendererClient : public content::ContentRendererClient { AtomRendererClient(); virtual ~AtomRendererClient(); - AtomBindings* atom_bindings() const { return atom_bindings_.get(); } + AtomRendererBindings* atom_bindings() const { return atom_bindings_.get(); } NodeBindings* node_bindings() const { return node_bindings_.get(); } private: virtual void RenderThreadStarted() OVERRIDE; virtual void RenderViewCreated(content::RenderView*) OVERRIDE; - scoped_ptr atom_bindings_; + scoped_ptr atom_bindings_; scoped_ptr node_bindings_; DISALLOW_COPY_AND_ASSIGN(AtomRendererClient); -- 2.7.4