| OLD | NEW |
| (Empty) |
| 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_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | |
| 6 #define CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <utility> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/id_map.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "content/public/renderer/render_frame_observer.h" | |
| 15 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h
" | |
| 16 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO
rientationCallback.h" | |
| 17 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationClient.h" | |
| 18 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | |
| 19 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationType.h" | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 using device::mojom::ScreenOrientationAssociatedPtr; | |
| 24 using device::mojom::ScreenOrientationLockResult; | |
| 25 | |
| 26 class RenderFrame; | |
| 27 | |
| 28 // ScreenOrientationDispatcher implements the WebScreenOrientationClient API | |
| 29 // which handles screen lock. It sends lock (or unlock) requests to the browser | |
| 30 // process and listens for responses and let Blink know about the result of the | |
| 31 // request via WebLockOrientationCallback. | |
| 32 class CONTENT_EXPORT ScreenOrientationDispatcher : | |
| 33 public RenderFrameObserver, | |
| 34 NON_EXPORTED_BASE(public blink::WebScreenOrientationClient) { | |
| 35 public: | |
| 36 explicit ScreenOrientationDispatcher(RenderFrame* render_frame); | |
| 37 ~ScreenOrientationDispatcher() override; | |
| 38 | |
| 39 private: | |
| 40 friend class ScreenOrientationDispatcherTest; | |
| 41 | |
| 42 // RenderFrameObserver implementation. | |
| 43 void OnDestruct() override; | |
| 44 | |
| 45 // blink::WebScreenOrientationClient implementation. | |
| 46 void lockOrientation( | |
| 47 blink::WebScreenOrientationLockType orientation, | |
| 48 std::unique_ptr<blink::WebLockOrientationCallback> callback) override; | |
| 49 void unlockOrientation() override; | |
| 50 void startAccurateListen() override; | |
| 51 void stopAccurateListen() override; | |
| 52 | |
| 53 void OnLockOrientationResult(int request_id, | |
| 54 ScreenOrientationLockResult result); | |
| 55 | |
| 56 void CancelPendingLocks(); | |
| 57 | |
| 58 int GetRequestIdForTests(); | |
| 59 | |
| 60 device::mojom::ScreenOrientation* GetRemoteScreenOrientation(); | |
| 61 | |
| 62 // This should only be called by ScreenOrientationDispatcherTest | |
| 63 void SetScreenOrientationForTests( | |
| 64 ScreenOrientationAssociatedPtr& screen_orientation_for_tests) { | |
| 65 screen_orientation_ = std::move(screen_orientation_for_tests); | |
| 66 } | |
| 67 | |
| 68 // The pending_callbacks_ map is mostly meant to have a unique ID to associate | |
| 69 // with every callback going trough the dispatcher. The map will own the | |
| 70 // pointer in the sense that it will destroy it when Remove() will be called. | |
| 71 // Furthermore, we only expect to have one callback at a time in this map, | |
| 72 // which is what IDMap was designed for. | |
| 73 using CallbackMap = IDMap<std::unique_ptr<blink::WebLockOrientationCallback>>; | |
| 74 CallbackMap pending_callbacks_; | |
| 75 | |
| 76 ScreenOrientationAssociatedPtr screen_orientation_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDispatcher); | |
| 79 }; | |
| 80 | |
| 81 } // namespace content | |
| 82 | |
| 83 #endif // CONTENT_RENDERER_SCREEN_ORIENTATION_SCREEN_ORIENTATION_DISPATCHER_H_ | |
| OLD | NEW |