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

Side by Side Diff: content/public/browser/screen_orientation_provider.cc

Issue 2649823002: [ScreenOrientation] Merge ScreenOrientation into ScreenOrientationProvider. (Closed)
Patch Set: Fix tests Created 3 years, 10 months 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/browser/screen_orientation_provider.h" 5 #include "content/public/browser/screen_orientation_provider.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/render_widget_host.h" 10 #include "content/public/browser/render_widget_host.h"
11 #include "content/public/browser/screen_orientation_delegate.h" 11 #include "content/public/browser/screen_orientation_delegate.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationError.h" 13 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationError.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 using device::mojom::ScreenOrientationLockResult; 17 using device::mojom::ScreenOrientationLockResult;
18 18
19 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; 19 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr;
20 20
21 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) 21 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents)
22 : WebContentsObserver(web_contents), lock_applied_(false) {} 22 : WebContentsObserver(web_contents),
23 lock_applied_(false),
24 bindings_(web_contents, this) {}
23 25
24 ScreenOrientationProvider::~ScreenOrientationProvider() { 26 ScreenOrientationProvider::~ScreenOrientationProvider() {
25 } 27 }
26 28
27 void ScreenOrientationProvider::LockOrientation( 29 void ScreenOrientationProvider::LockOrientation(
28 blink::WebScreenOrientationLockType orientation, 30 blink::WebScreenOrientationLockType orientation,
29 const LockOrientationCallback& callback) { 31 const LockOrientationCallback& callback) {
30 // Cancel any pending lock request. 32 // Cancel any pending lock request.
31 NotifyLockResult(ScreenOrientationLockResult:: 33 NotifyLockResult(ScreenOrientationLockResult::
32 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); 34 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 101
100 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) { 102 if (LockMatchesCurrentOrientation(pending_lock_orientation_.value())) {
101 DCHECK(!pending_callback_.is_null()); 103 DCHECK(!pending_callback_.is_null());
102 NotifyLockResult( 104 NotifyLockResult(
103 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS); 105 ScreenOrientationLockResult::SCREEN_ORIENTATION_LOCK_RESULT_SUCCESS);
104 } 106 }
105 } 107 }
106 108
107 void ScreenOrientationProvider::NotifyLockResult( 109 void ScreenOrientationProvider::NotifyLockResult(
108 ScreenOrientationLockResult result) { 110 ScreenOrientationLockResult result) {
109 if (!pending_callback_.is_null()) { 111 if (!pending_callback_.is_null())
110 base::ResetAndReturn(&pending_callback_).Run(result); 112 base::ResetAndReturn(&pending_callback_).Run(result);
111 } 113
112 pending_lock_orientation_.reset(); 114 pending_lock_orientation_.reset();
113 } 115 }
114 116
115 void ScreenOrientationProvider::SetDelegate( 117 void ScreenOrientationProvider::SetDelegate(
116 ScreenOrientationDelegate* delegate) { 118 ScreenOrientationDelegate* delegate) {
117 delegate_ = delegate; 119 delegate_ = delegate;
118 } 120 }
119 121
120 void ScreenOrientationProvider::DidToggleFullscreenModeForTab( 122 void ScreenOrientationProvider::DidToggleFullscreenModeForTab(
121 bool entered_fullscreen, bool will_cause_resize) { 123 bool entered_fullscreen, bool will_cause_resize) {
122 if (!lock_applied_ || !delegate_) 124 if (!lock_applied_ || !delegate_)
123 return; 125 return;
124 126
125 // If fullscreen is not required in order to lock orientation, don't unlock 127 // If fullscreen is not required in order to lock orientation, don't unlock
126 // when fullscreen state changes. 128 // when fullscreen state changes.
127 if (!delegate_->FullScreenRequired(web_contents())) 129 if (!delegate_->FullScreenRequired(web_contents()))
128 return; 130 return;
129 131
130 DCHECK(!entered_fullscreen); 132 DCHECK(!entered_fullscreen);
131 UnlockOrientation(); 133 UnlockOrientation();
132 } 134 }
133 135
136 void ScreenOrientationProvider::DidNavigateMainFrame(
137 const LoadCommittedDetails& details,
138 const FrameNavigateParams& params) {
139 if (details.is_in_page)
140 return;
141 UnlockOrientation();
142 }
143
134 blink::WebScreenOrientationLockType 144 blink::WebScreenOrientationLockType
135 ScreenOrientationProvider::GetNaturalLockType() const { 145 ScreenOrientationProvider::GetNaturalLockType() const {
136 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); 146 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget();
137 if (!rwh) 147 if (!rwh)
138 return blink::WebScreenOrientationLockDefault; 148 return blink::WebScreenOrientationLockDefault;
139 149
140 ScreenInfo screen_info; 150 ScreenInfo screen_info;
141 rwh->GetScreenInfo(&screen_info); 151 rwh->GetScreenInfo(&screen_info);
142 152
143 switch (screen_info.orientation_type) { 153 switch (screen_info.orientation_type) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 case blink::WebScreenOrientationLockDefault: 211 case blink::WebScreenOrientationLockDefault:
202 NOTREACHED(); 212 NOTREACHED();
203 return false; 213 return false;
204 } 214 }
205 215
206 NOTREACHED(); 216 NOTREACHED();
207 return false; 217 return false;
208 } 218 }
209 219
210 } // namespace content 220 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698