#ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_
#define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_
#include <optional>
#include "base/functional/callback.h"
#include "content/common/content_export.h"
#include "content/public/browser/render_frame_host_receiver_set.h"
#include "content/public/browser/web_contents_observer.h"
#include "services/device/public/mojom/screen_orientation.mojom.h"
#include "services/device/public/mojom/screen_orientation_lock_types.mojom.h"
#include "ui/display/mojom/screen_orientation.mojom.h"
namespace content {
class ScreenOrientationDelegate;
class WebContents;
class CONTENT_EXPORT ScreenOrientationProvider
: public device::mojom::ScreenOrientation,
public WebContentsObserver {
public:
ScreenOrientationProvider(WebContents* web_contents);
ScreenOrientationProvider(const ScreenOrientationProvider&) = delete;
ScreenOrientationProvider& operator=(const ScreenOrientationProvider&) =
delete;
~ScreenOrientationProvider() override;
void BindScreenOrientation(
RenderFrameHost* rfh,
mojo::PendingAssociatedReceiver<device::mojom::ScreenOrientation>
receiver);
bool IsOrientationLockSupported() const;
void LockOrientation(device::mojom::ScreenOrientationLockType,
LockOrientationCallback callback) override;
void UnlockOrientation() override;
void OnOrientationChange();
static void SetDelegate(ScreenOrientationDelegate* delegate);
static ScreenOrientationDelegate* GetDelegateForTesting();
static bool LockMatchesOrientation(
device::mojom::ScreenOrientationLockType lock,
display::mojom::ScreenOrientation orientation);
void DidToggleFullscreenModeForTab(bool entered_fullscreen,
bool will_cause_resize) override;
void PrimaryPageChanged(Page& page) override;
private:
void NotifyLockResult(device::mojom::ScreenOrientationLockResult result);
device::mojom::ScreenOrientationLockType GetNaturalLockType() const;
bool LockMatchesCurrentOrientation(
device::mojom::ScreenOrientationLockType lock);
static ScreenOrientationDelegate* delegate_;
bool lock_applied_;
std::optional<device::mojom::ScreenOrientationLockType>
pending_lock_orientation_;
LockOrientationCallback pending_callback_;
RenderFrameHostReceiverSet<device::mojom::ScreenOrientation> receivers_;
};
}
#endif