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 4d87b2c3da8df85af85d482cbd6a74a833044682..229a1c77fe2b78196469381a39ca1a4c82b9e860 100644 |
--- a/ios/web/web_state/ui/crw_web_controller.mm |
+++ b/ios/web/web_state/ui/crw_web_controller.mm |
@@ -459,8 +459,10 @@ @interface CRWWebController ()<CRWContextMenuDelegate, |
// Returns YES if the user interacted with the page recently. |
@property(nonatomic, readonly) BOOL userClickedRecently; |
-// Whether or not desktop user agent is used for the currentItem. |
-@property(nonatomic, readonly) BOOL usesDesktopUserAgent; |
+// 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; |
// Facade for Mojo API. |
@property(nonatomic, readonly) web::MojoFacade* mojoFacade; |
@@ -477,10 +479,10 @@ @interface CRWWebController ()<CRWContextMenuDelegate, |
// unless the request was a POST. |
@property(nonatomic, readonly) NSDictionary* currentHTTPHeaders; |
-// 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; |
+// Updates the user agent used to make HTTP request if |item|'s user agent type |
+// is not NONE and has changed. |
+- (void)updateUserAgentForItem:(web::NavigationItem*)item |
Eugene But (OOO till 7-30)
2017/04/12 18:22:02
updateWebViewUserAgentFromItem: ?
liaoyuke
2017/04/12 19:17:59
Thanks! that's even better, and after looking at t
|
+ previousUserAgentType:(web::UserAgentType)previousUserAgentType; |
// Removes the container view from the hierarchy and resets the ivar. |
- (void)resetContainerView; |
@@ -1616,6 +1618,10 @@ - (void)loadCurrentURLInWebView { |
[self ensureWebViewCreated]; |
+ NSString* userAgent = base::SysUTF8ToNSString( |
+ web::GetWebClient()->GetUserAgent(self.userAgentType)); |
+ [_webView setCustomUserAgent:userAgent]; |
Eugene But (OOO till 7-30)
2017/04/12 18:22:02
Are there any performance implications in calling
liaoyuke
2017/04/12 19:17:59
That is a very good question. I'm not sure how WKW
Eugene But (OOO till 7-30)
2017/04/13 00:34:06
WKWebView code is open source, so it should not be
liaoyuke
2017/04/13 23:03:53
Sorry, forgot to reply. I was only able to find th
Eugene But (OOO till 7-30)
2017/04/14 00:19:53
WKWebView source code:
https://trac.webkit.org/bro
|
+ |
[self loadRequestForCurrentNavigationItem]; |
} |
@@ -2030,8 +2036,8 @@ - (void)goToItemAtIndex:(int)index { |
web::UserAgentType previousUserAgentType = |
previousItem ? previousItem->GetUserAgentType() |
: web::UserAgentType::NONE; |
- [self updateDesktopUserAgentForItem:toItem |
- previousUserAgentType:previousUserAgentType]; |
+ [self updateUserAgentForItem:toItem |
+ previousUserAgentType:previousUserAgentType]; |
BOOL sameDocumentNavigation = |
[sessionController isSameDocumentNavigationBetweenItem:previousItem |
@@ -2189,9 +2195,11 @@ - (BOOL)shouldClosePageOnNativeApplicationLoad { |
return rendererInitiatedWithoutInteraction || noNavigationItems; |
} |
-- (BOOL)usesDesktopUserAgent { |
- web::NavigationItem* item = self.currentNavItem; |
- return item && item->GetUserAgentType() == web::UserAgentType::DESKTOP; |
+- (web::UserAgentType)userAgentType { |
+ if (!self.currentNavItem) |
Eugene But (OOO till 7-30)
2017/04/12 18:22:02
Old code with ternary could be faster
liaoyuke
2017/04/12 19:17:59
Done.
|
+ return web::UserAgentType::MOBILE; |
+ |
+ return self.currentNavItem->GetUserAgentType(); |
} |
- (web::MojoFacade*)mojoFacade { |
@@ -2230,15 +2238,19 @@ - (CRWPassKitDownloader*)passKitDownloader { |
return _passKitDownloader.get(); |
} |
-- (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item |
- previousUserAgentType:(web::UserAgentType)userAgentType { |
+- (void)updateUserAgentForItem:(web::NavigationItem*)item |
+ previousUserAgentType:(web::UserAgentType)previousUserAgentType { |
if (!item) |
return; |
- web::UserAgentType itemUserAgentType = item->GetUserAgentType(); |
- if (itemUserAgentType == web::UserAgentType::NONE) |
+ web::UserAgentType currentUserAgentType = item->GetUserAgentType(); |
Eugene But (OOO till 7-30)
2017/04/12 18:22:02
This isn't "current", right? Current is one that i
liaoyuke
2017/04/12 19:17:59
Done.
|
+ if (currentUserAgentType == web::UserAgentType::NONE) |
return; |
- if (itemUserAgentType != userAgentType) |
- [self requirePageReconstruction]; |
+ |
+ if (currentUserAgentType != previousUserAgentType) { |
+ NSString* currentUserAgent = base::SysUTF8ToNSString( |
Eugene But (OOO till 7-30)
2017/04/12 18:22:02
ditto
liaoyuke
2017/04/12 19:17:59
Done.
|
+ web::GetWebClient()->GetUserAgent(currentUserAgentType)); |
+ [_webView setCustomUserAgent:currentUserAgent]; |
+ } |
} |
#pragma mark - |
@@ -4040,7 +4052,7 @@ - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { |
// delegate must be specified. |
return web::BuildWKWebView(CGRectZero, config, |
self.webStateImpl->GetBrowserState(), |
- self.usesDesktopUserAgent); |
+ self.userAgentType); |
} |
- (void)setWebView:(WKWebView*)webView { |