diff options
37 files changed, 363 insertions, 471 deletions
diff --git a/content/browser/mojo/mojo_application_host.cc b/content/browser/mojo/mojo_application_host.cc deleted file mode 100644 index 48d343a..0000000 --- a/content/browser/mojo/mojo_application_host.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/mojo/mojo_application_host.h" - -#include "content/common/mojo/mojo_messages.h" -#include "content/public/browser/browser_thread.h" -#include "ipc/ipc_sender.h" -#include "mojo/embedder/platform_channel_pair.h" - -namespace content { -namespace { - -base::PlatformFile PlatformFileFromScopedPlatformHandle( - mojo::embedder::ScopedPlatformHandle handle) { -#if defined(OS_POSIX) - return handle.release().fd; -#elif defined(OS_WIN) - return handle.release().handle; -#endif -} - -} // namespace - -MojoApplicationHost::MojoApplicationHost() : did_activate_(false) { -} - -MojoApplicationHost::~MojoApplicationHost() { -} - -bool MojoApplicationHost::Init() { - DCHECK(shell_client_.is_null()) << "Already initialized!"; - - mojo::embedder::PlatformChannelPair channel_pair; - - mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init( - PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); - if (!message_pipe.is_valid()) - return false; - - // Forward this to the client once we know its process handle. - client_handle_ = channel_pair.PassClientHandle(); - - // TODO(darin): Provide a Shell implementation - shell_client_.reset( - mojo::ScopedShellClientHandle::From(message_pipe.Pass()), NULL); - - return true; -} - -bool MojoApplicationHost::Activate(IPC::Sender* sender, - base::ProcessHandle process_handle) { - DCHECK(!did_activate_); - DCHECK(client_handle_.is_valid()); - - base::PlatformFile client_file = - PlatformFileFromScopedPlatformHandle(client_handle_.Pass()); - did_activate_ = sender->Send(new MojoMsg_Activate( - IPC::GetFileHandleForProcess(client_file, process_handle, true))); - return did_activate_; -} - -} // namespace content diff --git a/content/browser/mojo/mojo_application_host.h b/content/browser/mojo/mojo_application_host.h deleted file mode 100644 index 68f6c32..0000000 --- a/content/browser/mojo/mojo_application_host.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ -#define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ - -#include "base/process/process_handle.h" -#include "mojo/common/channel_init.h" -#include "mojo/embedder/scoped_platform_handle.h" -#include "mojo/public/cpp/bindings/remote_ptr.h" -#include "mojo/public/interfaces/shell/shell.mojom.h" - -namespace IPC { -class Sender; -} - -namespace content { - -// MojoApplicationHost represents the code needed on the browser side to setup -// a child process as a Mojo application via Chrome IPC. The child process -// should use MojoApplication to handle messages generated by an instance of -// MojoApplicationHost. MojoApplicationHost makes the mojo::ShellClient -// interface available so that child-provided services can be invoked. -class MojoApplicationHost { - public: - MojoApplicationHost(); - ~MojoApplicationHost(); - - // Two-phase initialization: - // 1- Init makes the shell_client() available synchronously. - // 2- Activate establishes the actual connection to the peer process. - bool Init(); - bool Activate(IPC::Sender* sender, base::ProcessHandle process_handle); - - bool did_activate() const { return did_activate_; } - - mojo::ShellClient* shell_client() { return shell_client_.get(); } - - private: - mojo::common::ChannelInit channel_init_; - mojo::embedder::ScopedPlatformHandle client_handle_; - mojo::RemotePtr<mojo::ShellClient> shell_client_; - bool did_activate_; - - DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 566a227..2b6ebf1 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -64,7 +64,6 @@ #include "content/browser/media/media_internals.h" #include "content/browser/message_port_message_filter.h" #include "content/browser/mime_registry_message_filter.h" -#include "content/browser/mojo/mojo_application_host.h" #include "content/browser/plugin_service_impl.h" #include "content/browser/profiler_message_filter.h" #include "content/browser/push_messaging_message_filter.h" @@ -87,6 +86,7 @@ #include "content/browser/renderer_host/pepper/pepper_message_filter.h" #include "content/browser/renderer_host/pepper/pepper_renderer_connection.h" #include "content/browser/renderer_host/render_message_filter.h" +#include "content/browser/renderer_host/render_process_host_mojo_impl.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_widget_helper.h" @@ -112,7 +112,6 @@ #include "content/common/child_process_messages.h" #include "content/common/content_switches_internal.h" #include "content/common/gpu/gpu_messages.h" -#include "content/common/mojo/mojo_messages.h" #include "content/common/resource_messages.h" #include "content/common/view_messages.h" #include "content/port/browser/render_widget_host_view_frame_subscriber.h" @@ -138,8 +137,6 @@ #include "ipc/ipc_logging.h" #include "ipc/ipc_switches.h" #include "media/base/media_switches.h" -#include "mojo/common/common_type_converters.h" -#include "mojo/public/cpp/bindings/allocation_scope.h" #include "net/url_request/url_request_context_getter.h" #include "ppapi/shared_impl/ppapi_switches.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -546,10 +543,6 @@ bool RenderProcessHostImpl::Init() { BrowserThread::GetMessageLoopProxyForThread( BrowserThread::IO).get())); - // Setup the Mojo channel. - mojo_application_host_.reset(new MojoApplicationHost()); - mojo_application_host_->Init(); - // Call the embedder first so that their IPC filters have priority. GetContentClient()->browser()->RenderProcessWillLaunch(this); @@ -1904,7 +1897,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { ClearTransportDIBCache(); - mojo_application_host_.reset(); + render_process_host_mojo_.reset(); // It's possible that one of the calls out to the observers might have caused // this object to be no longer needed. @@ -2039,14 +2032,6 @@ void RenderProcessHostImpl::OnProcessLaunched() { Source<RenderProcessHost>(this), NotificationService::NoDetails()); - // TODO(darin): This is blocked on security review. Un-commenting this will - // allow Mojo calls from all renderers. -#if 0 - // Let the Mojo system get setup on the child process side before any other - // IPCs arrive. This way those may safely generate Mojo-related RPCs. - mojo_application_host_->Activate(this, GetHandle()); -#endif - while (!queued_messages_.empty()) { Send(queued_messages_.front()); queued_messages_.pop(); @@ -2056,6 +2041,9 @@ void RenderProcessHostImpl::OnProcessLaunched() { if (WebRTCInternals::GetInstance()->aec_dump_enabled()) EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); #endif + + if (render_process_host_mojo_.get()) + render_process_host_mojo_->OnProcessLaunched(); } scoped_refptr<AudioRendererHost> @@ -2129,15 +2117,12 @@ void RenderProcessHostImpl::DecrementWorkerRefCount() { Cleanup(); } -void RenderProcessHostImpl::ConnectTo( - const base::StringPiece& service_name, +void RenderProcessHostImpl::SetWebUIHandle( + int32 view_routing_id, mojo::ScopedMessagePipeHandle handle) { - if (!mojo_application_host_->did_activate()) - mojo_application_host_->Activate(this, GetHandle()); - - mojo::AllocationScope scope; - mojo_application_host_->shell_client()->AcceptConnection(service_name, - handle.Pass()); + if (!render_process_host_mojo_) + render_process_host_mojo_.reset(new RenderProcessHostMojoImpl(this)); + render_process_host_mojo_->SetWebUIHandle(view_routing_id, handle.Pass()); } } // namespace content diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index 15873e7..284332f 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -21,9 +21,7 @@ #include "content/public/browser/render_process_host.h" #include "ipc/ipc_channel_proxy.h" #include "ipc/ipc_platform_file.h" -#include "mojo/embedder/scoped_platform_handle.h" -#include "mojo/public/cpp/bindings/remote_ptr.h" -#include "mojo/public/interfaces/shell/shell.mojom.h" +#include "mojo/public/cpp/system/core.h" #include "ui/surface/transport_dib.h" struct ViewHostMsg_CompositorSurfaceBuffersSwapped_Params; @@ -43,7 +41,6 @@ class BrowserDemuxerAndroid; class GeolocationDispatcherHost; class GpuMessageFilter; class MessagePortMessageFilter; -class MojoApplicationHost; class PeerConnectionTrackerHost; class RendererMainThread; class RenderProcessHostMojoImpl; @@ -243,10 +240,8 @@ class CONTENT_EXPORT RenderProcessHostImpl void IncrementWorkerRefCount(); void DecrementWorkerRefCount(); - // Establish a connection to a renderer-provided service. See - // content/common/mojo/mojo_service_names.h for a list of services. - void ConnectTo(const base::StringPiece& service_name, - mojo::ScopedMessagePipeHandle handle); + void SetWebUIHandle(int32 view_routing_id, + mojo::ScopedMessagePipeHandle handle); protected: // A proxy for our IPC::Channel that lives on the IO thread (see @@ -311,8 +306,6 @@ class CONTENT_EXPORT RenderProcessHostImpl void SendDisableAecDumpToRenderer(); #endif - scoped_ptr<MojoApplicationHost> mojo_application_host_; - // The registered IPC listener objects. When this list is empty, we should // delete ourselves. IDMap<IPC::Listener> listeners_; @@ -438,6 +431,8 @@ class CONTENT_EXPORT RenderProcessHostImpl // Records the time when the process starts surviving for workers for UMA. base::TimeTicks survive_for_worker_start_time_; + scoped_ptr<RenderProcessHostMojoImpl> render_process_host_mojo_; + base::WeakPtrFactory<RenderProcessHostImpl> weak_factory_; DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); diff --git a/content/browser/renderer_host/render_process_host_mojo_impl.cc b/content/browser/renderer_host/render_process_host_mojo_impl.cc new file mode 100644 index 0000000..1adb4a1 --- /dev/null +++ b/content/browser/renderer_host/render_process_host_mojo_impl.cc @@ -0,0 +1,93 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/renderer_host/render_process_host_mojo_impl.h" + +#include "base/platform_file.h" +#include "content/common/mojo/mojo_messages.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_process_host.h" +#include "mojo/common/mojo_channel_init.h" +#include "mojo/embedder/platform_channel_pair.h" + +namespace content { + +namespace { + +base::PlatformFile PlatformFileFromScopedPlatformHandle( + mojo::embedder::ScopedPlatformHandle handle) { +#if defined(OS_POSIX) + return handle.release().fd; +#elif defined(OS_WIN) + return handle.release().handle; +#endif +} + +} // namespace + +struct RenderProcessHostMojoImpl::PendingHandle { + PendingHandle() : view_routing_id(0) {} + + int32 view_routing_id; + mojo::ScopedMessagePipeHandle handle; +}; + +RenderProcessHostMojoImpl::RenderProcessHostMojoImpl(RenderProcessHost* host) + : host_(host) { +} + +RenderProcessHostMojoImpl::~RenderProcessHostMojoImpl() { +} + +void RenderProcessHostMojoImpl::SetWebUIHandle( + int32 view_routing_id, + mojo::ScopedMessagePipeHandle handle) { + base::ProcessHandle process = host_->GetHandle(); + if (process != base::kNullProcessHandle) { + CreateMojoChannel(process); // Does nothing if already connected. + if (!render_process_mojo_.is_null()) { + render_process_mojo_->SetWebUIHandle(view_routing_id, handle.Pass()); + return; + } + } + + // Remember the request, we'll attempt to reconnect once the child process is + // launched. + pending_handle_.reset(new PendingHandle); + pending_handle_->view_routing_id = view_routing_id; + pending_handle_->handle = handle.Pass(); +} + +void RenderProcessHostMojoImpl::OnProcessLaunched() { + if (pending_handle_) { + scoped_ptr<PendingHandle> handle(pending_handle_.Pass()); + SetWebUIHandle(handle->view_routing_id, handle->handle.Pass()); + } +} + + +void RenderProcessHostMojoImpl::CreateMojoChannel( + base::ProcessHandle process_handle) { + if (mojo_channel_init_.get()) + return; + + mojo::embedder::PlatformChannelPair channel_pair; + mojo_channel_init_.reset(new mojo::common::MojoChannelInit); + mojo_channel_init_->Init( + PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); + if (!mojo_channel_init_->is_handle_valid()) + return; + base::PlatformFile client_file = + PlatformFileFromScopedPlatformHandle(channel_pair.PassClientHandle()); + host_->Send(new MojoMsg_ChannelCreated( + IPC::GetFileHandleForProcess(client_file, process_handle, + true))); + ScopedRenderProcessMojoHandle render_process_handle( + RenderProcessMojoHandle( + mojo_channel_init_->bootstrap_message_pipe().release().value())); + render_process_mojo_.reset(render_process_handle.Pass(), this); +} + +} // namespace content diff --git a/content/browser/renderer_host/render_process_host_mojo_impl.h b/content/browser/renderer_host/render_process_host_mojo_impl.h new file mode 100644 index 0000000..f55268d --- /dev/null +++ b/content/browser/renderer_host/render_process_host_mojo_impl.h @@ -0,0 +1,58 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_MOJO_IMPL_H_ +#define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_MOJO_IMPL_H_ + +#include "base/memory/scoped_ptr.h" +#include "base/process/process_handle.h" +#include "content/common/mojo/render_process.mojom.h" +#include "mojo/public/cpp/bindings/remote_ptr.h" + +namespace mojo { +namespace common { +class MojoChannelInit; +} +} + +namespace content { + +class RenderProcessHost; + +// RenderProcessHostMojoImpl is responsible for initiating and maintaining the +// connection with the content side of RenderProcessHostMojo. +class RenderProcessHostMojoImpl : public RenderProcessHostMojo { + public: + explicit RenderProcessHostMojoImpl(RenderProcessHost* host); + virtual ~RenderProcessHostMojoImpl(); + + void SetWebUIHandle(int32 view_routing_id, + mojo::ScopedMessagePipeHandle handle); + + // Invoked when the RenderPorcessHost has established a channel. + void OnProcessLaunched(); + +private: + struct PendingHandle; + + // Establishes the mojo channel to the renderer. + void CreateMojoChannel(base::ProcessHandle process_handle); + + RenderProcessHost* host_; + + // Used to establish the connection. + scoped_ptr<mojo::common::MojoChannelInit> mojo_channel_init_; + + mojo::RemotePtr<content::RenderProcessMojo> render_process_mojo_; + + // If non-null we're waiting to send a WebUI handle to the renderer when + // connected. + scoped_ptr<PendingHandle> pending_handle_; + + DISALLOW_COPY_AND_ASSIGN(RenderProcessHostMojoImpl); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_MOJO_IMPL_H_ diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 99dea2ba..ac03ecc 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -46,11 +46,9 @@ #include "content/common/frame_messages.h" #include "content/common/input_messages.h" #include "content/common/inter_process_time_ticks_converter.h" -#include "content/common/mojo/mojo_service_names.h" #include "content/common/speech_recognition_messages.h" #include "content/common/swapped_out_messages.h" #include "content/common/view_messages.h" -#include "content/common/web_ui_setup.mojom.h" #include "content/port/browser/render_view_host_delegate_view.h" #include "content/port/browser/render_widget_host_view_port.h" #include "content/public/browser/ax_event_notification_details.h" @@ -696,13 +694,9 @@ void RenderViewHostImpl::SetWebUIHandle(mojo::ScopedMessagePipeHandle handle) { } DCHECK(renderer_initialized_); - - mojo::InterfacePipe<WebUISetup, mojo::AnyInterface> pipe; - mojo::RemotePtr<WebUISetup> web_ui_setup(pipe.handle_to_self.Pass(), NULL); - web_ui_setup->SetWebUIHandle(GetRoutingID(), handle.Pass()); - - static_cast<RenderProcessHostImpl*>(GetProcess())->ConnectTo( - kRendererService_WebUISetup, pipe.handle_to_peer.Pass()); + RenderProcessHostImpl* process = + static_cast<RenderProcessHostImpl*>(GetProcess()); + process->SetWebUIHandle(GetRoutingID(), handle.Pass()); } #if defined(OS_ANDROID) diff --git a/content/child/child_thread.cc b/content/child/child_thread.cc index 4bced8c..72be9fb 100644 --- a/content/child/child_thread.cc +++ b/content/child/child_thread.cc @@ -29,7 +29,6 @@ #include "content/child/child_resource_message_filter.h" #include "content/child/child_shared_bitmap_manager.h" #include "content/child/fileapi/file_system_dispatcher.h" -#include "content/child/mojo/mojo_application.h" #include "content/child/power_monitor_broadcast_source.h" #include "content/child/quota_dispatcher.h" #include "content/child/quota_message_filter.h" @@ -237,8 +236,6 @@ void ChildThread::Init() { IPC::Logging::GetInstance()->SetIPCSender(this); #endif - mojo_application_.reset(new MojoApplication(this)); - sync_message_filter_ = new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); thread_safe_sender_ = new ThreadSafeSender( @@ -352,13 +349,6 @@ void ChildThread::OnChannelError() { base::MessageLoop::current()->Quit(); } -void ChildThread::AcceptConnection( - const mojo::String& service_name, - mojo::ScopedMessagePipeHandle message_pipe) { - // By default, we don't expect incoming connections. - NOTREACHED(); -} - bool ChildThread::Send(IPC::Message* msg) { DCHECK(base::MessageLoop::current() == message_loop()); if (!channel_) { @@ -419,9 +409,6 @@ base::SharedMemory* ChildThread::AllocateSharedMemory( } bool ChildThread::OnMessageReceived(const IPC::Message& msg) { - if (mojo_application_->OnMessageReceived(msg)) - return true; - // Resource responses are sent to the resource dispatcher. if (resource_dispatcher_->OnMessageReceived(msg)) return true; diff --git a/content/child/child_thread.h b/content/child/child_thread.h index 6af7016..f8d9bf4 100644 --- a/content/child/child_thread.h +++ b/content/child/child_thread.h @@ -16,7 +16,6 @@ #include "content/common/content_export.h" #include "content/common/message_router.h" #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. -#include "mojo/public/interfaces/shell/shell.mojom.h" namespace base { class MessageLoop; @@ -44,7 +43,6 @@ class ChildHistogramMessageFilter; class ChildResourceMessageFilter; class ChildSharedBitmapManager; class FileSystemDispatcher; -class MojoApplication; class ServiceWorkerDispatcher; class ServiceWorkerMessageFilter; class QuotaDispatcher; @@ -56,9 +54,7 @@ class WebSocketDispatcher; struct RequestInfo; // The main thread of a child process derives from this class. -class CONTENT_EXPORT ChildThread : public IPC::Listener, - public IPC::Sender, - public mojo::ShellClient { +class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender { public: // Creates the thread. ChildThread(); @@ -174,11 +170,6 @@ class CONTENT_EXPORT ChildThread : public IPC::Listener, virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; virtual void OnChannelError() OVERRIDE; - // mojo::ShellClient implementation: - virtual void AcceptConnection( - const mojo::String& service_name, - mojo::ScopedMessagePipeHandle message_pipe) OVERRIDE; - private: class ChildThreadMessageRouter : public MessageRouter { public: @@ -206,8 +197,6 @@ class CONTENT_EXPORT ChildThread : public IPC::Listener, void EnsureConnected(); - scoped_ptr<MojoApplication> mojo_application_; - std::string channel_name_; scoped_ptr<IPC::SyncChannel> channel_; diff --git a/content/child/mojo/mojo_application.cc b/content/child/mojo/mojo_application.cc deleted file mode 100644 index 1d61c0b..0000000 --- a/content/child/mojo/mojo_application.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/child/mojo/mojo_application.h" - -#include "content/child/child_process.h" -#include "content/common/mojo/mojo_messages.h" -#include "ipc/ipc_message.h" - -namespace content { - -MojoApplication::MojoApplication(mojo::ShellClient* shell_client) - : shell_client_(shell_client) { -} - -MojoApplication::~MojoApplication() { -} - -bool MojoApplication::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(MojoApplication, msg) - IPC_MESSAGE_HANDLER(MojoMsg_Activate, OnActivate) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void MojoApplication::OnActivate( - const IPC::PlatformFileForTransit& file) { -#if defined(OS_POSIX) - base::PlatformFile handle = file.fd; -#elif defined(OS_WIN) - base::PlatformFile handle = file; -#endif - mojo::ScopedMessagePipeHandle message_pipe = - channel_init_.Init(handle, - ChildProcess::current()->io_message_loop_proxy()); - DCHECK(message_pipe.is_valid()); - - shell_.reset( - mojo::ScopedShellHandle::From(message_pipe.Pass()), shell_client_); -} - -} // namespace content diff --git a/content/child/mojo/mojo_application.h b/content/child/mojo/mojo_application.h deleted file mode 100644 index fad9888..0000000 --- a/content/child/mojo/mojo_application.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_CHILD_MOJO_MOJO_APPLICATION_H_ -#define CONTENT_CHILD_MOJO_MOJO_APPLICATION_H_ - -#include "ipc/ipc_platform_file.h" -#include "mojo/common/channel_init.h" -#include "mojo/public/cpp/bindings/remote_ptr.h" -#include "mojo/public/interfaces/shell/shell.mojom.h" - -namespace IPC { -class Message; -} - -namespace content { - -// MojoApplication represents the code needed to setup a child process as a -// Mojo application via Chrome IPC. Instantiate MojoApplication and call its -// OnMessageReceived method to give it a shot at handling Chrome IPC messages. -// It makes the mojo::Shell interface available and calls methods on the given -// mojo::ShellClient interface as calls come in. -class MojoApplication { - public: - // The ShellClient pointer must remain valid for the lifetime of the - // MojoApplication instance. - explicit MojoApplication(mojo::ShellClient* shell_client); - ~MojoApplication(); - - bool OnMessageReceived(const IPC::Message& msg); - - mojo::Shell* shell() { return shell_.get(); } - - private: - void OnActivate(const IPC::PlatformFileForTransit& file); - - mojo::common::ChannelInit channel_init_; - mojo::RemotePtr<mojo::Shell> shell_; - mojo::ShellClient* shell_client_; - - DISALLOW_COPY_AND_ASSIGN(MojoApplication); -}; - -} // namespace content - -#endif // CONTENT_CHILD_MOJO_MOJO_APPLICATION_H_ diff --git a/content/common/mojo/mojo_messages.h b/content/common/mojo/mojo_messages.h index e9657da..6e7685b 100644 --- a/content/common/mojo/mojo_messages.h +++ b/content/common/mojo/mojo_messages.h @@ -19,6 +19,5 @@ #define IPC_MESSAGE_START MojoMsgStart -// Mojo IPC is bootstrapped over Chrome IPC via this message. -IPC_MESSAGE_CONTROL1(MojoMsg_Activate, +IPC_MESSAGE_CONTROL1(MojoMsg_ChannelCreated, IPC::PlatformFileForTransit /* handle */); diff --git a/content/common/mojo/mojo_service_names.cc b/content/common/mojo/mojo_service_names.cc deleted file mode 100644 index 26ff68f..0000000 --- a/content/common/mojo/mojo_service_names.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/common/mojo/mojo_service_names.h" - -namespace content { - -// Renderer-provided services: - -const char kRendererService_WebUISetup[] = "content:web_ui_setup"; - -} // namespace content diff --git a/content/common/mojo/mojo_service_names.h b/content/common/mojo/mojo_service_names.h deleted file mode 100644 index 787b67d..0000000 --- a/content/common/mojo/mojo_service_names.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_COMMON_SERVICE_CONSTANTS_H_ -#define CONTENT_COMMON_SERVICE_CONSTANTS_H_ - -namespace content { - -// ---------------------------------------------------------------------------- -// Renderer-provided services: - -// WebUISetup <-> WebUISetupClient -extern const char kRendererService_WebUISetup[]; - -} // namespace content - -#endif // CONTENT_COMMON_SERVICE_CONSTANTS_H_ diff --git a/content/common/mojo/render_process.mojom b/content/common/mojo/render_process.mojom new file mode 100644 index 0000000..1ad9e55 --- /dev/null +++ b/content/common/mojo/render_process.mojom @@ -0,0 +1,17 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module content { + +[Peer=RenderProcessMojo] +interface RenderProcessHostMojo { +}; + +[Peer=RenderProcessHostMojo] +interface RenderProcessMojo { + SetWebUIHandle(int32 view_routing_id, + handle<message_pipe> browser_web_ui_handle); +}; + +} diff --git a/content/common/web_ui_setup.mojom b/content/common/web_ui_setup.mojom deleted file mode 100644 index d61d96c..0000000 --- a/content/common/web_ui_setup.mojom +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -module content { - -[Peer=WebUISetup] -interface WebUISetupClient { -}; - -[Peer=WebUISetupClient] -interface WebUISetup { - SetWebUIHandle(int32 view_routing_id, handle<message_pipe> web_ui_handle); -}; - -} diff --git a/content/content_app.gypi b/content/content_app.gypi index 5cc4925..ad443e2 100644 --- a/content/content_app.gypi +++ b/content/content_app.gypi @@ -10,7 +10,6 @@ '../base/base.gyp:base', '../base/base.gyp:base_i18n', '../crypto/crypto.gyp:crypto', - '../mojo/mojo.gyp:mojo_shell_bindings', '../ui/base/ui_base.gyp:ui_base', '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', diff --git a/content/content_browser.gypi b/content/content_browser.gypi index b323ec2..e767477 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -7,7 +7,6 @@ '../base/base.gyp:base_static', '../crypto/crypto.gyp:crypto', '../google_apis/google_apis.gyp:google_apis', - '../mojo/mojo.gyp:mojo_shell_bindings', '../net/net.gyp:net', '../skia/skia.gyp:skia', '../sql/sql.gyp:sql', @@ -809,8 +808,6 @@ 'browser/message_port_service.h', 'browser/mime_registry_message_filter.cc', 'browser/mime_registry_message_filter.h', - 'browser/mojo/mojo_application_host.cc', - 'browser/mojo/mojo_application_host.h', 'browser/net/browser_online_state_observer.cc', 'browser/net/browser_online_state_observer.h', 'browser/net/sqlite_persistent_cookie_store.cc', @@ -1078,6 +1075,8 @@ 'browser/renderer_host/render_message_filter.h', 'browser/renderer_host/render_process_host_impl.cc', 'browser/renderer_host/render_process_host_impl.h', + 'browser/renderer_host/render_process_host_mojo_impl.cc', + 'browser/renderer_host/render_process_host_mojo_impl.h', 'browser/renderer_host/render_sandbox_host_linux.cc', 'browser/renderer_host/render_process_host_impl.h', 'browser/renderer_host/render_view_host_delegate.cc', diff --git a/content/content_child.gypi b/content/content_child.gypi index c46451c..575e5ff 100644 --- a/content/content_child.gypi +++ b/content/content_child.gypi @@ -6,8 +6,6 @@ 'dependencies': [ '../base/base.gyp:base', '../components/tracing.gyp:tracing', - '../mojo/mojo.gyp:mojo_environment_chromium', - '../mojo/mojo.gyp:mojo_shell_bindings', '../skia/skia.gyp:skia', '../ui/base/ui_base.gyp:ui_base', '../ui/gfx/gfx.gyp:gfx', @@ -81,8 +79,6 @@ 'child/indexed_db/webidbdatabase_impl.h', 'child/indexed_db/webidbfactory_impl.cc', 'child/indexed_db/webidbfactory_impl.h', - 'child/mojo/mojo_application.cc', - 'child/mojo/mojo_application.h', 'child/npapi/np_channel_base.cc', 'child/npapi/np_channel_base.h', 'child/npapi/npobject_base.h', diff --git a/content/content_common.gypi b/content/content_common.gypi index c9aa6a7..a4d16c3 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -352,8 +352,6 @@ 'common/message_router.h', 'common/mime_registry_messages.h', 'common/mojo/mojo_messages.h', - 'common/mojo/mojo_service_names.cc', - 'common/mojo/mojo_service_names.h', 'common/navigation_gesture.h', 'common/net/url_fetcher.cc', 'common/net/url_request_user_data.cc', diff --git a/content/content_common_mojo_bindings.gypi b/content/content_common_mojo_bindings.gypi index 6e0a62a..71d9225 100644 --- a/content/content_common_mojo_bindings.gypi +++ b/content/content_common_mojo_bindings.gypi @@ -12,7 +12,7 @@ '../mojo/mojo.gyp:mojo_environment_chromium', ], 'sources': [ - 'common/web_ui_setup.mojom', + 'common/mojo/render_process.mojom', ], # TODO(sky): this shouldn't be necessary. It's working around a bug in # gyp. diff --git a/content/content_gpu.gypi b/content/content_gpu.gypi index 14ae896..1cc6de6 100644 --- a/content/content_gpu.gypi +++ b/content/content_gpu.gypi @@ -5,7 +5,6 @@ { 'dependencies': [ '../base/base.gyp:base', - '../mojo/mojo.gyp:mojo_shell_bindings', '../skia/skia.gyp:skia', '../ui/gl/gl.gyp:gl', ], diff --git a/content/content_plugin.gypi b/content/content_plugin.gypi index a8fa444..2b53523 100644 --- a/content/content_plugin.gypi +++ b/content/content_plugin.gypi @@ -6,7 +6,6 @@ 'conditions': [ ['enable_plugins==1 and OS!="linux"', { 'dependencies': [ - '../mojo/mojo.gyp:mojo_shell_bindings', '../skia/skia.gyp:skia', '../third_party/WebKit/public/blink.gyp:blink', '../third_party/npapi/npapi.gyp:npapi', diff --git a/content/content_ppapi_plugin.gypi b/content/content_ppapi_plugin.gypi index 0757a7d..578ffd0 100644 --- a/content/content_ppapi_plugin.gypi +++ b/content/content_ppapi_plugin.gypi @@ -7,7 +7,6 @@ ['enable_plugins==1', { 'dependencies': [ '../base/base.gyp:base', - '../mojo/mojo.gyp:mojo_shell_bindings', '../ppapi/ppapi_internal.gyp:ppapi_ipc', '../ui/base/ui_base.gyp:ui_base', '../ui/gfx/gfx.gyp:gfx', diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index f45e51b..8f86f8b 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -10,7 +10,6 @@ '../media/media.gyp:media', '../mojo/mojo.gyp:mojo_environment_chromium', '../mojo/mojo.gyp:mojo_js_bindings_lib', - '../mojo/mojo.gyp:mojo_shell_bindings', '../net/net.gyp:net', '../skia/skia.gyp:skia', '../third_party/WebKit/public/blink.gyp:blink', @@ -314,6 +313,8 @@ 'renderer/menu_item_builder.h', 'renderer/mhtml_generator.cc', 'renderer/mhtml_generator.h', + 'renderer/mojo/mojo_render_process_observer.cc', + 'renderer/mojo/mojo_render_process_observer.h', 'renderer/mouse_lock_dispatcher.cc', 'renderer/mouse_lock_dispatcher.h', 'renderer/notification_provider.cc', @@ -536,8 +537,6 @@ 'renderer/web_ui_mojo_context_state.h', 'renderer/web_ui_runner.cc', 'renderer/web_ui_runner.h', - 'renderer/web_ui_setup_impl.cc', - 'renderer/web_ui_setup_impl.h', 'renderer/webclipboard_impl.cc', 'renderer/webclipboard_impl.h', 'renderer/webgraphicscontext3d_provider_impl.cc', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 58490de..76ff48d 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -22,7 +22,6 @@ ], 'include_dirs': [ '..', - '<(SHARED_INTERMEDIATE_DIR)', ], 'sources': [ 'public/test/layouttest_support.h', diff --git a/content/content_utility.gypi b/content/content_utility.gypi index 513c240..2d2a7c0 100644 --- a/content/content_utility.gypi +++ b/content/content_utility.gypi @@ -6,7 +6,6 @@ 'dependencies': [ '../base/base.gyp:base', '../courgette/courgette.gyp:courgette_lib', - '../mojo/mojo.gyp:mojo_shell_bindings', ], 'sources': [ 'public/utility/content_utility_client.cc', diff --git a/content/content_worker.gypi b/content/content_worker.gypi index 5264a2c..95d5292 100644 --- a/content/content_worker.gypi +++ b/content/content_worker.gypi @@ -5,7 +5,6 @@ { 'dependencies': [ '../base/base.gyp:base', - '../mojo/mojo.gyp:mojo_shell_bindings', '../skia/skia.gyp:skia', '../third_party/WebKit/public/blink.gyp:blink', ], diff --git a/content/renderer/mojo/mojo_render_process_observer.cc b/content/renderer/mojo/mojo_render_process_observer.cc new file mode 100644 index 0000000..9790787 --- /dev/null +++ b/content/renderer/mojo/mojo_render_process_observer.cc @@ -0,0 +1,72 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/renderer/mojo/mojo_render_process_observer.h" + +#include "base/message_loop/message_loop.h" +#include "content/child/child_process.h" +#include "content/common/mojo/mojo_messages.h" +#include "content/public/renderer/render_thread.h" +#include "content/public/renderer/render_view.h" +#include "content/renderer/web_ui_mojo.h" +#include "mojo/common/mojo_channel_init.h" + +namespace content { + +MojoRenderProcessObserver::MojoRenderProcessObserver( + RenderThread* render_thread) + : render_thread_(render_thread) { + render_thread_->AddObserver(this); +} + +bool MojoRenderProcessObserver::OnControlMessageReceived( + const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(MojoRenderProcessObserver, message) + IPC_MESSAGE_HANDLER(MojoMsg_ChannelCreated, OnChannelCreated) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void MojoRenderProcessObserver::OnRenderProcessShutdown() { + delete this; +} + +MojoRenderProcessObserver::~MojoRenderProcessObserver() { + render_thread_->RemoveObserver(this); +} + +void MojoRenderProcessObserver::OnChannelCreated( + const IPC::PlatformFileForTransit& file) { +#if defined(OS_POSIX) + base::PlatformFile handle = file.fd; +#elif defined(OS_WIN) + base::PlatformFile handle = file; +#endif + DCHECK(!channel_init_.get()); + channel_init_.reset(new mojo::common::MojoChannelInit); + channel_init_->Init(handle, ChildProcess::current()->io_message_loop_proxy()); + if (!channel_init_->is_handle_valid()) + return; + + ScopedRenderProcessHostMojoHandle render_process_host_handle( + RenderProcessHostMojoHandle( + channel_init_->bootstrap_message_pipe().release().value())); + render_process_host_mojo_.reset(render_process_host_handle.Pass(), this); +} + +void MojoRenderProcessObserver::SetWebUIHandle( + int32 view_routing_id, + mojo::ScopedMessagePipeHandle web_ui_handle) { + RenderView* render_view = RenderView::FromRoutingID(view_routing_id); + if (!render_view) + return; + WebUIMojo* web_ui_mojo = WebUIMojo::Get(render_view); + if (!web_ui_mojo) + return; + web_ui_mojo->SetBrowserHandle(web_ui_handle.Pass()); +} + +} // namespace content diff --git a/content/renderer/mojo/mojo_render_process_observer.h b/content/renderer/mojo/mojo_render_process_observer.h new file mode 100644 index 0000000..a66a98d --- /dev/null +++ b/content/renderer/mojo/mojo_render_process_observer.h @@ -0,0 +1,61 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_RENDERER_MOJO_MOJO_RENDER_PROCESS_OBSERVER_H_ +#define CONTENT_RENDERER_MOJO_MOJO_RENDER_PROCESS_OBSERVER_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/common/mojo/render_process.mojom.h" +#include "content/public/renderer/render_process_observer.h" +#include "ipc/ipc_platform_file.h" +#include "mojo/public/cpp/bindings/remote_ptr.h" + +namespace mojo { +namespace common { +class MojoChannelInit; +} +namespace embedder { +struct ChannelInfo; +} +} + +namespace content { + +class RenderThread; + +// RenderProcessObserver implementation that initializes the mojo channel when +// the right IPC is seen. +// MojoRenderProcessObserver deletes itself when the RenderProcess is shutdown. +class MojoRenderProcessObserver + : public content::RenderProcessObserver, + public RenderProcessMojo { + public: + MojoRenderProcessObserver(RenderThread* render_thread); + + // RenderProcessObserver overrides: + virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; + virtual void OnRenderProcessShutdown() OVERRIDE; + + private: + virtual ~MojoRenderProcessObserver(); + + void OnChannelCreated(const IPC::PlatformFileForTransit& file); + + // RenderProcessMojo overrides: + virtual void SetWebUIHandle( + int32 view_routing_id, + mojo::ScopedMessagePipeHandle web_ui_handle) OVERRIDE; + + content::RenderThread* render_thread_; + + scoped_ptr<mojo::common::MojoChannelInit> channel_init_; + + mojo::RemotePtr<content::RenderProcessHostMojo> render_process_host_mojo_; + + DISALLOW_COPY_AND_ASSIGN(MojoRenderProcessObserver); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_MOJO_MOJO_RENDER_PROCESS_OBSERVER_H_ diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index 455c20d..8122735 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -51,7 +51,6 @@ #include "content/common/gpu/client/gpu_memory_buffer_impl.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/gpu_process_launch_causes.h" -#include "content/common/mojo/mojo_service_names.h" #include "content/common/resource_messages.h" #include "content/common/view_messages.h" #include "content/common/worker_messages.h" @@ -83,6 +82,7 @@ #include "content/renderer/media/video_capture_impl_manager.h" #include "content/renderer/media/video_capture_message_filter.h" #include "content/renderer/media/webrtc_identity_service.h" +#include "content/renderer/mojo/mojo_render_process_observer.h" #include "content/renderer/p2p/socket_dispatcher.h" #include "content/renderer/render_process_impl.h" #include "content/renderer/render_view_impl.h" @@ -90,7 +90,6 @@ #include "content/renderer/service_worker/embedded_worker_context_message_filter.h" #include "content/renderer/service_worker/embedded_worker_dispatcher.h" #include "content/renderer/shared_worker/embedded_shared_worker_stub.h" -#include "content/renderer/web_ui_setup_impl.h" #include "grit/content_resources.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_forwarding_message_filter.h" @@ -98,7 +97,6 @@ #include "media/base/audio_hardware_config.h" #include "media/base/media.h" #include "media/filters/gpu_video_accelerator_factories.h" -#include "mojo/common/common_type_converters.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "skia/ext/event_tracer_impl.h" @@ -396,6 +394,9 @@ void RenderThreadImpl::Init() { AddFilter((new EmbeddedWorkerContextMessageFilter())->GetFilter()); + // MojoRenderProcessObserver deletes itself as necessary. + new MojoRenderProcessObserver(this); + GetContentClient()->renderer()->RenderThreadStarted(); InitSkiaEventTracer(); @@ -1201,17 +1202,6 @@ scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer( internalformat).PassAs<gfx::GpuMemoryBuffer>(); } -void RenderThreadImpl::AcceptConnection( - const mojo::String& service_name, - mojo::ScopedMessagePipeHandle message_pipe) { - // TODO(darin): Invent some kind of registration system to use here. - if (service_name.To<base::StringPiece>() == kRendererService_WebUISetup) { - WebUISetupImpl::Bind(message_pipe.Pass()); - } else { - NOTREACHED() << "Unknown service name"; - } -} - void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() { suspend_webkit_shared_timer_ = false; } diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index a816bfe..4c945b1 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -401,11 +401,6 @@ class CONTENT_EXPORT RenderThreadImpl : public RenderThread, size_t height, unsigned internalformat) OVERRIDE; - // mojo::ShellClient implementation: - virtual void AcceptConnection( - const mojo::String& service_name, - mojo::ScopedMessagePipeHandle message_pipe) OVERRIDE; - void Init(); void OnSetZoomLevelForCurrentURL(const std::string& scheme, diff --git a/content/renderer/web_ui_setup_impl.cc b/content/renderer/web_ui_setup_impl.cc deleted file mode 100644 index e4c065f..0000000 --- a/content/renderer/web_ui_setup_impl.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/renderer/web_ui_setup_impl.h" - -#include "content/public/renderer/render_view.h" -#include "content/renderer/web_ui_mojo.h" - -namespace content { - -// static -void WebUISetupImpl::Bind(mojo::ScopedMessagePipeHandle handle) { - // This instance will be destroyed when the pipe is closed. See OnError. - new WebUISetupImpl(handle.Pass()); -} - -WebUISetupImpl::WebUISetupImpl(mojo::ScopedMessagePipeHandle handle) - : client_(ScopedWebUISetupClientHandle::From(handle.Pass()), this) { -} - -WebUISetupImpl::~WebUISetupImpl() { -} - -void WebUISetupImpl::SetWebUIHandle( - int32 view_routing_id, - mojo::ScopedMessagePipeHandle web_ui_handle) { - RenderView* render_view = RenderView::FromRoutingID(view_routing_id); - if (!render_view) - return; - WebUIMojo* web_ui_mojo = WebUIMojo::Get(render_view); - if (!web_ui_mojo) - return; - web_ui_mojo->SetBrowserHandle(web_ui_handle.Pass()); -} - -void WebUISetupImpl::OnError() { - delete this; -} - -} // namespace content diff --git a/content/renderer/web_ui_setup_impl.h b/content/renderer/web_ui_setup_impl.h deleted file mode 100644 index 1bfc6ca..0000000 --- a/content/renderer/web_ui_setup_impl.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_RENDERER_WEB_UI_SETUP_IMPL_H_ -#define CONTENT_RENDERER_WEB_UI_SETUP_IMPL_H_ - -#include "base/basictypes.h" -#include "content/common/web_ui_setup.mojom.h" -#include "mojo/public/cpp/bindings/error_handler.h" -#include "mojo/public/cpp/bindings/remote_ptr.h" - -namespace content { - -class WebUISetupImpl : public WebUISetup, - public mojo::ErrorHandler { - public: - static void Bind(mojo::ScopedMessagePipeHandle handle); - - private: - explicit WebUISetupImpl(mojo::ScopedMessagePipeHandle handle); - virtual ~WebUISetupImpl(); - - // WebUISetup methods: - virtual void SetWebUIHandle( - int32_t view_routing_id, - mojo::ScopedMessagePipeHandle web_ui_handle) OVERRIDE; - - // mojo::ErrorHandler methods: - virtual void OnError() OVERRIDE; - - mojo::RemotePtr<WebUISetupClient> client_; - - DISALLOW_COPY_AND_ASSIGN(WebUISetupImpl); -}; - -} // namespace content - -#endif // CONTENT_RENDERER_WEB_UI_SETUP_IMPL_H_ diff --git a/mojo/common/channel_init.cc b/mojo/common/mojo_channel_init.cc index 7eef2ae..96190f9 100644 --- a/mojo/common/channel_init.cc +++ b/mojo/common/mojo_channel_init.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "mojo/common/channel_init.h" +#include "mojo/common/mojo_channel_init.h" #include "base/bind.h" #include "base/message_loop/message_loop.h" @@ -11,12 +11,13 @@ namespace mojo { namespace common { -ChannelInit::ChannelInit() +MojoChannelInit::MojoChannelInit() : channel_info_(NULL), weak_factory_(this) { } -ChannelInit::~ChannelInit() { +MojoChannelInit::~MojoChannelInit() { + bootstrap_message_pipe_.reset(); if (channel_info_) { io_thread_task_runner_->PostTask( FROM_HERE, @@ -24,24 +25,23 @@ ChannelInit::~ChannelInit() { } } -mojo::ScopedMessagePipeHandle ChannelInit::Init( +void MojoChannelInit::Init( base::PlatformFile file, scoped_refptr<base::TaskRunner> io_thread_task_runner) { DCHECK(!io_thread_task_runner_.get()); // Should only init once. io_thread_task_runner_ = io_thread_task_runner; - mojo::ScopedMessagePipeHandle message_pipe = mojo::embedder::CreateChannel( + bootstrap_message_pipe_ = mojo::embedder::CreateChannel( mojo::embedder::ScopedPlatformHandle( mojo::embedder::PlatformHandle(file)), io_thread_task_runner, - base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), + base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), io_thread_task_runner), base::MessageLoop::current()->message_loop_proxy()).Pass(); - return message_pipe.Pass(); } // static -void ChannelInit::OnCreatedChannel( - base::WeakPtr<ChannelInit> host, +void MojoChannelInit::OnCreatedChannel( + base::WeakPtr<MojoChannelInit> host, scoped_refptr<base::TaskRunner> io_thread, embedder::ChannelInfo* channel) { // By the time we get here |host| may have been destroyed. If so, shutdown the diff --git a/mojo/common/channel_init.h b/mojo/common/mojo_channel_init.h index ca134cb..8fa0094 100644 --- a/mojo/common/channel_init.h +++ b/mojo/common/mojo_channel_init.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MOJO_COMMON_CHANNEL_INIT_H_ -#define MOJO_COMMON_CHANNEL_INIT_H_ +#ifndef MOJO_COMMON_MOJO_CHANNEL_INIT_H_ +#define MOJO_COMMON_MOJO_CHANNEL_INIT_H_ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" @@ -23,23 +23,27 @@ struct ChannelInfo; namespace common { -// ChannelInit handle creation (and destruction) of the mojo channel. It is +// MojoChannelInit handle creation (and destruction) of the mojo channel. It is // expected that this class is created and destroyed on the main thread. -class MOJO_COMMON_EXPORT ChannelInit { +class MOJO_COMMON_EXPORT MojoChannelInit { public: - ChannelInit(); - ~ChannelInit(); + MojoChannelInit(); + ~MojoChannelInit(); - // Initializes the channel. This takes ownership of |file|. Returns the - // primordial MessagePipe for the channel. - mojo::ScopedMessagePipeHandle Init( - base::PlatformFile file, - scoped_refptr<base::TaskRunner> io_thread_task_runner); + // Inits the channel. This takes ownership of |file|. + void Init(base::PlatformFile file, + scoped_refptr<base::TaskRunner> io_thread_task_runner); + + bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } + + mojo::ScopedMessagePipeHandle bootstrap_message_pipe() { + return bootstrap_message_pipe_.Pass(); + } private: // Invoked on the main thread once the channel has been established. static void OnCreatedChannel( - base::WeakPtr<ChannelInit> host, + base::WeakPtr<MojoChannelInit> host, scoped_refptr<base::TaskRunner> io_thread, embedder::ChannelInfo* channel); @@ -48,12 +52,15 @@ class MOJO_COMMON_EXPORT ChannelInit { // If non-null the channel has been established. embedder::ChannelInfo* channel_info_; - base::WeakPtrFactory<ChannelInit> weak_factory_; + // The handle from channel creation. + mojo::ScopedMessagePipeHandle bootstrap_message_pipe_; + + base::WeakPtrFactory<MojoChannelInit> weak_factory_; - DISALLOW_COPY_AND_ASSIGN(ChannelInit); + DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); }; } // namespace common } // namespace mojo -#endif // MOJO_COMMON_CHANNEL_INIT_H_ +#endif // MOJO_COMMON_MOJO_CHANNEL_INIT_H_ diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index 7c187a3..24bedee 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -279,8 +279,6 @@ 'mojo_system_impl', ], 'sources': [ - 'common/channel_init.cc', - 'common/channel_init.h', 'common/common_type_converters.cc', 'common/common_type_converters.h', 'common/environment_data.cc', @@ -290,6 +288,8 @@ 'common/message_pump_mojo.cc', 'common/message_pump_mojo.h', 'common/message_pump_mojo_handler.h', + 'common/mojo_channel_init.cc', + 'common/mojo_channel_init.h', 'common/time_helper.cc', 'common/time_helper.h', ], |