| 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/chrome/browser/tabs/tab.h" | 5 #import "ios/chrome/browser/tabs/tab.h" |
| 6 | 6 |
| 7 #import <CoreLocation/CoreLocation.h> | 7 #import <CoreLocation/CoreLocation.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 #import "ios/web/public/navigation_manager.h" | 135 #import "ios/web/public/navigation_manager.h" |
| 136 #include "ios/web/public/referrer.h" | 136 #include "ios/web/public/referrer.h" |
| 137 #include "ios/web/public/ssl_status.h" | 137 #include "ios/web/public/ssl_status.h" |
| 138 #include "ios/web/public/url_scheme_util.h" | 138 #include "ios/web/public/url_scheme_util.h" |
| 139 #include "ios/web/public/url_util.h" | 139 #include "ios/web/public/url_util.h" |
| 140 #include "ios/web/public/web_client.h" | 140 #include "ios/web/public/web_client.h" |
| 141 #import "ios/web/public/web_state/crw_web_user_interface_delegate.h" | 141 #import "ios/web/public/web_state/crw_web_user_interface_delegate.h" |
| 142 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 142 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 143 #import "ios/web/public/web_state/ui/crw_generic_content_view.h" | 143 #import "ios/web/public/web_state/ui/crw_generic_content_view.h" |
| 144 #include "ios/web/public/web_state/web_state.h" | 144 #include "ios/web/public/web_state/web_state.h" |
| 145 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 145 #include "ios/web/public/web_thread.h" | 146 #include "ios/web/public/web_thread.h" |
| 146 #import "ios/web/web_state/ui/crw_web_controller.h" | 147 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 147 #import "ios/web/web_state/web_state_impl.h" | 148 #import "ios/web/web_state/web_state_impl.h" |
| 148 #include "net/base/escape.h" | 149 #include "net/base/escape.h" |
| 149 #include "net/base/filename_util.h" | 150 #include "net/base/filename_util.h" |
| 150 #import "net/base/mac/url_conversions.h" | 151 #import "net/base/mac/url_conversions.h" |
| 151 #include "net/base/net_errors.h" | 152 #include "net/base/net_errors.h" |
| 152 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 153 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 153 #include "net/cert/x509_certificate.h" | 154 #include "net/cert/x509_certificate.h" |
| 154 #include "net/http/http_response_headers.h" | 155 #include "net/http/http_response_headers.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 FOREGROUND_TAB_FOREGROUND_APP = 0, | 194 FOREGROUND_TAB_FOREGROUND_APP = 0, |
| 194 BACKGROUND_TAB_FOREGROUND_APP, | 195 BACKGROUND_TAB_FOREGROUND_APP, |
| 195 // These are for when the app is in the background. | 196 // These are for when the app is in the background. |
| 196 FOREGROUND_TAB_BACKGROUND_APP, | 197 FOREGROUND_TAB_BACKGROUND_APP, |
| 197 BACKGROUND_TAB_BACKGROUND_APP, | 198 BACKGROUND_TAB_BACKGROUND_APP, |
| 198 TERMINATION_TAB_STATE_COUNT | 199 TERMINATION_TAB_STATE_COUNT |
| 199 }; | 200 }; |
| 200 } // namespace | 201 } // namespace |
| 201 | 202 |
| 202 @interface Tab ()<BlockedPopupHandlerDelegate, | 203 @interface Tab ()<BlockedPopupHandlerDelegate, |
| 204 CRWWebStateObserver, |
| 203 CRWWebUserInterfaceDelegate, | 205 CRWWebUserInterfaceDelegate, |
| 204 FindInPageControllerDelegate, | 206 FindInPageControllerDelegate, |
| 205 ReaderModeControllerDelegate> { | 207 ReaderModeControllerDelegate> { |
| 206 TabModel* parentTabModel_; // weak | 208 TabModel* parentTabModel_; // weak |
| 207 ios::ChromeBrowserState* browserState_; // weak | 209 ios::ChromeBrowserState* browserState_; // weak |
| 208 | 210 |
| 209 base::scoped_nsobject<OpenInController> openInController_; | 211 base::scoped_nsobject<OpenInController> openInController_; |
| 210 base::WeakNSProtocol<id<PassKitDialogProvider>> passKitDialogProvider_; | 212 base::WeakNSProtocol<id<PassKitDialogProvider>> passKitDialogProvider_; |
| 211 // TODO(crbug.com/546213): Move this out of Tab, probably to native app | 213 // TODO(crbug.com/546213): Move this out of Tab, probably to native app |
| 212 // launcher since that's the only thing that uses it. | 214 // launcher since that's the only thing that uses it. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 303 |
| 302 // Handles support for window.print JavaScript calls. | 304 // Handles support for window.print JavaScript calls. |
| 303 std::unique_ptr<PrintObserver> printObserver_; | 305 std::unique_ptr<PrintObserver> printObserver_; |
| 304 | 306 |
| 305 // AutoReloadBridge for this tab. | 307 // AutoReloadBridge for this tab. |
| 306 base::scoped_nsobject<AutoReloadBridge> autoReloadBridge_; | 308 base::scoped_nsobject<AutoReloadBridge> autoReloadBridge_; |
| 307 | 309 |
| 308 // WebStateImpl for this tab. | 310 // WebStateImpl for this tab. |
| 309 std::unique_ptr<web::WebStateImpl> webStateImpl_; | 311 std::unique_ptr<web::WebStateImpl> webStateImpl_; |
| 310 | 312 |
| 313 // Allows Tab to conform CRWWebStateDelegate protocol. |
| 314 std::unique_ptr<web::WebStateObserverBridge> webStateObserver_; |
| 315 |
| 311 // Context used by history to scope the lifetime of navigation entry | 316 // Context used by history to scope the lifetime of navigation entry |
| 312 // references to Tab. | 317 // references to Tab. |
| 313 std::unique_ptr<TabHistoryContext> tabHistoryContext_; | 318 std::unique_ptr<TabHistoryContext> tabHistoryContext_; |
| 314 | 319 |
| 315 // The controller for everything related to reader mode. | 320 // The controller for everything related to reader mode. |
| 316 base::scoped_nsobject<ReaderModeController> readerModeController_; | 321 base::scoped_nsobject<ReaderModeController> readerModeController_; |
| 317 | 322 |
| 318 // C++ bridge that receives notifications from the FaviconDriver. | 323 // C++ bridge that receives notifications from the FaviconDriver. |
| 319 std::unique_ptr<FaviconDriverObserverBridge> faviconDriverObserverBridge_; | 324 std::unique_ptr<FaviconDriverObserverBridge> faviconDriverObserverBridge_; |
| 320 | 325 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 DCHECK(webState); | 556 DCHECK(webState); |
| 552 self = [super init]; | 557 self = [super init]; |
| 553 if (self) { | 558 if (self) { |
| 554 propertyReleaser_Tab_.Init(self, [Tab class]); | 559 propertyReleaser_Tab_.Init(self, [Tab class]); |
| 555 tabHistoryContext_.reset(new TabHistoryContext()); | 560 tabHistoryContext_.reset(new TabHistoryContext()); |
| 556 parentTabModel_ = parentModel; | 561 parentTabModel_ = parentModel; |
| 557 browserState_ = | 562 browserState_ = |
| 558 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); | 563 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); |
| 559 | 564 |
| 560 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release())); | 565 webStateImpl_.reset(static_cast<web::WebStateImpl*>(webState.release())); |
| 566 webStateObserver_.reset( |
| 567 new web::WebStateObserverBridge(webStateImpl_.get(), self)); |
| 568 |
| 561 [self.webController setDelegate:self]; | 569 [self.webController setDelegate:self]; |
| 562 [self.webController setUIDelegate:self]; | 570 [self.webController setUIDelegate:self]; |
| 563 | 571 |
| 564 NSString* sessionID = [self currentSessionID]; | 572 NSString* sessionID = [self currentSessionID]; |
| 565 DCHECK(sessionID); | 573 DCHECK(sessionID); |
| 566 snapshotManager_.reset([[SnapshotManager alloc] init]); | 574 snapshotManager_.reset([[SnapshotManager alloc] init]); |
| 567 | 575 |
| 568 webControllerSnapshotHelper_.reset([[WebControllerSnapshotHelper alloc] | 576 webControllerSnapshotHelper_.reset([[WebControllerSnapshotHelper alloc] |
| 569 initWithSnapshotManager:snapshotManager_ | 577 initWithSnapshotManager:snapshotManager_ |
| 570 tab:self]); | 578 tab:self]); |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 | 1675 |
| 1668 - (void)evaluateU2FResultFromURL:(const GURL&)URL { | 1676 - (void)evaluateU2FResultFromURL:(const GURL&)URL { |
| 1669 DCHECK(U2FController_); | 1677 DCHECK(U2FController_); |
| 1670 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; | 1678 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; |
| 1671 } | 1679 } |
| 1672 | 1680 |
| 1673 - (NSString*)currentSessionID { | 1681 - (NSString*)currentSessionID { |
| 1674 return [self tabId]; | 1682 return [self tabId]; |
| 1675 } | 1683 } |
| 1676 | 1684 |
| 1677 #pragma mark - WebDelegate protocol methods. | 1685 #pragma mark - CRWWebDelegate and CRWWebStateObserver protocol methods. |
| 1678 | 1686 |
| 1679 - (CRWWebController*)webPageOrderedOpen:(const GURL&)URL | 1687 - (CRWWebController*)webPageOrderedOpen:(const GURL&)URL |
| 1680 referrer:(const web::Referrer&)referrer | 1688 referrer:(const web::Referrer&)referrer |
| 1681 windowName:(NSString*)windowName | 1689 windowName:(NSString*)windowName |
| 1682 inBackground:(BOOL)inBackground { | 1690 inBackground:(BOOL)inBackground { |
| 1683 // Prerendered Tabs cannot open child windows. | 1691 // Prerendered Tabs cannot open child windows. |
| 1684 // TODO(crbug.com/661673): Should we kill prerendering in this case? | 1692 // TODO(crbug.com/661673): Should we kill prerendering in this case? |
| 1685 if (!parentTabModel_) | 1693 if (!parentTabModel_) |
| 1686 return nil; | 1694 return nil; |
| 1687 if (!inBackground) | 1695 if (!inBackground) |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 NSString* urlString = base::SysUTF8ToNSString(currentUrl.spec()); | 1895 NSString* urlString = base::SysUTF8ToNSString(currentUrl.spec()); |
| 1888 if ([urlString length]) { | 1896 if ([urlString length]) { |
| 1889 [[NSNotificationCenter defaultCenter] | 1897 [[NSNotificationCenter defaultCenter] |
| 1890 postNotificationName:kTabUrlStartedLoadingNotificationForCrashReporting | 1898 postNotificationName:kTabUrlStartedLoadingNotificationForCrashReporting |
| 1891 object:self | 1899 object:self |
| 1892 userInfo:[NSDictionary dictionaryWithObject:urlString | 1900 userInfo:[NSDictionary dictionaryWithObject:urlString |
| 1893 forKey:kTabUrlKey]]; | 1901 forKey:kTabUrlKey]]; |
| 1894 } | 1902 } |
| 1895 } | 1903 } |
| 1896 | 1904 |
| 1897 // Called when the page finishes loading, with the URL and a boolean indicating | 1905 - (void)webStateDidLoadPage:(web::WebState*)webState |
| 1898 // if the page was successfully loaded. | 1906 withSuccess:(BOOL)loadSuccess { |
| 1899 - (void)webDidFinishWithURL:(const GURL&)url loadSuccess:(BOOL)loadSuccess { | |
| 1900 DCHECK(self.webController.loadPhase == web::PAGE_LOADED); | 1907 DCHECK(self.webController.loadPhase == web::PAGE_LOADED); |
| 1901 | 1908 |
| 1902 // Cancel prerendering if response is "application/octet-stream". It can be a | 1909 // Cancel prerendering if response is "application/octet-stream". It can be a |
| 1903 // video file which should not be played from preload tab (crbug.com/436813). | 1910 // video file which should not be played from preload tab (crbug.com/436813). |
| 1904 if (isPrerenderTab_ && | 1911 if (isPrerenderTab_ && |
| 1905 self.webState->GetContentsMimeType() == "application/octet-stream") { | 1912 self.webState->GetContentsMimeType() == "application/octet-stream") { |
| 1906 [delegate_ discardPrerender]; | 1913 [delegate_ discardPrerender]; |
| 1907 } | 1914 } |
| 1908 | 1915 |
| 1909 bool wasPost = false; | 1916 bool wasPost = false; |
| 1910 if (self.currentSessionEntry) | 1917 if (self.currentSessionEntry) |
| 1911 wasPost = self.currentSessionEntry.navigationItem->HasPostData(); | 1918 wasPost = self.currentSessionEntry.navigationItem->HasPostData(); |
| 1919 GURL lastCommittedURL = self.webState->GetLastCommittedURL(); |
| 1912 if (loadSuccess) | 1920 if (loadSuccess) |
| 1913 [autoReloadBridge_ loadFinishedForURL:url wasPost:wasPost]; | 1921 [autoReloadBridge_ loadFinishedForURL:lastCommittedURL wasPost:wasPost]; |
| 1914 else | 1922 else |
| 1915 [autoReloadBridge_ loadFailedForURL:url wasPost:wasPost]; | 1923 [autoReloadBridge_ loadFailedForURL:lastCommittedURL wasPost:wasPost]; |
| 1916 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:YES]; | 1924 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:YES]; |
| 1917 if (!loadSuccess) { | 1925 if (!loadSuccess) { |
| 1918 [fullScreenController_ disableFullScreen]; | 1926 [fullScreenController_ disableFullScreen]; |
| 1919 } | 1927 } |
| 1920 [self recordInterfaceOrientation]; | 1928 [self recordInterfaceOrientation]; |
| 1921 navigation_metrics::OriginsSeenService* originsSeenService = | 1929 navigation_metrics::OriginsSeenService* originsSeenService = |
| 1922 IOSChromeOriginsSeenServiceFactory::GetForBrowserState(self.browserState); | 1930 IOSChromeOriginsSeenServiceFactory::GetForBrowserState(self.browserState); |
| 1923 bool already_seen = originsSeenService->Insert(url::Origin::Origin(url)); | 1931 bool alreadySeen = |
| 1932 originsSeenService->Insert(url::Origin::Origin(lastCommittedURL)); |
| 1924 navigation_metrics::RecordMainFrameNavigation( | 1933 navigation_metrics::RecordMainFrameNavigation( |
| 1925 url, true, self.browserState->IsOffTheRecord(), already_seen); | 1934 lastCommittedURL, true, self.browserState->IsOffTheRecord(), alreadySeen); |
| 1926 | 1935 |
| 1927 if (loadSuccess) { | 1936 if (loadSuccess) { |
| 1928 scoped_refptr<net::HttpResponseHeaders> headers = | 1937 scoped_refptr<net::HttpResponseHeaders> headers = |
| 1929 self.webStateImpl->GetHttpResponseHeaders(); | 1938 self.webStateImpl->GetHttpResponseHeaders(); |
| 1930 [self handleExportableFile:headers.get()]; | 1939 [self handleExportableFile:headers.get()]; |
| 1931 } | 1940 } |
| 1932 | 1941 |
| 1933 [metricsClientManager_ pageLoadCompleted]; | 1942 [metricsClientManager_ pageLoadCompleted]; |
| 1934 [parentTabModel_ notifyTabChanged:self]; | 1943 [parentTabModel_ notifyTabChanged:self]; |
| 1935 | 1944 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1946 kTabModelPageLoadSuccess, nil]]; | 1955 kTabModelPageLoadSuccess, nil]]; |
| 1947 } | 1956 } |
| 1948 [[OmniboxGeolocationController sharedInstance] | 1957 [[OmniboxGeolocationController sharedInstance] |
| 1949 finishPageLoadForTab:self | 1958 finishPageLoadForTab:self |
| 1950 loadSuccess:loadSuccess]; | 1959 loadSuccess:loadSuccess]; |
| 1951 | 1960 |
| 1952 // Always take snapshots on iPad if the tab switcher is enabled. | 1961 // Always take snapshots on iPad if the tab switcher is enabled. |
| 1953 // If the tab switcher is not enabled, don't take snapshot of chrome scheme | 1962 // If the tab switcher is not enabled, don't take snapshot of chrome scheme |
| 1954 // pages. | 1963 // pages. |
| 1955 BOOL takeSnapshotOnIpad = | 1964 BOOL takeSnapshotOnIpad = |
| 1956 IsIPadIdiom() && (experimental_flags::IsTabSwitcherEnabled() || | 1965 IsIPadIdiom() && |
| 1957 !web::GetWebClient()->IsAppSpecificURL(url)); | 1966 (experimental_flags::IsTabSwitcherEnabled() || |
| 1967 !web::GetWebClient()->IsAppSpecificURL(lastCommittedURL)); |
| 1958 // Always take snapshot on iPhone. | 1968 // Always take snapshot on iPhone. |
| 1959 BOOL takeSnapshot = !IsIPadIdiom() || takeSnapshotOnIpad; | 1969 BOOL takeSnapshot = !IsIPadIdiom() || takeSnapshotOnIpad; |
| 1960 if (loadSuccess && takeSnapshot) { | 1970 if (loadSuccess && takeSnapshot) { |
| 1961 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 1971 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 1962 } | 1972 } |
| 1963 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:NO]; | 1973 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:NO]; |
| 1964 } | 1974 } |
| 1965 | 1975 |
| 1966 - (void)webLoadCancelled:(const GURL&)url { | 1976 - (void)webLoadCancelled:(const GURL&)url { |
| 1967 // When a load is cancelled, this is the maximum that a page will ever load. | 1977 // When a load is cancelled, this is the maximum that a page will ever load. |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2400 | 2410 |
| 2401 - (void)replaceWebStateImpl:(std::unique_ptr<web::WebStateImpl>)webState { | 2411 - (void)replaceWebStateImpl:(std::unique_ptr<web::WebStateImpl>)webState { |
| 2402 // Stop observing the old InfoBarManager and FaviconDriver since they will | 2412 // Stop observing the old InfoBarManager and FaviconDriver since they will |
| 2403 // be deleted with the old web controller. | 2413 // be deleted with the old web controller. |
| 2404 [self setShouldObserveInfoBarManager:NO]; | 2414 [self setShouldObserveInfoBarManager:NO]; |
| 2405 [self setShouldObserveFaviconChanges:NO]; | 2415 [self setShouldObserveFaviconChanges:NO]; |
| 2406 [self.webController setDelegate:nil]; | 2416 [self.webController setDelegate:nil]; |
| 2407 // Set the new web state. | 2417 // Set the new web state. |
| 2408 webStateImpl_.reset(webState.release()); | 2418 webStateImpl_.reset(webState.release()); |
| 2409 [self.webController setDelegate:self]; | 2419 [self.webController setDelegate:self]; |
| 2420 webStateObserver_.reset( |
| 2421 new web::WebStateObserverBridge(webStateImpl_.get(), self)); |
| 2410 // SessionTabHelper comes first because it sets up the tab ID, and other | 2422 // SessionTabHelper comes first because it sets up the tab ID, and other |
| 2411 // helpers may rely on that. | 2423 // helpers may rely on that. |
| 2412 IOSChromeSessionTabHelper::CreateForWebState(webStateImpl_.get()); | 2424 IOSChromeSessionTabHelper::CreateForWebState(webStateImpl_.get()); |
| 2413 IOSChromeSyncedTabDelegate::CreateForWebState(webStateImpl_.get()); | 2425 IOSChromeSyncedTabDelegate::CreateForWebState(webStateImpl_.get()); |
| 2414 // Start observing the new web controller's InfoBarManager and FaviconDriver. | 2426 // Start observing the new web controller's InfoBarManager and FaviconDriver. |
| 2415 [self setShouldObserveInfoBarManager:YES]; | 2427 [self setShouldObserveInfoBarManager:YES]; |
| 2416 [self setShouldObserveFaviconChanges:YES]; | 2428 [self setShouldObserveFaviconChanges:YES]; |
| 2417 findInPageController_.reset(); | 2429 findInPageController_.reset(); |
| 2418 } | 2430 } |
| 2419 | 2431 |
| 2420 - (void)replaceExternalAppLauncher:(id)externalAppLauncher { | 2432 - (void)replaceExternalAppLauncher:(id)externalAppLauncher { |
| 2421 externalAppLauncher_.reset([externalAppLauncher retain]); | 2433 externalAppLauncher_.reset([externalAppLauncher retain]); |
| 2422 } | 2434 } |
| 2423 | 2435 |
| 2424 - (TabModel*)parentTabModel { | 2436 - (TabModel*)parentTabModel { |
| 2425 return parentTabModel_; | 2437 return parentTabModel_; |
| 2426 } | 2438 } |
| 2427 | 2439 |
| 2428 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 2440 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 2429 return inputAccessoryViewController_.get(); | 2441 return inputAccessoryViewController_.get(); |
| 2430 } | 2442 } |
| 2431 | 2443 |
| 2432 @end | 2444 @end |
| OLD | NEW |