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 "content/public/browser/navigation_details.h" | |
9 #include "content/public/browser/screen_orientation_provider.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 | |
12 namespace content { | |
13 | |
14 using LockResult = ::blink::mojom::ScreenOrientationLockResult; | |
15 | |
16 ScreenOrientation::ScreenOrientation(WebContents* web_contents) | |
17 : WebContentsObserver(web_contents), | |
18 bindings_(web_contents, this), | |
19 weak_factory_(this) { | |
20 provider_.reset(new ScreenOrientationProvider(web_contents)); | |
21 } | |
22 | |
23 ScreenOrientation::~ScreenOrientation() = default; | |
24 | |
25 void ScreenOrientation::LockOrientation( | |
26 blink::WebScreenOrientationLockType orientation, | |
27 const LockOrientationCallback& callback) { | |
28 if (!on_result_callback_.is_null()) { | |
29 NotifyLockResult( | |
30 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | |
31 } | |
32 | |
33 on_result_callback_ = callback; | |
34 | |
35 if (!provider_) { | |
36 NotifyLockResult( | |
37 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_NOT_AVAILABLE); | |
38 return; | |
39 } | |
40 | |
41 provider_->LockOrientation(orientation, | |
42 base::Bind(&ScreenOrientation::NotifyLockResult, | |
43 base::Unretained(this))); | |
44 } | |
45 | |
46 void ScreenOrientation::UnlockOrientation() { | |
47 // Cancel any pending lock request. | |
48 NotifyLockResult( | |
49 LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); | |
50 | |
51 if (provider_) | |
52 provider_->UnlockOrientation(); | |
53 } | |
54 | |
55 void ScreenOrientation::DidNavigateMainFrame( | |
56 const LoadCommittedDetails& details, | |
57 const FrameNavigateParams& params) { | |
58 if (!provider_ || details.is_in_page) | |
59 return; | |
60 provider_->UnlockOrientation(); | |
61 } | |
62 | |
63 void ScreenOrientation::NotifyLockResult(LockResult result) { | |
64 if (on_result_callback_.is_null()) | |
65 return; | |
66 | |
67 on_result_callback_.Run(result); | |
68 // Reset the callback. | |
69 on_result_callback_ = LockOrientationCallback(); | |
mlamouri (slow - plz ping)
2016/11/13 00:26:35
`base::ResetAndReturn(&on_result_callback_).Run(re
lunalu1
2016/11/16 18:46:58
Done.
| |
70 } | |
71 | |
72 ScreenOrientationProvider* ScreenOrientation::GetScreenOrientationProvider() { | |
73 return provider_.get(); | |
74 } | |
75 | |
76 } // namespace content | |
OLD | NEW |