OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ | 5 #ifndef CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ |
6 #define CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ | 6 #define CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/timer.h" | 14 #include "base/timer.h" |
15 #include "chrome/common/extensions/permissions/api_permission.h" | 15 #include "chrome/common/extensions/permissions/api_permission.h" |
16 #include "content/public/renderer/render_view_observer.h" | 16 #include "content/public/renderer/render_view_observer.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPermissionClient.h
" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPermissionClient.h
" |
19 | 19 |
20 class ChromeRenderProcessObserver; | 20 class ChromeRenderProcessObserver; |
21 class ContentSettingsObserver; | 21 class ContentSettingsObserver; |
22 class ExternalHostBindings; | 22 class ExternalHostBindings; |
| 23 class FaviconHelper; |
23 class SkBitmap; | 24 class SkBitmap; |
24 class TranslateHelper; | 25 class TranslateHelper; |
25 class WebViewColorOverlay; | 26 class WebViewColorOverlay; |
26 class WebViewAnimatingOverlay; | 27 class WebViewAnimatingOverlay; |
27 | 28 |
28 namespace extensions { | 29 namespace extensions { |
29 class Dispatcher; | 30 class Dispatcher; |
30 class Extension; | 31 class Extension; |
31 } | 32 } |
32 | 33 |
33 namespace WebKit { | 34 namespace WebKit { |
34 class WebView; | 35 class WebView; |
35 } | 36 } |
36 | 37 |
37 namespace safe_browsing { | 38 namespace safe_browsing { |
38 class PhishingClassifierDelegate; | 39 class PhishingClassifierDelegate; |
39 } | 40 } |
40 | 41 |
41 namespace webkit_glue { | |
42 class MultiResolutionImageResourceFetcher; | |
43 } | |
44 | |
45 // This class holds the Chrome specific parts of RenderView, and has the same | 42 // This class holds the Chrome specific parts of RenderView, and has the same |
46 // lifetime. | 43 // lifetime. |
47 class ChromeRenderViewObserver : public content::RenderViewObserver, | 44 class ChromeRenderViewObserver : public content::RenderViewObserver, |
48 public WebKit::WebPermissionClient { | 45 public WebKit::WebPermissionClient { |
49 public: | 46 public: |
50 // translate_helper can be NULL. | 47 // translate_helper can be NULL. |
51 ChromeRenderViewObserver( | 48 ChromeRenderViewObserver( |
52 content::RenderView* render_view, | 49 content::RenderView* render_view, |
53 ContentSettingsObserver* content_settings, | 50 ContentSettingsObserver* content_settings, |
54 ChromeRenderProcessObserver* chrome_render_process_observer, | 51 ChromeRenderProcessObserver* chrome_render_process_observer, |
55 extensions::Dispatcher* extension_dispatcher, | 52 extensions::Dispatcher* extension_dispatcher, |
56 TranslateHelper* translate_helper); | 53 TranslateHelper* translate_helper); |
57 virtual ~ChromeRenderViewObserver(); | 54 virtual ~ChromeRenderViewObserver(); |
58 | 55 |
59 private: | 56 private: |
60 // Holds the information received in OnWebUIJavaScript for later use | 57 // Holds the information received in OnWebUIJavaScript for later use |
61 // to call EvaluateScript() to preload javascript for WebUI tests. | 58 // to call EvaluateScript() to preload javascript for WebUI tests. |
62 struct WebUIJavaScript { | 59 struct WebUIJavaScript { |
63 string16 frame_xpath; | 60 string16 frame_xpath; |
64 string16 jscript; | 61 string16 jscript; |
65 int id; | 62 int id; |
66 bool notify_result; | 63 bool notify_result; |
67 }; | 64 }; |
68 | 65 |
69 // RenderViewObserver implementation. | 66 // RenderViewObserver implementation. |
70 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 67 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
71 virtual void DidStartLoading() OVERRIDE; | 68 virtual void DidStartLoading() OVERRIDE; |
72 virtual void DidStopLoading() OVERRIDE; | 69 virtual void DidStopLoading() OVERRIDE; |
73 virtual void DidChangeIcon(WebKit::WebFrame* frame, | |
74 WebKit::WebIconURL::Type icon_type) OVERRIDE; | |
75 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, | 70 virtual void DidCommitProvisionalLoad(WebKit::WebFrame* frame, |
76 bool is_new_navigation) OVERRIDE; | 71 bool is_new_navigation) OVERRIDE; |
77 virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE; | 72 virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE; |
78 virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) OVERRIDE; | 73 virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) OVERRIDE; |
79 | 74 |
80 // WebKit::WebPermissionClient implementation. | 75 // WebKit::WebPermissionClient implementation. |
81 virtual bool allowDatabase(WebKit::WebFrame* frame, | 76 virtual bool allowDatabase(WebKit::WebFrame* frame, |
82 const WebKit::WebString& name, | 77 const WebKit::WebString& name, |
83 const WebKit::WebString& display_name, | 78 const WebKit::WebString& display_name, |
84 unsigned long estimated_size) OVERRIDE; | 79 unsigned long estimated_size) OVERRIDE; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 125 |
131 void OnWebUIJavaScript(const string16& frame_xpath, | 126 void OnWebUIJavaScript(const string16& frame_xpath, |
132 const string16& jscript, | 127 const string16& jscript, |
133 int id, | 128 int id, |
134 bool notify_result); | 129 bool notify_result); |
135 void OnCaptureSnapshot(); | 130 void OnCaptureSnapshot(); |
136 void OnHandleMessageFromExternalHost(const std::string& message, | 131 void OnHandleMessageFromExternalHost(const std::string& message, |
137 const std::string& origin, | 132 const std::string& origin, |
138 const std::string& target); | 133 const std::string& target); |
139 void OnJavaScriptStressTestControl(int cmd, int param); | 134 void OnJavaScriptStressTestControl(int cmd, int param); |
140 void OnDownloadFavicon(int id, const GURL& image_url, int image_size); | |
141 void OnSetIsPrerendering(bool is_prerendering); | 135 void OnSetIsPrerendering(bool is_prerendering); |
142 void OnSetAllowDisplayingInsecureContent(bool allow); | 136 void OnSetAllowDisplayingInsecureContent(bool allow); |
143 void OnSetAllowRunningInsecureContent(bool allow); | 137 void OnSetAllowRunningInsecureContent(bool allow); |
144 void OnSetClientSidePhishingDetection(bool enable_phishing_detection); | 138 void OnSetClientSidePhishingDetection(bool enable_phishing_detection); |
145 void OnSetVisuallyDeemphasized(bool deemphasized); | 139 void OnSetVisuallyDeemphasized(bool deemphasized); |
146 void OnStartFrameSniffer(const string16& frame_name); | 140 void OnStartFrameSniffer(const string16& frame_name); |
147 void OnGetFPS(); | 141 void OnGetFPS(); |
148 void OnAddStrictSecurityHost(const std::string& host); | 142 void OnAddStrictSecurityHost(const std::string& host); |
149 | 143 |
150 void CapturePageInfoLater(bool preliminary_capture, base::TimeDelta delay); | 144 void CapturePageInfoLater(bool preliminary_capture, base::TimeDelta delay); |
151 | 145 |
152 // Captures the thumbnail and text contents for indexing for the given load | 146 // Captures the thumbnail and text contents for indexing for the given load |
153 // ID. Kicks off analysis of the captured text. | 147 // ID. Kicks off analysis of the captured text. |
154 void CapturePageInfo(bool preliminary_capture); | 148 void CapturePageInfo(bool preliminary_capture); |
155 | 149 |
156 // Retrieves the text from the given frame contents, the page text up to the | 150 // Retrieves the text from the given frame contents, the page text up to the |
157 // maximum amount kMaxIndexChars will be placed into the given buffer. | 151 // maximum amount kMaxIndexChars will be placed into the given buffer. |
158 void CaptureText(WebKit::WebFrame* frame, string16* contents); | 152 void CaptureText(WebKit::WebFrame* frame, string16* contents); |
159 | 153 |
160 // Capture a snapshot of a view. This is used to allow an extension | 154 // Capture a snapshot of a view. This is used to allow an extension |
161 // to get a snapshot of a tab using chrome.tabs.captureVisibleTab(). | 155 // to get a snapshot of a tab using chrome.tabs.captureVisibleTab(). |
162 bool CaptureSnapshot(WebKit::WebView* view, SkBitmap* snapshot); | 156 bool CaptureSnapshot(WebKit::WebView* view, SkBitmap* snapshot); |
163 | 157 |
164 ExternalHostBindings* GetExternalHostBindings(); | 158 ExternalHostBindings* GetExternalHostBindings(); |
165 | 159 |
166 // This callback is triggered when DownloadFavicon completes, either | |
167 // succesfully or with a failure. See DownloadFavicon for more | |
168 // details. | |
169 void DidDownloadFavicon( | |
170 int requested_size, | |
171 webkit_glue::MultiResolutionImageResourceFetcher* fetcher, | |
172 const std::vector<SkBitmap>& images); | |
173 | |
174 // Requests to download a favicon image. When done, the RenderView | |
175 // is notified by way of DidDownloadFavicon. Returns true if the | |
176 // request was successfully started, false otherwise. id is used to | |
177 // uniquely identify the request and passed back to the | |
178 // DidDownloadFavicon method. If the image has multiple frames, the | |
179 // frame whose size is image_size is returned. If the image doesn't | |
180 // have a frame at the specified size, the first is returned. | |
181 bool DownloadFavicon(int id, const GURL& image_url, int image_size); | |
182 | |
183 // Decodes a data: URL image or returns an empty image in case of failure. | |
184 SkBitmap ImageFromDataUrl(const GURL&) const; | |
185 | |
186 // Determines if a host is in the strict security host set. | 160 // Determines if a host is in the strict security host set. |
187 bool IsStrictSecurityHost(const std::string& host); | 161 bool IsStrictSecurityHost(const std::string& host); |
188 | 162 |
189 // If |origin| corresponds to an installed extension, returns that extension. | 163 // If |origin| corresponds to an installed extension, returns that extension. |
190 // Otherwise returns NULL. | 164 // Otherwise returns NULL. |
191 const extensions::Extension* GetExtension( | 165 const extensions::Extension* GetExtension( |
192 const WebKit::WebSecurityOrigin& origin) const; | 166 const WebKit::WebSecurityOrigin& origin) const; |
193 | 167 |
194 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received. | 168 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received. |
195 scoped_ptr<WebUIJavaScript> webui_javascript_; | 169 scoped_ptr<WebUIJavaScript> webui_javascript_; |
(...skipping 16 matching lines...) Expand all Loading... |
212 GURL last_indexed_url_; | 186 GURL last_indexed_url_; |
213 | 187 |
214 // Insecure content may be permitted for the duration of this render view. | 188 // Insecure content may be permitted for the duration of this render view. |
215 bool allow_displaying_insecure_content_; | 189 bool allow_displaying_insecure_content_; |
216 bool allow_running_insecure_content_; | 190 bool allow_running_insecure_content_; |
217 std::set<std::string> strict_security_hosts_; | 191 std::set<std::string> strict_security_hosts_; |
218 | 192 |
219 // External host exposed through automation controller. | 193 // External host exposed through automation controller. |
220 scoped_ptr<ExternalHostBindings> external_host_bindings_; | 194 scoped_ptr<ExternalHostBindings> external_host_bindings_; |
221 | 195 |
222 typedef std::vector< | |
223 linked_ptr<webkit_glue::MultiResolutionImageResourceFetcher> > | |
224 ImageResourceFetcherList; | |
225 | |
226 // ImageResourceFetchers schedule via DownloadImage. | |
227 ImageResourceFetcherList image_fetchers_; | |
228 | |
229 // A color page overlay when visually de-emaphasized. | 196 // A color page overlay when visually de-emaphasized. |
230 scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_; | 197 scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_; |
231 | 198 |
232 // Used to delay calling CapturePageInfo. | 199 // Used to delay calling CapturePageInfo. |
233 base::Timer capture_timer_; | 200 base::Timer capture_timer_; |
234 | 201 |
235 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver); | 202 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver); |
236 }; | 203 }; |
237 | 204 |
238 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ | 205 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ |
OLD | NEW |