Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / renderer / web_ui_runner.cc
blobf1d0cce17c19beda4141e41dab4c3b1614b0e02e
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/web_ui_runner.h"
7 #include "content/public/renderer/render_frame.h"
8 #include "gin/modules/module_registry.h"
9 #include "gin/per_context_data.h"
10 #include "gin/public/context_holder.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
12 #include "third_party/WebKit/public/web/WebScriptSource.h"
14 using v8::Context;
15 using v8::HandleScope;
16 using v8::Isolate;
17 using v8::Object;
18 using v8::ObjectTemplate;
19 using v8::Script;
21 namespace content {
23 WebUIRunner::WebUIRunner(blink::WebFrame* frame,
24 gin::ContextHolder* context_holder)
25 : frame_(frame),
26 context_holder_(context_holder) {
27 DCHECK(frame_);
28 v8::Isolate::Scope isolate_scope(context_holder->isolate());
29 HandleScope handle_scope(context_holder->isolate());
30 // Note: this installs the runner globally. If we need to support more than
31 // one runner at a time we'll have to revisit this.
32 gin::PerContextData::From(context_holder->context())->set_runner(this);
35 WebUIRunner::~WebUIRunner() {
38 void WebUIRunner::Run(const std::string& source,
39 const std::string& resource_name) {
40 frame_->executeScript(
41 blink::WebScriptSource(blink::WebString::fromUTF8(source)));
44 v8::Local<v8::Value> WebUIRunner::Call(v8::Local<v8::Function> function,
45 v8::Local<v8::Value> receiver,
46 int argc,
47 v8::Local<v8::Value> argv[]) {
48 return frame_->callFunctionEvenIfScriptDisabled(function, receiver, argc,
49 argv);
52 gin::ContextHolder* WebUIRunner::GetContextHolder() {
53 return context_holder_;
56 } // namespace content