| 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" | 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" | 9 #include "components/view_manager/public/cpp/tests/view_manager_test_base.h" |
| 10 #include "components/view_manager/public/cpp/view_manager_client_factory.h" | 10 #include "components/view_manager/public/cpp/view_manager_client_factory.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ViewManager* EmbedAllowingReembed(View* view) { | 177 ViewManager* EmbedAllowingReembed(View* view) { |
| 178 return EmbedImpl(view, EmbedType::ALLOW_REEMBED); | 178 return EmbedImpl(view, EmbedType::ALLOW_REEMBED); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Establishes a connection to this application and asks for a | 181 // Establishes a connection to this application and asks for a |
| 182 // ViewManagerClient. The ViewManagerClient is then embedded in |view|. | 182 // ViewManagerClient. The ViewManagerClient is then embedded in |view|. |
| 183 // This does *not* wait for the connection to complete. | 183 // This does *not* wait for the connection to complete. |
| 184 void ConnectToApplicationAndEmbed(View* view) { | 184 void ConnectToApplicationAndEmbed(View* view) { |
| 185 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 185 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 186 request->url = mojo::String::From(application_impl()->url()); | 186 request->url = mojo::String::From(application_impl()->url()); |
| 187 ApplicationConnection* connection = | 187 scoped_ptr<ApplicationConnection> connection = |
| 188 application_impl()->ConnectToApplication(request.Pass()); | 188 application_impl()->ConnectToApplication(request.Pass()); |
| 189 mojo::ViewManagerClientPtr client; | 189 mojo::ViewManagerClientPtr client; |
| 190 connection->ConnectToService(&client); | 190 connection->ConnectToService(&client); |
| 191 view->Embed(client.Pass()); | 191 view->Embed(client.Pass()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Overridden from ViewManagerDelegate: | 194 // Overridden from ViewManagerDelegate: |
| 195 void OnEmbedForDescendant(View* view, | 195 void OnEmbedForDescendant(View* view, |
| 196 mojo::URLRequestPtr request, | 196 mojo::URLRequestPtr request, |
| 197 mojo::ViewManagerClientPtr* client) override { | 197 mojo::ViewManagerClientPtr* client) override { |
| 198 on_will_embed_count_++; | 198 on_will_embed_count_++; |
| 199 if (on_will_embed_return_value_) { | 199 if (on_will_embed_return_value_) { |
| 200 ApplicationConnection* connection = | 200 scoped_ptr<ApplicationConnection> connection = |
| 201 application_impl()->ConnectToApplication(request.Pass()); | 201 application_impl()->ConnectToApplication(request.Pass()); |
| 202 connection->ConnectToService(client); | 202 connection->ConnectToService(client); |
| 203 } else { | 203 } else { |
| 204 EXPECT_TRUE(QuitRunLoop()); | 204 EXPECT_TRUE(QuitRunLoop()); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 enum class EmbedType { | 209 enum class EmbedType { |
| 210 ALLOW_REEMBED, | 210 ALLOW_REEMBED, |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 bool got_destroy = false; | 832 bool got_destroy = false; |
| 833 DestroyObserver observer(this, embedded_view_manager, &got_destroy); | 833 DestroyObserver observer(this, embedded_view_manager, &got_destroy); |
| 834 // Delete the view |embedded_view_manager| is embedded in. This is async, | 834 // Delete the view |embedded_view_manager| is embedded in. This is async, |
| 835 // but will eventually trigger deleting |embedded_view_manager|. | 835 // but will eventually trigger deleting |embedded_view_manager|. |
| 836 embed_view->Destroy(); | 836 embed_view->Destroy(); |
| 837 EXPECT_TRUE(DoRunLoopWithTimeout()); | 837 EXPECT_TRUE(DoRunLoopWithTimeout()); |
| 838 EXPECT_TRUE(got_destroy); | 838 EXPECT_TRUE(got_destroy); |
| 839 } | 839 } |
| 840 | 840 |
| 841 } // namespace mojo | 841 } // namespace mojo |
| OLD | NEW |