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

Side by Side Diff: chromecast/renderer/cast_gin_runner.h

Issue 2535313004: [Chromecast] Clarify lifetime of CastGinRunner. (Closed)
Patch Set: Address nits 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMECAST_RENDERER_CAST_GIN_RUNNER_H_ 5 #ifndef CHROMECAST_RENDERER_CAST_GIN_RUNNER_H_
6 #define CHROMECAST_RENDERER_CAST_GIN_RUNNER_H_ 6 #define CHROMECAST_RENDERER_CAST_GIN_RUNNER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/supports_user_data.h" 9 #include "base/supports_user_data.h"
10 #include "content/public/renderer/render_frame_observer.h"
11 #include "gin/runner.h" 10 #include "gin/runner.h"
12 11
13 namespace {
14 const char kCastContextData[] = "CastContextData";
15 }
16
17 namespace blink { 12 namespace blink {
18 class WebFrame; 13 class WebFrame;
19 } 14 }
20 15
16 namespace content {
17 class RenderFrame;
18 }
19
20 namespace gin {
21 class PerContextData;
22 }
23
21 namespace chromecast { 24 namespace chromecast {
22 namespace shell { 25 namespace shell {
23 26
24 // Implementation of gin::Runner that forwards Runner functions to WebFrame. 27 // Implementation of gin::Runner that forwards Runner functions to WebFrame.
25 class CastGinRunner : public gin::Runner, 28 // This class is lazily created per RenderFrame with the Get function and it's
26 public base::SupportsUserData::Data, 29 // lifetime is managed by the gin::PerContextData associated with the frame.
27 public content::RenderFrameObserver { 30 class CastGinRunner : public gin::Runner, public base::SupportsUserData::Data {
28 public: 31 public:
29 // Does not take ownership of ContextHolder. 32 // Gets or creates the CastGinRunner for this RenderFrame
30 CastGinRunner(content::RenderFrame* render_frame); 33 static CastGinRunner* Get(content::RenderFrame* render_frame);
31 ~CastGinRunner() override; 34 ~CastGinRunner() override;
32 35
33 // gin:Runner implementation: 36 // gin:Runner implementation:
34 void Run(const std::string& source, 37 void Run(const std::string& source,
35 const std::string& resource_name) override; 38 const std::string& resource_name) override;
36 v8::Local<v8::Value> Call(v8::Local<v8::Function> function, 39 v8::Local<v8::Value> Call(v8::Local<v8::Function> function,
37 v8::Local<v8::Value> receiver, 40 v8::Local<v8::Value> receiver,
38 int argc, 41 int argc,
39 v8::Local<v8::Value> argv[]) override; 42 v8::Local<v8::Value> argv[]) override;
40 gin::ContextHolder* GetContextHolder() override; 43 gin::ContextHolder* GetContextHolder() override;
41 44
42 // content::RenderFrameObserver implementation:
43 void WillReleaseScriptContext(v8::Local<v8::Context> context,
44 int world_id) override;
45 void DidClearWindowObject() override;
46 void OnDestruct() override;
47
48 private: 45 private:
49 void RemoveUserDataFromMainWorldContext(); 46 CastGinRunner(blink::WebFrame* frame, gin::PerContextData* context_data);
50 void RemoveUserData(v8::Local<v8::Context> context);
51 47
52 // Frame to execute script in. 48 // Frame to execute script in.
53 blink::WebFrame* const frame_; 49 blink::WebFrame* const frame_;
54 50
55 // Created by blink bindings to V8. 51 // Created by blink bindings to V8.
56 gin::ContextHolder* const context_holder_; 52 gin::ContextHolder* const context_holder_;
57 53
58 DISALLOW_COPY_AND_ASSIGN(CastGinRunner); 54 DISALLOW_COPY_AND_ASSIGN(CastGinRunner);
59 }; 55 };
60 56
61 } // namespace shell 57 } // namespace shell
62 } // namespace chromecast 58 } // namespace chromecast
63 59
64 #endif // CHROMECAST_RENDERER_CAST_GIN_RUNNER_H_ 60 #endif // CHROMECAST_RENDERER_CAST_GIN_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698