| 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 #include <iostream> | 5 #include <iostream> |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "mojo/application/application_runner_chromium.h" | 8 #include "mojo/application/application_runner_chromium.h" |
| 9 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 public mojo::ViewManagerDelegate, | 57 public mojo::ViewManagerDelegate, |
| 58 public window_manager::WindowManagerDelegate, | 58 public window_manager::WindowManagerDelegate, |
| 59 public mojo::ViewObserver, | 59 public mojo::ViewObserver, |
| 60 public TestRunnerClient { | 60 public TestRunnerClient { |
| 61 public: | 61 public: |
| 62 SkyTester() | 62 SkyTester() |
| 63 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), | 63 : window_manager_app_(new window_manager::WindowManagerApp(this, this)), |
| 64 root_(NULL), | 64 root_(NULL), |
| 65 content_(NULL), | 65 content_(NULL), |
| 66 weak_ptr_factory_(this) {} | 66 weak_ptr_factory_(this) {} |
| 67 virtual ~SkyTester() {} | 67 ~SkyTester() override {} |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 // Overridden from mojo::ApplicationDelegate: | 70 // Overridden from mojo::ApplicationDelegate: |
| 71 virtual void Initialize(mojo::ApplicationImpl* impl) override { | 71 void Initialize(mojo::ApplicationImpl* impl) override { |
| 72 window_manager_app_->Initialize(impl); | 72 window_manager_app_->Initialize(impl); |
| 73 | 73 |
| 74 if (impl->args().size() >= 2) | 74 if (impl->args().size() >= 2) |
| 75 url_from_args_ = impl->args()[1]; | 75 url_from_args_ = impl->args()[1]; |
| 76 } | 76 } |
| 77 virtual bool ConfigureIncomingConnection( | 77 bool ConfigureIncomingConnection( |
| 78 mojo::ApplicationConnection* connection) override { | 78 mojo::ApplicationConnection* connection) override { |
| 79 window_manager_app_->ConfigureIncomingConnection(connection); | 79 window_manager_app_->ConfigureIncomingConnection(connection); |
| 80 if (test_runner_) | 80 if (test_runner_) |
| 81 connection->AddService(test_runner_.get()); | 81 connection->AddService(test_runner_.get()); |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Overridden from mojo::ViewManagerDelegate: | 85 // Overridden from mojo::ViewManagerDelegate: |
| 86 virtual void OnEmbed(mojo::View* root, | 86 void OnEmbed(mojo::View* root, |
| 87 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 87 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 88 mojo::ServiceProviderPtr exposed_services) override { | 88 mojo::ServiceProviderPtr exposed_services) override { |
| 89 root_ = root; | 89 root_ = root; |
| 90 root_->AddObserver(this); | 90 root_->AddObserver(this); |
| 91 | 91 |
| 92 content_ = root->view_manager()->CreateView(); | 92 content_ = root->view_manager()->CreateView(); |
| 93 content_->SetBounds(root_->bounds()); | 93 content_->SetBounds(root_->bounds()); |
| 94 root_->AddChild(content_); | 94 root_->AddChild(content_); |
| 95 content_->SetVisible(true); | 95 content_->SetVisible(true); |
| 96 | 96 |
| 97 std::cout << "#READY\n"; | 97 std::cout << "#READY\n"; |
| 98 std::cout.flush(); | 98 std::cout.flush(); |
| 99 ScheduleRun(); | 99 ScheduleRun(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Overridden from window_manager::WindowManagerDelegate: | 102 // Overridden from window_manager::WindowManagerDelegate: |
| 103 virtual void Embed(const mojo::String& url, | 103 void Embed(const mojo::String& url, |
| 104 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 104 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 105 mojo::ServiceProviderPtr exposed_services) override {} | 105 mojo::ServiceProviderPtr exposed_services) override {} |
| 106 | 106 |
| 107 virtual void OnViewManagerDisconnected( | 107 void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override { |
| 108 mojo::ViewManager* view_manager) override { | |
| 109 root_ = NULL; | 108 root_ = NULL; |
| 110 } | 109 } |
| 111 | 110 |
| 112 virtual void OnViewDestroyed(mojo::View* view) override { | 111 void OnViewDestroyed(mojo::View* view) override { |
| 113 view->RemoveObserver(this); | 112 view->RemoveObserver(this); |
| 114 } | 113 } |
| 115 | 114 |
| 116 virtual void OnViewBoundsChanged(mojo::View* view, | 115 void OnViewBoundsChanged(mojo::View* view, |
| 117 const mojo::Rect& old_bounds, | 116 const mojo::Rect& old_bounds, |
| 118 const mojo::Rect& new_bounds) override { | 117 const mojo::Rect& new_bounds) override { |
| 119 content_->SetBounds(new_bounds); | 118 content_->SetBounds(new_bounds); |
| 120 } | 119 } |
| 121 | 120 |
| 122 void ScheduleRun() { | 121 void ScheduleRun() { |
| 123 base::MessageLoop::current()->PostTask(FROM_HERE, | 122 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 124 base::Bind(&SkyTester::Run, weak_ptr_factory_.GetWeakPtr())); | 123 base::Bind(&SkyTester::Run, weak_ptr_factory_.GetWeakPtr())); |
| 125 } | 124 } |
| 126 | 125 |
| 127 void Run() { | 126 void Run() { |
| 128 DCHECK(!test_runner_); | 127 DCHECK(!test_runner_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 DISALLOW_COPY_AND_ASSIGN(SkyTester); | 162 DISALLOW_COPY_AND_ASSIGN(SkyTester); |
| 164 }; | 163 }; |
| 165 | 164 |
| 166 } // namespace tester | 165 } // namespace tester |
| 167 } // namespace examples | 166 } // namespace examples |
| 168 | 167 |
| 169 MojoResult MojoMain(MojoHandle shell_handle) { | 168 MojoResult MojoMain(MojoHandle shell_handle) { |
| 170 mojo::ApplicationRunnerChromium runner(new sky::tester::SkyTester); | 169 mojo::ApplicationRunnerChromium runner(new sky::tester::SkyTester); |
| 171 return runner.Run(shell_handle); | 170 return runner.Run(shell_handle); |
| 172 } | 171 } |
| OLD | NEW |