• 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 ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_
6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_
7 
8 #include "content/public/browser/web_contents_observer.h"
9 
10 #include "android_webview/common/aw_hit_test_data.h"
11 #include "base/callback_forward.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "third_party/skia/include/core/SkColor.h"
14 #include "ui/gfx/size.h"
15 
16 class GURL;
17 
18 namespace content {
19 struct FrameNavigateParams;
20 struct LoadCommittedDetails;
21 }  // namespace content
22 
23 namespace android_webview {
24 
25 class AwRenderViewHostExtClient {
26  public:
27   // Called when the RenderView page scale changes.
28   virtual void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) = 0;
29   virtual void OnWebLayoutContentsSizeChanged(
30       const gfx::Size& contents_size) = 0;
31 
32  protected:
~AwRenderViewHostExtClient()33   virtual ~AwRenderViewHostExtClient() {}
34 };
35 
36 // Provides RenderViewHost wrapper functionality for sending WebView-specific
37 // IPC messages to the renderer and from there to WebKit.
38 class AwRenderViewHostExt : public content::WebContentsObserver,
39                             public base::NonThreadSafe {
40  public:
41 
42   // To send receive messages to a RenderView we take the WebContents instance,
43   // as it internally handles RenderViewHost instances changing underneath us.
44   AwRenderViewHostExt(
45       AwRenderViewHostExtClient* client, content::WebContents* contents);
46   virtual ~AwRenderViewHostExt();
47 
48   // |result| will be invoked with the outcome of the request.
49   typedef base::Callback<void(bool)> DocumentHasImagesResult;
50   void DocumentHasImages(DocumentHasImagesResult result);
51 
52   // Clear all WebCore memory cache (not only for this view).
53   void ClearCache();
54 
55   // Do a hit test at the view port coordinates and asynchronously update
56   // |last_hit_test_data_|. |view_x| and |view_y| are in density independent
57   // pixels used by blink::WebView.
58   void RequestNewHitTestDataAt(int view_x, int view_y);
59 
60   // Optimization to avoid unnecessary Java object creation on hit test.
61   bool HasNewHitTestData() const;
62   void MarkHitTestDataRead();
63 
64   // Return |last_hit_test_data_|. Note that this is unavoidably racy;
65   // the corresponding public WebView API is as well.
66   const AwHitTestData& GetLastHitTestData() const;
67 
68   // Sets the zoom factor for text only. Used in layout modes other than
69   // Text Autosizing.
70   void SetTextZoomFactor(float factor);
71 
72   void ResetScrollAndScaleState();
73 
74   // Sets the initial page scale. This overrides initial scale set by
75   // the meta viewport tag.
76   void SetInitialPageScale(double page_scale_factor);
77   void SetBackgroundColor(SkColor c);
78   void SetJsOnlineProperty(bool network_up);
79 
80  private:
81   // content::WebContentsObserver implementation.
82   virtual void RenderViewCreated(content::RenderViewHost* view_host) OVERRIDE;
83   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
84   virtual void DidNavigateAnyFrame(
85       const content::LoadCommittedDetails& details,
86       const content::FrameNavigateParams& params) OVERRIDE;
87   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
88 
89   void OnDocumentHasImagesResponse(int msg_id, bool has_images);
90   void OnUpdateHitTestData(const AwHitTestData& hit_test_data);
91   void OnPageScaleFactorChanged(float page_scale_factor);
92   void OnContentsSizeChanged(const gfx::Size& contents_size);
93 
94   bool IsRenderViewReady() const;
95 
96   AwRenderViewHostExtClient* client_;
97 
98   SkColor background_color_;
99 
100   std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_;
101 
102   // Master copy of hit test data on the browser side. This is updated
103   // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
104   // is called in AwRenderViewExt.
105   AwHitTestData last_hit_test_data_;
106 
107   bool has_new_hit_test_data_;
108 
109   DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt);
110 };
111 
112 }  // namespace android_webview
113 
114 #endif  // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_
115