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