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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/screen_orientation/screen_orientation.h"
6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "content/public/browser/navigation_details.h"
10 #include "content/public/browser/screen_orientation_provider.h"
11 #include "content/public/browser/web_contents.h"
12
13 namespace content {
14
15 using LockResult = blink::mojom::ScreenOrientationLockResult;
16
17 ScreenOrientation::ScreenOrientation(WebContents* web_contents)
18 : WebContentsObserver(web_contents),
19 bindings_(web_contents, this),
20 weak_factory_(this) {
21 provider_.reset(new ScreenOrientationProvider(web_contents));
22 }
23
24 ScreenOrientation::~ScreenOrientation() = default;
25
26 void ScreenOrientation::LockOrientation(
27 blink::WebScreenOrientationLockType orientation,
28 const LockOrientationCallback& callback) {
29 if (!on_result_callback_.is_null()) {
30 NotifyLockResult(
31 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
32 }
33
34 on_result_callback_ = callback;
35
36 if (!provider_) {
37 NotifyLockResult(
38 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE);
39 return;
40 }
41
42 provider_->LockOrientation(orientation,
43 base::Bind(&ScreenOrientation::NotifyLockResult,
44 base::Unretained(this)));
45 }
46
47 void ScreenOrientation::UnlockOrientation() {
48 // Cancel any pending lock request.
49 NotifyLockResult(
50 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
51
52 if (provider_)
53 provider_->UnlockOrientation();
54 }
55
56 void ScreenOrientation::DidNavigateMainFrame(
57 const LoadCommittedDetails& details,
58 const FrameNavigateParams& params) {
59 if (!provider_ || details.is_in_page)
60 return;
61 provider_->UnlockOrientation();
62 }
63
64 void ScreenOrientation::NotifyLockResult(LockResult result) {
65 if (on_result_callback_.is_null())
66 return;
67
68 base::ResetAndReturn(&on_result_callback_).Run(result);
69 }
70
71 ScreenOrientationProvider* ScreenOrientation::GetScreenOrientationProvider() {
72 return provider_.get();
73 }
74
75 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698