From 618b9f7478656c9388f79daa6d54bf84d5927473 Mon Sep 17 00:00:00 2001 From: "sadrul@chromium.org" Date: Wed, 18 Jun 2014 00:23:40 +0000 Subject: [PATCH] app-shell: Introduce a ShellRendererMainDelegate. It may be necessary to create custom filters/observers etc. on the renderer side in athena (e.g., for virtual keyboard support). So allow athena to install a delegate to be created in the renderer process. The delegate is notified when the RenderThread is initialized, or when new RenderViews are created. BUG=380215 R=jamescook@chromium.org, oshima@chromium.org Review URL: https://codereview.chromium.org/331323008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277922 0039d316-1c4b-4281-b951-d872f2087c98 --- apps/shell/app/shell_main_delegate.cc | 9 +++++- apps/shell/app/shell_main_delegate.h | 5 ++++ apps/shell/app_shell.gyp | 1 + .../renderer/shell_content_renderer_client.cc | 10 ++++++- .../renderer/shell_content_renderer_client.h | 5 +++- .../renderer/shell_renderer_main_delegate.h | 30 +++++++++++++++++++ athena/main/DEPS | 1 + athena/main/athena_main.cc | 21 +++++++++++++ 8 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 apps/shell/renderer/shell_renderer_main_delegate.h diff --git a/apps/shell/app/shell_main_delegate.cc b/apps/shell/app/shell_main_delegate.cc index b8f835d1ae84a3..2a9cd1439f170d 100644 --- a/apps/shell/app/shell_main_delegate.cc +++ b/apps/shell/app/shell_main_delegate.cc @@ -8,6 +8,7 @@ #include "apps/shell/browser/shell_content_browser_client.h" #include "apps/shell/common/shell_content_client.h" #include "apps/shell/renderer/shell_content_renderer_client.h" +#include "apps/shell/renderer/shell_renderer_main_delegate.h" #include "base/command_line.h" #include "base/files/file_path.h" #include "base/logging.h" @@ -73,7 +74,8 @@ content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { content::ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() { - renderer_client_.reset(new ShellContentRendererClient); + renderer_client_.reset( + new ShellContentRendererClient(CreateShellRendererMainDelegate())); return renderer_client_.get(); } @@ -81,6 +83,11 @@ ShellBrowserMainDelegate* ShellMainDelegate::CreateShellBrowserMainDelegate() { return new DefaultShellBrowserMainDelegate(); } +scoped_ptr +ShellMainDelegate::CreateShellRendererMainDelegate() { + return scoped_ptr(); +} + // static bool ShellMainDelegate::ProcessNeedsResourceBundle( const std::string& process_type) { diff --git a/apps/shell/app/shell_main_delegate.h b/apps/shell/app/shell_main_delegate.h index 45ba122f32378f..594f7634dabe0f 100644 --- a/apps/shell/app/shell_main_delegate.h +++ b/apps/shell/app/shell_main_delegate.h @@ -18,6 +18,7 @@ class ContentRendererClient; namespace apps { class ShellBrowserMainDelegate; +class ShellRendererMainDelegate; class ShellMainDelegate : public content::ContentMainDelegate { public: @@ -35,6 +36,10 @@ class ShellMainDelegate : public content::ContentMainDelegate { // The created object is owned by ShellBrowserMainParts. virtual ShellBrowserMainDelegate* CreateShellBrowserMainDelegate(); + // The returned object is owned by ShellContentRendererClient. + virtual scoped_ptr + CreateShellRendererMainDelegate(); + private: // |process_type| is zygote, renderer, utility, etc. Returns true if the // process needs data from resources.pak. diff --git a/apps/shell/app_shell.gyp b/apps/shell/app_shell.gyp index 2f95c699b657fa..8b2996cf1d905e 100644 --- a/apps/shell/app_shell.gyp +++ b/apps/shell/app_shell.gyp @@ -146,6 +146,7 @@ 'renderer/shell_dispatcher_delegate.h', 'renderer/shell_extensions_renderer_client.cc', 'renderer/shell_extensions_renderer_client.h', + 'renderer/shell_renderer_main_delegate.h', ], 'conditions': [ ['chromeos==1', { diff --git a/apps/shell/renderer/shell_content_renderer_client.cc b/apps/shell/renderer/shell_content_renderer_client.cc index e0217fd2c70276..70e0698ce500e9 100644 --- a/apps/shell/renderer/shell_content_renderer_client.cc +++ b/apps/shell/renderer/shell_content_renderer_client.cc @@ -7,6 +7,7 @@ #include "apps/shell/common/shell_extensions_client.h" #include "apps/shell/renderer/shell_dispatcher_delegate.h" #include "apps/shell/renderer/shell_extensions_renderer_client.h" +#include "apps/shell/renderer/shell_renderer_main_delegate.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer_tracker.h" @@ -58,7 +59,10 @@ void ShellFrameHelper::WillReleaseScriptContext(v8::Handle context, } // namespace -ShellContentRendererClient::ShellContentRendererClient() {} +ShellContentRendererClient::ShellContentRendererClient( + scoped_ptr delegate) + : delegate_(delegate.Pass()) { +} ShellContentRendererClient::~ShellContentRendererClient() {} @@ -80,6 +84,8 @@ void ShellContentRendererClient::RenderThreadStarted() { // TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes. // See ChromeContentRendererClient for details. + if (delegate_) + delegate_->OnThreadStarted(thread); } void ShellContentRendererClient::RenderFrameCreated( @@ -91,6 +97,8 @@ void ShellContentRendererClient::RenderFrameCreated( void ShellContentRendererClient::RenderViewCreated( content::RenderView* render_view) { new extensions::ExtensionHelper(render_view, extension_dispatcher_.get()); + if (delegate_) + delegate_->OnViewCreated(render_view); } bool ShellContentRendererClient::WillSendRequest( diff --git a/apps/shell/renderer/shell_content_renderer_client.h b/apps/shell/renderer/shell_content_renderer_client.h index 506704c6939b81..9f7aee2e227a9a 100644 --- a/apps/shell/renderer/shell_content_renderer_client.h +++ b/apps/shell/renderer/shell_content_renderer_client.h @@ -19,11 +19,13 @@ namespace apps { class ShellExtensionsClient; class ShellExtensionsRendererClient; +class ShellRendererMainDelegate; // Renderer initialization and runtime support for app_shell. class ShellContentRendererClient : public content::ContentRendererClient { public: - ShellContentRendererClient(); + explicit ShellContentRendererClient( + scoped_ptr delegate); virtual ~ShellContentRendererClient(); // content::ContentRendererClient implementation: @@ -42,6 +44,7 @@ class ShellContentRendererClient : public content::ContentRendererClient { virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE; private: + scoped_ptr delegate_; scoped_ptr extensions_client_; scoped_ptr extensions_renderer_client_; scoped_ptr extension_dispatcher_delegate_; diff --git a/apps/shell/renderer/shell_renderer_main_delegate.h b/apps/shell/renderer/shell_renderer_main_delegate.h new file mode 100644 index 00000000000000..604b6c72887ea4 --- /dev/null +++ b/apps/shell/renderer/shell_renderer_main_delegate.h @@ -0,0 +1,30 @@ +// 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 APPS_SHELL_RENDERER_SHELL_RENDERER_MAIN_DELEGATE_H_ +#define APPS_SHELL_RENDERER_SHELL_RENDERER_MAIN_DELEGATE_H_ + +namespace content { +class RenderThread; +class RenderView; +} + +namespace apps { + +class ShellRendererMainDelegate { + public: + virtual ~ShellRendererMainDelegate() {} + + // Called when |thread| is started, after the extensions subsystem has been + // initialized for |thread|. + virtual void OnThreadStarted(content::RenderThread* thread) = 0; + + // Called for each RenderView created in the renderer process, after the + // extension related code has been initialized for the view. + virtual void OnViewCreated(content::RenderView* view) = 0; +}; + +} // namespace apps + +#endif // APPS_SHELL_RENDERER_SHELL_RENDERER_MAIN_DELEGATE_H_ diff --git a/athena/main/DEPS b/athena/main/DEPS index 3868d5f42cc2c7..b03fcf4d456f37 100644 --- a/athena/main/DEPS +++ b/athena/main/DEPS @@ -20,6 +20,7 @@ specific_include_rules = { "athena_main\.cc": [ "+apps/shell/app", "+apps/shell/browser", + "+apps/shell/renderer", "+content/public/app", ], "athena_app_window_controller\.*": [ diff --git a/athena/main/athena_main.cc b/athena/main/athena_main.cc index f12006cb476eb9..6ac6efc6fd013b 100644 --- a/athena/main/athena_main.cc +++ b/athena/main/athena_main.cc @@ -6,6 +6,7 @@ #include "apps/shell/browser/shell_browser_main_delegate.h" #include "apps/shell/browser/shell_desktop_controller.h" #include "apps/shell/browser/shell_extension_system.h" +#include "apps/shell/renderer/shell_renderer_main_delegate.h" #include "athena/content/public/content_activity_factory.h" #include "athena/content/public/content_app_model_builder.h" #include "athena/home/public/home_card.h" @@ -63,6 +64,20 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate { DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); }; +class AthenaRendererMainDelegate : public apps::ShellRendererMainDelegate { + public: + AthenaRendererMainDelegate() {} + virtual ~AthenaRendererMainDelegate() {} + + private: + // apps::ShellRendererMainDelegate: + virtual void OnThreadStarted(content::RenderThread* thread) OVERRIDE {} + + virtual void OnViewCreated(content::RenderView* render_view) OVERRIDE {} + + DISALLOW_COPY_AND_ASSIGN(AthenaRendererMainDelegate); +}; + class AthenaMainDelegate : public apps::ShellMainDelegate { public: AthenaMainDelegate() {} @@ -75,6 +90,12 @@ class AthenaMainDelegate : public apps::ShellMainDelegate { return new AthenaBrowserMainDelegate(); } + virtual scoped_ptr + CreateShellRendererMainDelegate() OVERRIDE { + return scoped_ptr( + new AthenaRendererMainDelegate()); + } + DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate); };