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

Unified Diff: content/renderer/screen_orientation/screen_orientation_dispatcher.cc

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Modified test for manifest_manager_messages.h Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..7703055fa94357394396d4a5dec4799e15100612 100644
--- a/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
+++ b/content/renderer/screen_orientation/screen_orientation_dispatcher.cc
@@ -4,10 +4,13 @@
#include "content/renderer/screen_orientation/screen_orientation_dispatcher.h"
-#include "content/common/screen_orientation_messages.h"
+#include "content/public/common/associated_interface_provider.h"
+#include "content/public/renderer/render_frame.h"
namespace content {
+using ::blink::mojom::ScreenOrientationLockResult;
+
ScreenOrientationDispatcher::ScreenOrientationDispatcher(
RenderFrame* render_frame)
: RenderFrameObserver(render_frame) {
@@ -16,41 +19,39 @@ ScreenOrientationDispatcher::ScreenOrientationDispatcher(
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 +69,31 @@ void ScreenOrientationDispatcher::lockOrientation(
CancelPendingLocks();
int request_id = pending_callbacks_.Add(callback);
- Send(new ScreenOrientationHostMsg_LockRequest(
- routing_id(), orientation, request_id));
+ SetScreenOrientationInterface();
mlamouri (slow - plz ping) 2016/11/13 00:26:36 Maybe "EnsureScreenOrientationService" would be a
lunalu1 2016/11/16 18:46:58 Done.
+ screen_orientation_->LockOrientation(
+ orientation,
+ base::Bind(&ScreenOrientationDispatcher::OnLockOrientationResult,
+ base::Unretained(this), request_id));
}
void ScreenOrientationDispatcher::unlockOrientation() {
CancelPendingLocks();
- Send(new ScreenOrientationHostMsg_Unlock(routing_id()));
+ SetScreenOrientationInterface();
+ screen_orientation_->UnlockOrientation();
+}
+
+void ScreenOrientationDispatcher::SetScreenOrientationInterface() {
+ if (!screen_orientation_)
mlamouri (slow - plz ping) 2016/11/13 00:26:36 style: add { }
lunalu1 2016/11/16 18:46:58 Done.
+ render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
+ &screen_orientation_);
+}
+
+int ScreenOrientationDispatcher::GetRequestIdForTests() {
+ if (pending_callbacks_.IsEmpty())
+ return -1;
+ CallbackMap::Iterator<blink::WebLockOrientationCallback> iterator(
+ &pending_callbacks_);
+ return iterator.GetCurrentKey();
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698