OLD | NEW |
| (Empty) |
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 "mojo/services/public/cpp/view_manager/view_manager_context.h" | |
6 | |
7 #include "mojo/public/cpp/application/application_impl.h" | |
8 #include "mojo/public/cpp/bindings/interface_request.h" | |
9 #include "mojo/services/window_manager/public/interfaces/window_manager.mojom.h" | |
10 | |
11 namespace mojo { | |
12 class ApplicationImpl; | |
13 | |
14 class ViewManagerContext::InternalState { | |
15 public: | |
16 explicit InternalState(ApplicationImpl* application_impl) { | |
17 application_impl->ConnectToService("mojo:window_manager", &wm_); | |
18 } | |
19 ~InternalState() {} | |
20 | |
21 WindowManager* wm() { return wm_.get(); } | |
22 | |
23 private: | |
24 WindowManagerPtr wm_; | |
25 | |
26 MOJO_DISALLOW_COPY_AND_ASSIGN(InternalState); | |
27 }; | |
28 | |
29 ViewManagerContext::ViewManagerContext(ApplicationImpl* application_impl) | |
30 : state_(new InternalState(application_impl)) {} | |
31 ViewManagerContext::~ViewManagerContext() {} | |
32 | |
33 void ViewManagerContext::Embed(const String& url) { | |
34 scoped_ptr<ServiceProviderImpl> spi(new ServiceProviderImpl); | |
35 Embed(url, spi.Pass()); | |
36 } | |
37 | |
38 scoped_ptr<ServiceProvider> ViewManagerContext::Embed( | |
39 const String& url, | |
40 scoped_ptr<ServiceProviderImpl> exported_services) { | |
41 scoped_ptr<ServiceProvider> imported_services; | |
42 // BindToProxy() takes ownership of |exported_services|. | |
43 ServiceProviderImpl* registry = exported_services.release(); | |
44 ServiceProviderPtr sp; | |
45 if (registry) { | |
46 BindToProxy(registry, &sp); | |
47 imported_services.reset(registry->CreateRemoteServiceProvider()); | |
48 } | |
49 state_->wm()->Embed(url, MakeRequest<ServiceProvider>(sp.PassMessagePipe())); | |
50 return imported_services.Pass(); | |
51 } | |
52 | |
53 } // namespace mojo | |
OLD | NEW |