Commit 618b9f74 authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent 75ef0cd2
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "apps/shell/browser/shell_content_browser_client.h" #include "apps/shell/browser/shell_content_browser_client.h"
#include "apps/shell/common/shell_content_client.h" #include "apps/shell/common/shell_content_client.h"
#include "apps/shell/renderer/shell_content_renderer_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/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -73,7 +74,8 @@ content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { ...@@ -73,7 +74,8 @@ content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {
content::ContentRendererClient* content::ContentRendererClient*
ShellMainDelegate::CreateContentRendererClient() { ShellMainDelegate::CreateContentRendererClient() {
renderer_client_.reset(new ShellContentRendererClient); renderer_client_.reset(
new ShellContentRendererClient(CreateShellRendererMainDelegate()));
return renderer_client_.get(); return renderer_client_.get();
} }
...@@ -81,6 +83,11 @@ ShellBrowserMainDelegate* ShellMainDelegate::CreateShellBrowserMainDelegate() { ...@@ -81,6 +83,11 @@ ShellBrowserMainDelegate* ShellMainDelegate::CreateShellBrowserMainDelegate() {
return new DefaultShellBrowserMainDelegate(); return new DefaultShellBrowserMainDelegate();
} }
scoped_ptr<ShellRendererMainDelegate>
ShellMainDelegate::CreateShellRendererMainDelegate() {
return scoped_ptr<ShellRendererMainDelegate>();
}
// static // static
bool ShellMainDelegate::ProcessNeedsResourceBundle( bool ShellMainDelegate::ProcessNeedsResourceBundle(
const std::string& process_type) { const std::string& process_type) {
......
...@@ -18,6 +18,7 @@ class ContentRendererClient; ...@@ -18,6 +18,7 @@ class ContentRendererClient;
namespace apps { namespace apps {
class ShellBrowserMainDelegate; class ShellBrowserMainDelegate;
class ShellRendererMainDelegate;
class ShellMainDelegate : public content::ContentMainDelegate { class ShellMainDelegate : public content::ContentMainDelegate {
public: public:
...@@ -35,6 +36,10 @@ class ShellMainDelegate : public content::ContentMainDelegate { ...@@ -35,6 +36,10 @@ class ShellMainDelegate : public content::ContentMainDelegate {
// The created object is owned by ShellBrowserMainParts. // The created object is owned by ShellBrowserMainParts.
virtual ShellBrowserMainDelegate* CreateShellBrowserMainDelegate(); virtual ShellBrowserMainDelegate* CreateShellBrowserMainDelegate();
// The returned object is owned by ShellContentRendererClient.
virtual scoped_ptr<ShellRendererMainDelegate>
CreateShellRendererMainDelegate();
private: private:
// |process_type| is zygote, renderer, utility, etc. Returns true if the // |process_type| is zygote, renderer, utility, etc. Returns true if the
// process needs data from resources.pak. // process needs data from resources.pak.
......
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
'renderer/shell_dispatcher_delegate.h', 'renderer/shell_dispatcher_delegate.h',
'renderer/shell_extensions_renderer_client.cc', 'renderer/shell_extensions_renderer_client.cc',
'renderer/shell_extensions_renderer_client.h', 'renderer/shell_extensions_renderer_client.h',
'renderer/shell_renderer_main_delegate.h',
], ],
'conditions': [ 'conditions': [
['chromeos==1', { ['chromeos==1', {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "apps/shell/common/shell_extensions_client.h" #include "apps/shell/common/shell_extensions_client.h"
#include "apps/shell/renderer/shell_dispatcher_delegate.h" #include "apps/shell/renderer/shell_dispatcher_delegate.h"
#include "apps/shell/renderer/shell_extensions_renderer_client.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.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h" #include "content/public/renderer/render_frame_observer_tracker.h"
...@@ -58,7 +59,10 @@ void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context, ...@@ -58,7 +59,10 @@ void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context,
} // namespace } // namespace
ShellContentRendererClient::ShellContentRendererClient() {} ShellContentRendererClient::ShellContentRendererClient(
scoped_ptr<ShellRendererMainDelegate> delegate)
: delegate_(delegate.Pass()) {
}
ShellContentRendererClient::~ShellContentRendererClient() {} ShellContentRendererClient::~ShellContentRendererClient() {}
...@@ -80,6 +84,8 @@ void ShellContentRendererClient::RenderThreadStarted() { ...@@ -80,6 +84,8 @@ void ShellContentRendererClient::RenderThreadStarted() {
// TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes. // TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes.
// See ChromeContentRendererClient for details. // See ChromeContentRendererClient for details.
if (delegate_)
delegate_->OnThreadStarted(thread);
} }
void ShellContentRendererClient::RenderFrameCreated( void ShellContentRendererClient::RenderFrameCreated(
...@@ -91,6 +97,8 @@ void ShellContentRendererClient::RenderFrameCreated( ...@@ -91,6 +97,8 @@ void ShellContentRendererClient::RenderFrameCreated(
void ShellContentRendererClient::RenderViewCreated( void ShellContentRendererClient::RenderViewCreated(
content::RenderView* render_view) { content::RenderView* render_view) {
new extensions::ExtensionHelper(render_view, extension_dispatcher_.get()); new extensions::ExtensionHelper(render_view, extension_dispatcher_.get());
if (delegate_)
delegate_->OnViewCreated(render_view);
} }
bool ShellContentRendererClient::WillSendRequest( bool ShellContentRendererClient::WillSendRequest(
......
...@@ -19,11 +19,13 @@ namespace apps { ...@@ -19,11 +19,13 @@ namespace apps {
class ShellExtensionsClient; class ShellExtensionsClient;
class ShellExtensionsRendererClient; class ShellExtensionsRendererClient;
class ShellRendererMainDelegate;
// Renderer initialization and runtime support for app_shell. // Renderer initialization and runtime support for app_shell.
class ShellContentRendererClient : public content::ContentRendererClient { class ShellContentRendererClient : public content::ContentRendererClient {
public: public:
ShellContentRendererClient(); explicit ShellContentRendererClient(
scoped_ptr<ShellRendererMainDelegate> delegate);
virtual ~ShellContentRendererClient(); virtual ~ShellContentRendererClient();
// content::ContentRendererClient implementation: // content::ContentRendererClient implementation:
...@@ -42,6 +44,7 @@ class ShellContentRendererClient : public content::ContentRendererClient { ...@@ -42,6 +44,7 @@ class ShellContentRendererClient : public content::ContentRendererClient {
virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE; virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE;
private: private:
scoped_ptr<ShellRendererMainDelegate> delegate_;
scoped_ptr<ShellExtensionsClient> extensions_client_; scoped_ptr<ShellExtensionsClient> extensions_client_;
scoped_ptr<ShellExtensionsRendererClient> extensions_renderer_client_; scoped_ptr<ShellExtensionsRendererClient> extensions_renderer_client_;
scoped_ptr<extensions::DispatcherDelegate> extension_dispatcher_delegate_; scoped_ptr<extensions::DispatcherDelegate> extension_dispatcher_delegate_;
......
// 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_
...@@ -20,6 +20,7 @@ specific_include_rules = { ...@@ -20,6 +20,7 @@ specific_include_rules = {
"athena_main\.cc": [ "athena_main\.cc": [
"+apps/shell/app", "+apps/shell/app",
"+apps/shell/browser", "+apps/shell/browser",
"+apps/shell/renderer",
"+content/public/app", "+content/public/app",
], ],
"athena_app_window_controller\.*": [ "athena_app_window_controller\.*": [
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "apps/shell/browser/shell_browser_main_delegate.h" #include "apps/shell/browser/shell_browser_main_delegate.h"
#include "apps/shell/browser/shell_desktop_controller.h" #include "apps/shell/browser/shell_desktop_controller.h"
#include "apps/shell/browser/shell_extension_system.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_activity_factory.h"
#include "athena/content/public/content_app_model_builder.h" #include "athena/content/public/content_app_model_builder.h"
#include "athena/home/public/home_card.h" #include "athena/home/public/home_card.h"
...@@ -63,6 +64,20 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate { ...@@ -63,6 +64,20 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); 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 { class AthenaMainDelegate : public apps::ShellMainDelegate {
public: public:
AthenaMainDelegate() {} AthenaMainDelegate() {}
...@@ -75,6 +90,12 @@ class AthenaMainDelegate : public apps::ShellMainDelegate { ...@@ -75,6 +90,12 @@ class AthenaMainDelegate : public apps::ShellMainDelegate {
return new AthenaBrowserMainDelegate(); return new AthenaBrowserMainDelegate();
} }
virtual scoped_ptr<apps::ShellRendererMainDelegate>
CreateShellRendererMainDelegate() OVERRIDE {
return scoped_ptr<apps::ShellRendererMainDelegate>(
new AthenaRendererMainDelegate());
}
DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate); DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment