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

Unified Diff: content/browser/screen_orientation/screen_orientation_impl.cc

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Ensure correct ordering between ViewMsg_Resize and screen orientation messages Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/screen_orientation/screen_orientation_impl.cc
diff --git a/content/browser/screen_orientation/screen_orientation_impl.cc b/content/browser/screen_orientation/screen_orientation_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f8f28f034573618f32e96c3dc3b1e96b085a520e
--- /dev/null
+++ b/content/browser/screen_orientation/screen_orientation_impl.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/screen_orientation/screen_orientation_impl.h"
+
+#include "base/bind.h"
+#include "content/public/browser/screen_orientation_provider.h"
+#include "content/public/browser/web_contents.h"
+
+namespace content {
+
+using typename ::blink::mojom::ScreenOrientationLockResult;
+
+ScreenOrientationImpl::ScreenOrientationImpl(WebContents* web_contents)
+ : web_contents_(web_contents),
+ binding_(web_contents, this),
+ weak_factory_(this) {
+ provider_.reset(new ScreenOrientationProvider(web_contents));
+}
+
+ScreenOrientationImpl::~ScreenOrientationImpl() = default;
+
+void ScreenOrientationImpl::LockOrientation(
+ blink::WebScreenOrientationLockType orientation,
+ const LockOrientationCallback& callback) {
+ DCHECK(on_result_callback_.is_null());
blundell 2016/10/21 18:16:31 This object is per-WebContents, the same as the ol
lunalu1 2016/10/24 16:57:36 Done.
+ on_result_callback_ = callback;
+
+ if (!provider_) {
+ NotifyLockResult(ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
+ return;
+ }
+
+ provider_->LockOrientation(
+ orientation, base::Bind(&ScreenOrientationImpl::NotifyLockResult,
+ weak_factory_.GetWeakPtr()));
+}
+
+void ScreenOrientationImpl::UnlockOrientation() {
+ // Cancel any pending lock request.
+ NotifyLockResult(ScreenOrientationLockResult::
+ SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
+
+ if (provider_)
+ provider_->UnlockOrientation();
+}
+
+void ScreenOrientationImpl::NotifyLockResult(
+ ScreenOrientationLockResult result) {
+ if (on_result_callback_.is_null())
+ return;
+ if (result ==
+ ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS &&
+ binding_.GetCurrentTargetFrame() != web_contents_->GetMainFrame())
blundell 2016/10/21 18:16:31 Why this short-circuit?
lunalu1 2016/10/24 16:57:36 This is done to make sure the lock success message
+ return;
+
+ on_result_callback_.Run(result);
+
+ // Reset the callback.
+ on_result_callback_ = LockOrientationCallback();
+}
+
+ScreenOrientationProvider*
+ScreenOrientationImpl::GetScreenOrientationProvider() {
+ return provider_.get();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698