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

Unified Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2820983003: Revert of Replace requirePageReconstruction with setCustomUserAgent (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | ios/web/web_state/web_view_internal_creation_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/ui/crw_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 1f186d549373f07690ce3f2293f29be3e1d858cd..4d87b2c3da8df85af85d482cbd6a74a833044682 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -459,10 +459,8 @@
// Returns YES if the user interacted with the page recently.
@property(nonatomic, readonly) BOOL userClickedRecently;
-// User agent type of the transient item if any, the pending item if a
-// navigation is in progress or the last committed item otherwise.
-// Returns MOBILE, the default type, if navigation manager is nullptr or empty.
-@property(nonatomic, readonly) web::UserAgentType userAgentType;
+// Whether or not desktop user agent is used for the currentItem.
+@property(nonatomic, readonly) BOOL usesDesktopUserAgent;
// Facade for Mojo API.
@property(nonatomic, readonly) web::MojoFacade* mojoFacade;
@@ -479,18 +477,10 @@
// unless the request was a POST.
@property(nonatomic, readonly) NSDictionary* currentHTTPHeaders;
-// Updates web view's user agent according to |userAgentType|. It is no-op if
-// |userAgentType| is NONE.
-- (void)updateWebViewUserAgentFromUserAgentType:
- (web::UserAgentType)userAgentType;
-
-// Requires that the next load rebuild the web view. This is expensive, and
-// should be used only in the case where something has changed that web view
-// only checks on creation, such that the whole object needs to be rebuilt.
-// TODO(stuartmorgan): Merge this and reinitializeWebViewAndReload:. They are
-// currently subtly different in terms of implementation, but are for
-// fundamentally the same purpose.
-- (void)requirePageReconstruction;
+// Requires page reconstruction if |item| has a non-NONE UserAgentType and it
+// differs from that of |fromItem|.
+- (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item
+ previousUserAgentType:(web::UserAgentType)userAgentType;
// Removes the container view from the hierarchy and resets the ivar.
- (void)resetContainerView;
@@ -1626,13 +1616,6 @@
[self ensureWebViewCreated];
- // Update web view's user agent is called for every load, which may have
- // performance implications because update web view's user agent may
- // potentially send a message to a separate thread. However, this is not an
- // issue for WKWebView because WKWebView's |setCustomUserAgent| is non-op if
- // user agent stays thesame.
- [self updateWebViewUserAgentFromUserAgentType:self.userAgentType];
-
[self loadRequestForCurrentNavigationItem];
}
@@ -2043,11 +2026,15 @@
// Update the user agent before attempting the navigation.
web::NavigationItem* toItem = items[index].get();
- [self updateWebViewUserAgentFromUserAgentType:toItem->GetUserAgentType()];
-
- web::NavigationItem* fromItem = sessionController.currentItem;
+ web::NavigationItem* previousItem = sessionController.currentItem;
+ web::UserAgentType previousUserAgentType =
+ previousItem ? previousItem->GetUserAgentType()
+ : web::UserAgentType::NONE;
+ [self updateDesktopUserAgentForItem:toItem
+ previousUserAgentType:previousUserAgentType];
+
BOOL sameDocumentNavigation =
- [sessionController isSameDocumentNavigationBetweenItem:fromItem
+ [sessionController isSameDocumentNavigationBetweenItem:previousItem
andItem:toItem];
if (sameDocumentNavigation) {
[sessionController goToItemAtIndex:index];
@@ -2202,9 +2189,9 @@
return rendererInitiatedWithoutInteraction || noNavigationItems;
}
-- (web::UserAgentType)userAgentType {
+- (BOOL)usesDesktopUserAgent {
web::NavigationItem* item = self.currentNavItem;
- return item ? item->GetUserAgentType() : web::UserAgentType::MOBILE;
+ return item && item->GetUserAgentType() == web::UserAgentType::DESKTOP;
}
- (web::MojoFacade*)mojoFacade {
@@ -2243,14 +2230,15 @@
return _passKitDownloader.get();
}
-- (void)updateWebViewUserAgentFromUserAgentType:
- (web::UserAgentType)userAgentType {
- if (userAgentType == web::UserAgentType::NONE)
- return;
-
- NSString* userAgent =
- base::SysUTF8ToNSString(web::GetWebClient()->GetUserAgent(userAgentType));
- [_webView setCustomUserAgent:userAgent];
+- (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item
+ previousUserAgentType:(web::UserAgentType)userAgentType {
+ if (!item)
+ return;
+ web::UserAgentType itemUserAgentType = item->GetUserAgentType();
+ if (itemUserAgentType == web::UserAgentType::NONE)
+ return;
+ if (itemUserAgentType != userAgentType)
+ [self requirePageReconstruction];
}
#pragma mark -
@@ -4052,7 +4040,7 @@
// delegate must be specified.
return web::BuildWKWebView(CGRectZero, config,
self.webStateImpl->GetBrowserState(),
- self.userAgentType);
+ self.usesDesktopUserAgent);
}
- (void)setWebView:(WKWebView*)webView {
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller.h ('k') | ios/web/web_state/web_view_internal_creation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698