Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / renderer / screen_orientation / screen_orientation_dispatcher.cc
blobf0060ef0b2127ad16113a5b36b936729f88e2e90
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 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
7 #include "content/common/screen_orientation_messages.h"
9 namespace content {
11 ScreenOrientationDispatcher::ScreenOrientationDispatcher(
12 RenderFrame* render_frame)
13 : RenderFrameObserver(render_frame) {
16 ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
19 bool ScreenOrientationDispatcher::OnMessageReceived(
20 const IPC::Message& message) {
21 bool handled = true;
23 IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcher, message)
24 IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockSuccess,
25 OnLockSuccess)
26 IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockError,
27 OnLockError)
28 IPC_MESSAGE_UNHANDLED(handled = false)
29 IPC_END_MESSAGE_MAP()
31 return handled;
34 void ScreenOrientationDispatcher::OnLockSuccess(int request_id) {
35 blink::WebLockOrientationCallback* callback =
36 pending_callbacks_.Lookup(request_id);
37 if (!callback)
38 return;
39 callback->onSuccess();
40 pending_callbacks_.Remove(request_id);
43 void ScreenOrientationDispatcher::OnLockError(
44 int request_id, blink::WebLockOrientationError error) {
45 blink::WebLockOrientationCallback* callback =
46 pending_callbacks_.Lookup(request_id);
47 if (!callback)
48 return;
49 callback->onError(error);
50 pending_callbacks_.Remove(request_id);
53 void ScreenOrientationDispatcher::CancelPendingLocks() {
54 for (CallbackMap::Iterator<blink::WebLockOrientationCallback>
55 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) {
56 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled);
57 pending_callbacks_.Remove(iterator.GetCurrentKey());
61 void ScreenOrientationDispatcher::lockOrientation(
62 blink::WebScreenOrientationLockType orientation,
63 blink::WebLockOrientationCallback* callback) {
64 CancelPendingLocks();
66 int request_id = pending_callbacks_.Add(callback);
67 Send(new ScreenOrientationHostMsg_LockRequest(
68 routing_id(), orientation, request_id));
71 void ScreenOrientationDispatcher::unlockOrientation() {
72 CancelPendingLocks();
73 Send(new ScreenOrientationHostMsg_Unlock(routing_id()));
76 } // namespace content