| 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_WEB_UI_MOJO_H_ |
| 6 #define CONTENT_RENDERER_WEB_UI_MOJO_H_ | 6 #define CONTENT_RENDERER_WEB_UI_MOJO_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "content/public/renderer/render_frame_observer.h" | 10 #include "content/public/renderer/render_frame_observer.h" |
| 11 #include "content/public/renderer/render_view_observer.h" | 11 #include "content/public/renderer/render_view_observer.h" |
| 12 #include "content/public/renderer/render_view_observer_tracker.h" | 12 #include "content/public/renderer/render_view_observer_tracker.h" |
| 13 #include "mojo/public/system/core.h" | 13 #include "mojo/public/system/core_cpp.h" |
| 14 | 14 |
| 15 namespace gin { | 15 namespace gin { |
| 16 class PerContextData; | 16 class PerContextData; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class WebUIMojoContextState; | 21 class WebUIMojoContextState; |
| 22 | 22 |
| 23 // WebUIMojo is responsible for enabling the renderer side of mojo bindings. | 23 // WebUIMojo is responsible for enabling the renderer side of mojo bindings. |
| 24 // It creates (and destroys) a WebUIMojoContextState at the appropriate times | 24 // It creates (and destroys) a WebUIMojoContextState at the appropriate times |
| 25 // and handles the necessary browser messages. WebUIMojo destroys itself when | 25 // and handles the necessary browser messages. WebUIMojo destroys itself when |
| 26 // the RendererView it is created with is destroyed. | 26 // the RendererView it is created with is destroyed. |
| 27 class WebUIMojo | 27 class WebUIMojo |
| 28 : public RenderViewObserver, | 28 : public RenderViewObserver, |
| 29 public RenderViewObserverTracker<WebUIMojo> { | 29 public RenderViewObserverTracker<WebUIMojo> { |
| 30 public: | 30 public: |
| 31 explicit WebUIMojo(RenderView* render_view); | 31 explicit WebUIMojo(RenderView* render_view); |
| 32 | 32 |
| 33 // Sets the handle to the current WebUI. |
| 34 void SetBrowserHandle(mojo::ScopedMessagePipeHandle handle); |
| 35 |
| 33 private: | 36 private: |
| 34 class MainFrameObserver : public RenderFrameObserver { | 37 class MainFrameObserver : public RenderFrameObserver { |
| 35 public: | 38 public: |
| 36 explicit MainFrameObserver(WebUIMojo* web_ui_mojo); | 39 explicit MainFrameObserver(WebUIMojo* web_ui_mojo); |
| 37 virtual ~MainFrameObserver(); | 40 virtual ~MainFrameObserver(); |
| 38 | 41 |
| 39 // RenderFrameObserver overrides: | 42 // RenderFrameObserver overrides: |
| 40 virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context, | 43 virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context, |
| 41 int world_id) OVERRIDE; | 44 int world_id) OVERRIDE; |
| 42 | 45 |
| 43 private: | 46 private: |
| 44 WebUIMojo* web_ui_mojo_; | 47 WebUIMojo* web_ui_mojo_; |
| 45 | 48 |
| 46 DISALLOW_COPY_AND_ASSIGN(MainFrameObserver); | 49 DISALLOW_COPY_AND_ASSIGN(MainFrameObserver); |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 virtual ~WebUIMojo(); | 52 virtual ~WebUIMojo(); |
| 50 | 53 |
| 51 // Invoked from ViewMsg_SetBrowserHandle. Passes handle to current | |
| 52 // MojoWebUIContextState. | |
| 53 void OnSetBrowserHandle(MojoHandle handle); | |
| 54 | |
| 55 void CreateContextState(); | 54 void CreateContextState(); |
| 56 void DestroyContextState(v8::Handle<v8::Context> context); | 55 void DestroyContextState(v8::Handle<v8::Context> context); |
| 57 | 56 |
| 58 WebUIMojoContextState* GetContextState(); | 57 WebUIMojoContextState* GetContextState(); |
| 59 | 58 |
| 60 // RenderViewObserver overrides: | 59 // RenderViewObserver overrides: |
| 61 virtual void DidClearWindowObject(blink::WebFrame* frame, | 60 virtual void DidClearWindowObject(blink::WebFrame* frame, |
| 62 int world_id) OVERRIDE; | 61 int world_id) OVERRIDE; |
| 63 | 62 |
| 64 MainFrameObserver main_frame_observer_; | 63 MainFrameObserver main_frame_observer_; |
| 65 | 64 |
| 66 DISALLOW_COPY_AND_ASSIGN(WebUIMojo); | 65 DISALLOW_COPY_AND_ASSIGN(WebUIMojo); |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 } // namespace content | 68 } // namespace content |
| 70 | 69 |
| 71 #endif // CONTENT_RENDERER_WEB_UI_MOJO_H_ | 70 #endif // CONTENT_RENDERER_WEB_UI_MOJO_H_ |
| OLD | NEW |