Suppression for crbug/241044.
[chromium-blink-merge.git] / chrome / renderer / chrome_render_view_observer.h
blobeda1d90d7a629e6bbe72b57d175697f1ebf7312b
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_RENDER_VIEW_OBSERVER_H_
6 #define CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/timer.h"
15 #include "chrome/common/extensions/permissions/api_permission.h"
16 #include "content/public/renderer/render_view_observer.h"
17 #include "googleurl/src/gurl.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPermissionClient.h"
20 class ChromeRenderProcessObserver;
21 class ContentSettingsObserver;
22 class ExternalHostBindings;
23 class SkBitmap;
24 class TranslateHelper;
25 class WebViewColorOverlay;
26 class WebViewAnimatingOverlay;
28 namespace extensions {
29 class Dispatcher;
30 class Extension;
33 namespace WebKit {
34 class WebView;
37 namespace safe_browsing {
38 class PhishingClassifierDelegate;
41 // This class holds the Chrome specific parts of RenderView, and has the same
42 // lifetime.
43 class ChromeRenderViewObserver : public content::RenderViewObserver,
44 public WebKit::WebPermissionClient {
45 public:
46 // translate_helper can be NULL.
47 ChromeRenderViewObserver(
48 content::RenderView* render_view,
49 ContentSettingsObserver* content_settings,
50 ChromeRenderProcessObserver* chrome_render_process_observer,
51 extensions::Dispatcher* extension_dispatcher);
52 virtual ~ChromeRenderViewObserver();
54 private:
55 // Holds the information received in OnWebUIJavaScript for later use
56 // to call EvaluateScript() to preload javascript for WebUI tests.
57 struct WebUIJavaScript {
58 string16 frame_xpath;
59 string16 jscript;
60 int id;
61 bool notify_result;
64 // RenderViewObserver implementation.
65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
66 virtual void DidStartLoading() OVERRIDE;
67 virtual void DidStopLoading() OVERRIDE;
68 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame,
69 bool is_new_navigation) OVERRIDE;
70 virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE;
71 virtual void DidHandleGestureEvent(
72 const WebKit::WebGestureEvent& event) OVERRIDE;
74 // WebKit::WebPermissionClient implementation.
75 virtual bool allowDatabase(WebKit::WebFrame* frame,
76 const WebKit::WebString& name,
77 const WebKit::WebString& display_name,
78 unsigned long estimated_size) OVERRIDE;
79 virtual bool allowFileSystem(WebKit::WebFrame* frame) OVERRIDE;
80 virtual bool allowImage(WebKit::WebFrame* frame,
81 bool enabled_per_settings,
82 const WebKit::WebURL& image_url) OVERRIDE;
83 virtual bool allowIndexedDB(WebKit::WebFrame* frame,
84 const WebKit::WebString& name,
85 const WebKit::WebSecurityOrigin& origin) OVERRIDE;
86 virtual bool allowPlugins(WebKit::WebFrame* frame,
87 bool enabled_per_settings) OVERRIDE;
88 virtual bool allowScript(WebKit::WebFrame* frame,
89 bool enabled_per_settings) OVERRIDE;
90 virtual bool allowScriptFromSource(WebKit::WebFrame* frame,
91 bool enabled_per_settings,
92 const WebKit::WebURL& script_url) OVERRIDE;
93 virtual bool allowScriptExtension(WebKit::WebFrame* frame,
94 const WebKit::WebString& extension_name,
95 int extension_group) OVERRIDE;
96 virtual bool allowScriptExtension(WebKit::WebFrame* frame,
97 const WebKit::WebString& extension_name,
98 int extension_group,
99 int world_id);
100 virtual bool allowStorage(WebKit::WebFrame* frame, bool local) OVERRIDE;
101 virtual bool allowReadFromClipboard(WebKit::WebFrame* frame,
102 bool default_value) OVERRIDE;
103 virtual bool allowWriteToClipboard(WebKit::WebFrame* frame,
104 bool default_value) OVERRIDE;
105 virtual bool allowWebComponents(const WebKit::WebDocument&, bool) OVERRIDE;
106 virtual bool allowHTMLNotifications(
107 const WebKit::WebDocument& document) OVERRIDE;
108 virtual bool allowMutationEvents(const WebKit::WebDocument&,
109 bool default_value) OVERRIDE;
110 virtual bool allowPushState(const WebKit::WebDocument&) OVERRIDE;
111 virtual void didNotAllowPlugins(WebKit::WebFrame* frame) OVERRIDE;
112 virtual void didNotAllowScript(WebKit::WebFrame* frame) OVERRIDE;
113 virtual bool allowDisplayingInsecureContent(
114 WebKit::WebFrame* frame,
115 bool allowed_per_settings,
116 const WebKit::WebSecurityOrigin& context,
117 const WebKit::WebURL& url) OVERRIDE;
118 virtual bool allowRunningInsecureContent(
119 WebKit::WebFrame* frame,
120 bool allowed_per_settings,
121 const WebKit::WebSecurityOrigin& context,
122 const WebKit::WebURL& url) OVERRIDE;
123 virtual void Navigate(const GURL& url) OVERRIDE;
125 void OnWebUIJavaScript(const string16& frame_xpath,
126 const string16& jscript,
127 int id,
128 bool notify_result);
129 void OnHandleMessageFromExternalHost(const std::string& message,
130 const std::string& origin,
131 const std::string& target);
132 void OnJavaScriptStressTestControl(int cmd, int param);
133 void OnSetIsPrerendering(bool is_prerendering);
134 void OnSetAllowDisplayingInsecureContent(bool allow);
135 void OnSetAllowRunningInsecureContent(bool allow);
136 void OnSetClientSidePhishingDetection(bool enable_phishing_detection);
137 void OnSetVisuallyDeemphasized(bool deemphasized);
138 void OnStartFrameSniffer(const string16& frame_name);
139 void OnGetFPS();
140 void OnAddStrictSecurityHost(const std::string& host);
141 void OnNPAPINotSupported();
143 void CapturePageInfoLater(bool preliminary_capture, base::TimeDelta delay);
145 // Captures the thumbnail and text contents for indexing for the given load
146 // ID. Kicks off analysis of the captured text.
147 void CapturePageInfo(bool preliminary_capture);
149 // Retrieves the text from the given frame contents, the page text up to the
150 // maximum amount kMaxIndexChars will be placed into the given buffer.
151 void CaptureText(WebKit::WebFrame* frame, string16* contents);
153 ExternalHostBindings* GetExternalHostBindings();
155 // Determines if a host is in the strict security host set.
156 bool IsStrictSecurityHost(const std::string& host);
158 // If |origin| corresponds to an installed extension, returns that extension.
159 // Otherwise returns NULL.
160 const extensions::Extension* GetExtension(
161 const WebKit::WebSecurityOrigin& origin) const;
163 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received.
164 scoped_ptr<WebUIJavaScript> webui_javascript_;
166 // Owned by ChromeContentRendererClient and outlive us.
167 ChromeRenderProcessObserver* chrome_render_process_observer_;
168 extensions::Dispatcher* extension_dispatcher_;
170 // Have the same lifetime as us.
171 ContentSettingsObserver* content_settings_;
172 TranslateHelper* translate_helper_;
173 safe_browsing::PhishingClassifierDelegate* phishing_classifier_;
175 // Page_id from the last page we indexed. This prevents us from indexing the
176 // same page twice in a row.
177 int32 last_indexed_page_id_;
178 // The toplevel URL that was last indexed. This is used together with the
179 // page id to decide whether to reindex in certain cases like history
180 // replacement.
181 GURL last_indexed_url_;
183 // Insecure content may be permitted for the duration of this render view.
184 bool allow_displaying_insecure_content_;
185 bool allow_running_insecure_content_;
186 std::set<std::string> strict_security_hosts_;
188 // External host exposed through automation controller.
189 scoped_ptr<ExternalHostBindings> external_host_bindings_;
191 // A color page overlay when visually de-emaphasized.
192 scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_;
194 // Used to delay calling CapturePageInfo.
195 base::Timer capture_timer_;
197 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver);
200 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_