| 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 CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class WebUIDataSource; | 22 class WebUIDataSource; |
| 23 } | 23 } |
| 24 | 24 |
| 25 class MojoWebUIControllerBase : public content::WebUIController { | 25 class MojoWebUIControllerBase : public content::WebUIController { |
| 26 public: | 26 public: |
| 27 explicit MojoWebUIControllerBase(content::WebUI* contents); | 27 explicit MojoWebUIControllerBase(content::WebUI* contents); |
| 28 virtual ~MojoWebUIControllerBase(); | 28 virtual ~MojoWebUIControllerBase(); |
| 29 | 29 |
| 30 // WebUIController overrides: | 30 // WebUIController overrides: |
| 31 virtual void RenderViewCreated( | 31 virtual void RenderViewCreated( |
| 32 content::RenderViewHost* render_view_host) OVERRIDE; | 32 content::RenderViewHost* render_view_host) override; |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 // Invoke to register mapping between binding file and resource id (IDR_...). | 35 // Invoke to register mapping between binding file and resource id (IDR_...). |
| 36 void AddMojoResourcePath(const std::string& path, int resource_id); | 36 void AddMojoResourcePath(const std::string& path, int resource_id); |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 // Bindings files are registered here. | 39 // Bindings files are registered here. |
| 40 content::WebUIDataSource* mojo_data_source_; | 40 content::WebUIDataSource* mojo_data_source_; |
| 41 | 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(MojoWebUIControllerBase); | 42 DISALLOW_COPY_AND_ASSIGN(MojoWebUIControllerBase); |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 // MojoWebUIController is intended for web ui pages that use mojo. It is | 45 // MojoWebUIController is intended for web ui pages that use mojo. It is |
| 46 // expected that subclasses will do two things: | 46 // expected that subclasses will do two things: |
| 47 // . In the constructor invoke AddMojoResourcePath() to register the bindings | 47 // . In the constructor invoke AddMojoResourcePath() to register the bindings |
| 48 // files, eg: | 48 // files, eg: |
| 49 // AddMojoResourcePath("chrome/browser/ui/webui/omnibox/omnibox.mojom", | 49 // AddMojoResourcePath("chrome/browser/ui/webui/omnibox/omnibox.mojom", |
| 50 // IDR_OMNIBOX_MOJO_JS); | 50 // IDR_OMNIBOX_MOJO_JS); |
| 51 // . Override CreateUIHandler() to create the implementation of the bindings. | 51 // . Override CreateUIHandler() to create the implementation of the bindings. |
| 52 template <typename Interface> | 52 template <typename Interface> |
| 53 class MojoWebUIController : public MojoWebUIControllerBase { | 53 class MojoWebUIController : public MojoWebUIControllerBase { |
| 54 public: | 54 public: |
| 55 explicit MojoWebUIController(content::WebUI* contents) | 55 explicit MojoWebUIController(content::WebUI* contents) |
| 56 : MojoWebUIControllerBase(contents), weak_factory_(this) {} | 56 : MojoWebUIControllerBase(contents), weak_factory_(this) {} |
| 57 virtual ~MojoWebUIController() {} | 57 virtual ~MojoWebUIController() {} |
| 58 virtual void RenderViewCreated( | 58 virtual void RenderViewCreated( |
| 59 content::RenderViewHost* render_view_host) OVERRIDE { | 59 content::RenderViewHost* render_view_host) override { |
| 60 MojoWebUIControllerBase::RenderViewCreated(render_view_host); | 60 MojoWebUIControllerBase::RenderViewCreated(render_view_host); |
| 61 render_view_host->GetMainFrame()->GetServiceRegistry()-> | 61 render_view_host->GetMainFrame()->GetServiceRegistry()-> |
| 62 AddService<Interface>( | 62 AddService<Interface>( |
| 63 base::Bind(&MojoWebUIController::CreateAndStoreUIHandler, | 63 base::Bind(&MojoWebUIController::CreateAndStoreUIHandler, |
| 64 weak_factory_.GetWeakPtr())); | 64 weak_factory_.GetWeakPtr())); |
| 65 } | 65 } |
| 66 | 66 |
| 67 protected: | 67 protected: |
| 68 // Invoked to create the specific bindings implementation. | 68 // Invoked to create the specific bindings implementation. |
| 69 virtual scoped_ptr<MojoWebUIHandler> CreateUIHandler( | 69 virtual scoped_ptr<MojoWebUIHandler> CreateUIHandler( |
| 70 mojo::InterfaceRequest<Interface> request) = 0; | 70 mojo::InterfaceRequest<Interface> request) = 0; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 void CreateAndStoreUIHandler(mojo::InterfaceRequest<Interface> request) { | 73 void CreateAndStoreUIHandler(mojo::InterfaceRequest<Interface> request) { |
| 74 ui_handler_ = CreateUIHandler(request.Pass()); | 74 ui_handler_ = CreateUIHandler(request.Pass()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 scoped_ptr<MojoWebUIHandler> ui_handler_; | 77 scoped_ptr<MojoWebUIHandler> ui_handler_; |
| 78 | 78 |
| 79 base::WeakPtrFactory<MojoWebUIController> weak_factory_; | 79 base::WeakPtrFactory<MojoWebUIController> weak_factory_; |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(MojoWebUIController); | 81 DISALLOW_COPY_AND_ASSIGN(MojoWebUIController); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 #endif // CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ | 84 #endif // CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ |
| OLD | NEW |