Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/renderer/screen_orientation/screen_orientation_dispatcher.cc

Issue 549603003: Create Mojo service for locking/unlocking screen orientation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/screen_orientation_utils.h"
8 #include "content/public/common/service_registry.h"
9 #include "content/public/renderer/render_frame.h"
8 10
9 namespace content { 11 namespace content {
10 12
11 ScreenOrientationDispatcher::ScreenOrientationDispatcher( 13 ScreenOrientationDispatcher::ScreenOrientationDispatcher(
12 RenderFrame* render_frame) 14 RenderFrame* render_frame) {
13 : RenderFrameObserver(render_frame) { 15 render_frame->GetServiceRegistry()->ConnectToRemoteService(
16 &screen_orientation_service_);
14 } 17 }
15 18
16 ScreenOrientationDispatcher::~ScreenOrientationDispatcher() { 19 ScreenOrientationDispatcher::~ScreenOrientationDispatcher() {
17 } 20 }
18 21
19 bool ScreenOrientationDispatcher::OnMessageReceived( 22 void ScreenOrientationDispatcher::OnLockOrientationResult(
20 const IPC::Message& message) { 23 int request_id,
21 bool handled = true; 24 ScreenOrientationLockResult result) {
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::OnLockSuccess(int request_id) {
35 blink::WebLockOrientationCallback* callback = 25 blink::WebLockOrientationCallback* callback =
36 pending_callbacks_.Lookup(request_id); 26 pending_callbacks_.Lookup(request_id);
37 if (!callback) 27 if (!callback)
38 return; 28 return;
39 callback->onSuccess(); 29
30 switch (result) {
31 case SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS:
32 callback->onSuccess();
33 break;
34 case SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE:
35 callback->onError(blink::WebLockOrientationErrorNotAvailable);
36 break;
37 case SCREEN_ORIENTATION_LOCK_RESULT_ERROR_FULLSCREEN_REQUIRED:
38 callback->onError(blink::WebLockOrientationErrorFullScreenRequired);
39 break;
40 case SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED:
41 callback->onError(blink::WebLockOrientationErrorCanceled);
42 break;
43 default:
44 NOTREACHED();
45 break;
46 }
47
40 pending_callbacks_.Remove(request_id); 48 pending_callbacks_.Remove(request_id);
41 } 49 }
42 50
43 void ScreenOrientationDispatcher::OnLockError(
44 int request_id, blink::WebLockOrientationError error) {
45 blink::WebLockOrientationCallback* callback =
46 pending_callbacks_.Lookup(request_id);
47 if (!callback)
48 return;
49 callback->onError(error);
50 pending_callbacks_.Remove(request_id);
51 }
52
53 void ScreenOrientationDispatcher::CancelPendingLocks() { 51 void ScreenOrientationDispatcher::CancelPendingLocks() {
54 for (CallbackMap::Iterator<blink::WebLockOrientationCallback> 52 for (CallbackMap::Iterator<blink::WebLockOrientationCallback>
55 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) { 53 iterator(&pending_callbacks_); !iterator.IsAtEnd(); iterator.Advance()) {
56 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled); 54 iterator.GetCurrentValue()->onError(blink::WebLockOrientationErrorCanceled);
57 pending_callbacks_.Remove(iterator.GetCurrentKey()); 55 pending_callbacks_.Remove(iterator.GetCurrentKey());
58 } 56 }
59 } 57 }
60 58
61 void ScreenOrientationDispatcher::lockOrientation( 59 void ScreenOrientationDispatcher::lockOrientation(
62 blink::WebScreenOrientationLockType orientation, 60 blink::WebScreenOrientationLockType orientation,
63 blink::WebLockOrientationCallback* callback) { 61 blink::WebLockOrientationCallback* callback) {
64 CancelPendingLocks(); 62 CancelPendingLocks();
65 63
66 int request_id = pending_callbacks_.Add(callback); 64 int request_id = pending_callbacks_.Add(callback);
67 Send(new ScreenOrientationHostMsg_LockRequest( 65 screen_orientation_service_->LockOrientation(
68 routing_id(), orientation, request_id)); 66 WebScreenOrientationLockTypeToScreenOrientationLockType(orientation),
67 base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult,
68 base::Unretained(this),
69 request_id));
69 } 70 }
70 71
71 void ScreenOrientationDispatcher::unlockOrientation() { 72 void ScreenOrientationDispatcher::unlockOrientation() {
72 CancelPendingLocks(); 73 CancelPendingLocks();
73 Send(new ScreenOrientationHostMsg_Unlock(routing_id())); 74 screen_orientation_service_->UnlockOrientation();
74 } 75 }
75 76
76 } // namespace content 77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698