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 // Captures the thumbnail and text contents for indexing for the given load
69 // ID. Kicks off analysis of the captured text.
70 void CapturePageInfo(content::RenderFrame
* render_frame
,
71 CaptureType capture_type
);
73 // Retrieves the text from the given frame contents, the page text up to the
74 // maximum amount kMaxIndexChars will be placed into the given buffer.
75 void CaptureText(blink::WebLocalFrame
* frame
, base::string16
* contents
);
77 PageInfoReceiver
* context_
;
79 // Used to delay calling CapturePageInfo.
80 base::Timer capture_timer_
;
82 DISALLOW_COPY_AND_ASSIGN(PageInfo
);
85 // This class holds the Chrome specific parts of RenderView, and has the same
87 class ChromeRenderViewObserver
: public content::RenderViewObserver
,
88 public PageInfoReceiver
{
90 // translate_helper can be NULL.
91 ChromeRenderViewObserver(
92 content::RenderView
* render_view
,
93 web_cache::WebCacheRenderProcessObserver
*
94 web_cache_render_process_observer
);
95 ~ChromeRenderViewObserver() override
;
98 // RenderViewObserver implementation.
99 bool OnMessageReceived(const IPC::Message
& message
) override
;
100 void DidStartLoading() override
;
101 void DidStopLoading() override
;
102 void DidStartProvisionalLoad(blink::WebLocalFrame
* frame
) override
;
103 void DidCommitProvisionalLoad(blink::WebLocalFrame
* frame
,
104 bool is_new_navigation
) override
;
105 void Navigate(const GURL
& url
) override
;
107 #if !defined(OS_ANDROID) && !defined(OS_IOS)
108 void OnWebUIJavaScript(const base::string16
& javascript
);
110 #if defined(ENABLE_EXTENSIONS)
111 void OnSetVisuallyDeemphasized(bool deemphasized
);
113 #if defined(OS_ANDROID)
114 void OnUpdateTopControlsState(content::TopControlsState constraints
,
115 content::TopControlsState current
,
118 void OnGetWebApplicationInfo();
119 void OnSetClientSidePhishingDetection(bool enable_phishing_detection
);
120 void OnSetWindowFeatures(const blink::WebWindowFeatures
& window_features
);
122 // Determines if a host is in the strict security host set.
123 bool IsStrictSecurityHost(const std::string
& host
);
125 // Checks if a page contains <meta http-equiv="refresh" ...> tag.
126 bool HasRefreshMetaTag(blink::WebFrame
* frame
);
128 // PageInfoReceiver implementation.
129 void PageCaptured(base::string16
* content
, CaptureType capture_type
) override
;
131 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received.
132 std::vector
<base::string16
> webui_javascript_
;
134 // Owned by ChromeContentRendererClient and outlive us.
135 web_cache::WebCacheRenderProcessObserver
* web_cache_render_process_observer_
;
137 // Have the same lifetime as us.
138 translate::TranslateHelper
* translate_helper_
;
139 safe_browsing::PhishingClassifierDelegate
* phishing_classifier_
;
141 // true if webview is overlayed with grey color.
142 bool webview_visually_deemphasized_
;
146 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver
);
149 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_