Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: content/browser/screen_orientation/screen_orientation_provider.h

Issue 2685513002: [For trybots test] [ScreenOrientation] Hide ScreenOrientationProvider inside WebContentsImpl. (Closed)
Patch Set: Fix android bots Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ 5 #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_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/macros.h" 10 #include "base/macros.h"
10 #include "base/optional.h" 11 #include "base/optional.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "content/public/browser/web_contents_binding_set.h"
12 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
15 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h "
13 #include "device/screen_orientation/public/interfaces/screen_orientation_lock_ty pes.mojom.h" 16 #include "device/screen_orientation/public/interfaces/screen_orientation_lock_ty pes.mojom.h"
14 #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"
15 18
16 namespace content { 19 namespace content {
17 20
18 class ScreenOrientationDelegate; 21 class ScreenOrientationDelegate;
19 class WebContents; 22 class WebContents;
20 23
21 using LockOrientationCallback =
22 base::Callback<void(device::mojom::ScreenOrientationLockResult)>;
23
24 // Handles screen orientation lock/unlock. Platforms which wish to provide 24 // Handles screen orientation lock/unlock. Platforms which wish to provide
25 // custom implementations can provide a factory for ScreenOrientationDelegate. 25 // custom implementations can provide a factory for ScreenOrientationDelegate.
26 class CONTENT_EXPORT ScreenOrientationProvider : public WebContentsObserver { 26 class CONTENT_EXPORT ScreenOrientationProvider
27 : NON_EXPORTED_BASE(public device::mojom::ScreenOrientation),
28 public WebContentsObserver {
27 public: 29 public:
28 ScreenOrientationProvider(WebContents* web_contents); 30 ScreenOrientationProvider(WebContents* web_contents);
29 31
30 ~ScreenOrientationProvider() override; 32 ~ScreenOrientationProvider() override;
31 33
32 // Lock the screen orientation to |orientation|, |callback| is the callback 34 // device::mojom::ScreenOrientation:
33 // that should be invoked when this request receives a result.
34 void LockOrientation(blink::WebScreenOrientationLockType orientation, 35 void LockOrientation(blink::WebScreenOrientationLockType orientation,
35 const LockOrientationCallback& callback); 36 const LockOrientationCallback& callback) override;
36 37 void UnlockOrientation() override;
37 // Unlock the screen orientation.
38 void UnlockOrientation();
39 38
40 // Inform about a screen orientation update. It is called to let the provider 39 // Inform about a screen orientation update. It is called to let the provider
41 // know if a lock has been resolved. 40 // know if a lock has been resolved.
42 void OnOrientationChange(); 41 void OnOrientationChange();
43 42
44 // Provide a delegate which creates delegates for platform implementations. 43 // Provide a delegate which creates delegates for platform implementations.
45 // The delegate is not owned by ScreenOrientationProvider. 44 // The delegate is not owned by ScreenOrientationProvider.
46 static void SetDelegate(ScreenOrientationDelegate* delegate_); 45 static void SetDelegate(ScreenOrientationDelegate* delegate_);
47 46
48 // WebContentsObserver 47 // WebContentsObserver
49 void DidToggleFullscreenModeForTab(bool entered_fullscreen, 48 void DidToggleFullscreenModeForTab(bool entered_fullscreen,
50 bool will_cause_resize) override; 49 bool will_cause_resize) override;
50 void DidFinishNavigation(NavigationHandle* navigation_handle) override;
51 51
52 private: 52 private:
53 // Calls on |on_result_callback_| with |result|, followed by resetting 53 // Calls on |on_result_callback_| with |result|, followed by resetting
54 // |on_result_callback_| and |pending_lock_orientation_|. 54 // |on_result_callback_| and |pending_lock_orientation_|.
55 void NotifyLockResult(device::mojom::ScreenOrientationLockResult result); 55 void NotifyLockResult(device::mojom::ScreenOrientationLockResult result);
56 56
57 // Returns the lock type that should be associated with 'natural' lock. 57 // Returns the lock type that should be associated with 'natural' lock.
58 // Returns WebScreenOrientationLockDefault if the natural lock type can't be 58 // Returns WebScreenOrientationLockDefault if the natural lock type can't be
59 // found. 59 // found.
60 blink::WebScreenOrientationLockType GetNaturalLockType() const; 60 blink::WebScreenOrientationLockType GetNaturalLockType() const;
61 61
62 // Whether the passed |lock| matches the current orientation. In other words, 62 // Whether the passed |lock| matches the current orientation. In other words,
63 // whether the orientation will need to change to match the |lock|. 63 // whether the orientation will need to change to match the |lock|.
64 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); 64 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock);
65 65
66 // Not owned, responsible for platform implementations. 66 // Not owned, responsible for platform implementations.
67 static ScreenOrientationDelegate* delegate_; 67 static ScreenOrientationDelegate* delegate_;
68 68
69 // Whether the ScreenOrientationProvider currently has a lock applied. 69 // Whether the ScreenOrientationProvider currently has a lock applied.
70 bool lock_applied_; 70 bool lock_applied_;
71 71
72 // Locks that require orientation changes are not completed until 72 // Lock that require orientation changes are not completed until
73 // OnOrientationChange. 73 // OnOrientationChange.
74 base::Optional<blink::WebScreenOrientationLockType> pending_lock_orientation_; 74 base::Optional<blink::WebScreenOrientationLockType> pending_lock_orientation_;
75 75
76 LockOrientationCallback pending_callback_; 76 LockOrientationCallback pending_callback_;
77 77
78 WebContentsFrameBindingSet<device::mojom::ScreenOrientation> bindings_;
79
78 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); 80 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider);
79 }; 81 };
80 82
81 } // namespace content 83 } // namespace content
82 84
83 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ 85 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698