OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ |
6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ |
7 | 7 |
8 #include "content/public/browser/web_contents_observer.h" | 8 #include "content/public/browser/web_contents_observer.h" |
9 | 9 |
10 #include "android_webview/common/aw_hit_test_data.h" | 10 #include "android_webview/common/aw_hit_test_data.h" |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
13 | 13 |
14 class GURL; | 14 class GURL; |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 struct FrameNavigateParams; | 17 struct FrameNavigateParams; |
18 struct LoadCommittedDetails; | 18 struct LoadCommittedDetails; |
19 } // namespace content | 19 } // namespace content |
20 | 20 |
21 namespace android_webview { | 21 namespace android_webview { |
22 | 22 |
23 // Provides RenderViewHost wrapper functionality for sending WebView-specific | 23 // Provides RenderViewHost wrapper functionality for sending WebView-specific |
24 // IPC messages to the renderer and from there to WebKit. | 24 // IPC messages to the renderer and from there to WebKit. |
25 class AwRenderViewHostExt : public content::WebContentsObserver, | 25 class AwRenderViewHostExt : public content::WebContentsObserver, |
26 public base::NonThreadSafe { | 26 public base::NonThreadSafe { |
27 public: | 27 public: |
28 class Client { | |
29 public: | |
30 virtual void OnPictureUpdated(int process_id, int render_view_id) = 0; | |
31 | |
32 protected: | |
33 virtual ~Client() {} | |
34 }; | |
35 | |
36 // To send receive messages to a RenderView we take the WebContents instance, | 28 // To send receive messages to a RenderView we take the WebContents instance, |
37 // as it internally handles RenderViewHost instances changing underneath us. | 29 // as it internally handles RenderViewHost instances changing underneath us. |
38 AwRenderViewHostExt(content::WebContents* contents, Client* client); | 30 AwRenderViewHostExt(content::WebContents* contents); |
39 virtual ~AwRenderViewHostExt(); | 31 virtual ~AwRenderViewHostExt(); |
40 | 32 |
41 // |result| will be invoked with the outcome of the request. | 33 // |result| will be invoked with the outcome of the request. |
42 typedef base::Callback<void(bool)> DocumentHasImagesResult; | 34 typedef base::Callback<void(bool)> DocumentHasImagesResult; |
43 void DocumentHasImages(DocumentHasImagesResult result); | 35 void DocumentHasImages(DocumentHasImagesResult result); |
44 | 36 |
45 // Clear all WebCore memory cache (not only for this view). | 37 // Clear all WebCore memory cache (not only for this view). |
46 void ClearCache(); | 38 void ClearCache(); |
47 | 39 |
48 // Do a hit test at the view port coordinates and asynchronously update | 40 // Do a hit test at the view port coordinates and asynchronously update |
49 // |last_hit_test_data_|. |view_x| and |view_y| are in density independent | 41 // |last_hit_test_data_|. |view_x| and |view_y| are in density independent |
50 // pixels used by WebKit::WebView. | 42 // pixels used by WebKit::WebView. |
51 void RequestNewHitTestDataAt(int view_x, int view_y); | 43 void RequestNewHitTestDataAt(int view_x, int view_y); |
52 | 44 |
53 // Optimization to avoid unnecessary Java object creation on hit test. | 45 // Optimization to avoid unnecessary Java object creation on hit test. |
54 bool HasNewHitTestData() const; | 46 bool HasNewHitTestData() const; |
55 void MarkHitTestDataRead(); | 47 void MarkHitTestDataRead(); |
56 | 48 |
57 // Return |last_hit_test_data_|. Note that this is unavoidably racy; | 49 // Return |last_hit_test_data_|. Note that this is unavoidably racy; |
58 // the corresponding public WebView API is as well. | 50 // the corresponding public WebView API is as well. |
59 const AwHitTestData& GetLastHitTestData() const; | 51 const AwHitTestData& GetLastHitTestData() const; |
60 | 52 |
61 // Enables updating picture piles on every new frame. | |
62 // OnPictureUpdated is called when a new picture is available, | |
63 // stored by renderer id in RendererPictureMap. | |
64 void EnableCapturePictureCallback(bool enabled); | |
65 | |
66 // Captures the latest available picture pile synchronously. | |
67 void CapturePictureSync(); | |
68 | |
69 private: | 53 private: |
70 // content::WebContentsObserver implementation. | 54 // content::WebContentsObserver implementation. |
71 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 55 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
72 virtual void DidNavigateAnyFrame( | 56 virtual void DidNavigateAnyFrame( |
73 const content::LoadCommittedDetails& details, | 57 const content::LoadCommittedDetails& details, |
74 const content::FrameNavigateParams& params) OVERRIDE; | 58 const content::FrameNavigateParams& params) OVERRIDE; |
75 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 59 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
76 | 60 |
77 void OnDocumentHasImagesResponse(int msg_id, bool has_images); | 61 void OnDocumentHasImagesResponse(int msg_id, bool has_images); |
78 void OnUpdateHitTestData(const AwHitTestData& hit_test_data); | 62 void OnUpdateHitTestData(const AwHitTestData& hit_test_data); |
79 void OnPictureUpdated(); | 63 void OnPictureUpdated(); |
80 | 64 |
81 bool IsRenderViewReady() const; | 65 bool IsRenderViewReady() const; |
82 | 66 |
83 std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_; | 67 std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_; |
84 | 68 |
85 // Master copy of hit test data on the browser side. This is updated | 69 // Master copy of hit test data on the browser side. This is updated |
86 // as a result of DoHitTest called explicitly or when the FocusedNodeChanged | 70 // as a result of DoHitTest called explicitly or when the FocusedNodeChanged |
87 // is called in AwRenderViewExt. | 71 // is called in AwRenderViewExt. |
88 AwHitTestData last_hit_test_data_; | 72 AwHitTestData last_hit_test_data_; |
89 | 73 |
90 bool has_new_hit_test_data_; | 74 bool has_new_hit_test_data_; |
91 | 75 |
92 Client* client_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt); | 76 DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt); |
95 }; | 77 }; |
96 | 78 |
97 } // namespace android_webview | 79 } // namespace android_webview |
98 | 80 |
99 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ | 81 #endif // ANDROID_WEBVIEW_BROWSER_RENDER_HOST_RENDER_VIEW_HOST_EXT_H_ |
OLD | NEW |