73be9a6d34b1c64f1822b80d967b9639d8bd35dd
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / renderer_host / xwalk_render_view_host_ext.h
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 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_
7
8 #include <map>
9 #include <string>
10
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"
15
16 class GURL;
17
18 namespace content {
19 struct FrameNavigateParams;
20 struct LoadCommittedDetails;
21 }  // namespace content
22
23 namespace xwalk {
24
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 {
29  public:
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();
34
35   // |result| will be invoked with the outcome of the request.
36   typedef base::Callback<void(bool)> DocumentHasImagesResult; // NOLINT *
37   void DocumentHasImages(DocumentHasImagesResult result);
38
39   // Clear all WebCore memory cache (not only for this view).
40   void ClearCache();
41
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);
46
47   // Optimization to avoid unnecessary Java object creation on hit test.
48   bool HasNewHitTestData() const;
49   void MarkHitTestDataRead();
50
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;
54
55   // Sets the zoom level for text only. Used in layout modes other than
56   // Text Autosizing.
57   void SetTextZoomLevel(double level);
58
59   void ResetScrollAndScaleState();
60
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);
65
66   // Sets the white list for Cross-Origin access.
67   void SetOriginAccessWhitelist(const std::string& base_url,
68                                 const std::string& permissions);
69
70  private:
71   // content::WebContentsObserver implementation.
72   virtual void RenderViewCreated(
73       content::RenderViewHost* render_view_host) OVERRIDE;
74   virtual void RenderProcessGone(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;
79
80   void OnDocumentHasImagesResponse(int msg_id, bool has_images);
81   void OnUpdateHitTestData(const XWalkHitTestData& hit_test_data);
82   void OnPictureUpdated();
83   void OnPageScaleFactorChanged(float page_scale_factor);
84
85   bool IsRenderViewReady() const;
86
87   std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_;
88
89   // Master copy of hit test data on the browser side. This is updated
90   // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
91   // is called in XWalkRenderViewExt.
92   XWalkHitTestData last_hit_test_data_;
93
94   bool has_new_hit_test_data_;
95
96   std::string pending_base_url_;
97   std::string pending_match_patterns_;
98   bool is_render_view_created_;
99
100   DISALLOW_COPY_AND_ASSIGN(XWalkRenderViewHostExt);
101 };
102
103 }  // namespace xwalk
104
105 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_RENDERER_HOST_XWALK_RENDER_VIEW_HOST_EXT_H_