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

Side by Side Diff: sky/viewer/script/script_runner.cc

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « sky/viewer/script/script_runner.h ('k') | sky/viewer/script/support.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "sky/viewer/script/script_runner.h"
6
7 #include "gin/per_context_data.h"
8 #include "gin/try_catch.h"
9 #include "sky/engine/public/web/WebFrame.h"
10 #include "sky/engine/public/web/WebScriptSource.h"
11 #include "sky/engine/public/web/WebView.h"
12 #include "v8/include/v8.h"
13 #include <iostream>
14
15 namespace sky {
16
17 ScriptRunner::ScriptRunner(blink::WebFrame* frame,
18 v8::Handle<v8::Context> context)
19 : frame_(frame),
20 context_holder_(nullptr) {
21 gin::PerContextData* context_data = gin::PerContextData::From(context);
22 context_data->set_runner(this);
23 context_holder_ = context_data->context_holder();
24 }
25
26 ScriptRunner::~ScriptRunner() {
27 }
28
29 void ScriptRunner::Run(const std::string& source,
30 const std::string& resource_name) {
31 gin::TryCatch try_catch;
32 frame_->executeScript(blink::WebScriptSource(
33 blink::WebString::fromUTF8(source),
34 GURL("internal-resouce:" + resource_name)));
35 // FIXME: We should really log to the console rather than to INFO.
36 if (try_catch.HasCaught())
37 std::cout << try_catch.GetStackTrace();
38 }
39
40 v8::Handle<v8::Value> ScriptRunner::Call(v8::Handle<v8::Function> function,
41 v8::Handle<v8::Value> receiver,
42 int argc,
43 v8::Handle<v8::Value> argv[]) {
44 gin::TryCatch try_catch;
45 v8::Handle<v8::Value> result = frame_->callFunctionEvenIfScriptDisabled(
46 function, receiver, argc, argv);
47 if (try_catch.HasCaught())
48 std::cout << try_catch.GetStackTrace();
49 return result;
50 }
51
52 gin::ContextHolder* ScriptRunner::GetContextHolder() {
53 return context_holder_;
54 }
55
56 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/script/script_runner.h ('k') | sky/viewer/script/support.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698