Chromium Code Reviews| 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 "content/public/renderer/render_frame.h" | |
| 8 #include "gin/per_context_data.h" | |
| 9 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 10 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 11 #include "third_party/WebKit/public/web/WebScriptSource.h" | |
| 12 | |
| 13 namespace chromecast { | |
| 14 namespace shell { | |
| 15 | |
| 16 const char kCastContextData[] = "CastContextData"; | |
| 17 | |
| 18 CastGinRunner::CastGinRunner(content::RenderFrame* render_frame, | |
| 19 blink::WebFrame* frame, | |
| 20 gin::ContextHolder* context_holder) | |
| 21 : content::RenderFrameObserver(render_frame), | |
| 22 frame_(frame), | |
| 23 context_holder_(context_holder) { | |
| 24 DCHECK(context_holder); | |
| 25 DCHECK(frame_); | |
| 26 v8::Isolate::Scope isolate_scope(context_holder->isolate()); | |
| 27 v8::HandleScope handle_scope(context_holder->isolate()); | |
| 28 // Note: this installs the runner globally. If we need to support more than | |
| 29 // one runner at a time we'll have to revisit this. | |
| 30 gin::PerContextData::From(context_holder->context())->set_runner(this); | |
| 31 } | |
| 32 | |
| 33 void CastGinRunner::Run(const std::string& source, | |
| 34 const std::string& resource_name) { | |
| 35 frame_->executeScript( | |
| 36 blink::WebScriptSource(blink::WebString::fromUTF8(source))); | |
| 37 } | |
| 38 | |
| 39 v8::Local<v8::Value> CastGinRunner::Call(v8::Local<v8::Function> function, | |
| 40 v8::Local<v8::Value> receiver, | |
| 41 int argc, | |
| 42 v8::Local<v8::Value> argv[]) { | |
| 43 return frame_->callFunctionEvenIfScriptDisabled(function, receiver, argc, | |
| 44 argv); | |
| 45 } | |
| 46 | |
| 47 gin::ContextHolder* CastGinRunner::GetContextHolder() { | |
| 48 return context_holder_; | |
| 49 } | |
| 50 | |
| 51 void CastGinRunner::WillReleaseScriptContext(v8::Local<v8::Context> context, | |
| 52 int world_id) { | |
| 53 gin::PerContextData* context_data = gin::PerContextData::From(context); | |
| 54 if (!context_data) | |
| 55 return; | |
| 56 context_data->RemoveUserData(kCastContextData); | |
| 57 } | |
| 58 | |
| 59 void CastGinRunner::DidClearWindowObject() { | |
| 60 v8::Local<v8::Context> context = | |
| 61 render_frame()->GetWebFrame()->mainWorldScriptContext(); | |
| 62 gin::PerContextData* context_data = gin::PerContextData::From(context); | |
| 63 if (!context_data) | |
| 64 return; | |
| 65 context_data->RemoveUserData(kCastContextData); | |
| 66 } | |
| 67 | |
| 68 void CastGinRunner::OnDestruct() { | |
| 69 v8::Local<v8::Context> context = | |
|
derekjchow1
2016/09/16 17:02:01
This function should call the destructor of this c
| |
| 70 render_frame()->GetWebFrame()->mainWorldScriptContext(); | |
| 71 gin::PerContextData* context_data = gin::PerContextData::From(context); | |
| 72 if (!context_data) | |
| 73 return; | |
| 74 context_data->RemoveUserData(kCastContextData); | |
| 75 } | |
| 76 | |
| 77 } // namespace shell | |
| 78 } // namespace chromecast | |
| OLD | NEW |