Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / content / browser / screen_orientation / screen_orientation_dispatcher_host.h
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.
4
5 #ifndef CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_
7
8 #include "base/id_map.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "third_party/WebKit/public/platform/WebLockOrientationError.h"
12 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
13 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
14
15 namespace content {
16
17 class RenderFrameHost;
18 class ScreenOrientationProvider;
19 class WebContents;
20
21 // ScreenOrientationDispatcherHost receives lock and unlock requests from the
22 // RenderFrames and dispatch them to the ScreenOrientationProvider. It also
23 // make sure that the right RenderFrame get replied for each lock request.
24 class CONTENT_EXPORT ScreenOrientationDispatcherHost
25     : public WebContentsObserver {
26  public:
27   explicit ScreenOrientationDispatcherHost(WebContents* web_contents);
28   virtual ~ScreenOrientationDispatcherHost();
29
30   // WebContentsObserver
31   virtual bool OnMessageReceived(const IPC::Message&,
32                                  RenderFrameHost* render_frame_host) OVERRIDE;
33
34   // Notifies that the lock with the given |request_id| has succeeded.
35   // The renderer process will be notified that the lock succeeded only if
36   // |request_id| matches the |current_lock_|.
37   void NotifyLockSuccess(int request_id);
38
39   // Notifies that the lock with the given |request_id| has failed.
40   // The renderer process will be notified that the lock succeeded only if
41   // |request_id| matches the |current_lock_|.
42   void NotifyLockError(int request_id, blink::WebLockOrientationError error);
43
44   void OnOrientationChange();
45
46   void SetProvider(ScreenOrientationProvider* provider);
47
48  private:
49   void OnLockRequest(RenderFrameHost* render_frame_host,
50                      blink::WebScreenOrientationLockType orientation,
51                      int request_id);
52   void OnUnlockRequest(RenderFrameHost* render_frame_host);
53
54   // Returns a RenderFrameHost if the request_id is still valid and the
55   // associated RenderFrameHost still exists. Returns NULL otherwise.
56   RenderFrameHost* GetRenderFrameHostForRequestID(int request_id);
57
58   void ResetCurrentLock();
59   void NotifyLockError(int request_id,
60                        RenderFrameHost* render_frame_host,
61                        blink::WebLockOrientationError error);
62
63   scoped_ptr<ScreenOrientationProvider> provider_;
64
65   struct LockInformation {
66     LockInformation(int request_id, int process_id, int routing_id);
67     int request_id;
68     int process_id;
69     int routing_id;
70   };
71   // current_lock_ will be NULL if there are no current lock.
72   LockInformation* current_lock_;
73
74   DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcherHost);
75 };
76
77 }  // namespace content
78
79 #endif // CONTENT_BROWSER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_HOST_H_