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 provider_->LockOrientation( |
| 36 orientation, |
| 37 base::Bind(&ScreenOrientation::NotifyLockResult, base::Unretained(this))); |
| 38 } |
| 39 |
| 40 void ScreenOrientation::UnlockOrientation() { |
| 41 // Cancel any pending lock request. |
| 42 NotifyLockResult(LockResult::SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); |
| 43 |
| 44 provider_->UnlockOrientation(); |
| 45 } |
| 46 |
| 47 void ScreenOrientation::DidNavigateMainFrame( |
| 48 const LoadCommittedDetails& details, |
| 49 const FrameNavigateParams& params) { |
| 50 if (details.is_in_page) |
| 51 return; |
| 52 provider_->UnlockOrientation(); |
| 53 } |
| 54 |
| 55 void ScreenOrientation::NotifyLockResult(LockResult result) { |
| 56 if (on_result_callback_.is_null()) |
| 57 return; |
| 58 |
| 59 base::ResetAndReturn(&on_result_callback_).Run(result); |
| 60 } |
| 61 |
| 62 ScreenOrientationProvider* ScreenOrientation::GetScreenOrientationProvider() { |
| 63 return provider_.get(); |
| 64 } |
| 65 |
| 66 } // namespace content |
OLD | NEW |