| 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, |
| 54 FaviconHelper* favicon_helper); |
| 57 virtual ~ChromeRenderViewObserver(); | 55 virtual ~ChromeRenderViewObserver(); |
| 58 | 56 |
| 59 private: | 57 private: |
| 60 // Holds the information received in OnWebUIJavaScript for later use | 58 // Holds the information received in OnWebUIJavaScript for later use |
| 61 // to call EvaluateScript() to preload javascript for WebUI tests. | 59 // to call EvaluateScript() to preload javascript for WebUI tests. |
| 62 struct WebUIJavaScript { | 60 struct WebUIJavaScript { |
| 63 string16 frame_xpath; | 61 string16 frame_xpath; |
| 64 string16 jscript; | 62 string16 jscript; |
| 65 int id; | 63 int id; |
| 66 bool notify_result; | 64 bool notify_result; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 127 |
| 130 void OnWebUIJavaScript(const string16& frame_xpath, | 128 void OnWebUIJavaScript(const string16& frame_xpath, |
| 131 const string16& jscript, | 129 const string16& jscript, |
| 132 int id, | 130 int id, |
| 133 bool notify_result); | 131 bool notify_result); |
| 134 void OnCaptureSnapshot(); | 132 void OnCaptureSnapshot(); |
| 135 void OnHandleMessageFromExternalHost(const std::string& message, | 133 void OnHandleMessageFromExternalHost(const std::string& message, |
| 136 const std::string& origin, | 134 const std::string& origin, |
| 137 const std::string& target); | 135 const std::string& target); |
| 138 void OnJavaScriptStressTestControl(int cmd, int param); | 136 void OnJavaScriptStressTestControl(int cmd, int param); |
| 139 void OnDownloadFavicon(int id, const GURL& image_url, int image_size); | |
| 140 void OnSetIsPrerendering(bool is_prerendering); | 137 void OnSetIsPrerendering(bool is_prerendering); |
| 141 void OnSetAllowDisplayingInsecureContent(bool allow); | 138 void OnSetAllowDisplayingInsecureContent(bool allow); |
| 142 void OnSetAllowRunningInsecureContent(bool allow); | 139 void OnSetAllowRunningInsecureContent(bool allow); |
| 143 void OnSetClientSidePhishingDetection(bool enable_phishing_detection); | 140 void OnSetClientSidePhishingDetection(bool enable_phishing_detection); |
| 144 void OnSetVisuallyDeemphasized(bool deemphasized); | 141 void OnSetVisuallyDeemphasized(bool deemphasized); |
| 145 void OnStartFrameSniffer(const string16& frame_name); | 142 void OnStartFrameSniffer(const string16& frame_name); |
| 146 void OnGetFPS(); | 143 void OnGetFPS(); |
| 147 void OnAddStrictSecurityHost(const std::string& host); | 144 void OnAddStrictSecurityHost(const std::string& host); |
| 148 | 145 |
| 149 void CapturePageInfoLater(bool preliminary_capture, base::TimeDelta delay); | 146 void CapturePageInfoLater(bool preliminary_capture, base::TimeDelta delay); |
| 150 | 147 |
| 151 // Captures the thumbnail and text contents for indexing for the given load | 148 // Captures the thumbnail and text contents for indexing for the given load |
| 152 // ID. Kicks off analysis of the captured text. | 149 // ID. Kicks off analysis of the captured text. |
| 153 void CapturePageInfo(bool preliminary_capture); | 150 void CapturePageInfo(bool preliminary_capture); |
| 154 | 151 |
| 155 // Retrieves the text from the given frame contents, the page text up to the | 152 // Retrieves the text from the given frame contents, the page text up to the |
| 156 // maximum amount kMaxIndexChars will be placed into the given buffer. | 153 // maximum amount kMaxIndexChars will be placed into the given buffer. |
| 157 void CaptureText(WebKit::WebFrame* frame, string16* contents); | 154 void CaptureText(WebKit::WebFrame* frame, string16* contents); |
| 158 | 155 |
| 159 // Capture a snapshot of a view. This is used to allow an extension | 156 // Capture a snapshot of a view. This is used to allow an extension |
| 160 // to get a snapshot of a tab using chrome.tabs.captureVisibleTab(). | 157 // to get a snapshot of a tab using chrome.tabs.captureVisibleTab(). |
| 161 bool CaptureSnapshot(WebKit::WebView* view, SkBitmap* snapshot); | 158 bool CaptureSnapshot(WebKit::WebView* view, SkBitmap* snapshot); |
| 162 | 159 |
| 163 ExternalHostBindings* GetExternalHostBindings(); | 160 ExternalHostBindings* GetExternalHostBindings(); |
| 164 | 161 |
| 165 // This callback is triggered when DownloadFavicon completes, either | |
| 166 // succesfully or with a failure. See DownloadFavicon for more | |
| 167 // details. | |
| 168 void DidDownloadFavicon( | |
| 169 int requested_size, | |
| 170 webkit_glue::MultiResolutionImageResourceFetcher* fetcher, | |
| 171 const std::vector<SkBitmap>& images); | |
| 172 | |
| 173 // Requests to download a favicon image. When done, the RenderView | |
| 174 // is notified by way of DidDownloadFavicon. Returns true if the | |
| 175 // request was successfully started, false otherwise. id is used to | |
| 176 // uniquely identify the request and passed back to the | |
| 177 // DidDownloadFavicon method. If the image has multiple frames, the | |
| 178 // frame whose size is image_size is returned. If the image doesn't | |
| 179 // have a frame at the specified size, the first is returned. | |
| 180 bool DownloadFavicon(int id, const GURL& image_url, int image_size); | |
| 181 | |
| 182 // Decodes a data: URL image or returns an empty image in case of failure. | |
| 183 SkBitmap ImageFromDataUrl(const GURL&) const; | |
| 184 | |
| 185 // Determines if a host is in the strict security host set. | 162 // Determines if a host is in the strict security host set. |
| 186 bool IsStrictSecurityHost(const std::string& host); | 163 bool IsStrictSecurityHost(const std::string& host); |
| 187 | 164 |
| 188 // If |origin| corresponds to an installed extension, returns that extension. | 165 // If |origin| corresponds to an installed extension, returns that extension. |
| 189 // Otherwise returns NULL. | 166 // Otherwise returns NULL. |
| 190 const extensions::Extension* GetExtension( | 167 const extensions::Extension* GetExtension( |
| 191 const WebKit::WebSecurityOrigin& origin) const; | 168 const WebKit::WebSecurityOrigin& origin) const; |
| 192 | 169 |
| 193 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received. | 170 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received. |
| 194 scoped_ptr<WebUIJavaScript> webui_javascript_; | 171 scoped_ptr<WebUIJavaScript> webui_javascript_; |
| 195 | 172 |
| 196 // Owned by ChromeContentRendererClient and outlive us. | 173 // Owned by ChromeContentRendererClient and outlive us. |
| 197 ChromeRenderProcessObserver* chrome_render_process_observer_; | 174 ChromeRenderProcessObserver* chrome_render_process_observer_; |
| 198 extensions::Dispatcher* extension_dispatcher_; | 175 extensions::Dispatcher* extension_dispatcher_; |
| 199 | 176 |
| 200 // Have the same lifetime as us. | 177 // Have the same lifetime as us. |
| 201 ContentSettingsObserver* content_settings_; | 178 ContentSettingsObserver* content_settings_; |
| 202 TranslateHelper* translate_helper_; | 179 TranslateHelper* translate_helper_; |
| 203 safe_browsing::PhishingClassifierDelegate* phishing_classifier_; | 180 safe_browsing::PhishingClassifierDelegate* phishing_classifier_; |
| 181 FaviconHelper* favicon_helper_; |
| 204 | 182 |
| 205 // Page_id from the last page we indexed. This prevents us from indexing the | 183 // Page_id from the last page we indexed. This prevents us from indexing the |
| 206 // same page twice in a row. | 184 // same page twice in a row. |
| 207 int32 last_indexed_page_id_; | 185 int32 last_indexed_page_id_; |
| 208 // The toplevel URL that was last indexed. This is used together with the | 186 // The toplevel URL that was last indexed. This is used together with the |
| 209 // page id to decide whether to reindex in certain cases like history | 187 // page id to decide whether to reindex in certain cases like history |
| 210 // replacement. | 188 // replacement. |
| 211 GURL last_indexed_url_; | 189 GURL last_indexed_url_; |
| 212 | 190 |
| 213 // Insecure content may be permitted for the duration of this render view. | 191 // Insecure content may be permitted for the duration of this render view. |
| 214 bool allow_displaying_insecure_content_; | 192 bool allow_displaying_insecure_content_; |
| 215 bool allow_running_insecure_content_; | 193 bool allow_running_insecure_content_; |
| 216 std::set<std::string> strict_security_hosts_; | 194 std::set<std::string> strict_security_hosts_; |
| 217 | 195 |
| 218 // External host exposed through automation controller. | 196 // External host exposed through automation controller. |
| 219 scoped_ptr<ExternalHostBindings> external_host_bindings_; | 197 scoped_ptr<ExternalHostBindings> external_host_bindings_; |
| 220 | 198 |
| 221 typedef std::vector< | |
| 222 linked_ptr<webkit_glue::MultiResolutionImageResourceFetcher> > | |
| 223 ImageResourceFetcherList; | |
| 224 | |
| 225 // ImageResourceFetchers schedule via DownloadImage. | |
| 226 ImageResourceFetcherList image_fetchers_; | |
| 227 | |
| 228 // A color page overlay when visually de-emaphasized. | 199 // A color page overlay when visually de-emaphasized. |
| 229 scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_; | 200 scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_; |
| 230 | 201 |
| 231 // Used to delay calling CapturePageInfo. | 202 // Used to delay calling CapturePageInfo. |
| 232 base::Timer capture_timer_; | 203 base::Timer capture_timer_; |
| 233 | 204 |
| 234 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver); | 205 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver); |
| 235 }; | 206 }; |
| 236 | 207 |
| 237 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ | 208 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ |
| OLD | NEW |