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_DISPATCHER_HOST_IMPL_H_
6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_IMPL_H_
8 #include "content/public/browser/screen_orientation_dispatcher_host.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "third_party/WebKit/public/platform/WebLockOrientationError.h"
11 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
15 class RenderFrameHost;
16 class ScreenOrientationProvider;
19 // ScreenOrientationDispatcherHost receives lock and unlock requests from the
20 // RenderFrames and dispatch them to the ScreenOrientationProvider. It also
21 // make sure that the right RenderFrame get replied for each lock request.
22 class CONTENT_EXPORT ScreenOrientationDispatcherHostImpl
23 : public ScreenOrientationDispatcherHost,
24 public WebContentsObserver {
26 explicit ScreenOrientationDispatcherHostImpl(WebContents* web_contents);
27 virtual ~ScreenOrientationDispatcherHostImpl();
29 // ScreenOrientationDispatcherHost:
30 virtual void NotifyLockSuccess(int request_id) OVERRIDE;
31 virtual void NotifyLockError(int request_id,
32 blink::WebLockOrientationError error) OVERRIDE;
33 virtual void OnOrientationChange() OVERRIDE;
34 virtual void SetProvider(ScreenOrientationProvider* provider) OVERRIDE;
36 // WebContentsObserver:
37 virtual bool OnMessageReceived(const IPC::Message&,
38 RenderFrameHost* render_frame_host) OVERRIDE;
39 virtual void DidNavigateMainFrame(const LoadCommittedDetails& details,
40 const FrameNavigateParams& params) OVERRIDE;
43 void OnLockRequest(RenderFrameHost* render_frame_host,
44 blink::WebScreenOrientationLockType orientation,
46 void OnUnlockRequest(RenderFrameHost* render_frame_host);
48 // Returns a RenderFrameHost if the request_id is still valid and the
49 // associated RenderFrameHost still exists. Returns NULL otherwise.
50 RenderFrameHost* GetRenderFrameHostForRequestID(int request_id);
52 void ResetCurrentLock();
53 void NotifyLockError(int request_id,
54 RenderFrameHost* render_frame_host,
55 blink::WebLockOrientationError error);
57 scoped_ptr<ScreenOrientationProvider> provider_;
59 struct LockInformation {
60 LockInformation(int request_id, int process_id, int routing_id);
65 // current_lock_ will be NULL if there are no current lock.
66 LockInformation* current_lock_;
68 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcherHostImpl);
71 } // namespace content
73 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_IMPL_H_