| 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_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | 
| 6 #define CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | 
| 7 | 7 | 
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" | 
| 9 #include "base/id_map.h" | 9 #include "base/id_map.h" | 
| 10 #include "base/macros.h" | 10 #include "base/macros.h" | 
| 11 #include "content/public/renderer/render_frame_observer.h" | 11 #include "content/common/content_export.h" | 
|  | 12 #include "content/common/screen_orientation_service.mojom.h" | 
| 12 #include "third_party/WebKit/public/platform/WebLockOrientationCallback.h" | 13 #include "third_party/WebKit/public/platform/WebLockOrientationCallback.h" | 
| 13 #include "third_party/WebKit/public/platform/WebScreenOrientationClient.h" | 14 #include "third_party/WebKit/public/platform/WebScreenOrientationClient.h" | 
| 14 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | 15 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | 
| 15 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h" | 16 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h" | 
| 16 | 17 | 
| 17 namespace content { | 18 namespace content { | 
| 18 | 19 | 
| 19 class RenderFrame; | 20 class ServiceRegistry; | 
| 20 | 21 | 
| 21 // ScreenOrientationDispatcher implements the WebScreenOrientationClient API | 22 // ScreenOrientationDispatcher implements the WebScreenOrientationClient API | 
| 22 // which handles screen lock. It sends lock (or unlock) requests to the browser | 23 // which handles screen lock. It sends lock (or unlock) requests to the browser | 
| 23 // process and listens for responses and let Blink know about the result of the | 24 // process and listens for responses and let Blink know about the result of the | 
| 24 // request via WebLockOrientationCallback. | 25 // request via WebLockOrientationCallback. | 
| 25 class CONTENT_EXPORT ScreenOrientationDispatcher : | 26 class CONTENT_EXPORT ScreenOrientationDispatcher : | 
| 26     public RenderFrameObserver, |  | 
| 27     NON_EXPORTED_BASE(public blink::WebScreenOrientationClient) { | 27     NON_EXPORTED_BASE(public blink::WebScreenOrientationClient) { | 
| 28  public: | 28  public: | 
| 29   explicit ScreenOrientationDispatcher(RenderFrame* render_frame); | 29   explicit ScreenOrientationDispatcher( | 
|  | 30       ScreenOrientationService* screen_orientation_service); | 
| 30   virtual ~ScreenOrientationDispatcher(); | 31   virtual ~ScreenOrientationDispatcher(); | 
| 31 | 32 | 
| 32  private: | 33  private: | 
| 33   friend class ScreenOrientationDispatcherTest; | 34   friend class ScreenOrientationDispatcherTest; | 
| 34 | 35 | 
| 35   // RenderFrameObserver implementation. |  | 
| 36   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |  | 
| 37 |  | 
| 38   // blink::WebScreenOrientationClient implementation. | 36   // blink::WebScreenOrientationClient implementation. | 
| 39   virtual void lockOrientation( | 37   virtual void lockOrientation( | 
| 40       blink::WebScreenOrientationLockType orientation, | 38       blink::WebScreenOrientationLockType orientation, | 
| 41       blink::WebLockOrientationCallback* callback) OVERRIDE; | 39       blink::WebLockOrientationCallback* callback) OVERRIDE; | 
| 42   virtual void unlockOrientation() OVERRIDE; | 40   virtual void unlockOrientation() OVERRIDE; | 
| 43 | 41 | 
| 44   void OnLockSuccess(int request_id); | 42   void OnLockOrientationResult(int request_id, | 
| 45   void OnLockError(int request_id, | 43                                ScreenOrientationLockResult result); | 
| 46                    blink::WebLockOrientationError error); |  | 
| 47 | 44 | 
| 48   void CancelPendingLocks(); | 45   void CancelPendingLocks(); | 
| 49 | 46 | 
| 50   // The pending_callbacks_ map is mostly meant to have a unique ID to associate | 47   // The pending_callbacks_ map is mostly meant to have a unique ID to associate | 
| 51   // with every callback going trough the dispatcher. The map will own the | 48   // with every callback going trough the dispatcher. The map will own the | 
| 52   // pointer in the sense that it will destroy it when Remove() will be called. | 49   // pointer in the sense that it will destroy it when Remove() will be called. | 
| 53   // Furthermore, we only expect to have one callback at a time in this map, | 50   // Furthermore, we only expect to have one callback at a time in this map, | 
| 54   // which is what IDMap was designed for. | 51   // which is what IDMap was designed for. | 
| 55   typedef IDMap<blink::WebLockOrientationCallback, IDMapOwnPointer> CallbackMap; | 52   typedef IDMap<blink::WebLockOrientationCallback, IDMapOwnPointer> CallbackMap; | 
| 56   CallbackMap pending_callbacks_; | 53   CallbackMap pending_callbacks_; | 
|  | 54   ScreenOrientationService* screen_orientation_service_; | 
| 57 | 55 | 
| 58   DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcher); | 56   DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcher); | 
| 59 }; | 57 }; | 
| 60 | 58 | 
| 61 }  // namespace content | 59 }  // namespace content | 
| 62 | 60 | 
| 63 #endif // CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | 61 #endif // CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | 
| OLD | NEW | 
|---|