| 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 f0060ef0b2127ad16113a5b36b936729f88e2e90..5e4338c467f9ea32b42c89b67c83562675d25974 100644
|
| --- a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
|
| +++ b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
|
| @@ -4,49 +4,46 @@
|
|
|
| #include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
|
|
|
| -#include "content/common/screen_orientation_messages.h"
|
| +#include "content/common/screen_orientation_utils.h"
|
| +#include "content/public/common/service_registry.h"
|
|
|
| namespace content {
|
|
|
| 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::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 SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS:
|
| + callback->onSuccess();
|
| + break;
|
| + case SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE:
|
| + callback->onError(blink::WebLockOrientationErrorNotAvailable);
|
| + break;
|
| + case SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED:
|
| + callback->onError(blink::WebLockOrientationErrorFullScreenRequired);
|
| + break;
|
| + case SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED:
|
| + callback->onError(blink::WebLockOrientationErrorCanceled);
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + break;
|
| + }
|
| +
|
| pending_callbacks_.Remove(request_id);
|
| }
|
|
|
| @@ -64,13 +61,17 @@ void ScreenOrientationDispatcher::lockOrientation(
|
| CancelPendingLocks();
|
|
|
| int request_id = pending_callbacks_.Add(callback);
|
| - Send(new ScreenOrientationHostMsg_LockRequest(
|
| - routing_id(), orientation, request_id));
|
| + DCHECK(screen_orientation_service_);
|
| + screen_orientation_service_->LockOrientation(
|
| + WebScreenOrientationLockTypeToScreenOrientationLockType(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
|
|
|