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

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

Issue 2682643002: [ScreenOrientation] Hide ScreenOrientationProvider inside WebContentsImpl. (Closed)
Patch Set: Rebase only 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/browser/screen_orientation/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/navigation_handle.h" 10 #include "content/public/browser/navigation_handle.h"
11 #include "content/public/browser/render_widget_host.h" 11 #include "content/public/browser/render_widget_host.h"
12 #include "content/public/browser/screen_orientation_delegate.h" 12 #include "content/public/browser/screen_orientation_delegate.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationError.h" 14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebLockO rientationError.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 using device::mojom::ScreenOrientationLockResult; 18 using device::mojom::ScreenOrientationLockResult;
19 19
20 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; 20 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr;
21 21
22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) 22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents)
23 : WebContentsObserver(web_contents), 23 : WebContentsObserver(web_contents),
24 lock_applied_(false), 24 lock_applied_(false),
25 bindings_(web_contents, this) {} 25 bindings_(web_contents, this) {}
26 26
27 ScreenOrientationProvider::~ScreenOrientationProvider() { 27 ScreenOrientationProvider::~ScreenOrientationProvider() = default;
28 }
29 28
30 void ScreenOrientationProvider::LockOrientation( 29 void ScreenOrientationProvider::LockOrientation(
31 blink::WebScreenOrientationLockType orientation, 30 blink::WebScreenOrientationLockType orientation,
32 const LockOrientationCallback& callback) { 31 const LockOrientationCallback& callback) {
33 // Cancel any pending lock request. 32 // Cancel any pending lock request.
34 NotifyLockResult(ScreenOrientationLockResult:: 33 NotifyLockResult(ScreenOrientationLockResult::
35 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED); 34 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED);
36 // Record new pending lock request. 35 // Record new pending lock request.
37 pending_callback_ = callback; 36 pending_callback_ = callback;
38 37
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 113
115 pending_lock_orientation_.reset(); 114 pending_lock_orientation_.reset();
116 } 115 }
117 116
118 void ScreenOrientationProvider::SetDelegate( 117 void ScreenOrientationProvider::SetDelegate(
119 ScreenOrientationDelegate* delegate) { 118 ScreenOrientationDelegate* delegate) {
120 delegate_ = delegate; 119 delegate_ = delegate;
121 } 120 }
122 121
123 void ScreenOrientationProvider::DidToggleFullscreenModeForTab( 122 void ScreenOrientationProvider::DidToggleFullscreenModeForTab(
124 bool entered_fullscreen, bool will_cause_resize) { 123 bool entered_fullscreen,
124 bool will_cause_resize) {
125 if (!lock_applied_ || !delegate_) 125 if (!lock_applied_ || !delegate_)
126 return; 126 return;
127 127
128 // If fullscreen is not required in order to lock orientation, don't unlock 128 // If fullscreen is not required in order to lock orientation, don't unlock
129 // when fullscreen state changes. 129 // when fullscreen state changes.
130 if (!delegate_->FullScreenRequired(web_contents())) 130 if (!delegate_->FullScreenRequired(web_contents()))
131 return; 131 return;
132 132
133 DCHECK(!entered_fullscreen); 133 DCHECK(!entered_fullscreen);
134 UnlockOrientation(); 134 UnlockOrientation();
135 } 135 }
136 136
137 void ScreenOrientationProvider::DidFinishNavigation( 137 void ScreenOrientationProvider::DidFinishNavigation(
138 NavigationHandle* navigation_handle) { 138 NavigationHandle* navigation_handle) {
139 if (!navigation_handle->IsInMainFrame() || 139 if (!navigation_handle->IsInMainFrame() ||
140 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) { 140 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) {
141 return; 141 return;
142 } 142 }
143 UnlockOrientation(); 143 UnlockOrientation();
144 } 144 }
145 145
146 blink::WebScreenOrientationLockType 146 blink::WebScreenOrientationLockType
147 ScreenOrientationProvider::GetNaturalLockType() const { 147 ScreenOrientationProvider::GetNaturalLockType() const {
148 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); 148 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget();
149 if (!rwh) 149 if (!rwh)
150 return blink::WebScreenOrientationLockDefault; 150 return blink::WebScreenOrientationLockDefault;
151 151
152 ScreenInfo screen_info; 152 ScreenInfo screen_info;
153 rwh->GetScreenInfo(&screen_info); 153 rwh->GetScreenInfo(&screen_info);
154 154
155 switch (screen_info.orientation_type) { 155 switch (screen_info.orientation_type) {
156 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY: 156 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
157 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY: 157 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
(...skipping 22 matching lines...) Expand all
180 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); 180 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget();
181 if (!rwh) 181 if (!rwh)
182 return false; 182 return false;
183 183
184 ScreenInfo screen_info; 184 ScreenInfo screen_info;
185 rwh->GetScreenInfo(&screen_info); 185 rwh->GetScreenInfo(&screen_info);
186 186
187 switch (lock) { 187 switch (lock) {
188 case blink::WebScreenOrientationLockPortraitPrimary: 188 case blink::WebScreenOrientationLockPortraitPrimary:
189 return screen_info.orientation_type == 189 return screen_info.orientation_type ==
190 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY; 190 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY;
191 case blink::WebScreenOrientationLockPortraitSecondary: 191 case blink::WebScreenOrientationLockPortraitSecondary:
192 return screen_info.orientation_type == 192 return screen_info.orientation_type ==
193 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY; 193 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY;
194 case blink::WebScreenOrientationLockLandscapePrimary: 194 case blink::WebScreenOrientationLockLandscapePrimary:
195 return screen_info.orientation_type == 195 return screen_info.orientation_type ==
196 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY; 196 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY;
197 case blink::WebScreenOrientationLockLandscapeSecondary: 197 case blink::WebScreenOrientationLockLandscapeSecondary:
198 return screen_info.orientation_type == 198 return screen_info.orientation_type ==
199 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY; 199 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY;
200 case blink::WebScreenOrientationLockLandscape: 200 case blink::WebScreenOrientationLockLandscape:
201 return screen_info.orientation_type == 201 return screen_info.orientation_type ==
202 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY || 202 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY ||
203 screen_info.orientation_type == 203 screen_info.orientation_type ==
204 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY; 204 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY;
205 case blink::WebScreenOrientationLockPortrait: 205 case blink::WebScreenOrientationLockPortrait:
206 return screen_info.orientation_type == 206 return screen_info.orientation_type ==
207 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY || 207 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY ||
208 screen_info.orientation_type == 208 screen_info.orientation_type ==
209 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY; 209 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY;
210 case blink::WebScreenOrientationLockAny: 210 case blink::WebScreenOrientationLockAny:
211 return true; 211 return true;
212 case blink::WebScreenOrientationLockNatural: 212 case blink::WebScreenOrientationLockNatural:
213 case blink::WebScreenOrientationLockDefault: 213 case blink::WebScreenOrientationLockDefault:
214 NOTREACHED(); 214 NOTREACHED();
215 return false; 215 return false;
216 } 216 }
217 217
218 NOTREACHED(); 218 NOTREACHED();
219 return false; 219 return false;
220 } 220 }
221 221
222 } // namespace content 222 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698