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

Unified Diff: chromecast/renderer/cast_gin_runner.cc

Issue 2535313004: [Chromecast] Clarify lifetime of CastGinRunner. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « chromecast/renderer/cast_gin_runner.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/renderer/cast_gin_runner.cc
diff --git a/chromecast/renderer/cast_gin_runner.cc b/chromecast/renderer/cast_gin_runner.cc
index 7d9db16f9a8d2d198be730369e575f0b85ff6a94..10b4f62a0142a31ffc20ea38c5c427a79dfdb897 100644
--- a/chromecast/renderer/cast_gin_runner.cc
+++ b/chromecast/renderer/cast_gin_runner.cc
@@ -7,36 +7,42 @@
#include "content/public/renderer/render_frame.h"
#include "gin/per_context_data.h"
#include "third_party/WebKit/public/web/WebFrame.h"
+#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
namespace chromecast {
namespace shell {
-CastGinRunner::CastGinRunner(content::RenderFrame* render_frame)
- : content::RenderFrameObserver(render_frame),
- frame_(render_frame->GetWebFrame()),
- context_holder_(
- gin::PerContextData::From(frame_->mainWorldScriptContext())
- ->context_holder()) {
- DCHECK(frame_);
- DCHECK(context_holder_);
+namespace {
+const void* kCastGinRunnerKey = static_cast<const void*>(kCastGinRunnerKey);
slan 2016/11/30 19:26:09 kCastContextData? (with declaration above?)
derekjchow1 2016/11/30 22:32:34 Done.
+}
+
+// static
+CastGinRunner* CastGinRunner::Get(content::RenderFrame* render_frame) {
+ blink::WebFrame* frame = render_frame->GetWebFrame();
slan 2016/11/30 19:26:09 nit: DCHECK(render_frame)
derekjchow1 2016/11/30 22:32:34 Done.
+ v8::HandleScope handle_scope(blink::mainThreadIsolate());
gin::PerContextData* context_data =
- gin::PerContextData::From(frame_->mainWorldScriptContext());
+ gin::PerContextData::From(frame->mainWorldScriptContext());
+ CastGinRunner* runner =
+ static_cast<CastGinRunner*>(context_data->GetUserData(kCastGinRunnerKey));
+ return runner ? runner : new CastGinRunner(frame, context_data);
+}
- v8::Isolate::Scope isolate_scope(context_holder_->isolate());
- v8::HandleScope handle_scope(context_holder_->isolate());
+CastGinRunner::CastGinRunner(blink::WebFrame* frame,
+ gin::PerContextData* context_data)
+ : frame_(frame), context_holder_(context_data->context_holder()) {
+ DCHECK(frame_);
+ DCHECK(context_holder_);
- context_data->SetUserData(kCastContextData, this);
+ context_data->SetUserData(kCastGinRunnerKey, this);
slan 2016/11/30 19:26:09 Can you add a comment here that |context_data| tak
derekjchow1 2016/11/30 22:32:34 Done.
// Note: this installs the runner globally. If we need to support more than
// one runner at a time we'll have to revisit this.
context_data->set_runner(this);
}
-CastGinRunner::~CastGinRunner() {
- RemoveUserData(render_frame()->GetWebFrame()->mainWorldScriptContext());
-}
+CastGinRunner::~CastGinRunner() {}
void CastGinRunner::Run(const std::string& source,
const std::string& resource_name) {
@@ -56,31 +62,5 @@ gin::ContextHolder* CastGinRunner::GetContextHolder() {
return context_holder_;
}
-void CastGinRunner::WillReleaseScriptContext(v8::Local<v8::Context> context,
- int world_id) {
- RemoveUserDataFromMainWorldContext();
-}
-
-void CastGinRunner::DidClearWindowObject() {
- RemoveUserDataFromMainWorldContext();
-}
-
-void CastGinRunner::OnDestruct() {
- RemoveUserDataFromMainWorldContext();
-}
-
-void CastGinRunner::RemoveUserDataFromMainWorldContext() {
- v8::HandleScope handle_scope(context_holder_->isolate());
- RemoveUserData(render_frame()->GetWebFrame()->mainWorldScriptContext());
-}
-
-void CastGinRunner::RemoveUserData(v8::Local<v8::Context> context) {
- gin::PerContextData* context_data = gin::PerContextData::From(context);
- if (!context_data)
- return;
-
- context_data->RemoveUserData(kCastContextData);
-}
-
} // namespace shell
} // namespace chromecast
« no previous file with comments | « chromecast/renderer/cast_gin_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698