Home | History | Annotate | Download | only in renderer
      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 ExternalHostBindings;
     24 class SkBitmap;
     25 class TranslateHelper;
     26 class WebViewColorOverlay;
     27 class WebViewAnimatingOverlay;
     28 
     29 namespace blink {
     30 class WebView;
     31 struct WebWindowFeatures;
     32 }
     33 
     34 namespace safe_browsing {
     35 class PhishingClassifierDelegate;
     36 }
     37 
     38 // This class holds the Chrome specific parts of RenderView, and has the same
     39 // lifetime.
     40 class ChromeRenderViewObserver : public content::RenderViewObserver {
     41  public:
     42   // translate_helper can be NULL.
     43   ChromeRenderViewObserver(
     44       content::RenderView* render_view,
     45       ChromeRenderProcessObserver* chrome_render_process_observer);
     46   virtual ~ChromeRenderViewObserver();
     47 
     48  private:
     49   // Holds the information received in OnWebUIJavaScript for later use
     50   // to call EvaluateScript() to preload javascript for WebUI tests.
     51   struct WebUIJavaScript {
     52     base::string16 frame_xpath;
     53     base::string16 jscript;
     54     int id;
     55     bool notify_result;
     56   };
     57 
     58   // RenderViewObserver implementation.
     59   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     60   virtual void DidStartLoading() OVERRIDE;
     61   virtual void DidStopLoading() OVERRIDE;
     62   virtual void DidCommitProvisionalLoad(blink::WebFrame* frame,
     63                                         bool is_new_navigation) OVERRIDE;
     64   virtual void DidClearWindowObject(blink::WebFrame* frame) OVERRIDE;
     65   virtual void DetailedConsoleMessageAdded(const base::string16& message,
     66                                            const base::string16& source,
     67                                            const base::string16& stack_trace,
     68                                            int32 line_number,
     69                                            int32 severity_level) OVERRIDE;
     70   virtual void Navigate(const GURL& url) OVERRIDE;
     71 
     72   void OnWebUIJavaScript(const base::string16& frame_xpath,
     73                          const base::string16& jscript,
     74                          int id,
     75                          bool notify_result);
     76   void OnHandleMessageFromExternalHost(const std::string& message,
     77                                        const std::string& origin,
     78                                        const std::string& target);
     79   void OnJavaScriptStressTestControl(int cmd, int param);
     80   void OnSetClientSidePhishingDetection(bool enable_phishing_detection);
     81   void OnSetVisuallyDeemphasized(bool deemphasized);
     82   void OnRequestThumbnailForContextNode(int thumbnail_min_area_pixels,
     83                                         gfx::Size thumbnail_max_size_pixels);
     84   void OnGetFPS();
     85 #if defined(OS_ANDROID)
     86   void OnUpdateTopControlsState(content::TopControlsState constraints,
     87                                 content::TopControlsState current,
     88                                 bool animate);
     89   void OnRetrieveWebappInformation(const GURL& expected_url);
     90 #endif
     91   void OnSetWindowFeatures(const blink::WebWindowFeatures& window_features);
     92 
     93   void CapturePageInfoLater(int page_id,
     94                             bool preliminary_capture,
     95                             base::TimeDelta delay);
     96 
     97   // Captures the thumbnail and text contents for indexing for the given load
     98   // ID.  Kicks off analysis of the captured text.
     99   void CapturePageInfo(int page_id, bool preliminary_capture);
    100 
    101   // Retrieves the text from the given frame contents, the page text up to the
    102   // maximum amount kMaxIndexChars will be placed into the given buffer.
    103   void CaptureText(blink::WebFrame* frame, base::string16* contents);
    104 
    105   ExternalHostBindings* GetExternalHostBindings();
    106 
    107   // Determines if a host is in the strict security host set.
    108   bool IsStrictSecurityHost(const std::string& host);
    109 
    110   // Checks if a page contains <meta http-equiv="refresh" ...> tag.
    111   bool HasRefreshMetaTag(blink::WebFrame* frame);
    112 
    113   // Save the JavaScript to preload if a ViewMsg_WebUIJavaScript is received.
    114   scoped_ptr<WebUIJavaScript> webui_javascript_;
    115 
    116   // Owned by ChromeContentRendererClient and outlive us.
    117   ChromeRenderProcessObserver* chrome_render_process_observer_;
    118 
    119   // Have the same lifetime as us.
    120   TranslateHelper* translate_helper_;
    121   safe_browsing::PhishingClassifierDelegate* phishing_classifier_;
    122 
    123   // Page_id from the last page we indexed. This prevents us from indexing the
    124   // same page twice in a row.
    125   int32 last_indexed_page_id_;
    126   // The toplevel URL that was last indexed.  This is used together with the
    127   // page id to decide whether to reindex in certain cases like history
    128   // replacement.
    129   GURL last_indexed_url_;
    130 
    131   // External host exposed through automation controller.
    132   scoped_ptr<ExternalHostBindings> external_host_bindings_;
    133 
    134   // A color page overlay when visually de-emaphasized.
    135   scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_;
    136 
    137   // Used to delay calling CapturePageInfo.
    138   base::Timer capture_timer_;
    139 
    140   DISALLOW_COPY_AND_ASSIGN(ChromeRenderViewObserver);
    141 };
    142 
    143 #endif  // CHROME_RENDERER_CHROME_RENDER_VIEW_OBSERVER_H_
    144