Chromium Code Reviews| 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 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" | 5 #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" |
| 6 | 6 |
| 7 #include "content/common/screen_orientation_messages.h" | 7 #include "content/public/common/associated_interface_provider.h" |
| 8 #include "content/public/renderer/render_frame.h" | |
| 8 | 9 |
| 9 namespace content { | 10 namespace content { |
| 10 | 11 |
| 12 using ::blink::mojom::ScreenOrientationLockResult; | |
| 13 | |
| 11 ScreenOrientationDispatcher::ScreenOrientationDispatcher( | 14 ScreenOrientationDispatcher::ScreenOrientationDispatcher( |
| 12 RenderFrame* render_frame) | 15 RenderFrame* render_frame) |
| 13 : RenderFrameObserver(render_frame) { | 16 : RenderFrameObserver(render_frame) { |
| 14 } | 17 } |
| 15 | 18 |
| 16 ScreenOrientationDispatcher::~ScreenOrientationDispatcher() { | 19 ScreenOrientationDispatcher::~ScreenOrientationDispatcher() { |
| 17 } | 20 } |
| 18 | 21 |
| 19 bool ScreenOrientationDispatcher::OnMessageReceived( | |
| 20 const IPC::Message& message) { | |
| 21 bool handled = true; | |
| 22 | |
| 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() | |
| 30 | |
| 31 return handled; | |
| 32 } | |
| 33 | |
| 34 void ScreenOrientationDispatcher::OnDestruct() { | 22 void ScreenOrientationDispatcher::OnDestruct() { |
| 35 delete this; | 23 delete this; |
| 36 } | 24 } |
| 37 | 25 |
| 38 void ScreenOrientationDispatcher::OnLockSuccess(int request_id) { | 26 void ScreenOrientationDispatcher::OnLockOrientationResult( |
| 27 int request_id, | |
| 28 ScreenOrientationLockResult result) { | |
| 39 blink::WebLockOrientationCallback* callback = | 29 blink::WebLockOrientationCallback* callback = |
| 40 pending_callbacks_.Lookup(request_id); | 30 pending_callbacks_.Lookup(request_id); |
| 41 if (!callback) | 31 if (!callback) |
| 42 return; | 32 return; |
| 43 callback->onSuccess(); | 33 |
| 34 switch (result) { | |
| 35 case ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS: | |
| 36 callback->onSuccess(); | |
| 37 break; | |
| 38 case ScreenOrientationLockResult:: | |
| 39 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE: | |
| 40 callback->onError(blink::WebLockOrientationErrorNotAvailable); | |
| 41 break; | |
| 42 case ScreenOrientationLockResult:: | |
| 43 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED: | |
| 44 callback->onError(blink::WebLockOrientationErrorFullscreenRequired); | |
| 45 break; | |
| 46 case ScreenOrientationLockResult:: | |
| 47 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED: | |
| 48 callback->onError(blink::WebLockOrientationErrorCanceled); | |
| 49 break; | |
| 50 default: | |
| 51 NOTREACHED(); | |
| 52 break; | |
| 53 } | |
| 54 | |
| 44 pending_callbacks_.Remove(request_id); | 55 pending_callbacks_.Remove(request_id); |
| 45 } | 56 } |
| 46 | 57 |
| 47 void ScreenOrientationDispatcher::OnLockError( | |
| 48 int request_id, blink::WebLockOrientationError error) { | |
| 49 blink::WebLockOrientationCallback* callback = | |
| 50 pending_callbacks_.Lookup(request_id); | |
| 51 if (!callback) | |
| 52 return; | |
| 53 callback->onError(error); | |
| 54 pending_callbacks_.Remove(request_id); | |
| 55 } | |
| 56 | |
| 57 void ScreenOrientationDispatcher::CancelPendingLocks() { | 58 void ScreenOrientationDispatcher::CancelPendingLocks() { |
| 58 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> | 59 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> |
| 59 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { | 60 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { |
| 60 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled); | 61 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled); |
| 61 pending_callbacks_.Remove(iterator.GetCurrentKey()); | 62 pending_callbacks_.Remove(iterator.GetCurrentKey()); |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 void ScreenOrientationDispatcher::lockOrientation( | 66 void ScreenOrientationDispatcher::lockOrientation( |
| 66 blink::WebScreenOrientationLockType orientation, | 67 blink::WebScreenOrientationLockType orientation, |
| 67 blink::WebLockOrientationCallback* callback) { | 68 blink::WebLockOrientationCallback* callback) { |
| 68 CancelPendingLocks(); | 69 CancelPendingLocks(); |
| 69 | 70 |
| 70 int request_id = pending_callbacks_.Add(callback); | 71 int request_id = pending_callbacks_.Add(callback); |
| 71 Send(new ScreenOrientationHostMsg_LockRequest( | 72 SetScreenOrientationInterface(); |
|
mlamouri (slow - plz ping)
2016/11/13 00:26:36
Maybe "EnsureScreenOrientationService" would be a
lunalu1
2016/11/16 18:46:58
Done.
| |
| 72 routing_id(), orientation, request_id)); | 73 screen_orientation_->LockOrientation( |
| 74 orientation, | |
| 75 base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult, | |
| 76 base::Unretained(this), request_id)); | |
| 73 } | 77 } |
| 74 | 78 |
| 75 void ScreenOrientationDispatcher::unlockOrientation() { | 79 void ScreenOrientationDispatcher::unlockOrientation() { |
| 76 CancelPendingLocks(); | 80 CancelPendingLocks(); |
| 77 Send(new ScreenOrientationHostMsg_Unlock(routing_id())); | 81 SetScreenOrientationInterface(); |
| 82 screen_orientation_->UnlockOrientation(); | |
| 83 } | |
| 84 | |
| 85 void ScreenOrientationDispatcher::SetScreenOrientationInterface() { | |
| 86 if (!screen_orientation_) | |
|
mlamouri (slow - plz ping)
2016/11/13 00:26:36
style: add { }
lunalu1
2016/11/16 18:46:58
Done.
| |
| 87 render_frame()->GetRemoteAssociatedInterfaces()->GetInterface( | |
| 88 &screen_orientation_); | |
| 89 } | |
| 90 | |
| 91 int ScreenOrientationDispatcher::GetRequestIdForTests() { | |
| 92 if (pending_callbacks_.IsEmpty()) | |
| 93 return -1; | |
| 94 CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator( | |
| 95 &pending_callbacks_); | |
| 96 return iterator.GetCurrentKey(); | |
| 78 } | 97 } |
| 79 | 98 |
| 80 } // namespace content | 99 } // namespace content |
| OLD | NEW |