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

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

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Codereview update 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/browser/screen_orientation/screen_orientation.cc
diff --git a/content/browser/screen_orientation/screen_orientation.cc b/content/browser/screen_orientation/screen_orientation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ec4c8c0b2c76fc45d3e4237b92f630c740a914e2
--- /dev/null
+++ b/content/browser/screen_orientation/screen_orientation.cc
@@ -0,0 +1,73 @@
+// 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.h"
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/screen_orientation_provider.h"
+#include "content/public/browser/web_contents.h"
+
+namespace content {
+
+using LockResult = blink::mojom::ScreenOrientationLockResult;
+
+ScreenOrientation::ScreenOrientation(WebContents* web_contents)
+ : WebContentsObserver(web_contents),
+ bindings_(web_contents, this),
+ weak_factory_(this) {
+ provider_.reset(new ScreenOrientationProvider(web_contents));
+}
+
+ScreenOrientation::~ScreenOrientation() = default;
+
+void ScreenOrientation::LockOrientation(
+ blink::WebScreenOrientationLockType orientation,
+ const LockOrientationCallback& callback) {
+ if (!on_result_callback_.is_null()) {
+ NotifyLockResult(LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
+ }
+
+ on_result_callback_ = callback;
+
+ if (!provider_) {
pfeldman 2016/11/21 21:30:25 This is never the case.
lunalu1 2016/11/21 21:40:51 Done.
+ NotifyLockResult(
+ LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
+ return;
+ }
+
+ provider_->LockOrientation(
+ orientation,
+ base::Bind(&ScreenOrientation::NotifyLockResult, base::Unretained(this)));
+}
+
+void ScreenOrientation::UnlockOrientation() {
+ // Cancel any pending lock request.
+ NotifyLockResult(LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
+
+ if (provider_)
pfeldman 2016/11/21 21:30:26 Always true
lunalu1 2016/11/21 21:40:51 Done.
+ provider_->UnlockOrientation();
+}
+
+void ScreenOrientation::DidNavigateMainFrame(
+ const LoadCommittedDetails& details,
+ const FrameNavigateParams& params) {
+ if (!provider_ || details.is_in_page)
pfeldman 2016/11/21 21:30:25 useless check.
lunalu1 2016/11/21 21:40:51 Done.
+ return;
+ provider_->UnlockOrientation();
+}
+
+void ScreenOrientation::NotifyLockResult(LockResult result) {
+ if (on_result_callback_.is_null())
+ return;
+
+ base::ResetAndReturn(&on_result_callback_).Run(result);
+}
+
+ScreenOrientationProvider* ScreenOrientation::GetScreenOrientationProvider() {
+ return provider_.get();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698