| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/ios/block_types.h" | 14 #include "base/ios/block_types.h" |
| 15 #import "base/ios/weak_nsobject.h" | |
| 16 #include "base/json/string_escape.h" | 15 #include "base/json/string_escape.h" |
| 17 #include "base/logging.h" | 16 #include "base/logging.h" |
| 18 #include "base/mac/bind_objc_block.h" | 17 #include "base/mac/bind_objc_block.h" |
| 19 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
| 20 #include "base/mac/objc_property_releaser.h" | 19 #include "base/memory/ptr_util.h" |
| 21 #include "base/mac/scoped_nsobject.h" | |
| 22 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 23 #include "base/metrics/user_metrics.h" | 21 #include "base/metrics/user_metrics.h" |
| 24 #include "base/metrics/user_metrics_action.h" | 22 #include "base/metrics/user_metrics_action.h" |
| 25 #include "base/scoped_observer.h" | 23 #include "base/scoped_observer.h" |
| 26 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 27 #include "base/strings/sys_string_conversions.h" | 25 #include "base/strings/sys_string_conversions.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 30 #include "components/favicon/core/favicon_driver_observer.h" | 28 #include "components/favicon/core/favicon_driver_observer.h" |
| 31 #include "components/favicon/ios/web_favicon_driver.h" | 29 #include "components/favicon/ios/web_favicon_driver.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 #import "net/base/mac/url_conversions.h" | 135 #import "net/base/mac/url_conversions.h" |
| 138 #include "net/base/net_errors.h" | 136 #include "net/base/net_errors.h" |
| 139 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 137 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 140 #include "net/cert/x509_certificate.h" | 138 #include "net/cert/x509_certificate.h" |
| 141 #include "net/http/http_response_headers.h" | 139 #include "net/http/http_response_headers.h" |
| 142 #include "net/url_request/url_fetcher.h" | 140 #include "net/url_request/url_fetcher.h" |
| 143 #include "ui/base/l10n/l10n_util.h" | 141 #include "ui/base/l10n/l10n_util.h" |
| 144 #include "ui/base/page_transition_types.h" | 142 #include "ui/base/page_transition_types.h" |
| 145 #include "url/origin.h" | 143 #include "url/origin.h" |
| 146 | 144 |
| 147 using base::UserMetricsAction; | 145 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 148 using web::NavigationManagerImpl; | 146 #error "This file requires ARC support." |
| 149 using net::RequestTracker; | 147 #endif |
| 150 | 148 |
| 151 NSString* const kTabUrlStartedLoadingNotificationForCrashReporting = | 149 NSString* const kTabUrlStartedLoadingNotificationForCrashReporting = |
| 152 @"kTabUrlStartedLoadingNotificationForCrashReporting"; | 150 @"kTabUrlStartedLoadingNotificationForCrashReporting"; |
| 153 NSString* const kTabUrlMayStartLoadingNotificationForCrashReporting = | 151 NSString* const kTabUrlMayStartLoadingNotificationForCrashReporting = |
| 154 @"kTabUrlMayStartLoadingNotificationForCrashReporting"; | 152 @"kTabUrlMayStartLoadingNotificationForCrashReporting"; |
| 155 NSString* const kTabIsShowingExportableNotificationForCrashReporting = | 153 NSString* const kTabIsShowingExportableNotificationForCrashReporting = |
| 156 @"kTabIsShowingExportableNotificationForCrashReporting"; | 154 @"kTabIsShowingExportableNotificationForCrashReporting"; |
| 157 NSString* const kTabClosingCurrentDocumentNotificationForCrashReporting = | 155 NSString* const kTabClosingCurrentDocumentNotificationForCrashReporting = |
| 158 @"kTabClosingCurrentDocumentNotificationForCrashReporting"; | 156 @"kTabClosingCurrentDocumentNotificationForCrashReporting"; |
| 159 | 157 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 195 |
| 198 // Returns true if |item| is the result of a HTTP redirect. | 196 // Returns true if |item| is the result of a HTTP redirect. |
| 199 // Returns false if |item| is nullptr; | 197 // Returns false if |item| is nullptr; |
| 200 bool IsItemRedirectItem(web::NavigationItem* item) { | 198 bool IsItemRedirectItem(web::NavigationItem* item) { |
| 201 if (!item) | 199 if (!item) |
| 202 return false; | 200 return false; |
| 203 | 201 |
| 204 return (ui::PageTransition::PAGE_TRANSITION_IS_REDIRECT_MASK & | 202 return (ui::PageTransition::PAGE_TRANSITION_IS_REDIRECT_MASK & |
| 205 item->GetTransitionType()) == 0; | 203 item->GetTransitionType()) == 0; |
| 206 } | 204 } |
| 205 |
| 206 // TabHistoryContext is used by history to scope the lifetime of navigation |
| 207 // entry references to Tab. |
| 208 class TabHistoryContext : public history::Context { |
| 209 public: |
| 210 TabHistoryContext() {} |
| 211 ~TabHistoryContext() {} |
| 212 |
| 213 private: |
| 214 DISALLOW_COPY_AND_ASSIGN(TabHistoryContext); |
| 215 }; |
| 207 } // namespace | 216 } // namespace |
| 208 | 217 |
| 209 @interface Tab ()<CRWWebStateObserver, | 218 @interface Tab ()<CRWWebStateObserver, |
| 210 CRWWebControllerObserver, | 219 CRWWebControllerObserver, |
| 211 FindInPageControllerDelegate, | 220 FindInPageControllerDelegate, |
| 212 ReaderModeControllerDelegate> { | 221 ReaderModeControllerDelegate> { |
| 213 TabModel* parentTabModel_; // weak | 222 __weak TabModel* parentTabModel_; |
| 214 ios::ChromeBrowserState* browserState_; // weak | 223 ios::ChromeBrowserState* browserState_; |
| 215 | 224 |
| 216 base::scoped_nsobject<OpenInController> openInController_; | 225 OpenInController* openInController_; |
| 217 base::WeakNSProtocol<id<PassKitDialogProvider>> passKitDialogProvider_; | |
| 218 | 226 |
| 219 // Whether or not this tab is currently being displayed. | 227 // Whether or not this tab is currently being displayed. |
| 220 BOOL visible_; | 228 BOOL visible_; |
| 221 | 229 |
| 222 // Holds entries that need to be added to the history DB. Prerender tabs do | 230 // Holds entries that need to be added to the history DB. Prerender tabs do |
| 223 // not write navigation data to the history DB. Instead, they cache history | 231 // not write navigation data to the history DB. Instead, they cache history |
| 224 // data in this vector and add it to the DB when the prerender status is | 232 // data in this vector and add it to the DB when the prerender status is |
| 225 // removed (when the Tab is swapped in as a real Tab). | 233 // removed (when the Tab is swapped in as a real Tab). |
| 226 std::vector<history::HistoryAddPageArgs> addPageVector_; | 234 std::vector<history::HistoryAddPageArgs> addPageVector_; |
| 227 | 235 |
| 228 // YES if this Tab is being prerendered. | 236 // YES if this Tab is being prerendered. |
| 229 BOOL isPrerenderTab_; | 237 BOOL isPrerenderTab_; |
| 230 | 238 |
| 231 // YES if this Tab was initiated from a voice search. | 239 // YES if this Tab was initiated from a voice search. |
| 232 BOOL isVoiceSearchResultsTab_; | 240 BOOL isVoiceSearchResultsTab_; |
| 233 | 241 |
| 234 // YES if the Tab needs to be reloaded after the app becomes active. | 242 // YES if the Tab needs to be reloaded after the app becomes active. |
| 235 BOOL requireReloadAfterBecomingActive_; | 243 BOOL requireReloadAfterBecomingActive_; |
| 236 | 244 |
| 237 // Last visited timestamp. | 245 // Last visited timestamp. |
| 238 double lastVisitedTimestamp_; | 246 double lastVisitedTimestamp_; |
| 239 | 247 |
| 240 base::mac::ObjCPropertyReleaser propertyReleaser_Tab_; | |
| 241 | |
| 242 id<TabDelegate> delegate_; // weak | |
| 243 base::WeakNSProtocol<id<TabDialogDelegate>> dialogDelegate_; | |
| 244 base::WeakNSProtocol<id<SnapshotOverlayProvider>> snapshotOverlayProvider_; | |
| 245 | |
| 246 // Delegate used for snapshotting geometry. | |
| 247 id<TabSnapshottingDelegate> tabSnapshottingDelegate_; // weak | |
| 248 | |
| 249 // The Full Screen Controller responsible for hiding/showing the toolbar. | 248 // The Full Screen Controller responsible for hiding/showing the toolbar. |
| 250 base::scoped_nsobject<FullScreenController> fullScreenController_; | 249 FullScreenController* fullScreenController_; |
| 251 | |
| 252 // The delegate responsible for headers over the tab. | |
| 253 id<TabHeadersDelegate> tabHeadersDelegate_; // weak | |
| 254 | |
| 255 base::WeakNSProtocol<id<FullScreenControllerDelegate>> | |
| 256 fullScreenControllerDelegate_; | |
| 257 | 250 |
| 258 // The Overscroll controller responsible for displaying the | 251 // The Overscroll controller responsible for displaying the |
| 259 // overscrollActionsView above the toolbar. | 252 // overscrollActionsView above the toolbar. |
| 260 base::scoped_nsobject<OverscrollActionsController> | 253 OverscrollActionsController* overscrollActionsController_; |
| 261 overscrollActionsController_; | |
| 262 base::WeakNSProtocol<id<OverscrollActionsControllerDelegate>> | |
| 263 overscrollActionsControllerDelegate_; | |
| 264 | |
| 265 base::scoped_nsobject<NSString> tabId_; | |
| 266 | 254 |
| 267 // Lightweight object dealing with various different UI behaviours when | 255 // Lightweight object dealing with various different UI behaviours when |
| 268 // opening a URL in an external application. | 256 // opening a URL in an external application. |
| 269 base::scoped_nsobject<ExternalAppLauncher> externalAppLauncher_; | 257 ExternalAppLauncher* externalAppLauncher_; |
| 270 | 258 |
| 271 // Handles suggestions for form entry. | 259 // Handles suggestions for form entry. |
| 272 base::scoped_nsobject<FormSuggestionController> suggestionController_; | 260 FormSuggestionController* suggestionController_; |
| 273 | 261 |
| 274 // Manages the input accessory view during form input. | 262 // Manages the input accessory view during form input. |
| 275 base::scoped_nsobject<FormInputAccessoryViewController> | 263 FormInputAccessoryViewController* inputAccessoryViewController_; |
| 276 inputAccessoryViewController_; | |
| 277 | |
| 278 // TODO(crbug.com/661665): move the WebContentsObservers into their own | |
| 279 // container. | |
| 280 // Handles saving and autofill of passwords. | |
| 281 base::scoped_nsobject<PasswordController> passwordController_; | |
| 282 | 264 |
| 283 // Handles autofill. | 265 // Handles autofill. |
| 284 base::scoped_nsobject<AutofillController> autofillController_; | 266 AutofillController* autofillController_; |
| 285 | 267 |
| 286 // Handles GAL infobar on web pages. | 268 // Handles GAL infobar on web pages. |
| 287 base::scoped_nsobject<NativeAppNavigationController> | 269 NativeAppNavigationController* nativeAppNavigationController_; |
| 288 nativeAppNavigationController_; | |
| 289 | 270 |
| 290 // Handles caching and retrieving of snapshots. | 271 // Handles caching and retrieving of snapshots. |
| 291 base::scoped_nsobject<SnapshotManager> snapshotManager_; | 272 SnapshotManager* snapshotManager_; |
| 292 | 273 |
| 293 // Handles retrieving, generating and updating snapshots of CRWWebController's | 274 // Handles retrieving, generating and updating snapshots of CRWWebController's |
| 294 // web page. | 275 // web page. |
| 295 base::scoped_nsobject<WebControllerSnapshotHelper> | 276 WebControllerSnapshotHelper* webControllerSnapshotHelper_; |
| 296 webControllerSnapshotHelper_; | |
| 297 | 277 |
| 298 // Handles support for window.print JavaScript calls. | 278 // Handles support for window.print JavaScript calls. |
| 299 std::unique_ptr<PrintObserver> printObserver_; | 279 std::unique_ptr<PrintObserver> printObserver_; |
| 300 | 280 |
| 301 // AutoReloadBridge for this tab. | 281 // AutoReloadBridge for this tab. |
| 302 base::scoped_nsobject<AutoReloadBridge> autoReloadBridge_; | 282 AutoReloadBridge* autoReloadBridge_; |
| 303 | 283 |
| 304 // WebStateImpl for this tab. | 284 // WebStateImpl for this tab. |
| 305 web::WebStateImpl* webStateImpl_; | 285 web::WebStateImpl* webStateImpl_; |
| 306 | 286 |
| 307 // Allows Tab to conform CRWWebStateDelegate protocol. | 287 // Allows Tab to conform CRWWebStateDelegate protocol. |
| 308 std::unique_ptr<web::WebStateObserverBridge> webStateObserver_; | 288 std::unique_ptr<web::WebStateObserverBridge> webStateObserver_; |
| 309 | 289 |
| 310 // Context used by history to scope the lifetime of navigation entry | 290 // Context used by history to scope the lifetime of navigation entry |
| 311 // references to Tab. | 291 // references to Tab. |
| 312 std::unique_ptr<TabHistoryContext> tabHistoryContext_; | 292 TabHistoryContext tabHistoryContext_; |
| 313 | |
| 314 // The controller for everything related to reader mode. | |
| 315 base::scoped_nsobject<ReaderModeController> readerModeController_; | |
| 316 | 293 |
| 317 // C++ bridge that receives notifications from the FaviconDriver. | 294 // C++ bridge that receives notifications from the FaviconDriver. |
| 318 std::unique_ptr<FaviconDriverObserverBridge> faviconDriverObserverBridge_; | 295 std::unique_ptr<FaviconDriverObserverBridge> faviconDriverObserverBridge_; |
| 319 | 296 |
| 320 // U2F call controller object. | 297 // U2F call controller object. |
| 321 base::scoped_nsobject<U2FController> U2FController_; | 298 U2FController* U2FController_; |
| 322 | 299 |
| 323 // C++ observer used to trigger snapshots after the removal of InfoBars. | 300 // C++ observer used to trigger snapshots after the removal of InfoBars. |
| 324 std::unique_ptr<TabInfoBarObserver> tabInfoBarObserver_; | 301 std::unique_ptr<TabInfoBarObserver> tabInfoBarObserver_; |
| 325 } | 302 } |
| 326 | 303 |
| 327 // Returns the tab's reader mode controller. May contain nil if the feature is | 304 // Returns the tab's reader mode controller. May contain nil if the feature is |
| 328 // disabled. | 305 // disabled. |
| 329 @property(nonatomic, readonly) ReaderModeController* readerModeController; | 306 @property(nonatomic, readonly) ReaderModeController* readerModeController; |
| 330 | 307 |
| 331 // Returns a list of FormSuggestionProviders to be queried for suggestions | 308 // Returns a list of FormSuggestionProviders to be queried for suggestions |
| (...skipping 28 matching lines...) Expand all Loading... |
| 360 // Called after the session history is replaced, useful for updating members | 337 // Called after the session history is replaced, useful for updating members |
| 361 // with new sessionID. | 338 // with new sessionID. |
| 362 - (void)didReplaceSessionHistory; | 339 - (void)didReplaceSessionHistory; |
| 363 | 340 |
| 364 // Called when the UIApplication's state becomes active. | 341 // Called when the UIApplication's state becomes active. |
| 365 - (void)applicationDidBecomeActive; | 342 - (void)applicationDidBecomeActive; |
| 366 | 343 |
| 367 @end | 344 @end |
| 368 | 345 |
| 369 namespace { | 346 namespace { |
| 370 // TabHistoryContext is used by history to scope the lifetime of navigation | |
| 371 // entry references to Tab. | |
| 372 class TabHistoryContext : public history::Context { | |
| 373 public: | |
| 374 TabHistoryContext() {} | |
| 375 ~TabHistoryContext() {} | |
| 376 | |
| 377 private: | |
| 378 DISALLOW_COPY_AND_ASSIGN(TabHistoryContext); | |
| 379 }; | |
| 380 | |
| 381 class FaviconDriverObserverBridge : public favicon::FaviconDriverObserver { | 347 class FaviconDriverObserverBridge : public favicon::FaviconDriverObserver { |
| 382 public: | 348 public: |
| 383 FaviconDriverObserverBridge(Tab* owner, | 349 FaviconDriverObserverBridge(Tab* owner, |
| 384 favicon::FaviconDriver* favicon_driver); | 350 favicon::FaviconDriver* favicon_driver); |
| 385 ~FaviconDriverObserverBridge() override; | 351 ~FaviconDriverObserverBridge() override; |
| 386 | 352 |
| 387 // favicon::FaviconDriverObserver implementation. | 353 // favicon::FaviconDriverObserver implementation. |
| 388 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, | 354 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, |
| 389 NotificationIconType notification_icon_type, | 355 NotificationIconType notification_icon_type, |
| 390 const GURL& icon_url, | 356 const GURL& icon_url, |
| 391 bool icon_url_changed, | 357 bool icon_url_changed, |
| 392 const gfx::Image& image) override; | 358 const gfx::Image& image) override; |
| 393 | 359 |
| 394 private: | 360 private: |
| 395 Tab* owner_; // Owns this instance. | 361 __weak Tab* owner_; |
| 396 ScopedObserver<favicon::FaviconDriver, favicon::FaviconDriverObserver> | 362 ScopedObserver<favicon::FaviconDriver, favicon::FaviconDriverObserver> |
| 397 scoped_observer_; | 363 scoped_observer_; |
| 398 DISALLOW_COPY_AND_ASSIGN(FaviconDriverObserverBridge); | 364 DISALLOW_COPY_AND_ASSIGN(FaviconDriverObserverBridge); |
| 399 }; | 365 }; |
| 400 | 366 |
| 401 FaviconDriverObserverBridge::FaviconDriverObserverBridge( | 367 FaviconDriverObserverBridge::FaviconDriverObserverBridge( |
| 402 Tab* owner, | 368 Tab* owner, |
| 403 favicon::FaviconDriver* favicon_driver) | 369 favicon::FaviconDriver* favicon_driver) |
| 404 : owner_(owner), scoped_observer_(this) { | 370 : owner_(owner), scoped_observer_(this) { |
| 405 scoped_observer_.Add(favicon_driver); | 371 scoped_observer_.Add(favicon_driver); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 421 public: | 387 public: |
| 422 explicit TabInfoBarObserver(Tab* owner); | 388 explicit TabInfoBarObserver(Tab* owner); |
| 423 ~TabInfoBarObserver() override; | 389 ~TabInfoBarObserver() override; |
| 424 void SetShouldObserveInfoBarManager(bool should_observe); | 390 void SetShouldObserveInfoBarManager(bool should_observe); |
| 425 void OnInfoBarAdded(infobars::InfoBar* infobar) override; | 391 void OnInfoBarAdded(infobars::InfoBar* infobar) override; |
| 426 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override; | 392 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override; |
| 427 void OnInfoBarReplaced(infobars::InfoBar* old_infobar, | 393 void OnInfoBarReplaced(infobars::InfoBar* old_infobar, |
| 428 infobars::InfoBar* new_infobar) override; | 394 infobars::InfoBar* new_infobar) override; |
| 429 | 395 |
| 430 private: | 396 private: |
| 431 Tab* owner_; // Owns this instance; | 397 __weak Tab* owner_; |
| 432 ScopedObserver<infobars::InfoBarManager, TabInfoBarObserver> scoped_observer_; | 398 ScopedObserver<infobars::InfoBarManager, TabInfoBarObserver> scoped_observer_; |
| 433 DISALLOW_COPY_AND_ASSIGN(TabInfoBarObserver); | 399 DISALLOW_COPY_AND_ASSIGN(TabInfoBarObserver); |
| 434 }; | 400 }; |
| 435 | 401 |
| 436 TabInfoBarObserver::TabInfoBarObserver(Tab* owner) | 402 TabInfoBarObserver::TabInfoBarObserver(Tab* owner) |
| 437 : owner_(owner), scoped_observer_(this) {} | 403 : owner_(owner), scoped_observer_(this) {} |
| 438 | 404 |
| 439 TabInfoBarObserver::~TabInfoBarObserver() {} | 405 TabInfoBarObserver::~TabInfoBarObserver() {} |
| 440 | 406 |
| 441 void TabInfoBarObserver::SetShouldObserveInfoBarManager(bool should_observe) { | 407 void TabInfoBarObserver::SetShouldObserveInfoBarManager(bool should_observe) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 466 infobars::InfoBar* new_infobar) { | 432 infobars::InfoBar* new_infobar) { |
| 467 // Update snapshots after the infobar has been replaced. | 433 // Update snapshots after the infobar has been replaced. |
| 468 [owner_ updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 434 [owner_ updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 469 } | 435 } |
| 470 | 436 |
| 471 } // anonymous namespace | 437 } // anonymous namespace |
| 472 | 438 |
| 473 @implementation Tab | 439 @implementation Tab |
| 474 | 440 |
| 475 @synthesize browserState = browserState_; | 441 @synthesize browserState = browserState_; |
| 442 @synthesize tabId = tabId_; |
| 476 @synthesize useGreyImageCache = useGreyImageCache_; | 443 @synthesize useGreyImageCache = useGreyImageCache_; |
| 477 @synthesize isPrerenderTab = isPrerenderTab_; | 444 @synthesize isPrerenderTab = isPrerenderTab_; |
| 478 @synthesize isLinkLoadingPrerenderTab = isLinkLoadingPrerenderTab_; | 445 @synthesize isLinkLoadingPrerenderTab = isLinkLoadingPrerenderTab_; |
| 479 @synthesize isVoiceSearchResultsTab = isVoiceSearchResultsTab_; | 446 @synthesize isVoiceSearchResultsTab = isVoiceSearchResultsTab_; |
| 447 @synthesize passwordController = passwordController_; |
| 448 @synthesize overscrollActionsController = overscrollActionsController_; |
| 449 @synthesize readerModeController = readerModeController_; |
| 450 @synthesize overscrollActionsControllerDelegate = |
| 451 overscrollActionsControllerDelegate_; |
| 452 @synthesize passKitDialogProvider = passKitDialogProvider_; |
| 480 @synthesize delegate = delegate_; | 453 @synthesize delegate = delegate_; |
| 454 @synthesize dialogDelegate = dialogDelegate_; |
| 455 @synthesize snapshotOverlayProvider = snapshotOverlayProvider_; |
| 481 @synthesize tabSnapshottingDelegate = tabSnapshottingDelegate_; | 456 @synthesize tabSnapshottingDelegate = tabSnapshottingDelegate_; |
| 482 @synthesize tabHeadersDelegate = tabHeadersDelegate_; | 457 @synthesize tabHeadersDelegate = tabHeadersDelegate_; |
| 458 @synthesize fullScreenControllerDelegate = fullScreenControllerDelegate_; |
| 483 | 459 |
| 484 - (instancetype)initWithWebState:(web::WebState*)webState { | 460 - (instancetype)initWithWebState:(web::WebState*)webState { |
| 485 DCHECK(webState); | 461 DCHECK(webState); |
| 486 self = [super init]; | 462 self = [super init]; |
| 487 if (self) { | 463 if (self) { |
| 488 propertyReleaser_Tab_.Init(self, [Tab class]); | |
| 489 | |
| 490 // TODO(crbug.com/620465): Tab should only use public API of WebState. | 464 // TODO(crbug.com/620465): Tab should only use public API of WebState. |
| 491 // Remove this cast once this is the case. | 465 // Remove this cast once this is the case. |
| 492 webStateImpl_ = static_cast<web::WebStateImpl*>(webState); | 466 webStateImpl_ = static_cast<web::WebStateImpl*>(webState); |
| 493 browserState_ = | 467 browserState_ = |
| 494 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); | 468 ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState()); |
| 495 | |
| 496 tabHistoryContext_ = base::MakeUnique<TabHistoryContext>(); | |
| 497 webStateObserver_ = | 469 webStateObserver_ = |
| 498 base::MakeUnique<web::WebStateObserverBridge>(webState, self); | 470 base::MakeUnique<web::WebStateObserverBridge>(webState, self); |
| 499 | 471 |
| 500 [self updateLastVisitedTimestamp]; | 472 [self updateLastVisitedTimestamp]; |
| 501 [[self webController] addObserver:self]; | 473 [[self webController] addObserver:self]; |
| 502 [[self webController] setDelegate:self]; | 474 [[self webController] setDelegate:self]; |
| 503 | 475 |
| 504 snapshotManager_.reset([[SnapshotManager alloc] init]); | 476 snapshotManager_ = [[SnapshotManager alloc] init]; |
| 505 webControllerSnapshotHelper_.reset([[WebControllerSnapshotHelper alloc] | 477 webControllerSnapshotHelper_ = [[WebControllerSnapshotHelper alloc] |
| 506 initWithSnapshotManager:snapshotManager_ | 478 initWithSnapshotManager:snapshotManager_ |
| 507 tab:self]); | 479 tab:self]; |
| 508 | 480 |
| 509 if (experimental_flags::IsNativeAppLauncherEnabled()) | 481 if (experimental_flags::IsNativeAppLauncherEnabled()) |
| 510 [self initNativeAppNavigationController]; | 482 [self initNativeAppNavigationController]; |
| 511 | 483 |
| 512 [[NSNotificationCenter defaultCenter] | 484 [[NSNotificationCenter defaultCenter] |
| 513 addObserver:self | 485 addObserver:self |
| 514 selector:@selector(applicationDidBecomeActive) | 486 selector:@selector(applicationDidBecomeActive) |
| 515 name:UIApplicationDidBecomeActiveNotification | 487 name:UIApplicationDidBecomeActiveNotification |
| 516 object:nil]; | 488 object:nil]; |
| 517 } | 489 } |
| 518 return self; | 490 return self; |
| 519 } | 491 } |
| 520 | 492 |
| 521 - (void)attachTabHelpers { | 493 - (void)attachTabHelpers { |
| 522 tabInfoBarObserver_.reset(new TabInfoBarObserver(self)); | 494 tabInfoBarObserver_ = base::MakeUnique<TabInfoBarObserver>(self); |
| 523 tabInfoBarObserver_->SetShouldObserveInfoBarManager(true); | 495 tabInfoBarObserver_->SetShouldObserveInfoBarManager(true); |
| 524 | 496 |
| 525 if (experimental_flags::IsAutoReloadEnabled()) { | 497 if (experimental_flags::IsAutoReloadEnabled()) |
| 526 autoReloadBridge_.reset([[AutoReloadBridge alloc] initWithTab:self]); | 498 autoReloadBridge_ = [[AutoReloadBridge alloc] initWithTab:self]; |
| 527 } | |
| 528 printObserver_ = base::MakeUnique<PrintObserver>(self.webState); | 499 printObserver_ = base::MakeUnique<PrintObserver>(self.webState); |
| 529 | 500 |
| 530 base::scoped_nsprotocol<id<PasswordsUiDelegate>> passwordsUiDelegate( | 501 id<PasswordsUiDelegate> passwordsUiDelegate = |
| 531 [[PasswordsUiDelegateImpl alloc] init]); | 502 [[PasswordsUiDelegateImpl alloc] init]; |
| 532 passwordController_.reset([[PasswordController alloc] | 503 passwordController_ = |
| 533 initWithWebState:self.webState | 504 [[PasswordController alloc] initWithWebState:self.webState |
| 534 passwordsUiDelegate:passwordsUiDelegate]); | 505 passwordsUiDelegate:passwordsUiDelegate]; |
| 535 password_manager::PasswordGenerationManager* passwordGenerationManager = | 506 password_manager::PasswordGenerationManager* passwordGenerationManager = |
| 536 [passwordController_ passwordGenerationManager]; | 507 [passwordController_ passwordGenerationManager]; |
| 537 autofillController_.reset([[AutofillController alloc] | 508 autofillController_ = |
| 538 initWithBrowserState:browserState_ | 509 [[AutofillController alloc] initWithBrowserState:browserState_ |
| 539 passwordGenerationManager:passwordGenerationManager | 510 passwordGenerationManager:passwordGenerationManager |
| 540 webState:self.webState]); | 511 webState:self.webState]; |
| 541 suggestionController_.reset([[FormSuggestionController alloc] | 512 suggestionController_ = [[FormSuggestionController alloc] |
| 542 initWithWebState:self.webState | 513 initWithWebState:self.webState |
| 543 providers:[self suggestionProviders]]); | 514 providers:[self suggestionProviders]]; |
| 544 inputAccessoryViewController_.reset([[FormInputAccessoryViewController alloc] | 515 inputAccessoryViewController_ = [[FormInputAccessoryViewController alloc] |
| 545 initWithWebState:self.webState | 516 initWithWebState:self.webState |
| 546 providers:[self accessoryViewProviders]]); | 517 providers:[self accessoryViewProviders]]; |
| 547 | 518 |
| 548 [self setShouldObserveFaviconChanges:YES]; | 519 [self setShouldObserveFaviconChanges:YES]; |
| 549 | 520 |
| 550 // Create the ReaderModeController immediately so it can register for | 521 // Create the ReaderModeController immediately so it can register for |
| 551 // WebState changes. | 522 // WebState changes. |
| 552 if (experimental_flags::IsReaderModeEnabled()) { | 523 if (experimental_flags::IsReaderModeEnabled()) { |
| 553 readerModeController_.reset([[ReaderModeController alloc] | 524 readerModeController_ = |
| 554 initWithWebState:self.webState | 525 [[ReaderModeController alloc] initWithWebState:self.webState |
| 555 delegate:self]); | 526 delegate:self]; |
| 556 } | 527 } |
| 557 } | 528 } |
| 558 | 529 |
| 559 - (NSArray*)accessoryViewProviders { | 530 - (NSArray*)accessoryViewProviders { |
| 560 NSMutableArray* providers = [NSMutableArray array]; | 531 NSMutableArray* providers = [NSMutableArray array]; |
| 561 id<FormInputAccessoryViewProvider> provider = | 532 id<FormInputAccessoryViewProvider> provider = |
| 562 [passwordController_ accessoryViewProvider]; | 533 [passwordController_ accessoryViewProvider]; |
| 563 if (provider) | 534 if (provider) |
| 564 [providers addObject:provider]; | 535 [providers addObject:provider]; |
| 565 [providers addObject:[suggestionController_ accessoryViewProvider]]; | 536 [providers addObject:[suggestionController_ accessoryViewProvider]]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 568 } |
| 598 | 569 |
| 599 - (id<TabDialogDelegate>)dialogDelegate { | 570 - (id<TabDialogDelegate>)dialogDelegate { |
| 600 return dialogDelegate_; | 571 return dialogDelegate_; |
| 601 } | 572 } |
| 602 | 573 |
| 603 - (BOOL)loadFinished { | 574 - (BOOL)loadFinished { |
| 604 return [self.webController loadPhase] == web::PAGE_LOADED; | 575 return [self.webController loadPhase] == web::PAGE_LOADED; |
| 605 } | 576 } |
| 606 | 577 |
| 607 - (void)setDialogDelegate:(id<TabDialogDelegate>)dialogDelegate { | |
| 608 dialogDelegate_.reset(dialogDelegate); | |
| 609 } | |
| 610 | |
| 611 - (void)setIsVoiceSearchResultsTab:(BOOL)isVoiceSearchResultsTab { | 578 - (void)setIsVoiceSearchResultsTab:(BOOL)isVoiceSearchResultsTab { |
| 612 // There is intentionally no equality check in this setter, as we want the | 579 // There is intentionally no equality check in this setter, as we want the |
| 613 // notificaiton to be sent regardless of whether the value has changed. | 580 // notificaiton to be sent regardless of whether the value has changed. |
| 614 isVoiceSearchResultsTab_ = isVoiceSearchResultsTab; | 581 isVoiceSearchResultsTab_ = isVoiceSearchResultsTab; |
| 615 [parentTabModel_ notifyTabChanged:self]; | 582 [parentTabModel_ notifyTabChanged:self]; |
| 616 } | 583 } |
| 617 | 584 |
| 618 - (PasswordController*)passwordController { | |
| 619 return passwordController_.get(); | |
| 620 } | |
| 621 | |
| 622 - (void)retrieveSnapshot:(void (^)(UIImage*))callback { | 585 - (void)retrieveSnapshot:(void (^)(UIImage*))callback { |
| 623 [webControllerSnapshotHelper_ | 586 [webControllerSnapshotHelper_ |
| 624 retrieveSnapshotForWebController:self.webController | 587 retrieveSnapshotForWebController:self.webController |
| 625 sessionID:self.tabId | 588 sessionID:self.tabId |
| 626 withOverlays:[self snapshotOverlays] | 589 withOverlays:[self snapshotOverlays] |
| 627 callback:callback]; | 590 callback:callback]; |
| 628 } | 591 } |
| 629 | 592 |
| 630 - (const GURL&)url { | 593 - (const GURL&)url { |
| 631 // See note in header; this method should be removed. | 594 // See note in header; this method should be removed. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 627 |
| 665 - (NSString*)urlDisplayString { | 628 - (NSString*)urlDisplayString { |
| 666 base::string16 urlText = url_formatter::FormatUrl( | 629 base::string16 urlText = url_formatter::FormatUrl( |
| 667 self.url, url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | 630 self.url, url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, |
| 668 nullptr, nullptr, nullptr); | 631 nullptr, nullptr, nullptr); |
| 669 return base::SysUTF16ToNSString(urlText); | 632 return base::SysUTF16ToNSString(urlText); |
| 670 } | 633 } |
| 671 | 634 |
| 672 - (NSString*)tabId { | 635 - (NSString*)tabId { |
| 673 if (tabId_) | 636 if (tabId_) |
| 674 return tabId_.get(); | 637 return tabId_; |
| 675 | 638 |
| 676 DCHECK(self.webState); | 639 DCHECK(self.webState); |
| 677 web::SerializableUserDataManager* userDataManager = | 640 web::SerializableUserDataManager* userDataManager = |
| 678 web::SerializableUserDataManager::FromWebState(self.webState); | 641 web::SerializableUserDataManager::FromWebState(self.webState); |
| 679 NSString* tabId = base::mac::ObjCCast<NSString>( | 642 NSString* tabId = base::mac::ObjCCast<NSString>( |
| 680 userDataManager->GetValueForSerializationKey(kTabIDKey)); | 643 userDataManager->GetValueForSerializationKey(kTabIDKey)); |
| 681 | 644 |
| 682 if (!tabId || ![tabId length]) { | 645 if (!tabId || ![tabId length]) { |
| 683 tabId = [[NSUUID UUID] UUIDString]; | 646 tabId = [[NSUUID UUID] UUIDString]; |
| 684 userDataManager->AddSerializableData(tabId, kTabIDKey); | 647 userDataManager->AddSerializableData(tabId, kTabIDKey); |
| 685 } | 648 } |
| 686 | 649 |
| 687 tabId_.reset([tabId copy]); | 650 tabId_ = [tabId copy]; |
| 688 return tabId_.get(); | 651 return tabId_; |
| 689 } | 652 } |
| 690 | 653 |
| 691 - (web::WebState*)webState { | 654 - (web::WebState*)webState { |
| 692 return webStateImpl_; | 655 return webStateImpl_; |
| 693 } | 656 } |
| 694 | 657 |
| 695 - (void)fetchFavicon { | 658 - (void)fetchFavicon { |
| 696 const GURL& url = self.url; | 659 const GURL& url = self.url; |
| 697 if (!url.is_valid()) | 660 if (!url.is_valid()) |
| 698 return; | 661 return; |
| 699 | 662 |
| 700 favicon::FaviconDriver* faviconDriver = | 663 favicon::FaviconDriver* faviconDriver = |
| 701 favicon::WebFaviconDriver::FromWebState(self.webState); | 664 favicon::WebFaviconDriver::FromWebState(self.webState); |
| 702 if (faviconDriver) { | 665 if (faviconDriver) |
| 703 faviconDriver->FetchFavicon(url); | 666 faviconDriver->FetchFavicon(url); |
| 704 } | |
| 705 } | 667 } |
| 706 | 668 |
| 707 - (void)setFavicon:(const gfx::Image*)image { | 669 - (void)setFavicon:(const gfx::Image*)image { |
| 708 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); | 670 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); |
| 709 if (!item) | 671 if (!item) |
| 710 return; | 672 return; |
| 711 if (image) { | 673 if (image) { |
| 712 item->GetFavicon().image = *image; | 674 item->GetFavicon().image = *image; |
| 713 item->GetFavicon().valid = true; | 675 item->GetFavicon().valid = true; |
| 714 } | 676 } |
| 715 [parentTabModel_ notifyTabChanged:self]; | 677 [parentTabModel_ notifyTabChanged:self]; |
| 716 } | 678 } |
| 717 | 679 |
| 718 - (UIImage*)favicon { | 680 - (UIImage*)favicon { |
| 719 DCHECK([self navigationManager]); | 681 DCHECK([self navigationManager]); |
| 720 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); | 682 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); |
| 721 if (!item) | 683 if (!item) |
| 722 return nil; | 684 return nil; |
| 723 const gfx::Image& image = item->GetFavicon().image; | 685 const gfx::Image& image = item->GetFavicon().image; |
| 724 if (image.IsEmpty()) | 686 if (image.IsEmpty()) |
| 725 return nil; | 687 return nil; |
| 726 return image.ToUIImage(); | 688 return image.ToUIImage(); |
| 727 } | 689 } |
| 728 | 690 |
| 729 - (UIView*)view { | 691 - (UIView*)view { |
| 730 // Record reload of previously-evicted tab. | 692 // Record reload of previously-evicted tab. |
| 731 if (![self.webController isViewAlive] && [parentTabModel_ tabUsageRecorder]) { | 693 if (![self.webController isViewAlive] && [parentTabModel_ tabUsageRecorder]) |
| 732 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 694 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
| 733 } | |
| 734 return self.webState ? self.webState->GetView() : nil; | 695 return self.webState ? self.webState->GetView() : nil; |
| 735 } | 696 } |
| 736 | 697 |
| 737 - (UIView*)viewForPrinting { | 698 - (UIView*)viewForPrinting { |
| 738 return self.webController.viewForPrinting; | 699 return self.webController.viewForPrinting; |
| 739 } | 700 } |
| 740 | 701 |
| 741 - (web::NavigationManager*)navigationManager { | 702 - (web::NavigationManager*)navigationManager { |
| 742 return self.webState ? self.webState->GetNavigationManager() : nullptr; | 703 return self.webState ? self.webState->GetNavigationManager() : nullptr; |
| 743 } | 704 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 763 } | 724 } |
| 764 | 725 |
| 765 - (void)didReplaceSessionHistory { | 726 - (void)didReplaceSessionHistory { |
| 766 // Replace fullScreenController_ with a new sessionID when the navigation | 727 // Replace fullScreenController_ with a new sessionID when the navigation |
| 767 // manager changes. | 728 // manager changes. |
| 768 // TODO(crbug.com/661666): Consider just updating sessionID and not replacing | 729 // TODO(crbug.com/661666): Consider just updating sessionID and not replacing |
| 769 // |fullScreenController_|. | 730 // |fullScreenController_|. |
| 770 if (fullScreenController_) { | 731 if (fullScreenController_) { |
| 771 [fullScreenController_ invalidate]; | 732 [fullScreenController_ invalidate]; |
| 772 [self.webController removeObserver:fullScreenController_]; | 733 [self.webController removeObserver:fullScreenController_]; |
| 773 fullScreenController_.reset([[FullScreenController alloc] | 734 fullScreenController_ = [[FullScreenController alloc] |
| 774 initWithDelegate:fullScreenControllerDelegate_ | 735 initWithDelegate:fullScreenControllerDelegate_ |
| 775 navigationManager:self.navigationManager | 736 navigationManager:self.navigationManager |
| 776 sessionID:self.tabId]); | 737 sessionID:self.tabId]; |
| 777 [self.webController addObserver:fullScreenController_]; | 738 [self.webController addObserver:fullScreenController_]; |
| 778 // If the content of the page was loaded without knowledge of the | 739 // If the content of the page was loaded without knowledge of the |
| 779 // toolbar position it will be misplaced under the toolbar instead of | 740 // toolbar position it will be misplaced under the toolbar instead of |
| 780 // right below. This happens e.g. in the case of preloading. This is to make | 741 // right below. This happens e.g. in the case of preloading. This is to make |
| 781 // sure the content is moved to the right place. | 742 // sure the content is moved to the right place. |
| 782 [fullScreenController_ moveContentBelowHeader]; | 743 [fullScreenController_ moveContentBelowHeader]; |
| 783 } | 744 } |
| 784 } | 745 } |
| 785 | 746 |
| 786 - (void)setIsLinkLoadingPrerenderTab:(BOOL)isLinkLoadingPrerenderTab { | 747 - (void)setIsLinkLoadingPrerenderTab:(BOOL)isLinkLoadingPrerenderTab { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 810 BOOL loadingFinished = self.webController.loadPhase == web::PAGE_LOADED; | 771 BOOL loadingFinished = self.webController.loadPhase == web::PAGE_LOADED; |
| 811 if (loadingFinished) | 772 if (loadingFinished) |
| 812 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 773 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 813 | 774 |
| 814 [[OmniboxGeolocationController sharedInstance] | 775 [[OmniboxGeolocationController sharedInstance] |
| 815 finishPageLoadForTab:self | 776 finishPageLoadForTab:self |
| 816 loadSuccess:loadingFinished]; | 777 loadSuccess:loadingFinished]; |
| 817 [self countMainFrameLoad]; | 778 [self countMainFrameLoad]; |
| 818 } | 779 } |
| 819 | 780 |
| 820 - (id<FullScreenControllerDelegate>)fullScreenControllerDelegate { | |
| 821 return fullScreenControllerDelegate_.get(); | |
| 822 } | |
| 823 | |
| 824 - (void)setFullScreenControllerDelegate: | 781 - (void)setFullScreenControllerDelegate: |
| 825 (id<FullScreenControllerDelegate>)fullScreenControllerDelegate { | 782 (id<FullScreenControllerDelegate>)fullScreenControllerDelegate { |
| 826 if (fullScreenControllerDelegate == fullScreenControllerDelegate_) { | 783 if (fullScreenControllerDelegate == fullScreenControllerDelegate_) |
| 827 return; | 784 return; |
| 828 } | |
| 829 // Lazily create a FullScreenController. | 785 // Lazily create a FullScreenController. |
| 830 // The check for fullScreenControllerDelegate is necessary to avoid recreating | 786 // The check for fullScreenControllerDelegate is necessary to avoid recreating |
| 831 // a FullScreenController during teardown. | 787 // a FullScreenController during teardown. |
| 832 if (!fullScreenController_ && fullScreenControllerDelegate) { | 788 if (!fullScreenController_ && fullScreenControllerDelegate) { |
| 833 fullScreenController_.reset([[FullScreenController alloc] | 789 fullScreenController_ = [[FullScreenController alloc] |
| 834 initWithDelegate:fullScreenControllerDelegate | 790 initWithDelegate:fullScreenControllerDelegate |
| 835 navigationManager:self.navigationManager | 791 navigationManager:self.navigationManager |
| 836 sessionID:self.tabId]); | 792 sessionID:self.tabId]; |
| 837 [self.webController addObserver:fullScreenController_]; | 793 [self.webController addObserver:fullScreenController_]; |
| 838 // If the content of the page was loaded without knowledge of the | 794 // If the content of the page was loaded without knowledge of the |
| 839 // toolbar position it will be misplaced under the toolbar instead of | 795 // toolbar position it will be misplaced under the toolbar instead of |
| 840 // right below. This happens e.g. in the case of preloading. This is to make | 796 // right below. This happens e.g. in the case of preloading. This is to make |
| 841 // sure the content is moved to the right place. | 797 // sure the content is moved to the right place. |
| 842 [fullScreenController_ moveContentBelowHeader]; | 798 [fullScreenController_ moveContentBelowHeader]; |
| 843 } | 799 } |
| 844 fullScreenControllerDelegate_.reset(fullScreenControllerDelegate); | 800 fullScreenControllerDelegate_ = fullScreenControllerDelegate; |
| 845 } | |
| 846 | |
| 847 - (OverscrollActionsController*)overscrollActionsController { | |
| 848 return overscrollActionsController_.get(); | |
| 849 } | |
| 850 | |
| 851 - (id<OverscrollActionsControllerDelegate>)overscrollActionsControllerDelegate { | |
| 852 return overscrollActionsControllerDelegate_.get(); | |
| 853 } | 801 } |
| 854 | 802 |
| 855 - (void)setOverscrollActionsControllerDelegate: | 803 - (void)setOverscrollActionsControllerDelegate: |
| 856 (id<OverscrollActionsControllerDelegate>) | 804 (id<OverscrollActionsControllerDelegate>) |
| 857 overscrollActionsControllerDelegate { | 805 overscrollActionsControllerDelegate { |
| 858 if (overscrollActionsControllerDelegate_ == | 806 if (overscrollActionsControllerDelegate_ == |
| 859 overscrollActionsControllerDelegate) | 807 overscrollActionsControllerDelegate) { |
| 860 return; | 808 return; |
| 809 } |
| 861 | 810 |
| 862 // Lazily create a OverscrollActionsController. | 811 // Lazily create a OverscrollActionsController. |
| 863 // The check for overscrollActionsControllerDelegate is necessary to avoid | 812 // The check for overscrollActionsControllerDelegate is necessary to avoid |
| 864 // recreating a OverscrollActionsController during teardown. | 813 // recreating a OverscrollActionsController during teardown. |
| 865 if (!overscrollActionsController_) { | 814 if (!overscrollActionsController_) { |
| 866 overscrollActionsController_.reset( | 815 overscrollActionsController_ = [[OverscrollActionsController alloc] init]; |
| 867 [[OverscrollActionsController alloc] init]); | |
| 868 [self.webController addObserver:overscrollActionsController_]; | 816 [self.webController addObserver:overscrollActionsController_]; |
| 869 } | 817 } |
| 870 OverscrollStyle style = OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO; | 818 OverscrollStyle style = OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO; |
| 871 if (browserState_->IsOffTheRecord()) { | 819 if (browserState_->IsOffTheRecord()) |
| 872 style = OverscrollStyle::REGULAR_PAGE_INCOGNITO; | 820 style = OverscrollStyle::REGULAR_PAGE_INCOGNITO; |
| 873 } | |
| 874 [overscrollActionsController_ setStyle:style]; | 821 [overscrollActionsController_ setStyle:style]; |
| 875 [overscrollActionsController_ | 822 [overscrollActionsController_ |
| 876 setDelegate:overscrollActionsControllerDelegate]; | 823 setDelegate:overscrollActionsControllerDelegate]; |
| 877 overscrollActionsControllerDelegate_.reset( | 824 overscrollActionsControllerDelegate_ = overscrollActionsControllerDelegate; |
| 878 overscrollActionsControllerDelegate); | |
| 879 } | 825 } |
| 880 | 826 |
| 881 - (void)saveTitleToHistoryDB { | 827 - (void)saveTitleToHistoryDB { |
| 882 // If incognito, don't update history. | 828 // If incognito, don't update history. |
| 883 if (browserState_->IsOffTheRecord()) | 829 if (browserState_->IsOffTheRecord()) |
| 884 return; | 830 return; |
| 885 // Don't update the history if current entry has no title. | 831 // Don't update the history if current entry has no title. |
| 886 NSString* title = [self title]; | 832 NSString* title = [self title]; |
| 887 if (![title length] || | 833 if (![title length] || |
| 888 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) | 834 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) { |
| 889 return; | 835 return; |
| 836 } |
| 890 | 837 |
| 891 history::HistoryService* historyService = | 838 history::HistoryService* historyService = |
| 892 ios::HistoryServiceFactory::GetForBrowserState( | 839 ios::HistoryServiceFactory::GetForBrowserState( |
| 893 browserState_, ServiceAccessType::IMPLICIT_ACCESS); | 840 browserState_, ServiceAccessType::IMPLICIT_ACCESS); |
| 894 DCHECK(historyService); | 841 DCHECK(historyService); |
| 895 historyService->SetPageTitle(self.url, base::SysNSStringToUTF16(title)); | 842 historyService->SetPageTitle(self.url, base::SysNSStringToUTF16(title)); |
| 896 } | 843 } |
| 897 | 844 |
| 898 - (void)addCurrentEntryToHistoryDB { | 845 - (void)addCurrentEntryToHistoryDB { |
| 899 DCHECK([self navigationManager]->GetVisibleItem()); | 846 DCHECK([self navigationManager]->GetVisibleItem()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 } | 892 } |
| 946 | 893 |
| 947 DCHECK(item->GetTimestamp().ToInternalValue() > 0); | 894 DCHECK(item->GetTimestamp().ToInternalValue() > 0); |
| 948 if ([self isPrerenderTab]) { | 895 if ([self isPrerenderTab]) { |
| 949 // Clicks on content suggestions on the NTP should not contribute to the | 896 // Clicks on content suggestions on the NTP should not contribute to the |
| 950 // Most Visited tiles in the NTP. | 897 // Most Visited tiles in the NTP. |
| 951 const bool consider_for_ntp_most_visited = | 898 const bool consider_for_ntp_most_visited = |
| 952 referrer.url != GURL(kChromeContentSuggestionsReferrer); | 899 referrer.url != GURL(kChromeContentSuggestionsReferrer); |
| 953 | 900 |
| 954 history::HistoryAddPageArgs args( | 901 history::HistoryAddPageArgs args( |
| 955 url, item->GetTimestamp(), tabHistoryContext_.get(), | 902 url, item->GetTimestamp(), &tabHistoryContext_, item->GetUniqueID(), |
| 956 item->GetUniqueID(), referrer.url, redirects, item->GetTransitionType(), | 903 referrer.url, redirects, item->GetTransitionType(), |
| 957 history::SOURCE_BROWSED, false, consider_for_ntp_most_visited); | 904 history::SOURCE_BROWSED, false, consider_for_ntp_most_visited); |
| 958 addPageVector_.push_back(args); | 905 addPageVector_.push_back(args); |
| 959 } else { | 906 } else { |
| 960 historyService->AddPage(url, item->GetTimestamp(), tabHistoryContext_.get(), | 907 historyService->AddPage(url, item->GetTimestamp(), &tabHistoryContext_, |
| 961 item->GetUniqueID(), referrer.url, redirects, | 908 item->GetUniqueID(), referrer.url, redirects, |
| 962 item->GetTransitionType(), history::SOURCE_BROWSED, | 909 item->GetTransitionType(), history::SOURCE_BROWSED, |
| 963 false); | 910 false); |
| 964 [self saveTitleToHistoryDB]; | 911 [self saveTitleToHistoryDB]; |
| 965 } | 912 } |
| 966 } | 913 } |
| 967 | 914 |
| 968 - (void)commitCachedEntriesToHistoryDB { | 915 - (void)commitCachedEntriesToHistoryDB { |
| 969 // If OTR, don't update history. | 916 // If OTR, don't update history. |
| 970 if (browserState_->IsOffTheRecord()) { | 917 if (browserState_->IsOffTheRecord()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 998 } | 945 } |
| 999 } | 946 } |
| 1000 | 947 |
| 1001 ui::PageTransition transition = params.transition_type; | 948 ui::PageTransition transition = params.transition_type; |
| 1002 | 949 |
| 1003 // Record any explicit, non-redirect navigation as a clobber (as long as it's | 950 // Record any explicit, non-redirect navigation as a clobber (as long as it's |
| 1004 // in a real tab). | 951 // in a real tab). |
| 1005 if (!initialNavigation && !isPrerenderTab_ && | 952 if (!initialNavigation && !isPrerenderTab_ && |
| 1006 !PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && | 953 !PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && |
| 1007 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) { | 954 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) { |
| 1008 base::RecordAction(UserMetricsAction("MobileTabClobbered")); | 955 base::RecordAction(base::UserMetricsAction("MobileTabClobbered")); |
| 1009 } | 956 } |
| 1010 if ([parentTabModel_ tabUsageRecorder]) | 957 if ([parentTabModel_ tabUsageRecorder]) |
| 1011 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 958 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
| 1012 | 959 |
| 1013 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. | 960 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. |
| 1014 self.isVoiceSearchResultsTab = NO; | 961 self.isVoiceSearchResultsTab = NO; |
| 1015 | 962 |
| 1016 web::NavigationItem* navigationItem = | 963 web::NavigationItem* navigationItem = |
| 1017 [self navigationManager]->GetPendingItem(); | 964 [self navigationManager]->GetPendingItem(); |
| 1018 | 965 |
| 1019 // TODO(crbug.com/676129): the pending item is not correctly set when the | 966 // TODO(crbug.com/676129): the pending item is not correctly set when the |
| 1020 // page is reloading, use the last committed item if pending item is null. | 967 // page is reloading, use the last committed item if pending item is null. |
| 1021 // Remove this once tracking bug is fixed. | 968 // Remove this once tracking bug is fixed. |
| 1022 if (!navigationItem) | 969 if (!navigationItem) |
| 1023 navigationItem = [self navigationManager]->GetLastCommittedItem(); | 970 navigationItem = [self navigationManager]->GetLastCommittedItem(); |
| 1024 | 971 |
| 1025 [[OmniboxGeolocationController sharedInstance] | 972 [[OmniboxGeolocationController sharedInstance] |
| 1026 addLocationToNavigationItem:navigationItem | 973 addLocationToNavigationItem:navigationItem |
| 1027 browserState:browserState_]; | 974 browserState:browserState_]; |
| 1028 } | 975 } |
| 1029 | 976 |
| 1030 - (void)loadSessionTab:(const sessions::SessionTab*)sessionTab { | 977 - (void)loadSessionTab:(const sessions::SessionTab*)sessionTab { |
| 1031 DCHECK(sessionTab); | 978 DCHECK(sessionTab); |
| 1032 [self replaceHistoryWithNavigations:sessionTab->navigations | 979 [self replaceHistoryWithNavigations:sessionTab->navigations |
| 1033 currentIndex:sessionTab->current_navigation_index]; | 980 currentIndex:sessionTab->current_navigation_index]; |
| 1034 } | 981 } |
| 1035 | 982 |
| 1036 - (void)webWillReload { | 983 - (void)webWillReload { |
| 1037 if ([parentTabModel_ tabUsageRecorder]) { | 984 if ([parentTabModel_ tabUsageRecorder]) |
| 1038 [parentTabModel_ tabUsageRecorder]->RecordReload(self); | 985 [parentTabModel_ tabUsageRecorder]->RecordReload(self); |
| 1039 } | |
| 1040 } | 986 } |
| 1041 | 987 |
| 1042 // Halt the tab, which amounts to halting its webController. | 988 // Halt the tab, which amounts to halting its webController. |
| 1043 - (void)terminateNetworkActivity { | 989 - (void)terminateNetworkActivity { |
| 1044 [self.webController terminateNetworkActivity]; | 990 [self.webController terminateNetworkActivity]; |
| 1045 } | 991 } |
| 1046 | 992 |
| 1047 - (void)webStateDestroyed:(web::WebState*)webState { | 993 - (void)webStateDestroyed:(web::WebState*)webState { |
| 1048 DCHECK_EQ(webStateImpl_, webState); | 994 DCHECK_EQ(webStateImpl_, webState); |
| 1049 self.fullScreenControllerDelegate = nil; | 995 self.fullScreenControllerDelegate = nil; |
| 1050 self.overscrollActionsControllerDelegate = nil; | 996 self.overscrollActionsControllerDelegate = nil; |
| 1051 self.passKitDialogProvider = nil; | 997 self.passKitDialogProvider = nil; |
| 1052 self.snapshotOverlayProvider = nil; | 998 self.snapshotOverlayProvider = nil; |
| 1053 | 999 |
| 1054 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 1000 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 1055 | 1001 |
| 1056 [passwordController_ detach]; | 1002 [passwordController_ detach]; |
| 1057 passwordController_.reset(); | 1003 passwordController_ = nil; |
| 1058 tabInfoBarObserver_.reset(); | 1004 tabInfoBarObserver_.reset(); |
| 1059 | 1005 |
| 1060 faviconDriverObserverBridge_.reset(); | 1006 faviconDriverObserverBridge_.reset(); |
| 1061 [openInController_ detachFromWebController]; | 1007 [openInController_ detachFromWebController]; |
| 1062 openInController_.reset(); | 1008 openInController_ = nil; |
| 1063 [autofillController_ detachFromWebState]; | 1009 [autofillController_ detachFromWebState]; |
| 1064 [suggestionController_ detachFromWebState]; | 1010 [suggestionController_ detachFromWebState]; |
| 1065 if (fullScreenController_) | 1011 if (fullScreenController_) |
| 1066 [self.webController removeObserver:fullScreenController_]; | 1012 [self.webController removeObserver:fullScreenController_]; |
| 1067 [fullScreenController_ invalidate]; | 1013 [fullScreenController_ invalidate]; |
| 1068 fullScreenController_.reset(); | 1014 fullScreenController_ = nil; |
| 1069 if (overscrollActionsController_) | 1015 if (overscrollActionsController_) |
| 1070 [self.webController removeObserver:overscrollActionsController_]; | 1016 [self.webController removeObserver:overscrollActionsController_]; |
| 1071 [overscrollActionsController_ invalidate]; | 1017 [overscrollActionsController_ invalidate]; |
| 1072 overscrollActionsController_.reset(); | 1018 overscrollActionsController_ = nil; |
| 1073 [readerModeController_ detachFromWebState]; | 1019 [readerModeController_ detachFromWebState]; |
| 1074 readerModeController_.reset(); | 1020 readerModeController_ = nil; |
| 1075 | 1021 |
| 1076 // Invalidate any snapshot stored for this session. | 1022 // Invalidate any snapshot stored for this session. |
| 1077 DCHECK(self.tabId); | 1023 DCHECK(self.tabId); |
| 1078 [snapshotManager_ removeImageWithSessionID:self.tabId]; | 1024 [snapshotManager_ removeImageWithSessionID:self.tabId]; |
| 1079 | 1025 |
| 1080 // Cancel any queued dialogs. | 1026 // Cancel any queued dialogs. |
| 1081 [self.dialogDelegate cancelDialogForTab:self]; | 1027 [self.dialogDelegate cancelDialogForTab:self]; |
| 1082 | 1028 |
| 1083 webStateObserver_.reset(); | 1029 webStateObserver_.reset(); |
| 1084 webStateImpl_ = nullptr; | 1030 webStateImpl_ = nullptr; |
| 1085 } | 1031 } |
| 1086 | 1032 |
| 1087 - (void)dismissModals { | 1033 - (void)dismissModals { |
| 1088 [openInController_ disable]; | 1034 [openInController_ disable]; |
| 1089 [self.webController dismissModals]; | 1035 [self.webController dismissModals]; |
| 1090 } | 1036 } |
| 1091 | 1037 |
| 1092 - (void)setShouldObserveInfoBarManager:(BOOL)shouldObserveInfoBarManager { | 1038 - (void)setShouldObserveInfoBarManager:(BOOL)shouldObserveInfoBarManager { |
| 1093 tabInfoBarObserver_->SetShouldObserveInfoBarManager( | 1039 tabInfoBarObserver_->SetShouldObserveInfoBarManager( |
| 1094 shouldObserveInfoBarManager); | 1040 shouldObserveInfoBarManager); |
| 1095 } | 1041 } |
| 1096 | 1042 |
| 1097 - (void)setShouldObserveFaviconChanges:(BOOL)shouldObserveFaviconChanges { | 1043 - (void)setShouldObserveFaviconChanges:(BOOL)shouldObserveFaviconChanges { |
| 1098 if (shouldObserveFaviconChanges) { | 1044 if (shouldObserveFaviconChanges) { |
| 1099 favicon::FaviconDriver* faviconDriver = | 1045 favicon::FaviconDriver* faviconDriver = |
| 1100 favicon::WebFaviconDriver::FromWebState(self.webState); | 1046 favicon::WebFaviconDriver::FromWebState(self.webState); |
| 1101 // Some MockWebContents used in tests do not support the FaviconDriver. | 1047 // Some MockWebContents used in tests do not support the FaviconDriver. |
| 1102 if (faviconDriver) { | 1048 if (faviconDriver) { |
| 1103 faviconDriverObserverBridge_.reset( | 1049 faviconDriverObserverBridge_ = |
| 1104 new FaviconDriverObserverBridge(self, faviconDriver)); | 1050 base::MakeUnique<FaviconDriverObserverBridge>(self, faviconDriver); |
| 1105 } | 1051 } |
| 1106 } else { | 1052 } else { |
| 1107 faviconDriverObserverBridge_.reset(); | 1053 faviconDriverObserverBridge_.reset(); |
| 1108 } | 1054 } |
| 1109 } | 1055 } |
| 1110 | 1056 |
| 1111 - (void)goBack { | 1057 - (void)goBack { |
| 1112 if (self.navigationManager) { | 1058 if (self.navigationManager) { |
| 1113 DCHECK(self.navigationManager->CanGoBack()); | 1059 DCHECK(self.navigationManager->CanGoBack()); |
| 1114 base::RecordAction(UserMetricsAction("Back")); | 1060 base::RecordAction(base::UserMetricsAction("Back")); |
| 1115 self.navigationManager->GoBack(); | 1061 self.navigationManager->GoBack(); |
| 1116 } | 1062 } |
| 1117 } | 1063 } |
| 1118 | 1064 |
| 1119 - (void)goForward { | 1065 - (void)goForward { |
| 1120 if (self.navigationManager) { | 1066 if (self.navigationManager) { |
| 1121 DCHECK(self.navigationManager->CanGoForward()); | 1067 DCHECK(self.navigationManager->CanGoForward()); |
| 1122 base::RecordAction(UserMetricsAction("Forward")); | 1068 base::RecordAction(base::UserMetricsAction("Forward")); |
| 1123 self.navigationManager->GoForward(); | 1069 self.navigationManager->GoForward(); |
| 1124 } | 1070 } |
| 1125 } | 1071 } |
| 1126 | 1072 |
| 1127 - (BOOL)canGoBack { | 1073 - (BOOL)canGoBack { |
| 1128 return self.navigationManager && self.navigationManager->CanGoBack(); | 1074 return self.navigationManager && self.navigationManager->CanGoBack(); |
| 1129 } | 1075 } |
| 1130 | 1076 |
| 1131 - (BOOL)canGoForward { | 1077 - (BOOL)canGoForward { |
| 1132 return self.navigationManager && self.navigationManager->CanGoForward(); | 1078 return self.navigationManager && self.navigationManager->CanGoForward(); |
| 1133 } | 1079 } |
| 1134 | 1080 |
| 1135 - (void)goToItem:(const web::NavigationItem*)item { | 1081 - (void)goToItem:(const web::NavigationItem*)item { |
| 1136 DCHECK(item); | 1082 DCHECK(item); |
| 1137 | 1083 |
| 1138 if (self.navigationManager) { | 1084 if (self.navigationManager) { |
| 1139 CRWSessionController* sessionController = | 1085 CRWSessionController* sessionController = |
| 1140 [self navigationManagerImpl]->GetSessionController(); | 1086 [self navigationManagerImpl]->GetSessionController(); |
| 1141 NSInteger itemIndex = [sessionController indexOfItem:item]; | 1087 NSInteger itemIndex = [sessionController indexOfItem:item]; |
| 1142 DCHECK_NE(itemIndex, NSNotFound); | 1088 DCHECK_NE(itemIndex, NSNotFound); |
| 1143 self.navigationManager->GoToIndex(itemIndex); | 1089 self.navigationManager->GoToIndex(itemIndex); |
| 1144 } | 1090 } |
| 1145 } | 1091 } |
| 1146 | 1092 |
| 1147 - (BOOL)openExternalURL:(const GURL&)url | 1093 - (BOOL)openExternalURL:(const GURL&)url |
| 1148 sourceURL:(const GURL&)sourceURL | 1094 sourceURL:(const GURL&)sourceURL |
| 1149 linkClicked:(BOOL)linkClicked { | 1095 linkClicked:(BOOL)linkClicked { |
| 1150 if (!externalAppLauncher_.get()) | 1096 if (!externalAppLauncher_) |
| 1151 externalAppLauncher_.reset([[ExternalAppLauncher alloc] init]); | 1097 externalAppLauncher_ = [[ExternalAppLauncher alloc] init]; |
| 1152 | |
| 1153 // This method may release CRWWebController which may cause a crash | |
| 1154 // (crbug.com/393949). | |
| 1155 [[self.webController retain] autorelease]; | |
| 1156 | 1098 |
| 1157 // Make a local url copy for possible modification. | 1099 // Make a local url copy for possible modification. |
| 1158 GURL finalURL = url; | 1100 GURL finalURL = url; |
| 1159 | 1101 |
| 1160 // Check if it's a direct FIDO U2F x-callback call. If so, do not open it, to | 1102 // Check if it's a direct FIDO U2F x-callback call. If so, do not open it, to |
| 1161 // prevent pages from spoofing requests with different origins. | 1103 // prevent pages from spoofing requests with different origins. |
| 1162 if (finalURL.SchemeIs("u2f-x-callback")) { | 1104 if (finalURL.SchemeIs("u2f-x-callback")) |
| 1163 return NO; | 1105 return NO; |
| 1164 } | |
| 1165 | 1106 |
| 1166 // Block attempts to open this application's settings in the native system | 1107 // Block attempts to open this application's settings in the native system |
| 1167 // settings application. | 1108 // settings application. |
| 1168 if (finalURL.SchemeIs("app-settings")) | 1109 if (finalURL.SchemeIs("app-settings")) |
| 1169 return NO; | 1110 return NO; |
| 1170 | 1111 |
| 1171 // Check if it's a FIDO U2F call. | 1112 // Check if it's a FIDO U2F call. |
| 1172 if (finalURL.SchemeIs("u2f")) { | 1113 if (finalURL.SchemeIs("u2f")) { |
| 1173 // Create U2FController object lazily. | 1114 // Create U2FController object lazily. |
| 1174 if (!U2FController_) { | 1115 if (!U2FController_) |
| 1175 U2FController_.reset([[U2FController alloc] init]); | 1116 U2FController_ = [[U2FController alloc] init]; |
| 1176 } | |
| 1177 | 1117 |
| 1178 DCHECK([self navigationManager]); | 1118 DCHECK([self navigationManager]); |
| 1179 GURL origin = | 1119 GURL origin = |
| 1180 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); | 1120 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); |
| 1181 | 1121 |
| 1182 // Compose u2f-x-callback URL and update urlToOpen. | 1122 // Compose u2f-x-callback URL and update urlToOpen. |
| 1183 finalURL = [U2FController_ XCallbackFromRequestURL:finalURL | 1123 finalURL = [U2FController_ XCallbackFromRequestURL:finalURL |
| 1184 originURL:origin | 1124 originURL:origin |
| 1185 tabURL:self.url | 1125 tabURL:self.url |
| 1186 tabID:self.tabId]; | 1126 tabID:self.tabId]; |
| 1187 | 1127 |
| 1188 if (!finalURL.is_valid()) { | 1128 if (!finalURL.is_valid()) |
| 1189 return NO; | 1129 return NO; |
| 1190 } | |
| 1191 } | 1130 } |
| 1192 | 1131 |
| 1193 if ([externalAppLauncher_ openURL:finalURL linkClicked:linkClicked]) { | 1132 if ([externalAppLauncher_ openURL:finalURL linkClicked:linkClicked]) { |
| 1194 // Clears pending navigation history after successfully launching the | 1133 // Clears pending navigation history after successfully launching the |
| 1195 // external app. | 1134 // external app. |
| 1196 DCHECK([self navigationManager]); | 1135 DCHECK([self navigationManager]); |
| 1197 [self navigationManager]->DiscardNonCommittedItems(); | 1136 [self navigationManager]->DiscardNonCommittedItems(); |
| 1198 // Ensure the UI reflects the current entry, not the just-discarded pending | 1137 // Ensure the UI reflects the current entry, not the just-discarded pending |
| 1199 // entry. | 1138 // entry. |
| 1200 [parentTabModel_ notifyTabChanged:self]; | 1139 [parentTabModel_ notifyTabChanged:self]; |
| 1201 | 1140 |
| 1202 if (sourceURL.is_valid()) { | 1141 if (sourceURL.is_valid()) { |
| 1203 ReadingListModel* model = | 1142 ReadingListModel* model = |
| 1204 ReadingListModelFactory::GetForBrowserState(browserState_); | 1143 ReadingListModelFactory::GetForBrowserState(browserState_); |
| 1205 if (model && model->loaded()) { | 1144 if (model && model->loaded()) |
| 1206 model->SetReadStatus(sourceURL, true); | 1145 model->SetReadStatus(sourceURL, true); |
| 1207 } | |
| 1208 } | 1146 } |
| 1209 | 1147 |
| 1210 return YES; | 1148 return YES; |
| 1211 } | 1149 } |
| 1212 return NO; | 1150 return NO; |
| 1213 } | 1151 } |
| 1214 | 1152 |
| 1215 - (void)webState:(web::WebState*)webState | 1153 - (void)webState:(web::WebState*)webState |
| 1216 didFinishNavigation:(web::NavigationContext*)navigation { | 1154 didFinishNavigation:(web::NavigationContext*)navigation { |
| 1217 if (navigation->IsSameDocument()) { | 1155 if (navigation->IsSameDocument()) { |
| 1156 // Fetch the favicon for the new URL. |
| 1218 auto* faviconDriver = favicon::WebFaviconDriver::FromWebState(webState); | 1157 auto* faviconDriver = favicon::WebFaviconDriver::FromWebState(webState); |
| 1219 if (faviconDriver) { | 1158 if (faviconDriver) |
| 1220 // Fetch the favicon for the new URL. | |
| 1221 faviconDriver->FetchFavicon(navigation->GetUrl()); | 1159 faviconDriver->FetchFavicon(navigation->GetUrl()); |
| 1222 } | |
| 1223 } | 1160 } |
| 1224 | 1161 |
| 1225 if (!navigation->IsErrorPage()) { | 1162 if (!navigation->IsErrorPage()) { |
| 1226 [self addCurrentEntryToHistoryDB]; | 1163 [self addCurrentEntryToHistoryDB]; |
| 1227 [self countMainFrameLoad]; | 1164 [self countMainFrameLoad]; |
| 1228 } | 1165 } |
| 1229 | 1166 |
| 1230 [parentTabModel_ notifyTabChanged:self]; | 1167 [parentTabModel_ notifyTabChanged:self]; |
| 1231 } | 1168 } |
| 1232 | 1169 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1243 break; | 1180 break; |
| 1244 case UIInterfaceOrientationUnknown: | 1181 case UIInterfaceOrientationUnknown: |
| 1245 // TODO(crbug.com/228832): Convert from a boolean histogram to an | 1182 // TODO(crbug.com/228832): Convert from a boolean histogram to an |
| 1246 // enumerated histogram and log this case as well. | 1183 // enumerated histogram and log this case as well. |
| 1247 break; | 1184 break; |
| 1248 } | 1185 } |
| 1249 } | 1186 } |
| 1250 | 1187 |
| 1251 - (OpenInController*)openInController { | 1188 - (OpenInController*)openInController { |
| 1252 if (!openInController_) { | 1189 if (!openInController_) { |
| 1253 openInController_.reset([[OpenInController alloc] | 1190 openInController_ = [[OpenInController alloc] |
| 1254 initWithRequestContext:browserState_->GetRequestContext() | 1191 initWithRequestContext:browserState_->GetRequestContext() |
| 1255 webController:self.webController]); | 1192 webController:self.webController]; |
| 1256 } | 1193 } |
| 1257 return openInController_.get(); | 1194 return openInController_; |
| 1258 } | 1195 } |
| 1259 | 1196 |
| 1260 - (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url { | 1197 - (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url { |
| 1261 // Shows download manager UI for unhandled content. | 1198 // Shows download manager UI for unhandled content. |
| 1262 DownloadManagerController* downloadController = | 1199 DownloadManagerController* downloadController = |
| 1263 [[[DownloadManagerController alloc] initWithWebState:self.webState | 1200 [[DownloadManagerController alloc] initWithWebState:self.webState |
| 1264 downloadURL:url] autorelease]; | 1201 downloadURL:url]; |
| 1265 [downloadController start]; | 1202 [downloadController start]; |
| 1266 return downloadController; | 1203 return downloadController; |
| 1267 } | 1204 } |
| 1268 | 1205 |
| 1269 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers { | 1206 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers { |
| 1270 // Only "application/pdf" is supported for now. | 1207 // Only "application/pdf" is supported for now. |
| 1271 if (self.webState->GetContentsMimeType() != "application/pdf") | 1208 if (self.webState->GetContentsMimeType() != "application/pdf") |
| 1272 return; | 1209 return; |
| 1273 | 1210 |
| 1274 [[NSNotificationCenter defaultCenter] | 1211 [[NSNotificationCenter defaultCenter] |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1287 "", // referrer-charset | 1224 "", // referrer-charset |
| 1288 "", // suggested-name | 1225 "", // suggested-name |
| 1289 "application/pdf", // mime-type | 1226 "application/pdf", // mime-type |
| 1290 defaultFilename); | 1227 defaultFilename); |
| 1291 [[self openInController] | 1228 [[self openInController] |
| 1292 enableWithDocumentURL:self.url | 1229 enableWithDocumentURL:self.url |
| 1293 suggestedFilename:base::SysUTF16ToNSString(filename)]; | 1230 suggestedFilename:base::SysUTF16ToNSString(filename)]; |
| 1294 } | 1231 } |
| 1295 | 1232 |
| 1296 - (void)countMainFrameLoad { | 1233 - (void)countMainFrameLoad { |
| 1297 if ([self isPrerenderTab] || [self url].SchemeIs(kChromeUIScheme)) { | 1234 if ([self isPrerenderTab] || [self url].SchemeIs(kChromeUIScheme)) |
| 1298 return; | 1235 return; |
| 1299 } | 1236 base::RecordAction(base::UserMetricsAction("MobilePageLoaded")); |
| 1300 base::RecordAction(UserMetricsAction("MobilePageLoaded")); | |
| 1301 } | 1237 } |
| 1302 | 1238 |
| 1303 - (void)applicationDidBecomeActive { | 1239 - (void)applicationDidBecomeActive { |
| 1304 if (requireReloadAfterBecomingActive_) { | 1240 if (!requireReloadAfterBecomingActive_) |
| 1305 if (visible_) { | 1241 return; |
| 1306 self.navigationManager->Reload(web::ReloadType::NORMAL, | 1242 if (visible_) { |
| 1307 false /* check_for_repost */); | 1243 self.navigationManager->Reload(web::ReloadType::NORMAL, |
| 1308 } else { | 1244 false /* check_for_repost */); |
| 1309 [self.webController requirePageReload]; | 1245 } else { |
| 1310 } | 1246 [self.webController requirePageReload]; |
| 1311 requireReloadAfterBecomingActive_ = NO; | |
| 1312 } | 1247 } |
| 1248 requireReloadAfterBecomingActive_ = NO; |
| 1313 } | 1249 } |
| 1314 | 1250 |
| 1315 #pragma mark - | 1251 #pragma mark - |
| 1316 #pragma mark FindInPageControllerDelegate | 1252 #pragma mark FindInPageControllerDelegate |
| 1317 | 1253 |
| 1318 - (void)willAdjustScrollPosition { | 1254 - (void)willAdjustScrollPosition { |
| 1319 // Skip the next attempt to correct the scroll offset for the toolbar height. | 1255 // Skip the next attempt to correct the scroll offset for the toolbar height. |
| 1320 // Used when programatically scrolling down the y offset. | 1256 // Used when programatically scrolling down the y offset. |
| 1321 [fullScreenController_ shouldSkipNextScrollOffsetForHeader]; | 1257 [fullScreenController_ shouldSkipNextScrollOffsetForHeader]; |
| 1322 } | 1258 } |
| 1323 | 1259 |
| 1324 #pragma mark - | 1260 #pragma mark - |
| 1325 #pragma mark FullScreen | 1261 #pragma mark FullScreen |
| 1326 | 1262 |
| 1327 - (void)updateFullscreenWithToolbarVisible:(BOOL)visible { | 1263 - (void)updateFullscreenWithToolbarVisible:(BOOL)visible { |
| 1328 [fullScreenController_ moveHeaderToRestingPosition:visible]; | 1264 [fullScreenController_ moveHeaderToRestingPosition:visible]; |
| 1329 } | 1265 } |
| 1330 | 1266 |
| 1331 #pragma mark - | 1267 #pragma mark - |
| 1332 #pragma mark Reader mode | 1268 #pragma mark Reader mode |
| 1333 | 1269 |
| 1334 - (UIView*)superviewForReaderModePanel { | 1270 - (UIView*)superviewForReaderModePanel { |
| 1335 return self.view; | 1271 return self.view; |
| 1336 } | 1272 } |
| 1337 | 1273 |
| 1338 - (ReaderModeController*)readerModeController { | |
| 1339 return readerModeController_.get(); | |
| 1340 } | |
| 1341 | |
| 1342 - (BOOL)canSwitchToReaderMode { | 1274 - (BOOL)canSwitchToReaderMode { |
| 1343 // Only if the page is loaded and the page passes suitability checks. | 1275 // Only if the page is loaded and the page passes suitability checks. |
| 1344 ReaderModeController* controller = self.readerModeController; | 1276 ReaderModeController* controller = self.readerModeController; |
| 1345 return controller && controller.checker->CanSwitchToReaderMode(); | 1277 return controller && controller.checker->CanSwitchToReaderMode(); |
| 1346 } | 1278 } |
| 1347 | 1279 |
| 1348 - (void)switchToReaderMode { | 1280 - (void)switchToReaderMode { |
| 1349 DCHECK(self.view); | 1281 DCHECK(self.view); |
| 1350 [self.readerModeController switchToReaderMode]; | 1282 [self.readerModeController switchToReaderMode]; |
| 1351 } | 1283 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 params.user_agent_override_option = | 1341 params.user_agent_override_option = |
| 1410 web::NavigationManager::UserAgentOverrideOption::MOBILE; | 1342 web::NavigationManager::UserAgentOverrideOption::MOBILE; |
| 1411 break; | 1343 break; |
| 1412 case web::UserAgentType::NONE: | 1344 case web::UserAgentType::NONE: |
| 1413 NOTREACHED(); | 1345 NOTREACHED(); |
| 1414 } | 1346 } |
| 1415 | 1347 |
| 1416 navigationManager->LoadURLWithParams(params); | 1348 navigationManager->LoadURLWithParams(params); |
| 1417 } | 1349 } |
| 1418 | 1350 |
| 1419 - (id<SnapshotOverlayProvider>)snapshotOverlayProvider { | |
| 1420 return snapshotOverlayProvider_.get(); | |
| 1421 } | |
| 1422 | |
| 1423 - (void)setSnapshotOverlayProvider: | |
| 1424 (id<SnapshotOverlayProvider>)snapshotOverlayProvider { | |
| 1425 snapshotOverlayProvider_.reset(snapshotOverlayProvider); | |
| 1426 } | |
| 1427 | |
| 1428 - (void)evaluateU2FResultFromURL:(const GURL&)URL { | 1351 - (void)evaluateU2FResultFromURL:(const GURL&)URL { |
| 1429 DCHECK(U2FController_); | 1352 DCHECK(U2FController_); |
| 1430 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; | 1353 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; |
| 1431 } | 1354 } |
| 1432 | 1355 |
| 1433 #pragma mark - CRWWebControllerObserver protocol methods. | 1356 #pragma mark - CRWWebControllerObserver protocol methods. |
| 1434 | 1357 |
| 1435 - (void)webControllerWillClose:(CRWWebController*)webController { | 1358 - (void)webControllerWillClose:(CRWWebController*)webController { |
| 1436 DCHECK_EQ(webController, [self webController]); | 1359 DCHECK_EQ(webController, [self webController]); |
| 1437 [[self webController] removeObserver:self]; | 1360 [[self webController] removeObserver:self]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1458 BOOL isUserNavigationEvent = | 1381 BOOL isUserNavigationEvent = |
| 1459 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; | 1382 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; |
| 1460 // Check for link-follow clobbers. These are changes where there is no | 1383 // Check for link-follow clobbers. These are changes where there is no |
| 1461 // pending entry (since that means the change wasn't caused by this class), | 1384 // pending entry (since that means the change wasn't caused by this class), |
| 1462 // and where the URL changes (to avoid counting page resurrection). | 1385 // and where the URL changes (to avoid counting page resurrection). |
| 1463 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or | 1386 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or |
| 1464 // into a NavigationManager observer callback, so it doesn't need to be | 1387 // into a NavigationManager observer callback, so it doesn't need to be |
| 1465 // checked in several places. | 1388 // checked in several places. |
| 1466 if (isUserNavigationEvent && !isPrerenderTab_ && | 1389 if (isUserNavigationEvent && !isPrerenderTab_ && |
| 1467 ![self navigationManager]->GetPendingItem() && url != self.url) { | 1390 ![self navigationManager]->GetPendingItem() && url != self.url) { |
| 1468 base::RecordAction(UserMetricsAction("MobileTabClobbered")); | 1391 base::RecordAction(base::UserMetricsAction("MobileTabClobbered")); |
| 1469 if ([parentTabModel_ tabUsageRecorder]) | 1392 if ([parentTabModel_ tabUsageRecorder]) |
| 1470 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 1393 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
| 1471 } | 1394 } |
| 1472 if (![self navigationManager]->GetPendingItem()) { | 1395 if (![self navigationManager]->GetPendingItem()) { |
| 1473 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. | 1396 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. |
| 1474 self.isVoiceSearchResultsTab = NO; | 1397 self.isVoiceSearchResultsTab = NO; |
| 1475 } | 1398 } |
| 1476 } | 1399 } |
| 1477 | 1400 |
| 1478 - (void)webState:(web::WebState*)webState | 1401 - (void)webState:(web::WebState*)webState |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1497 [autoReloadBridge_ loadStartedForURL:lastCommittedURL]; | 1420 [autoReloadBridge_ loadStartedForURL:lastCommittedURL]; |
| 1498 | 1421 |
| 1499 if (parentTabModel_) { | 1422 if (parentTabModel_) { |
| 1500 [[NSNotificationCenter defaultCenter] | 1423 [[NSNotificationCenter defaultCenter] |
| 1501 postNotificationName:kTabModelTabWillStartLoadingNotification | 1424 postNotificationName:kTabModelTabWillStartLoadingNotification |
| 1502 object:parentTabModel_ | 1425 object:parentTabModel_ |
| 1503 userInfo:@{kTabModelTabKey : self}]; | 1426 userInfo:@{kTabModelTabKey : self}]; |
| 1504 } | 1427 } |
| 1505 favicon::FaviconDriver* faviconDriver = | 1428 favicon::FaviconDriver* faviconDriver = |
| 1506 favicon::WebFaviconDriver::FromWebState(webState); | 1429 favicon::WebFaviconDriver::FromWebState(webState); |
| 1507 if (faviconDriver) { | 1430 if (faviconDriver) |
| 1508 faviconDriver->FetchFavicon(lastCommittedURL); | 1431 faviconDriver->FetchFavicon(lastCommittedURL); |
| 1509 } | |
| 1510 [parentTabModel_ notifyTabChanged:self]; | 1432 [parentTabModel_ notifyTabChanged:self]; |
| 1511 if (parentTabModel_) { | 1433 if (parentTabModel_) { |
| 1512 [[NSNotificationCenter defaultCenter] | 1434 [[NSNotificationCenter defaultCenter] |
| 1513 postNotificationName:kTabModelTabDidStartLoadingNotification | 1435 postNotificationName:kTabModelTabDidStartLoadingNotification |
| 1514 object:parentTabModel_ | 1436 object:parentTabModel_ |
| 1515 userInfo:@{kTabModelTabKey : self}]; | 1437 userInfo:@{kTabModelTabKey : self}]; |
| 1516 } | 1438 } |
| 1517 | 1439 |
| 1518 web::NavigationItem* previousItem = nullptr; | 1440 web::NavigationItem* previousItem = nullptr; |
| 1519 if (details.previous_item_index >= 0) { | 1441 if (details.previous_item_index >= 0) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 [self navigationManager]->GetLastCommittedItem(); | 1474 [self navigationManager]->GetLastCommittedItem(); |
| 1553 if (lastCommittedItem) { | 1475 if (lastCommittedItem) { |
| 1554 wasPost = lastCommittedItem->HasPostData(); | 1476 wasPost = lastCommittedItem->HasPostData(); |
| 1555 lastCommittedURL = lastCommittedItem->GetVirtualURL(); | 1477 lastCommittedURL = lastCommittedItem->GetVirtualURL(); |
| 1556 } | 1478 } |
| 1557 if (loadSuccess) | 1479 if (loadSuccess) |
| 1558 [autoReloadBridge_ loadFinishedForURL:lastCommittedURL wasPost:wasPost]; | 1480 [autoReloadBridge_ loadFinishedForURL:lastCommittedURL wasPost:wasPost]; |
| 1559 else | 1481 else |
| 1560 [autoReloadBridge_ loadFailedForURL:lastCommittedURL wasPost:wasPost]; | 1482 [autoReloadBridge_ loadFailedForURL:lastCommittedURL wasPost:wasPost]; |
| 1561 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:YES]; | 1483 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:YES]; |
| 1562 if (!loadSuccess) { | 1484 if (!loadSuccess) |
| 1563 [fullScreenController_ disableFullScreen]; | 1485 [fullScreenController_ disableFullScreen]; |
| 1564 } | |
| 1565 [self recordInterfaceOrientation]; | 1486 [self recordInterfaceOrientation]; |
| 1566 navigation_metrics::RecordMainFrameNavigation( | 1487 navigation_metrics::RecordMainFrameNavigation( |
| 1567 lastCommittedURL, true, self.browserState->IsOffTheRecord()); | 1488 lastCommittedURL, true, self.browserState->IsOffTheRecord()); |
| 1568 | 1489 |
| 1569 if (loadSuccess) { | 1490 if (loadSuccess) { |
| 1570 scoped_refptr<net::HttpResponseHeaders> headers = | 1491 scoped_refptr<net::HttpResponseHeaders> headers = |
| 1571 webStateImpl_->GetHttpResponseHeaders(); | 1492 webStateImpl_->GetHttpResponseHeaders(); |
| 1572 [self handleExportableFile:headers.get()]; | 1493 [self handleExportableFile:headers.get()]; |
| 1573 } | 1494 } |
| 1574 | 1495 |
| 1575 [parentTabModel_ notifyTabChanged:self]; | 1496 [parentTabModel_ notifyTabChanged:self]; |
| 1576 | 1497 |
| 1577 if (parentTabModel_) { | 1498 if (parentTabModel_) { |
| 1578 if ([parentTabModel_ tabUsageRecorder]) | 1499 if ([parentTabModel_ tabUsageRecorder]) |
| 1579 [parentTabModel_ tabUsageRecorder]->RecordPageLoadDone(self, loadSuccess); | 1500 [parentTabModel_ tabUsageRecorder]->RecordPageLoadDone(self, loadSuccess); |
| 1580 [[NSNotificationCenter defaultCenter] | 1501 [[NSNotificationCenter defaultCenter] |
| 1581 postNotificationName:kTabModelTabDidFinishLoadingNotification | 1502 postNotificationName:kTabModelTabDidFinishLoadingNotification |
| 1582 object:parentTabModel_ | 1503 object:parentTabModel_ |
| 1583 userInfo:[NSDictionary | 1504 userInfo:[NSDictionary |
| 1584 dictionaryWithObjectsAndKeys: | 1505 dictionaryWithObjectsAndKeys: |
| 1585 self, kTabModelTabKey, | 1506 self, kTabModelTabKey, |
| 1586 [NSNumber numberWithBool:loadSuccess], | 1507 [NSNumber numberWithBool:loadSuccess], |
| 1587 kTabModelPageLoadSuccess, nil]]; | 1508 kTabModelPageLoadSuccess, nil]]; |
| 1588 } | 1509 } |
| 1589 [[OmniboxGeolocationController sharedInstance] | 1510 [[OmniboxGeolocationController sharedInstance] |
| 1590 finishPageLoadForTab:self | 1511 finishPageLoadForTab:self |
| 1591 loadSuccess:loadSuccess]; | 1512 loadSuccess:loadSuccess]; |
| 1592 | 1513 |
| 1593 if (loadSuccess) { | 1514 if (loadSuccess) |
| 1594 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 1515 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
| 1595 } | |
| 1596 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:NO]; | 1516 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:NO]; |
| 1597 } | 1517 } |
| 1598 | 1518 |
| 1599 - (void)webState:(web::WebState*)webState | 1519 - (void)webState:(web::WebState*)webState |
| 1600 didChangeLoadingProgress:(double)progress { | 1520 didChangeLoadingProgress:(double)progress { |
| 1601 // TODO(crbug.com/546406): It is probably possible to do something smarter, | 1521 // TODO(crbug.com/546406): It is probably possible to do something smarter, |
| 1602 // but the fact that this is not always sent will have to be taken into | 1522 // but the fact that this is not always sent will have to be taken into |
| 1603 // account. | 1523 // account. |
| 1604 [parentTabModel_ notifyTabChanged:self]; | 1524 [parentTabModel_ notifyTabChanged:self]; |
| 1605 } | 1525 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1635 // TODO(crbug/711511): If Native App Launcher is not enabled, returning NO | 1555 // TODO(crbug/711511): If Native App Launcher is not enabled, returning NO |
| 1636 // bypasses all Link Navigation logic. This call should eventually be | 1556 // bypasses all Link Navigation logic. This call should eventually be |
| 1637 // eliminated. | 1557 // eliminated. |
| 1638 if (!experimental_flags::IsNativeAppLauncherEnabled()) | 1558 if (!experimental_flags::IsNativeAppLauncherEnabled()) |
| 1639 return NO; | 1559 return NO; |
| 1640 | 1560 |
| 1641 // Don't open any native app directly when prerendering or from Incognito. | 1561 // Don't open any native app directly when prerendering or from Incognito. |
| 1642 if (isPrerenderTab_ || self.browserState->IsOffTheRecord()) | 1562 if (isPrerenderTab_ || self.browserState->IsOffTheRecord()) |
| 1643 return NO; | 1563 return NO; |
| 1644 | 1564 |
| 1645 base::scoped_nsprotocol<id<NativeAppMetadata>> metadata( | 1565 id<NativeAppMetadata> metadata = |
| 1646 [[ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() | 1566 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() |
| 1647 nativeAppForURL:url] retain]); | 1567 nativeAppForURL:url]; |
| 1648 if (![metadata shouldAutoOpenLinks]) | 1568 if (![metadata shouldAutoOpenLinks]) |
| 1649 return NO; | 1569 return NO; |
| 1650 | 1570 |
| 1651 AuthenticationService* authenticationService = | 1571 AuthenticationService* authenticationService = |
| 1652 AuthenticationServiceFactory::GetForBrowserState(self.browserState); | 1572 AuthenticationServiceFactory::GetForBrowserState(self.browserState); |
| 1653 ChromeIdentity* identity = authenticationService->GetAuthenticatedIdentity(); | 1573 ChromeIdentity* identity = authenticationService->GetAuthenticatedIdentity(); |
| 1654 | 1574 |
| 1655 // Attempts to open external app without x-callback. | 1575 // Attempts to open external app without x-callback. |
| 1656 if ([self openExternalURL:[metadata launchURLWithURL:url identity:identity] | 1576 if ([self openExternalURL:[metadata launchURLWithURL:url identity:identity] |
| 1657 sourceURL:sourceURL | 1577 sourceURL:sourceURL |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 linkClicked:(BOOL)linkClicked { | 1611 linkClicked:(BOOL)linkClicked { |
| 1692 // chrome:// URLs are only allowed if the mainDocumentURL is also a chrome:// | 1612 // chrome:// URLs are only allowed if the mainDocumentURL is also a chrome:// |
| 1693 // URL. | 1613 // URL. |
| 1694 if (url.SchemeIs(kChromeUIScheme) && | 1614 if (url.SchemeIs(kChromeUIScheme) && |
| 1695 !mainDocumentURL.SchemeIs(kChromeUIScheme)) { | 1615 !mainDocumentURL.SchemeIs(kChromeUIScheme)) { |
| 1696 return NO; | 1616 return NO; |
| 1697 } | 1617 } |
| 1698 | 1618 |
| 1699 // Always allow frame loads. | 1619 // Always allow frame loads. |
| 1700 BOOL isFrameLoad = (url != mainDocumentURL); | 1620 BOOL isFrameLoad = (url != mainDocumentURL); |
| 1701 if (isFrameLoad) { | 1621 if (isFrameLoad) |
| 1702 return YES; | 1622 return YES; |
| 1703 } | |
| 1704 | 1623 |
| 1705 // TODO(crbug.com/546402): If this turns out to be useful, find a less hacky | 1624 // TODO(crbug.com/546402): If this turns out to be useful, find a less hacky |
| 1706 // hook point to send this from. | 1625 // hook point to send this from. |
| 1707 NSString* urlString = base::SysUTF8ToNSString(url.spec()); | 1626 NSString* urlString = base::SysUTF8ToNSString(url.spec()); |
| 1708 if ([urlString length]) { | 1627 if ([urlString length]) { |
| 1709 [[NSNotificationCenter defaultCenter] | 1628 [[NSNotificationCenter defaultCenter] |
| 1710 postNotificationName:kTabUrlMayStartLoadingNotificationForCrashReporting | 1629 postNotificationName:kTabUrlMayStartLoadingNotificationForCrashReporting |
| 1711 object:self | 1630 object:self |
| 1712 userInfo:[NSDictionary dictionaryWithObject:urlString | 1631 userInfo:[NSDictionary dictionaryWithObject:urlString |
| 1713 forKey:kTabUrlKey]]; | 1632 forKey:kTabUrlKey]]; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 } | 1741 } |
| 1823 UMA_HISTOGRAM_ENUMERATION( | 1742 UMA_HISTOGRAM_ENUMERATION( |
| 1824 kRendererTerminationStateHistogram, static_cast<int>(tab_state), | 1743 kRendererTerminationStateHistogram, static_cast<int>(tab_state), |
| 1825 static_cast<int>( | 1744 static_cast<int>( |
| 1826 RendererTerminationTabState::TERMINATION_TAB_STATE_COUNT)); | 1745 RendererTerminationTabState::TERMINATION_TAB_STATE_COUNT)); |
| 1827 if ([parentTabModel_ tabUsageRecorder]) | 1746 if ([parentTabModel_ tabUsageRecorder]) |
| 1828 [parentTabModel_ tabUsageRecorder]->RendererTerminated(self, visible_); | 1747 [parentTabModel_ tabUsageRecorder]->RendererTerminated(self, visible_); |
| 1829 } | 1748 } |
| 1830 | 1749 |
| 1831 if (visible_) { | 1750 if (visible_) { |
| 1832 if (!applicationIsNotActive) { | 1751 if (!applicationIsNotActive) |
| 1833 [fullScreenController_ disableFullScreen]; | 1752 [fullScreenController_ disableFullScreen]; |
| 1834 } | |
| 1835 } else { | 1753 } else { |
| 1836 [self.webController requirePageReload]; | 1754 [self.webController requirePageReload]; |
| 1837 } | 1755 } |
| 1838 // Returning to the app (after the renderer crashed in the background) and | 1756 // Returning to the app (after the renderer crashed in the background) and |
| 1839 // having the page reload is much less confusing for the user. | 1757 // having the page reload is much less confusing for the user. |
| 1840 // Note: Given that the tab is visible, calling |requirePageReload| will not | 1758 // Note: Given that the tab is visible, calling |requirePageReload| will not |
| 1841 // work when the app becomes active because there is nothing to trigger | 1759 // work when the app becomes active because there is nothing to trigger |
| 1842 // a view redisplay in that scenario. | 1760 // a view redisplay in that scenario. |
| 1843 requireReloadAfterBecomingActive_ = visible_ && applicationIsNotActive; | 1761 requireReloadAfterBecomingActive_ = visible_ && applicationIsNotActive; |
| 1844 [self.dialogDelegate cancelDialogForTab:self]; | 1762 [self.dialogDelegate cancelDialogForTab:self]; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1866 if (isPrerenderTab_) { | 1784 if (isPrerenderTab_) { |
| 1867 [delegate_ discardPrerender]; | 1785 [delegate_ discardPrerender]; |
| 1868 return; | 1786 return; |
| 1869 } | 1787 } |
| 1870 if (self != [parentTabModel_ currentTab]) | 1788 if (self != [parentTabModel_ currentTab]) |
| 1871 return; | 1789 return; |
| 1872 | 1790 |
| 1873 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 1791 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
| 1874 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) | 1792 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) |
| 1875 ->GetState()); | 1793 ->GetState()); |
| 1876 base::scoped_nsobject<GenericChromeCommand> command( | 1794 GenericChromeCommand* command = |
| 1877 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]); | 1795 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]; |
| 1878 [self.view chromeExecuteCommand:command]; | 1796 [self.view chromeExecuteCommand:command]; |
| 1879 } | 1797 } |
| 1880 | 1798 |
| 1881 - (void)onAddAccount { | 1799 - (void)onAddAccount { |
| 1882 if (isPrerenderTab_) { | 1800 if (isPrerenderTab_) { |
| 1883 [delegate_ discardPrerender]; | 1801 [delegate_ discardPrerender]; |
| 1884 return; | 1802 return; |
| 1885 } | 1803 } |
| 1886 if (self != [parentTabModel_ currentTab]) | 1804 if (self != [parentTabModel_ currentTab]) |
| 1887 return; | 1805 return; |
| 1888 | 1806 |
| 1889 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 1807 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
| 1890 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) | 1808 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) |
| 1891 ->GetState()); | 1809 ->GetState()); |
| 1892 base::scoped_nsobject<GenericChromeCommand> command( | 1810 GenericChromeCommand* command = |
| 1893 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ADD_ACCOUNT]); | 1811 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ADD_ACCOUNT]; |
| 1894 [self.view chromeExecuteCommand:command]; | 1812 [self.view chromeExecuteCommand:command]; |
| 1895 } | 1813 } |
| 1896 | 1814 |
| 1897 - (void)onGoIncognito:(const GURL&)url { | 1815 - (void)onGoIncognito:(const GURL&)url { |
| 1898 if (isPrerenderTab_) { | 1816 if (isPrerenderTab_) { |
| 1899 [delegate_ discardPrerender]; | 1817 [delegate_ discardPrerender]; |
| 1900 return; | 1818 return; |
| 1901 } | 1819 } |
| 1902 if (self != [parentTabModel_ currentTab]) | 1820 if (self != [parentTabModel_ currentTab]) |
| 1903 return; | 1821 return; |
| 1904 | 1822 |
| 1905 // The user taps on go incognito from the mobile U-turn webpage (the web page | 1823 // The user taps on go incognito from the mobile U-turn webpage (the web page |
| 1906 // that displays all users accounts available in the content area). As the | 1824 // that displays all users accounts available in the content area). As the |
| 1907 // user chooses to go to incognito, the mobile U-turn page is no longer | 1825 // user chooses to go to incognito, the mobile U-turn page is no longer |
| 1908 // neeeded. The current solution is to go back in history. This has the | 1826 // neeeded. The current solution is to go back in history. This has the |
| 1909 // advantage of keeping the current browsing session and give a good user | 1827 // advantage of keeping the current browsing session and give a good user |
| 1910 // experience when the user comes back from incognito. | 1828 // experience when the user comes back from incognito. |
| 1911 [self goBack]; | 1829 [self goBack]; |
| 1912 | 1830 |
| 1913 if (url.is_valid()) { | 1831 if (url.is_valid()) { |
| 1914 base::scoped_nsobject<OpenUrlCommand> command([[OpenUrlCommand alloc] | 1832 OpenUrlCommand* command = [[OpenUrlCommand alloc] |
| 1915 initWithURL:url | 1833 initWithURL:url |
| 1916 referrer:web::Referrer() // Strip referrer when switching modes. | 1834 referrer:web::Referrer() // Strip referrer when switching modes. |
| 1917 inIncognito:YES | 1835 inIncognito:YES |
| 1918 inBackground:NO | 1836 inBackground:NO |
| 1919 appendTo:kLastTab]); | 1837 appendTo:kLastTab]; |
| 1920 [self.view chromeExecuteCommand:command]; | 1838 [self.view chromeExecuteCommand:command]; |
| 1921 } else { | 1839 } else { |
| 1922 base::scoped_nsobject<GenericChromeCommand> chromeCommand( | 1840 GenericChromeCommand* command = |
| 1923 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]); | 1841 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]; |
| 1924 [self.view chromeExecuteCommand:chromeCommand]; | 1842 [self.view chromeExecuteCommand:command]; |
| 1925 } | 1843 } |
| 1926 } | 1844 } |
| 1927 | 1845 |
| 1928 - (NativeAppNavigationController*)nativeAppNavigationController { | 1846 - (NativeAppNavigationController*)nativeAppNavigationController { |
| 1929 // TODO(crbug.com/711511): If Native App Launcher is not enabled, simply | 1847 // TODO(crbug.com/711511): If Native App Launcher is not enabled, simply |
| 1930 // return nil here. This method should eventually be eliminated. | 1848 // return nil here. This method should eventually be eliminated. |
| 1931 if (!experimental_flags::IsNativeAppLauncherEnabled()) | 1849 if (!experimental_flags::IsNativeAppLauncherEnabled()) |
| 1932 return nil; | 1850 return nil; |
| 1933 return nativeAppNavigationController_; | 1851 return nativeAppNavigationController_; |
| 1934 } | 1852 } |
| 1935 | 1853 |
| 1936 - (void)initNativeAppNavigationController { | 1854 - (void)initNativeAppNavigationController { |
| 1937 if (browserState_->IsOffTheRecord()) | 1855 if (browserState_->IsOffTheRecord()) |
| 1938 return; | 1856 return; |
| 1939 DCHECK(!nativeAppNavigationController_); | 1857 DCHECK(!nativeAppNavigationController_); |
| 1940 nativeAppNavigationController_.reset( | 1858 nativeAppNavigationController_ = |
| 1941 [[NativeAppNavigationController alloc] initWithWebState:self.webState]); | 1859 [[NativeAppNavigationController alloc] initWithWebState:self.webState]; |
| 1942 DCHECK(nativeAppNavigationController_); | 1860 DCHECK(nativeAppNavigationController_); |
| 1943 } | 1861 } |
| 1944 | 1862 |
| 1945 - (id<PassKitDialogProvider>)passKitDialogProvider { | |
| 1946 return passKitDialogProvider_.get(); | |
| 1947 } | |
| 1948 | |
| 1949 - (void)setPassKitDialogProvider:(id<PassKitDialogProvider>)provider { | |
| 1950 passKitDialogProvider_.reset(provider); | |
| 1951 } | |
| 1952 | |
| 1953 - (void)wasShown { | 1863 - (void)wasShown { |
| 1954 visible_ = YES; | 1864 visible_ = YES; |
| 1955 [self updateFullscreenWithToolbarVisible:YES]; | 1865 [self updateFullscreenWithToolbarVisible:YES]; |
| 1956 [self.webController wasShown]; | 1866 [self.webController wasShown]; |
| 1957 [inputAccessoryViewController_ wasShown]; | 1867 [inputAccessoryViewController_ wasShown]; |
| 1958 } | 1868 } |
| 1959 | 1869 |
| 1960 - (void)wasHidden { | 1870 - (void)wasHidden { |
| 1961 visible_ = NO; | 1871 visible_ = NO; |
| 1962 [self updateFullscreenWithToolbarVisible:YES]; | 1872 [self updateFullscreenWithToolbarVisible:YES]; |
| 1963 [self.webController wasHidden]; | 1873 [self.webController wasHidden]; |
| 1964 [inputAccessoryViewController_ wasHidden]; | 1874 [inputAccessoryViewController_ wasHidden]; |
| 1965 } | 1875 } |
| 1966 | 1876 |
| 1967 #pragma mark - SadTabTabHelperDelegate | 1877 #pragma mark - SadTabTabHelperDelegate |
| 1968 | 1878 |
| 1969 - (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper { | 1879 - (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper { |
| 1970 UIApplicationState state = UIApplication.sharedApplication.applicationState; | 1880 UIApplicationState state = UIApplication.sharedApplication.applicationState; |
| 1971 return visible_ && !IsApplicationStateNotActive(state); | 1881 return visible_ && !IsApplicationStateNotActive(state); |
| 1972 } | 1882 } |
| 1973 | 1883 |
| 1974 @end | 1884 @end |
| 1975 | 1885 |
| 1976 #pragma mark - TestingSupport | 1886 #pragma mark - TestingSupport |
| 1977 | 1887 |
| 1978 @implementation Tab (TestingSupport) | 1888 @implementation Tab (TestingSupport) |
| 1979 | 1889 |
| 1980 - (void)replaceExternalAppLauncher:(id)externalAppLauncher { | 1890 - (void)replaceExternalAppLauncher:(id)externalAppLauncher { |
| 1981 externalAppLauncher_.reset([externalAppLauncher retain]); | 1891 externalAppLauncher_ = externalAppLauncher; |
| 1982 } | 1892 } |
| 1983 | 1893 |
| 1984 - (TabModel*)parentTabModel { | 1894 - (TabModel*)parentTabModel { |
| 1985 return parentTabModel_; | 1895 return parentTabModel_; |
| 1986 } | 1896 } |
| 1987 | 1897 |
| 1988 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 1898 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
| 1989 return inputAccessoryViewController_.get(); | 1899 return inputAccessoryViewController_; |
| 1990 } | 1900 } |
| 1991 | 1901 |
| 1992 @end | 1902 @end |
| OLD | NEW |