Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8800)

Unified Diff: chromecast/renderer/cast_gin_runner.cc

Issue 2342563003: [chromecast] Enable Mojo javascript bindings for cast_shell (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f56cd487f6f04e839f8cefab69a4541e0f547449
--- /dev/null
+++ b/chromecast/renderer/cast_gin_runner.cc
@@ -0,0 +1,44 @@
+// 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) {
derekjchow1 2016/09/14 21:20:13 DCHECK(context_holder)?
jarhar 2016/09/15 00:32:42 Done.
+ 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
« chromecast/renderer/cast_gin_runner.h ('K') | « chromecast/renderer/cast_gin_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698