| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H
    _ | 5 #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H
    _ | 
| 6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H
    _ | 6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID_H
    _ | 
| 7 | 7 | 
| 8 #include <jni.h> | 8 #include <jni.h> | 
| 9 | 9 | 
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" | 
| 11 #include "content/public/browser/screen_orientation_provider.h" | 11 #include "content/public/browser/screen_orientation_provider.h" | 
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" | 
|  | 13 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | 
| 13 | 14 | 
| 14 namespace content { | 15 namespace content { | 
| 15 | 16 | 
| 16 class ScreenOrientationDispatcherHost; |  | 
| 17 class WebContentsImpl; | 17 class WebContentsImpl; | 
| 18 | 18 | 
| 19 class ScreenOrientationProviderAndroid : public ScreenOrientationProvider, | 19 class ScreenOrientationProviderAndroid : public ScreenOrientationProvider, | 
| 20                                          public WebContentsObserver { | 20                                          public WebContentsObserver { | 
| 21  public: | 21  public: | 
| 22   explicit ScreenOrientationProviderAndroid( | 22   explicit ScreenOrientationProviderAndroid( | 
| 23       ScreenOrientationDispatcherHost* dispatcher, |  | 
| 24       WebContents* web_contents); | 23       WebContents* web_contents); | 
| 25 | 24 | 
| 26   static bool Register(JNIEnv* env); | 25   static bool Register(JNIEnv* env); | 
| 27 | 26 | 
| 28   // ScreenOrientationProvider | 27   // ScreenOrientationProvider | 
| 29   virtual void LockOrientation(int request_id, | 28   virtual void LockOrientation( | 
| 30                                blink::WebScreenOrientationLockType) OVERRIDE; | 29       ScreenOrientationLockType lock_type, | 
|  | 30       const ScreenOrientationLockCallback& callback) OVERRIDE; | 
| 31   virtual void UnlockOrientation() OVERRIDE; | 31   virtual void UnlockOrientation() OVERRIDE; | 
| 32   virtual void OnOrientationChange() OVERRIDE; | 32   virtual void OnOrientationChange() OVERRIDE; | 
| 33 | 33 | 
| 34   // WebContentsObserver | 34   // WebContentsObserver | 
| 35   virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen) OVERRIDE; | 35   virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen) OVERRIDE; | 
| 36 | 36 | 
| 37   // Ask the ScreenOrientationListener (Java) to start accurately listening to | 37   // Ask the ScreenOrientationListener (Java) to start accurately listening to | 
| 38   // the screen orientation. It keep track of the number of start request if it | 38   // the screen orientation. It keep track of the number of start request if it | 
| 39   // is already running an accurate listening. | 39   // is already running an accurate listening. | 
| 40   static void StartAccurateListening(); | 40   static void StartAccurateListening(); | 
| 41 | 41 | 
| 42   // Ask the ScreenOrientationListener (Java) to stop accurately listening to | 42   // Ask the ScreenOrientationListener (Java) to stop accurately listening to | 
| 43   // the screen orientation. It will actually stop only if the number of stop | 43   // the screen orientation. It will actually stop only if the number of stop | 
| 44   // requests matches the number of start requests. | 44   // requests matches the number of start requests. | 
| 45   static void StopAccurateListening(); | 45   static void StopAccurateListening(); | 
| 46 | 46 | 
| 47  private: | 47  private: | 
| 48   WebContentsImpl* web_contents_impl(); | 48   WebContentsImpl* web_contents_impl(); | 
| 49 | 49 | 
|  | 50   // Calls |on_result_callback_| with |result|, followed by resetting | 
|  | 51   // |on_result_callback_| and |pending_lock_orientation_|. Does nothing if | 
|  | 52   // |on_result_callback_| is null. | 
|  | 53   void NotifyLockResult(ScreenOrientationLockResult result); | 
|  | 54 | 
| 50   // Whether the passed |lock| matches the current orientation. In other words, | 55   // Whether the passed |lock| matches the current orientation. In other words, | 
| 51   // whether the orientation will need to change to match the |lock|. | 56   // whether the orientation will need to change to match the |lock|. | 
| 52   bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); | 57   bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); | 
| 53 | 58 | 
| 54   // Returns the lock type that should be associated with 'natural' lock. | 59   // Returns the lock type that should be associated with 'natural' lock. | 
| 55   // Returns WebScreenOrientationLockDefault if the natural lock type can't be | 60   // Returns WebScreenOrientationLockDefault if the natural lock type can't be | 
| 56   // found. | 61   // found. | 
| 57   blink::WebScreenOrientationLockType GetNaturalLockType() const; | 62   blink::WebScreenOrientationLockType GetNaturalLockType() const; | 
| 58 | 63 | 
| 59   virtual ~ScreenOrientationProviderAndroid(); | 64   virtual ~ScreenOrientationProviderAndroid(); | 
| 60 | 65 | 
| 61   // ScreenOrientationDispatcherHost owns ScreenOrientationProvider so | 66   // The callback that should be invoked when the current lock request | 
| 62   // dispatcher_ should not point to an invalid memory. | 67   // receives a result. | 
| 63   ScreenOrientationDispatcherHost* dispatcher_; | 68   ScreenOrientationLockCallback on_result_callback_; | 
| 64 | 69 | 
| 65   // Whether the ScreenOrientationProvider currently has a lock applied. | 70   // Whether the ScreenOrientationProvider currently has a lock applied. | 
| 66   bool lock_applied_; | 71   bool lock_applied_; | 
| 67 | 72 | 
| 68   struct LockInformation { | 73   // The requested orientation of the pending lock request, or | 
| 69     LockInformation(int request_id, blink::WebScreenOrientationLockType lock); | 74   // blink::WebScreenOrientationLockDefault if there is no pending lock | 
| 70     int request_id; | 75   // request. | 
| 71     blink::WebScreenOrientationLockType lock; | 76   blink::WebScreenOrientationLockType pending_lock_orientation_; | 
| 72   }; |  | 
| 73   LockInformation* pending_lock_; |  | 
| 74 | 77 | 
| 75   DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProviderAndroid); | 78   DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProviderAndroid); | 
| 76 }; | 79 }; | 
| 77 | 80 | 
| 78 } // namespace content | 81 } // namespace content | 
| 79 | 82 | 
| 80 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID
    _H_ | 83 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_ANDROID
    _H_ | 
| OLD | NEW | 
|---|