OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_RENDERER_WEB_UI_MOJO_H_ | 5 #ifndef CONTENT_RENDERER_MOJO_BINDINGS_CONTROLLER_H_ |
6 #define CONTENT_RENDERER_WEB_UI_MOJO_H_ | 6 #define CONTENT_RENDERER_MOJO_BINDINGS_CONTROLLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/macros.h" |
10 #include "content/public/renderer/render_frame_observer.h" | 11 #include "content/public/renderer/render_frame_observer.h" |
11 #include "content/public/renderer/render_view_observer.h" | 12 #include "content/public/renderer/render_view_observer.h" |
12 #include "content/public/renderer/render_view_observer_tracker.h" | 13 #include "content/public/renderer/render_view_observer_tracker.h" |
13 #include "mojo/public/cpp/system/core.h" | 14 #include "mojo/public/cpp/system/core.h" |
14 | 15 |
15 namespace gin { | 16 namespace gin { |
16 class PerContextData; | 17 class PerContextData; |
17 } | 18 } |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 class WebUIMojoContextState; | 22 class MojoContextState; |
22 | 23 |
23 // WebUIMojo is responsible for enabling the renderer side of mojo bindings. | 24 // MojoBindingsController is responsible for enabling the renderer side of mojo |
24 // It creates (and destroys) a WebUIMojoContextState at the appropriate times | 25 // bindings. It creates (and destroys) a MojoContextState at the appropriate |
25 // and handles the necessary browser messages. WebUIMojo destroys itself when | 26 // times and handles the necessary browser messages. MojoBindingsController |
26 // the RendererView it is created with is destroyed. | 27 // destroys itself when the RendererView it is created with is destroyed. |
27 class WebUIMojo | 28 class MojoBindingsController |
28 : public RenderViewObserver, | 29 : public RenderViewObserver, |
29 public RenderViewObserverTracker<WebUIMojo> { | 30 public RenderViewObserverTracker<MojoBindingsController> { |
30 public: | 31 public: |
31 explicit WebUIMojo(RenderView* render_view); | 32 explicit MojoBindingsController(RenderView* render_view); |
32 | 33 |
33 private: | 34 private: |
34 class MainFrameObserver : public RenderFrameObserver { | 35 class MainFrameObserver : public RenderFrameObserver { |
35 public: | 36 public: |
36 explicit MainFrameObserver(WebUIMojo* web_ui_mojo); | 37 explicit MainFrameObserver(MojoBindingsController* web_ui_mojo); |
37 ~MainFrameObserver() override; | 38 ~MainFrameObserver() override; |
38 | 39 |
39 // RenderFrameObserver overrides: | 40 // RenderFrameObserver overrides: |
40 void WillReleaseScriptContext(v8::Local<v8::Context> context, | 41 void WillReleaseScriptContext(v8::Local<v8::Context> context, |
41 int world_id) override; | 42 int world_id) override; |
42 void DidFinishDocumentLoad() override; | 43 void DidFinishDocumentLoad() override; |
43 // MainFrameObserver is inline owned by WebUIMojo and should not be | 44 // MainFrameObserver is inline owned by MojoBindingsController and should |
44 // destroyed when the main RenderFrame is deleted. Overriding the | 45 // not be destroyed when the main RenderFrame is deleted. Overriding the |
45 // OnDestruct method allows this object to remain alive and be cleaned | 46 // OnDestruct method allows this object to remain alive and be cleaned |
46 // up as part of WebUIMojo deletion. | 47 // up as part of MojoBindingsController deletion. |
47 void OnDestruct() override; | 48 void OnDestruct() override; |
48 | 49 |
49 private: | 50 private: |
50 WebUIMojo* web_ui_mojo_; | 51 MojoBindingsController* mojo_bindings_controller_; |
51 | 52 |
52 DISALLOW_COPY_AND_ASSIGN(MainFrameObserver); | 53 DISALLOW_COPY_AND_ASSIGN(MainFrameObserver); |
53 }; | 54 }; |
54 | 55 |
55 ~WebUIMojo() override; | 56 ~MojoBindingsController() override; |
56 | 57 |
57 void CreateContextState(); | 58 void CreateContextState(); |
58 void DestroyContextState(v8::Local<v8::Context> context); | 59 void DestroyContextState(v8::Local<v8::Context> context); |
59 | 60 |
60 // Invoked when the frame finishes loading. Invokes Run() on the | 61 // Invoked when the frame finishes loading. Invokes Run() on the |
61 // WebUIMojoContextState. | 62 // MojoContextState. |
62 void OnDidFinishDocumentLoad(); | 63 void OnDidFinishDocumentLoad(); |
63 | 64 |
64 WebUIMojoContextState* GetContextState(); | 65 MojoContextState* GetContextState(); |
65 | 66 |
66 // RenderViewObserver overrides: | 67 // RenderViewObserver overrides: |
67 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override; | 68 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override; |
68 void DidClearWindowObject(blink::WebLocalFrame* frame) override; | 69 void DidClearWindowObject(blink::WebLocalFrame* frame) override; |
69 | 70 |
70 MainFrameObserver main_frame_observer_; | 71 MainFrameObserver main_frame_observer_; |
71 | 72 |
72 DISALLOW_COPY_AND_ASSIGN(WebUIMojo); | 73 DISALLOW_COPY_AND_ASSIGN(MojoBindingsController); |
73 }; | 74 }; |
74 | 75 |
75 } // namespace content | 76 } // namespace content |
76 | 77 |
77 #endif // CONTENT_RENDERER_WEB_UI_MOJO_H_ | 78 #endif // CONTENT_RENDERER_MOJO_BINDINGS_CONTROLLER_H_ |
OLD | NEW |