OLD | NEW |
---|---|
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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 // This method can change the state of the CRWWebController, as it will display | 451 // This method can change the state of the CRWWebController, as it will display |
452 // an error if the returned URL is not reliable from a security point of view. | 452 // an error if the returned URL is not reliable from a security point of view. |
453 // Note that this method is expensive, so it should always be cached locally if | 453 // Note that this method is expensive, so it should always be cached locally if |
454 // it's needed multiple times in a method. | 454 // it's needed multiple times in a method. |
455 @property(nonatomic, readonly) GURL currentURL; | 455 @property(nonatomic, readonly) GURL currentURL; |
456 // Returns the referrer for the current page. | 456 // Returns the referrer for the current page. |
457 @property(nonatomic, readonly) web::Referrer currentReferrer; | 457 @property(nonatomic, readonly) web::Referrer currentReferrer; |
458 | 458 |
459 // Returns YES if the user interacted with the page recently. | 459 // Returns YES if the user interacted with the page recently. |
460 @property(nonatomic, readonly) BOOL userClickedRecently; | 460 @property(nonatomic, readonly) BOOL userClickedRecently; |
461 // Returns whether the desktop user agent should be used when setting the user | |
462 // agent. | |
463 @property(nonatomic, readonly) BOOL useDesktopUserAgent; | |
464 | 461 |
465 // Facade for Mojo API. | 462 // Facade for Mojo API. |
466 @property(nonatomic, readonly) web::MojoFacade* mojoFacade; | 463 @property(nonatomic, readonly) web::MojoFacade* mojoFacade; |
467 | 464 |
468 // Updates Desktop User Agent and calls webWillFinishHistoryNavigationFromEntry: | 465 // Updates Desktop User Agent and calls webWillFinishHistoryNavigationFromEntry: |
469 // on CRWWebDelegate. TODO(crbug.com/684098): Remove this method and inline its | 466 // on CRWWebDelegate. TODO(crbug.com/684098): Remove this method and inline its |
470 // content. | 467 // content. |
471 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry; | 468 - (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry; |
472 // Recreates web view if |entry| and |fromEntry| have different value for | 469 // Recreates web view if |entry| and |fromEntry| have different value for |
473 // IsOverridingUserAgent() flag. | 470 // IsOverridingUserAgent() flag. |
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2324 // The page should be closed if it was initiated by the DOM and there has been | 2321 // The page should be closed if it was initiated by the DOM and there has been |
2325 // no user interaction with the page since the web view was created, or if | 2322 // no user interaction with the page since the web view was created, or if |
2326 // the page has no navigation items, as occurs when an App Store link is | 2323 // the page has no navigation items, as occurs when an App Store link is |
2327 // opened from another application. | 2324 // opened from another application. |
2328 BOOL rendererInitiatedWithoutInteraction = | 2325 BOOL rendererInitiatedWithoutInteraction = |
2329 self.sessionController.openedByDOM && !_userInteractedWithWebController; | 2326 self.sessionController.openedByDOM && !_userInteractedWithWebController; |
2330 BOOL noNavigationItems = !(self.navigationManagerImpl->GetItemCount()); | 2327 BOOL noNavigationItems = !(self.navigationManagerImpl->GetItemCount()); |
2331 return rendererInitiatedWithoutInteraction || noNavigationItems; | 2328 return rendererInitiatedWithoutInteraction || noNavigationItems; |
2332 } | 2329 } |
2333 | 2330 |
2334 - (BOOL)useDesktopUserAgent { | |
2335 web::NavigationItem* item = [self currentNavItem]; | |
2336 return item && item->IsOverridingUserAgent(); | |
2337 } | |
2338 | |
2339 - (web::MojoFacade*)mojoFacade { | 2331 - (web::MojoFacade*)mojoFacade { |
2340 if (!_mojoFacade) { | 2332 if (!_mojoFacade) { |
2341 service_manager::mojom::InterfaceProvider* interfaceProvider = | 2333 service_manager::mojom::InterfaceProvider* interfaceProvider = |
2342 _webStateImpl->GetMojoInterfaceRegistry(); | 2334 _webStateImpl->GetMojoInterfaceRegistry(); |
2343 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); | 2335 _mojoFacade.reset(new web::MojoFacade(interfaceProvider, self)); |
2344 } | 2336 } |
2345 return _mojoFacade.get(); | 2337 return _mojoFacade.get(); |
2346 } | 2338 } |
2347 | 2339 |
2348 - (CRWPassKitDownloader*)passKitDownloader { | 2340 - (CRWPassKitDownloader*)passKitDownloader { |
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4197 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | 4189 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
4198 [[CRWWebViewContentView alloc] initWithWebView:_webView | 4190 [[CRWWebViewContentView alloc] initWithWebView:_webView |
4199 scrollView:self.webScrollView]); | 4191 scrollView:self.webScrollView]); |
4200 [_containerView displayWebViewContentView:webViewContentView]; | 4192 [_containerView displayWebViewContentView:webViewContentView]; |
4201 } | 4193 } |
4202 } | 4194 } |
4203 | 4195 |
4204 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { | 4196 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { |
4205 // Do not attach the context menu controller immediately as the JavaScript | 4197 // Do not attach the context menu controller immediately as the JavaScript |
4206 // delegate must be specified. | 4198 // delegate must be specified. |
4207 return web::BuildWKWebView(CGRectZero, config, | 4199 return web::BuildWKWebView( |
4208 self.webStateImpl->GetBrowserState(), | 4200 CGRectZero, config, self.webStateImpl->GetBrowserState(), |
4209 [self useDesktopUserAgent]); | 4201 self.navigationManagerImpl->IsUsingDesktopUserAgent()); |
Eugene But (OOO till 7-30)
2017/02/22 21:57:42
Is it guaranteed that |self.navigationManagerImpl|
liaoyuke
2017/02/22 23:48:31
Good catch!
| |
4210 } | 4202 } |
4211 | 4203 |
4212 - (void)setWebView:(WKWebView*)webView { | 4204 - (void)setWebView:(WKWebView*)webView { |
4213 DCHECK_NE(_webView.get(), webView); | 4205 DCHECK_NE(_webView.get(), webView); |
4214 | 4206 |
4215 // Unwind the old web view. | 4207 // Unwind the old web view. |
4216 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is | 4208 // TODO(eugenebut): Remove CRWWKScriptMessageRouter once crbug.com/543374 is |
4217 // fixed. | 4209 // fixed. |
4218 CRWWKScriptMessageRouter* messageRouter = | 4210 CRWWKScriptMessageRouter* messageRouter = |
4219 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4211 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5231 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5223 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
5232 _lastRegisteredRequestURL = URL; | 5224 _lastRegisteredRequestURL = URL; |
5233 _loadPhase = web::LOAD_REQUESTED; | 5225 _loadPhase = web::LOAD_REQUESTED; |
5234 } | 5226 } |
5235 | 5227 |
5236 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5228 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
5237 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5229 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
5238 } | 5230 } |
5239 | 5231 |
5240 @end | 5232 @end |
OLD | NEW |