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"
11 ScreenOrientationDispatcher::ScreenOrientationDispatcher(
12 RenderFrame
* render_frame
)
13 : RenderFrameObserver(render_frame
) {
16 ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
19 bool ScreenOrientationDispatcher::OnMessageReceived(
20 const IPC::Message
& message
) {
23 IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcher
, message
)
24 IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockSuccess
,
26 IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockError
,
28 IPC_MESSAGE_UNHANDLED(handled
= false)
34 void ScreenOrientationDispatcher::OnLockSuccess(int request_id
) {
35 blink::WebLockOrientationCallback
* callback
=
36 pending_callbacks_
.Lookup(request_id
);
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
);
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
) {
66 int request_id
= pending_callbacks_
.Add(callback
);
67 Send(new ScreenOrientationHostMsg_LockRequest(
68 routing_id(), orientation
, request_id
));
71 void ScreenOrientationDispatcher::unlockOrientation() {
73 Send(new ScreenOrientationHostMsg_Unlock(routing_id()));
76 } // namespace content