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

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2896623003: Added web::NavigationContext::GetPageTransition. (Closed)
Patch Set: Fixed condition for SetIsCreatedFromHashChange call Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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/web/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #import <objc/runtime.h> 9 #import <objc/runtime.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 // advance and use that instead. https://crbug.com/227769. 1333 // advance and use that instead. https://crbug.com/227769.
1334 return web::Referrer(GURL(base::SysNSStringToUTF8(referrerString)), 1334 return web::Referrer(GURL(base::SysNSStringToUTF8(referrerString)),
1335 web::ReferrerPolicyAlways); 1335 web::ReferrerPolicyAlways);
1336 } 1336 }
1337 1337
1338 - (void)pushStateWithPageURL:(const GURL&)pageURL 1338 - (void)pushStateWithPageURL:(const GURL&)pageURL
1339 stateObject:(NSString*)stateObject 1339 stateObject:(NSString*)stateObject
1340 transition:(ui::PageTransition)transition { 1340 transition:(ui::PageTransition)transition {
1341 std::unique_ptr<web::NavigationContextImpl> context = 1341 std::unique_ptr<web::NavigationContextImpl> context =
1342 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl, 1342 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl,
1343 pageURL); 1343 pageURL, transition);
1344 _webStateImpl->OnNavigationStarted(context.get()); 1344 _webStateImpl->OnNavigationStarted(context.get());
1345 [[self sessionController] pushNewItemWithURL:pageURL 1345 [[self sessionController] pushNewItemWithURL:pageURL
1346 stateObject:stateObject 1346 stateObject:stateObject
1347 transition:transition]; 1347 transition:transition];
1348 context->SetIsSameDocument(true); 1348 context->SetIsSameDocument(true);
1349 _webStateImpl->OnNavigationFinished(context.get()); 1349 _webStateImpl->OnNavigationFinished(context.get());
1350 self.userInteractionRegistered = NO; 1350 self.userInteractionRegistered = NO;
1351 } 1351 }
1352 1352
1353 - (void)replaceStateWithPageURL:(const GURL&)pageURL 1353 - (void)replaceStateWithPageURL:(const GURL&)pageURL
1354 stateObject:(NSString*)stateObject { 1354 stateObject:(NSString*)stateObject {
1355 std::unique_ptr<web::NavigationContextImpl> context = 1355 std::unique_ptr<web::NavigationContextImpl> context =
1356 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl, 1356 web::NavigationContextImpl::CreateNavigationContext(
1357 pageURL); 1357 _webStateImpl, pageURL,
1358 ui::PageTransition::PAGE_TRANSITION_CLIENT_REDIRECT);
1358 _webStateImpl->OnNavigationStarted(context.get()); 1359 _webStateImpl->OnNavigationStarted(context.get());
1359 [[self sessionController] updateCurrentItemWithURL:pageURL 1360 [[self sessionController] updateCurrentItemWithURL:pageURL
1360 stateObject:stateObject]; 1361 stateObject:stateObject];
1361 context->SetIsSameDocument(true); 1362 context->SetIsSameDocument(true);
1362 _webStateImpl->OnNavigationFinished(context.get()); 1363 _webStateImpl->OnNavigationFinished(context.get());
1363 } 1364 }
1364 1365
1365 - (void)setDocumentURL:(const GURL&)newURL { 1366 - (void)setDocumentURL:(const GURL&)newURL {
1366 if (newURL != _documentURL && newURL.is_valid()) { 1367 if (newURL != _documentURL && newURL.is_valid()) {
1367 _documentURL = newURL; 1368 _documentURL = newURL;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT. 1523 // Typically on PAGE_TRANSITION_CLIENT_REDIRECT.
1523 [[self sessionController] updatePendingItem:requestURL]; 1524 [[self sessionController] updatePendingItem:requestURL];
1524 } else { 1525 } else {
1525 // A new session history entry needs to be created. 1526 // A new session history entry needs to be created.
1526 self.navigationManagerImpl->AddPendingItem( 1527 self.navigationManagerImpl->AddPendingItem(
1527 requestURL, referrer, transition, 1528 requestURL, referrer, transition,
1528 web::NavigationInitiationType::RENDERER_INITIATED, 1529 web::NavigationInitiationType::RENDERER_INITIATED,
1529 web::NavigationManager::UserAgentOverrideOption::INHERIT); 1530 web::NavigationManager::UserAgentOverrideOption::INHERIT);
1530 } 1531 }
1531 std::unique_ptr<web::NavigationContextImpl> context = 1532 std::unique_ptr<web::NavigationContextImpl> context =
1532 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl, 1533 web::NavigationContextImpl::CreateNavigationContext(
1533 requestURL); 1534 _webStateImpl, requestURL, transition);
1534 1535
1535 web::NavigationItem* item = self.navigationManagerImpl->GetPendingItem(); 1536 web::NavigationItem* item = self.navigationManagerImpl->GetPendingItem();
1536 // TODO(crbug.com/676129): AddPendingItem does not always create a pending 1537 // TODO(crbug.com/676129): AddPendingItem does not always create a pending
1537 // item. Remove this workaround once the bug is fixed. 1538 // item. Remove this workaround once the bug is fixed.
1538 if (!item) { 1539 if (!item) {
1539 item = self.navigationManagerImpl->GetLastCommittedItem(); 1540 item = self.navigationManagerImpl->GetLastCommittedItem();
1540 } 1541 }
1541 context->SetNavigationItemUniqueID(item->GetUniqueID()); 1542 context->SetNavigationItemUniqueID(item->GetUniqueID());
1542 _webStateImpl->SetIsLoading(true); 1543 _webStateImpl->SetIsLoading(true);
1543 _webStateImpl->OnNavigationStarted(context.get()); 1544 _webStateImpl->OnNavigationStarted(context.get());
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 BOOL initialNavigation = !self.currentNavItem; 1856 BOOL initialNavigation = !self.currentNavItem;
1856 1857
1857 web::NavigationInitiationType navigationInitiationType = 1858 web::NavigationInitiationType navigationInitiationType =
1858 params.is_renderer_initiated 1859 params.is_renderer_initiated
1859 ? web::NavigationInitiationType::RENDERER_INITIATED 1860 ? web::NavigationInitiationType::RENDERER_INITIATED
1860 : web::NavigationInitiationType::USER_INITIATED; 1861 : web::NavigationInitiationType::USER_INITIATED;
1861 self.navigationManagerImpl->AddPendingItem( 1862 self.navigationManagerImpl->AddPendingItem(
1862 params.url, params.referrer, params.transition_type, 1863 params.url, params.referrer, params.transition_type,
1863 navigationInitiationType, params.user_agent_override_option); 1864 navigationInitiationType, params.user_agent_override_option);
1864 1865
1866 // Mark pending item as created from hash change if necessary. This is needed
1867 // because window.hashchange message may not arrive on time.
1868 web::NavigationItemImpl* pendingItem = self.sessionController.pendingItem;
1869 if (pendingItem) {
1870 GURL lastCommittedURL = _webStateImpl->GetLastCommittedURL();
1871 GURL pendingURL = pendingItem->GetURL();
1872 if (lastCommittedURL != pendingURL &&
1873 lastCommittedURL.EqualsIgnoringRef(pendingURL)) {
1874 pendingItem->SetIsCreatedFromHashChange(true);
1875 }
1876 }
kkhorimoto 2017/05/22 21:13:56 This change seems to be unrelated to the page tran
Eugene But (OOO till 7-30) 2017/05/22 22:04:28 This was needed to make sure that hash change navi
1877
1865 web::NavigationItemImpl* addedItem = self.currentNavItem; 1878 web::NavigationItemImpl* addedItem = self.currentNavItem;
1866 DCHECK(addedItem); 1879 DCHECK(addedItem);
1867 if (params.extra_headers) 1880 if (params.extra_headers)
1868 addedItem->AddHttpRequestHeaders(params.extra_headers); 1881 addedItem->AddHttpRequestHeaders(params.extra_headers);
1869 if (params.post_data) { 1882 if (params.post_data) {
1870 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) 1883 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"])
1871 << "Post data should have an associated content type"; 1884 << "Post data should have an associated content type";
1872 addedItem->SetPostData(params.post_data); 1885 addedItem->SetPostData(params.post_data);
1873 addedItem->SetShouldSkipRepostFormConfirmation(true); 1886 addedItem->SetShouldSkipRepostFormConfirmation(true);
1874 } 1887 }
(...skipping 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 // Web View should not be created for App Specific URLs. 4170 // Web View should not be created for App Specific URLs.
4158 if (!web::GetWebClient()->IsAppSpecificURL(URL)) { 4171 if (!web::GetWebClient()->IsAppSpecificURL(URL)) {
4159 [self ensureWebViewCreated]; 4172 [self ensureWebViewCreated];
4160 DCHECK(_webView) << "_webView null while trying to load HTML"; 4173 DCHECK(_webView) << "_webView null while trying to load HTML";
4161 } 4174 }
4162 WKNavigation* navigation = 4175 WKNavigation* navigation =
4163 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)]; 4176 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)];
4164 [_navigationStates setState:web::WKNavigationState::REQUESTED 4177 [_navigationStates setState:web::WKNavigationState::REQUESTED
4165 forNavigation:navigation]; 4178 forNavigation:navigation];
4166 std::unique_ptr<web::NavigationContextImpl> context; 4179 std::unique_ptr<web::NavigationContextImpl> context;
4180 const ui::PageTransition loadHTMLTransition =
4181 ui::PageTransition::PAGE_TRANSITION_TYPED;
4167 if (_webStateImpl->HasWebUI()) { 4182 if (_webStateImpl->HasWebUI()) {
4168 // WebUI uses |loadHTML:forURL:| to feed the content to web view. This 4183 // WebUI uses |loadHTML:forURL:| to feed the content to web view. This
4169 // should not be treated as a navigation, but WKNavigationDelegate callbacks 4184 // should not be treated as a navigation, but WKNavigationDelegate callbacks
4170 // still expect a valid context. 4185 // still expect a valid context.
4171 context = 4186 context = web::NavigationContextImpl::CreateNavigationContext(
4172 web::NavigationContextImpl::CreateNavigationContext(_webStateImpl, URL); 4187 _webStateImpl, URL, loadHTMLTransition);
4173 } else { 4188 } else {
4174 context = [self 4189 context = [self registerLoadRequestForURL:URL
4175 registerLoadRequestForURL:URL 4190 referrer:web::Referrer()
4176 referrer:web::Referrer() 4191 transition:loadHTMLTransition];
4177 transition:ui::PageTransition::PAGE_TRANSITION_TYPED];
4178 } 4192 }
4179 [_navigationStates setContext:std::move(context) forNavigation:navigation]; 4193 [_navigationStates setContext:std::move(context) forNavigation:navigation];
4180 } 4194 }
4181 4195
4182 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { 4196 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL {
4183 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); 4197 CHECK(web::GetWebClient()->IsAppSpecificURL(URL));
4184 [self loadHTML:HTML forURL:URL]; 4198 [self loadHTML:HTML forURL:URL];
4185 } 4199 }
4186 4200
4187 - (void)loadHTMLForCurrentURL:(NSString*)HTML { 4201 - (void)loadHTMLForCurrentURL:(NSString*)HTML {
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
5220 - (NSUInteger)observerCount { 5234 - (NSUInteger)observerCount {
5221 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5235 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5222 return [_observers count]; 5236 return [_observers count];
5223 } 5237 }
5224 5238
5225 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5239 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5226 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5240 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5227 } 5241 }
5228 5242
5229 @end 5243 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/navigation_context_impl_unittest.mm ('k') | ios/web/web_state/ui/crw_wk_navigation_states_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698