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 XWALK_RUNTIME_BROWSER_ANDROID_RENDERER_HOST_XWALK_RENDER_VIEW_HOST_EXT_H_
6 #define XWALK_RUNTIME_BROWSER_ANDROID_RENDERER_HOST_XWALK_RENDER_VIEW_HOST_EXT_H_
11 #include "base/callback_forward.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "xwalk/runtime/common/android/xwalk_hit_test_data.h"
19 struct FrameNavigateParams;
20 struct LoadCommittedDetails;
21 } // namespace content
25 // Provides RenderViewHost wrapper functionality for sending WebView-specific
26 // IPC messages to the renderer and from there to WebKit.
27 class XWalkRenderViewHostExt : public content::WebContentsObserver,
28 public base::NonThreadSafe {
30 // To send receive messages to a RenderView we take the WebContents instance,
31 // as it internally handles RenderViewHost instances changing underneath us.
32 explicit XWalkRenderViewHostExt(content::WebContents* contents);
33 virtual ~XWalkRenderViewHostExt();
35 // |result| will be invoked with the outcome of the request.
36 typedef base::Callback<void(bool)> DocumentHasImagesResult; // NOLINT *
37 void DocumentHasImages(DocumentHasImagesResult result);
39 // Clear all WebCore memory cache (not only for this view).
42 // Do a hit test at the view port coordinates and asynchronously update
43 // |last_hit_test_data_|. |view_x| and |view_y| are in density independent
44 // pixels used by WebKit::WebView.
45 void RequestNewHitTestDataAt(int view_x, int view_y);
47 // Optimization to avoid unnecessary Java object creation on hit test.
48 bool HasNewHitTestData() const;
49 void MarkHitTestDataRead();
51 // Return |last_hit_test_data_|. Note that this is unavoidably racy;
52 // the corresponding public WebView API is as well.
53 const XWalkHitTestData& GetLastHitTestData() const;
55 // Sets the zoom level for text only. Used in layout modes other than
57 void SetTextZoomLevel(double level);
59 void ResetScrollAndScaleState();
61 // Sets the initial page scale. This overrides initial scale set by
62 // the meta viewport tag.
63 void SetInitialPageScale(double page_scale_factor);
64 void SetJsOnlineProperty(bool network_up);
66 // Sets the white list for Cross-Origin access.
67 void SetOriginAccessWhitelist(const std::string& base_url,
68 const std::string& permissions);
71 // content::WebContentsObserver implementation.
72 virtual void RenderViewCreated(
73 content::RenderViewHost* render_view_host) OVERRIDE;
74 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
75 virtual void DidNavigateAnyFrame(
76 const content::LoadCommittedDetails& details,
77 const content::FrameNavigateParams& params) OVERRIDE;
78 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
80 void OnDocumentHasImagesResponse(int msg_id, bool has_images);
81 void OnUpdateHitTestData(const XWalkHitTestData& hit_test_data);
82 void OnPictureUpdated();
84 bool IsRenderViewReady() const;
86 std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_;
88 // Master copy of hit test data on the browser side. This is updated
89 // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
90 // is called in XWalkRenderViewExt.
91 XWalkHitTestData last_hit_test_data_;
93 bool has_new_hit_test_data_;
95 std::string pending_base_url_;
96 std::string pending_match_patterns_;
97 bool is_render_view_created_;
99 DISALLOW_COPY_AND_ASSIGN(XWalkRenderViewHostExt);
104 #endif // XWALK_RUNTIME_BROWSER_ANDROID_RENDERER_HOST_XWALK_RENDER_VIEW_HOST_EXT_H_