| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/frame_host/frame_mojo_shell.h" | 5 #include "content/browser/frame_host/frame_mojo_shell.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/browser/mojo/mojo_shell_context.h" | 11 #include "content/browser/mojo/mojo_shell_context.h" |
| 12 #include "content/common/mojo/service_registry_impl.h" | 12 #include "content/common/mojo/service_registry_impl.h" |
| 13 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
| 14 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
| 16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 17 #include "mojo/public/cpp/system/message_pipe.h" | 17 #include "mojo/public/cpp/system/message_pipe.h" |
| 18 | 18 |
| 19 #if defined(OS_ANDROID) && defined(ENABLE_MOJO_MEDIA) |
| 20 #include "content/browser/media/android/provision_fetcher_impl.h" |
| 21 #endif |
| 22 |
| 19 namespace content { | 23 namespace content { |
| 20 | 24 |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 // This wraps a ServiceRegistryImpl in a mojo::ServiceProvider implementation | 27 // This wraps a ServiceRegistryImpl in a mojo::ServiceProvider implementation |
| 24 // so it can be bound to a mojo::ServiceProvider pipe. | 28 // so it can be bound to a mojo::ServiceProvider pipe. |
| 25 class ServiceRegistryWrapper : public mojo::ServiceProvider { | 29 class ServiceRegistryWrapper : public mojo::ServiceProvider { |
| 26 public: | 30 public: |
| 27 explicit ServiceRegistryWrapper(scoped_ptr<ServiceRegistryImpl> registry) | 31 explicit ServiceRegistryWrapper(scoped_ptr<ServiceRegistryImpl> registry) |
| 28 : registry_(std::move(registry)) { | 32 : registry_(std::move(registry)) { |
| 29 } | 33 } |
| 30 ~ServiceRegistryWrapper() override {} | 34 ~ServiceRegistryWrapper() override {} |
| 31 | 35 |
| 32 private: | 36 private: |
| 33 // mojo::ServiceProvider: | 37 // mojo::ServiceProvider: |
| 34 void ConnectToService(const mojo::String& service_name, | 38 void ConnectToService(const mojo::String& service_name, |
| 35 mojo::ScopedMessagePipeHandle pipe) override { | 39 mojo::ScopedMessagePipeHandle pipe) override { |
| 36 registry_->Connect(base::StringPiece(service_name), std::move(pipe)); | 40 registry_->Connect(base::StringPiece(service_name), std::move(pipe)); |
| 37 } | 41 } |
| 38 | 42 |
| 39 const scoped_ptr<ServiceRegistryImpl> registry_; | 43 const scoped_ptr<ServiceRegistryImpl> registry_; |
| 40 | 44 |
| 41 DISALLOW_COPY_AND_ASSIGN(ServiceRegistryWrapper); | 45 DISALLOW_COPY_AND_ASSIGN(ServiceRegistryWrapper); |
| 42 }; | 46 }; |
| 43 | 47 |
| 48 void RegisterFrameMojoShellServices(ServiceRegistry* registry, |
| 49 RenderFrameHost* render_frame_host) { |
| 50 #if defined(OS_ANDROID) && defined(ENABLE_MOJO_MEDIA) |
| 51 registry->AddService( |
| 52 base::Bind(&ProvisionFetcherImpl::Create, render_frame_host)); |
| 53 #endif |
| 54 } |
| 55 |
| 44 } // namespace | 56 } // namespace |
| 45 | 57 |
| 46 FrameMojoShell::FrameMojoShell(RenderFrameHost* frame_host) | 58 FrameMojoShell::FrameMojoShell(RenderFrameHost* frame_host) |
| 47 : frame_host_(frame_host) { | 59 : frame_host_(frame_host) { |
| 48 } | 60 } |
| 49 | 61 |
| 50 FrameMojoShell::~FrameMojoShell() { | 62 FrameMojoShell::~FrameMojoShell() { |
| 51 } | 63 } |
| 52 | 64 |
| 53 void FrameMojoShell::BindRequest( | 65 void FrameMojoShell::BindRequest( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 std::move(services), std::move(frame_services), capability_filter, | 89 std::move(services), std::move(frame_services), capability_filter, |
| 78 callback); | 90 callback); |
| 79 } | 91 } |
| 80 | 92 |
| 81 void FrameMojoShell::QuitApplication() { | 93 void FrameMojoShell::QuitApplication() { |
| 82 } | 94 } |
| 83 | 95 |
| 84 mojo::ServiceProvider* FrameMojoShell::GetServiceProvider() { | 96 mojo::ServiceProvider* FrameMojoShell::GetServiceProvider() { |
| 85 if (!service_provider_) { | 97 if (!service_provider_) { |
| 86 scoped_ptr<ServiceRegistryImpl> registry(new ServiceRegistryImpl()); | 98 scoped_ptr<ServiceRegistryImpl> registry(new ServiceRegistryImpl()); |
| 99 // TODO(rockot/xhwang): Currently all applications connected share the same |
| 100 // set of services registered in the |registry|. We may want to provide |
| 101 // different services for different apps for better isolation. |
| 102 RegisterFrameMojoShellServices(registry.get(), frame_host_); |
| 87 GetContentClient()->browser()->RegisterFrameMojoShellServices( | 103 GetContentClient()->browser()->RegisterFrameMojoShellServices( |
| 88 registry.get(), frame_host_); | 104 registry.get(), frame_host_); |
| 89 service_provider_.reset(new ServiceRegistryWrapper(std::move(registry))); | 105 service_provider_.reset(new ServiceRegistryWrapper(std::move(registry))); |
| 90 } | 106 } |
| 91 return service_provider_.get(); | 107 return service_provider_.get(); |
| 92 } | 108 } |
| 93 | 109 |
| 94 } // namespace content | 110 } // namespace content |
| OLD | NEW |