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.
5 #include "mojo/services/public/cpp/view_manager/view_manager_context.h"
7 #include "mojo/public/cpp/application/application_impl.h"
8 #include "mojo/public/cpp/bindings/interface_request.h"
9 #include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
12 class ApplicationImpl;
14 class ViewManagerContext::InternalState {
16 explicit InternalState(ApplicationImpl* application_impl) {
17 application_impl->ConnectToService("mojo:window_manager", &wm_);
21 WindowManager* wm() { return wm_.get(); }
26 MOJO_DISALLOW_COPY_AND_ASSIGN(InternalState);
29 ViewManagerContext::ViewManagerContext(ApplicationImpl* application_impl)
30 : state_(new InternalState(application_impl)) {}
31 ViewManagerContext::~ViewManagerContext() {}
33 void ViewManagerContext::Embed(const String& url) {
34 scoped_ptr<ServiceProviderImpl> spi(new ServiceProviderImpl);
35 Embed(url, spi.Pass());
38 scoped_ptr<ServiceProvider> ViewManagerContext::Embed(
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;
46 BindToProxy(registry, &sp);
47 imported_services.reset(registry->CreateRemoteServiceProvider());
49 state_->wm()->Embed(url, MakeRequest<ServiceProvider>(sp.PassMessagePipe()));
50 return imported_services.Pass();