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

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

Issue 2685513002: [For trybots test] [ScreenOrientation] Hide ScreenOrientationProvider inside WebContentsImpl. (Closed)
Patch Set: Fix android bots 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/render_widget_host.h" 11 #include "content/public/browser/render_widget_host.h"
11 #include "content/public/browser/screen_orientation_delegate.h" 12 #include "content/public/browser/screen_orientation_delegate.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #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"
14 15
15 namespace content { 16 namespace content {
16 17
17 using device::mojom::ScreenOrientationLockResult; 18 using device::mojom::ScreenOrientationLockResult;
18 19
19 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr; 20 ScreenOrientationDelegate* ScreenOrientationProvider::delegate_ = nullptr;
20 21
21 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents) 22 ScreenOrientationProvider::ScreenOrientationProvider(WebContents* web_contents)
22 : WebContentsObserver(web_contents), lock_applied_(false) {} 23 : WebContentsObserver(web_contents),
24 lock_applied_(false),
25 bindings_(web_contents, this) {}
23 26
24 ScreenOrientationProvider::~ScreenOrientationProvider() { 27 ScreenOrientationProvider::~ScreenOrientationProvider() = default;
25 }
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);
33 // Record new pending lock request. 35 // Record new pending lock request.
34 pending_callback_ = callback; 36 pending_callback_ = callback;
35 37
(...skipping 63 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,
124 bool will_cause_resize) {
122 if (!lock_applied_ || !delegate_) 125 if (!lock_applied_ || !delegate_)
123 return; 126 return;
124 127
125 // 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
126 // when fullscreen state changes. 129 // when fullscreen state changes.
127 if (!delegate_->FullScreenRequired(web_contents())) 130 if (!delegate_->FullScreenRequired(web_contents()))
128 return; 131 return;
129 132
130 DCHECK(!entered_fullscreen); 133 DCHECK(!entered_fullscreen);
131 UnlockOrientation(); 134 UnlockOrientation();
132 } 135 }
133 136
137 void ScreenOrientationProvider::DidFinishNavigation(
138 NavigationHandle* navigation_handle) {
139 if (!navigation_handle->IsInMainFrame() ||
140 !navigation_handle->HasCommitted() || navigation_handle->IsSamePage()) {
141 return;
142 }
143 UnlockOrientation();
144 }
145
134 blink::WebScreenOrientationLockType 146 blink::WebScreenOrientationLockType
135 ScreenOrientationProvider::GetNaturalLockType() const { 147 ScreenOrientationProvider::GetNaturalLockType() const {
136 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); 148 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget();
137 if (!rwh) 149 if (!rwh)
138 return blink::WebScreenOrientationLockDefault; 150 return blink::WebScreenOrientationLockDefault;
139 151
140 ScreenInfo screen_info; 152 ScreenInfo screen_info;
141 rwh->GetScreenInfo(&screen_info); 153 rwh->GetScreenInfo(&screen_info);
142 154
143 switch (screen_info.orientation_type) { 155 switch (screen_info.orientation_type) {
144 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY: 156 case SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY:
145 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY: 157 case SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY:
(...skipping 22 matching lines...) Expand all
168 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget(); 180 RenderWidgetHost* rwh = web_contents()->GetRenderViewHost()->GetWidget();
169 if (!rwh) 181 if (!rwh)
170 return false; 182 return false;
171 183
172 ScreenInfo screen_info; 184 ScreenInfo screen_info;
173 rwh->GetScreenInfo(&screen_info); 185 rwh->GetScreenInfo(&screen_info);
174 186
175 switch (lock) { 187 switch (lock) {
176 case blink::WebScreenOrientationLockPortraitPrimary: 188 case blink::WebScreenOrientationLockPortraitPrimary:
177 return screen_info.orientation_type == 189 return screen_info.orientation_type ==
178 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY; 190 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY;
179 case blink::WebScreenOrientationLockPortraitSecondary: 191 case blink::WebScreenOrientationLockPortraitSecondary:
180 return screen_info.orientation_type == 192 return screen_info.orientation_type ==
181 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY; 193 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY;
182 case blink::WebScreenOrientationLockLandscapePrimary: 194 case blink::WebScreenOrientationLockLandscapePrimary:
183 return screen_info.orientation_type == 195 return screen_info.orientation_type ==
184 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY; 196 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY;
185 case blink::WebScreenOrientationLockLandscapeSecondary: 197 case blink::WebScreenOrientationLockLandscapeSecondary:
186 return screen_info.orientation_type == 198 return screen_info.orientation_type ==
187 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY; 199 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY;
188 case blink::WebScreenOrientationLockLandscape: 200 case blink::WebScreenOrientationLockLandscape:
189 return screen_info.orientation_type == 201 return screen_info.orientation_type ==
190 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY || 202 SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY ||
191 screen_info.orientation_type == 203 screen_info.orientation_type ==
192 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY; 204 SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY;
193 case blink::WebScreenOrientationLockPortrait: 205 case blink::WebScreenOrientationLockPortrait:
194 return screen_info.orientation_type == 206 return screen_info.orientation_type ==
195 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY || 207 SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY ||
196 screen_info.orientation_type == 208 screen_info.orientation_type ==
197 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY; 209 SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY;
198 case blink::WebScreenOrientationLockAny: 210 case blink::WebScreenOrientationLockAny:
199 return true; 211 return true;
200 case blink::WebScreenOrientationLockNatural: 212 case blink::WebScreenOrientationLockNatural:
201 case blink::WebScreenOrientationLockDefault: 213 case blink::WebScreenOrientationLockDefault:
202 NOTREACHED(); 214 NOTREACHED();
203 return false; 215 return false;
204 } 216 }
205 217
206 NOTREACHED(); 218 NOTREACHED();
207 return false; 219 return false;
208 } 220 }
209 221
210 } // namespace content 222 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698