Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / browser / screen_orientation_provider.h
blobc3bda14ba896059e8ac45ce0bdec8a9d52db8167
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_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/content_export.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScreenOrientationLockType.h"
14 namespace content {
16 class ScreenOrientationDelegate;
17 class ScreenOrientationDispatcherHost;
18 class WebContents;
20 // Handles screen orientation lock/unlock. Platforms which wish to provide
21 // custom implementations can provide a factory for ScreenOrientationDelegate.
22 class CONTENT_EXPORT ScreenOrientationProvider : public WebContentsObserver {
23 public:
24 ScreenOrientationProvider(ScreenOrientationDispatcherHost* dispatcher_host,
25 WebContents* web_contents);
26 ~ScreenOrientationProvider() override;
28 // Lock the screen orientation to |orientations|.
29 void LockOrientation(int request_id,
30 blink::WebScreenOrientationLockType lock_orientation);
32 // Unlock the screen orientation.
33 void UnlockOrientation();
35 // Inform about a screen orientation update. It is called to let the provider
36 // know if a lock has been resolved.
37 void OnOrientationChange();
39 // Provide a delegate which creates delegates for platform implementations.
40 // The delegate is not owned by ScreenOrientationProvider.
41 static void SetDelegate(ScreenOrientationDelegate* delegate_);
43 // WebContentsObserver
44 void DidToggleFullscreenModeForTab(bool entered_fullscreen) override;
46 private:
47 struct LockInformation {
48 LockInformation(int request_id, blink::WebScreenOrientationLockType lock);
49 int request_id;
50 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
55 // found.
56 blink::WebScreenOrientationLockType GetNaturalLockType() const;
58 // Whether the passed |lock| matches the current orientation. In other words,
59 // whether the orientation will need to change to match the |lock|.
60 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock);
62 // Not owned, responsible for platform implementations.
63 static ScreenOrientationDelegate* delegate_;
65 // ScreenOrientationDispatcherHost owns ScreenOrientationProvider.
66 ScreenOrientationDispatcherHost* dispatcher_;
68 // Whether the ScreenOrientationProvider currently has a lock applied.
69 bool lock_applied_;
71 // Locks that require orientation changes are not completed until
72 // OnOrientationChange.
73 scoped_ptr<LockInformation> pending_lock_;
75 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider);
78 } // namespace content
80 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_