Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / chrome_content_renderer_client.h
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.
4
5 #ifndef CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
6 #define CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "content/public/renderer/content_renderer_client.h"
16 #include "ipc/ipc_channel_proxy.h"
17
18 class ChromeRenderProcessObserver;
19 class PrescientNetworkingDispatcher;
20 class RendererNetPredictor;
21 class SearchBouncer;
22 #if defined(ENABLE_SPELLCHECK)
23 class SpellCheck;
24 class SpellCheckProvider;
25 #endif
26
27 struct ChromeViewHostMsg_GetPluginInfo_Output;
28
29 namespace content {
30 struct WebPluginInfo;
31 }
32
33 namespace extensions {
34 class Dispatcher;
35 class Extension;
36 class ExtensionSet;
37 class RendererPermissionsPolicyDelegate;
38 }
39
40 namespace prerender {
41 class PrerenderDispatcher;
42 }
43
44 namespace safe_browsing {
45 class PhishingClassifierFilter;
46 }
47
48 namespace visitedlink {
49 class VisitedLinkSlave;
50 }
51
52 namespace blink {
53 class WebSecurityOrigin;
54 }
55
56 #if defined(ENABLE_WEBRTC)
57 class WebRtcLoggingMessageFilter;
58 #endif
59
60 class ChromeContentRendererClient : public content::ContentRendererClient {
61  public:
62   ChromeContentRendererClient();
63   virtual ~ChromeContentRendererClient();
64
65   virtual void RenderThreadStarted() OVERRIDE;
66   virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE;
67   virtual void RenderViewCreated(content::RenderView* render_view) OVERRIDE;
68   virtual void SetNumberOfViews(int number_of_views) OVERRIDE;
69   virtual SkBitmap* GetSadPluginBitmap() OVERRIDE;
70   virtual SkBitmap* GetSadWebViewBitmap() OVERRIDE;
71   virtual std::string GetDefaultEncoding() OVERRIDE;
72   virtual bool OverrideCreatePlugin(
73       content::RenderFrame* render_frame,
74       blink::WebFrame* frame,
75       const blink::WebPluginParams& params,
76       blink::WebPlugin** plugin) OVERRIDE;
77   virtual blink::WebPlugin* CreatePluginReplacement(
78       content::RenderFrame* render_frame,
79       const base::FilePath& plugin_path) OVERRIDE;
80   virtual bool HasErrorPage(int http_status_code,
81                             std::string* error_domain) OVERRIDE;
82   virtual bool ShouldSuppressErrorPage(content::RenderFrame* render_frame,
83                                        const GURL& url) OVERRIDE;
84   virtual void GetNavigationErrorStrings(
85       content::RenderView* render_view,
86       blink::WebFrame* frame,
87       const blink::WebURLRequest& failed_request,
88       const blink::WebURLError& error,
89       std::string* error_html,
90       base::string16* error_description) OVERRIDE;
91   virtual void DeferMediaLoad(content::RenderFrame* render_frame,
92                               const base::Closure& closure) OVERRIDE;
93   virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE;
94   virtual bool AllowPopup() OVERRIDE;
95   virtual bool ShouldFork(blink::WebFrame* frame,
96                           const GURL& url,
97                           const std::string& http_method,
98                           bool is_initial_navigation,
99                           bool is_server_redirect,
100                           bool* send_referrer) OVERRIDE;
101   virtual bool WillSendRequest(blink::WebFrame* frame,
102                                content::PageTransition transition_type,
103                                const GURL& url,
104                                const GURL& first_party_for_cookies,
105                                GURL* new_url) OVERRIDE;
106   virtual void DidCreateScriptContext(blink::WebFrame* frame,
107                                       v8::Handle<v8::Context> context,
108                                       int extension_group,
109                                       int world_id) OVERRIDE;
110   virtual void WillReleaseScriptContext(blink::WebFrame* frame,
111                                         v8::Handle<v8::Context> context,
112                                         int world_id) OVERRIDE;
113   virtual unsigned long long VisitedLinkHash(const char* canonical_url,
114                                              size_t length) OVERRIDE;
115   virtual bool IsLinkVisited(unsigned long long link_hash) OVERRIDE;
116   virtual blink::WebPrescientNetworking* GetPrescientNetworking() OVERRIDE;
117   virtual bool ShouldOverridePageVisibilityState(
118       const content::RenderFrame* render_frame,
119       blink::WebPageVisibilityState* override_state) OVERRIDE;
120   virtual bool AllowBrowserPlugin(
121       blink::WebPluginContainer* container) OVERRIDE;
122   virtual const void* CreatePPAPIInterface(
123       const std::string& interface_name) OVERRIDE;
124   virtual bool IsExternalPepperPlugin(const std::string& module_name) OVERRIDE;
125   virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
126       blink::WebSpeechSynthesizerClient* client) OVERRIDE;
127   virtual bool ShouldReportDetailedMessageForSource(
128       const base::string16& source) const OVERRIDE;
129   virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE;
130   virtual blink::WebWorkerPermissionClientProxy*
131       CreateWorkerPermissionClientProxy(content::RenderFrame* render_frame,
132                                         blink::WebFrame* frame) OVERRIDE;
133   virtual bool AllowPepperMediaStreamAPI(const GURL& url) OVERRIDE;
134   virtual void AddKeySystems(
135       std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
136
137   // For testing.
138   void SetExtensionDispatcher(extensions::Dispatcher* extension_dispatcher);
139
140 #if defined(ENABLE_SPELLCHECK)
141   // Sets a new |spellcheck|. Used for low-mem restart and testing only.
142   // Takes ownership of |spellcheck|.
143   void SetSpellcheck(SpellCheck* spellcheck);
144 #endif
145
146   // Called in low-memory conditions to dump the memory used by the spellchecker
147   // and start over.
148   void OnPurgeMemory();
149
150   static blink::WebPlugin* CreatePlugin(
151       content::RenderFrame* render_frame,
152       blink::WebFrame* frame,
153       const blink::WebPluginParams& params,
154       const ChromeViewHostMsg_GetPluginInfo_Output& output);
155
156   static bool IsExtensionOrSharedModuleWhitelisted(
157       const GURL& url, const std::set<std::string>& whitelist);
158
159   // TODO(mpcomplete): remove after we collect histogram data.
160   // http://crbug.com/100411
161   static bool IsAdblockInstalled();
162   static bool IsAdblockPlusInstalled();
163   static bool IsAdblockWithWebRequestInstalled();
164   static bool IsAdblockPlusWithWebRequestInstalled();
165   static bool IsOtherExtensionWithWebRequestInstalled();
166
167  private:
168   FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction);
169   FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest,
170                            ShouldSuppressErrorPage);
171
172   // Gets extension by the given origin, regardless of whether the extension
173   // is active in the current process.
174   const extensions::Extension* GetExtensionByOrigin(
175       const blink::WebSecurityOrigin& origin) const;
176
177   // Returns true if the frame is navigating to an URL either into or out of an
178   // extension app's extent.
179   bool CrossesExtensionExtents(blink::WebFrame* frame,
180                                const GURL& new_url,
181                                const extensions::ExtensionSet& extensions,
182                                bool is_extension_url,
183                                bool is_initial_navigation);
184
185   static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type,
186                                        const content::WebPluginInfo& plugin);
187
188   // Determines if a NaCl app is allowed, and modifies params to pass the app's
189   // permissions to the trusted NaCl plugin.
190   static bool IsNaClAllowed(const GURL& manifest_url,
191                             const GURL& app_url,
192                             bool is_nacl_unrestricted,
193                             const extensions::Extension* extension,
194                             blink::WebPluginParams* params);
195
196   scoped_ptr<ChromeRenderProcessObserver> chrome_observer_;
197   scoped_ptr<extensions::Dispatcher> extension_dispatcher_;
198   scoped_ptr<extensions::RendererPermissionsPolicyDelegate>
199       permissions_policy_delegate_;
200   scoped_ptr<PrescientNetworkingDispatcher> prescient_networking_dispatcher_;
201   scoped_ptr<RendererNetPredictor> net_predictor_;
202 #if defined(ENABLE_SPELLCHECK)
203   scoped_ptr<SpellCheck> spellcheck_;
204 #endif
205   scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
206   scoped_ptr<safe_browsing::PhishingClassifierFilter> phishing_classifier_;
207   scoped_ptr<prerender::PrerenderDispatcher> prerender_dispatcher_;
208 #if defined(ENABLE_WEBRTC)
209   scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_;
210 #endif
211   scoped_ptr<SearchBouncer> search_bouncer_;
212 };
213
214 #endif  // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_