| 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 "components/view_manager/public/cpp/view_manager.h" | 5 #include "components/view_manager/public/cpp/view_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "components/view_manager/public/cpp/lib/view_manager_client_impl.h" | |
| 9 #include "components/view_manager/public/cpp/tests/view_manager_test_base.h" | 8 #include "components/view_manager/public/cpp/tests/view_manager_test_base.h" |
| 10 #include "components/view_manager/public/cpp/view_manager_delegate.h" | 9 #include "components/view_manager/public/cpp/view_manager_delegate.h" |
| 11 #include "components/view_manager/public/cpp/view_manager_init.h" | 10 #include "components/view_manager/public/cpp/view_manager_init.h" |
| 12 #include "components/view_manager/public/cpp/view_observer.h" | 11 #include "components/view_manager/public/cpp/view_observer.h" |
| 13 #include "mojo/application/public/cpp/application_connection.h" | 12 #include "mojo/application/public/cpp/application_connection.h" |
| 14 #include "mojo/application/public/cpp/application_impl.h" | 13 #include "mojo/application/public/cpp/application_impl.h" |
| 15 #include "mojo/application/public/cpp/application_test_base.h" | 14 #include "mojo/application/public/cpp/application_test_base.h" |
| 16 #include "ui/mojo/geometry/geometry_util.h" | 15 #include "ui/mojo/geometry/geometry_util.h" |
| 17 | 16 |
| 18 namespace mojo { | 17 namespace mojo { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 ViewManager* Embed(View* view) { | 172 ViewManager* Embed(View* view) { |
| 174 return EmbedImpl(view, EmbedType::NO_REEMBED); | 173 return EmbedImpl(view, EmbedType::NO_REEMBED); |
| 175 } | 174 } |
| 176 | 175 |
| 177 // Same as Embed(), but uses EmbedAllowingReembed(). | 176 // Same as Embed(), but uses EmbedAllowingReembed(). |
| 178 ViewManager* EmbedAllowingReembed(View* view) { | 177 ViewManager* EmbedAllowingReembed(View* view) { |
| 179 return EmbedImpl(view, EmbedType::ALLOW_REEMBED); | 178 return EmbedImpl(view, EmbedType::ALLOW_REEMBED); |
| 180 } | 179 } |
| 181 | 180 |
| 182 // Establishes a connection to this application and asks for a | 181 // Establishes a connection to this application and asks for a |
| 183 // ViewManagerClient. The ViewManagerClient is then embedded in |view|. | 182 // ViewTreeClient. The ViewTreeClient is then embedded in |view|. This does |
| 184 // This does *not* wait for the connection to complete. | 183 // *not* wait for the connection to complete. |
| 185 void ConnectToApplicationAndEmbed(View* view) { | 184 void ConnectToApplicationAndEmbed(View* view) { |
| 186 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 185 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 187 request->url = mojo::String::From(application_impl()->url()); | 186 request->url = mojo::String::From(application_impl()->url()); |
| 188 scoped_ptr<ApplicationConnection> connection = | 187 scoped_ptr<ApplicationConnection> connection = |
| 189 application_impl()->ConnectToApplication(request.Pass()); | 188 application_impl()->ConnectToApplication(request.Pass()); |
| 190 mojo::ViewManagerClientPtr client; | 189 mojo::ViewTreeClientPtr client; |
| 191 connection->ConnectToService(&client); | 190 connection->ConnectToService(&client); |
| 192 view->Embed(client.Pass()); | 191 view->Embed(client.Pass()); |
| 193 } | 192 } |
| 194 | 193 |
| 195 // Overridden from ViewManagerDelegate: | 194 // Overridden from ViewManagerDelegate: |
| 196 void OnEmbedForDescendant(View* view, | 195 void OnEmbedForDescendant(View* view, |
| 197 mojo::URLRequestPtr request, | 196 mojo::URLRequestPtr request, |
| 198 mojo::ViewManagerClientPtr* client) override { | 197 mojo::ViewTreeClientPtr* client) override { |
| 199 on_will_embed_count_++; | 198 on_will_embed_count_++; |
| 200 if (on_will_embed_return_value_) { | 199 if (on_will_embed_return_value_) { |
| 201 scoped_ptr<ApplicationConnection> connection = | 200 scoped_ptr<ApplicationConnection> connection = |
| 202 application_impl()->ConnectToApplication(request.Pass()); | 201 application_impl()->ConnectToApplication(request.Pass()); |
| 203 connection->ConnectToService(client); | 202 connection->ConnectToService(client); |
| 204 } else { | 203 } else { |
| 205 EXPECT_TRUE(QuitRunLoop()); | 204 EXPECT_TRUE(QuitRunLoop()); |
| 206 } | 205 } |
| 207 } | 206 } |
| 208 | 207 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 // As |vm2| is an embed root it should get notified about |vm3_v1|. | 848 // As |vm2| is an embed root it should get notified about |vm3_v1|. |
| 850 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); | 849 ASSERT_TRUE(WaitForTreeSizeToMatch(vm2_v1, 2)); |
| 851 | 850 |
| 852 // Embed() from vm2 in vm3_v1. This is allowed as vm2 is an embed root. | 851 // Embed() from vm2 in vm3_v1. This is allowed as vm2 is an embed root. |
| 853 ASSERT_EQ(1u, vm2_v1->children().size()); | 852 ASSERT_EQ(1u, vm2_v1->children().size()); |
| 854 View* vm3_v1_in_vm2 = vm2_v1->children()[0]; | 853 View* vm3_v1_in_vm2 = vm2_v1->children()[0]; |
| 855 ASSERT_TRUE(Embed(vm3_v1_in_vm2)); | 854 ASSERT_TRUE(Embed(vm3_v1_in_vm2)); |
| 856 } | 855 } |
| 857 | 856 |
| 858 } // namespace mojo | 857 } // namespace mojo |
| OLD | NEW |