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

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

Issue 2811073005: Replace requirePageReconstruction with setCustomUserAgent (Closed)
Patch Set: Address comments 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 4d87b2c3da8df85af85d482cbd6a74a833044682..e90658afbe79f6af60186778fa8f9b5b3279a1b6 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,18 @@ @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 when navigating from
+// |fromItem| to |toItem|. |toItem| must not be nullptr.
+- (void)updateWebViewUserAgentFromItem:(web::NavigationItem*)fromItem
+ toItem:(web::NavigationItem*)toItem;
+
+// Requires that the next load rebuild the UIWebView. This is expensive, and
kkhorimoto 2017/04/12 19:42:28 s/UIWebView/WKWebView.
liaoyuke 2017/04/12 22:45:33 maybe web view?
+// should be used only in the case where something has changed that UIWebView
+// 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;
// Removes the container view from the hierarchy and resets the ivar.
- (void)resetContainerView;
@@ -1616,6 +1626,10 @@ - (void)loadCurrentURLInWebView {
[self ensureWebViewCreated];
+ NSString* userAgent = base::SysUTF8ToNSString(
kkhorimoto 2017/04/12 19:42:27 Can we check whether the current NavigationItem ha
liaoyuke 2017/04/12 22:45:33 How about we directly compare web view's current c
+ web::GetWebClient()->GetUserAgent(self.userAgentType));
+ [_webView setCustomUserAgent:userAgent];
+
[self loadRequestForCurrentNavigationItem];
}
@@ -2026,15 +2040,11 @@ - (void)goToItemAtIndex:(int)index {
// Update the user agent before attempting the navigation.
web::NavigationItem* toItem = items[index].get();
- web::NavigationItem* previousItem = sessionController.currentItem;
- web::UserAgentType previousUserAgentType =
- previousItem ? previousItem->GetUserAgentType()
- : web::UserAgentType::NONE;
- [self updateDesktopUserAgentForItem:toItem
- previousUserAgentType:previousUserAgentType];
+ web::NavigationItem* fromItem = sessionController.currentItem;
+ [self updateWebViewUserAgentFromItem:fromItem toItem:toItem];
BOOL sameDocumentNavigation =
- [sessionController isSameDocumentNavigationBetweenItem:previousItem
+ [sessionController isSameDocumentNavigationBetweenItem:fromItem
andItem:toItem];
if (sameDocumentNavigation) {
[sessionController goToItemAtIndex:index];
@@ -2189,9 +2199,9 @@ - (BOOL)shouldClosePageOnNativeApplicationLoad {
return rendererInitiatedWithoutInteraction || noNavigationItems;
}
-- (BOOL)usesDesktopUserAgent {
+- (web::UserAgentType)userAgentType {
web::NavigationItem* item = self.currentNavItem;
- return item && item->GetUserAgentType() == web::UserAgentType::DESKTOP;
+ return item ? item->GetUserAgentType() : web::UserAgentType::MOBILE;
}
- (web::MojoFacade*)mojoFacade {
@@ -2230,15 +2240,19 @@ - (CRWPassKitDownloader*)passKitDownloader {
return _passKitDownloader.get();
}
-- (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item
- previousUserAgentType:(web::UserAgentType)userAgentType {
- if (!item)
- return;
- web::UserAgentType itemUserAgentType = item->GetUserAgentType();
- if (itemUserAgentType == web::UserAgentType::NONE)
+- (void)updateWebViewUserAgentFromItem:(web::NavigationItem*)fromItem
+ toItem:(web::NavigationItem*)toItem {
+ DCHECK(toItem);
+
+ web::UserAgentType toUserAgentType = toItem->GetUserAgentType();
+ if (toUserAgentType == web::UserAgentType::NONE)
return;
- if (itemUserAgentType != userAgentType)
- [self requirePageReconstruction];
+
+ if (!fromItem || fromItem->GetUserAgentType() != toUserAgentType) {
+ NSString* toUserAgent = base::SysUTF8ToNSString(
+ web::GetWebClient()->GetUserAgent(toUserAgentType));
+ [_webView setCustomUserAgent:toUserAgent];
+ }
}
#pragma mark -
@@ -4040,7 +4054,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 {
« 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