| 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_H_ | 5 #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ |
| 6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/optional.h" | 11 #include "base/optional.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/public/browser/web_contents_binding_set.h" | |
| 14 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h
" | 14 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h
" |
| 16 #include "device/screen_orientation/public/interfaces/screen_orientation_lock_ty
pes.mojom.h" | 15 #include "device/screen_orientation/public/interfaces/screen_orientation_lock_ty
pes.mojom.h" |
| 16 #include "mojo/public/cpp/bindings/binding_set.h" |
| 17 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 17 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class RenderFrameHost; |
| 21 class ScreenOrientationDelegate; | 22 class ScreenOrientationDelegate; |
| 22 class WebContents; | 23 class WebContents; |
| 23 | 24 |
| 24 // Handles screen orientation lock/unlock. Platforms which wish to provide | 25 // Handles screen orientation lock/unlock. Platforms which wish to provide |
| 25 // custom implementations can provide a factory for ScreenOrientationDelegate. | 26 // custom implementations can provide a factory for ScreenOrientationDelegate. |
| 26 class CONTENT_EXPORT ScreenOrientationProvider | 27 class CONTENT_EXPORT ScreenOrientationProvider |
| 27 : NON_EXPORTED_BASE(public device::mojom::ScreenOrientation), | 28 : NON_EXPORTED_BASE(public device::mojom::ScreenOrientation), |
| 28 public WebContentsObserver { | 29 public WebContentsObserver { |
| 29 public: | 30 public: |
| 30 ScreenOrientationProvider(WebContents* web_contents); | 31 ScreenOrientationProvider(WebContents* web_contents); |
| 31 | 32 |
| 32 ~ScreenOrientationProvider() override; | 33 ~ScreenOrientationProvider() override; |
| 33 | 34 |
| 35 // Provide a delegate which creates delegates for platform implementations. |
| 36 // The delegate is not owned by ScreenOrientationProvider. |
| 37 static void SetDelegate(ScreenOrientationDelegate* delegate_); |
| 38 |
| 39 static void BindRequest(RenderFrameHost* render_frame_host, |
| 40 device::mojom::ScreenOrientationRequest request); |
| 41 |
| 34 // device::mojom::ScreenOrientation: | 42 // device::mojom::ScreenOrientation: |
| 35 void LockOrientation(blink::WebScreenOrientationLockType orientation, | 43 void LockOrientation(blink::WebScreenOrientationLockType orientation, |
| 36 const LockOrientationCallback& callback) override; | 44 const LockOrientationCallback& callback) override; |
| 37 void UnlockOrientation() override; | 45 void UnlockOrientation() override; |
| 38 void StartAccurateListen() override; | 46 void StartAccurateListen() override; |
| 39 void StopAccurateListen() override; | 47 void StopAccurateListen() override; |
| 40 | 48 |
| 41 // Inform about a screen orientation update. It is called to let the provider | 49 // Inform about a screen orientation update. It is called to let the provider |
| 42 // know if a lock has been resolved. | 50 // know if a lock has been resolved. |
| 43 void OnOrientationChange(); | 51 void OnOrientationChange(); |
| 44 | 52 |
| 45 // Provide a delegate which creates delegates for platform implementations. | |
| 46 // The delegate is not owned by ScreenOrientationProvider. | |
| 47 static void SetDelegate(ScreenOrientationDelegate* delegate_); | |
| 48 | |
| 49 // WebContentsObserver | 53 // WebContentsObserver |
| 50 void DidToggleFullscreenModeForTab(bool entered_fullscreen, | 54 void DidToggleFullscreenModeForTab(bool entered_fullscreen, |
| 51 bool will_cause_resize) override; | 55 bool will_cause_resize) override; |
| 52 void DidFinishNavigation(NavigationHandle* navigation_handle) override; | 56 void DidFinishNavigation(NavigationHandle* navigation_handle) override; |
| 53 | 57 |
| 54 private: | 58 private: |
| 59 void AddBinding(device::mojom::ScreenOrientationRequest request); |
| 60 |
| 55 // Calls on |on_result_callback_| with |result|, followed by resetting | 61 // Calls on |on_result_callback_| with |result|, followed by resetting |
| 56 // |on_result_callback_| and |pending_lock_orientation_|. | 62 // |on_result_callback_| and |pending_lock_orientation_|. |
| 57 void NotifyLockResult(device::mojom::ScreenOrientationLockResult result); | 63 void NotifyLockResult(device::mojom::ScreenOrientationLockResult result); |
| 58 | 64 |
| 59 // Returns the lock type that should be associated with 'natural' lock. | 65 // Returns the lock type that should be associated with 'natural' lock. |
| 60 // Returns WebScreenOrientationLockDefault if the natural lock type can't be | 66 // Returns WebScreenOrientationLockDefault if the natural lock type can't be |
| 61 // found. | 67 // found. |
| 62 blink::WebScreenOrientationLockType GetNaturalLockType() const; | 68 blink::WebScreenOrientationLockType GetNaturalLockType() const; |
| 63 | 69 |
| 64 // Whether the passed |lock| matches the current orientation. In other words, | 70 // Whether the passed |lock| matches the current orientation. In other words, |
| 65 // whether the orientation will need to change to match the |lock|. | 71 // whether the orientation will need to change to match the |lock|. |
| 66 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); | 72 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); |
| 67 | 73 |
| 68 // Not owned, responsible for platform implementations. | 74 // Not owned, responsible for platform implementations. |
| 69 static ScreenOrientationDelegate* delegate_; | 75 static ScreenOrientationDelegate* delegate_; |
| 70 | 76 |
| 71 #if defined(OS_ANDROID) | 77 #if defined(OS_ANDROID) |
| 72 int accurate_listener_count_ = 0; | 78 int accurate_listener_count_ = 0; |
| 73 #endif | 79 #endif |
| 74 | 80 |
| 75 // Whether the ScreenOrientationProvider currently has a lock applied. | 81 // Whether the ScreenOrientationProvider currently has a lock applied. |
| 76 bool lock_applied_; | 82 bool lock_applied_; |
| 77 | 83 |
| 78 // Lock that require orientation changes are not completed until | 84 // Lock that require orientation changes are not completed until |
| 79 // OnOrientationChange. | 85 // OnOrientationChange. |
| 80 base::Optional<blink::WebScreenOrientationLockType> pending_lock_orientation_; | 86 base::Optional<blink::WebScreenOrientationLockType> pending_lock_orientation_; |
| 81 | 87 |
| 82 LockOrientationCallback pending_callback_; | 88 LockOrientationCallback pending_callback_; |
| 83 | 89 |
| 84 WebContentsFrameBindingSet<device::mojom::ScreenOrientation> bindings_; | 90 mojo::BindingSet<device::mojom::ScreenOrientation> bindings_; |
| 85 | 91 |
| 86 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); | 92 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); |
| 87 }; | 93 }; |
| 88 | 94 |
| 89 } // namespace content | 95 } // namespace content |
| 90 | 96 |
| 91 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ | 97 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_ |
| OLD | NEW |