Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / renderer / chrome_render_view_observer.h
blob048cdd5f395f6de056244703c1e7237a2562dc62
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_
8 #include <set>
9 #include <string>
10 #include <vector>
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"
19 #include "url/gurl.h"
21 class ContentSettingsObserver;
22 class SkBitmap;
24 namespace blink {
25 class WebView;
26 struct WebWindowFeatures;
29 namespace content {
30 class RenderFrame;
33 namespace safe_browsing {
34 class PhishingClassifierDelegate;
37 namespace translate {
38 class TranslateHelper;
41 namespace web_cache {
42 class WebCacheRenderProcessObserver;
45 // Receives page information that was captured by PageInfo instance.
46 class PageInfoReceiver {
47 public:
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.
56 class PageInfo {
57 public:
58 using CaptureType = PageInfoReceiver::CaptureType;
60 explicit PageInfo(PageInfoReceiver* context);
61 ~PageInfo() {}
63 void CapturePageInfoLater(CaptureType capture_type,
64 content::RenderFrame* render_frame,
65 base::TimeDelta delay);
67 private:
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
86 // lifetime.
87 class ChromeRenderViewObserver : public content::RenderViewObserver,
88 public PageInfoReceiver {
89 public:
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;
97 private:
98 // RenderViewObserver implementation.
99 bool OnMessageReceived(const IPC::Message& message) override;
100 void DidStartLoading() override;
101 void DidStopLoading() override;
102 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame,
103 bool is_new_navigation) override;
104 void Navigate(const GURL& url) override;
106 #if !defined(OS_ANDROID) && !defined(OS_IOS)
107 void OnWebUIJavaScript(const base::string16& javascript);
108 #endif
109 #if defined(ENABLE_EXTENSIONS)
110 void OnSetVisuallyDeemphasized(bool deemphasized);
111 #endif
112 #if defined(OS_ANDROID)
113 void OnUpdateTopControlsState(content::TopControlsState constraints,
114 content::TopControlsState current,
115 bool animate);
116 #endif
117 void OnGetWebApplicationInfo();
118 void OnSetClientSidePhishingDetection(bool enable_phishing_detection);
119 void OnSetWindowFeatures(const blink::WebWindowFeatures& window_features);
121 // Determines if a host is in the strict security host set.
122 bool IsStrictSecurityHost(const std::string& host);
124 // Checks if a page contains <meta http-equiv="refresh" ...> tag.
125 bool HasRefreshMetaTag(blink::WebFrame* frame);
127 // PageInfoReceiver implementation.
128 void PageCaptured(base::string16* content, CaptureType capture_type) override;
130 // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received.
131 std::vector<base::string16> webui_javascript_;
133 // Owned by ChromeContentRendererClient and outlive us.
134 web_cache::WebCacheRenderProcessObserver* web_cache_render_process_observer_;
136 // Have the same lifetime as us.
137 translate::TranslateHelper* translate_helper_;
138 safe_browsing::PhishingClassifierDelegate* phishing_classifier_;
140 // true if webview is overlayed with grey color.
141 bool webview_visually_deemphasized_;
143 PageInfo page_info_;
145 DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver);
148 #endif // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_