| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 <vector> |
| 6 |
| 7 #include "base/strings/string_split.h" |
| 8 #include "examples/ui/tile/tile_app.h" |
| 9 #include "examples/ui/tile/tile_view.h" |
| 10 #include "url/gurl.h" |
| 11 |
| 12 namespace examples { |
| 13 |
| 14 class TileViewProvider : public mojo::ui::ViewProvider { |
| 15 public: |
| 16 TileViewProvider(mojo::ApplicationImpl* app_impl, |
| 17 const std::vector<std::string>& view_urls) |
| 18 : app_impl_(app_impl), view_urls_(view_urls) {} |
| 19 ~TileViewProvider() override {} |
| 20 |
| 21 private: |
| 22 // |ViewProvider|: |
| 23 void CreateView(mojo::InterfaceRequest<mojo::ServiceProvider> services, |
| 24 mojo::ServiceProviderPtr exposed_services, |
| 25 const CreateViewCallback& callback) override { |
| 26 new TileView(app_impl_, view_urls_, callback); |
| 27 } |
| 28 |
| 29 mojo::ApplicationImpl* app_impl_; |
| 30 std::vector<std::string> view_urls_; |
| 31 |
| 32 DISALLOW_COPY_AND_ASSIGN(TileViewProvider); |
| 33 }; |
| 34 |
| 35 TileApp::TileApp() {} |
| 36 |
| 37 TileApp::~TileApp() {} |
| 38 |
| 39 void TileApp::Initialize(mojo::ApplicationImpl* app_impl) { |
| 40 app_impl_ = app_impl; |
| 41 } |
| 42 |
| 43 bool TileApp::ConfigureIncomingConnection( |
| 44 mojo::ApplicationConnection* connection) { |
| 45 connection->AddService<mojo::ui::ViewProvider>(this); |
| 46 return true; |
| 47 } |
| 48 |
| 49 void TileApp::Create(mojo::ApplicationConnection* connection, |
| 50 mojo::InterfaceRequest<mojo::ui::ViewProvider> request) { |
| 51 GURL url(connection->GetConnectionURL()); |
| 52 std::vector<std::string> view_urls; |
| 53 base::SplitString(url.query(), ',', &view_urls); |
| 54 |
| 55 if (view_urls.empty()) { |
| 56 LOG(ERROR) << "Must supply comma-delimited URLs of mojo views to tile as a " |
| 57 "query parameter."; |
| 58 return; |
| 59 } |
| 60 |
| 61 bindings_.AddBinding(new TileViewProvider(app_impl_, view_urls), |
| 62 request.Pass()); |
| 63 } |
| 64 |
| 65 } // namespace examples |
| OLD | NEW |