Commit df8e8c6e authored by jochen's avatar jochen Committed by Commit bot

Inline binding_helpers.h

This code is inlined all over the place, however, there's no good
location to put it. Just factoring it out in two places, however,
doesn't really make sense, so don't do it

R=mkwst@chromium.org
BUG=478250

Review URL: https://codereview.chromium.org/1141993002

Cr-Commit-Position: refs/heads/master@{#330308}
parent cfb07325
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_SHELL_RENDERER_BINDING_HELPERS_H_
#define CONTENT_SHELL_RENDERER_BINDING_HELPERS_H_
#include <string>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "gin/handle.h"
#include "gin/wrappable.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebKit.h"
namespace content {
template<class WrappedClass>
void InstallAsWindowProperties(WrappedClass* wrapped,
blink::WebFrame* frame,
const std::vector<std::string>& names) {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope context_scope(context);
gin::Handle<WrappedClass> bindings = gin::CreateHandle(isolate, wrapped);
if (bindings.IsEmpty())
return;
v8::Local<v8::Object> global = context->Global();
v8::Local<v8::Value> v8_bindings = bindings.ToV8();
for (size_t i = 0; i < names.size(); ++i)
global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
}
} // namespace content
#endif // CONTENT_SHELL_RENDERER_BINDING_HELPERS_H_
......@@ -5,13 +5,16 @@
#include "content/shell/renderer/ipc_echo.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "content/shell/common/shell_messages.h"
#include "content/shell/renderer/binding_helpers.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "ipc/ipc_sender.h"
#include "third_party/WebKit/public/web/WebDOMCustomEvent.h"
#include "third_party/WebKit/public/web/WebDOMEvent.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
namespace content {
......@@ -72,10 +75,21 @@ gin::ObjectTemplateBuilder IPCEchoBindings::GetObjectTemplateBuilder(
// static
void IPCEchoBindings::Install(base::WeakPtr<IPCEcho> echo,
blink::WebFrame* frame) {
std::vector<std::string> names;
names.push_back("ipcEcho");
return InstallAsWindowProperties(
new IPCEchoBindings(echo), frame, names);
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope context_scope(context);
IPCEchoBindings* wrapped = new IPCEchoBindings(echo);
gin::Handle<IPCEchoBindings> bindings = gin::CreateHandle(isolate, wrapped);
if (bindings.IsEmpty())
return;
v8::Local<v8::Object> global = context->Global();
v8::Local<v8::Value> v8_bindings = bindings.ToV8();
global->Set(gin::StringToV8(isolate, "ipcEcho"), v8_bindings);
}
IPCEcho::IPCEcho(blink::WebDocument document,
......
......@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "content/shell/common/test_runner/test_preferences.h"
#include "content/shell/renderer/binding_helpers.h"
#include "content/shell/renderer/test_runner/mock_credential_manager_client.h"
#include "content/shell/renderer/test_runner/mock_web_speech_recognizer.h"
#include "content/shell/renderer/test_runner/test_interfaces.h"
......@@ -327,11 +326,27 @@ gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
// static
void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
WebFrame* frame) {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
if (context.IsEmpty())
return;
v8::Context::Scope context_scope(context);
TestRunnerBindings* wrapped = new TestRunnerBindings(runner);
gin::Handle<TestRunnerBindings> bindings =
gin::CreateHandle(isolate, wrapped);
if (bindings.IsEmpty())
return;
v8::Local<v8::Object> global = context->Global();
v8::Local<v8::Value> v8_bindings = bindings.ToV8();
std::vector<std::string> names;
names.push_back("testRunner");
names.push_back("layoutTestController");
return InstallAsWindowProperties(
new TestRunnerBindings(runner), frame, names);
for (size_t i = 0; i < names.size(); ++i)
global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
}
TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment