Fix sort order of unlaunched apps on app list start page.
[chromium-blink-merge.git] / extensions / shell / renderer / shell_content_renderer_client.cc
blob47e3ad4696f3f5f3587c4384ba3d7529b1bce686
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/default_dispatcher_delegate.h"
14 #include "extensions/renderer/dispatcher.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/guest_view_container.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"
29 #endif
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 DefaultDispatcherDelegate());
54 // Must be initialized after ExtensionsRendererClient.
55 extension_dispatcher_.reset(
56 new Dispatcher(extension_dispatcher_delegate_.get()));
57 thread->AddObserver(extension_dispatcher_.get());
59 // TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes.
60 // See ChromeContentRendererClient for details.
63 void ShellContentRendererClient::RenderFrameCreated(
64 content::RenderFrame* render_frame) {
65 // ExtensionFrameHelper destroys itself when the RenderFrame is destroyed.
66 new ExtensionFrameHelper(render_frame, extension_dispatcher_.get());
68 // TODO(jamescook): Do we need to add a new PepperHelper(render_frame) here?
69 // It doesn't seem necessary for either Pepper or NaCl.
70 // http://crbug.com/403004
71 #if !defined(DISABLE_NACL)
72 new nacl::NaClHelper(render_frame);
73 #endif
76 void ShellContentRendererClient::RenderViewCreated(
77 content::RenderView* render_view) {
78 new ExtensionHelper(render_view, extension_dispatcher_.get());
79 extension_dispatcher_->OnRenderViewCreated(render_view);
82 bool ShellContentRendererClient::OverrideCreatePlugin(
83 content::RenderFrame* render_frame,
84 blink::WebLocalFrame* frame,
85 const blink::WebPluginParams& params,
86 blink::WebPlugin** plugin) {
87 // Allow the content module to create the plugin.
88 return false;
91 blink::WebPlugin* ShellContentRendererClient::CreatePluginReplacement(
92 content::RenderFrame* render_frame,
93 const base::FilePath& plugin_path) {
94 // Don't provide a custom "failed to load" plugin.
95 return NULL;
98 bool ShellContentRendererClient::ShouldForwardToGuestContainer(
99 const IPC::Message& msg) {
100 return GuestViewContainer::HandlesMessage(msg);
103 bool ShellContentRendererClient::WillSendRequest(
104 blink::WebFrame* frame,
105 ui::PageTransition transition_type,
106 const GURL& url,
107 const GURL& first_party_for_cookies,
108 GURL* new_url) {
109 // TODO(jamescook): Cause an error for bad extension scheme requests?
110 return false;
113 void ShellContentRendererClient::DidCreateScriptContext(
114 WebFrame* frame,
115 v8::Handle<v8::Context> context,
116 int extension_group,
117 int world_id) {
118 extension_dispatcher_->DidCreateScriptContext(
119 frame, context, extension_group, world_id);
122 const void* ShellContentRendererClient::CreatePPAPIInterface(
123 const std::string& interface_name) {
124 #if !defined(DISABLE_NACL)
125 if (interface_name == PPB_NACL_PRIVATE_INTERFACE)
126 return nacl::GetNaClPrivateInterface();
127 #endif
128 return NULL;
131 bool ShellContentRendererClient::IsExternalPepperPlugin(
132 const std::string& module_name) {
133 #if !defined(DISABLE_NACL)
134 // TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
135 // We must defer certain plugin events for NaCl instances since we switch
136 // from the in-process to the out-of-process proxy after instantiating them.
137 return module_name == nacl::kNaClPluginName;
138 #else
139 return false;
140 #endif
143 bool ShellContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
144 // Extension renderers don't need site isolation.
145 return false;
148 content::BrowserPluginDelegate*
149 ShellContentRendererClient::CreateBrowserPluginDelegate(
150 content::RenderFrame* render_frame,
151 const std::string& mime_type,
152 const GURL& original_url) {
153 if (mime_type == content::kBrowserPluginMimeType) {
154 return new extensions::ExtensionsGuestViewContainer(render_frame);
155 } else {
156 return new extensions::MimeHandlerViewContainer(
157 render_frame, mime_type, original_url);
161 ExtensionsClient* ShellContentRendererClient::CreateExtensionsClient() {
162 return new ShellExtensionsClient;
165 } // namespace extensions