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 [self initNativeAppNavigationController]; | 481 [self initNativeAppNavigationController]; |
510 | 482 |
511 [[NSNotificationCenter defaultCenter] | 483 [[NSNotificationCenter defaultCenter] |
512 addObserver:self | 484 addObserver:self |
513 selector:@selector(applicationDidBecomeActive) | 485 selector:@selector(applicationDidBecomeActive) |
514 name:UIApplicationDidBecomeActiveNotification | 486 name:UIApplicationDidBecomeActiveNotification |
515 object:nil]; | 487 object:nil]; |
516 } | 488 } |
517 return self; | 489 return self; |
518 } | 490 } |
519 | 491 |
520 - (void)attachTabHelpers { | 492 - (void)attachTabHelpers { |
521 tabInfoBarObserver_.reset(new TabInfoBarObserver(self)); | 493 tabInfoBarObserver_ = base::MakeUnique<TabInfoBarObserver>(self); |
522 tabInfoBarObserver_->SetShouldObserveInfoBarManager(true); | 494 tabInfoBarObserver_->SetShouldObserveInfoBarManager(true); |
523 | 495 |
524 if (experimental_flags::IsAutoReloadEnabled()) { | 496 if (experimental_flags::IsAutoReloadEnabled()) |
525 autoReloadBridge_.reset([[AutoReloadBridge alloc] initWithTab:self]); | 497 autoReloadBridge_ = [[AutoReloadBridge alloc] initWithTab:self]; |
526 } | |
527 printObserver_ = base::MakeUnique<PrintObserver>(self.webState); | 498 printObserver_ = base::MakeUnique<PrintObserver>(self.webState); |
528 | 499 |
529 base::scoped_nsprotocol<id<PasswordsUiDelegate>> passwordsUiDelegate( | 500 base::scoped_nsprotocol<id<PasswordsUiDelegate>> passwordsUiDelegate( |
rohitrao (ping after 24h)
2017/05/02 11:42:54
Intentionally still using scoped_nsprotocol?
sdefresne
2017/05/02 15:08:51
No, I missed that one. Fixed. Thank you for the ca
| |
530 [[PasswordsUiDelegateImpl alloc] init]); | 501 [[PasswordsUiDelegateImpl alloc] init]); |
531 passwordController_.reset([[PasswordController alloc] | 502 passwordController_ = |
532 initWithWebState:self.webState | 503 [[PasswordController alloc] initWithWebState:self.webState |
533 passwordsUiDelegate:passwordsUiDelegate]); | 504 passwordsUiDelegate:passwordsUiDelegate]; |
534 password_manager::PasswordGenerationManager* passwordGenerationManager = | 505 password_manager::PasswordGenerationManager* passwordGenerationManager = |
535 [passwordController_ passwordGenerationManager]; | 506 [passwordController_ passwordGenerationManager]; |
536 autofillController_.reset([[AutofillController alloc] | 507 autofillController_ = |
537 initWithBrowserState:browserState_ | 508 [[AutofillController alloc] initWithBrowserState:browserState_ |
538 passwordGenerationManager:passwordGenerationManager | 509 passwordGenerationManager:passwordGenerationManager |
539 webState:self.webState]); | 510 webState:self.webState]; |
540 suggestionController_.reset([[FormSuggestionController alloc] | 511 suggestionController_ = [[FormSuggestionController alloc] |
541 initWithWebState:self.webState | 512 initWithWebState:self.webState |
542 providers:[self suggestionProviders]]); | 513 providers:[self suggestionProviders]]; |
543 inputAccessoryViewController_.reset([[FormInputAccessoryViewController alloc] | 514 inputAccessoryViewController_ = [[FormInputAccessoryViewController alloc] |
544 initWithWebState:self.webState | 515 initWithWebState:self.webState |
545 providers:[self accessoryViewProviders]]); | 516 providers:[self accessoryViewProviders]]; |
546 | 517 |
547 [self setShouldObserveFaviconChanges:YES]; | 518 [self setShouldObserveFaviconChanges:YES]; |
548 | 519 |
549 // Create the ReaderModeController immediately so it can register for | 520 // Create the ReaderModeController immediately so it can register for |
550 // WebState changes. | 521 // WebState changes. |
551 if (experimental_flags::IsReaderModeEnabled()) { | 522 if (experimental_flags::IsReaderModeEnabled()) { |
552 readerModeController_.reset([[ReaderModeController alloc] | 523 readerModeController_ = |
553 initWithWebState:self.webState | 524 [[ReaderModeController alloc] initWithWebState:self.webState |
554 delegate:self]); | 525 delegate:self]; |
555 } | 526 } |
556 } | 527 } |
557 | 528 |
558 - (NSArray*)accessoryViewProviders { | 529 - (NSArray*)accessoryViewProviders { |
559 NSMutableArray* providers = [NSMutableArray array]; | 530 NSMutableArray* providers = [NSMutableArray array]; |
560 id<FormInputAccessoryViewProvider> provider = | 531 id<FormInputAccessoryViewProvider> provider = |
561 [passwordController_ accessoryViewProvider]; | 532 [passwordController_ accessoryViewProvider]; |
562 if (provider) | 533 if (provider) |
563 [providers addObject:provider]; | 534 [providers addObject:provider]; |
564 [providers addObject:[suggestionController_ accessoryViewProvider]]; | 535 [providers addObject:[suggestionController_ accessoryViewProvider]]; |
565 return providers; | 536 return providers; |
566 } | 537 } |
567 | 538 |
568 - (NSArray*)suggestionProviders { | 539 - (NSArray*)suggestionProviders { |
569 NSMutableArray* providers = [NSMutableArray array]; | 540 NSMutableArray* providers = [NSMutableArray array]; |
570 [providers addObject:[passwordController_ suggestionProvider]]; | 541 [providers addObject:[passwordController_ suggestionProvider]]; |
571 [providers addObject:[autofillController_ suggestionProvider]]; | 542 [providers addObject:[autofillController_ suggestionProvider]]; |
572 return providers; | 543 return providers; |
573 } | 544 } |
574 | 545 |
575 - (id<FindInPageControllerDelegate>)findInPageControllerDelegate { | 546 - (id<FindInPageControllerDelegate>)findInPageControllerDelegate { |
576 return self; | 547 return self; |
577 } | 548 } |
578 | 549 |
579 - (void)setParentTabModel:(TabModel*)model { | 550 - (void)setParentTabModel:(TabModel*)model { |
580 DCHECK(!model || !parentTabModel_); | 551 DCHECK(!model || !parentTabModel_); |
581 parentTabModel_ = model; | 552 parentTabModel_ = model; |
582 | 553 |
583 if (parentTabModel_.syncedWindowDelegate) { | 554 if ([parentTabModel_ syncedWindowDelegate]) { |
rohitrao (ping after 24h)
2017/05/02 11:42:54
This no longer works as a property?
sdefresne
2017/05/02 15:08:51
I had an intermediate steps where I changed parent
| |
584 IOSChromeSessionTabHelper::FromWebState(self.webState) | 555 IOSChromeSessionTabHelper::FromWebState(self.webState) |
585 ->SetWindowID(model.sessionID); | 556 ->SetWindowID(model.sessionID); |
586 } | 557 } |
587 } | 558 } |
588 | 559 |
589 - (NSString*)description { | 560 - (NSString*)description { |
590 return [NSString stringWithFormat:@"%p ... %@ - %s", self, self.title, | 561 return [NSString stringWithFormat:@"%p ... %@ - %s", self, self.title, |
591 self.url.spec().c_str()]; | 562 self.url.spec().c_str()]; |
592 } | 563 } |
593 | 564 |
594 - (CRWWebController*)webController { | 565 - (CRWWebController*)webController { |
595 return webStateImpl_ ? webStateImpl_->GetWebController() : nil; | 566 return webStateImpl_ ? webStateImpl_->GetWebController() : nil; |
596 } | 567 } |
597 | 568 |
598 - (id<TabDialogDelegate>)dialogDelegate { | 569 - (id<TabDialogDelegate>)dialogDelegate { |
599 return dialogDelegate_; | 570 return dialogDelegate_; |
600 } | 571 } |
601 | 572 |
602 - (BOOL)loadFinished { | 573 - (BOOL)loadFinished { |
603 return [self.webController loadPhase] == web::PAGE_LOADED; | 574 return [self.webController loadPhase] == web::PAGE_LOADED; |
604 } | 575 } |
605 | 576 |
606 - (void)setDialogDelegate:(id<TabDialogDelegate>)dialogDelegate { | |
607 dialogDelegate_.reset(dialogDelegate); | |
608 } | |
609 | |
610 - (void)setIsVoiceSearchResultsTab:(BOOL)isVoiceSearchResultsTab { | 577 - (void)setIsVoiceSearchResultsTab:(BOOL)isVoiceSearchResultsTab { |
611 // There is intentionally no equality check in this setter, as we want the | 578 // There is intentionally no equality check in this setter, as we want the |
612 // notificaiton to be sent regardless of whether the value has changed. | 579 // notificaiton to be sent regardless of whether the value has changed. |
613 isVoiceSearchResultsTab_ = isVoiceSearchResultsTab; | 580 isVoiceSearchResultsTab_ = isVoiceSearchResultsTab; |
614 [parentTabModel_ notifyTabChanged:self]; | 581 [parentTabModel_ notifyTabChanged:self]; |
615 } | 582 } |
616 | 583 |
617 - (PasswordController*)passwordController { | |
618 return passwordController_.get(); | |
619 } | |
620 | |
621 - (void)retrieveSnapshot:(void (^)(UIImage*))callback { | 584 - (void)retrieveSnapshot:(void (^)(UIImage*))callback { |
622 [webControllerSnapshotHelper_ | 585 [webControllerSnapshotHelper_ |
623 retrieveSnapshotForWebController:self.webController | 586 retrieveSnapshotForWebController:self.webController |
624 sessionID:self.tabId | 587 sessionID:self.tabId |
625 withOverlays:[self snapshotOverlays] | 588 withOverlays:[self snapshotOverlays] |
626 callback:callback]; | 589 callback:callback]; |
627 } | 590 } |
628 | 591 |
629 - (const GURL&)url { | 592 - (const GURL&)url { |
630 // See note in header; this method should be removed. | 593 // See note in header; this method should be removed. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 | 626 |
664 - (NSString*)urlDisplayString { | 627 - (NSString*)urlDisplayString { |
665 base::string16 urlText = url_formatter::FormatUrl( | 628 base::string16 urlText = url_formatter::FormatUrl( |
666 self.url, url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, | 629 self.url, url_formatter::kFormatUrlOmitNothing, net::UnescapeRule::SPACES, |
667 nullptr, nullptr, nullptr); | 630 nullptr, nullptr, nullptr); |
668 return base::SysUTF16ToNSString(urlText); | 631 return base::SysUTF16ToNSString(urlText); |
669 } | 632 } |
670 | 633 |
671 - (NSString*)tabId { | 634 - (NSString*)tabId { |
672 if (tabId_) | 635 if (tabId_) |
673 return tabId_.get(); | 636 return tabId_; |
674 | 637 |
675 DCHECK(self.webState); | 638 DCHECK(self.webState); |
676 web::SerializableUserDataManager* userDataManager = | 639 web::SerializableUserDataManager* userDataManager = |
677 web::SerializableUserDataManager::FromWebState(self.webState); | 640 web::SerializableUserDataManager::FromWebState(self.webState); |
678 NSString* tabId = base::mac::ObjCCast<NSString>( | 641 NSString* tabId = base::mac::ObjCCast<NSString>( |
679 userDataManager->GetValueForSerializationKey(kTabIDKey)); | 642 userDataManager->GetValueForSerializationKey(kTabIDKey)); |
680 | 643 |
681 if (!tabId || ![tabId length]) { | 644 if (!tabId || ![tabId length]) { |
682 tabId = [[NSUUID UUID] UUIDString]; | 645 tabId = [[NSUUID UUID] UUIDString]; |
683 userDataManager->AddSerializableData(tabId, kTabIDKey); | 646 userDataManager->AddSerializableData(tabId, kTabIDKey); |
684 } | 647 } |
685 | 648 |
686 tabId_.reset([tabId copy]); | 649 tabId_ = [tabId copy]; |
687 return tabId_.get(); | 650 return tabId_; |
688 } | 651 } |
689 | 652 |
690 - (web::WebState*)webState { | 653 - (web::WebState*)webState { |
691 return webStateImpl_; | 654 return webStateImpl_; |
692 } | 655 } |
693 | 656 |
694 - (void)fetchFavicon { | 657 - (void)fetchFavicon { |
695 const GURL& url = self.url; | 658 const GURL& url = self.url; |
696 if (!url.is_valid()) | 659 if (!url.is_valid()) |
697 return; | 660 return; |
698 | 661 |
699 favicon::FaviconDriver* faviconDriver = | 662 favicon::FaviconDriver* faviconDriver = |
700 favicon::WebFaviconDriver::FromWebState(self.webState); | 663 favicon::WebFaviconDriver::FromWebState(self.webState); |
701 if (faviconDriver) { | 664 if (faviconDriver) |
702 faviconDriver->FetchFavicon(url); | 665 faviconDriver->FetchFavicon(url); |
703 } | |
704 } | 666 } |
705 | 667 |
706 - (void)setFavicon:(const gfx::Image*)image { | 668 - (void)setFavicon:(const gfx::Image*)image { |
707 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); | 669 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); |
708 if (!item) | 670 if (!item) |
709 return; | 671 return; |
710 if (image) { | 672 if (image) { |
711 item->GetFavicon().image = *image; | 673 item->GetFavicon().image = *image; |
712 item->GetFavicon().valid = true; | 674 item->GetFavicon().valid = true; |
713 } | 675 } |
714 [parentTabModel_ notifyTabChanged:self]; | 676 [parentTabModel_ notifyTabChanged:self]; |
715 } | 677 } |
716 | 678 |
717 - (UIImage*)favicon { | 679 - (UIImage*)favicon { |
718 DCHECK([self navigationManager]); | 680 DCHECK([self navigationManager]); |
719 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); | 681 web::NavigationItem* item = [self navigationManager]->GetVisibleItem(); |
720 if (!item) | 682 if (!item) |
721 return nil; | 683 return nil; |
722 const gfx::Image& image = item->GetFavicon().image; | 684 const gfx::Image& image = item->GetFavicon().image; |
723 if (image.IsEmpty()) | 685 if (image.IsEmpty()) |
724 return nil; | 686 return nil; |
725 return image.ToUIImage(); | 687 return image.ToUIImage(); |
726 } | 688 } |
727 | 689 |
728 - (UIView*)view { | 690 - (UIView*)view { |
729 // Record reload of previously-evicted tab. | 691 // Record reload of previously-evicted tab. |
730 if (![self.webController isViewAlive] && [parentTabModel_ tabUsageRecorder]) { | 692 if (![self.webController isViewAlive] && [parentTabModel_ tabUsageRecorder]) |
731 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 693 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
732 } | |
733 return self.webState ? self.webState->GetView() : nil; | 694 return self.webState ? self.webState->GetView() : nil; |
734 } | 695 } |
735 | 696 |
736 - (UIView*)viewForPrinting { | 697 - (UIView*)viewForPrinting { |
737 return self.webController.viewForPrinting; | 698 return self.webController.viewForPrinting; |
738 } | 699 } |
739 | 700 |
740 - (web::NavigationManager*)navigationManager { | 701 - (web::NavigationManager*)navigationManager { |
741 return self.webState ? self.webState->GetNavigationManager() : nullptr; | 702 return self.webState ? self.webState->GetNavigationManager() : nullptr; |
742 } | 703 } |
(...skipping 19 matching lines...) Expand all Loading... | |
762 } | 723 } |
763 | 724 |
764 - (void)didReplaceSessionHistory { | 725 - (void)didReplaceSessionHistory { |
765 // Replace fullScreenController_ with a new sessionID when the navigation | 726 // Replace fullScreenController_ with a new sessionID when the navigation |
766 // manager changes. | 727 // manager changes. |
767 // TODO(crbug.com/661666): Consider just updating sessionID and not replacing | 728 // TODO(crbug.com/661666): Consider just updating sessionID and not replacing |
768 // |fullScreenController_|. | 729 // |fullScreenController_|. |
769 if (fullScreenController_) { | 730 if (fullScreenController_) { |
770 [fullScreenController_ invalidate]; | 731 [fullScreenController_ invalidate]; |
771 [self.webController removeObserver:fullScreenController_]; | 732 [self.webController removeObserver:fullScreenController_]; |
772 fullScreenController_.reset([[FullScreenController alloc] | 733 fullScreenController_ = [[FullScreenController alloc] |
773 initWithDelegate:fullScreenControllerDelegate_ | 734 initWithDelegate:fullScreenControllerDelegate_ |
774 navigationManager:self.navigationManager | 735 navigationManager:self.navigationManager |
775 sessionID:self.tabId]); | 736 sessionID:self.tabId]; |
776 [self.webController addObserver:fullScreenController_]; | 737 [self.webController addObserver:fullScreenController_]; |
777 // If the content of the page was loaded without knowledge of the | 738 // If the content of the page was loaded without knowledge of the |
778 // toolbar position it will be misplaced under the toolbar instead of | 739 // toolbar position it will be misplaced under the toolbar instead of |
779 // right below. This happens e.g. in the case of preloading. This is to make | 740 // right below. This happens e.g. in the case of preloading. This is to make |
780 // sure the content is moved to the right place. | 741 // sure the content is moved to the right place. |
781 [fullScreenController_ moveContentBelowHeader]; | 742 [fullScreenController_ moveContentBelowHeader]; |
782 } | 743 } |
783 } | 744 } |
784 | 745 |
785 - (void)setIsLinkLoadingPrerenderTab:(BOOL)isLinkLoadingPrerenderTab { | 746 - (void)setIsLinkLoadingPrerenderTab:(BOOL)isLinkLoadingPrerenderTab { |
(...skipping 23 matching lines...) Expand all Loading... | |
809 BOOL loadingFinished = self.webController.loadPhase == web::PAGE_LOADED; | 770 BOOL loadingFinished = self.webController.loadPhase == web::PAGE_LOADED; |
810 if (loadingFinished) | 771 if (loadingFinished) |
811 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 772 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
812 | 773 |
813 [[OmniboxGeolocationController sharedInstance] | 774 [[OmniboxGeolocationController sharedInstance] |
814 finishPageLoadForTab:self | 775 finishPageLoadForTab:self |
815 loadSuccess:loadingFinished]; | 776 loadSuccess:loadingFinished]; |
816 [self countMainFrameLoad]; | 777 [self countMainFrameLoad]; |
817 } | 778 } |
818 | 779 |
819 - (id<FullScreenControllerDelegate>)fullScreenControllerDelegate { | |
820 return fullScreenControllerDelegate_.get(); | |
821 } | |
822 | |
823 - (void)setFullScreenControllerDelegate: | 780 - (void)setFullScreenControllerDelegate: |
824 (id<FullScreenControllerDelegate>)fullScreenControllerDelegate { | 781 (id<FullScreenControllerDelegate>)fullScreenControllerDelegate { |
825 if (fullScreenControllerDelegate == fullScreenControllerDelegate_) { | 782 if (fullScreenControllerDelegate == fullScreenControllerDelegate_) |
826 return; | 783 return; |
827 } | |
828 // Lazily create a FullScreenController. | 784 // Lazily create a FullScreenController. |
829 // The check for fullScreenControllerDelegate is necessary to avoid recreating | 785 // The check for fullScreenControllerDelegate is necessary to avoid recreating |
830 // a FullScreenController during teardown. | 786 // a FullScreenController during teardown. |
831 if (!fullScreenController_ && fullScreenControllerDelegate) { | 787 if (!fullScreenController_ && fullScreenControllerDelegate) { |
832 fullScreenController_.reset([[FullScreenController alloc] | 788 fullScreenController_ = [[FullScreenController alloc] |
833 initWithDelegate:fullScreenControllerDelegate | 789 initWithDelegate:fullScreenControllerDelegate |
834 navigationManager:self.navigationManager | 790 navigationManager:self.navigationManager |
835 sessionID:self.tabId]); | 791 sessionID:self.tabId]; |
836 [self.webController addObserver:fullScreenController_]; | 792 [self.webController addObserver:fullScreenController_]; |
837 // If the content of the page was loaded without knowledge of the | 793 // If the content of the page was loaded without knowledge of the |
838 // toolbar position it will be misplaced under the toolbar instead of | 794 // toolbar position it will be misplaced under the toolbar instead of |
839 // right below. This happens e.g. in the case of preloading. This is to make | 795 // right below. This happens e.g. in the case of preloading. This is to make |
840 // sure the content is moved to the right place. | 796 // sure the content is moved to the right place. |
841 [fullScreenController_ moveContentBelowHeader]; | 797 [fullScreenController_ moveContentBelowHeader]; |
842 } | 798 } |
843 fullScreenControllerDelegate_.reset(fullScreenControllerDelegate); | 799 fullScreenControllerDelegate_ = fullScreenControllerDelegate; |
844 } | |
845 | |
846 - (OverscrollActionsController*)overscrollActionsController { | |
847 return overscrollActionsController_.get(); | |
848 } | |
849 | |
850 - (id<OverscrollActionsControllerDelegate>)overscrollActionsControllerDelegate { | |
851 return overscrollActionsControllerDelegate_.get(); | |
852 } | 800 } |
853 | 801 |
854 - (void)setOverscrollActionsControllerDelegate: | 802 - (void)setOverscrollActionsControllerDelegate: |
855 (id<OverscrollActionsControllerDelegate>) | 803 (id<OverscrollActionsControllerDelegate>) |
856 overscrollActionsControllerDelegate { | 804 overscrollActionsControllerDelegate { |
857 if (overscrollActionsControllerDelegate_ == | 805 if (overscrollActionsControllerDelegate_ == |
858 overscrollActionsControllerDelegate) | 806 overscrollActionsControllerDelegate) { |
859 return; | 807 return; |
808 } | |
860 | 809 |
861 // Lazily create a OverscrollActionsController. | 810 // Lazily create a OverscrollActionsController. |
862 // The check for overscrollActionsControllerDelegate is necessary to avoid | 811 // The check for overscrollActionsControllerDelegate is necessary to avoid |
863 // recreating a OverscrollActionsController during teardown. | 812 // recreating a OverscrollActionsController during teardown. |
864 if (!overscrollActionsController_) { | 813 if (!overscrollActionsController_) { |
865 overscrollActionsController_.reset( | 814 overscrollActionsController_ = [[OverscrollActionsController alloc] init]; |
866 [[OverscrollActionsController alloc] init]); | |
867 [self.webController addObserver:overscrollActionsController_]; | 815 [self.webController addObserver:overscrollActionsController_]; |
868 } | 816 } |
869 OverscrollStyle style = OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO; | 817 OverscrollStyle style = OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO; |
870 if (browserState_->IsOffTheRecord()) { | 818 if (browserState_->IsOffTheRecord()) |
871 style = OverscrollStyle::REGULAR_PAGE_INCOGNITO; | 819 style = OverscrollStyle::REGULAR_PAGE_INCOGNITO; |
872 } | |
873 [overscrollActionsController_ setStyle:style]; | 820 [overscrollActionsController_ setStyle:style]; |
874 [overscrollActionsController_ | 821 [overscrollActionsController_ |
875 setDelegate:overscrollActionsControllerDelegate]; | 822 setDelegate:overscrollActionsControllerDelegate]; |
876 overscrollActionsControllerDelegate_.reset( | 823 overscrollActionsControllerDelegate_ = overscrollActionsControllerDelegate; |
877 overscrollActionsControllerDelegate); | |
878 } | 824 } |
879 | 825 |
880 - (void)saveTitleToHistoryDB { | 826 - (void)saveTitleToHistoryDB { |
881 // If incognito, don't update history. | 827 // If incognito, don't update history. |
882 if (browserState_->IsOffTheRecord()) | 828 if (browserState_->IsOffTheRecord()) |
883 return; | 829 return; |
884 // Don't update the history if current entry has no title. | 830 // Don't update the history if current entry has no title. |
885 NSString* title = [self title]; | 831 NSString* title = [self title]; |
886 if (![title length] || | 832 if (![title length] || |
887 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) | 833 [title isEqualToString:l10n_util::GetNSString(IDS_DEFAULT_TAB_TITLE)]) { |
888 return; | 834 return; |
835 } | |
889 | 836 |
890 history::HistoryService* historyService = | 837 history::HistoryService* historyService = |
891 ios::HistoryServiceFactory::GetForBrowserState( | 838 ios::HistoryServiceFactory::GetForBrowserState( |
892 browserState_, ServiceAccessType::IMPLICIT_ACCESS); | 839 browserState_, ServiceAccessType::IMPLICIT_ACCESS); |
893 DCHECK(historyService); | 840 DCHECK(historyService); |
894 historyService->SetPageTitle(self.url, base::SysNSStringToUTF16(title)); | 841 historyService->SetPageTitle(self.url, base::SysNSStringToUTF16(title)); |
895 } | 842 } |
896 | 843 |
897 - (void)addCurrentEntryToHistoryDB { | 844 - (void)addCurrentEntryToHistoryDB { |
898 DCHECK([self navigationManager]->GetVisibleItem()); | 845 DCHECK([self navigationManager]->GetVisibleItem()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 } | 891 } |
945 | 892 |
946 DCHECK(item->GetTimestamp().ToInternalValue() > 0); | 893 DCHECK(item->GetTimestamp().ToInternalValue() > 0); |
947 if ([self isPrerenderTab]) { | 894 if ([self isPrerenderTab]) { |
948 // Clicks on content suggestions on the NTP should not contribute to the | 895 // Clicks on content suggestions on the NTP should not contribute to the |
949 // Most Visited tiles in the NTP. | 896 // Most Visited tiles in the NTP. |
950 const bool consider_for_ntp_most_visited = | 897 const bool consider_for_ntp_most_visited = |
951 referrer.url != GURL(kChromeContentSuggestionsReferrer); | 898 referrer.url != GURL(kChromeContentSuggestionsReferrer); |
952 | 899 |
953 history::HistoryAddPageArgs args( | 900 history::HistoryAddPageArgs args( |
954 url, item->GetTimestamp(), tabHistoryContext_.get(), | 901 url, item->GetTimestamp(), &tabHistoryContext_, item->GetUniqueID(), |
955 item->GetUniqueID(), referrer.url, redirects, item->GetTransitionType(), | 902 referrer.url, redirects, item->GetTransitionType(), |
956 history::SOURCE_BROWSED, false, consider_for_ntp_most_visited); | 903 history::SOURCE_BROWSED, false, consider_for_ntp_most_visited); |
957 addPageVector_.push_back(args); | 904 addPageVector_.push_back(args); |
958 } else { | 905 } else { |
959 historyService->AddPage(url, item->GetTimestamp(), tabHistoryContext_.get(), | 906 historyService->AddPage(url, item->GetTimestamp(), &tabHistoryContext_, |
960 item->GetUniqueID(), referrer.url, redirects, | 907 item->GetUniqueID(), referrer.url, redirects, |
961 item->GetTransitionType(), history::SOURCE_BROWSED, | 908 item->GetTransitionType(), history::SOURCE_BROWSED, |
962 false); | 909 false); |
963 [self saveTitleToHistoryDB]; | 910 [self saveTitleToHistoryDB]; |
964 } | 911 } |
965 } | 912 } |
966 | 913 |
967 - (void)commitCachedEntriesToHistoryDB { | 914 - (void)commitCachedEntriesToHistoryDB { |
968 // If OTR, don't update history. | 915 // If OTR, don't update history. |
969 if (browserState_->IsOffTheRecord()) { | 916 if (browserState_->IsOffTheRecord()) { |
(...skipping 27 matching lines...) Expand all Loading... | |
997 } | 944 } |
998 } | 945 } |
999 | 946 |
1000 ui::PageTransition transition = params.transition_type; | 947 ui::PageTransition transition = params.transition_type; |
1001 | 948 |
1002 // Record any explicit, non-redirect navigation as a clobber (as long as it's | 949 // Record any explicit, non-redirect navigation as a clobber (as long as it's |
1003 // in a real tab). | 950 // in a real tab). |
1004 if (!initialNavigation && !isPrerenderTab_ && | 951 if (!initialNavigation && !isPrerenderTab_ && |
1005 !PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && | 952 !PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && |
1006 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) { | 953 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) { |
1007 base::RecordAction(UserMetricsAction("MobileTabClobbered")); | 954 base::RecordAction(base::UserMetricsAction("MobileTabClobbered")); |
1008 } | 955 } |
1009 if ([parentTabModel_ tabUsageRecorder]) | 956 if ([parentTabModel_ tabUsageRecorder]) |
1010 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 957 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
1011 | 958 |
1012 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. | 959 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. |
1013 self.isVoiceSearchResultsTab = NO; | 960 self.isVoiceSearchResultsTab = NO; |
1014 | 961 |
1015 web::NavigationItem* navigationItem = | 962 web::NavigationItem* navigationItem = |
1016 [self navigationManager]->GetPendingItem(); | 963 [self navigationManager]->GetPendingItem(); |
1017 | 964 |
1018 // TODO(crbug.com/676129): the pending item is not correctly set when the | 965 // TODO(crbug.com/676129): the pending item is not correctly set when the |
1019 // page is reloading, use the last committed item if pending item is null. | 966 // page is reloading, use the last committed item if pending item is null. |
1020 // Remove this once tracking bug is fixed. | 967 // Remove this once tracking bug is fixed. |
1021 if (!navigationItem) | 968 if (!navigationItem) |
1022 navigationItem = [self navigationManager]->GetLastCommittedItem(); | 969 navigationItem = [self navigationManager]->GetLastCommittedItem(); |
1023 | 970 |
1024 [[OmniboxGeolocationController sharedInstance] | 971 [[OmniboxGeolocationController sharedInstance] |
1025 addLocationToNavigationItem:navigationItem | 972 addLocationToNavigationItem:navigationItem |
1026 browserState:browserState_]; | 973 browserState:browserState_]; |
1027 } | 974 } |
1028 | 975 |
1029 - (void)loadSessionTab:(const sessions::SessionTab*)sessionTab { | 976 - (void)loadSessionTab:(const sessions::SessionTab*)sessionTab { |
1030 DCHECK(sessionTab); | 977 DCHECK(sessionTab); |
1031 [self replaceHistoryWithNavigations:sessionTab->navigations | 978 [self replaceHistoryWithNavigations:sessionTab->navigations |
1032 currentIndex:sessionTab->current_navigation_index]; | 979 currentIndex:sessionTab->current_navigation_index]; |
1033 } | 980 } |
1034 | 981 |
1035 - (void)webWillReload { | 982 - (void)webWillReload { |
1036 if ([parentTabModel_ tabUsageRecorder]) { | 983 if ([parentTabModel_ tabUsageRecorder]) |
1037 [parentTabModel_ tabUsageRecorder]->RecordReload(self); | 984 [parentTabModel_ tabUsageRecorder]->RecordReload(self); |
1038 } | |
1039 } | 985 } |
1040 | 986 |
1041 // Halt the tab, which amounts to halting its webController. | 987 // Halt the tab, which amounts to halting its webController. |
1042 - (void)terminateNetworkActivity { | 988 - (void)terminateNetworkActivity { |
1043 [self.webController terminateNetworkActivity]; | 989 [self.webController terminateNetworkActivity]; |
1044 } | 990 } |
1045 | 991 |
1046 - (void)webStateDestroyed:(web::WebState*)webState { | 992 - (void)webStateDestroyed:(web::WebState*)webState { |
1047 DCHECK_EQ(webStateImpl_, webState); | 993 DCHECK_EQ(webStateImpl_, webState); |
1048 self.fullScreenControllerDelegate = nil; | 994 self.fullScreenControllerDelegate = nil; |
1049 self.overscrollActionsControllerDelegate = nil; | 995 self.overscrollActionsControllerDelegate = nil; |
1050 self.passKitDialogProvider = nil; | 996 self.passKitDialogProvider = nil; |
1051 self.snapshotOverlayProvider = nil; | 997 self.snapshotOverlayProvider = nil; |
1052 | 998 |
1053 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 999 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
1054 | 1000 |
1055 [passwordController_ detach]; | 1001 [passwordController_ detach]; |
1056 passwordController_.reset(); | 1002 passwordController_ = nil; |
1057 tabInfoBarObserver_.reset(); | 1003 tabInfoBarObserver_.reset(); |
1058 | 1004 |
1059 faviconDriverObserverBridge_.reset(); | 1005 faviconDriverObserverBridge_.reset(); |
1060 [openInController_ detachFromWebController]; | 1006 [openInController_ detachFromWebController]; |
1061 openInController_.reset(); | 1007 openInController_ = nil; |
1062 [autofillController_ detachFromWebState]; | 1008 [autofillController_ detachFromWebState]; |
1063 [suggestionController_ detachFromWebState]; | 1009 [suggestionController_ detachFromWebState]; |
1064 if (fullScreenController_) | 1010 if (fullScreenController_) |
1065 [self.webController removeObserver:fullScreenController_]; | 1011 [self.webController removeObserver:fullScreenController_]; |
1066 [fullScreenController_ invalidate]; | 1012 [fullScreenController_ invalidate]; |
1067 fullScreenController_.reset(); | 1013 fullScreenController_ = nil; |
1068 if (overscrollActionsController_) | 1014 if (overscrollActionsController_) |
1069 [self.webController removeObserver:overscrollActionsController_]; | 1015 [self.webController removeObserver:overscrollActionsController_]; |
1070 [overscrollActionsController_ invalidate]; | 1016 [overscrollActionsController_ invalidate]; |
1071 overscrollActionsController_.reset(); | 1017 overscrollActionsController_ = nil; |
1072 [readerModeController_ detachFromWebState]; | 1018 [readerModeController_ detachFromWebState]; |
1073 readerModeController_.reset(); | 1019 readerModeController_ = nil; |
1074 | 1020 |
1075 // Invalidate any snapshot stored for this session. | 1021 // Invalidate any snapshot stored for this session. |
1076 DCHECK(self.tabId); | 1022 DCHECK(self.tabId); |
1077 [snapshotManager_ removeImageWithSessionID:self.tabId]; | 1023 [snapshotManager_ removeImageWithSessionID:self.tabId]; |
1078 | 1024 |
1079 // Cancel any queued dialogs. | 1025 // Cancel any queued dialogs. |
1080 [self.dialogDelegate cancelDialogForTab:self]; | 1026 [self.dialogDelegate cancelDialogForTab:self]; |
1081 | 1027 |
1082 webStateObserver_.reset(); | 1028 webStateObserver_.reset(); |
1083 webStateImpl_ = nullptr; | 1029 webStateImpl_ = nullptr; |
1084 } | 1030 } |
1085 | 1031 |
1086 - (void)dismissModals { | 1032 - (void)dismissModals { |
1087 [openInController_ disable]; | 1033 [openInController_ disable]; |
1088 [self.webController dismissModals]; | 1034 [self.webController dismissModals]; |
1089 } | 1035 } |
1090 | 1036 |
1091 - (void)setShouldObserveInfoBarManager:(BOOL)shouldObserveInfoBarManager { | 1037 - (void)setShouldObserveInfoBarManager:(BOOL)shouldObserveInfoBarManager { |
1092 tabInfoBarObserver_->SetShouldObserveInfoBarManager( | 1038 tabInfoBarObserver_->SetShouldObserveInfoBarManager( |
1093 shouldObserveInfoBarManager); | 1039 shouldObserveInfoBarManager); |
1094 } | 1040 } |
1095 | 1041 |
1096 - (void)setShouldObserveFaviconChanges:(BOOL)shouldObserveFaviconChanges { | 1042 - (void)setShouldObserveFaviconChanges:(BOOL)shouldObserveFaviconChanges { |
1097 if (shouldObserveFaviconChanges) { | 1043 if (shouldObserveFaviconChanges) { |
1098 favicon::FaviconDriver* faviconDriver = | 1044 favicon::FaviconDriver* faviconDriver = |
1099 favicon::WebFaviconDriver::FromWebState(self.webState); | 1045 favicon::WebFaviconDriver::FromWebState(self.webState); |
1100 // Some MockWebContents used in tests do not support the FaviconDriver. | 1046 // Some MockWebContents used in tests do not support the FaviconDriver. |
1101 if (faviconDriver) { | 1047 if (faviconDriver) { |
1102 faviconDriverObserverBridge_.reset( | 1048 faviconDriverObserverBridge_ = |
1103 new FaviconDriverObserverBridge(self, faviconDriver)); | 1049 base::MakeUnique<FaviconDriverObserverBridge>(self, faviconDriver); |
1104 } | 1050 } |
1105 } else { | 1051 } else { |
1106 faviconDriverObserverBridge_.reset(); | 1052 faviconDriverObserverBridge_.reset(); |
1107 } | 1053 } |
1108 } | 1054 } |
1109 | 1055 |
1110 - (void)goBack { | 1056 - (void)goBack { |
1111 if (self.navigationManager) { | 1057 if (self.navigationManager) { |
1112 DCHECK(self.navigationManager->CanGoBack()); | 1058 DCHECK(self.navigationManager->CanGoBack()); |
1113 base::RecordAction(UserMetricsAction("Back")); | 1059 base::RecordAction(base::UserMetricsAction("Back")); |
1114 self.navigationManager->GoBack(); | 1060 self.navigationManager->GoBack(); |
1115 } | 1061 } |
1116 } | 1062 } |
1117 | 1063 |
1118 - (void)goForward { | 1064 - (void)goForward { |
1119 if (self.navigationManager) { | 1065 if (self.navigationManager) { |
1120 DCHECK(self.navigationManager->CanGoForward()); | 1066 DCHECK(self.navigationManager->CanGoForward()); |
1121 base::RecordAction(UserMetricsAction("Forward")); | 1067 base::RecordAction(base::UserMetricsAction("Forward")); |
1122 self.navigationManager->GoForward(); | 1068 self.navigationManager->GoForward(); |
1123 } | 1069 } |
1124 } | 1070 } |
1125 | 1071 |
1126 - (BOOL)canGoBack { | 1072 - (BOOL)canGoBack { |
1127 return self.navigationManager && self.navigationManager->CanGoBack(); | 1073 return self.navigationManager && self.navigationManager->CanGoBack(); |
1128 } | 1074 } |
1129 | 1075 |
1130 - (BOOL)canGoForward { | 1076 - (BOOL)canGoForward { |
1131 return self.navigationManager && self.navigationManager->CanGoForward(); | 1077 return self.navigationManager && self.navigationManager->CanGoForward(); |
1132 } | 1078 } |
1133 | 1079 |
1134 - (void)goToItem:(const web::NavigationItem*)item { | 1080 - (void)goToItem:(const web::NavigationItem*)item { |
1135 DCHECK(item); | 1081 DCHECK(item); |
1136 | 1082 |
1137 if (self.navigationManager) { | 1083 if (self.navigationManager) { |
1138 CRWSessionController* sessionController = | 1084 CRWSessionController* sessionController = |
1139 [self navigationManagerImpl]->GetSessionController(); | 1085 [self navigationManagerImpl]->GetSessionController(); |
1140 NSInteger itemIndex = [sessionController indexOfItem:item]; | 1086 NSInteger itemIndex = [sessionController indexOfItem:item]; |
1141 DCHECK_NE(itemIndex, NSNotFound); | 1087 DCHECK_NE(itemIndex, NSNotFound); |
1142 self.navigationManager->GoToIndex(itemIndex); | 1088 self.navigationManager->GoToIndex(itemIndex); |
1143 } | 1089 } |
1144 } | 1090 } |
1145 | 1091 |
1146 - (BOOL)openExternalURL:(const GURL&)url | 1092 - (BOOL)openExternalURL:(const GURL&)url |
1147 sourceURL:(const GURL&)sourceURL | 1093 sourceURL:(const GURL&)sourceURL |
1148 linkClicked:(BOOL)linkClicked { | 1094 linkClicked:(BOOL)linkClicked { |
1149 if (!externalAppLauncher_.get()) | 1095 if (!externalAppLauncher_) |
1150 externalAppLauncher_.reset([[ExternalAppLauncher alloc] init]); | 1096 externalAppLauncher_ = [[ExternalAppLauncher alloc] init]; |
1151 | 1097 |
1152 // This method may release CRWWebController which may cause a crash | 1098 // This method may release CRWWebController which may cause a crash |
1153 // (crbug.com/393949). | 1099 // (crbug.com/393949). |
1154 [[self.webController retain] autorelease]; | 1100 // [[self.webController retain] autorelease]; |
rohitrao (ping after 24h)
2017/05/02 11:42:54
What is the plan for replacing this call? Should
sdefresne
2017/05/02 15:08:51
This call can be safely removed as the lifetime of
| |
1155 | 1101 |
1156 // Make a local url copy for possible modification. | 1102 // Make a local url copy for possible modification. |
1157 GURL finalURL = url; | 1103 GURL finalURL = url; |
1158 | 1104 |
1159 // Check if it's a direct FIDO U2F x-callback call. If so, do not open it, to | 1105 // Check if it's a direct FIDO U2F x-callback call. If so, do not open it, to |
1160 // prevent pages from spoofing requests with different origins. | 1106 // prevent pages from spoofing requests with different origins. |
1161 if (finalURL.SchemeIs("u2f-x-callback")) { | 1107 if (finalURL.SchemeIs("u2f-x-callback")) |
1162 return NO; | 1108 return NO; |
1163 } | |
1164 | 1109 |
1165 // Check if it's a FIDO U2F call. | 1110 // Check if it's a FIDO U2F call. |
1166 if (finalURL.SchemeIs("u2f")) { | 1111 if (finalURL.SchemeIs("u2f")) { |
1167 // Create U2FController object lazily. | 1112 // Create U2FController object lazily. |
1168 if (!U2FController_) { | 1113 if (!U2FController_) |
1169 U2FController_.reset([[U2FController alloc] init]); | 1114 U2FController_ = [[U2FController alloc] init]; |
1170 } | |
1171 | 1115 |
1172 DCHECK([self navigationManager]); | 1116 DCHECK([self navigationManager]); |
1173 GURL origin = | 1117 GURL origin = |
1174 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); | 1118 [self navigationManager]->GetLastCommittedItem()->GetURL().GetOrigin(); |
1175 | 1119 |
1176 // Compose u2f-x-callback URL and update urlToOpen. | 1120 // Compose u2f-x-callback URL and update urlToOpen. |
1177 finalURL = [U2FController_ XCallbackFromRequestURL:finalURL | 1121 finalURL = [U2FController_ XCallbackFromRequestURL:finalURL |
1178 originURL:origin | 1122 originURL:origin |
1179 tabURL:self.url | 1123 tabURL:self.url |
1180 tabID:self.tabId]; | 1124 tabID:self.tabId]; |
1181 | 1125 |
1182 if (!finalURL.is_valid()) { | 1126 if (!finalURL.is_valid()) |
1183 return NO; | 1127 return NO; |
1184 } | |
1185 } | 1128 } |
1186 | 1129 |
1187 if ([externalAppLauncher_ openURL:finalURL linkClicked:linkClicked]) { | 1130 if ([externalAppLauncher_ openURL:finalURL linkClicked:linkClicked]) { |
1188 // Clears pending navigation history after successfully launching the | 1131 // Clears pending navigation history after successfully launching the |
1189 // external app. | 1132 // external app. |
1190 DCHECK([self navigationManager]); | 1133 DCHECK([self navigationManager]); |
1191 [self navigationManager]->DiscardNonCommittedItems(); | 1134 [self navigationManager]->DiscardNonCommittedItems(); |
1192 // Ensure the UI reflects the current entry, not the just-discarded pending | 1135 // Ensure the UI reflects the current entry, not the just-discarded pending |
1193 // entry. | 1136 // entry. |
1194 [parentTabModel_ notifyTabChanged:self]; | 1137 [parentTabModel_ notifyTabChanged:self]; |
1195 | 1138 |
1196 if (sourceURL.is_valid()) { | 1139 if (sourceURL.is_valid()) { |
1197 ReadingListModel* model = | 1140 ReadingListModel* model = |
1198 ReadingListModelFactory::GetForBrowserState(browserState_); | 1141 ReadingListModelFactory::GetForBrowserState(browserState_); |
1199 if (model && model->loaded()) { | 1142 if (model && model->loaded()) |
1200 model->SetReadStatus(sourceURL, true); | 1143 model->SetReadStatus(sourceURL, true); |
1201 } | |
1202 } | 1144 } |
1203 | 1145 |
1204 return YES; | 1146 return YES; |
1205 } | 1147 } |
1206 return NO; | 1148 return NO; |
1207 } | 1149 } |
1208 | 1150 |
1209 - (void)webState:(web::WebState*)webState | 1151 - (void)webState:(web::WebState*)webState |
1210 didFinishNavigation:(web::NavigationContext*)navigation { | 1152 didFinishNavigation:(web::NavigationContext*)navigation { |
1211 if (navigation->IsSameDocument()) { | 1153 if (navigation->IsSameDocument()) { |
1154 // Fetch the favicon for the new URL. | |
1212 auto* faviconDriver = favicon::WebFaviconDriver::FromWebState(webState); | 1155 auto* faviconDriver = favicon::WebFaviconDriver::FromWebState(webState); |
1213 if (faviconDriver) { | 1156 if (faviconDriver) |
1214 // Fetch the favicon for the new URL. | |
1215 faviconDriver->FetchFavicon(navigation->GetUrl()); | 1157 faviconDriver->FetchFavicon(navigation->GetUrl()); |
1216 } | |
1217 } | 1158 } |
1218 | 1159 |
1219 if (!navigation->IsErrorPage()) { | 1160 if (!navigation->IsErrorPage()) { |
1220 [self addCurrentEntryToHistoryDB]; | 1161 [self addCurrentEntryToHistoryDB]; |
1221 [self countMainFrameLoad]; | 1162 [self countMainFrameLoad]; |
1222 } | 1163 } |
1223 | 1164 |
1224 [parentTabModel_ notifyTabChanged:self]; | 1165 [parentTabModel_ notifyTabChanged:self]; |
1225 } | 1166 } |
1226 | 1167 |
(...skipping 10 matching lines...) Expand all Loading... | |
1237 break; | 1178 break; |
1238 case UIInterfaceOrientationUnknown: | 1179 case UIInterfaceOrientationUnknown: |
1239 // TODO(crbug.com/228832): Convert from a boolean histogram to an | 1180 // TODO(crbug.com/228832): Convert from a boolean histogram to an |
1240 // enumerated histogram and log this case as well. | 1181 // enumerated histogram and log this case as well. |
1241 break; | 1182 break; |
1242 } | 1183 } |
1243 } | 1184 } |
1244 | 1185 |
1245 - (OpenInController*)openInController { | 1186 - (OpenInController*)openInController { |
1246 if (!openInController_) { | 1187 if (!openInController_) { |
1247 openInController_.reset([[OpenInController alloc] | 1188 openInController_ = [[OpenInController alloc] |
1248 initWithRequestContext:browserState_->GetRequestContext() | 1189 initWithRequestContext:browserState_->GetRequestContext() |
1249 webController:self.webController]); | 1190 webController:self.webController]; |
1250 } | 1191 } |
1251 return openInController_.get(); | 1192 return openInController_; |
1252 } | 1193 } |
1253 | 1194 |
1254 - (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url { | 1195 - (id<CRWNativeContent>)controllerForUnhandledContentAtURL:(const GURL&)url { |
1255 // Shows download manager UI for unhandled content. | 1196 // Shows download manager UI for unhandled content. |
1256 DownloadManagerController* downloadController = | 1197 DownloadManagerController* downloadController = |
1257 [[[DownloadManagerController alloc] initWithWebState:self.webState | 1198 [[DownloadManagerController alloc] initWithWebState:self.webState |
1258 downloadURL:url] autorelease]; | 1199 downloadURL:url]; |
1259 [downloadController start]; | 1200 [downloadController start]; |
1260 return downloadController; | 1201 return downloadController; |
1261 } | 1202 } |
1262 | 1203 |
1263 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers { | 1204 - (void)handleExportableFile:(net::HttpResponseHeaders*)headers { |
1264 // Only "application/pdf" is supported for now. | 1205 // Only "application/pdf" is supported for now. |
1265 if (self.webState->GetContentsMimeType() != "application/pdf") | 1206 if (self.webState->GetContentsMimeType() != "application/pdf") |
1266 return; | 1207 return; |
1267 | 1208 |
1268 [[NSNotificationCenter defaultCenter] | 1209 [[NSNotificationCenter defaultCenter] |
(...skipping 12 matching lines...) Expand all Loading... | |
1281 "", // referrer-charset | 1222 "", // referrer-charset |
1282 "", // suggested-name | 1223 "", // suggested-name |
1283 "application/pdf", // mime-type | 1224 "application/pdf", // mime-type |
1284 defaultFilename); | 1225 defaultFilename); |
1285 [[self openInController] | 1226 [[self openInController] |
1286 enableWithDocumentURL:self.url | 1227 enableWithDocumentURL:self.url |
1287 suggestedFilename:base::SysUTF16ToNSString(filename)]; | 1228 suggestedFilename:base::SysUTF16ToNSString(filename)]; |
1288 } | 1229 } |
1289 | 1230 |
1290 - (void)countMainFrameLoad { | 1231 - (void)countMainFrameLoad { |
1291 if ([self isPrerenderTab] || [self url].SchemeIs(kChromeUIScheme)) { | 1232 if ([self isPrerenderTab] || [self url].SchemeIs(kChromeUIScheme)) |
1292 return; | 1233 return; |
1293 } | 1234 base::RecordAction(base::UserMetricsAction("MobilePageLoaded")); |
1294 base::RecordAction(UserMetricsAction("MobilePageLoaded")); | |
1295 } | 1235 } |
1296 | 1236 |
1297 - (void)applicationDidBecomeActive { | 1237 - (void)applicationDidBecomeActive { |
1298 if (requireReloadAfterBecomingActive_) { | 1238 if (!requireReloadAfterBecomingActive_) |
1299 if (visible_) { | 1239 return; |
1300 self.navigationManager->Reload(web::ReloadType::NORMAL, | 1240 if (visible_) { |
1301 false /* check_for_repost */); | 1241 self.navigationManager->Reload(web::ReloadType::NORMAL, |
1302 } else { | 1242 false /* check_for_repost */); |
1303 [self.webController requirePageReload]; | 1243 } else { |
1304 } | 1244 [self.webController requirePageReload]; |
1305 requireReloadAfterBecomingActive_ = NO; | |
1306 } | 1245 } |
1246 requireReloadAfterBecomingActive_ = NO; | |
1307 } | 1247 } |
1308 | 1248 |
1309 #pragma mark - | 1249 #pragma mark - |
1310 #pragma mark FindInPageControllerDelegate | 1250 #pragma mark FindInPageControllerDelegate |
1311 | 1251 |
1312 - (void)willAdjustScrollPosition { | 1252 - (void)willAdjustScrollPosition { |
1313 // Skip the next attempt to correct the scroll offset for the toolbar height. | 1253 // Skip the next attempt to correct the scroll offset for the toolbar height. |
1314 // Used when programatically scrolling down the y offset. | 1254 // Used when programatically scrolling down the y offset. |
1315 [fullScreenController_ shouldSkipNextScrollOffsetForHeader]; | 1255 [fullScreenController_ shouldSkipNextScrollOffsetForHeader]; |
1316 } | 1256 } |
1317 | 1257 |
1318 #pragma mark - | 1258 #pragma mark - |
1319 #pragma mark FullScreen | 1259 #pragma mark FullScreen |
1320 | 1260 |
1321 - (void)updateFullscreenWithToolbarVisible:(BOOL)visible { | 1261 - (void)updateFullscreenWithToolbarVisible:(BOOL)visible { |
1322 [fullScreenController_ moveHeaderToRestingPosition:visible]; | 1262 [fullScreenController_ moveHeaderToRestingPosition:visible]; |
1323 } | 1263 } |
1324 | 1264 |
1325 #pragma mark - | 1265 #pragma mark - |
1326 #pragma mark Reader mode | 1266 #pragma mark Reader mode |
1327 | 1267 |
1328 - (UIView*)superviewForReaderModePanel { | 1268 - (UIView*)superviewForReaderModePanel { |
1329 return self.view; | 1269 return self.view; |
1330 } | 1270 } |
1331 | 1271 |
1332 - (ReaderModeController*)readerModeController { | |
1333 return readerModeController_.get(); | |
1334 } | |
1335 | |
1336 - (BOOL)canSwitchToReaderMode { | 1272 - (BOOL)canSwitchToReaderMode { |
1337 // Only if the page is loaded and the page passes suitability checks. | 1273 // Only if the page is loaded and the page passes suitability checks. |
1338 ReaderModeController* controller = self.readerModeController; | 1274 ReaderModeController* controller = self.readerModeController; |
1339 return controller && controller.checker->CanSwitchToReaderMode(); | 1275 return controller && controller.checker->CanSwitchToReaderMode(); |
1340 } | 1276 } |
1341 | 1277 |
1342 - (void)switchToReaderMode { | 1278 - (void)switchToReaderMode { |
1343 DCHECK(self.view); | 1279 DCHECK(self.view); |
1344 [self.readerModeController switchToReaderMode]; | 1280 [self.readerModeController switchToReaderMode]; |
1345 } | 1281 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1403 params.user_agent_override_option = | 1339 params.user_agent_override_option = |
1404 web::NavigationManager::UserAgentOverrideOption::MOBILE; | 1340 web::NavigationManager::UserAgentOverrideOption::MOBILE; |
1405 break; | 1341 break; |
1406 case web::UserAgentType::NONE: | 1342 case web::UserAgentType::NONE: |
1407 NOTREACHED(); | 1343 NOTREACHED(); |
1408 } | 1344 } |
1409 | 1345 |
1410 navigationManager->LoadURLWithParams(params); | 1346 navigationManager->LoadURLWithParams(params); |
1411 } | 1347 } |
1412 | 1348 |
1413 - (id<SnapshotOverlayProvider>)snapshotOverlayProvider { | |
1414 return snapshotOverlayProvider_.get(); | |
1415 } | |
1416 | |
1417 - (void)setSnapshotOverlayProvider: | |
1418 (id<SnapshotOverlayProvider>)snapshotOverlayProvider { | |
1419 snapshotOverlayProvider_.reset(snapshotOverlayProvider); | |
1420 } | |
1421 | |
1422 - (void)evaluateU2FResultFromURL:(const GURL&)URL { | 1349 - (void)evaluateU2FResultFromURL:(const GURL&)URL { |
1423 DCHECK(U2FController_); | 1350 DCHECK(U2FController_); |
1424 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; | 1351 [U2FController_ evaluateU2FResultFromU2FURL:URL webState:self.webState]; |
1425 } | 1352 } |
1426 | 1353 |
1427 #pragma mark - CRWWebControllerObserver protocol methods. | 1354 #pragma mark - CRWWebControllerObserver protocol methods. |
1428 | 1355 |
1429 - (void)webControllerWillClose:(CRWWebController*)webController { | 1356 - (void)webControllerWillClose:(CRWWebController*)webController { |
1430 DCHECK_EQ(webController, [self webController]); | 1357 DCHECK_EQ(webController, [self webController]); |
1431 [[self webController] removeObserver:self]; | 1358 [[self webController] removeObserver:self]; |
(...skipping 20 matching lines...) Expand all Loading... | |
1452 BOOL isUserNavigationEvent = | 1379 BOOL isUserNavigationEvent = |
1453 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; | 1380 (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0; |
1454 // Check for link-follow clobbers. These are changes where there is no | 1381 // Check for link-follow clobbers. These are changes where there is no |
1455 // pending entry (since that means the change wasn't caused by this class), | 1382 // pending entry (since that means the change wasn't caused by this class), |
1456 // and where the URL changes (to avoid counting page resurrection). | 1383 // and where the URL changes (to avoid counting page resurrection). |
1457 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or | 1384 // TODO(crbug.com/546401): Consider moving this into NavigationManager, or |
1458 // into a NavigationManager observer callback, so it doesn't need to be | 1385 // into a NavigationManager observer callback, so it doesn't need to be |
1459 // checked in several places. | 1386 // checked in several places. |
1460 if (isUserNavigationEvent && !isPrerenderTab_ && | 1387 if (isUserNavigationEvent && !isPrerenderTab_ && |
1461 ![self navigationManager]->GetPendingItem() && url != self.url) { | 1388 ![self navigationManager]->GetPendingItem() && url != self.url) { |
1462 base::RecordAction(UserMetricsAction("MobileTabClobbered")); | 1389 base::RecordAction(base::UserMetricsAction("MobileTabClobbered")); |
1463 if ([parentTabModel_ tabUsageRecorder]) | 1390 if ([parentTabModel_ tabUsageRecorder]) |
1464 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); | 1391 [parentTabModel_ tabUsageRecorder]->RecordPageLoadStart(self); |
1465 } | 1392 } |
1466 if (![self navigationManager]->GetPendingItem()) { | 1393 if (![self navigationManager]->GetPendingItem()) { |
1467 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. | 1394 // Reset |isVoiceSearchResultsTab| since a new page is being navigated to. |
1468 self.isVoiceSearchResultsTab = NO; | 1395 self.isVoiceSearchResultsTab = NO; |
1469 } | 1396 } |
1470 } | 1397 } |
1471 | 1398 |
1472 - (void)webState:(web::WebState*)webState | 1399 - (void)webState:(web::WebState*)webState |
(...skipping 18 matching lines...) Expand all Loading... | |
1491 [autoReloadBridge_ loadStartedForURL:lastCommittedURL]; | 1418 [autoReloadBridge_ loadStartedForURL:lastCommittedURL]; |
1492 | 1419 |
1493 if (parentTabModel_) { | 1420 if (parentTabModel_) { |
1494 [[NSNotificationCenter defaultCenter] | 1421 [[NSNotificationCenter defaultCenter] |
1495 postNotificationName:kTabModelTabWillStartLoadingNotification | 1422 postNotificationName:kTabModelTabWillStartLoadingNotification |
1496 object:parentTabModel_ | 1423 object:parentTabModel_ |
1497 userInfo:@{kTabModelTabKey : self}]; | 1424 userInfo:@{kTabModelTabKey : self}]; |
1498 } | 1425 } |
1499 favicon::FaviconDriver* faviconDriver = | 1426 favicon::FaviconDriver* faviconDriver = |
1500 favicon::WebFaviconDriver::FromWebState(webState); | 1427 favicon::WebFaviconDriver::FromWebState(webState); |
1501 if (faviconDriver) { | 1428 if (faviconDriver) |
1502 faviconDriver->FetchFavicon(lastCommittedURL); | 1429 faviconDriver->FetchFavicon(lastCommittedURL); |
1503 } | |
1504 [parentTabModel_ notifyTabChanged:self]; | 1430 [parentTabModel_ notifyTabChanged:self]; |
1505 if (parentTabModel_) { | 1431 if (parentTabModel_) { |
1506 [[NSNotificationCenter defaultCenter] | 1432 [[NSNotificationCenter defaultCenter] |
1507 postNotificationName:kTabModelTabDidStartLoadingNotification | 1433 postNotificationName:kTabModelTabDidStartLoadingNotification |
1508 object:parentTabModel_ | 1434 object:parentTabModel_ |
1509 userInfo:@{kTabModelTabKey : self}]; | 1435 userInfo:@{kTabModelTabKey : self}]; |
1510 } | 1436 } |
1511 | 1437 |
1512 web::NavigationItem* previousItem = nullptr; | 1438 web::NavigationItem* previousItem = nullptr; |
1513 if (details.previous_item_index >= 0) { | 1439 if (details.previous_item_index >= 0) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1546 [self navigationManager]->GetLastCommittedItem(); | 1472 [self navigationManager]->GetLastCommittedItem(); |
1547 if (lastCommittedItem) { | 1473 if (lastCommittedItem) { |
1548 wasPost = lastCommittedItem->HasPostData(); | 1474 wasPost = lastCommittedItem->HasPostData(); |
1549 lastCommittedURL = lastCommittedItem->GetVirtualURL(); | 1475 lastCommittedURL = lastCommittedItem->GetVirtualURL(); |
1550 } | 1476 } |
1551 if (loadSuccess) | 1477 if (loadSuccess) |
1552 [autoReloadBridge_ loadFinishedForURL:lastCommittedURL wasPost:wasPost]; | 1478 [autoReloadBridge_ loadFinishedForURL:lastCommittedURL wasPost:wasPost]; |
1553 else | 1479 else |
1554 [autoReloadBridge_ loadFailedForURL:lastCommittedURL wasPost:wasPost]; | 1480 [autoReloadBridge_ loadFailedForURL:lastCommittedURL wasPost:wasPost]; |
1555 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:YES]; | 1481 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:YES]; |
1556 if (!loadSuccess) { | 1482 if (!loadSuccess) |
1557 [fullScreenController_ disableFullScreen]; | 1483 [fullScreenController_ disableFullScreen]; |
1558 } | |
1559 [self recordInterfaceOrientation]; | 1484 [self recordInterfaceOrientation]; |
1560 navigation_metrics::RecordMainFrameNavigation( | 1485 navigation_metrics::RecordMainFrameNavigation( |
1561 lastCommittedURL, true, self.browserState->IsOffTheRecord()); | 1486 lastCommittedURL, true, self.browserState->IsOffTheRecord()); |
1562 | 1487 |
1563 if (loadSuccess) { | 1488 if (loadSuccess) { |
1564 scoped_refptr<net::HttpResponseHeaders> headers = | 1489 scoped_refptr<net::HttpResponseHeaders> headers = |
1565 webStateImpl_->GetHttpResponseHeaders(); | 1490 webStateImpl_->GetHttpResponseHeaders(); |
1566 [self handleExportableFile:headers.get()]; | 1491 [self handleExportableFile:headers.get()]; |
1567 } | 1492 } |
1568 | 1493 |
1569 [parentTabModel_ notifyTabChanged:self]; | 1494 [parentTabModel_ notifyTabChanged:self]; |
1570 | 1495 |
1571 if (parentTabModel_) { | 1496 if (parentTabModel_) { |
1572 if ([parentTabModel_ tabUsageRecorder]) | 1497 if ([parentTabModel_ tabUsageRecorder]) |
1573 [parentTabModel_ tabUsageRecorder]->RecordPageLoadDone(self, loadSuccess); | 1498 [parentTabModel_ tabUsageRecorder]->RecordPageLoadDone(self, loadSuccess); |
1574 [[NSNotificationCenter defaultCenter] | 1499 [[NSNotificationCenter defaultCenter] |
1575 postNotificationName:kTabModelTabDidFinishLoadingNotification | 1500 postNotificationName:kTabModelTabDidFinishLoadingNotification |
1576 object:parentTabModel_ | 1501 object:parentTabModel_ |
1577 userInfo:[NSDictionary | 1502 userInfo:[NSDictionary |
1578 dictionaryWithObjectsAndKeys: | 1503 dictionaryWithObjectsAndKeys: |
1579 self, kTabModelTabKey, | 1504 self, kTabModelTabKey, |
1580 [NSNumber numberWithBool:loadSuccess], | 1505 [NSNumber numberWithBool:loadSuccess], |
1581 kTabModelPageLoadSuccess, nil]]; | 1506 kTabModelPageLoadSuccess, nil]]; |
1582 } | 1507 } |
1583 [[OmniboxGeolocationController sharedInstance] | 1508 [[OmniboxGeolocationController sharedInstance] |
1584 finishPageLoadForTab:self | 1509 finishPageLoadForTab:self |
1585 loadSuccess:loadSuccess]; | 1510 loadSuccess:loadSuccess]; |
1586 | 1511 |
1587 if (loadSuccess) { | 1512 if (loadSuccess) |
1588 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 1513 [self updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
1589 } | |
1590 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:NO]; | 1514 [webControllerSnapshotHelper_ setSnapshotCoalescingEnabled:NO]; |
1591 } | 1515 } |
1592 | 1516 |
1593 - (void)webState:(web::WebState*)webState | 1517 - (void)webState:(web::WebState*)webState |
1594 didChangeLoadingProgress:(double)progress { | 1518 didChangeLoadingProgress:(double)progress { |
1595 // TODO(crbug.com/546406): It is probably possible to do something smarter, | 1519 // TODO(crbug.com/546406): It is probably possible to do something smarter, |
1596 // but the fact that this is not always sent will have to be taken into | 1520 // but the fact that this is not always sent will have to be taken into |
1597 // account. | 1521 // account. |
1598 [parentTabModel_ notifyTabChanged:self]; | 1522 [parentTabModel_ notifyTabChanged:self]; |
1599 } | 1523 } |
(...skipping 23 matching lines...) Expand all Loading... | |
1623 return YES; | 1547 return YES; |
1624 } | 1548 } |
1625 | 1549 |
1626 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)url | 1550 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)url |
1627 sourceURL:(const GURL&)sourceURL | 1551 sourceURL:(const GURL&)sourceURL |
1628 linkClicked:(BOOL)linkClicked { | 1552 linkClicked:(BOOL)linkClicked { |
1629 // Don't open any native app directly when prerendering or from Incognito. | 1553 // Don't open any native app directly when prerendering or from Incognito. |
1630 if (isPrerenderTab_ || self.browserState->IsOffTheRecord()) | 1554 if (isPrerenderTab_ || self.browserState->IsOffTheRecord()) |
1631 return NO; | 1555 return NO; |
1632 | 1556 |
1633 base::scoped_nsprotocol<id<NativeAppMetadata>> metadata( | 1557 base::scoped_nsprotocol<id<NativeAppMetadata>> metadata( |
rohitrao (ping after 24h)
2017/05/02 11:42:54
Are we intentionally still using scoped_nsprotocol
sdefresne
2017/05/02 15:08:51
No, it was a mistake (but the code has been remove
| |
1634 [[ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() | 1558 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() |
1635 nativeAppForURL:url] retain]); | 1559 nativeAppForURL:url]); |
1636 if (![metadata shouldAutoOpenLinks]) | 1560 if (![metadata shouldAutoOpenLinks]) |
1637 return NO; | 1561 return NO; |
1638 | 1562 |
1639 AuthenticationService* authenticationService = | 1563 AuthenticationService* authenticationService = |
1640 AuthenticationServiceFactory::GetForBrowserState(self.browserState); | 1564 AuthenticationServiceFactory::GetForBrowserState(self.browserState); |
1641 ChromeIdentity* identity = authenticationService->GetAuthenticatedIdentity(); | 1565 ChromeIdentity* identity = authenticationService->GetAuthenticatedIdentity(); |
1642 | 1566 |
1643 // Attempts to open external app without x-callback. | 1567 // Attempts to open external app without x-callback. |
1644 if ([self openExternalURL:[metadata launchURLWithURL:url identity:identity] | 1568 if ([self openExternalURL:[metadata launchURLWithURL:url identity:identity] |
1645 sourceURL:sourceURL | 1569 sourceURL:sourceURL |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1679 linkClicked:(BOOL)linkClicked { | 1603 linkClicked:(BOOL)linkClicked { |
1680 // chrome:// URLs are only allowed if the mainDocumentURL is also a chrome:// | 1604 // chrome:// URLs are only allowed if the mainDocumentURL is also a chrome:// |
1681 // URL. | 1605 // URL. |
1682 if (url.SchemeIs(kChromeUIScheme) && | 1606 if (url.SchemeIs(kChromeUIScheme) && |
1683 !mainDocumentURL.SchemeIs(kChromeUIScheme)) { | 1607 !mainDocumentURL.SchemeIs(kChromeUIScheme)) { |
1684 return NO; | 1608 return NO; |
1685 } | 1609 } |
1686 | 1610 |
1687 // Always allow frame loads. | 1611 // Always allow frame loads. |
1688 BOOL isFrameLoad = (url != mainDocumentURL); | 1612 BOOL isFrameLoad = (url != mainDocumentURL); |
1689 if (isFrameLoad) { | 1613 if (isFrameLoad) |
1690 return YES; | 1614 return YES; |
1691 } | |
1692 | 1615 |
1693 // TODO(crbug.com/546402): If this turns out to be useful, find a less hacky | 1616 // TODO(crbug.com/546402): If this turns out to be useful, find a less hacky |
1694 // hook point to send this from. | 1617 // hook point to send this from. |
1695 NSString* urlString = base::SysUTF8ToNSString(url.spec()); | 1618 NSString* urlString = base::SysUTF8ToNSString(url.spec()); |
1696 if ([urlString length]) { | 1619 if ([urlString length]) { |
1697 [[NSNotificationCenter defaultCenter] | 1620 [[NSNotificationCenter defaultCenter] |
1698 postNotificationName:kTabUrlMayStartLoadingNotificationForCrashReporting | 1621 postNotificationName:kTabUrlMayStartLoadingNotificationForCrashReporting |
1699 object:self | 1622 object:self |
1700 userInfo:[NSDictionary dictionaryWithObject:urlString | 1623 userInfo:[NSDictionary dictionaryWithObject:urlString |
1701 forKey:kTabUrlKey]]; | 1624 forKey:kTabUrlKey]]; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1810 } | 1733 } |
1811 UMA_HISTOGRAM_ENUMERATION( | 1734 UMA_HISTOGRAM_ENUMERATION( |
1812 kRendererTerminationStateHistogram, static_cast<int>(tab_state), | 1735 kRendererTerminationStateHistogram, static_cast<int>(tab_state), |
1813 static_cast<int>( | 1736 static_cast<int>( |
1814 RendererTerminationTabState::TERMINATION_TAB_STATE_COUNT)); | 1737 RendererTerminationTabState::TERMINATION_TAB_STATE_COUNT)); |
1815 if ([parentTabModel_ tabUsageRecorder]) | 1738 if ([parentTabModel_ tabUsageRecorder]) |
1816 [parentTabModel_ tabUsageRecorder]->RendererTerminated(self, visible_); | 1739 [parentTabModel_ tabUsageRecorder]->RendererTerminated(self, visible_); |
1817 } | 1740 } |
1818 | 1741 |
1819 if (visible_) { | 1742 if (visible_) { |
1820 if (!applicationIsNotActive) { | 1743 if (!applicationIsNotActive) |
1821 [fullScreenController_ disableFullScreen]; | 1744 [fullScreenController_ disableFullScreen]; |
1822 } | |
1823 } else { | 1745 } else { |
1824 [self.webController requirePageReload]; | 1746 [self.webController requirePageReload]; |
1825 } | 1747 } |
1826 // Returning to the app (after the renderer crashed in the background) and | 1748 // Returning to the app (after the renderer crashed in the background) and |
1827 // having the page reload is much less confusing for the user. | 1749 // having the page reload is much less confusing for the user. |
1828 // Note: Given that the tab is visible, calling |requirePageReload| will not | 1750 // Note: Given that the tab is visible, calling |requirePageReload| will not |
1829 // work when the app becomes active because there is nothing to trigger | 1751 // work when the app becomes active because there is nothing to trigger |
1830 // a view redisplay in that scenario. | 1752 // a view redisplay in that scenario. |
1831 requireReloadAfterBecomingActive_ = visible_ && applicationIsNotActive; | 1753 requireReloadAfterBecomingActive_ = visible_ && applicationIsNotActive; |
1832 [self.dialogDelegate cancelDialogForTab:self]; | 1754 [self.dialogDelegate cancelDialogForTab:self]; |
(...skipping 21 matching lines...) Expand all Loading... | |
1854 if (isPrerenderTab_) { | 1776 if (isPrerenderTab_) { |
1855 [delegate_ discardPrerender]; | 1777 [delegate_ discardPrerender]; |
1856 return; | 1778 return; |
1857 } | 1779 } |
1858 if (self != [parentTabModel_ currentTab]) | 1780 if (self != [parentTabModel_ currentTab]) |
1859 return; | 1781 return; |
1860 | 1782 |
1861 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 1783 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
1862 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) | 1784 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) |
1863 ->GetState()); | 1785 ->GetState()); |
1864 base::scoped_nsobject<GenericChromeCommand> command( | 1786 GenericChromeCommand* command = |
1865 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]); | 1787 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ACCOUNTS_SETTINGS]; |
1866 [self.view chromeExecuteCommand:command]; | 1788 [self.view chromeExecuteCommand:command]; |
1867 } | 1789 } |
1868 | 1790 |
1869 - (void)onAddAccount { | 1791 - (void)onAddAccount { |
1870 if (isPrerenderTab_) { | 1792 if (isPrerenderTab_) { |
1871 [delegate_ discardPrerender]; | 1793 [delegate_ discardPrerender]; |
1872 return; | 1794 return; |
1873 } | 1795 } |
1874 if (self != [parentTabModel_ currentTab]) | 1796 if (self != [parentTabModel_ currentTab]) |
1875 return; | 1797 return; |
1876 | 1798 |
1877 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( | 1799 signin_metrics::LogAccountReconcilorStateOnGaiaResponse( |
1878 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) | 1800 ios::AccountReconcilorFactory::GetForBrowserState(browserState_) |
1879 ->GetState()); | 1801 ->GetState()); |
1880 base::scoped_nsobject<GenericChromeCommand> command( | 1802 GenericChromeCommand* command = |
1881 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ADD_ACCOUNT]); | 1803 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_ADD_ACCOUNT]; |
1882 [self.view chromeExecuteCommand:command]; | 1804 [self.view chromeExecuteCommand:command]; |
1883 } | 1805 } |
1884 | 1806 |
1885 - (void)onGoIncognito:(const GURL&)url { | 1807 - (void)onGoIncognito:(const GURL&)url { |
1886 if (isPrerenderTab_) { | 1808 if (isPrerenderTab_) { |
1887 [delegate_ discardPrerender]; | 1809 [delegate_ discardPrerender]; |
1888 return; | 1810 return; |
1889 } | 1811 } |
1890 if (self != [parentTabModel_ currentTab]) | 1812 if (self != [parentTabModel_ currentTab]) |
1891 return; | 1813 return; |
1892 | 1814 |
1893 // The user taps on go incognito from the mobile U-turn webpage (the web page | 1815 // The user taps on go incognito from the mobile U-turn webpage (the web page |
1894 // that displays all users accounts available in the content area). As the | 1816 // that displays all users accounts available in the content area). As the |
1895 // user chooses to go to incognito, the mobile U-turn page is no longer | 1817 // user chooses to go to incognito, the mobile U-turn page is no longer |
1896 // neeeded. The current solution is to go back in history. This has the | 1818 // neeeded. The current solution is to go back in history. This has the |
1897 // advantage of keeping the current browsing session and give a good user | 1819 // advantage of keeping the current browsing session and give a good user |
1898 // experience when the user comes back from incognito. | 1820 // experience when the user comes back from incognito. |
1899 [self goBack]; | 1821 [self goBack]; |
1900 | 1822 |
1901 if (url.is_valid()) { | 1823 if (url.is_valid()) { |
1902 base::scoped_nsobject<OpenUrlCommand> command([[OpenUrlCommand alloc] | 1824 OpenUrlCommand* command = [[OpenUrlCommand alloc] |
1903 initWithURL:url | 1825 initWithURL:url |
1904 referrer:web::Referrer() // Strip referrer when switching modes. | 1826 referrer:web::Referrer() // Strip referrer when switching modes. |
1905 inIncognito:YES | 1827 inIncognito:YES |
1906 inBackground:NO | 1828 inBackground:NO |
1907 appendTo:kLastTab]); | 1829 appendTo:kLastTab]; |
1908 [self.view chromeExecuteCommand:command]; | 1830 [self.view chromeExecuteCommand:command]; |
1909 } else { | 1831 } else { |
1910 base::scoped_nsobject<GenericChromeCommand> chromeCommand( | 1832 GenericChromeCommand* command = |
1911 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]); | 1833 [[GenericChromeCommand alloc] initWithTag:IDC_NEW_INCOGNITO_TAB]; |
1912 [self.view chromeExecuteCommand:chromeCommand]; | 1834 [self.view chromeExecuteCommand:command]; |
1913 } | 1835 } |
1914 } | 1836 } |
1915 | 1837 |
1916 - (NativeAppNavigationController*)nativeAppNavigationController { | 1838 - (NativeAppNavigationController*)nativeAppNavigationController { |
1917 return nativeAppNavigationController_; | 1839 return nativeAppNavigationController_; |
1918 } | 1840 } |
1919 | 1841 |
1920 - (void)initNativeAppNavigationController { | 1842 - (void)initNativeAppNavigationController { |
1921 if (browserState_->IsOffTheRecord()) | 1843 if (browserState_->IsOffTheRecord()) |
1922 return; | 1844 return; |
1923 DCHECK(!nativeAppNavigationController_); | 1845 DCHECK(!nativeAppNavigationController_); |
1924 nativeAppNavigationController_.reset( | 1846 nativeAppNavigationController_ = |
1925 [[NativeAppNavigationController alloc] initWithWebState:self.webState]); | 1847 [[NativeAppNavigationController alloc] initWithWebState:self.webState]; |
1926 DCHECK(nativeAppNavigationController_); | 1848 DCHECK(nativeAppNavigationController_); |
1927 } | 1849 } |
1928 | 1850 |
1929 - (id<PassKitDialogProvider>)passKitDialogProvider { | |
1930 return passKitDialogProvider_.get(); | |
1931 } | |
1932 | |
1933 - (void)setPassKitDialogProvider:(id<PassKitDialogProvider>)provider { | |
1934 passKitDialogProvider_.reset(provider); | |
1935 } | |
1936 | |
1937 - (void)wasShown { | 1851 - (void)wasShown { |
1938 visible_ = YES; | 1852 visible_ = YES; |
1939 [self updateFullscreenWithToolbarVisible:YES]; | 1853 [self updateFullscreenWithToolbarVisible:YES]; |
1940 [self.webController wasShown]; | 1854 [self.webController wasShown]; |
1941 [inputAccessoryViewController_ wasShown]; | 1855 [inputAccessoryViewController_ wasShown]; |
1942 } | 1856 } |
1943 | 1857 |
1944 - (void)wasHidden { | 1858 - (void)wasHidden { |
1945 visible_ = NO; | 1859 visible_ = NO; |
1946 [self updateFullscreenWithToolbarVisible:YES]; | 1860 [self updateFullscreenWithToolbarVisible:YES]; |
1947 [self.webController wasHidden]; | 1861 [self.webController wasHidden]; |
1948 [inputAccessoryViewController_ wasHidden]; | 1862 [inputAccessoryViewController_ wasHidden]; |
1949 } | 1863 } |
1950 | 1864 |
1951 #pragma mark - SadTabTabHelperDelegate | 1865 #pragma mark - SadTabTabHelperDelegate |
1952 | 1866 |
1953 - (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper { | 1867 - (BOOL)isTabVisibleForTabHelper:(SadTabTabHelper*)tabHelper { |
1954 UIApplicationState state = UIApplication.sharedApplication.applicationState; | 1868 UIApplicationState state = UIApplication.sharedApplication.applicationState; |
1955 return visible_ && !IsApplicationStateNotActive(state); | 1869 return visible_ && !IsApplicationStateNotActive(state); |
1956 } | 1870 } |
1957 | 1871 |
1958 @end | 1872 @end |
1959 | 1873 |
1960 #pragma mark - TestingSupport | 1874 #pragma mark - TestingSupport |
1961 | 1875 |
1962 @implementation Tab (TestingSupport) | 1876 @implementation Tab (TestingSupport) |
1963 | 1877 |
1964 - (void)replaceExternalAppLauncher:(id)externalAppLauncher { | 1878 - (void)replaceExternalAppLauncher:(id)externalAppLauncher { |
1965 externalAppLauncher_.reset([externalAppLauncher retain]); | 1879 externalAppLauncher_ = externalAppLauncher; |
1966 } | 1880 } |
1967 | 1881 |
1968 - (TabModel*)parentTabModel { | 1882 - (TabModel*)parentTabModel { |
1969 return parentTabModel_; | 1883 return parentTabModel_; |
1970 } | 1884 } |
1971 | 1885 |
1972 - (FormInputAccessoryViewController*)inputAccessoryViewController { | 1886 - (FormInputAccessoryViewController*)inputAccessoryViewController { |
1973 return inputAccessoryViewController_.get(); | 1887 return inputAccessoryViewController_; |
1974 } | 1888 } |
1975 | 1889 |
1976 @end | 1890 @end |
OLD | NEW |