Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / renderer / chrome_content_renderer_client.h
blobdc346c57cb3bf59a2b1323a9dcadf3e56e86171f
1 // Copyright (c) 2012 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 #ifndef CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
6 #define CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "content/public/renderer/content_renderer_client.h"
17 #include "ipc/ipc_channel_proxy.h"
18 #include "v8/include/v8.h"
20 class ChromeExtensionsDispatcherDelegate;
21 class ChromeRenderProcessObserver;
22 #if defined(ENABLE_PRINT_PREVIEW)
23 class ChromePDFPrintClient;
24 #endif
25 class PrescientNetworkingDispatcher;
26 #if defined(ENABLE_SPELLCHECK)
27 class SpellCheck;
28 class SpellCheckProvider;
29 #endif
31 struct ChromeViewHostMsg_GetPluginInfo_Output;
33 namespace content {
34 class BrowserPluginDelegate;
35 struct WebPluginInfo;
38 namespace network_hints {
39 class PrescientNetworkingDispatcher;
42 namespace extensions {
43 class Dispatcher;
44 class Extension;
45 class ExtensionSet;
46 class ExtensionsGuestViewContainerDispatcher;
47 class RendererPermissionsPolicyDelegate;
48 class ResourceRequestPolicy;
51 namespace prerender {
52 class PrerenderDispatcher;
55 namespace safe_browsing {
56 class PhishingClassifierFilter;
59 namespace visitedlink {
60 class VisitedLinkSlave;
63 namespace web_cache {
64 class WebCacheRenderProcessObserver;
67 namespace blink {
68 class WebSecurityOrigin;
71 namespace password_manager {
72 class CredentialManagerClient;
75 #if defined(ENABLE_WEBRTC)
76 class WebRtcLoggingMessageFilter;
77 #endif
79 class ChromeContentRendererClient : public content::ContentRendererClient {
80 public:
81 ChromeContentRendererClient();
82 ~ChromeContentRendererClient() override;
84 void RenderThreadStarted() override;
85 void RenderFrameCreated(content::RenderFrame* render_frame) override;
86 void RenderViewCreated(content::RenderView* render_view) override;
87 SkBitmap* GetSadPluginBitmap() override;
88 SkBitmap* GetSadWebViewBitmap() override;
89 bool OverrideCreatePlugin(content::RenderFrame* render_frame,
90 blink::WebLocalFrame* frame,
91 const blink::WebPluginParams& params,
92 blink::WebPlugin** plugin) override;
93 blink::WebPlugin* CreatePluginReplacement(
94 content::RenderFrame* render_frame,
95 const base::FilePath& plugin_path) override;
96 bool HasErrorPage(int http_status_code, std::string* error_domain) override;
97 bool ShouldSuppressErrorPage(content::RenderFrame* render_frame,
98 const GURL& url) override;
99 void GetNavigationErrorStrings(content::RenderView* render_view,
100 blink::WebFrame* frame,
101 const blink::WebURLRequest& failed_request,
102 const blink::WebURLError& error,
103 std::string* error_html,
104 base::string16* error_description) override;
105 void DeferMediaLoad(content::RenderFrame* render_frame,
106 bool has_played_media_before,
107 const base::Closure& closure) override;
108 bool RunIdleHandlerWhenWidgetsHidden() override;
109 bool AllowTimerSuspensionWhenProcessBackgrounded() override;
110 bool AllowPopup() override;
111 bool ShouldFork(blink::WebLocalFrame* frame,
112 const GURL& url,
113 const std::string& http_method,
114 bool is_initial_navigation,
115 bool is_server_redirect,
116 bool* send_referrer) override;
117 bool WillSendRequest(blink::WebFrame* frame,
118 ui::PageTransition transition_type,
119 const GURL& url,
120 const GURL& first_party_for_cookies,
121 GURL* new_url) override;
122 unsigned long long VisitedLinkHash(const char* canonical_url,
123 size_t length) override;
124 bool IsLinkVisited(unsigned long long link_hash) override;
125 blink::WebPrescientNetworking* GetPrescientNetworking() override;
126 bool ShouldOverridePageVisibilityState(
127 const content::RenderFrame* render_frame,
128 blink::WebPageVisibilityState* override_state) override;
129 const void* CreatePPAPIInterface(const std::string& interface_name) override;
130 bool IsExternalPepperPlugin(const std::string& module_name) override;
131 blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
132 blink::WebSpeechSynthesizerClient* client) override;
133 bool ShouldReportDetailedMessageForSource(
134 const base::string16& source) const override;
135 bool ShouldGatherSiteIsolationStats() const override;
136 blink::WebWorkerContentSettingsClientProxy*
137 CreateWorkerContentSettingsClientProxy(content::RenderFrame* render_frame,
138 blink::WebFrame* frame) override;
139 bool AllowPepperMediaStreamAPI(const GURL& url) override;
140 void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
141 bool IsPluginAllowedToUseDevChannelAPIs() override;
142 bool IsPluginAllowedToUseCameraDeviceAPI(const GURL& url) override;
143 bool IsPluginAllowedToUseCompositorAPI(const GURL& url) override;
144 content::BrowserPluginDelegate* CreateBrowserPluginDelegate(
145 content::RenderFrame* render_frame,
146 const std::string& mime_type,
147 const GURL& original_url) override;
148 void RecordRappor(const std::string& metric,
149 const std::string& sample) override;
150 void RecordRapporURL(const std::string& metric, const GURL& url) override;
151 scoped_ptr<blink::WebAppBannerClient> CreateAppBannerClient(
152 content::RenderFrame* render_frame) override;
153 void AddImageContextMenuProperties(
154 const blink::WebURLResponse& response,
155 std::map<std::string, std::string>* properties) override;
156 void DidInitializeServiceWorkerContextOnWorkerThread(
157 v8::Local<v8::Context> context,
158 const GURL& url) override;
159 void WillDestroyServiceWorkerContextOnWorkerThread(const GURL& url) override;
160 #if defined(ENABLE_EXTENSIONS)
161 // Takes ownership.
162 void SetExtensionDispatcherForTest(
163 extensions::Dispatcher* extension_dispatcher);
164 extensions::Dispatcher* GetExtensionDispatcherForTest();
165 #endif
167 #if defined(ENABLE_SPELLCHECK)
168 // Sets a new |spellcheck|. Used for testing only.
169 // Takes ownership of |spellcheck|.
170 void SetSpellcheck(SpellCheck* spellcheck);
171 #endif
173 #if defined(ENABLE_PLUGINS)
174 static blink::WebPlugin* CreatePlugin(
175 content::RenderFrame* render_frame,
176 blink::WebLocalFrame* frame,
177 const blink::WebPluginParams& params,
178 const ChromeViewHostMsg_GetPluginInfo_Output& output);
179 #endif
181 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
182 static bool IsExtensionOrSharedModuleWhitelisted(
183 const GURL& url, const std::set<std::string>& whitelist);
184 #endif
186 static bool WasWebRequestUsedBySomeExtensions();
188 private:
189 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction);
190 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest,
191 ShouldSuppressErrorPage);
193 #if defined(ENABLE_EXTENSIONS)
194 // Gets extension by the given origin, regardless of whether the extension
195 // is active in the current process.
196 const extensions::Extension* GetExtensionByOrigin(
197 const blink::WebSecurityOrigin& origin) const;
199 // Returns true if the frame is navigating to an URL either into or out of an
200 // extension app's extent.
201 bool CrossesExtensionExtents(blink::WebLocalFrame* frame,
202 const GURL& new_url,
203 bool is_extension_url,
204 bool is_initial_navigation);
205 #endif
207 static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type,
208 const content::WebPluginInfo& plugin);
210 #if !defined(DISABLE_NACL)
211 // Determines if a NaCl app is allowed, and modifies params to pass the app's
212 // permissions to the trusted NaCl plugin.
213 static bool IsNaClAllowed(const GURL& manifest_url,
214 const GURL& app_url,
215 bool is_nacl_unrestricted,
216 const extensions::Extension* extension,
217 blink::WebPluginParams* params);
218 #endif
220 scoped_ptr<ChromeRenderProcessObserver> chrome_observer_;
221 scoped_ptr<web_cache::WebCacheRenderProcessObserver> web_cache_observer_;
223 // TODO(thestig): Extract into a separate file if possible. Cleanup
224 // ENABLE_EXTENSIONS ifdefs in the .cc file as well.
225 #if defined(ENABLE_EXTENSIONS)
226 scoped_ptr<ChromeExtensionsDispatcherDelegate> extension_dispatcher_delegate_;
227 scoped_ptr<extensions::Dispatcher> extension_dispatcher_;
228 scoped_ptr<extensions::RendererPermissionsPolicyDelegate>
229 permissions_policy_delegate_;
230 scoped_ptr<extensions::ExtensionsGuestViewContainerDispatcher>
231 guest_view_container_dispatcher_;
232 scoped_ptr<extensions::ResourceRequestPolicy> resource_request_policy_;
233 #endif
235 scoped_ptr<network_hints::PrescientNetworkingDispatcher>
236 prescient_networking_dispatcher_;
237 scoped_ptr<password_manager::CredentialManagerClient>
238 credential_manager_client_;
239 #if defined(ENABLE_SPELLCHECK)
240 scoped_ptr<SpellCheck> spellcheck_;
241 #endif
242 scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
243 scoped_ptr<safe_browsing::PhishingClassifierFilter> phishing_classifier_;
244 scoped_ptr<prerender::PrerenderDispatcher> prerender_dispatcher_;
245 #if defined(ENABLE_WEBRTC)
246 scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_;
247 #endif
248 #if defined(ENABLE_PRINT_PREVIEW)
249 scoped_ptr<ChromePDFPrintClient> pdf_print_client_;
250 #endif
251 #if defined(ENABLE_PLUGINS)
252 std::set<std::string> allowed_camera_device_origins_;
253 std::set<std::string> allowed_compositor_origins_;
254 #endif
257 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_