| 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 | |
| 23 namespace content { | 19 namespace content { |
| 24 | 20 |
| 25 namespace { | 21 namespace { |
| 26 | 22 |
| 27 // This wraps a ServiceRegistryImpl in a mojo::ServiceProvider implementation | 23 // This wraps a ServiceRegistryImpl in a mojo::ServiceProvider implementation |
| 28 // so it can be bound to a mojo::ServiceProvider pipe. | 24 // so it can be bound to a mojo::ServiceProvider pipe. |
| 29 class ServiceRegistryWrapper : public mojo::ServiceProvider { | 25 class ServiceRegistryWrapper : public mojo::ServiceProvider { |
| 30 public: | 26 public: |
| 31 explicit ServiceRegistryWrapper(scoped_ptr<ServiceRegistryImpl> registry) | 27 explicit ServiceRegistryWrapper(scoped_ptr<ServiceRegistryImpl> registry) |
| 32 : registry_(std::move(registry)) { | 28 : registry_(std::move(registry)) { |
| 33 } | 29 } |
| 34 ~ServiceRegistryWrapper() override {} | 30 ~ServiceRegistryWrapper() override {} |
| 35 | 31 |
| 36 private: | 32 private: |
| 37 // mojo::ServiceProvider: | 33 // mojo::ServiceProvider: |
| 38 void ConnectToService(const mojo::String& service_name, | 34 void ConnectToService(const mojo::String& service_name, |
| 39 mojo::ScopedMessagePipeHandle pipe) override { | 35 mojo::ScopedMessagePipeHandle pipe) override { |
| 40 registry_->Connect(base::StringPiece(service_name), std::move(pipe)); | 36 registry_->Connect(base::StringPiece(service_name), std::move(pipe)); |
| 41 } | 37 } |
| 42 | 38 |
| 43 const scoped_ptr<ServiceRegistryImpl> registry_; | 39 const scoped_ptr<ServiceRegistryImpl> registry_; |
| 44 | 40 |
| 45 DISALLOW_COPY_AND_ASSIGN(ServiceRegistryWrapper); | 41 DISALLOW_COPY_AND_ASSIGN(ServiceRegistryWrapper); |
| 46 }; | 42 }; |
| 47 | 43 |
| 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 | |
| 56 } // namespace | 44 } // namespace |
| 57 | 45 |
| 58 FrameMojoShell::FrameMojoShell(RenderFrameHost* frame_host) | 46 FrameMojoShell::FrameMojoShell(RenderFrameHost* frame_host) |
| 59 : frame_host_(frame_host) { | 47 : frame_host_(frame_host) { |
| 60 } | 48 } |
| 61 | 49 |
| 62 FrameMojoShell::~FrameMojoShell() { | 50 FrameMojoShell::~FrameMojoShell() { |
| 63 } | 51 } |
| 64 | 52 |
| 65 void FrameMojoShell::BindRequest( | 53 void FrameMojoShell::BindRequest( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 89 std::move(services), std::move(frame_services), capability_filter, | 77 std::move(services), std::move(frame_services), capability_filter, |
| 90 callback); | 78 callback); |
| 91 } | 79 } |
| 92 | 80 |
| 93 void FrameMojoShell::QuitApplication() { | 81 void FrameMojoShell::QuitApplication() { |
| 94 } | 82 } |
| 95 | 83 |
| 96 mojo::ServiceProvider* FrameMojoShell::GetServiceProvider() { | 84 mojo::ServiceProvider* FrameMojoShell::GetServiceProvider() { |
| 97 if (!service_provider_) { | 85 if (!service_provider_) { |
| 98 scoped_ptr<ServiceRegistryImpl> registry(new ServiceRegistryImpl()); | 86 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_); | |
| 103 GetContentClient()->browser()->RegisterFrameMojoShellServices( | 87 GetContentClient()->browser()->RegisterFrameMojoShellServices( |
| 104 registry.get(), frame_host_); | 88 registry.get(), frame_host_); |
| 105 service_provider_.reset(new ServiceRegistryWrapper(std::move(registry))); | 89 service_provider_.reset(new ServiceRegistryWrapper(std::move(registry))); |
| 106 } | 90 } |
| 107 return service_provider_.get(); | 91 return service_provider_.get(); |
| 108 } | 92 } |
| 109 | 93 |
| 110 } // namespace content | 94 } // namespace content |
| OLD | NEW |