| 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 {
|
|
|