0

Create default implementations of ContentRendererClient, ContentUtilityClient, and ContentPluginClient to make it easier to embed content.

BUG=98716
Review URL: https://chromiumcodereview.appspot.com/10449063

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139432 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
jam@chromium.org
2012-05-30 00:03:10 +00:00
parent d6e476e77b
commit 22cf00959b
12 changed files with 153 additions and 227 deletions

@ -25,6 +25,7 @@
'..',
],
'sources': [
'public/renderer/content_renderer_client.cc',
'public/renderer/content_renderer_client.h',
'public/renderer/document_state.cc',
'public/renderer/document_state.h',

@ -7,6 +7,7 @@
'../base/base.gyp:base',
],
'sources': [
'public/utility/content_utility_client.cc',
'public/utility/content_utility_client.h',
'public/utility/utility_thread.cc',
'public/utility/utility_thread.h',

@ -12,10 +12,10 @@
namespace content {
// Embedder API for participating in plugin logic.
class ContentPluginClient {
class CONTENT_EXPORT ContentPluginClient {
public:
// Notifies that a plugin process has started.
virtual void PluginProcessStarted(const string16& plugin_name) = 0;
virtual void PluginProcessStarted(const string16& plugin_name) {}
};
} // namespace content

@ -0,0 +1,106 @@
// Copyright (c) 2012 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/public/renderer/content_renderer_client.h"
namespace content {
SkBitmap* ContentRendererClient::GetSadPluginBitmap() {
return NULL;
}
std::string ContentRendererClient::GetDefaultEncoding() {
return std::string();
}
bool ContentRendererClient::OverrideCreatePlugin(
RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) {
return false;
}
WebKit::WebPlugin* ContentRendererClient::CreatePluginReplacement(
RenderView* render_view,
const FilePath& plugin_path) {
return NULL;
}
bool ContentRendererClient::HasErrorPage(int http_status_code,
std::string* error_domain) {
return false;
}
webkit_media::WebMediaPlayerImpl*
ContentRendererClient::OverrideCreateWebMediaPlayer(
RenderView* render_view,
WebKit::WebFrame* frame,
WebKit::WebMediaPlayerClient* client,
base::WeakPtr<webkit_media::WebMediaPlayerDelegate> delegate,
media::FilterCollection* collection,
WebKit::WebAudioSourceProvider* audio_source_provider,
media::MessageLoopFactory* message_loop_factory,
webkit_media::MediaStreamClient* media_stream_client,
media::MediaLog* media_log) {
return NULL;
}
bool ContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
return true;
}
bool ContentRendererClient::AllowPopup(const GURL& creator) {
return false;
}
bool ContentRendererClient::ShouldFork(WebKit::WebFrame* frame,
const GURL& url,
bool is_initial_navigation,
bool* send_referrer) {
return false;
}
bool ContentRendererClient::WillSendRequest(WebKit::WebFrame* frame,
const GURL& url,
GURL* new_url) {
return false;
}
bool ContentRendererClient::ShouldPumpEventsDuringCookieMessage() {
return false;
}
unsigned long long ContentRendererClient::VisitedLinkHash(
const char* canonical_url, size_t length) {
return 0LL;
}
bool ContentRendererClient::IsLinkVisited(unsigned long long link_hash) {
return false;
}
bool ContentRendererClient::ShouldOverridePageVisibilityState(
const RenderView* render_view,
WebKit::WebPageVisibilityState* override_state) const {
return false;
}
bool ContentRendererClient::HandleGetCookieRequest(
RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
std::string* cookies) {
return false;
}
bool ContentRendererClient::HandleSetCookieRequest(
RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
const std::string& value) {
return false;
}
} // namespace content

@ -13,6 +13,7 @@
#include "ipc/ipc_message.h"
#include "content/public/common/content_client.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageVisibilityState.h"
#include "v8/include/v8.h"
class FilePath;
class GURL;
@ -47,34 +48,29 @@ class WebMediaPlayerDelegate;
class WebMediaPlayerImpl;
}
namespace v8 {
class Context;
template<class T> class Handle;
}
namespace content {
class RenderView;
// Embedder API for participating in renderer logic.
class ContentRendererClient {
class CONTENT_EXPORT ContentRendererClient {
public:
virtual ~ContentRendererClient() {}
// Notifies us that the RenderThread has been created.
virtual void RenderThreadStarted() = 0;
virtual void RenderThreadStarted() {}
// Notifies that a new RenderView has been created.
virtual void RenderViewCreated(RenderView* render_view) = 0;
virtual void RenderViewCreated(RenderView* render_view) {}
// Sets a number of views/tabs opened in this process.
virtual void SetNumberOfViews(int number_of_views) = 0;
virtual void SetNumberOfViews(int number_of_views) {}
// Returns the bitmap to show when a plugin crashed, or NULL for none.
virtual SkBitmap* GetSadPluginBitmap() = 0;
virtual SkBitmap* GetSadPluginBitmap();
// Returns the default text encoding.
virtual std::string GetDefaultEncoding() = 0;
virtual std::string GetDefaultEncoding();
// Allows the embedder to override creating a plugin. If it returns true, then
// |plugin| will contain the created plugin, although it could be NULL. If it
@ -83,20 +79,20 @@ class ContentRendererClient {
RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) = 0;
WebKit::WebPlugin** plugin);
// Creates a replacement plug-in that is shown when the plug-in at |file_path|
// couldn't be loaded. This allows the embedder to show a custom placeholder.
virtual WebKit::WebPlugin* CreatePluginReplacement(
RenderView* render_view,
const FilePath& plugin_path) = 0;
const FilePath& plugin_path);
// Returns true if the embedder has an error page to show for the given http
// status code. If so |error_domain| should be set to according to WebURLError
// and the embedder's GetNavigationErrorHtml will be called afterwards to get
// the error html.
virtual bool HasErrorPage(int http_status_code,
std::string* error_domain) = 0;
std::string* error_domain);
// Returns the information to display when a navigation error occurs.
// If |error_html| is not null then it may be set to a HTML page containing
@ -110,7 +106,7 @@ class ContentRendererClient {
const WebKit::WebURLRequest& failed_request,
const WebKit::WebURLError& error,
std::string* error_html,
string16* error_description) = 0;
string16* error_description) {}
// Allows embedder to override creating a WebMediaPlayerImpl. If it returns
// NULL the content layer will create the media player.
@ -123,65 +119,65 @@ class ContentRendererClient {
WebKit::WebAudioSourceProvider* audio_source_provider,
media::MessageLoopFactory* message_loop_factory,
webkit_media::MediaStreamClient* media_stream_client,
media::MediaLog* media_log) = 0;
media::MediaLog* media_log);
// Returns true if the renderer process should schedule the idle handler when
// all widgets are hidden.
virtual bool RunIdleHandlerWhenWidgetsHidden() = 0;
virtual bool RunIdleHandlerWhenWidgetsHidden();
// Returns true if the given url can create popup windows.
virtual bool AllowPopup(const GURL& creator) = 0;
virtual bool AllowPopup(const GURL& creator);
// Returns true if we should fork a new process for the given navigation.
virtual bool ShouldFork(WebKit::WebFrame* frame,
const GURL& url,
bool is_initial_navigation,
bool* send_referrer) = 0;
bool* send_referrer);
// Notifies the embedder that the given frame is requesting the resource at
// |url|. If the function returns true, the url is changed to |new_url|.
virtual bool WillSendRequest(WebKit::WebFrame* frame,
const GURL& url,
GURL* new_url) = 0;
GURL* new_url);
// Whether to pump events when sending sync cookie messages. Needed if the
// embedder can potentiall put up a modal dialog on the UI thread as a result.
virtual bool ShouldPumpEventsDuringCookieMessage() = 0;
virtual bool ShouldPumpEventsDuringCookieMessage();
// See the corresponding functions in WebKit::WebFrameClient.
virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,
int world_id) = 0;
int world_id) {}
virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
v8::Handle<v8::Context>,
int world_id) = 0;
int world_id) {}
// See WebKit::WebKitPlatformSupport.
virtual unsigned long long VisitedLinkHash(const char* canonical_url,
size_t length) = 0;
virtual bool IsLinkVisited(unsigned long long link_hash) = 0;
virtual void PrefetchHostName(const char* hostname, size_t length) = 0;
size_t length);
virtual bool IsLinkVisited(unsigned long long link_hash);
virtual void PrefetchHostName(const char* hostname, size_t length) {}
virtual bool ShouldOverridePageVisibilityState(
const RenderView* render_view,
WebKit::WebPageVisibilityState* override_state) const = 0;
WebKit::WebPageVisibilityState* override_state) const;
// Return true if the GetCookie request will be handled by the embedder.
// Cookies are returned in the cookie parameter.
virtual bool HandleGetCookieRequest(RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
std::string* cookies) = 0;
std::string* cookies);
// Return true if the SetCookie request will be handled by the embedder.
// Cookies to be set are passed in the value parameter.
virtual bool HandleSetCookieRequest(RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
const std::string& value) = 0;
const std::string& value);
virtual void RegisterPPAPIInterfaceFactories(
webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) = 0;
webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) {}
};
} // namespace content

@ -0,0 +1,13 @@
// Copyright (c) 2011 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/public/utility/content_utility_client.h"
namespace content {
bool ContentUtilityClient::OnMessageReceived(const IPC::Message& message) {
return false;
}
} // namespace content

@ -11,13 +11,13 @@
namespace content {
// Embedder API for participating in renderer logic.
class ContentUtilityClient {
class CONTENT_EXPORT ContentUtilityClient {
public:
// Notifies us that the UtilityThread has been created.
virtual void UtilityThreadStarted() = 0;
virtual void UtilityThreadStarted() {}
// Allows the embedder to filter messages.
virtual bool OnMessageReceived(const IPC::Message& message) = 0;
virtual bool OnMessageReceived(const IPC::Message& message);
};
} // namespace content

@ -16,7 +16,7 @@
namespace content {
class CONTENT_EXPORT UtilityThread : public IPC::Message::Sender {
class CONTENT_EXPORT UtilityThread : public IPC::Message::Sender {
public:
// Returns the one utility thread for this process. Note that this can only
// be accessed when running on the utility thread itself.

@ -9,8 +9,4 @@ namespace content {
ShellContentPluginClient::~ShellContentPluginClient() {
}
void ShellContentPluginClient::PluginProcessStarted(
const string16& plugin_name) {
}
} // namespace content

@ -14,7 +14,6 @@ namespace content {
class ShellContentPluginClient : public ContentPluginClient {
public:
virtual ~ShellContentPluginClient();
virtual void PluginProcessStarted(const string16& plugin_name) OVERRIDE;
};
} // namespace content

@ -24,128 +24,4 @@ void ShellContentRendererClient::RenderViewCreated(RenderView* render_view) {
new content::ShellRenderViewObserver(render_view);
}
void ShellContentRendererClient::SetNumberOfViews(int number_of_views) {
}
SkBitmap* ShellContentRendererClient::GetSadPluginBitmap() {
return NULL;
}
std::string ShellContentRendererClient::GetDefaultEncoding() {
return std::string();
}
bool ShellContentRendererClient::OverrideCreatePlugin(
RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) {
return false;
}
WebKit::WebPlugin* ShellContentRendererClient::CreatePluginReplacement(
RenderView* render_view,
const FilePath& plugin_path) {
return NULL;
}
bool ShellContentRendererClient::HasErrorPage(int http_status_code,
std::string* error_domain) {
return false;
}
void ShellContentRendererClient::GetNavigationErrorStrings(
const WebKit::WebURLRequest& failed_request,
const WebKit::WebURLError& error,
std::string* error_html,
string16* error_description) {
}
webkit_media::WebMediaPlayerImpl*
ShellContentRendererClient::OverrideCreateWebMediaPlayer(
RenderView* render_view,
WebKit::WebFrame* frame,
WebKit::WebMediaPlayerClient* client,
base::WeakPtr<webkit_media::WebMediaPlayerDelegate> delegate,
media::FilterCollection* collection,
WebKit::WebAudioSourceProvider* audio_source_provider,
media::MessageLoopFactory* message_loop_factory,
webkit_media::MediaStreamClient* media_stream_client,
media::MediaLog* media_log) {
return NULL;
}
bool ShellContentRendererClient::RunIdleHandlerWhenWidgetsHidden() {
return true;
}
bool ShellContentRendererClient::AllowPopup(const GURL& creator) {
return false;
}
bool ShellContentRendererClient::ShouldFork(WebKit::WebFrame* frame,
const GURL& url,
bool is_initial_navigation,
bool* send_referrer) {
return false;
}
bool ShellContentRendererClient::WillSendRequest(WebKit::WebFrame* frame,
const GURL& url,
GURL* new_url) {
return false;
}
bool ShellContentRendererClient::ShouldPumpEventsDuringCookieMessage() {
return false;
}
void ShellContentRendererClient::DidCreateScriptContext(
WebKit::WebFrame* frame, v8::Handle<v8::Context> context,
int extension_group, int world_id) {
}
void ShellContentRendererClient::WillReleaseScriptContext(
WebKit::WebFrame* frame, v8::Handle<v8::Context> context, int world_id) {
}
unsigned long long ShellContentRendererClient::VisitedLinkHash(
const char* canonical_url, size_t length) {
return 0LL;
}
bool ShellContentRendererClient::IsLinkVisited(unsigned long long link_hash) {
return false;
}
void ShellContentRendererClient::PrefetchHostName(
const char* hostname, size_t length) {
}
bool ShellContentRendererClient::ShouldOverridePageVisibilityState(
const RenderView* render_view,
WebKit::WebPageVisibilityState* override_state) const {
return false;
}
bool ShellContentRendererClient::HandleGetCookieRequest(
RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
std::string* cookies) {
return false;
}
bool ShellContentRendererClient::HandleSetCookieRequest(
RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
const std::string& value) {
return false;
}
void ShellContentRendererClient::RegisterPPAPIInterfaceFactories(
webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) {
}
} // namespace content

@ -20,68 +20,6 @@ class ShellContentRendererClient : public ContentRendererClient {
virtual ~ShellContentRendererClient();
virtual void RenderThreadStarted() OVERRIDE;
virtual void RenderViewCreated(RenderView* render_view) OVERRIDE;
virtual void SetNumberOfViews(int number_of_views) OVERRIDE;
virtual SkBitmap* GetSadPluginBitmap() OVERRIDE;
virtual std::string GetDefaultEncoding() OVERRIDE;
virtual bool OverrideCreatePlugin(
RenderView* render_view,
WebKit::WebFrame* frame,
const WebKit::WebPluginParams& params,
WebKit::WebPlugin** plugin) OVERRIDE;
virtual WebKit::WebPlugin* CreatePluginReplacement(
RenderView* render_view,
const FilePath& plugin_path) OVERRIDE;
virtual bool HasErrorPage(int http_status_code,
std::string* error_domain) OVERRIDE;
virtual void GetNavigationErrorStrings(
const WebKit::WebURLRequest& failed_request,
const WebKit::WebURLError& error,
std::string* error_html,
string16* error_description) OVERRIDE;
virtual webkit_media::WebMediaPlayerImpl* OverrideCreateWebMediaPlayer(
RenderView* render_view,
WebKit::WebFrame* frame,
WebKit::WebMediaPlayerClient* client,
base::WeakPtr<webkit_media::WebMediaPlayerDelegate> delegate,
media::FilterCollection* collection,
WebKit::WebAudioSourceProvider* audio_source_provider,
media::MessageLoopFactory* message_loop_factory,
webkit_media::MediaStreamClient* media_stream_client,
media::MediaLog* media_log) OVERRIDE;
virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE;
virtual bool AllowPopup(const GURL& creator) OVERRIDE;
virtual bool ShouldFork(WebKit::WebFrame* frame,
const GURL& url,
bool is_initial_navigation,
bool* send_referrer) OVERRIDE;
virtual bool WillSendRequest(WebKit::WebFrame* frame,
const GURL& url,
GURL* new_url) OVERRIDE;
virtual bool ShouldPumpEventsDuringCookieMessage() OVERRIDE;
virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,
int world_id) OVERRIDE;
virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
v8::Handle<v8::Context> context,
int world_id) OVERRIDE;
virtual unsigned long long VisitedLinkHash(const char* canonical_url,
size_t length) OVERRIDE;
virtual bool IsLinkVisited(unsigned long long link_hash) OVERRIDE;
virtual void PrefetchHostName(const char* hostname, size_t length) OVERRIDE;
virtual bool ShouldOverridePageVisibilityState(
const RenderView* render_view,
WebKit::WebPageVisibilityState* override_state) const OVERRIDE;
virtual bool HandleGetCookieRequest(RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
std::string* cookies) OVERRIDE;
virtual bool HandleSetCookieRequest(RenderView* sender,
const GURL& url,
const GURL& first_party_for_cookies,
const std::string& value) OVERRIDE;
virtual void RegisterPPAPIInterfaceFactories(
webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) OVERRIDE;
private:
scoped_ptr<ShellRenderProcessObserver> shell_observer_;