OLD | NEW |
---|---|
(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(LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | |
31 } | |
32 | |
33 on_result_callback_ = callback; | |
34 | |
35 if (!provider_) { | |
pfeldman
2016/11/21 21:30:25
This is never the case.
lunalu1
2016/11/21 21:40:51
Done.
| |
36 NotifyLockResult( | |
37 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); | |
38 return; | |
39 } | |
40 | |
41 provider_->LockOrientation( | |
42 orientation, | |
43 base::Bind(&ScreenOrientation::NotifyLockResult, base::Unretained(this))); | |
44 } | |
45 | |
46 void ScreenOrientation::UnlockOrientation() { | |
47 // Cancel any pending lock request. | |
48 NotifyLockResult(LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | |
49 | |
50 if (provider_) | |
pfeldman
2016/11/21 21:30:26
Always true
lunalu1
2016/11/21 21:40:51
Done.
| |
51 provider_->UnlockOrientation(); | |
52 } | |
53 | |
54 void ScreenOrientation::DidNavigateMainFrame( | |
55 const LoadCommittedDetails& details, | |
56 const FrameNavigateParams& params) { | |
57 if (!provider_ || details.is_in_page) | |
pfeldman
2016/11/21 21:30:25
useless check.
lunalu1
2016/11/21 21:40:51
Done.
| |
58 return; | |
59 provider_->UnlockOrientation(); | |
60 } | |
61 | |
62 void ScreenOrientation::NotifyLockResult(LockResult result) { | |
63 if (on_result_callback_.is_null()) | |
64 return; | |
65 | |
66 base::ResetAndReturn(&on_result_callback_).Run(result); | |
67 } | |
68 | |
69 ScreenOrientationProvider* ScreenOrientation::GetScreenOrientationProvider() { | |
70 return provider_.get(); | |
71 } | |
72 | |
73 } // namespace content | |
OLD | NEW |