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