Index: content/renderer/screen_orientation/screen_orientation_dispatcher.cc |
diff --git a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc |
index 5f2071d377945cab190ed1bfd71ddf2da976e616..4a6f95651df8dcb4843c2da04c978cec34ffb6d8 100644 |
--- a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc |
+++ b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc |
@@ -4,53 +4,48 @@ |
#include "content/renderer/screen_orientation/screen_orientation_dispatcher.h" |
-#include "content/common/screen_orientation_messages.h" |
- |
namespace content { |
+using mojom::ScreenOrientationLockResult; |
+ |
ScreenOrientationDispatcher::ScreenOrientationDispatcher( |
- RenderFrame* render_frame) |
- : RenderFrameObserver(render_frame) { |
+ ScreenOrientationService* screen_orientation_service) |
+ : screen_orientation_service_(screen_orientation_service) { |
+ DCHECK(screen_orientation_service_); |
} |
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::OnDestruct() { |
- delete this; |
-} |
- |
-void ScreenOrientationDispatcher::OnLockSuccess(int request_id) { |
+void ScreenOrientationDispatcher::OnLockOrientationResult( |
+ int request_id, |
+ ScreenOrientationLockResult result) { |
blink::WebLockOrientationCallback* callback = |
pending_callbacks_.Lookup(request_id); |
if (!callback) |
return; |
- callback->onSuccess(); |
- pending_callbacks_.Remove(request_id); |
-} |
-void ScreenOrientationDispatcher::OnLockError( |
- int request_id, blink::WebLockOrientationError error) { |
- blink::WebLockOrientationCallback* callback = |
- pending_callbacks_.Lookup(request_id); |
- if (!callback) |
- return; |
- callback->onError(error); |
+ switch (result) { |
+ case ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS: |
+ callback->onSuccess(); |
+ break; |
+ case ScreenOrientationLockResult:: |
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE: |
+ callback->onError(blink::WebLockOrientationErrorNotAvailable); |
+ break; |
+ case ScreenOrientationLockResult:: |
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED: |
+ callback->onError(blink::WebLockOrientationErrorFullscreenRequired); |
+ break; |
+ case ScreenOrientationLockResult:: |
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED: |
+ callback->onError(blink::WebLockOrientationErrorCanceled); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ break; |
+ } |
+ |
pending_callbacks_.Remove(request_id); |
} |
@@ -68,13 +63,15 @@ void ScreenOrientationDispatcher::lockOrientation( |
CancelPendingLocks(); |
int request_id = pending_callbacks_.Add(callback); |
- Send(new ScreenOrientationHostMsg_LockRequest( |
- routing_id(), orientation, request_id)); |
+ screen_orientation_service_->LockOrientation( |
+ orientation, |
+ base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult, |
+ base::Unretained(this), request_id)); |
} |
void ScreenOrientationDispatcher::unlockOrientation() { |
CancelPendingLocks(); |
- Send(new ScreenOrientationHostMsg_Unlock(routing_id())); |
+ screen_orientation_service_->UnlockOrientation(); |
} |
} // namespace content |