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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ 6#define CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ 7 8#include <string> 9 10#include "base/memory/scoped_ptr.h" 11#include "content/public/browser/web_ui_controller.h" 12#include "mojo/public/cpp/system/core.h" 13 14class MojoWebUIHandler; 15 16namespace content { 17class WebUIDataSource; 18} 19 20// MojoWebUIController is intended for web ui pages that use mojo. It is 21// expected that subclasses will do two things: 22// . In the constructor invoke AddMojoResourcePath() to register the bindings 23// files, eg: 24// AddMojoResourcePath("chrome/browser/ui/webui/omnibox/omnibox.mojom", 25// IDR_OMNIBOX_MOJO_JS); 26// . Override CreateUIHandler() to create the implementation of the bindings. 27class MojoWebUIController : public content::WebUIController { 28 public: 29 explicit MojoWebUIController(content::WebUI* contents); 30 virtual ~MojoWebUIController(); 31 32 // WebUIController overrides: 33 virtual void RenderViewCreated( 34 content::RenderViewHost* render_view_host) OVERRIDE; 35 36 protected: 37 // Invoke to register mapping between binding file and resource id (IDR_...). 38 void AddMojoResourcePath(const std::string& path, int resource_id); 39 40 // Invoked to create the specific bindings implementation. 41 virtual scoped_ptr<MojoWebUIHandler> CreateUIHandler( 42 mojo::ScopedMessagePipeHandle handle_to_page) = 0; 43 44 private: 45 // Bindings files are registered here. 46 content::WebUIDataSource* mojo_data_source_; 47 48 scoped_ptr<MojoWebUIHandler> ui_handler_; 49 50 DISALLOW_COPY_AND_ASSIGN(MojoWebUIController); 51}; 52 53#endif // CHROME_BROWSER_UI_WEBUI_MOJO_WEB_UI_CONTROLLER_H_ 54