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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 @property(nonatomic, readonly) UIScrollView* webScrollView; | 429 @property(nonatomic, readonly) UIScrollView* webScrollView; |
430 // The current page state of the web view. Writing to this property | 430 // The current page state of the web view. Writing to this property |
431 // asynchronously applies the passed value to the current web view. | 431 // asynchronously applies the passed value to the current web view. |
432 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; | 432 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; |
433 // The currently displayed native controller, if any. | 433 // The currently displayed native controller, if any. |
434 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; | 434 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; |
435 // Returns NavigationManager's session controller. | 435 // Returns NavigationManager's session controller. |
436 @property(nonatomic, readonly) CRWSessionController* sessionController; | 436 @property(nonatomic, readonly) CRWSessionController* sessionController; |
437 // The associated NavigationManagerImpl. | 437 // The associated NavigationManagerImpl. |
438 @property(nonatomic, readonly) NavigationManagerImpl* navigationManagerImpl; | 438 @property(nonatomic, readonly) NavigationManagerImpl* navigationManagerImpl; |
| 439 // Whether the associated WebState has an opener. |
| 440 @property(nonatomic, readonly) BOOL hasOpener; |
439 // Dictionary where keys are the names of WKWebView properties and values are | 441 // Dictionary where keys are the names of WKWebView properties and values are |
440 // selector names which should be called when a corresponding property has | 442 // selector names which should be called when a corresponding property has |
441 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 443 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
442 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 444 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
443 // changed. | 445 // changed. |
444 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; | 446 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; |
445 // Downloader for PassKit files. Lazy initialized. | 447 // Downloader for PassKit files. Lazy initialized. |
446 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; | 448 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; |
447 | 449 |
448 // The web view's view of the current URL. During page transitions | 450 // The web view's view of the current URL. During page transitions |
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 // Remove the transient content view. | 1859 // Remove the transient content view. |
1858 [self clearTransientContentView]; | 1860 [self clearTransientContentView]; |
1859 | 1861 |
1860 web::NavigationItem* item = self.currentNavItem; | 1862 web::NavigationItem* item = self.currentNavItem; |
1861 const GURL currentURL = item ? item->GetURL() : GURL::EmptyGURL(); | 1863 const GURL currentURL = item ? item->GetURL() : GURL::EmptyGURL(); |
1862 // If it's a chrome URL, but not a native one, create the WebUI instance. | 1864 // If it's a chrome URL, but not a native one, create the WebUI instance. |
1863 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && | 1865 if (web::GetWebClient()->IsAppSpecificURL(currentURL) && |
1864 ![_nativeProvider hasControllerForURL:currentURL]) { | 1866 ![_nativeProvider hasControllerForURL:currentURL]) { |
1865 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || | 1867 if (!(item->GetTransitionType() & ui::PAGE_TRANSITION_TYPED || |
1866 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && | 1868 item->GetTransitionType() & ui::PAGE_TRANSITION_AUTO_BOOKMARK) && |
1867 self.sessionController.openedByDOM) { | 1869 self.hasOpener) { |
1868 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as | 1870 // WebUI URLs can not be opened by DOM to prevent cross-site scripting as |
1869 // they have increased power. WebUI URLs may only be opened when the user | 1871 // they have increased power. WebUI URLs may only be opened when the user |
1870 // types in the URL or use bookmarks. | 1872 // types in the URL or use bookmarks. |
1871 [[self sessionController] discardNonCommittedItems]; | 1873 [[self sessionController] discardNonCommittedItems]; |
1872 return; | 1874 return; |
1873 } else { | 1875 } else { |
1874 [self createWebUIForURL:currentURL]; | 1876 [self createWebUIForURL:currentURL]; |
1875 } | 1877 } |
1876 } | 1878 } |
1877 | 1879 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2189 - (CRWJSInjectionReceiver*)jsInjectionReceiver { | 2191 - (CRWJSInjectionReceiver*)jsInjectionReceiver { |
2190 return _jsInjectionReceiver; | 2192 return _jsInjectionReceiver; |
2191 } | 2193 } |
2192 | 2194 |
2193 - (BOOL)shouldClosePageOnNativeApplicationLoad { | 2195 - (BOOL)shouldClosePageOnNativeApplicationLoad { |
2194 // The page should be closed if it was initiated by the DOM and there has been | 2196 // The page should be closed if it was initiated by the DOM and there has been |
2195 // no user interaction with the page since the web view was created, or if | 2197 // no user interaction with the page since the web view was created, or if |
2196 // the page has no navigation items, as occurs when an App Store link is | 2198 // the page has no navigation items, as occurs when an App Store link is |
2197 // opened from another application. | 2199 // opened from another application. |
2198 BOOL rendererInitiatedWithoutInteraction = | 2200 BOOL rendererInitiatedWithoutInteraction = |
2199 self.sessionController.openedByDOM && !_userInteractedWithWebController; | 2201 self.hasOpener && !_userInteractedWithWebController; |
2200 BOOL noNavigationItems = !(self.navigationManagerImpl->GetItemCount()); | 2202 BOOL noNavigationItems = !(self.navigationManagerImpl->GetItemCount()); |
2201 return rendererInitiatedWithoutInteraction || noNavigationItems; | 2203 return rendererInitiatedWithoutInteraction || noNavigationItems; |
2202 } | 2204 } |
2203 | 2205 |
2204 - (BOOL)usesDesktopUserAgent { | 2206 - (BOOL)usesDesktopUserAgent { |
2205 web::NavigationItem* item = self.currentNavItem; | 2207 web::NavigationItem* item = self.currentNavItem; |
2206 return item && item->GetUserAgentType() == web::UserAgentType::DESKTOP; | 2208 return item && item->GetUserAgentType() == web::UserAgentType::DESKTOP; |
2207 } | 2209 } |
2208 | 2210 |
2209 - (web::MojoFacade*)mojoFacade { | 2211 - (web::MojoFacade*)mojoFacade { |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3466 | 3468 |
3467 - (CRWSessionController*)sessionController { | 3469 - (CRWSessionController*)sessionController { |
3468 NavigationManagerImpl* navigationManager = self.navigationManagerImpl; | 3470 NavigationManagerImpl* navigationManager = self.navigationManagerImpl; |
3469 return navigationManager ? navigationManager->GetSessionController() : nil; | 3471 return navigationManager ? navigationManager->GetSessionController() : nil; |
3470 } | 3472 } |
3471 | 3473 |
3472 - (NavigationManagerImpl*)navigationManagerImpl { | 3474 - (NavigationManagerImpl*)navigationManagerImpl { |
3473 return _webStateImpl ? &(_webStateImpl->GetNavigationManagerImpl()) : nil; | 3475 return _webStateImpl ? &(_webStateImpl->GetNavigationManagerImpl()) : nil; |
3474 } | 3476 } |
3475 | 3477 |
| 3478 - (BOOL)hasOpener { |
| 3479 return _webStateImpl ? _webStateImpl->HasOpener() : NO; |
| 3480 } |
| 3481 |
3476 - (web::NavigationItemImpl*)currentNavItem { | 3482 - (web::NavigationItemImpl*)currentNavItem { |
3477 // This goes through the legacy Session* interface rather than Navigation* | 3483 // This goes through the legacy Session* interface rather than Navigation* |
3478 // because it is itself a legacy method that should not exist, and this | 3484 // because it is itself a legacy method that should not exist, and this |
3479 // avoids needing to add a GetActiveItem to NavigationManager. If/when this | 3485 // avoids needing to add a GetActiveItem to NavigationManager. If/when this |
3480 // method chain becomes a blocker to eliminating SessionController, the logic | 3486 // method chain becomes a blocker to eliminating SessionController, the logic |
3481 // can be moved here, using public NavigationManager getters. That's not | 3487 // can be moved here, using public NavigationManager getters. That's not |
3482 // done now in order to avoid code duplication. | 3488 // done now in order to avoid code duplication. |
3483 return [[self sessionController] currentItem]; | 3489 return [[self sessionController] currentItem]; |
3484 } | 3490 } |
3485 | 3491 |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4209 referrer.length ? GURL(base::SysNSStringToUTF8(referrer)) : _documentURL; | 4215 referrer.length ? GURL(base::SysNSStringToUTF8(referrer)) : _documentURL; |
4210 | 4216 |
4211 WebState* childWebState = _webStateImpl->CreateNewWebState( | 4217 WebState* childWebState = _webStateImpl->CreateNewWebState( |
4212 requestURL, openerURL, [self userIsInteracting]); | 4218 requestURL, openerURL, [self userIsInteracting]); |
4213 if (!childWebState) | 4219 if (!childWebState) |
4214 return nil; | 4220 return nil; |
4215 | 4221 |
4216 CRWWebController* childWebController = | 4222 CRWWebController* childWebController = |
4217 static_cast<WebStateImpl*>(childWebState)->GetWebController(); | 4223 static_cast<WebStateImpl*>(childWebState)->GetWebController(); |
4218 | 4224 |
4219 DCHECK(!childWebController || | 4225 DCHECK(!childWebController || childWebController.hasOpener); |
4220 childWebController.sessionController.openedByDOM); | |
4221 | 4226 |
4222 // WKWebView requires WKUIDelegate to return a child view created with | 4227 // WKWebView requires WKUIDelegate to return a child view created with |
4223 // exactly the same |configuration| object (exception is raised if config is | 4228 // exactly the same |configuration| object (exception is raised if config is |
4224 // different). |configuration| param and config returned by | 4229 // different). |configuration| param and config returned by |
4225 // WKWebViewConfigurationProvider are different objects because WKWebView | 4230 // WKWebViewConfigurationProvider are different objects because WKWebView |
4226 // makes a shallow copy of the config inside init, so every WKWebView | 4231 // makes a shallow copy of the config inside init, so every WKWebView |
4227 // owns a separate shallow copy of WKWebViewConfiguration. | 4232 // owns a separate shallow copy of WKWebViewConfiguration. |
4228 [childWebController ensureWebViewCreatedWithConfiguration:configuration]; | 4233 [childWebController ensureWebViewCreatedWithConfiguration:configuration]; |
4229 return childWebController.webView; | 4234 return childWebController.webView; |
4230 } | 4235 } |
4231 | 4236 |
4232 - (void)webViewDidClose:(WKWebView*)webView { | 4237 - (void)webViewDidClose:(WKWebView*)webView { |
4233 if (self.sessionController.openedByDOM) { | 4238 if (self.hasOpener) |
4234 _webStateImpl->CloseWebState(); | 4239 _webStateImpl->CloseWebState(); |
4235 } | |
4236 } | 4240 } |
4237 | 4241 |
4238 - (void)webView:(WKWebView*)webView | 4242 - (void)webView:(WKWebView*)webView |
4239 runJavaScriptAlertPanelWithMessage:(NSString*)message | 4243 runJavaScriptAlertPanelWithMessage:(NSString*)message |
4240 initiatedByFrame:(WKFrameInfo*)frame | 4244 initiatedByFrame:(WKFrameInfo*)frame |
4241 completionHandler:(void (^)())completionHandler { | 4245 completionHandler:(void (^)())completionHandler { |
4242 [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_ALERT | 4246 [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_ALERT |
4243 initiatedByFrame:frame | 4247 initiatedByFrame:frame |
4244 message:message | 4248 message:message |
4245 defaultText:nil | 4249 defaultText:nil |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5071 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5075 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
5072 _lastRegisteredRequestURL = URL; | 5076 _lastRegisteredRequestURL = URL; |
5073 _loadPhase = web::LOAD_REQUESTED; | 5077 _loadPhase = web::LOAD_REQUESTED; |
5074 } | 5078 } |
5075 | 5079 |
5076 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5080 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
5077 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5081 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
5078 } | 5082 } |
5079 | 5083 |
5080 @end | 5084 @end |
OLD | NEW |