aw_render_view_host_ext.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #ifndef ANDROID_WEBVIEW_BROWSER_RENDERER_HOST_AW_RENDER_VIEW_HOST_EXT_H_
  5. #define ANDROID_WEBVIEW_BROWSER_RENDERER_HOST_AW_RENDER_VIEW_HOST_EXT_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "content/public/browser/web_contents_observer.h"
  8. #include "android_webview/common/mojom/frame.mojom.h"
  9. #include "base/callback_forward.h"
  10. #include "content/public/browser/global_routing_id.h"
  11. #include "content/public/browser/render_frame_host_receiver_set.h"
  12. #include "mojo/public/cpp/bindings/associated_remote.h"
  13. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  14. #include "third_party/skia/include/core/SkColor.h"
  15. #include "ui/gfx/geometry/point_f.h"
  16. #include "ui/gfx/geometry/size.h"
  17. #include "ui/gfx/geometry/size_f.h"
  18. namespace android_webview {
  19. class AwRenderViewHostExtClient {
  20. public:
  21. // Called when the RenderView page scale changes.
  22. virtual void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) = 0;
  23. virtual void OnWebLayoutContentsSizeChanged(
  24. const gfx::Size& contents_size) = 0;
  25. protected:
  26. virtual ~AwRenderViewHostExtClient() {}
  27. };
  28. // Provides RenderViewHost wrapper functionality for sending WebView-specific
  29. // IPC messages to the renderer and from there to WebKit.
  30. class AwRenderViewHostExt : public content::WebContentsObserver,
  31. mojom::FrameHost {
  32. public:
  33. // Binds the Mojo receiver for the FrameHost endpoint to the
  34. // AwRenderViewHostExt associated with the RenderFrameHost.
  35. static void BindFrameHost(
  36. mojo::PendingAssociatedReceiver<mojom::FrameHost> receiver,
  37. content::RenderFrameHost* rfh);
  38. // To send receive messages to a RenderView we take the WebContents instance,
  39. // as it internally handles RenderViewHost instances changing underneath us.
  40. AwRenderViewHostExt(
  41. AwRenderViewHostExtClient* client, content::WebContents* contents);
  42. AwRenderViewHostExt(const AwRenderViewHostExt&) = delete;
  43. AwRenderViewHostExt& operator=(const AwRenderViewHostExt&) = delete;
  44. ~AwRenderViewHostExt() override;
  45. // |result| will be invoked with the outcome of the request.
  46. using DocumentHasImagesResult = base::OnceCallback<void(bool)>;
  47. void DocumentHasImages(DocumentHasImagesResult result);
  48. // Do a hit test at the view port coordinates and asynchronously update
  49. // |last_hit_test_data_|. Width and height in |touch_area| are in density
  50. // independent pixels used by blink::WebView.
  51. void RequestNewHitTestDataAt(const gfx::PointF& touch_center,
  52. const gfx::SizeF& touch_area);
  53. // Return |last_hit_test_data_|. Note that this is unavoidably racy;
  54. // the corresponding public WebView API is as well.
  55. mojom::HitTestDataPtr TakeLastHitTestData();
  56. // Sets the zoom factor for text only. Used in layout modes other than
  57. // Text Autosizing.
  58. void SetTextZoomFactor(float factor);
  59. void ResetScrollAndScaleState();
  60. // Sets the initial page scale. This overrides initial scale set by
  61. // the meta viewport tag.
  62. void SetInitialPageScale(double page_scale_factor);
  63. void SetWillSuppressErrorPage(bool suppress);
  64. void SmoothScroll(int target_x, int target_y, base::TimeDelta duration);
  65. private:
  66. // content::WebContentsObserver implementation.
  67. void DidStartNavigation(
  68. content::NavigationHandle* navigation_handle) override;
  69. void DidFinishNavigation(
  70. content::NavigationHandle* navigation_handle) override;
  71. void OnPageScaleFactorChanged(float page_scale_factor) override;
  72. // mojom::FrameHost overrides:
  73. void UpdateHitTestData(
  74. android_webview::mojom::HitTestDataPtr hit_test_data) override;
  75. void ContentsSizeChanged(const gfx::Size& contents_size) override;
  76. void ShouldOverrideUrlLoading(
  77. const std::u16string& url,
  78. bool has_user_gesture,
  79. bool is_redirect,
  80. bool is_main_frame,
  81. ShouldOverrideUrlLoadingCallback callback) override;
  82. mojom::LocalMainFrame* GetLocalMainFrameRemote();
  83. raw_ptr<AwRenderViewHostExtClient> client_;
  84. // Authoritative copy of hit test data on the browser side. This is updated
  85. // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
  86. // is called in AwRenderViewExt.
  87. android_webview::mojom::HitTestDataPtr last_hit_test_data_;
  88. // Some WebView users might want to show their own error pages / logic.
  89. bool will_suppress_error_page_ = false;
  90. content::GlobalRenderFrameHostId main_frame_global_id_;
  91. content::RenderFrameHostReceiverSet<mojom::FrameHost> frame_host_receivers_;
  92. // Associated channel to the webview LocalMainFrame extensions.
  93. mojo::AssociatedRemote<mojom::LocalMainFrame> local_main_frame_remote_;
  94. };
  95. } // namespace android_webview
  96. #endif // ANDROID_WEBVIEW_BROWSER_RENDERER_HOST_AW_RENDER_VIEW_HOST_EXT_H_