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 #include "base/memory/scoped_ptr.h" 6 #include "mojo/application/application_runner_chromium.h" 7 #include "mojo/public/c/system/main.h" 8 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/service_provider_impl.h" 10 #include "mojo/services/public/cpp/view_manager/view_manager.h" 11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 12 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" 13 #include "mojo/services/window_manager/window_manager_app.h" 14 15 // ApplicationDelegate implementation file for WindowManager users (e.g. 16 // core window manager tests) that do not want to provide their own 17 // ApplicationDelegate::Create(). 18 19 namespace mojo { 20 21 class DefaultWindowManager : public ApplicationDelegate, 22 public ViewManagerDelegate, 23 public WindowManagerDelegate { 24 public: 25 DefaultWindowManager() 26 : window_manager_app_(new WindowManagerApp(this, this)), 27 view_manager_(NULL), 28 root_(NULL) {} 29 virtual ~DefaultWindowManager() {} 30 31 private: 32 // Overridden from ApplicationDelegate: 33 virtual void Initialize(ApplicationImpl* impl) MOJO_OVERRIDE { 34 window_manager_app_->Initialize(impl); 35 } 36 virtual bool ConfigureIncomingConnection( 37 ApplicationConnection* connection) MOJO_OVERRIDE { 38 window_manager_app_->ConfigureIncomingConnection(connection); 39 return true; 40 } 41 42 // Overridden from ViewManagerDelegate: 43 virtual void OnEmbed( 44 ViewManager* view_manager, 45 View* root, 46 ServiceProviderImpl* exported_services, 47 scoped_ptr<ServiceProvider> imported_services) MOJO_OVERRIDE { 48 view_manager_ = view_manager; 49 root_ = root; 50 view_manager_->SetWindowManagerDelegate(this); 51 } 52 virtual void OnViewManagerDisconnected( 53 ViewManager* view_manager) MOJO_OVERRIDE {} 54 55 // Overridden from WindowManagerDelegate: 56 virtual void Embed( 57 const String& url, 58 InterfaceRequest<ServiceProvider> service_provider) MOJO_OVERRIDE { 59 View* view = View::Create(view_manager_); 60 root_->AddChild(view); 61 view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>( 62 new mojo::ServiceProviderImpl).Pass()); 63 } 64 virtual void DispatchEvent(EventPtr event) MOJO_OVERRIDE {} 65 66 scoped_ptr<WindowManagerApp> window_manager_app_; 67 68 ViewManager* view_manager_; 69 View* root_; 70 71 MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManager); 72 }; 73 74 } // namespace mojo 75 76 MojoResult MojoMain(MojoHandle shell_handle) { 77 mojo::ApplicationRunnerChromium runner(new mojo::DefaultWindowManager); 78 return runner.Run(shell_handle); 79 } 80