| OLD | NEW |
| (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 | |
| OLD | NEW |