Skip to content

Commit

Permalink
app-shell: Introduce a ShellRendererMainDelegate.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sadrul@chromium.org committed Jun 18, 2014
1 parent 75ef0cd commit 618b9f7
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
9 changes: 8 additions & 1 deletion apps/shell/app/shell_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -73,14 +74,20 @@ content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() {

content::ContentRendererClient*
ShellMainDelegate::CreateContentRendererClient() {
renderer_client_.reset(new ShellContentRendererClient);
renderer_client_.reset(
new ShellContentRendererClient(CreateShellRendererMainDelegate()));
return renderer_client_.get();
}

ShellBrowserMainDelegate* ShellMainDelegate::CreateShellBrowserMainDelegate() {
return new DefaultShellBrowserMainDelegate();
}

scoped_ptr<ShellRendererMainDelegate>
ShellMainDelegate::CreateShellRendererMainDelegate() {
return scoped_ptr<ShellRendererMainDelegate>();
}

// static
bool ShellMainDelegate::ProcessNeedsResourceBundle(
const std::string& process_type) {
Expand Down
5 changes: 5 additions & 0 deletions apps/shell/app/shell_main_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ContentRendererClient;

namespace apps {
class ShellBrowserMainDelegate;
class ShellRendererMainDelegate;

class ShellMainDelegate : public content::ContentMainDelegate {
public:
Expand All @@ -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<ShellRendererMainDelegate>
CreateShellRendererMainDelegate();

private:
// |process_type| is zygote, renderer, utility, etc. Returns true if the
// process needs data from resources.pak.
Expand Down
1 change: 1 addition & 0 deletions apps/shell/app_shell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
10 changes: 9 additions & 1 deletion apps/shell/renderer/shell_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,7 +59,10 @@ void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context,

} // namespace

ShellContentRendererClient::ShellContentRendererClient() {}
ShellContentRendererClient::ShellContentRendererClient(
scoped_ptr<ShellRendererMainDelegate> delegate)
: delegate_(delegate.Pass()) {
}

ShellContentRendererClient::~ShellContentRendererClient() {}

Expand All @@ -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(
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion apps/shell/renderer/shell_content_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShellRendererMainDelegate> delegate);
virtual ~ShellContentRendererClient();

// content::ContentRendererClient implementation:
Expand All @@ -42,6 +44,7 @@ class ShellContentRendererClient : public content::ContentRendererClient {
virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE;

private:
scoped_ptr<ShellRendererMainDelegate> delegate_;
scoped_ptr<ShellExtensionsClient> extensions_client_;
scoped_ptr<ShellExtensionsRendererClient> extensions_renderer_client_;
scoped_ptr<extensions::DispatcherDelegate> extension_dispatcher_delegate_;
Expand Down
30 changes: 30 additions & 0 deletions apps/shell/renderer/shell_renderer_main_delegate.h
Original file line number Diff line number Diff line change
@@ -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_
1 change: 1 addition & 0 deletions athena/main/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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\.*": [
Expand Down
21 changes: 21 additions & 0 deletions athena/main/athena_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {}
Expand All @@ -75,6 +90,12 @@ class AthenaMainDelegate : public apps::ShellMainDelegate {
return new AthenaBrowserMainDelegate();
}

virtual scoped_ptr<apps::ShellRendererMainDelegate>
CreateShellRendererMainDelegate() OVERRIDE {
return scoped_ptr<apps::ShellRendererMainDelegate>(
new AthenaRendererMainDelegate());
}

DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate);
};

Expand Down

0 comments on commit 618b9f7

Please sign in to comment.