1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
// 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.
#include "extensions/shell/renderer/shell_content_renderer_client.h"
#include "content/public/common/content_constants.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"
#include "content/public/renderer/render_thread.h"
#include "extensions/common/extensions_client.h"
#include "extensions/renderer/default_dispatcher_delegate.h"
#include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/extension_helper.h"
#include "extensions/renderer/guest_view/extensions_guest_view_container.h"
#include "extensions/renderer/guest_view/mime_handler_view_container.h"
#include "extensions/shell/common/shell_extensions_client.h"
#include "extensions/shell/renderer/shell_extensions_renderer_client.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#if !defined(DISABLE_NACL)
#include "components/nacl/common/nacl_constants.h"
#include "components/nacl/renderer/nacl_helper.h"
#include "components/nacl/renderer/ppb_nacl_private_impl.h"
#include "ppapi/c/private/ppb_nacl_private.h"
#endif
using blink::WebFrame;
using blink::WebString;
using content::RenderThread;
namespace extensions {
namespace {
// TODO: promote ExtensionFrameHelper to a common place and share with this.
class ShellFrameHelper
: public content::RenderFrameObserver,
public content::RenderFrameObserverTracker<ShellFrameHelper> {
public:
ShellFrameHelper(content::RenderFrame* render_frame,
Dispatcher* extension_dispatcher);
~ShellFrameHelper() override;
// RenderFrameObserver implementation.
void WillReleaseScriptContext(v8::Handle<v8::Context>, int world_id) override;
private:
Dispatcher* extension_dispatcher_;
DISALLOW_COPY_AND_ASSIGN(ShellFrameHelper);
};
ShellFrameHelper::ShellFrameHelper(content::RenderFrame* render_frame,
Dispatcher* extension_dispatcher)
: content::RenderFrameObserver(render_frame),
content::RenderFrameObserverTracker<ShellFrameHelper>(render_frame),
extension_dispatcher_(extension_dispatcher) {
}
ShellFrameHelper::~ShellFrameHelper() {
}
void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context,
int world_id) {
extension_dispatcher_->WillReleaseScriptContext(
render_frame()->GetWebFrame(), context, world_id);
}
} // namespace
ShellContentRendererClient::ShellContentRendererClient() {
}
ShellContentRendererClient::~ShellContentRendererClient() {
}
void ShellContentRendererClient::RenderThreadStarted() {
RenderThread* thread = RenderThread::Get();
extensions_client_.reset(new ShellExtensionsClient);
ExtensionsClient::Set(extensions_client_.get());
extensions_renderer_client_.reset(new ShellExtensionsRendererClient);
ExtensionsRendererClient::Set(extensions_renderer_client_.get());
extension_dispatcher_delegate_.reset(new DefaultDispatcherDelegate());
// Must be initialized after ExtensionsRendererClient.
extension_dispatcher_.reset(
new Dispatcher(extension_dispatcher_delegate_.get()));
thread->AddObserver(extension_dispatcher_.get());
// TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes.
// See ChromeContentRendererClient for details.
}
void ShellContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
// ShellFrameHelper destroys itself when the RenderFrame is destroyed.
new ShellFrameHelper(render_frame, extension_dispatcher_.get());
// TODO(jamescook): Do we need to add a new PepperHelper(render_frame) here?
// It doesn't seem necessary for either Pepper or NaCl.
// http://crbug.com/403004
#if !defined(DISABLE_NACL)
new nacl::NaClHelper(render_frame);
#endif
}
void ShellContentRendererClient::RenderViewCreated(
content::RenderView* render_view) {
new ExtensionHelper(render_view, extension_dispatcher_.get());
extension_dispatcher_->OnRenderViewCreated(render_view);
}
bool ShellContentRendererClient::OverrideCreatePlugin(
content::RenderFrame* render_frame,
blink::WebLocalFrame* frame,
const blink::WebPluginParams& params,
blink::WebPlugin** plugin) {
// Allow the content module to create the plugin.
return false;
}
blink::WebPlugin* ShellContentRendererClient::CreatePluginReplacement(
content::RenderFrame* render_frame,
const base::FilePath& plugin_path) {
// Don't provide a custom "failed to load" plugin.
return NULL;
}
bool ShellContentRendererClient::WillSendRequest(
blink::WebFrame* frame,
ui::PageTransition transition_type,
const GURL& url,
const GURL& first_party_for_cookies,
GURL* new_url) {
// TODO(jamescook): Cause an error for bad extension scheme requests?
return false;
}
void ShellContentRendererClient::DidCreateScriptContext(
WebFrame* frame,
v8::Handle<v8::Context> context,
int extension_group,
int world_id) {
extension_dispatcher_->DidCreateScriptContext(
frame, context, extension_group, world_id);
}
const void* ShellContentRendererClient::CreatePPAPIInterface(
const std::string& interface_name) {
#if !defined(DISABLE_NACL)
if (interface_name == PPB_NACL_PRIVATE_INTERFACE)
return nacl::GetNaClPrivateInterface();
#endif
return NULL;
}
bool ShellContentRendererClient::IsExternalPepperPlugin(
const std::string& module_name) {
#if !defined(DISABLE_NACL)
// TODO(bbudge) remove this when the trusted NaCl plugin has been removed.
// We must defer certain plugin events for NaCl instances since we switch
// from the in-process to the out-of-process proxy after instantiating them.
return module_name == nacl::kNaClPluginName;
#else
return false;
#endif
}
bool ShellContentRendererClient::ShouldEnableSiteIsolationPolicy() const {
// Extension renderers don't need site isolation.
return false;
}
content::BrowserPluginDelegate*
ShellContentRendererClient::CreateBrowserPluginDelegate(
content::RenderFrame* render_frame,
const std::string& mime_type,
const GURL& original_url) {
if (mime_type == content::kBrowserPluginMimeType) {
return new extensions::ExtensionsGuestViewContainer(render_frame);
} else {
return new extensions::MimeHandlerViewContainer(
render_frame, mime_type, original_url);
}
}
} // namespace extensions
|