OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #include "chromecast/renderer/cast_gin_runner.h" |
| 6 |
| 7 #include "gin/per_context_data.h" |
| 8 #include "third_party/WebKit/public/web/WebFrame.h" |
| 9 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 10 |
| 11 namespace chromecast { |
| 12 namespace shell { |
| 13 |
| 14 CastGinRunner::CastGinRunner(blink::WebFrame* frame, |
| 15 gin::ContextHolder* context_holder) |
| 16 : frame_(frame), context_holder_(context_holder) { |
| 17 DCHECK(context_holder); |
| 18 DCHECK(frame_); |
| 19 v8::Isolate::Scope isolate_scope(context_holder->isolate()); |
| 20 v8::HandleScope handle_scope(context_holder->isolate()); |
| 21 // Note: this installs the runner globally. If we need to support more than |
| 22 // one runner at a time we'll have to revisit this. |
| 23 gin::PerContextData::From(context_holder->context())->set_runner(this); |
| 24 } |
| 25 |
| 26 void CastGinRunner::Run(const std::string& source, |
| 27 const std::string& resource_name) { |
| 28 frame_->executeScript( |
| 29 blink::WebScriptSource(blink::WebString::fromUTF8(source))); |
| 30 } |
| 31 |
| 32 v8::Local<v8::Value> CastGinRunner::Call(v8::Local<v8::Function> function, |
| 33 v8::Local<v8::Value> receiver, |
| 34 int argc, |
| 35 v8::Local<v8::Value> argv[]) { |
| 36 return frame_->callFunctionEvenIfScriptDisabled(function, receiver, argc, |
| 37 argv); |
| 38 } |
| 39 |
| 40 gin::ContextHolder* CastGinRunner::GetContextHolder() { |
| 41 return context_holder_; |
| 42 } |
| 43 |
| 44 } // namespace shell |
| 45 } // namespace chromecast |
OLD | NEW |