1 // Copyright 2014 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 CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_
6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_
10 #include "base/compiler_specific.h"
11 #include "content/browser/screen_orientation/screen_orientation_provider.h"
12 #include "content/public/browser/web_contents_observer.h"
16 class WebContentsImpl
;
18 class ScreenOrientationProviderAndroid
: public ScreenOrientationProvider
,
19 public WebContentsObserver
{
21 explicit ScreenOrientationProviderAndroid(
22 ScreenOrientationDispatcherHost
* dispatcher
,
23 WebContents
* web_contents
);
25 static bool Register(JNIEnv
* env
);
27 // ScreenOrientationProvider
28 virtual void LockOrientation(int request_id
,
29 blink::WebScreenOrientationLockType
) OVERRIDE
;
30 virtual void UnlockOrientation() OVERRIDE
;
31 virtual void OnOrientationChange() OVERRIDE
;
33 // WebContentsObserver
34 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen
) OVERRIDE
;
36 // Ask the ScreenOrientationListener (Java) to start accurately listening to
37 // the screen orientation. It keep track of the number of start request if it
38 // is already running an accurate listening.
39 static void StartAccurateListening();
41 // Ask the ScreenOrientationListener (Java) to stop accurately listening to
42 // the screen orientation. It will actually stop only if the number of stop
43 // requests matches the number of start requests.
44 static void StopAccurateListening();
47 WebContentsImpl
* web_contents_impl();
49 // Whether the passed |lock| matches the current orientation. In other words,
50 // whether the orientation will need to change to match the |lock|.
51 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock
);
53 // Returns the lock type that should be associated with 'natural' lock.
54 // Returns WebScreenOrientationLockDefault if the natural lock type can't be
56 blink::WebScreenOrientationLockType
GetNaturalLockType() const;
58 virtual ~ScreenOrientationProviderAndroid();
60 // ScreenOrientationDispatcherHost owns ScreenOrientationProvider so
61 // dispatcher_ should not point to an invalid memory.
62 ScreenOrientationDispatcherHost
* dispatcher_
;
64 // Whether the ScreenOrientationProvider currently has a lock applied.
67 struct LockInformation
{
68 LockInformation(int request_id
, blink::WebScreenOrientationLockType lock
);
70 blink::WebScreenOrientationLockType lock
;
72 LockInformation
* pending_lock_
;
74 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProviderAndroid
);
77 } // namespace content
79 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H_