Index: chromecast/renderer/cast_gin_runner.cc |
diff --git a/chromecast/renderer/cast_gin_runner.cc b/chromecast/renderer/cast_gin_runner.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e761ce4a410900605a34a172205c24d22db93cbd |
--- /dev/null |
+++ b/chromecast/renderer/cast_gin_runner.cc |
@@ -0,0 +1,45 @@ |
+// Copyright 2016 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. |
+ |
+#include "chromecast/renderer/cast_gin_runner.h" |
+ |
+#include "gin/per_context_data.h" |
+#include "third_party/WebKit/public/web/WebFrame.h" |
+#include "third_party/WebKit/public/web/WebScriptSource.h" |
+ |
+namespace chromecast { |
+namespace shell { |
+ |
+CastGinRunner::CastGinRunner(blink::WebFrame* frame, |
+ gin::ContextHolder* context_holder) |
+ : frame_(frame), context_holder_(context_holder) { |
+ DCHECK(context_holder); |
+ DCHECK(frame_); |
+ v8::Isolate::Scope isolate_scope(context_holder->isolate()); |
+ v8::HandleScope handle_scope(context_holder->isolate()); |
+ // Note: this installs the runner globally. If we need to support more than |
+ // one runner at a time we'll have to revisit this. |
+ gin::PerContextData::From(context_holder->context())->set_runner(this); |
+} |
+ |
+void CastGinRunner::Run(const std::string& source, |
+ const std::string& resource_name) { |
+ frame_->executeScript( |
+ blink::WebScriptSource(blink::WebString::fromUTF8(source))); |
+} |
+ |
+v8::Local<v8::Value> CastGinRunner::Call(v8::Local<v8::Function> function, |
+ v8::Local<v8::Value> receiver, |
+ int argc, |
+ v8::Local<v8::Value> argv[]) { |
+ return frame_->callFunctionEvenIfScriptDisabled(function, receiver, argc, |
+ argv); |
+} |
+ |
+gin::ContextHolder* CastGinRunner::GetContextHolder() { |
+ return context_holder_; |
+} |
+ |
+} // namespace shell |
+} // namespace chromecast |