Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / android_webview / browser / renderer_host / aw_render_view_host_ext.h
blobb3fcfbc02c2ec12c16315f69eae12b3f02602008
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 ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_
6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_
8 #include "content/public/browser/web_contents_observer.h"
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/geometry/point_f.h"
15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/geometry/size_f.h"
18 class GURL;
20 namespace content {
21 struct FrameNavigateParams;
22 struct LoadCommittedDetails;
23 } // namespace content
25 namespace android_webview {
27 class AwRenderViewHostExtClient {
28 public:
29 // Called when the RenderView page scale changes.
30 virtual void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) = 0;
31 virtual void OnWebLayoutContentsSizeChanged(
32 const gfx::Size& contents_size) = 0;
34 protected:
35 virtual ~AwRenderViewHostExtClient() {}
38 // Provides RenderViewHost wrapper functionality for sending WebView-specific
39 // IPC messages to the renderer and from there to WebKit.
40 class AwRenderViewHostExt : public content::WebContentsObserver,
41 public base::NonThreadSafe {
42 public:
44 // To send receive messages to a RenderView we take the WebContents instance,
45 // as it internally handles RenderViewHost instances changing underneath us.
46 AwRenderViewHostExt(
47 AwRenderViewHostExtClient* client, content::WebContents* contents);
48 ~AwRenderViewHostExt() override;
50 // |result| will be invoked with the outcome of the request.
51 typedef base::Callback<void(bool)> DocumentHasImagesResult;
52 void DocumentHasImages(DocumentHasImagesResult result);
54 // Clear all WebCore memory cache (not only for this view).
55 void ClearCache();
57 // Do a hit test at the view port coordinates and asynchronously update
58 // |last_hit_test_data_|. Width and height in |touch_area| are in density
59 // independent pixels used by blink::WebView.
60 void RequestNewHitTestDataAt(const gfx::PointF& touch_center,
61 const gfx::SizeF& touch_area);
63 // Optimization to avoid unnecessary Java object creation on hit test.
64 bool HasNewHitTestData() const;
65 void MarkHitTestDataRead();
67 // Return |last_hit_test_data_|. Note that this is unavoidably racy;
68 // the corresponding public WebView API is as well.
69 const AwHitTestData& GetLastHitTestData() const;
71 // Sets the zoom factor for text only. Used in layout modes other than
72 // Text Autosizing.
73 void SetTextZoomFactor(float factor);
75 void ResetScrollAndScaleState();
77 // Sets the initial page scale. This overrides initial scale set by
78 // the meta viewport tag.
79 void SetInitialPageScale(double page_scale_factor);
80 void SetBackgroundColor(SkColor c);
81 void SetJsOnlineProperty(bool network_up);
83 void SmoothScroll(int target_x, int target_y, long duration_ms);
85 private:
86 // content::WebContentsObserver implementation.
87 void RenderViewCreated(content::RenderViewHost* view_host) override;
88 void RenderProcessGone(base::TerminationStatus status) override;
89 void DidNavigateAnyFrame(content::RenderFrameHost* render_frame_host,
90 const content::LoadCommittedDetails& details,
91 const content::FrameNavigateParams& params) override;
92 bool OnMessageReceived(const IPC::Message& message) override;
94 void OnDocumentHasImagesResponse(int msg_id, bool has_images);
95 void OnUpdateHitTestData(const AwHitTestData& hit_test_data);
96 void OnPageScaleFactorChanged(float page_scale_factor);
97 void OnContentsSizeChanged(const gfx::Size& contents_size);
99 bool IsRenderViewReady() const;
101 AwRenderViewHostExtClient* client_;
103 SkColor background_color_;
105 std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_;
107 // Master copy of hit test data on the browser side. This is updated
108 // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
109 // is called in AwRenderViewExt.
110 AwHitTestData last_hit_test_data_;
112 bool has_new_hit_test_data_;
114 DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt);
117 } // namespace android_webview
119 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_