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.
5 #ifndef CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_
6 #define CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_
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/geometry/size.h"
21 class ContentSettingsObserver
;
26 struct WebWindowFeatures
;
33 namespace safe_browsing
{
34 class PhishingClassifierDelegate
;
38 class TranslateHelper
;
42 class WebCacheRenderProcessObserver
;
45 // Receives page information that was captured by PageInfo instance.
46 class PageInfoReceiver
{
48 enum CaptureType
{ PRELIMINARY_CAPTURE
, FINAL_CAPTURE
};
49 virtual void PageCaptured(base::string16
* content
,
50 CaptureType capture_type
) = 0;
53 // Captures page information using the top (main) frame of a frame tree.
54 // Currently, this page information is just the text content of the all frames,
55 // collected and concatenated until a certain limit (kMaxIndexChars) is reached.
58 using CaptureType
= PageInfoReceiver::CaptureType
;
60 explicit PageInfo(PageInfoReceiver
* context
);
63 void CapturePageInfoLater(CaptureType capture_type
,
64 content::RenderFrame
* render_frame
,
65 base::TimeDelta delay
);
68 // Checks if the current frame is an error page.
69 bool IsErrorPage(blink::WebLocalFrame
* frame
);
71 // Captures the thumbnail and text contents for indexing for the given load
72 // ID. Kicks off analysis of the captured text.
73 void CapturePageInfo(content::RenderFrame
* render_frame
,
74 CaptureType capture_type
);
76 // Retrieves the text from the given frame contents, the page text up to the
77 // maximum amount kMaxIndexChars will be placed into the given buffer.
78 void CaptureText(blink::WebLocalFrame
* frame
, base::string16
* contents
);
80 PageInfoReceiver
* context_
;
82 // Used to delay calling CapturePageInfo.
83 base::Timer capture_timer_
;
85 DISALLOW_COPY_AND_ASSIGN(PageInfo
);
88 // This class holds the Chrome specific parts of RenderView, and has the same
90 class ChromeRenderViewObserver
: public content::RenderViewObserver
,
91 public PageInfoReceiver
{
93 // translate_helper can be NULL.
94 ChromeRenderViewObserver(
95 content::RenderView
* render_view
,
96 web_cache::WebCacheRenderProcessObserver
*
97 web_cache_render_process_observer
);
98 ~ChromeRenderViewObserver() override
;
101 // RenderViewObserver implementation.
102 bool OnMessageReceived(const IPC::Message
& message
) override
;
103 void DidStartLoading() override
;
104 void DidStartProvisionalLoad(blink::WebLocalFrame
* frame
) override
;
105 void DidFinishLoad(blink::WebLocalFrame
* frame
) override
;
106 void DidCommitProvisionalLoad(blink::WebLocalFrame
* frame
,
107 bool is_new_navigation
) override
;
108 void Navigate(const GURL
& url
) override
;
110 #if !defined(OS_ANDROID) && !defined(OS_IOS)
111 void OnWebUIJavaScript(const base::string16
& javascript
);
113 #if defined(ENABLE_EXTENSIONS)
114 void OnSetVisuallyDeemphasized(bool deemphasized
);
116 #if defined(OS_ANDROID)
117 void OnUpdateTopControlsState(content::TopControlsState constraints
,
118 content::TopControlsState current
,
121 void OnGetWebApplicationInfo();
122 void OnSetClientSidePhishingDetection(bool enable_phishing_detection
);
123 void OnSetWindowFeatures(const blink::WebWindowFeatures
& window_features
);
125 // Determines if a host is in the strict security host set.
126 bool IsStrictSecurityHost(const std::string
& host
);
128 // Checks if a page contains <meta http-equiv="refresh" ...> tag.
129 bool HasRefreshMetaTag(blink::WebFrame
* frame
);
131 // PageInfoReceiver implementation.
132 void PageCaptured(base::string16
* content
, CaptureType capture_type
) override
;
134 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received.
135 std::vector
<base::string16
> webui_javascript_
;
137 // Owned by ChromeContentRendererClient and outlive us.
138 web_cache::WebCacheRenderProcessObserver
* web_cache_render_process_observer_
;
140 // Have the same lifetime as us.
141 translate::TranslateHelper
* translate_helper_
;
142 safe_browsing::PhishingClassifierDelegate
* phishing_classifier_
;
144 // true if webview is overlayed with grey color.
145 bool webview_visually_deemphasized_
;
149 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver
);
152 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_