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 "ui/gfx/size.h" 19 #include "url/gurl.h" 20 21 class ContentSettingsObserver; 22 class SkBitmap; 23 class WebViewColorOverlay; 24 class WebViewAnimatingOverlay; 25 26 namespace blink { 27 class WebView; 28 struct WebWindowFeatures; 29 } 30 31 namespace safe_browsing { 32 class PhishingClassifierDelegate; 33 } 34 35 namespace translate { 36 class TranslateHelper; 37 } 38 39 namespace web_cache { 40 class WebCacheRenderProcessObserver; 41 } 42 43 // This class holds the Chrome specific parts of RenderView, and has the same 44 // lifetime. 45 class ChromeRenderViewObserver : public content::RenderViewObserver { 46 public: 47 // translate_helper can be NULL. 48 ChromeRenderViewObserver( 49 content::RenderView* render_view, 50 web_cache::WebCacheRenderProcessObserver* 51 web_cache_render_process_observer); 52 virtual ~ChromeRenderViewObserver(); 53 54 private: 55 // RenderViewObserver implementation. 56 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 57 virtual void DidStartLoading() OVERRIDE; 58 virtual void DidStopLoading() OVERRIDE; 59 virtual void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, 60 bool is_new_navigation) OVERRIDE; 61 virtual void Navigate(const GURL& url) OVERRIDE; 62 63 #if !defined(OS_ANDROID) && !defined(OS_IOS) 64 void OnWebUIJavaScript(const base::string16& javascript); 65 #endif 66 #if defined(ENABLE_EXTENSIONS) 67 void OnSetVisuallyDeemphasized(bool deemphasized); 68 #endif 69 #if defined(OS_ANDROID) 70 void OnUpdateTopControlsState(content::TopControlsState constraints, 71 content::TopControlsState current, 72 bool animate); 73 void OnRetrieveMetaTagContent(const GURL& expected_url, 74 const std::string tag_name); 75 #endif 76 void OnGetWebApplicationInfo(); 77 void OnSetClientSidePhishingDetection(bool enable_phishing_detection); 78 void OnSetWindowFeatures(const blink::WebWindowFeatures& window_features); 79 80 void CapturePageInfoLater(bool preliminary_capture, 81 base::TimeDelta delay); 82 83 // Captures the thumbnail and text contents for indexing for the given load 84 // ID. Kicks off analysis of the captured text. 85 void CapturePageInfo(bool preliminary_capture); 86 87 // Retrieves the text from the given frame contents, the page text up to the 88 // maximum amount kMaxIndexChars will be placed into the given buffer. 89 void CaptureText(blink::WebFrame* frame, base::string16* contents); 90 91 // Determines if a host is in the strict security host set. 92 bool IsStrictSecurityHost(const std::string& host); 93 94 // Checks if a page contains <meta http-equiv="refresh" ...> tag. 95 bool HasRefreshMetaTag(blink::WebFrame* frame); 96 97 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received. 98 std::vector<base::string16> webui_javascript_; 99 100 // Owned by ChromeContentRendererClient and outlive us. 101 web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer_; 102 103 // Have the same lifetime as us. 104 translate::TranslateHelper* translate_helper_; 105 safe_browsing::PhishingClassifierDelegate* phishing_classifier_; 106 107 // A color page overlay when visually de-emaphasized. 108 scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_; 109 110 // Used to delay calling CapturePageInfo. 111 base::Timer capture_timer_; 112 113 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver); 114 }; 115 116 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_ 117