summaryrefslogtreecommitdiffstats
path: root/chromium/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/renderer/screen_orientation/screen_orientation_dispatcher.cc')
-rw-r--r--chromium/content/renderer/screen_orientation/screen_orientation_dispatcher.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/chromium/content/renderer/screen_orientation/screen_orientation_dispatcher.cc b/chromium/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
new file mode 100644
index 00000000000..e67cc73634e
--- /dev/null
+++ b/chromium/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
+
+#include "content/common/screen_orientation_messages.h"
+
+namespace content {
+
+ScreenOrientationDispatcher::ScreenOrientationDispatcher(
+ RenderFrame* render_frame)
+ : RenderFrameObserver(render_frame) {
+}
+
+ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
+}
+
+bool ScreenOrientationDispatcher::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+
+ IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcher, message)
+ IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockSuccess,
+ OnLockSuccess)
+ IPC_MESSAGE_HANDLER(ScreenOrientationMsg_LockError,
+ OnLockError)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void ScreenOrientationDispatcher::OnLockSuccess(
+ int request_id,
+ unsigned angle,
+ blink::WebScreenOrientationType orientation) {
+ blink::WebLockOrientationCallback* callback =
+ pending_callbacks_.Lookup(request_id);
+ if (!callback)
+ return;
+ callback->onSuccess(angle, orientation);
+ pending_callbacks_.Remove(request_id);
+}
+
+void ScreenOrientationDispatcher::OnLockError(
+ int request_id,
+ blink::WebLockOrientationCallback::ErrorType error) {
+ blink::WebLockOrientationCallback* callback =
+ pending_callbacks_.Lookup(request_id);
+ if (!callback)
+ return;
+ callback->onError(error);
+ pending_callbacks_.Remove(request_id);
+}
+
+void ScreenOrientationDispatcher::CancelPendingLocks() {
+ for (CallbackMap::Iterator<blink::WebLockOrientationCallback>
+ iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) {
+ iterator.GetCurrentValue()->onError(
+ blink::WebLockOrientationCallback::ErrorTypeCanceled);
+ pending_callbacks_.Remove(iterator.GetCurrentKey());
+ }
+}
+
+void ScreenOrientationDispatcher::lockOrientation(
+ blink::WebScreenOrientationLockType orientation,
+ blink::WebLockOrientationCallback* callback) {
+ CancelPendingLocks();
+
+ int request_id = pending_callbacks_.Add(callback);
+ Send(new ScreenOrientationHostMsg_LockRequest(
+ routing_id(), orientation, request_id));
+}
+
+void ScreenOrientationDispatcher::unlockOrientation() {
+ CancelPendingLocks();
+ Send(new ScreenOrientationHostMsg_Unlock(routing_id()));
+}
+
+} // namespace content