1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/shell/renderer/shell_content_renderer_client.h"
7 #include "content/public/common/content_constants.h"
8 #include "content/public/renderer/render_frame.h"
9 #include "content/public/renderer/render_frame_observer.h"
10 #include "content/public/renderer/render_frame_observer_tracker.h"
11 #include "content/public/renderer/render_thread.h"
12 #include "extensions/common/extensions_client.h"
13 #include "extensions/renderer/dispatcher.h"
14 #include "extensions/renderer/dispatcher_delegate.h"
15 #include "extensions/renderer/extension_frame_helper.h"
16 #include "extensions/renderer/extension_helper.h"
17 #include "extensions/renderer/guest_view/extensions_guest_view_container.h"
18 #include "extensions/renderer/guest_view/extensions_guest_view_container_dispatcher.h"
19 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h"
20 #include "extensions/shell/common/shell_extensions_client.h"
21 #include "extensions/shell/renderer/shell_extensions_renderer_client.h"
22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
24 #if !defined(DISABLE_NACL)
25 #include "components/nacl/common/nacl_constants.h"
26 #include "components/nacl/renderer/nacl_helper.h"
27 #include "components/nacl/renderer/ppb_nacl_private.h"
28 #include "components/nacl/renderer/ppb_nacl_private_impl.h"
31 using blink::WebFrame
;
32 using blink::WebString
;
33 using content::RenderThread
;
35 namespace extensions
{
37 ShellContentRendererClient::ShellContentRendererClient() {
40 ShellContentRendererClient::~ShellContentRendererClient() {
43 void ShellContentRendererClient::RenderThreadStarted() {
44 RenderThread
* thread
= RenderThread::Get();
46 extensions_client_
.reset(CreateExtensionsClient());
47 ExtensionsClient::Set(extensions_client_
.get());
49 extensions_renderer_client_
.reset(new ShellExtensionsRendererClient
);
50 ExtensionsRendererClient::Set(extensions_renderer_client_
.get());
52 extension_dispatcher_delegate_
.reset(new DispatcherDelegate());
54 // Must be initialized after ExtensionsRendererClient.
55 extension_dispatcher_
.reset(
56 new Dispatcher(extension_dispatcher_delegate_
.get()));
57 thread
->AddObserver(extension_dispatcher_
.get());
59 guest_view_container_dispatcher_
.reset(
60 new ExtensionsGuestViewContainerDispatcher());
61 thread
->AddObserver(guest_view_container_dispatcher_
.get());
64 void ShellContentRendererClient::RenderFrameCreated(
65 content::RenderFrame
* render_frame
) {
66 // ExtensionFrameHelper destroys itself when the RenderFrame is destroyed.
67 new ExtensionFrameHelper(render_frame
, extension_dispatcher_
.get());
68 extension_dispatcher_
->OnRenderFrameCreated(render_frame
);
70 // TODO(jamescook): Do we need to add a new PepperHelper(render_frame) here?
71 // It doesn't seem necessary for either Pepper or NaCl.
72 // http://crbug.com/403004
73 #if !defined(DISABLE_NACL)
74 new nacl::NaClHelper(render_frame
);
78 void ShellContentRendererClient::RenderViewCreated(
79 content::RenderView
* render_view
) {
80 new ExtensionHelper(render_view
, extension_dispatcher_
.get());
83 bool ShellContentRendererClient::OverrideCreatePlugin(
84 content::RenderFrame
* render_frame
,
85 blink::WebLocalFrame
* frame
,
86 const blink::WebPluginParams
& params
,
87 blink::WebPlugin
** plugin
) {
88 // Allow the content module to create the plugin.
92 blink::WebPlugin
* ShellContentRendererClient::CreatePluginReplacement(
93 content::RenderFrame
* render_frame
,
94 const base::FilePath
& plugin_path
) {
95 // Don't provide a custom "failed to load" plugin.
99 bool ShellContentRendererClient::WillSendRequest(
100 blink::WebFrame
* frame
,
101 ui::PageTransition transition_type
,
103 const GURL
& first_party_for_cookies
,
105 // TODO(jamescook): Cause an error for bad extension scheme requests?
109 const void* ShellContentRendererClient::CreatePPAPIInterface(
110 const std::string
& interface_name
) {
111 #if !defined(DISABLE_NACL)
112 if (interface_name
== PPB_NACL_PRIVATE_INTERFACE
)
113 return nacl::GetNaClPrivateInterface();
118 bool ShellContentRendererClient::IsExternalPepperPlugin(
119 const std::string
& module_name
) {
120 #if !defined(DISABLE_NACL)
121 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
122 // We must defer certain plugin events for NaCl instances since we switch
123 // from the in-process to the out-of-process proxy after instantiating them.
124 return module_name
== nacl::kNaClPluginName
;
130 bool ShellContentRendererClient::ShouldGatherSiteIsolationStats() const {
134 content::BrowserPluginDelegate
*
135 ShellContentRendererClient::CreateBrowserPluginDelegate(
136 content::RenderFrame
* render_frame
,
137 const std::string
& mime_type
,
138 const GURL
& original_url
) {
139 if (mime_type
== content::kBrowserPluginMimeType
) {
140 return new extensions::ExtensionsGuestViewContainer(render_frame
);
142 return new extensions::MimeHandlerViewContainer(
143 render_frame
, mime_type
, original_url
);
147 ExtensionsClient
* ShellContentRendererClient::CreateExtensionsClient() {
148 return new ShellExtensionsClient
;
151 } // namespace extensions