Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 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 CONTENT_BROWSER_ANDROID_DIALOG_OVERLAY_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_ANDROID_DIALOG_OVERLAY_IMPL_H_ |
| 7 | |
| 8 | #include "base/android/jni_android.h" |
| 9 | #include "base/android/jni_weak_ref.h" |
| 10 | #include "base/android/scoped_java_ref.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 11 | #include "base/memory/raw_ptr.h" |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 12 | #include "base/unguessable_token.h" |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 13 | #include "content/public/browser/web_contents_observer.h" |
Jinsuk Kim | d5d29a2 | 2017-08-29 01:39:44 | [diff] [blame] | 14 | #include "ui/android/view_android_observer.h" |
Andrei Pascovici | b478402 | 2018-09-06 14:41:22 | [diff] [blame] | 15 | #include "ui/android/window_android.h" |
| 16 | #include "ui/android/window_android_observer.h" |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 17 | |
| 18 | namespace content { |
| 19 | |
David Sanders | 73ebb80c | 2022-04-19 00:53:12 | [diff] [blame] | 20 | class RenderFrameHost; |
| 21 | class RenderFrameHostImpl; |
| 22 | |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 23 | // Native counterpart to DialogOverlayImpl java class. This is created by the |
Jinsuk Kim | d665cf2 | 2018-07-25 23:20:10 | [diff] [blame] | 24 | // java side. When the WebContents for the provided token is attached or |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 25 | // detached from a WindowAndroid, we get the Android window token and notify the |
| 26 | // java side. |
Jinsuk Kim | d5d29a2 | 2017-08-29 01:39:44 | [diff] [blame] | 27 | class DialogOverlayImpl : public ui::ViewAndroidObserver, |
Andrei Pascovici | b478402 | 2018-09-06 14:41:22 | [diff] [blame] | 28 | public ui::WindowAndroidObserver, |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 29 | public WebContentsObserver { |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 30 | public: |
[email protected] | 251fe52 | 2017-07-11 00:54:06 | [diff] [blame] | 31 | // This may not call back into |obj| directly, but must post. This is because |
| 32 | // |obj| is still being initialized. |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 33 | DialogOverlayImpl(const base::android::JavaParamRef<jobject>& obj, |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 34 | RenderFrameHostImpl* rfhi, |
[email protected] | e62e7ebf | 2017-09-21 17:14:41 | [diff] [blame] | 35 | WebContents* web_contents, |
Richard Knoll | ba18275 | 2021-06-01 10:49:55 | [diff] [blame] | 36 | bool power_efficient, |
| 37 | bool observe_container_view); |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 38 | ~DialogOverlayImpl() override; |
| 39 | |
[email protected] | 251fe52 | 2017-07-11 00:54:06 | [diff] [blame] | 40 | // Called when the java side is ready for token / dismissed callbacks. May |
| 41 | // call back before returning. Must guarantee that a token is eventually sent |
| 42 | // if we have one. |
Andrew Grieve | ab2c915 | 2025-07-02 19:53:13 | [diff] [blame] | 43 | void CompleteInit(JNIEnv* env); |
[email protected] | 251fe52 | 2017-07-11 00:54:06 | [diff] [blame] | 44 | |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 45 | // Clean up and post to delete |this| later. |
Andrew Grieve | ab2c915 | 2025-07-02 19:53:13 | [diff] [blame] | 46 | void Destroy(JNIEnv* env); |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 47 | |
[email protected] | d6c1792 | 2017-06-26 18:48:06 | [diff] [blame] | 48 | // Calls ReceiveCompositorOffset() (java) with the compositor screen offset |
| 49 | // before returning, in physical pixels. We send |rect| as a convenience. |
| 50 | void GetCompositorOffset(JNIEnv* env, |
[email protected] | d6c1792 | 2017-06-26 18:48:06 | [diff] [blame] | 51 | const base::android::JavaParamRef<jobject>& rect); |
| 52 | |
Jinsuk Kim | d5d29a2 | 2017-08-29 01:39:44 | [diff] [blame] | 53 | // ui::ViewAndroidObserver |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 54 | void OnAttachedToWindow() override; |
| 55 | void OnDetachedFromWindow() override; |
| 56 | |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 57 | // WebContentsObserver |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 58 | void OnVisibilityChanged(content::Visibility visibility) override; |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 59 | void WebContentsDestroyed() override; |
Muyao Xu | db226be5 | 2023-12-01 04:23:09 | [diff] [blame] | 60 | void DidToggleFullscreenModeForTab(bool entered_fullscreen, |
| 61 | bool will_cause_resize) override; |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 62 | void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 63 | void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 64 | RenderFrameHost* new_host) override; |
| 65 | |
Andrei Pascovici | b478402 | 2018-09-06 14:41:22 | [diff] [blame] | 66 | // Unregister callbacks if previously registered. |
| 67 | void UnregisterCallbacksIfNeeded(); |
| 68 | |
| 69 | // WindowAndroidObserver |
| 70 | void OnRootWindowVisibilityChanged(bool visible) override; |
Andrei Pascovici | b478402 | 2018-09-06 14:41:22 | [diff] [blame] | 71 | void OnAttachCompositor() override {} |
| 72 | void OnDetachCompositor() override {} |
| 73 | void OnActivityStopped() override {} |
| 74 | void OnActivityStarted() override {} |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 75 | |
| 76 | private: |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 77 | // Signals the overlay should be cleaned up and no longer used. |
| 78 | void Stop(); |
Andrei Pascovici | b478402 | 2018-09-06 14:41:22 | [diff] [blame] | 79 | void RegisterWindowObserverIfNeeded(ui::WindowAndroid* window); |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 80 | |
Richard Knoll | ba18275 | 2021-06-01 10:49:55 | [diff] [blame] | 81 | void StartObservingContainerView(); |
| 82 | void StopObservingContainerView(); |
| 83 | void ObserveContainerViewIfNeeded( |
| 84 | const base::android::ScopedJavaLocalRef<jobject>& container_view); |
| 85 | |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 86 | // Java object that owns us. |
| 87 | JavaObjectWeakGlobalRef obj_; |
| 88 | |
Thomas Guilbert | 2d5ef44 | 2017-07-13 00:12:55 | [diff] [blame] | 89 | // RenderFrameHostImpl* associated with the given overlay routing token. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 90 | raw_ptr<RenderFrameHostImpl> rfhi_; |
[email protected] | e62e7ebf | 2017-09-21 17:14:41 | [diff] [blame] | 91 | |
| 92 | // Do we care about power efficiency? |
Richard Knoll | ba18275 | 2021-06-01 10:49:55 | [diff] [blame] | 93 | const bool power_efficient_; |
Andrei Pascovici | b478402 | 2018-09-06 14:41:22 | [diff] [blame] | 94 | |
| 95 | // Whether we added ourselves as an observer through WindowAndroid. |
| 96 | bool observed_window_android_; |
Richard Knoll | ba18275 | 2021-06-01 10:49:55 | [diff] [blame] | 97 | |
| 98 | // Whether we should observe the container view for location changes. |
| 99 | const bool observe_container_view_; |
liberato | a8da3b5 | 2017-05-02 20:23:51 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace content |
| 103 | |
| 104 | #endif // CONTENT_BROWSER_ANDROID_DIALOG_OVERLAY_IMPL_H_ |