Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/tabs/tab.h" | 5 #import "ios/chrome/browser/tabs/tab.h" |
| 6 | 6 |
| 7 #import <CoreLocation/CoreLocation.h> | 7 #import <CoreLocation/CoreLocation.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 BACKGROUND_TAB_BACKGROUND_APP, | 191 BACKGROUND_TAB_BACKGROUND_APP, |
| 192 TERMINATION_TAB_STATE_COUNT | 192 TERMINATION_TAB_STATE_COUNT |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 // Returns true if the application is in the background or inactive state. | 195 // Returns true if the application is in the background or inactive state. |
| 196 bool IsApplicationStateNotActive(UIApplicationState state) { | 196 bool IsApplicationStateNotActive(UIApplicationState state) { |
| 197 return (state == UIApplicationStateBackground || | 197 return (state == UIApplicationStateBackground || |
| 198 state == UIApplicationStateInactive); | 198 state == UIApplicationStateInactive); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // Returns true if |item| is the result of a HTTP redirect. | |
| 202 // Returns false if |item| is nullptr; | |
| 203 bool IsItemRedirectItem(web::NavigationItem* item) { | |
| 204 if (!item) | |
| 205 return false; | |
| 206 | |
| 207 return (ui::PageTransition::PAGE_TRANSITION_IS_REDIRECT_MASK & | |
| 208 item->GetTransitionType()) == 0; | |
| 209 } | |
| 201 } // namespace | 210 } // namespace |
| 202 | 211 |
| 203 @interface Tab ()<CRWWebStateObserver, | 212 @interface Tab ()<CRWWebStateObserver, |
| 204 CRWWebControllerObserver, | 213 CRWWebControllerObserver, |
| 205 FindInPageControllerDelegate, | 214 FindInPageControllerDelegate, |
| 206 ReaderModeControllerDelegate> { | 215 ReaderModeControllerDelegate> { |
| 207 TabModel* parentTabModel_; // weak | 216 TabModel* parentTabModel_; // weak |
| 208 ios::ChromeBrowserState* browserState_; // weak | 217 ios::ChromeBrowserState* browserState_; // weak |
| 209 | 218 |
| 210 base::scoped_nsobject<OpenInController> openInController_; | 219 base::scoped_nsobject<OpenInController> openInController_; |
| (...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1351 | 1360 |
| 1352 - (BOOL)usesDesktopUserAgent { | 1361 - (BOOL)usesDesktopUserAgent { |
| 1353 if (!self.navigationManager) | 1362 if (!self.navigationManager) |
| 1354 return NO; | 1363 return NO; |
| 1355 | 1364 |
| 1356 web::NavigationItem* visibleItem = self.navigationManager->GetVisibleItem(); | 1365 web::NavigationItem* visibleItem = self.navigationManager->GetVisibleItem(); |
| 1357 return visibleItem && | 1366 return visibleItem && |
| 1358 visibleItem->GetUserAgentType() == web::UserAgentType::DESKTOP; | 1367 visibleItem->GetUserAgentType() == web::UserAgentType::DESKTOP; |
| 1359 } | 1368 } |
| 1360 | 1369 |
| 1361 - (void)reloadForDesktopUserAgent { | 1370 - (void)reloadWithUserAgentType:(web::UserAgentType)userAgentType { |
| 1362 // This removes the web view, which will be recreated at the end of this. | 1371 // This removes the web view, which will be recreated at the end of this. |
| 1363 [self.webController requirePageReconstruction]; | 1372 [self.webController requirePageReconstruction]; |
| 1364 | 1373 |
| 1365 // TODO(crbug.com/228171): A hack in session_controller -addPendingItem | 1374 // TODO(crbug.com/228171): A hack in session_controller -addPendingItem |
| 1366 // discusses making tab responsible for distinguishing history stack | 1375 // discusses making tab responsible for distinguishing history stack |
| 1367 // navigation from new navigations. | 1376 // navigation from new navigations. |
| 1368 web::NavigationManager* navigationManager = [self navigationManager]; | 1377 web::NavigationManager* navigationManager = [self navigationManager]; |
| 1369 DCHECK(navigationManager); | 1378 DCHECK(navigationManager); |
| 1370 web::NavigationItem* lastNonRedirectedItem = | 1379 |
| 1371 GetLastCommittedNonRedirectedItem(navigationManager); | 1380 web::NavigationItem* lastNonRedirectItem = |
| 1372 if (!lastNonRedirectedItem) | 1381 navigationManager->GetTransientItem(); |
| 1382 if (!lastNonRedirectItem || IsItemRedirectItem(lastNonRedirectItem)) | |
| 1383 lastNonRedirectItem = navigationManager->GetPendingItem(); | |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:56
Should this be GetVisibleItem instead? Pending url
liaoyuke
2017/04/11 18:27:20
Good catch!
| |
| 1384 if (!lastNonRedirectItem || IsItemRedirectItem(lastNonRedirectItem)) | |
| 1385 lastNonRedirectItem = GetLastCommittedNonRedirectedItem(navigationManager); | |
| 1386 | |
| 1387 if (!lastNonRedirectItem) | |
| 1373 return; | 1388 return; |
| 1374 | 1389 |
| 1375 // |reloadURL| will be empty if a page was open by DOM. | 1390 // |reloadURL| will be empty if a page was open by DOM. |
| 1376 GURL reloadURL(lastNonRedirectedItem->GetOriginalRequestURL()); | 1391 GURL reloadURL(lastNonRedirectItem->GetOriginalRequestURL()); |
| 1377 if (reloadURL.is_empty()) { | 1392 if (reloadURL.is_empty()) { |
| 1378 DCHECK(self.webState && self.webState->HasOpener()); | 1393 DCHECK(self.webState && self.webState->HasOpener()); |
| 1379 reloadURL = lastNonRedirectedItem->GetVirtualURL(); | 1394 reloadURL = lastNonRedirectItem->GetVirtualURL(); |
| 1380 } | 1395 } |
| 1381 | 1396 |
| 1382 web::NavigationManager::WebLoadParams params(reloadURL); | 1397 web::NavigationManager::WebLoadParams params(reloadURL); |
| 1383 params.referrer = lastNonRedirectedItem->GetReferrer(); | 1398 params.referrer = lastNonRedirectItem->GetReferrer(); |
| 1384 // A new navigation is needed here for reloading with desktop User-Agent. | 1399 params.transition_type = ui::PAGE_TRANSITION_RELOAD; |
| 1385 params.user_agent_override_option = | 1400 |
| 1386 web::NavigationManager::UserAgentOverrideOption::DESKTOP; | 1401 switch (userAgentType) { |
| 1387 params.transition_type = | 1402 case web::UserAgentType::DESKTOP: |
| 1388 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_FORM_SUBMIT); | 1403 params.user_agent_override_option = |
| 1404 web::NavigationManager::UserAgentOverrideOption::DESKTOP; | |
| 1405 break; | |
| 1406 case web::UserAgentType::MOBILE: | |
| 1407 params.user_agent_override_option = | |
| 1408 web::NavigationManager::UserAgentOverrideOption::MOBILE; | |
| 1409 break; | |
| 1410 case web::UserAgentType::NONE: | |
| 1411 NOTREACHED(); | |
| 1412 } | |
| 1413 | |
| 1389 navigationManager->LoadURLWithParams(params); | 1414 navigationManager->LoadURLWithParams(params); |
| 1390 } | 1415 } |
| 1391 | 1416 |
| 1392 - (id<SnapshotOverlayProvider>)snapshotOverlayProvider { | 1417 - (id<SnapshotOverlayProvider>)snapshotOverlayProvider { |
| 1393 return snapshotOverlayProvider_.get(); | 1418 return snapshotOverlayProvider_.get(); |
| 1394 } | 1419 } |
| 1395 | 1420 |
| 1396 - (void)setSnapshotOverlayProvider: | 1421 - (void)setSnapshotOverlayProvider: |
| 1397 (id<SnapshotOverlayProvider>)snapshotOverlayProvider { | 1422 (id<SnapshotOverlayProvider>)snapshotOverlayProvider { |
| 1398 snapshotOverlayProvider_.reset(snapshotOverlayProvider); | 1423 snapshotOverlayProvider_.reset(snapshotOverlayProvider); |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1960 | 1985 |
| 1961 - (TabModel*)parentTabModel { | 1986 - (TabModel*)parentTabModel { |
| 1962 return parentTabModel_; | 1987 return parentTabModel_; |
| 1963 } | 1988 } |
| 1964 | 1989 |
| 1965 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 1990 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 1966 return inputAccessoryViewController_.get(); | 1991 return inputAccessoryViewController_.get(); |
| 1967 } | 1992 } |
| 1968 | 1993 |
| 1969 @end | 1994 @end |
| OLD | NEW |