Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / android_webview / browser / renderer_host / aw_render_view_host_ext.h
blob773e504a6a24d85232ac60771320f6f1e49a76bf
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/size.h"
16 class GURL;
18 namespace content {
19 struct FrameNavigateParams;
20 struct LoadCommittedDetails;
21 } // namespace content
23 namespace android_webview {
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;
32 protected:
33 virtual ~AwRenderViewHostExtClient() {}
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:
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();
48 // |result| will be invoked with the outcome of the request.
49 typedef base::Callback<void(bool)> DocumentHasImagesResult;
50 void DocumentHasImages(DocumentHasImagesResult result);
52 // Clear all WebCore memory cache (not only for this view).
53 void ClearCache();
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);
60 // Optimization to avoid unnecessary Java object creation on hit test.
61 bool HasNewHitTestData() const;
62 void MarkHitTestDataRead();
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;
68 // Sets the zoom factor for text only. Used in layout modes other than
69 // Text Autosizing.
70 void SetTextZoomFactor(float factor);
72 void ResetScrollAndScaleState();
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);
80 void SendCheckRenderThreadResponsiveness();
82 private:
83 // content::WebContentsObserver implementation.
84 virtual void RenderViewCreated(content::RenderViewHost* view_host) OVERRIDE;
85 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
86 virtual void DidNavigateAnyFrame(
87 const content::LoadCommittedDetails& details,
88 const content::FrameNavigateParams& params) OVERRIDE;
89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
91 void OnDocumentHasImagesResponse(int msg_id, bool has_images);
92 void OnUpdateHitTestData(const AwHitTestData& hit_test_data);
93 void OnPageScaleFactorChanged(float page_scale_factor);
94 void OnContentsSizeChanged(const gfx::Size& contents_size);
96 bool IsRenderViewReady() const;
98 AwRenderViewHostExtClient* client_;
100 SkColor background_color_;
102 std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_;
104 // Master copy of hit test data on the browser side. This is updated
105 // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
106 // is called in AwRenderViewExt.
107 AwHitTestData last_hit_test_data_;
109 bool has_new_hit_test_data_;
111 DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt);
114 } // namespace android_webview
116 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_