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/ui/browser_view_controller.h" | 5 #import "ios/chrome/browser/ui/browser_view_controller.h" |
6 | 6 |
7 #import <AssetsLibrary/AssetsLibrary.h> | 7 #import <AssetsLibrary/AssetsLibrary.h> |
8 #import <MobileCoreServices/MobileCoreServices.h> | 8 #import <MobileCoreServices/MobileCoreServices.h> |
9 #import <PassKit/PassKit.h> | 9 #import <PassKit/PassKit.h> |
10 #import <Photos/Photos.h> | 10 #import <Photos/Photos.h> |
11 #import <QuartzCore/QuartzCore.h> | 11 #import <QuartzCore/QuartzCore.h> |
12 | 12 |
13 #include <stdint.h> | 13 #include <stdint.h> |
14 #include <cmath> | 14 #include <cmath> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "base/base64.h" | 17 #include "base/base64.h" |
18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
20 #include "base/format_macros.h" | 20 #include "base/format_macros.h" |
21 #include "base/i18n/rtl.h" | 21 #include "base/i18n/rtl.h" |
22 #include "base/ios/block_types.h" | 22 #include "base/ios/block_types.h" |
23 #include "base/ios/ios_util.h" | 23 #include "base/ios/ios_util.h" |
24 #include "base/ios/weak_nsobject.h" | |
25 #include "base/logging.h" | 24 #include "base/logging.h" |
26 #include "base/mac/bind_objc_block.h" | 25 #include "base/mac/bind_objc_block.h" |
27 #include "base/mac/bundle_locations.h" | 26 #include "base/mac/bundle_locations.h" |
28 #include "base/mac/foundation_util.h" | 27 #include "base/mac/foundation_util.h" |
29 | |
30 #import "base/mac/scoped_block.h" | |
31 #import "base/mac/scoped_nsobject.h" | 28 #import "base/mac/scoped_nsobject.h" |
marq (ping after 24h)
2017/04/06 14:54:55
Presumably this is still needed to access public s
stkhapugin
2017/04/06 14:58:29
No, it's for HeaderDefinition struct that I remove
| |
32 #include "base/macros.h" | 29 #include "base/macros.h" |
33 #include "base/memory/ptr_util.h" | 30 #include "base/memory/ptr_util.h" |
34 #include "base/metrics/histogram_macros.h" | 31 #include "base/metrics/histogram_macros.h" |
35 #include "base/metrics/user_metrics.h" | 32 #include "base/metrics/user_metrics.h" |
36 #include "base/metrics/user_metrics_action.h" | 33 #include "base/metrics/user_metrics_action.h" |
37 #include "base/strings/sys_string_conversions.h" | 34 #include "base/strings/sys_string_conversions.h" |
38 #include "base/strings/utf_string_conversions.h" | 35 #include "base/strings/utf_string_conversions.h" |
39 #include "base/threading/sequenced_worker_pool.h" | 36 #include "base/threading/sequenced_worker_pool.h" |
40 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 37 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
41 #include "components/bookmarks/browser/bookmark_model.h" | 38 #include "components/bookmarks/browser/bookmark_model.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 TabDialogDelegate, | 318 TabDialogDelegate, |
322 TabHeadersDelegate, | 319 TabHeadersDelegate, |
323 TabModelObserver, | 320 TabModelObserver, |
324 TabSnapshottingDelegate, | 321 TabSnapshottingDelegate, |
325 UIGestureRecognizerDelegate, | 322 UIGestureRecognizerDelegate, |
326 UpgradeCenterClientProtocol, | 323 UpgradeCenterClientProtocol, |
327 VoiceSearchBarDelegate, | 324 VoiceSearchBarDelegate, |
328 VoiceSearchBarOwner> { | 325 VoiceSearchBarOwner> { |
329 // The dependency factory passed on initialization. Used to vend objects used | 326 // The dependency factory passed on initialization. Used to vend objects used |
330 // by the BVC. | 327 // by the BVC. |
331 base::scoped_nsobject<BrowserViewControllerDependencyFactory> | 328 BrowserViewControllerDependencyFactory* _dependencyFactory; |
332 _dependencyFactory; | |
333 | 329 |
334 // The browser's tab model. | 330 // The browser's tab model. |
335 base::scoped_nsobject<TabModel> _model; | 331 TabModel* _model; |
336 | 332 |
337 // Facade objects used by |_toolbarController|. | 333 // Facade objects used by |_toolbarController|. |
338 // Must outlive |_toolbarController|. | 334 // Must outlive |_toolbarController|. |
339 std::unique_ptr<ToolbarModelDelegateIOS> _toolbarModelDelegate; | 335 std::unique_ptr<ToolbarModelDelegateIOS> _toolbarModelDelegate; |
340 std::unique_ptr<ToolbarModelIOS> _toolbarModelIOS; | 336 std::unique_ptr<ToolbarModelIOS> _toolbarModelIOS; |
341 | 337 |
342 // Preload controller. Must outlive |_toolbarController|. | 338 // Preload controller. Must outlive |_toolbarController|. |
343 base::scoped_nsobject<PreloadController> _preloadController; | 339 PreloadController* _preloadController; |
344 | 340 |
345 // The WebToolbarController used to display the omnibox. | 341 // The WebToolbarController used to display the omnibox. |
346 base::scoped_nsobject<WebToolbarController> _toolbarController; | 342 WebToolbarController* _toolbarController; |
347 | 343 |
348 // Controller for edge swipe gestures for page and tab navigation. | 344 // Controller for edge swipe gestures for page and tab navigation. |
349 base::scoped_nsobject<SideSwipeController> _sideSwipeController; | 345 SideSwipeController* _sideSwipeController; |
350 | 346 |
351 // Handles displaying the context menu for all form factors. | 347 // Handles displaying the context menu for all form factors. |
352 base::scoped_nsobject<ContextMenuCoordinator> _contextMenuCoordinator; | 348 ContextMenuCoordinator* _contextMenuCoordinator; |
353 | 349 |
354 // Backing object for property of the same name. | 350 // Backing object for property of the same name. |
355 base::scoped_nsobject<DialogPresenter> _dialogPresenter; | 351 DialogPresenter* _dialogPresenter; |
356 | 352 |
357 // Handles presentation of JavaScript dialogs. | 353 // Handles presentation of JavaScript dialogs. |
358 std::unique_ptr<JavaScriptDialogPresenterImpl> _javaScriptDialogPresenter; | 354 std::unique_ptr<JavaScriptDialogPresenterImpl> _javaScriptDialogPresenter; |
359 | 355 |
360 // Keyboard commands provider. It offloads most of the keyboard commands | 356 // Keyboard commands provider. It offloads most of the keyboard commands |
361 // management off of the BVC. | 357 // management off of the BVC. |
362 base::scoped_nsobject<KeyCommandsProvider> _keyCommandsProvider; | 358 KeyCommandsProvider* _keyCommandsProvider; |
363 | 359 |
364 // Calls to |-relinquishedToolbarController| will set this to yes, and calls | 360 // Calls to |-relinquishedToolbarController| will set this to yes, and calls |
365 // to |-reparentToolbarController| will reset it to NO. | 361 // to |-reparentToolbarController| will reset it to NO. |
366 BOOL _isToolbarControllerRelinquished; | 362 BOOL _isToolbarControllerRelinquished; |
367 | 363 |
368 // The controller that owns the currently relinquished toolbar controller. | 364 // The controller that owns the currently relinquished toolbar controller. |
369 // The reference is weak because it's possible for the toolbar owner to be | 365 // The reference is weak because it's possible for the toolbar owner to be |
370 // deallocated mid-animation due to memory pressure or a tab being closed | 366 // deallocated mid-animation due to memory pressure or a tab being closed |
371 // before the animation is finished. | 367 // before the animation is finished. |
372 base::WeakNSObject<id> _relinquishedToolbarOwner; | 368 __weak id _relinquishedToolbarOwner; |
373 | 369 |
374 // Always present on tablet; always nil on phone. | 370 // Always present on tablet; always nil on phone. |
375 base::scoped_nsobject<TabStripController> _tabStripController; | 371 TabStripController* _tabStripController; |
376 | 372 |
377 // The contextual search controller. | 373 // The contextual search controller. |
378 base::scoped_nsobject<ContextualSearchController> _contextualSearchController; | 374 ContextualSearchController* _contextualSearchController; |
379 | 375 |
380 // The contextual search panel (always a subview of |self.view| if it exists). | 376 // The contextual search panel (always a subview of |self.view| if it exists). |
381 ContextualSearchPanelView* _contextualSearchPanel; | 377 ContextualSearchPanelView* _contextualSearchPanel; |
382 | 378 |
383 // The contextual search mask (always a subview of |self.view| if it exists). | 379 // The contextual search mask (always a subview of |self.view| if it exists). |
384 ContextualSearchMaskView* _contextualSearchMask; | 380 ContextualSearchMaskView* _contextualSearchMask; |
385 | 381 |
386 // Used to inject Javascript implementing the PaymentRequest API and to | 382 // Used to inject Javascript implementing the PaymentRequest API and to |
387 // display the UI. | 383 // display the UI. |
388 base::scoped_nsobject<PaymentRequestManager> _paymentRequestManager; | 384 PaymentRequestManager* _paymentRequestManager; |
389 | 385 |
390 // Used to display the Page Info UI. Nil if not visible. | 386 // Used to display the Page Info UI. Nil if not visible. |
391 base::scoped_nsobject<PageInfoViewController> _pageInfoController; | 387 PageInfoViewController* _pageInfoController; |
392 | 388 |
393 // Used to display the Voice Search UI. Nil if not visible. | 389 // Used to display the Voice Search UI. Nil if not visible. |
394 scoped_refptr<VoiceSearchController> _voiceSearchController; | 390 scoped_refptr<VoiceSearchController> _voiceSearchController; |
395 | 391 |
396 // Used to display the QR Scanner UI. Nil if not visible. | 392 // Used to display the QR Scanner UI. Nil if not visible. |
397 base::scoped_nsobject<QRScannerViewController> _qrScannerViewController; | 393 QRScannerViewController* _qrScannerViewController; |
398 | 394 |
399 // Used to display the Reading List. | 395 // Used to display the Reading List. |
400 base::scoped_nsobject<ReadingListCoordinator> _readingListCoordinator; | 396 ReadingListCoordinator* _readingListCoordinator; |
401 | 397 |
402 // Used to display the Suggestions. | 398 // Used to display the Suggestions. |
403 base::scoped_nsobject<ContentSuggestionsCoordinator> | 399 ContentSuggestionsCoordinator* _contentSuggestionsCoordinator; |
404 _contentSuggestionsCoordinator; | |
405 | 400 |
406 // Used to display the Find In Page UI. Nil if not visible. | 401 // Used to display the Find In Page UI. Nil if not visible. |
407 base::scoped_nsobject<FindBarControllerIOS> _findBarController; | 402 FindBarControllerIOS* _findBarController; |
408 | 403 |
409 // Used to display the Print UI. Nil if not visible. | 404 // Used to display the Print UI. Nil if not visible. |
410 base::scoped_nsobject<PrintController> _printController; | 405 PrintController* _printController; |
411 | 406 |
412 // Records the set of domains for which full screen alert has already been | 407 // Records the set of domains for which full screen alert has already been |
413 // shown. | 408 // shown. |
414 base::scoped_nsobject<NSMutableSet> _fullScreenAlertShown; | 409 NSMutableSet* _fullScreenAlertShown; |
415 | 410 |
416 // Adapter to let BVC be the delegate for WebState. | 411 // Adapter to let BVC be the delegate for WebState. |
417 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; | 412 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; |
418 | 413 |
419 // YES if new tab is animating in. | 414 // YES if new tab is animating in. |
420 BOOL _inNewTabAnimation; | 415 BOOL _inNewTabAnimation; |
421 | 416 |
422 // YES if Voice Search should be started when the new tab animation is | 417 // YES if Voice Search should be started when the new tab animation is |
423 // finished. | 418 // finished. |
424 BOOL _startVoiceSearchAfterNewTabAnimation; | 419 BOOL _startVoiceSearchAfterNewTabAnimation; |
(...skipping 20 matching lines...) Expand all Loading... | |
445 // A single infobar container handles all infobars in all tabs. It keeps | 440 // A single infobar container handles all infobars in all tabs. It keeps |
446 // track of infobars for current tab (accessed via infobar helper of | 441 // track of infobars for current tab (accessed via infobar helper of |
447 // the current tab). | 442 // the current tab). |
448 std::unique_ptr<InfoBarContainerIOS> _infoBarContainer; | 443 std::unique_ptr<InfoBarContainerIOS> _infoBarContainer; |
449 | 444 |
450 // Bridge class to deliver container change notifications to BVC. | 445 // Bridge class to deliver container change notifications to BVC. |
451 std::unique_ptr<InfoBarContainerDelegateIOS> _infoBarContainerDelegate; | 446 std::unique_ptr<InfoBarContainerDelegateIOS> _infoBarContainerDelegate; |
452 | 447 |
453 // Voice search bar at the bottom of the view overlayed on |_contentArea| | 448 // Voice search bar at the bottom of the view overlayed on |_contentArea| |
454 // when displaying voice search results. | 449 // when displaying voice search results. |
455 base::scoped_nsprotocol<UIView<VoiceSearchBar>*> _voiceSearchBar; | 450 UIView<VoiceSearchBar>* _voiceSearchBar; |
456 | 451 |
457 // The image fetcher used to save images and perform image-based searches. | 452 // The image fetcher used to save images and perform image-based searches. |
458 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; | 453 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; |
459 | 454 |
460 // Card side swipe view. | 455 // Card side swipe view. |
461 base::scoped_nsobject<CardSideSwipeView> _sideSwipeView; | 456 CardSideSwipeView* _sideSwipeView; |
462 | 457 |
463 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor. | 458 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor. |
464 base::scoped_nsobject<NSMutableDictionary> _dominantColorCache; | 459 NSMutableDictionary* _dominantColorCache; |
465 | 460 |
466 // Bridge to register for bookmark changes. | 461 // Bridge to register for bookmark changes. |
467 std::unique_ptr<BrowserBookmarkModelBridge> _bookmarkModelBridge; | 462 std::unique_ptr<BrowserBookmarkModelBridge> _bookmarkModelBridge; |
468 | 463 |
469 // Cached pointer to the bookmarks model. | 464 // Cached pointer to the bookmarks model. |
470 bookmarks::BookmarkModel* _bookmarkModel; // weak | 465 bookmarks::BookmarkModel* _bookmarkModel; // weak |
471 | 466 |
472 // The controller that shows the bookmarking UI after the user taps the star | 467 // The controller that shows the bookmarking UI after the user taps the star |
473 // button. | 468 // button. |
474 base::scoped_nsobject<BookmarkInteractionController> | 469 BookmarkInteractionController* _bookmarkInteractionController; |
475 _bookmarkInteractionController; | |
476 | 470 |
477 // Used to remove unreferenced external files. | 471 // Used to remove unreferenced external files. |
478 std::unique_ptr<ExternalFileRemover> _externalFileRemover; | 472 std::unique_ptr<ExternalFileRemover> _externalFileRemover; |
479 | 473 |
480 // The currently displayed "Rate This App" dialog, if one exists. | 474 // The currently displayed "Rate This App" dialog, if one exists. |
481 base::scoped_nsprotocol<id<AppRatingPrompt>> _rateThisAppDialog; | 475 id<AppRatingPrompt> _rateThisAppDialog; |
482 | 476 |
483 // Maps tab IDs to the most recent native content controller vended to that | 477 // Maps tab IDs to the most recent native content controller vended to that |
484 // tab's web controller. | 478 // tab's web controller. |
485 base::scoped_nsobject<NSMapTable> _nativeControllersForTabIDs; | 479 NSMapTable* _nativeControllersForTabIDs; |
486 | 480 |
487 // Notifies the toolbar menu of reading list changes. | 481 // Notifies the toolbar menu of reading list changes. |
488 base::scoped_nsobject<ReadingListMenuNotifier> _readingListMenuNotifier; | 482 ReadingListMenuNotifier* _readingListMenuNotifier; |
489 | 483 |
490 // The sender for the last received IDC_VOICE_SEARCH command. | 484 // The sender for the last received IDC_VOICE_SEARCH command. |
491 base::WeakNSObject<UIView> _voiceSearchButton; | 485 __weak UIView* _voiceSearchButton; |
492 | 486 |
493 // Coordinator for displaying alerts. | 487 // Coordinator for displaying alerts. |
494 base::scoped_nsobject<AlertCoordinator> _alertCoordinator; | 488 AlertCoordinator* _alertCoordinator; |
495 | |
496 // Releaser for properties that aren't backed by scoped_nsobjects. | |
497 } | 489 } |
498 | 490 |
499 // The browser's side swipe controller. Lazily instantiated on the first call. | 491 // The browser's side swipe controller. Lazily instantiated on the first call. |
500 @property(nonatomic, strong, readonly) SideSwipeController* sideSwipeController; | 492 @property(nonatomic, strong, readonly) SideSwipeController* sideSwipeController; |
501 // The browser's preload controller. | 493 // The browser's preload controller. |
502 @property(nonatomic, strong, readonly) PreloadController* preloadController; | 494 @property(nonatomic, strong, readonly) PreloadController* preloadController; |
503 // The dialog presenter for this BVC's tab model. | 495 // The dialog presenter for this BVC's tab model. |
504 @property(nonatomic, strong, readonly) DialogPresenter* dialogPresenter; | 496 @property(nonatomic, strong, readonly) DialogPresenter* dialogPresenter; |
505 // The object that manages keyboard commands on behalf of the BVC. | 497 // The object that manages keyboard commands on behalf of the BVC. |
506 @property(nonatomic, strong, readonly) KeyCommandsProvider* keyCommandsProvider; | 498 @property(nonatomic, strong, readonly) KeyCommandsProvider* keyCommandsProvider; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 *arrow_half_width = 0; | 813 *arrow_half_width = 0; |
822 *bar_height = animation.CurrentValueBetween(0, bar_target_height); | 814 *bar_height = animation.CurrentValueBetween(0, bar_target_height); |
823 } | 815 } |
824 | 816 |
825 void InfoBarContainerStateChanged(bool is_animating) override { | 817 void InfoBarContainerStateChanged(bool is_animating) override { |
826 [controller_ infoBarContainerStateChanged:is_animating]; | 818 [controller_ infoBarContainerStateChanged:is_animating]; |
827 } | 819 } |
828 | 820 |
829 bool DrawInfoBarArrows(int* x) const override { return false; } | 821 bool DrawInfoBarArrows(int* x) const override { return false; } |
830 | 822 |
831 BrowserViewController* controller_; // weak | 823 __weak BrowserViewController* controller_; // weak |
832 }; | 824 }; |
833 | 825 |
834 // Called from the BrowserBookmarkModelBridge from C++ -> ObjC. | 826 // Called from the BrowserBookmarkModelBridge from C++ -> ObjC. |
835 @interface BrowserViewController (BookmarkBridgeMethods) | 827 @interface BrowserViewController (BookmarkBridgeMethods) |
836 // If a bookmark matching the currentTab url is added or moved, update the | 828 // If a bookmark matching the currentTab url is added or moved, update the |
837 // toolbar state so the star highlight is in sync. | 829 // toolbar state so the star highlight is in sync. |
838 - (void)bookmarkNodeModified:(const BookmarkNode*)node; | 830 - (void)bookmarkNodeModified:(const BookmarkNode*)node; |
839 - (void)allBookmarksRemoved; | 831 - (void)allBookmarksRemoved; |
840 @end | 832 @end |
841 | 833 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model, | 872 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model, |
881 const BookmarkNode* node) override {} | 873 const BookmarkNode* node) override {} |
882 | 874 |
883 void BookmarkAllUserNodesRemoved( | 875 void BookmarkAllUserNodesRemoved( |
884 bookmarks::BookmarkModel* model, | 876 bookmarks::BookmarkModel* model, |
885 const std::set<GURL>& removed_urls) override { | 877 const std::set<GURL>& removed_urls) override { |
886 [owner_ allBookmarksRemoved]; | 878 [owner_ allBookmarksRemoved]; |
887 } | 879 } |
888 | 880 |
889 private: | 881 private: |
890 BrowserViewController* owner_; // Weak. | 882 __weak BrowserViewController* owner_; |
891 }; | 883 }; |
892 | 884 |
893 @implementation BrowserViewController | 885 @implementation BrowserViewController |
894 | 886 |
895 @synthesize contentArea = _contentArea; | 887 @synthesize contentArea = _contentArea; |
896 @synthesize typingShield = _typingShield; | 888 @synthesize typingShield = _typingShield; |
897 @synthesize active = _active; | 889 @synthesize active = _active; |
898 @synthesize visible = _visible; | 890 @synthesize visible = _visible; |
899 @synthesize viewVisible = _viewVisible; | 891 @synthesize viewVisible = _viewVisible; |
900 @synthesize dismissingModal = _dismissingModal; | 892 @synthesize dismissingModal = _dismissingModal; |
901 @synthesize hideStatusBar = _hideStatusBar; | 893 @synthesize hideStatusBar = _hideStatusBar; |
902 @synthesize activityOverlayCoordinator = _activityOverlayCoordinator; | 894 @synthesize activityOverlayCoordinator = _activityOverlayCoordinator; |
903 @synthesize presenting = _presenting; | 895 @synthesize presenting = _presenting; |
904 | 896 |
905 #pragma mark - Object lifecycle | 897 #pragma mark - Object lifecycle |
906 | 898 |
907 - (instancetype)initWithTabModel:(TabModel*)model | 899 - (instancetype)initWithTabModel:(TabModel*)model |
908 browserState:(ios::ChromeBrowserState*)browserState | 900 browserState:(ios::ChromeBrowserState*)browserState |
909 dependencyFactory: | 901 dependencyFactory: |
910 (BrowserViewControllerDependencyFactory*)factory { | 902 (BrowserViewControllerDependencyFactory*)factory { |
911 self = [super initWithNibName:nil bundle:base::mac::FrameworkBundle()]; | 903 self = [super initWithNibName:nil bundle:base::mac::FrameworkBundle()]; |
912 if (self) { | 904 if (self) { |
913 DCHECK(factory); | 905 DCHECK(factory); |
914 | 906 |
915 _dependencyFactory.reset(factory); | 907 _dependencyFactory = factory; |
916 _nativeControllersForTabIDs.reset([NSMapTable strongToWeakObjectsMapTable]); | 908 _nativeControllersForTabIDs = [NSMapTable strongToWeakObjectsMapTable]; |
917 _dialogPresenter.reset([[DialogPresenter alloc] initWithDelegate:self | 909 _dialogPresenter = [[DialogPresenter alloc] initWithDelegate:self |
918 presentingViewController:self]); | 910 presentingViewController:self]; |
919 _javaScriptDialogPresenter.reset( | 911 _javaScriptDialogPresenter.reset( |
920 new JavaScriptDialogPresenterImpl(_dialogPresenter)); | 912 new JavaScriptDialogPresenterImpl(_dialogPresenter)); |
921 _webStateDelegate.reset(new web::WebStateDelegateBridge(self)); | 913 _webStateDelegate.reset(new web::WebStateDelegateBridge(self)); |
922 // TODO(leng): Delay this. | 914 // TODO(leng): Delay this. |
923 [[UpgradeCenter sharedInstance] registerClient:self]; | 915 [[UpgradeCenter sharedInstance] registerClient:self]; |
924 _inNewTabAnimation = NO; | 916 _inNewTabAnimation = NO; |
925 if (model && browserState) | 917 if (model && browserState) |
926 [self updateWithTabModel:model browserState:browserState]; | 918 [self updateWithTabModel:model browserState:browserState]; |
927 if ([[NSUserDefaults standardUserDefaults] | 919 if ([[NSUserDefaults standardUserDefaults] |
928 boolForKey:@"fullScreenShowAlert"]) { | 920 boolForKey:@"fullScreenShowAlert"]) { |
929 _fullScreenAlertShown.reset([[NSMutableSet alloc] init]); | 921 _fullScreenAlertShown = [[NSMutableSet alloc] init]; |
930 } | 922 } |
931 } | 923 } |
932 return self; | 924 return self; |
933 } | 925 } |
934 | 926 |
935 - (instancetype)initWithNibName:(NSString*)nibNameOrNil | 927 - (instancetype)initWithNibName:(NSString*)nibNameOrNil |
936 bundle:(NSBundle*)nibBundleOrNil { | 928 bundle:(NSBundle*)nibBundleOrNil { |
937 NOTREACHED(); | 929 NOTREACHED(); |
938 return nil; | 930 return nil; |
939 } | 931 } |
940 | 932 |
941 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 933 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
942 NOTREACHED(); | 934 NOTREACHED(); |
943 return nil; | 935 return nil; |
944 } | 936 } |
945 | 937 |
946 - (void)dealloc { | 938 - (void)dealloc { |
947 _tabStripController.reset(); | 939 _tabStripController = nil; |
948 _infoBarContainer.reset(); | 940 _infoBarContainer = nil; |
949 _readingListMenuNotifier.reset(); | 941 _readingListMenuNotifier = nil; |
950 if (_bookmarkModel) | 942 if (_bookmarkModel) |
951 _bookmarkModel->RemoveObserver(_bookmarkModelBridge.get()); | 943 _bookmarkModel->RemoveObserver(_bookmarkModelBridge.get()); |
952 [_model removeObserver:self]; | 944 [_model removeObserver:self]; |
953 [[UpgradeCenter sharedInstance] unregisterClient:self]; | 945 [[UpgradeCenter sharedInstance] unregisterClient:self]; |
954 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 946 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
955 [_toolbarController setDelegate:nil]; | 947 [_toolbarController setDelegate:nil]; |
956 if (_voiceSearchController.get()) | 948 if (_voiceSearchController) |
957 _voiceSearchController->SetDelegate(nil); | 949 _voiceSearchController->SetDelegate(nil); |
958 [_rateThisAppDialog setDelegate:nil]; | 950 [_rateThisAppDialog setDelegate:nil]; |
959 [_model closeAllTabs]; | 951 [_model closeAllTabs]; |
960 } | 952 } |
961 | 953 |
962 #pragma mark - Accessibility | 954 #pragma mark - Accessibility |
963 | 955 |
964 - (BOOL)accessibilityPerformEscape { | 956 - (BOOL)accessibilityPerformEscape { |
965 [self dismissPopups]; | 957 [self dismissPopups]; |
966 return YES; | 958 return YES; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 | 1018 |
1027 - (BOOL)isPlayingTTS { | 1019 - (BOOL)isPlayingTTS { |
1028 return _voiceSearchController && _voiceSearchController->IsPlayingAudio(); | 1020 return _voiceSearchController && _voiceSearchController->IsPlayingAudio(); |
1029 } | 1021 } |
1030 | 1022 |
1031 - (ios::ChromeBrowserState*)browserState { | 1023 - (ios::ChromeBrowserState*)browserState { |
1032 return _browserState; | 1024 return _browserState; |
1033 } | 1025 } |
1034 | 1026 |
1035 - (TabModel*)tabModel { | 1027 - (TabModel*)tabModel { |
1036 return _model.get(); | 1028 return _model; |
1037 } | 1029 } |
1038 | 1030 |
1039 - (SideSwipeController*)sideSwipeController { | 1031 - (SideSwipeController*)sideSwipeController { |
1040 if (!_sideSwipeController) { | 1032 if (!_sideSwipeController) { |
1041 _sideSwipeController.reset([[SideSwipeController alloc] | 1033 _sideSwipeController = |
1042 initWithTabModel:_model | 1034 [[SideSwipeController alloc] initWithTabModel:_model |
1043 browserState:_browserState]); | 1035 browserState:_browserState]; |
1044 [_sideSwipeController setSnapshotDelegate:self]; | 1036 [_sideSwipeController setSnapshotDelegate:self]; |
1045 [_sideSwipeController setSwipeDelegate:self]; | 1037 [_sideSwipeController setSwipeDelegate:self]; |
1046 } | 1038 } |
1047 return _sideSwipeController; | 1039 return _sideSwipeController; |
1048 } | 1040 } |
1049 | 1041 |
1050 - (PreloadController*)preloadController { | 1042 - (PreloadController*)preloadController { |
1051 return _preloadController.get(); | 1043 return _preloadController; |
1052 } | 1044 } |
1053 | 1045 |
1054 - (DialogPresenter*)dialogPresenter { | 1046 - (DialogPresenter*)dialogPresenter { |
1055 return _dialogPresenter; | 1047 return _dialogPresenter; |
1056 } | 1048 } |
1057 | 1049 |
1058 - (BOOL)canUseReaderMode { | 1050 - (BOOL)canUseReaderMode { |
1059 Tab* tab = [_model currentTab]; | 1051 Tab* tab = [_model currentTab]; |
1060 if ([self isTabNativePage:tab]) | 1052 if ([self isTabNativePage:tab]) |
1061 return NO; | 1053 return NO; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1189 // Install fake status bar for iPad iOS7 | 1181 // Install fake status bar for iPad iOS7 |
1190 [self installFakeStatusBar]; | 1182 [self installFakeStatusBar]; |
1191 [self buildToolbarAndTabStrip]; | 1183 [self buildToolbarAndTabStrip]; |
1192 [self setUpViewLayout]; | 1184 [self setUpViewLayout]; |
1193 // If the tab model and browser state are valid, finish initialization. | 1185 // If the tab model and browser state are valid, finish initialization. |
1194 if (_model && _browserState) | 1186 if (_model && _browserState) |
1195 [self addUIFunctionalityForModelAndBrowserState]; | 1187 [self addUIFunctionalityForModelAndBrowserState]; |
1196 | 1188 |
1197 // Add a tap gesture recognizer to save the last tap location for the source | 1189 // Add a tap gesture recognizer to save the last tap location for the source |
1198 // location of the new tab animation. | 1190 // location of the new tab animation. |
1199 base::scoped_nsobject<UITapGestureRecognizer> tapRecognizer( | 1191 UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] |
1200 [[UITapGestureRecognizer alloc] | 1192 initWithTarget:self |
1201 initWithTarget:self | 1193 action:@selector(saveContentAreaTapLocation:)]; |
1202 action:@selector(saveContentAreaTapLocation:)]); | |
1203 [tapRecognizer setDelegate:self]; | 1194 [tapRecognizer setDelegate:self]; |
1204 [tapRecognizer setCancelsTouchesInView:NO]; | 1195 [tapRecognizer setCancelsTouchesInView:NO]; |
1205 [_contentArea addGestureRecognizer:tapRecognizer]; | 1196 [_contentArea addGestureRecognizer:tapRecognizer]; |
1206 } | 1197 } |
1207 | 1198 |
1208 - (void)viewDidAppear:(BOOL)animated { | 1199 - (void)viewDidAppear:(BOOL)animated { |
1209 [super viewDidAppear:animated]; | 1200 [super viewDidAppear:animated]; |
1210 self.viewVisible = YES; | 1201 self.viewVisible = YES; |
1211 [self updateDialogPresenterActiveState]; | 1202 [self updateDialogPresenterActiveState]; |
1212 } | 1203 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 _browserState); | 1274 _browserState); |
1284 if (loader) | 1275 if (loader) |
1285 loader->PurgeCache(); | 1276 loader->PurgeCache(); |
1286 } | 1277 } |
1287 | 1278 |
1288 if (![self isViewLoaded]) { | 1279 if (![self isViewLoaded]) { |
1289 // Do not release |_infoBarContainer|, as this must have the same lifecycle | 1280 // Do not release |_infoBarContainer|, as this must have the same lifecycle |
1290 // as the BrowserViewController. | 1281 // as the BrowserViewController. |
1291 self.contentArea = nil; | 1282 self.contentArea = nil; |
1292 self.typingShield = nil; | 1283 self.typingShield = nil; |
1293 if (_voiceSearchController.get()) | 1284 if (_voiceSearchController) |
1294 _voiceSearchController->SetDelegate(nil); | 1285 _voiceSearchController->SetDelegate(nil); |
1295 _contentSuggestionsCoordinator.reset(); | 1286 _contentSuggestionsCoordinator = nil; |
1296 _qrScannerViewController.reset(); | 1287 _qrScannerViewController = nil; |
1297 _readingListCoordinator.reset(); | 1288 _readingListCoordinator = nil; |
1298 _toolbarController.reset(); | 1289 _toolbarController = nil; |
1299 _toolbarModelDelegate.reset(); | 1290 _toolbarModelDelegate = nil; |
1300 _toolbarModelIOS.reset(); | 1291 _toolbarModelIOS = nil; |
1301 _tabStripController.reset(); | 1292 _tabStripController = nil; |
1302 _sideSwipeController.reset(); | 1293 _sideSwipeController = nil; |
1303 } | 1294 } |
1304 } | 1295 } |
1305 | 1296 |
1306 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { | 1297 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { |
1307 [super traitCollectionDidChange:previousTraitCollection]; | 1298 [super traitCollectionDidChange:previousTraitCollection]; |
1308 // TODO(crbug.com/527092): - traitCollectionDidChange: is not always forwarded | 1299 // TODO(crbug.com/527092): - traitCollectionDidChange: is not always forwarded |
1309 // because in some cases the presented view controller isn't a child of the | 1300 // because in some cases the presented view controller isn't a child of the |
1310 // BVC in the view controller hierarchy (some intervening object isn't a | 1301 // BVC in the view controller hierarchy (some intervening object isn't a |
1311 // view controller). | 1302 // view controller). |
1312 [self.presentedViewController | 1303 [self.presentedViewController |
(...skipping 14 matching lines...) Expand all Loading... | |
1327 - (void)reshowFindBarIfNeededWithCoordinator: | 1318 - (void)reshowFindBarIfNeededWithCoordinator: |
1328 (id<UIViewControllerTransitionCoordinator>)coordinator { | 1319 (id<UIViewControllerTransitionCoordinator>)coordinator { |
1329 if (![_findBarController isFindInPageShown]) | 1320 if (![_findBarController isFindInPageShown]) |
1330 return; | 1321 return; |
1331 | 1322 |
1332 // Record focused state. | 1323 // Record focused state. |
1333 BOOL isFocusedBeforeReshow = [_findBarController isFocused]; | 1324 BOOL isFocusedBeforeReshow = [_findBarController isFocused]; |
1334 | 1325 |
1335 [self hideFindBarWithAnimation:NO]; | 1326 [self hideFindBarWithAnimation:NO]; |
1336 | 1327 |
1337 base::WeakNSObject<BrowserViewController> weakSelf(self); | 1328 __weak BrowserViewController* weakSelf = self; |
1338 void (^completion)(id<UIViewControllerTransitionCoordinatorContext>) = ^( | 1329 void (^completion)(id<UIViewControllerTransitionCoordinatorContext>) = ^( |
1339 id<UIViewControllerTransitionCoordinatorContext> context) { | 1330 id<UIViewControllerTransitionCoordinatorContext> context) { |
1340 base::scoped_nsobject<BrowserViewController> strongSelf(weakSelf); | 1331 BrowserViewController* strongSelf = weakSelf; |
1341 if (strongSelf) | 1332 if (strongSelf) |
1342 [strongSelf showFindBarWithAnimation:NO | 1333 [strongSelf showFindBarWithAnimation:NO |
1343 selectText:NO | 1334 selectText:NO |
1344 shouldFocus:isFocusedBeforeReshow]; | 1335 shouldFocus:isFocusedBeforeReshow]; |
1345 }; | 1336 }; |
1346 | 1337 |
1347 BOOL enqueued = | 1338 BOOL enqueued = |
1348 [coordinator animateAlongsideTransition:nil completion:completion]; | 1339 [coordinator animateAlongsideTransition:nil completion:completion]; |
1349 if (!enqueued) { | 1340 if (!enqueued) { |
1350 completion(nil); | 1341 completion(nil); |
1351 } | 1342 } |
1352 } | 1343 } |
1353 | 1344 |
1354 - (void)dismissViewControllerAnimated:(BOOL)flag | 1345 - (void)dismissViewControllerAnimated:(BOOL)flag |
1355 completion:(void (^)())completion { | 1346 completion:(void (^)())completion { |
1356 self.dismissingModal = YES; | 1347 self.dismissingModal = YES; |
1357 base::WeakNSObject<BrowserViewController> weakSelf(self); | 1348 __weak BrowserViewController* weakSelf = self; |
1358 [super dismissViewControllerAnimated:flag | 1349 [super dismissViewControllerAnimated:flag |
1359 completion:^{ | 1350 completion:^{ |
1360 base::scoped_nsobject<BrowserViewController> | 1351 BrowserViewController* strongSelf = weakSelf; |
1361 strongSelf(weakSelf); | |
1362 [strongSelf setDismissingModal:NO]; | 1352 [strongSelf setDismissingModal:NO]; |
1363 [strongSelf setPresenting:NO]; | 1353 [strongSelf setPresenting:NO]; |
1364 if (completion) | 1354 if (completion) |
1365 completion(); | 1355 completion(); |
1366 [[strongSelf dialogPresenter] tryToPresent]; | 1356 [[strongSelf dialogPresenter] tryToPresent]; |
1367 }]; | 1357 }]; |
1368 } | 1358 } |
1369 | 1359 |
1370 - (void)presentViewController:(UIViewController*)viewControllerToPresent | 1360 - (void)presentViewController:(UIViewController*)viewControllerToPresent |
1371 animated:(BOOL)flag | 1361 animated:(BOOL)flag |
1372 completion:(void (^)())completion { | 1362 completion:(void (^)())completion { |
1373 base::mac::ScopedBlock<ProceduralBlock> finalCompletionHandler( | 1363 ProceduralBlock finalCompletionHandler = [completion copy]; |
1374 [completion copy]); | |
1375 // TODO(crbug.com/580098) This is an interim fix for the flicker between the | 1364 // TODO(crbug.com/580098) This is an interim fix for the flicker between the |
1376 // launch screen and the FRE Animation. The fix is, if the FRE is about to be | 1365 // launch screen and the FRE Animation. The fix is, if the FRE is about to be |
1377 // presented, to show a temporary view of the launch screen and then remove it | 1366 // presented, to show a temporary view of the launch screen and then remove it |
1378 // when the controller for the FRE has been presented. This fix should be | 1367 // when the controller for the FRE has been presented. This fix should be |
1379 // removed when the FRE startup code is rewritten. | 1368 // removed when the FRE startup code is rewritten. |
1380 BOOL firstRunLaunch = (FirstRun::IsChromeFirstRun() || | 1369 BOOL firstRunLaunch = (FirstRun::IsChromeFirstRun() || |
1381 experimental_flags::AlwaysDisplayFirstRun()) && | 1370 experimental_flags::AlwaysDisplayFirstRun()) && |
1382 !tests_hook::DisableFirstRun(); | 1371 !tests_hook::DisableFirstRun(); |
1383 // These if statements check that |presentViewController| is being called for | 1372 // These if statements check that |presentViewController| is being called for |
1384 // the FRE case. | 1373 // the FRE case. |
(...skipping 15 matching lines...) Expand all Loading... | |
1400 // |launchScreenView| is loaded as an autoreleased object, and is retained | 1389 // |launchScreenView| is loaded as an autoreleased object, and is retained |
1401 // by the |completion| block below. | 1390 // by the |completion| block below. |
1402 UIView* launchScreenView = launchScreenController.view; | 1391 UIView* launchScreenView = launchScreenController.view; |
1403 launchScreenView.userInteractionEnabled = NO; | 1392 launchScreenView.userInteractionEnabled = NO; |
1404 launchScreenView.frame = self.view.window.bounds; | 1393 launchScreenView.frame = self.view.window.bounds; |
1405 [self.view.window addSubview:launchScreenView]; | 1394 [self.view.window addSubview:launchScreenView]; |
1406 | 1395 |
1407 // Replace the completion handler sent to the superclass with one which | 1396 // Replace the completion handler sent to the superclass with one which |
1408 // removes |launchScreenView| and resets the status bar. If |completion| | 1397 // removes |launchScreenView| and resets the status bar. If |completion| |
1409 // exists, it is called from within the new completion handler. | 1398 // exists, it is called from within the new completion handler. |
1410 base::WeakNSObject<BrowserViewController> weakSelf(self); | 1399 __weak BrowserViewController* weakSelf = self; |
1411 finalCompletionHandler.reset([^{ | 1400 finalCompletionHandler = ^{ |
1412 [launchScreenView removeFromSuperview]; | 1401 [launchScreenView removeFromSuperview]; |
1413 weakSelf.get().hideStatusBar = NO; | 1402 weakSelf.hideStatusBar = NO; |
1414 if (completion) | 1403 if (completion) |
1415 completion(); | 1404 completion(); |
1416 } copy]); | 1405 }; |
1417 } | 1406 } |
1418 } | 1407 } |
1419 | 1408 |
1420 self.presenting = YES; | 1409 self.presenting = YES; |
1421 if ([_sideSwipeController inSwipe]) { | 1410 if ([_sideSwipeController inSwipe]) { |
1422 [_sideSwipeController resetContentView]; | 1411 [_sideSwipeController resetContentView]; |
1423 } | 1412 } |
1424 | 1413 |
1425 [super presentViewController:viewControllerToPresent | 1414 [super presentViewController:viewControllerToPresent |
1426 animated:flag | 1415 animated:flag |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1582 startVoiceSearchIfNecessaryBlock(); | 1571 startVoiceSearchIfNecessaryBlock(); |
1583 }); | 1572 }); |
1584 } else { | 1573 } else { |
1585 // -updateSnapshotWithOverlay will force a screen redraw, so take the | 1574 // -updateSnapshotWithOverlay will force a screen redraw, so take the |
1586 // snapshot before adding the views needed for the background animation. | 1575 // snapshot before adding the views needed for the background animation. |
1587 Tab* topTab = [_model currentTab]; | 1576 Tab* topTab = [_model currentTab]; |
1588 UIImage* image = [topTab updateSnapshotWithOverlay:YES | 1577 UIImage* image = [topTab updateSnapshotWithOverlay:YES |
1589 visibleFrameOnly:self.isToolbarOnScreen]; | 1578 visibleFrameOnly:self.isToolbarOnScreen]; |
1590 // Add three layers in order on top of the contentArea for the animation: | 1579 // Add three layers in order on top of the contentArea for the animation: |
1591 // 1. The black "background" screen. | 1580 // 1. The black "background" screen. |
1592 base::scoped_nsobject<UIView> background( | 1581 UIView* background = [[UIView alloc] initWithFrame:[_contentArea bounds]]; |
1593 [[UIView alloc] initWithFrame:[_contentArea bounds]]); | |
1594 InstallBackgroundInView(background); | 1582 InstallBackgroundInView(background); |
1595 [_contentArea addSubview:background]; | 1583 [_contentArea addSubview:background]; |
1596 | 1584 |
1597 // 2. A CardView displaying the data from the current tab. | 1585 // 2. A CardView displaying the data from the current tab. |
1598 CardView* topCard = [self addCardViewInFullscreen:!self.isToolbarOnScreen]; | 1586 CardView* topCard = [self addCardViewInFullscreen:!self.isToolbarOnScreen]; |
1599 NSString* title = [topTab title]; | 1587 NSString* title = [topTab title]; |
1600 if (![title length]) | 1588 if (![title length]) |
1601 title = [topTab urlDisplayString]; | 1589 title = [topTab urlDisplayString]; |
1602 [topCard setTitle:title]; | 1590 [topCard setTitle:title]; |
1603 [topCard setFavicon:[topTab favicon]]; | 1591 [topCard setFavicon:[topTab favicon]]; |
(...skipping 20 matching lines...) Expand all Loading... | |
1624 #pragma mark - UI Configuration and Layout | 1612 #pragma mark - UI Configuration and Layout |
1625 | 1613 |
1626 - (void)updateWithTabModel:(TabModel*)model | 1614 - (void)updateWithTabModel:(TabModel*)model |
1627 browserState:(ios::ChromeBrowserState*)browserState { | 1615 browserState:(ios::ChromeBrowserState*)browserState { |
1628 DCHECK(model); | 1616 DCHECK(model); |
1629 DCHECK(browserState); | 1617 DCHECK(browserState); |
1630 DCHECK(!_model); | 1618 DCHECK(!_model); |
1631 DCHECK(!_browserState); | 1619 DCHECK(!_browserState); |
1632 _browserState = browserState; | 1620 _browserState = browserState; |
1633 _isOffTheRecord = browserState->IsOffTheRecord() ? YES : NO; | 1621 _isOffTheRecord = browserState->IsOffTheRecord() ? YES : NO; |
1634 _model.reset(model); | 1622 _model = model; |
1635 [_model addObserver:self]; | 1623 [_model addObserver:self]; |
1636 | 1624 |
1637 if (!_isOffTheRecord) { | 1625 if (!_isOffTheRecord) { |
1638 [DefaultIOSWebViewFactory | 1626 [DefaultIOSWebViewFactory |
1639 registerWebViewFactory:[ChromeWebViewFactory class]]; | 1627 registerWebViewFactory:[ChromeWebViewFactory class]]; |
1640 } | 1628 } |
1641 NSUInteger count = [_model count]; | 1629 NSUInteger count = [_model count]; |
1642 for (NSUInteger index = 0; index < count; ++index) | 1630 for (NSUInteger index = 0; index < count; ++index) |
1643 [self installDelegatesForTab:[_model tabAtIndex:index]]; | 1631 [self installDelegatesForTab:[_model tabAtIndex:index]]; |
1644 | 1632 |
1645 [self registerForNotifications]; | 1633 [self registerForNotifications]; |
1646 | 1634 |
1647 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( | 1635 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( |
1648 _browserState->GetRequestContext(), web::WebThread::GetBlockingPool()); | 1636 _browserState->GetRequestContext(), web::WebThread::GetBlockingPool()); |
1649 _dominantColorCache.reset([[NSMutableDictionary alloc] init]); | 1637 _dominantColorCache = [[NSMutableDictionary alloc] init]; |
1650 | 1638 |
1651 // Register for bookmark changed notification (BookmarkModel may be null | 1639 // Register for bookmark changed notification (BookmarkModel may be null |
1652 // during testing, so explicitly support this). | 1640 // during testing, so explicitly support this). |
1653 _bookmarkModel = ios::BookmarkModelFactory::GetForBrowserState(_browserState); | 1641 _bookmarkModel = ios::BookmarkModelFactory::GetForBrowserState(_browserState); |
1654 if (_bookmarkModel) { | 1642 if (_bookmarkModel) { |
1655 _bookmarkModelBridge.reset(new BrowserBookmarkModelBridge(self)); | 1643 _bookmarkModelBridge.reset(new BrowserBookmarkModelBridge(self)); |
1656 _bookmarkModel->AddObserver(_bookmarkModelBridge.get()); | 1644 _bookmarkModel->AddObserver(_bookmarkModelBridge.get()); |
1657 } | 1645 } |
1658 } | 1646 } |
1659 | 1647 |
1660 - (void)ensureViewCreated { | 1648 - (void)ensureViewCreated { |
1661 ignore_result([self view]); | 1649 ignore_result([self view]); |
1662 } | 1650 } |
1663 | 1651 |
1664 - (void)browserStateDestroyed { | 1652 - (void)browserStateDestroyed { |
1665 [self setActive:NO]; | 1653 [self setActive:NO]; |
1666 // Reset the toolbar opacity in case it was changed for contextual search. | 1654 // Reset the toolbar opacity in case it was changed for contextual search. |
1667 [self updateToolbarControlsAlpha:1.0]; | 1655 [self updateToolbarControlsAlpha:1.0]; |
1668 [self updateToolbarBackgroundAlpha:1.0]; | 1656 [self updateToolbarBackgroundAlpha:1.0]; |
1669 [_contextualSearchController close]; | 1657 [_contextualSearchController close]; |
1670 _contextualSearchController.reset(); | 1658 _contextualSearchController = nil; |
1671 [_contextualSearchPanel removeFromSuperview]; | 1659 [_contextualSearchPanel removeFromSuperview]; |
1672 [_contextualSearchMask removeFromSuperview]; | 1660 [_contextualSearchMask removeFromSuperview]; |
1673 [_paymentRequestManager close]; | 1661 [_paymentRequestManager close]; |
1674 _paymentRequestManager.reset(); | 1662 _paymentRequestManager = nil; |
1675 [_toolbarController browserStateDestroyed]; | 1663 [_toolbarController browserStateDestroyed]; |
1676 [_model browserStateDestroyed]; | 1664 [_model browserStateDestroyed]; |
1677 [_preloadController browserStateDestroyed]; | 1665 [_preloadController browserStateDestroyed]; |
1678 _preloadController.reset(); | 1666 _preloadController = nil; |
1679 // The file remover needs the browser state, so needs to be destroyed now. | 1667 // The file remover needs the browser state, so needs to be destroyed now. |
1680 _externalFileRemover.reset(); | 1668 _externalFileRemover = nil; |
1681 _browserState = nullptr; | 1669 _browserState = nullptr; |
1682 } | 1670 } |
1683 | 1671 |
1684 - (void)installFakeStatusBar { | 1672 - (void)installFakeStatusBar { |
1685 if (IsIPadIdiom()) { | 1673 if (IsIPadIdiom()) { |
1686 CGFloat statusBarHeight = StatusBarHeight(); | 1674 CGFloat statusBarHeight = StatusBarHeight(); |
1687 CGRect statusBarFrame = | 1675 CGRect statusBarFrame = |
1688 CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight); | 1676 CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight); |
1689 base::scoped_nsobject<UIView> statusBarView( | 1677 UIView* statusBarView = [[UIView alloc] initWithFrame:statusBarFrame]; |
1690 [[UIView alloc] initWithFrame:statusBarFrame]); | |
1691 [statusBarView setBackgroundColor:TabStrip::BackgroundColor()]; | 1678 [statusBarView setBackgroundColor:TabStrip::BackgroundColor()]; |
1692 [statusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; | 1679 [statusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; |
1693 [statusBarView layer].zPosition = 99; | 1680 [statusBarView layer].zPosition = 99; |
1694 [[self view] addSubview:statusBarView]; | 1681 [[self view] addSubview:statusBarView]; |
1695 } | 1682 } |
1696 | 1683 |
1697 // Add a white bar on phone so that the status bar on the NTP is white. | 1684 // Add a white bar on phone so that the status bar on the NTP is white. |
1698 if (!IsIPadIdiom()) { | 1685 if (!IsIPadIdiom()) { |
1699 CGFloat statusBarHeight = StatusBarHeight(); | 1686 CGFloat statusBarHeight = StatusBarHeight(); |
1700 CGRect statusBarFrame = | 1687 CGRect statusBarFrame = |
1701 CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight); | 1688 CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight); |
1702 base::scoped_nsobject<UIView> statusBarView( | 1689 UIView* statusBarView = [[UIView alloc] initWithFrame:statusBarFrame]; |
1703 [[UIView alloc] initWithFrame:statusBarFrame]); | |
1704 [statusBarView setBackgroundColor:[UIColor whiteColor]]; | 1690 [statusBarView setBackgroundColor:[UIColor whiteColor]]; |
1705 [statusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; | 1691 [statusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; |
1706 [self.view insertSubview:statusBarView atIndex:0]; | 1692 [self.view insertSubview:statusBarView atIndex:0]; |
1707 } | 1693 } |
1708 } | 1694 } |
1709 | 1695 |
1710 // Create the UI elements. May or may not have valid browser state & tab model. | 1696 // Create the UI elements. May or may not have valid browser state & tab model. |
1711 - (void)buildToolbarAndTabStrip { | 1697 - (void)buildToolbarAndTabStrip { |
1712 DCHECK([self isViewLoaded]); | 1698 DCHECK([self isViewLoaded]); |
1713 DCHECK(!_toolbarModelDelegate); | 1699 DCHECK(!_toolbarModelDelegate); |
1714 | 1700 |
1715 // Create the preload controller before the toolbar controller. | 1701 // Create the preload controller before the toolbar controller. |
1716 if (!_preloadController) { | 1702 if (!_preloadController) { |
1717 _preloadController.reset([_dependencyFactory newPreloadController]); | 1703 _preloadController = [_dependencyFactory newPreloadController]; |
1718 [_preloadController setDelegate:self]; | 1704 [_preloadController setDelegate:self]; |
1719 } | 1705 } |
1720 | 1706 |
1721 // Create the toolbar model and controller. | 1707 // Create the toolbar model and controller. |
1722 _toolbarModelDelegate.reset( | 1708 _toolbarModelDelegate.reset( |
1723 new ToolbarModelDelegateIOS([_model webStateList])); | 1709 new ToolbarModelDelegateIOS([_model webStateList])); |
1724 _toolbarModelIOS.reset([_dependencyFactory | 1710 _toolbarModelIOS.reset([_dependencyFactory |
1725 newToolbarModelIOSWithDelegate:_toolbarModelDelegate.get()]); | 1711 newToolbarModelIOSWithDelegate:_toolbarModelDelegate.get()]); |
1726 _toolbarController.reset([_dependencyFactory | 1712 _toolbarController = [_dependencyFactory |
1727 newWebToolbarControllerWithDelegate:self | 1713 newWebToolbarControllerWithDelegate:self |
1728 urlLoader:self | 1714 urlLoader:self |
1729 preloadProvider:_preloadController.get()]); | 1715 preloadProvider:_preloadController]; |
1730 [_toolbarController setTabCount:[_model count]]; | 1716 [_toolbarController setTabCount:[_model count]]; |
1731 if (_voiceSearchController.get()) | 1717 if (_voiceSearchController) |
1732 _voiceSearchController->SetDelegate(_toolbarController); | 1718 _voiceSearchController->SetDelegate(_toolbarController); |
1733 | 1719 |
1734 // If needed, create the tabstrip. | 1720 // If needed, create the tabstrip. |
1735 if (IsIPadIdiom()) { | 1721 if (IsIPadIdiom()) { |
1736 _tabStripController.reset( | 1722 _tabStripController = |
1737 [_dependencyFactory newTabStripControllerWithTabModel:_model]); | 1723 [_dependencyFactory newTabStripControllerWithTabModel:_model]; |
1738 _tabStripController.get().fullscreenDelegate = self; | 1724 _tabStripController.fullscreenDelegate = self; |
1739 } | 1725 } |
1740 | 1726 |
1741 // Create infobar container. | 1727 // Create infobar container. |
1742 if (!_infoBarContainerDelegate) { | 1728 if (!_infoBarContainerDelegate) { |
1743 _infoBarContainerDelegate.reset(new InfoBarContainerDelegateIOS(self)); | 1729 _infoBarContainerDelegate.reset(new InfoBarContainerDelegateIOS(self)); |
1744 _infoBarContainer.reset( | 1730 _infoBarContainer.reset( |
1745 new InfoBarContainerIOS(_infoBarContainerDelegate.get())); | 1731 new InfoBarContainerIOS(_infoBarContainerDelegate.get())); |
1746 } | 1732 } |
1747 } | 1733 } |
1748 | 1734 |
(...skipping 12 matching lines...) Expand all Loading... | |
1761 | 1747 |
1762 // Create contextual search views and controller. | 1748 // Create contextual search views and controller. |
1763 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice] && | 1749 if ([TouchToSearchPermissionsMediator isTouchToSearchAvailableOnDevice] && |
1764 !_browserState->IsOffTheRecord()) { | 1750 !_browserState->IsOffTheRecord()) { |
1765 _contextualSearchMask = [[ContextualSearchMaskView alloc] init]; | 1751 _contextualSearchMask = [[ContextualSearchMaskView alloc] init]; |
1766 [self.view insertSubview:_contextualSearchMask | 1752 [self.view insertSubview:_contextualSearchMask |
1767 belowSubview:[_toolbarController view]]; | 1753 belowSubview:[_toolbarController view]]; |
1768 _contextualSearchPanel = [self createPanelView]; | 1754 _contextualSearchPanel = [self createPanelView]; |
1769 [self.view insertSubview:_contextualSearchPanel | 1755 [self.view insertSubview:_contextualSearchPanel |
1770 aboveSubview:[_toolbarController view]]; | 1756 aboveSubview:[_toolbarController view]]; |
1771 _contextualSearchController.reset([[ContextualSearchController alloc] | 1757 _contextualSearchController = |
1772 initWithBrowserState:_browserState | 1758 [[ContextualSearchController alloc] initWithBrowserState:_browserState |
1773 delegate:self]); | 1759 delegate:self]; |
1774 [_contextualSearchController setPanel:_contextualSearchPanel]; | 1760 [_contextualSearchController setPanel:_contextualSearchPanel]; |
1775 [_contextualSearchController setTab:[_model currentTab]]; | 1761 [_contextualSearchController setTab:[_model currentTab]]; |
1776 } | 1762 } |
1777 | 1763 |
1778 if (experimental_flags::IsPaymentRequestEnabled()) { | 1764 if (experimental_flags::IsPaymentRequestEnabled()) { |
1779 _paymentRequestManager.reset([[PaymentRequestManager alloc] | 1765 _paymentRequestManager = [[PaymentRequestManager alloc] |
1780 initWithBaseViewController:self | 1766 initWithBaseViewController:self |
1781 browserState:_browserState]); | 1767 browserState:_browserState]; |
1782 [_paymentRequestManager setWebState:[_model currentTab].webState]; | 1768 [_paymentRequestManager setWebState:[_model currentTab].webState]; |
1783 } | 1769 } |
1784 } | 1770 } |
1785 | 1771 |
1786 // Set the frame for the various views. View must be loaded. | 1772 // Set the frame for the various views. View must be loaded. |
1787 - (void)setUpViewLayout { | 1773 - (void)setUpViewLayout { |
1788 DCHECK([self isViewLoaded]); | 1774 DCHECK([self isViewLoaded]); |
1789 | 1775 |
1790 CGFloat widthOfView = CGRectGetWidth([self view].bounds); | 1776 CGFloat widthOfView = CGRectGetWidth([self view].bounds); |
1791 | 1777 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1876 if (newSelection) | 1862 if (newSelection) |
1877 [_toolbarController selectedTabChanged]; | 1863 [_toolbarController selectedTabChanged]; |
1878 | 1864 |
1879 // Notify the Tab that it was displayed. | 1865 // Notify the Tab that it was displayed. |
1880 [tab wasShown]; | 1866 [tab wasShown]; |
1881 } | 1867 } |
1882 | 1868 |
1883 - (void)initializeBookmarkInteractionController { | 1869 - (void)initializeBookmarkInteractionController { |
1884 if (_bookmarkInteractionController) | 1870 if (_bookmarkInteractionController) |
1885 return; | 1871 return; |
1886 _bookmarkInteractionController.reset([[BookmarkInteractionController alloc] | 1872 _bookmarkInteractionController = |
1887 initWithBrowserState:_browserState | 1873 [[BookmarkInteractionController alloc] initWithBrowserState:_browserState |
1888 loader:self | 1874 loader:self |
1889 parentController:self]); | 1875 parentController:self]; |
1890 } | 1876 } |
1891 | 1877 |
1892 // Update the state of back and forward buttons, hiding the forward button if | 1878 // Update the state of back and forward buttons, hiding the forward button if |
1893 // there is nowhere to go. Assumes the model's current tab is up to date. | 1879 // there is nowhere to go. Assumes the model's current tab is up to date. |
1894 - (void)updateToolbar { | 1880 - (void)updateToolbar { |
1895 // If the BVC has been partially torn down for low memory, wait for the | 1881 // If the BVC has been partially torn down for low memory, wait for the |
1896 // view rebuild to handle toolbar updates. | 1882 // view rebuild to handle toolbar updates. |
1897 if (!(_toolbarModelIOS && _browserState)) | 1883 if (!(_toolbarModelIOS && _browserState)) |
1898 return; | 1884 return; |
1899 | 1885 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2141 if (!self.visible || ![_model webUsageEnabled]) | 2127 if (!self.visible || ![_model webUsageEnabled]) |
2142 return; | 2128 return; |
2143 | 2129 |
2144 [self displayTab:tab isNewSelection:YES]; | 2130 [self displayTab:tab isNewSelection:YES]; |
2145 | 2131 |
2146 if (_expectingForegroundTab && !_inNewTabAnimation) { | 2132 if (_expectingForegroundTab && !_inNewTabAnimation) { |
2147 // Now that the new tab has been displayed, return to normal. Rather than | 2133 // Now that the new tab has been displayed, return to normal. Rather than |
2148 // keep a reference to the previous tab, just turn off preview mode for all | 2134 // keep a reference to the previous tab, just turn off preview mode for all |
2149 // tabs (since doing so is a no-op for the tabs that don't have it set). | 2135 // tabs (since doing so is a no-op for the tabs that don't have it set). |
2150 _expectingForegroundTab = NO; | 2136 _expectingForegroundTab = NO; |
2151 for (Tab* tab in _model.get()) { | 2137 for (Tab* tab in _model) { |
2152 [tab.webController setOverlayPreviewMode:NO]; | 2138 [tab.webController setOverlayPreviewMode:NO]; |
2153 } | 2139 } |
2154 } | 2140 } |
2155 } | 2141 } |
2156 | 2142 |
2157 #pragma mark - External files | 2143 #pragma mark - External files |
2158 | 2144 |
2159 - (NSSet*)referencedExternalFiles { | 2145 - (NSSet*)referencedExternalFiles { |
2160 NSSet* filesReferencedByTabs = [_model currentlyReferencedExternalFiles]; | 2146 NSSet* filesReferencedByTabs = [_model currentlyReferencedExternalFiles]; |
2161 | 2147 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2195 #pragma mark - SnapshotOverlayProvider methods | 2181 #pragma mark - SnapshotOverlayProvider methods |
2196 | 2182 |
2197 - (NSArray*)snapshotOverlaysForTab:(Tab*)tab { | 2183 - (NSArray*)snapshotOverlaysForTab:(Tab*)tab { |
2198 NSMutableArray* overlays = [NSMutableArray array]; | 2184 NSMutableArray* overlays = [NSMutableArray array]; |
2199 if (![_model webUsageEnabled]) { | 2185 if (![_model webUsageEnabled]) { |
2200 return overlays; | 2186 return overlays; |
2201 } | 2187 } |
2202 UIView* voiceSearchView = [self voiceSearchOverlayViewForTab:tab]; | 2188 UIView* voiceSearchView = [self voiceSearchOverlayViewForTab:tab]; |
2203 if (voiceSearchView) { | 2189 if (voiceSearchView) { |
2204 CGFloat voiceSearchYOffset = [self voiceSearchOverlayYOffsetForTab:tab]; | 2190 CGFloat voiceSearchYOffset = [self voiceSearchOverlayYOffsetForTab:tab]; |
2205 base::scoped_nsobject<SnapshotOverlay> voiceSearchOverlay( | 2191 SnapshotOverlay* voiceSearchOverlay = |
2206 [[SnapshotOverlay alloc] initWithView:voiceSearchView | 2192 [[SnapshotOverlay alloc] initWithView:voiceSearchView |
2207 yOffset:voiceSearchYOffset]); | 2193 yOffset:voiceSearchYOffset]; |
2208 [overlays addObject:voiceSearchOverlay]; | 2194 [overlays addObject:voiceSearchOverlay]; |
2209 } | 2195 } |
2210 UIView* infoBarView = [self infoBarOverlayViewForTab:tab]; | 2196 UIView* infoBarView = [self infoBarOverlayViewForTab:tab]; |
2211 if (infoBarView) { | 2197 if (infoBarView) { |
2212 CGFloat infoBarYOffset = [self infoBarOverlayYOffsetForTab:tab]; | 2198 CGFloat infoBarYOffset = [self infoBarOverlayYOffsetForTab:tab]; |
2213 base::scoped_nsobject<SnapshotOverlay> infoBarOverlay( | 2199 SnapshotOverlay* infoBarOverlay = |
2214 [[SnapshotOverlay alloc] initWithView:infoBarView | 2200 [[SnapshotOverlay alloc] initWithView:infoBarView |
2215 yOffset:infoBarYOffset]); | 2201 yOffset:infoBarYOffset]; |
2216 [overlays addObject:infoBarOverlay]; | 2202 [overlays addObject:infoBarOverlay]; |
2217 } | 2203 } |
2218 return overlays; | 2204 return overlays; |
2219 } | 2205 } |
2220 | 2206 |
2221 #pragma mark - | 2207 #pragma mark - |
2222 | 2208 |
2223 - (UIView*)infoBarOverlayViewForTab:(Tab*)tab { | 2209 - (UIView*)infoBarOverlayViewForTab:(Tab*)tab { |
2224 if (IsIPadIdiom()) { | 2210 if (IsIPadIdiom()) { |
2225 // Not using overlays on iPad because the content is pushed down by | 2211 // Not using overlays on iPad because the content is pushed down by |
2226 // infobar and the transition between snapshot and fresh page can | 2212 // infobar and the transition between snapshot and fresh page can |
2227 // cause both snapshot and real infobars to appear at the same time. | 2213 // cause both snapshot and real infobars to appear at the same time. |
2228 return nil; | 2214 return nil; |
2229 } | 2215 } |
2230 Tab* currentTab = [_model currentTab]; | 2216 Tab* currentTab = [_model currentTab]; |
2231 if (tab && tab == currentTab) { | 2217 if (tab && tab == currentTab) { |
2232 infobars::InfoBarManager* infoBarManager = [currentTab infoBarManager]; | 2218 infobars::InfoBarManager* infoBarManager = [currentTab infoBarManager]; |
2233 if (infoBarManager->infobar_count() > 0) { | 2219 if (infoBarManager->infobar_count() > 0) { |
2234 DCHECK(_infoBarContainer); | 2220 DCHECK(_infoBarContainer); |
2235 return _infoBarContainer->view(); | 2221 return _infoBarContainer->view(); |
2236 } | 2222 } |
2237 } | 2223 } |
2238 return nil; | 2224 return nil; |
2239 } | 2225 } |
2240 | 2226 |
2241 - (CGFloat)infoBarOverlayYOffsetForTab:(Tab*)tab { | 2227 - (CGFloat)infoBarOverlayYOffsetForTab:(Tab*)tab { |
2242 if (tab != [_model currentTab] || !_infoBarContainer.get()) { | 2228 if (tab != [_model currentTab] || !_infoBarContainer) { |
2243 // There is no UI representation for non-current tabs or there is | 2229 // There is no UI representation for non-current tabs or there is |
2244 // no _infoBarContainer instantiated yet. | 2230 // no _infoBarContainer instantiated yet. |
2245 // Return offset outside of tab. | 2231 // Return offset outside of tab. |
2246 return CGRectGetMaxY(self.view.frame); | 2232 return CGRectGetMaxY(self.view.frame); |
2247 } else if (IsIPadIdiom()) { | 2233 } else if (IsIPadIdiom()) { |
2248 // The infobars on iPad are display at the top of a tab. | 2234 // The infobars on iPad are display at the top of a tab. |
2249 return CGRectGetMinY([[_model currentTab].webController visibleFrame]); | 2235 return CGRectGetMinY([[_model currentTab].webController visibleFrame]); |
2250 } else { | 2236 } else { |
2251 // The infobars on iPhone are displayed at the bottom of a tab. | 2237 // The infobars on iPhone are displayed at the bottom of a tab. |
2252 CGRect visibleFrame = [[_model currentTab].webController visibleFrame]; | 2238 CGRect visibleFrame = [[_model currentTab].webController visibleFrame]; |
(...skipping 17 matching lines...) Expand all Loading... | |
2270 // no visible voice search. Return offset outside of tab. | 2256 // no visible voice search. Return offset outside of tab. |
2271 return CGRectGetMaxY(self.view.frame); | 2257 return CGRectGetMaxY(self.view.frame); |
2272 } else { | 2258 } else { |
2273 // The voice search bar on iPhone is displayed at the bottom of a tab. | 2259 // The voice search bar on iPhone is displayed at the bottom of a tab. |
2274 CGRect visibleFrame = [[_model currentTab].webController visibleFrame]; | 2260 CGRect visibleFrame = [[_model currentTab].webController visibleFrame]; |
2275 return CGRectGetMaxY(visibleFrame) - kVoiceSearchBarHeight; | 2261 return CGRectGetMaxY(visibleFrame) - kVoiceSearchBarHeight; |
2276 } | 2262 } |
2277 } | 2263 } |
2278 | 2264 |
2279 - (void)ensureVoiceSearchControllerCreated { | 2265 - (void)ensureVoiceSearchControllerCreated { |
2280 if (!_voiceSearchController.get()) { | 2266 if (!_voiceSearchController) { |
2281 VoiceSearchProvider* provider = | 2267 VoiceSearchProvider* provider = |
2282 ios::GetChromeBrowserProvider()->GetVoiceSearchProvider(); | 2268 ios::GetChromeBrowserProvider()->GetVoiceSearchProvider(); |
2283 if (provider) { | 2269 if (provider) { |
2284 _voiceSearchController = | 2270 _voiceSearchController = |
2285 provider->CreateVoiceSearchController(_browserState); | 2271 provider->CreateVoiceSearchController(_browserState); |
2286 _voiceSearchController->SetDelegate(_toolbarController); | 2272 _voiceSearchController->SetDelegate(_toolbarController); |
2287 } | 2273 } |
2288 } | 2274 } |
2289 } | 2275 } |
2290 | 2276 |
2291 - (void)ensureVoiceSearchBarCreated { | 2277 - (void)ensureVoiceSearchBarCreated { |
2292 if (_voiceSearchBar) | 2278 if (_voiceSearchBar) |
2293 return; | 2279 return; |
2294 | 2280 |
2295 CGFloat width = CGRectGetWidth([[self view] bounds]); | 2281 CGFloat width = CGRectGetWidth([[self view] bounds]); |
2296 CGFloat y = CGRectGetHeight([[self view] bounds]) - kVoiceSearchBarHeight; | 2282 CGFloat y = CGRectGetHeight([[self view] bounds]) - kVoiceSearchBarHeight; |
2297 CGRect frame = CGRectMake(0.0, y, width, kVoiceSearchBarHeight); | 2283 CGRect frame = CGRectMake(0.0, y, width, kVoiceSearchBarHeight); |
2298 _voiceSearchBar.reset(ios::GetChromeBrowserProvider() | 2284 _voiceSearchBar = ios::GetChromeBrowserProvider() |
2299 ->GetVoiceSearchProvider() | 2285 ->GetVoiceSearchProvider() |
2300 ->BuildVoiceSearchBar(frame)); | 2286 ->BuildVoiceSearchBar(frame); |
2301 [_voiceSearchBar setVoiceSearchBarDelegate:self]; | 2287 [_voiceSearchBar setVoiceSearchBarDelegate:self]; |
2302 [_voiceSearchBar setHidden:YES]; | 2288 [_voiceSearchBar setHidden:YES]; |
2303 [_voiceSearchBar setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | | 2289 [_voiceSearchBar setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | |
2304 UIViewAutoresizingFlexibleWidth]; | 2290 UIViewAutoresizingFlexibleWidth]; |
2305 [self.view insertSubview:_voiceSearchBar | 2291 [self.view insertSubview:_voiceSearchBar |
2306 belowSubview:_infoBarContainer->view()]; | 2292 belowSubview:_infoBarContainer->view()]; |
2307 } | 2293 } |
2308 | 2294 |
2309 - (void)updateVoiceSearchBarVisibilityAnimated:(BOOL)animated { | 2295 - (void)updateVoiceSearchBarVisibilityAnimated:(BOOL)animated { |
2310 // Voice search bar exists and is shown/hidden. | 2296 // Voice search bar exists and is shown/hidden. |
2311 BOOL show = self.shouldShowVoiceSearchBar; | 2297 BOOL show = self.shouldShowVoiceSearchBar; |
2312 if (_voiceSearchBar && _voiceSearchBar.get().hidden != show) | 2298 if (_voiceSearchBar && _voiceSearchBar.hidden != show) |
2313 return; | 2299 return; |
2314 | 2300 |
2315 // Voice search bar doesn't exist and thus is not visible. | 2301 // Voice search bar doesn't exist and thus is not visible. |
2316 if (!_voiceSearchBar && !show) | 2302 if (!_voiceSearchBar && !show) |
2317 return; | 2303 return; |
2318 | 2304 |
2319 if (animated) | 2305 if (animated) |
2320 [_voiceSearchBar.get() animateToBecomeVisible:show]; | 2306 [_voiceSearchBar animateToBecomeVisible:show]; |
2321 else | 2307 else |
2322 _voiceSearchBar.get().hidden = !show; | 2308 _voiceSearchBar.hidden = !show; |
2323 } | 2309 } |
2324 | 2310 |
2325 - (id<LogoAnimationControllerOwner>)currentLogoAnimationControllerOwner { | 2311 - (id<LogoAnimationControllerOwner>)currentLogoAnimationControllerOwner { |
2326 Protocol* ownerProtocol = @protocol(LogoAnimationControllerOwner); | 2312 Protocol* ownerProtocol = @protocol(LogoAnimationControllerOwner); |
2327 if ([_voiceSearchBar conformsToProtocol:ownerProtocol] && | 2313 if ([_voiceSearchBar conformsToProtocol:ownerProtocol] && |
2328 self.shouldShowVoiceSearchBar) { | 2314 self.shouldShowVoiceSearchBar) { |
2329 // Use |_voiceSearchBar| for VoiceSearch results tab and dismissal | 2315 // Use |_voiceSearchBar| for VoiceSearch results tab and dismissal |
2330 // animations. | 2316 // animations. |
2331 return static_cast<id<LogoAnimationControllerOwner>>(_voiceSearchBar.get()); | 2317 return static_cast<id<LogoAnimationControllerOwner>>(_voiceSearchBar); |
2332 } | 2318 } |
2333 id currentNativeController = | 2319 id currentNativeController = |
2334 [self nativeControllerForTab:self.tabModel.currentTab]; | 2320 [self nativeControllerForTab:self.tabModel.currentTab]; |
2335 Protocol* possibleOwnerProtocol = | 2321 Protocol* possibleOwnerProtocol = |
2336 @protocol(LogoAnimationControllerOwnerOwner); | 2322 @protocol(LogoAnimationControllerOwnerOwner); |
2337 if ([currentNativeController conformsToProtocol:possibleOwnerProtocol] && | 2323 if ([currentNativeController conformsToProtocol:possibleOwnerProtocol] && |
2338 [currentNativeController logoAnimationControllerOwner]) { | 2324 [currentNativeController logoAnimationControllerOwner]) { |
2339 // If the current native controller is showing a GLIF view (e.g. the NTP | 2325 // If the current native controller is showing a GLIF view (e.g. the NTP |
2340 // when there is no doodle), use that GLIFControllerOwner. | 2326 // when there is no doodle), use that GLIFControllerOwner. |
2341 return [currentNativeController logoAnimationControllerOwner]; | 2327 return [currentNativeController logoAnimationControllerOwner]; |
2342 } | 2328 } |
2343 return nil; | 2329 return nil; |
2344 } | 2330 } |
2345 | 2331 |
2346 #pragma mark - PassKitDialogProvider methods | 2332 #pragma mark - PassKitDialogProvider methods |
2347 | 2333 |
2348 - (void)presentPassKitDialog:(NSData*)data { | 2334 - (void)presentPassKitDialog:(NSData*)data { |
2349 NSError* error = nil; | 2335 NSError* error = nil; |
2350 base::scoped_nsobject<PKPass> pass; | 2336 PKPass* pass = nil; |
2351 if (data) | 2337 if (data) |
2352 pass.reset([[PKPass alloc] initWithData:data error:&error]); | 2338 pass = [[PKPass alloc] initWithData:data error:&error]; |
2353 if (error || !data) { | 2339 if (error || !data) { |
2354 if ([_model currentTab]) { | 2340 if ([_model currentTab]) { |
2355 infobars::InfoBarManager* infoBarManager = | 2341 infobars::InfoBarManager* infoBarManager = |
2356 [[_model currentTab] infoBarManager]; | 2342 [[_model currentTab] infoBarManager]; |
2357 // TODO(crbug.com/227994): Infobar cleanup (infoBarManager should never be | 2343 // TODO(crbug.com/227994): Infobar cleanup (infoBarManager should never be |
2358 // NULL, replace if with DCHECK). | 2344 // NULL, replace if with DCHECK). |
2359 if (infoBarManager) | 2345 if (infoBarManager) |
2360 [_dependencyFactory showPassKitErrorInfoBarForManager:infoBarManager]; | 2346 [_dependencyFactory showPassKitErrorInfoBarForManager:infoBarManager]; |
2361 } | 2347 } |
2362 } else { | 2348 } else { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2475 } | 2461 } |
2476 | 2462 |
2477 // No custom context menu if no valid url is available in |params|. | 2463 // No custom context menu if no valid url is available in |params|. |
2478 if (!params.link_url.is_valid() && !params.src_url.is_valid()) { | 2464 if (!params.link_url.is_valid() && !params.src_url.is_valid()) { |
2479 return NO; | 2465 return NO; |
2480 } | 2466 } |
2481 | 2467 |
2482 DCHECK(_browserState); | 2468 DCHECK(_browserState); |
2483 DCHECK([_model currentTab]); | 2469 DCHECK([_model currentTab]); |
2484 | 2470 |
2485 _contextMenuCoordinator.reset([[ContextMenuCoordinator alloc] | 2471 _contextMenuCoordinator = |
2486 initWithBaseViewController:self | 2472 [[ContextMenuCoordinator alloc] initWithBaseViewController:self |
2487 params:params]); | 2473 params:params]; |
2488 | 2474 |
2489 NSString* title = nil; | 2475 NSString* title = nil; |
2490 ProceduralBlock action = nil; | 2476 ProceduralBlock action = nil; |
2491 | 2477 |
2492 base::WeakNSObject<BrowserViewController> weakSelf(self); | 2478 __weak BrowserViewController* weakSelf = self; |
2493 GURL link = params.link_url; | 2479 GURL link = params.link_url; |
2494 bool isLink = link.is_valid(); | 2480 bool isLink = link.is_valid(); |
2495 GURL imageUrl = params.src_url; | 2481 GURL imageUrl = params.src_url; |
2496 bool isImage = imageUrl.is_valid(); | 2482 bool isImage = imageUrl.is_valid(); |
2497 | 2483 |
2498 if (isLink) { | 2484 if (isLink) { |
2499 if (link.SchemeIs(url::kJavaScriptScheme)) { | 2485 if (link.SchemeIs(url::kJavaScriptScheme)) { |
2500 // Open | 2486 // Open |
2501 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPEN); | 2487 title = l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPEN); |
2502 action = ^{ | 2488 action = ^{ |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3107 break; | 3093 break; |
3108 } | 3094 } |
3109 } | 3095 } |
3110 } | 3096 } |
3111 | 3097 |
3112 #pragma mark - Context menu methods | 3098 #pragma mark - Context menu methods |
3113 | 3099 |
3114 - (void)searchByImageAtURL:(const GURL&)url | 3100 - (void)searchByImageAtURL:(const GURL&)url |
3115 referrer:(const web::Referrer)referrer { | 3101 referrer:(const web::Referrer)referrer { |
3116 DCHECK(url.is_valid()); | 3102 DCHECK(url.is_valid()); |
3117 base::WeakNSObject<BrowserViewController> weakSelf(self); | 3103 __weak BrowserViewController* weakSelf = self; |
3118 const GURL image_source_url = url; | 3104 const GURL image_source_url = url; |
3119 image_fetcher::IOSImageDataFetcherCallback callback = ^( | 3105 image_fetcher::IOSImageDataFetcherCallback callback = ^( |
3120 NSData* data, const image_fetcher::RequestMetadata& metadata) { | 3106 NSData* data, const image_fetcher::RequestMetadata& metadata) { |
3121 DCHECK(data); | 3107 DCHECK(data); |
3122 dispatch_async(dispatch_get_main_queue(), ^{ | 3108 dispatch_async(dispatch_get_main_queue(), ^{ |
3123 [weakSelf searchByImageData:data atURL:image_source_url]; | 3109 [weakSelf searchByImageData:data atURL:image_source_url]; |
3124 }); | 3110 }); |
3125 }; | 3111 }; |
3126 _imageFetcher->FetchImageDataWebpDecoded( | 3112 _imageFetcher->FetchImageDataWebpDecoded( |
3127 url, callback, web::ReferrerHeaderValueForNavigation(url, referrer), | 3113 url, callback, web::ReferrerHeaderValueForNavigation(url, referrer), |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3286 | 3272 |
3287 - (void)displayImageErrorAlertWithSettings:(NSURL*)settingURL { | 3273 - (void)displayImageErrorAlertWithSettings:(NSURL*)settingURL { |
3288 // Dismiss current alert. | 3274 // Dismiss current alert. |
3289 [_alertCoordinator stop]; | 3275 [_alertCoordinator stop]; |
3290 | 3276 |
3291 NSString* title = | 3277 NSString* title = |
3292 l10n_util::GetNSString(IDS_IOS_SAVE_IMAGE_PRIVACY_ALERT_TITLE); | 3278 l10n_util::GetNSString(IDS_IOS_SAVE_IMAGE_PRIVACY_ALERT_TITLE); |
3293 NSString* message = l10n_util::GetNSString( | 3279 NSString* message = l10n_util::GetNSString( |
3294 IDS_IOS_SAVE_IMAGE_PRIVACY_ALERT_MESSAGE_GO_TO_SETTINGS); | 3280 IDS_IOS_SAVE_IMAGE_PRIVACY_ALERT_MESSAGE_GO_TO_SETTINGS); |
3295 | 3281 |
3296 _alertCoordinator.reset([[AlertCoordinator alloc] | 3282 _alertCoordinator = |
3297 initWithBaseViewController:self | 3283 [[AlertCoordinator alloc] initWithBaseViewController:self |
3298 title:title | 3284 title:title |
3299 message:message]); | 3285 message:message]; |
3300 | 3286 |
3301 [_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) | 3287 [_alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) |
3302 action:nil | 3288 action:nil |
3303 style:UIAlertActionStyleCancel]; | 3289 style:UIAlertActionStyleCancel]; |
3304 | 3290 |
3305 [_alertCoordinator | 3291 [_alertCoordinator |
3306 addItemWithTitle:l10n_util::GetNSString( | 3292 addItemWithTitle:l10n_util::GetNSString( |
3307 IDS_IOS_SAVE_IMAGE_PRIVACY_ALERT_GO_TO_SETTINGS) | 3293 IDS_IOS_SAVE_IMAGE_PRIVACY_ALERT_GO_TO_SETTINGS) |
3308 action:^{ | 3294 action:^{ |
3309 OpenUrlWithCompletionHandler(settingURL, nil); | 3295 OpenUrlWithCompletionHandler(settingURL, nil); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3348 DCHECK(_browserState); | 3334 DCHECK(_browserState); |
3349 DCHECK(self.visible || self.dismissingModal); | 3335 DCHECK(self.visible || self.dismissingModal); |
3350 | 3336 |
3351 // Dismiss the omnibox (if open). | 3337 // Dismiss the omnibox (if open). |
3352 [_toolbarController cancelOmniboxEdit]; | 3338 [_toolbarController cancelOmniboxEdit]; |
3353 // Dismiss the soft keyboard (if open). | 3339 // Dismiss the soft keyboard (if open). |
3354 [[_model currentTab].webController dismissKeyboard]; | 3340 [[_model currentTab].webController dismissKeyboard]; |
3355 // Dismiss Find in Page focus. | 3341 // Dismiss Find in Page focus. |
3356 [self updateFindBar:NO shouldFocus:NO]; | 3342 [self updateFindBar:NO shouldFocus:NO]; |
3357 | 3343 |
3358 base::scoped_nsobject<ToolsMenuConfiguration> configuration( | 3344 ToolsMenuConfiguration* configuration = |
3359 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]); | 3345 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
3360 if ([_model count] == 0) | 3346 if ([_model count] == 0) |
3361 [configuration setNoOpenedTabs:YES]; | 3347 [configuration setNoOpenedTabs:YES]; |
3362 | 3348 |
3363 if (_isOffTheRecord) | 3349 if (_isOffTheRecord) |
3364 [configuration setInIncognito:YES]; | 3350 [configuration setInIncognito:YES]; |
3365 | 3351 |
3366 if (!_readingListMenuNotifier) { | 3352 if (!_readingListMenuNotifier) { |
3367 _readingListMenuNotifier.reset([[ReadingListMenuNotifier alloc] | 3353 _readingListMenuNotifier = [[ReadingListMenuNotifier alloc] |
3368 initWithReadingList:ReadingListModelFactory::GetForBrowserState( | 3354 initWithReadingList:ReadingListModelFactory::GetForBrowserState( |
3369 _browserState)]); | 3355 _browserState)]; |
3370 } | 3356 } |
3371 [configuration setReadingListMenuNotifier:_readingListMenuNotifier]; | 3357 [configuration setReadingListMenuNotifier:_readingListMenuNotifier]; |
3372 | 3358 |
3373 [configuration setUserAgentType:self.userAgentType]; | 3359 [configuration setUserAgentType:self.userAgentType]; |
3374 | 3360 |
3375 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; | 3361 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
3376 | 3362 |
3377 ToolsPopupController* toolsPopupController = | 3363 ToolsPopupController* toolsPopupController = |
3378 [_toolbarController toolsPopupController]; | 3364 [_toolbarController toolsPopupController]; |
3379 if ([_model currentTab]) { | 3365 if ([_model currentTab]) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3421 [[NSNotificationCenter defaultCenter] | 3407 [[NSNotificationCenter defaultCenter] |
3422 postNotificationName:ios_internal::kPageInfoWillShowNotification | 3408 postNotificationName:ios_internal::kPageInfoWillShowNotification |
3423 object:nil]; | 3409 object:nil]; |
3424 | 3410 |
3425 // TODO(rohitrao): Get rid of PageInfoModel completely. | 3411 // TODO(rohitrao): Get rid of PageInfoModel completely. |
3426 PageInfoModelBubbleBridge* bridge = new PageInfoModelBubbleBridge(); | 3412 PageInfoModelBubbleBridge* bridge = new PageInfoModelBubbleBridge(); |
3427 PageInfoModel* pageInfoModel = new PageInfoModel( | 3413 PageInfoModel* pageInfoModel = new PageInfoModel( |
3428 _browserState, navItem->GetURL(), navItem->GetSSL(), bridge); | 3414 _browserState, navItem->GetURL(), navItem->GetSSL(), bridge); |
3429 | 3415 |
3430 UIView* view = [self view]; | 3416 UIView* view = [self view]; |
3431 _pageInfoController.reset([[PageInfoViewController alloc] | 3417 _pageInfoController = [[PageInfoViewController alloc] |
3432 initWithModel:pageInfoModel | 3418 initWithModel:pageInfoModel |
3433 bridge:bridge | 3419 bridge:bridge |
3434 sourceFrame:[sourceView convertRect:[sourceView bounds] toView:view] | 3420 sourceFrame:[sourceView convertRect:[sourceView bounds] toView:view] |
3435 parentView:view]); | 3421 parentView:view]; |
3436 bridge->set_controller(_pageInfoController.get()); | 3422 bridge->set_controller(_pageInfoController); |
3437 } | 3423 } |
3438 | 3424 |
3439 - (void)hidePageInfoPopupForView:(UIView*)sourceView { | 3425 - (void)hidePageInfoPopupForView:(UIView*)sourceView { |
3440 [_pageInfoController dismiss]; | 3426 [_pageInfoController dismiss]; |
3441 _pageInfoController.reset(); | 3427 _pageInfoController = nil; |
3442 } | 3428 } |
3443 | 3429 |
3444 - (void)showSecurityHelpPage { | 3430 - (void)showSecurityHelpPage { |
3445 [self webPageOrderedOpen:GURL(kPageInfoHelpCenterURL) | 3431 [self webPageOrderedOpen:GURL(kPageInfoHelpCenterURL) |
3446 referrer:web::Referrer() | 3432 referrer:web::Referrer() |
3447 inBackground:NO | 3433 inBackground:NO |
3448 appendTo:kCurrentTab]; | 3434 appendTo:kCurrentTab]; |
3449 [self hidePageInfoPopupForView:nil]; | 3435 [self hidePageInfoPopupForView:nil]; |
3450 } | 3436 } |
3451 | 3437 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3492 Tab* currentTab = [_model currentTab]; | 3478 Tab* currentTab = [_model currentTab]; |
3493 // The UI should prevent users from printing non-printable pages. However, a | 3479 // The UI should prevent users from printing non-printable pages. However, a |
3494 // redirection to an un-printable page can happen before it is reflected in | 3480 // redirection to an un-printable page can happen before it is reflected in |
3495 // the UI. | 3481 // the UI. |
3496 if (![currentTab viewForPrinting]) { | 3482 if (![currentTab viewForPrinting]) { |
3497 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeError); | 3483 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeError); |
3498 [self showSnackbar:l10n_util::GetNSString(IDS_IOS_CANNOT_PRINT_PAGE_ERROR)]; | 3484 [self showSnackbar:l10n_util::GetNSString(IDS_IOS_CANNOT_PRINT_PAGE_ERROR)]; |
3499 return; | 3485 return; |
3500 } | 3486 } |
3501 DCHECK(_browserState); | 3487 DCHECK(_browserState); |
3502 if (!_printController.get()) { | 3488 if (!_printController) { |
3503 _printController.reset([[PrintController alloc] | 3489 _printController = [[PrintController alloc] |
3504 initWithContextGetter:_browserState->GetRequestContext()]); | 3490 initWithContextGetter:_browserState->GetRequestContext()]; |
3505 } | 3491 } |
3506 [_printController printView:[currentTab viewForPrinting] | 3492 [_printController printView:[currentTab viewForPrinting] |
3507 withTitle:[currentTab title] | 3493 withTitle:[currentTab title] |
3508 viewController:self]; | 3494 viewController:self]; |
3509 } | 3495 } |
3510 | 3496 |
3511 - (void)addToReadingListURL:(const GURL&)URL title:(NSString*)title { | 3497 - (void)addToReadingListURL:(const GURL&)URL title:(NSString*)title { |
3512 base::RecordAction(UserMetricsAction("MobileReadingListAdd")); | 3498 base::RecordAction(UserMetricsAction("MobileReadingListAdd")); |
3513 | 3499 |
3514 ReadingListModel* readingModel = | 3500 ReadingListModel* readingModel = |
(...skipping 11 matching lines...) Expand all Loading... | |
3526 - (BOOL)shouldRegisterKeyboardCommands { | 3512 - (BOOL)shouldRegisterKeyboardCommands { |
3527 if ([self presentedViewController]) | 3513 if ([self presentedViewController]) |
3528 return NO; | 3514 return NO; |
3529 | 3515 |
3530 if (_voiceSearchController && _voiceSearchController->IsVisible()) | 3516 if (_voiceSearchController && _voiceSearchController->IsVisible()) |
3531 return NO; | 3517 return NO; |
3532 | 3518 |
3533 // If there is no first responder, try to make the webview the first | 3519 // If there is no first responder, try to make the webview the first |
3534 // responder. | 3520 // responder. |
3535 if (!GetFirstResponder()) { | 3521 if (!GetFirstResponder()) { |
3536 [_model.get().currentTab.webController.webViewProxy becomeFirstResponder]; | 3522 [_model.currentTab.webController.webViewProxy becomeFirstResponder]; |
3537 } | 3523 } |
3538 | 3524 |
3539 return YES; | 3525 return YES; |
3540 } | 3526 } |
3541 | 3527 |
3542 - (KeyCommandsProvider*)keyCommandsProvider { | 3528 - (KeyCommandsProvider*)keyCommandsProvider { |
3543 if (!_keyCommandsProvider) { | 3529 if (!_keyCommandsProvider) { |
3544 _keyCommandsProvider.reset([_dependencyFactory newKeyCommandsProvider]); | 3530 _keyCommandsProvider = [_dependencyFactory newKeyCommandsProvider]; |
3545 } | 3531 } |
3546 return _keyCommandsProvider.get(); | 3532 return _keyCommandsProvider; |
3547 } | 3533 } |
3548 | 3534 |
3549 #pragma mark - KeyCommandsPlumbing | 3535 #pragma mark - KeyCommandsPlumbing |
3550 | 3536 |
3551 - (BOOL)isOffTheRecord { | 3537 - (BOOL)isOffTheRecord { |
3552 return _isOffTheRecord; | 3538 return _isOffTheRecord; |
3553 } | 3539 } |
3554 | 3540 |
3555 - (NSUInteger)tabsCount { | 3541 - (NSUInteger)tabsCount { |
3556 return [_model count]; | 3542 return [_model count]; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3770 [self webPageOrderedOpen:url | 3756 [self webPageOrderedOpen:url |
3771 referrer:referrer | 3757 referrer:referrer |
3772 inBackground:inBackground | 3758 inBackground:inBackground |
3773 appendTo:appendTo]; | 3759 appendTo:appendTo]; |
3774 return; | 3760 return; |
3775 } | 3761 } |
3776 // When sending an open command that switches modes, ensure the tab | 3762 // When sending an open command that switches modes, ensure the tab |
3777 // ends up appended to the end of the model, not just next to what is | 3763 // ends up appended to the end of the model, not just next to what is |
3778 // currently selected in the other mode. This is done with the |append| | 3764 // currently selected in the other mode. This is done with the |append| |
3779 // parameter. | 3765 // parameter. |
3780 base::scoped_nsobject<OpenUrlCommand> command([[OpenUrlCommand alloc] | 3766 OpenUrlCommand* command = [[OpenUrlCommand alloc] |
3781 initWithURL:url | 3767 initWithURL:url |
3782 referrer:web::Referrer() // Strip referrer when switching modes. | 3768 referrer:web::Referrer() // Strip referrer when switching modes. |
3783 inIncognito:inIncognito | 3769 inIncognito:inIncognito |
3784 inBackground:inBackground | 3770 inBackground:inBackground |
3785 appendTo:kLastTab]); | 3771 appendTo:kLastTab]; |
3786 [self chromeExecuteCommand:command]; | 3772 [self chromeExecuteCommand:command]; |
3787 } | 3773 } |
3788 | 3774 |
3789 - (void)loadSessionTab:(const sessions::SessionTab*)sessionTab { | 3775 - (void)loadSessionTab:(const sessions::SessionTab*)sessionTab { |
3790 [[_model currentTab] loadSessionTab:sessionTab]; | 3776 [[_model currentTab] loadSessionTab:sessionTab]; |
3791 } | 3777 } |
3792 | 3778 |
3793 - (void)openJavascript:(NSString*)javascript { | 3779 - (void)openJavascript:(NSString*)javascript { |
3794 DCHECK(javascript); | 3780 DCHECK(javascript); |
3795 javascript = [javascript stringByRemovingPercentEncoding]; | 3781 javascript = [javascript stringByRemovingPercentEncoding]; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3856 web::WebState* webState = [_model currentTab].webState; | 3842 web::WebState* webState = [_model currentTab].webState; |
3857 if (!_toolbarModelIOS->IsLoading() && webState) | 3843 if (!_toolbarModelIOS->IsLoading() && webState) |
3858 webState->GetNavigationManager()->Reload(web::ReloadType::NORMAL, | 3844 webState->GetNavigationManager()->Reload(web::ReloadType::NORMAL, |
3859 false /* check_for_repost */); | 3845 false /* check_for_repost */); |
3860 } | 3846 } |
3861 } | 3847 } |
3862 | 3848 |
3863 - (IBAction)locationBarBeganEdit:(id)sender { | 3849 - (IBAction)locationBarBeganEdit:(id)sender { |
3864 // On handsets, if a page is currently loading it should be stopped. | 3850 // On handsets, if a page is currently loading it should be stopped. |
3865 if (!IsIPadIdiom() && _toolbarModelIOS->IsLoading()) { | 3851 if (!IsIPadIdiom() && _toolbarModelIOS->IsLoading()) { |
3866 base::scoped_nsobject<GenericChromeCommand> command( | 3852 GenericChromeCommand* command = |
3867 [[GenericChromeCommand alloc] initWithTag:IDC_STOP]); | 3853 [[GenericChromeCommand alloc] initWithTag:IDC_STOP]; |
3868 [self chromeExecuteCommand:command]; | 3854 [self chromeExecuteCommand:command]; |
3869 _locationBarEditCancelledLoad = YES; | 3855 _locationBarEditCancelledLoad = YES; |
3870 } | 3856 } |
3871 } | 3857 } |
3872 | 3858 |
3873 - (IBAction)prepareToEnterTabSwitcher:(id)sender { | 3859 - (IBAction)prepareToEnterTabSwitcher:(id)sender { |
3874 [[_model currentTab] updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 3860 [[_model currentTab] updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
3875 } | 3861 } |
3876 | 3862 |
3877 - (ToolbarModelIOS*)toolbarModelIOS { | 3863 - (ToolbarModelIOS*)toolbarModelIOS { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4089 case IDC_RATE_THIS_APP: | 4075 case IDC_RATE_THIS_APP: |
4090 [self showRateThisAppDialog]; | 4076 [self showRateThisAppDialog]; |
4091 break; | 4077 break; |
4092 case IDC_SHOW_READING_LIST: | 4078 case IDC_SHOW_READING_LIST: |
4093 [self showReadingList]; | 4079 [self showReadingList]; |
4094 break; | 4080 break; |
4095 case IDC_VOICE_SEARCH: | 4081 case IDC_VOICE_SEARCH: |
4096 // If the voice search command is coming from a UIView sender, store it | 4082 // If the voice search command is coming from a UIView sender, store it |
4097 // before sending the command up the responder chain. | 4083 // before sending the command up the responder chain. |
4098 if ([sender isKindOfClass:[UIView class]]) | 4084 if ([sender isKindOfClass:[UIView class]]) |
4099 _voiceSearchButton.reset(sender); | 4085 _voiceSearchButton = sender; |
4100 [super chromeExecuteCommand:sender]; | 4086 [super chromeExecuteCommand:sender]; |
4101 break; | 4087 break; |
4102 case IDC_SHOW_QR_SCANNER: | 4088 case IDC_SHOW_QR_SCANNER: |
4103 [self showQRScanner]; | 4089 [self showQRScanner]; |
4104 break; | 4090 break; |
4105 case IDC_SHOW_SUGGESTIONS: | 4091 case IDC_SHOW_SUGGESTIONS: |
4106 if (experimental_flags::IsSuggestionsUIEnabled()) { | 4092 if (experimental_flags::IsSuggestionsUIEnabled()) { |
4107 [self showSuggestionsUI]; | 4093 [self showSuggestionsUI]; |
4108 } | 4094 } |
4109 break; | 4095 break; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4177 if (findHelper) { | 4163 if (findHelper) { |
4178 findHelper->StopFinding(^{ | 4164 findHelper->StopFinding(^{ |
4179 [self updateFindBar:NO shouldFocus:NO]; | 4165 [self updateFindBar:NO shouldFocus:NO]; |
4180 }); | 4166 }); |
4181 } | 4167 } |
4182 } | 4168 } |
4183 | 4169 |
4184 [_contextualSearchController movePanelOffscreen]; | 4170 [_contextualSearchController movePanelOffscreen]; |
4185 [_paymentRequestManager cancelRequest]; | 4171 [_paymentRequestManager cancelRequest]; |
4186 [_printController dismissAnimated:YES]; | 4172 [_printController dismissAnimated:YES]; |
4187 _printController.reset(); | 4173 _printController = nil; |
4188 [_toolbarController dismissToolsMenuPopup]; | 4174 [_toolbarController dismissToolsMenuPopup]; |
4189 [_contextMenuCoordinator stop]; | 4175 [_contextMenuCoordinator stop]; |
4190 [self dismissRateThisAppDialog]; | 4176 [self dismissRateThisAppDialog]; |
4191 | 4177 |
4192 [_contentSuggestionsCoordinator stop]; | 4178 [_contentSuggestionsCoordinator stop]; |
4193 | 4179 |
4194 if (self.presentedViewController) { | 4180 if (self.presentedViewController) { |
4195 // Dismisses any other modal controllers that may be present, e.g. Recent | 4181 // Dismisses any other modal controllers that may be present, e.g. Recent |
4196 // Tabs. | 4182 // Tabs. |
4197 // Note that currently, some controllers like the bookmark ones were already | 4183 // Note that currently, some controllers like the bookmark ones were already |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4272 selectText:selectText]; | 4258 selectText:selectText]; |
4273 [self updateFindBar:YES shouldFocus:shouldFocus]; | 4259 [self updateFindBar:YES shouldFocus:shouldFocus]; |
4274 } | 4260 } |
4275 | 4261 |
4276 // Create find bar controller and pass it to the web controller. | 4262 // Create find bar controller and pass it to the web controller. |
4277 - (void)initFindBarForTab { | 4263 - (void)initFindBarForTab { |
4278 if (!self.canShowFindBar) | 4264 if (!self.canShowFindBar) |
4279 return; | 4265 return; |
4280 | 4266 |
4281 if (!_findBarController) | 4267 if (!_findBarController) |
4282 _findBarController.reset( | 4268 _findBarController = |
4283 [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]); | 4269 [[FindBarControllerIOS alloc] initWithIncognito:_isOffTheRecord]; |
4284 | 4270 |
4285 Tab* tab = [_model currentTab]; | 4271 Tab* tab = [_model currentTab]; |
4286 DCHECK(tab); | 4272 DCHECK(tab); |
4287 auto* helper = FindTabHelper::FromWebState(tab.webState); | 4273 auto* helper = FindTabHelper::FromWebState(tab.webState); |
4288 DCHECK(!helper->IsFindUIActive()); | 4274 DCHECK(!helper->IsFindUIActive()); |
4289 helper->SetFindUIActive(true); | 4275 helper->SetFindUIActive(true); |
4290 [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES]; | 4276 [self showFindBarWithAnimation:YES selectText:YES shouldFocus:YES]; |
4291 } | 4277 } |
4292 | 4278 |
4293 - (void)searchFindInPage { | 4279 - (void)searchFindInPage { |
4294 DCHECK([_model currentTab]); | 4280 DCHECK([_model currentTab]); |
4295 auto* helper = FindTabHelper::FromWebState([_model currentTab].webState); | 4281 auto* helper = FindTabHelper::FromWebState([_model currentTab].webState); |
4296 base::WeakNSObject<BrowserViewController> weakSelf(self); | 4282 __weak BrowserViewController* weakSelf = self; |
4297 helper->StartFinding([_findBarController searchTerm], | 4283 helper->StartFinding( |
4298 ^(FindInPageModel* model) { | 4284 [_findBarController searchTerm], ^(FindInPageModel* model) { |
4299 [_findBarController updateResultsCount:model]; | 4285 BrowserViewController* strongSelf = weakSelf; |
4300 }); | 4286 if (!strongSelf) { |
4287 return; | |
4288 } | |
4289 [strongSelf->_findBarController updateResultsCount:model]; | |
4290 }); | |
4301 | 4291 |
4302 if (!_isOffTheRecord) | 4292 if (!_isOffTheRecord) |
4303 helper->PersistSearchTerm(); | 4293 helper->PersistSearchTerm(); |
4304 } | 4294 } |
4305 | 4295 |
4306 - (void)closeFindInPage { | 4296 - (void)closeFindInPage { |
4307 base::WeakNSObject<BrowserViewController> weakSelf(self); | 4297 __weak BrowserViewController* weakSelf = self; |
4308 Tab* currentTab = [_model currentTab]; | 4298 Tab* currentTab = [_model currentTab]; |
4309 if (currentTab) { | 4299 if (currentTab) { |
4310 FindTabHelper::FromWebState(currentTab.webState)->StopFinding(^{ | 4300 FindTabHelper::FromWebState(currentTab.webState)->StopFinding(^{ |
4311 [weakSelf updateFindBar:NO shouldFocus:NO]; | 4301 [weakSelf updateFindBar:NO shouldFocus:NO]; |
4312 }); | 4302 }); |
4313 } | 4303 } |
4314 } | 4304 } |
4315 | 4305 |
4316 - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus { | 4306 - (void)updateFindBar:(BOOL)initialUpdate shouldFocus:(BOOL)shouldFocus { |
4317 DCHECK([_model currentTab]); | 4307 DCHECK([_model currentTab]); |
(...skipping 16 matching lines...) Expand all Loading... | |
4334 - (void)showAllBookmarks { | 4324 - (void)showAllBookmarks { |
4335 DCHECK(self.visible || self.dismissingModal); | 4325 DCHECK(self.visible || self.dismissingModal); |
4336 GURL URL(kChromeUIBookmarksURL); | 4326 GURL URL(kChromeUIBookmarksURL); |
4337 Tab* tab = [_model currentTab]; | 4327 Tab* tab = [_model currentTab]; |
4338 web::NavigationManager::WebLoadParams params(URL); | 4328 web::NavigationManager::WebLoadParams params(URL); |
4339 params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; | 4329 params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
4340 [tab navigationManager]->LoadURLWithParams(params); | 4330 [tab navigationManager]->LoadURLWithParams(params); |
4341 } | 4331 } |
4342 | 4332 |
4343 - (void)showReadingList { | 4333 - (void)showReadingList { |
4344 _readingListCoordinator.reset([[ReadingListCoordinator alloc] | 4334 _readingListCoordinator = [[ReadingListCoordinator alloc] |
4345 initWithBaseViewController:self | 4335 initWithBaseViewController:self |
4346 browserState:self.browserState | 4336 browserState:self.browserState |
4347 loader:self]); | 4337 loader:self]; |
4348 | 4338 |
4349 [_readingListCoordinator start]; | 4339 [_readingListCoordinator start]; |
4350 } | 4340 } |
4351 | 4341 |
4352 - (void)showQRScanner { | 4342 - (void)showQRScanner { |
4353 _qrScannerViewController.reset( | 4343 _qrScannerViewController = |
4354 [[QRScannerViewController alloc] initWithDelegate:_toolbarController]); | 4344 [[QRScannerViewController alloc] initWithDelegate:_toolbarController]; |
4355 [self presentViewController:[_qrScannerViewController | 4345 [self presentViewController:[_qrScannerViewController |
4356 getViewControllerToPresent] | 4346 getViewControllerToPresent] |
4357 animated:YES | 4347 animated:YES |
4358 completion:nil]; | 4348 completion:nil]; |
4359 } | 4349 } |
4360 | 4350 |
4361 - (void)showSuggestionsUI { | 4351 - (void)showSuggestionsUI { |
4362 if (!_contentSuggestionsCoordinator) { | 4352 if (!_contentSuggestionsCoordinator) { |
4363 _contentSuggestionsCoordinator.reset([[ContentSuggestionsCoordinator alloc] | 4353 _contentSuggestionsCoordinator = |
4364 initWithBaseViewController:self]); | 4354 [[ContentSuggestionsCoordinator alloc] initWithBaseViewController:self]; |
4365 [_contentSuggestionsCoordinator setURLLoader:self]; | 4355 [_contentSuggestionsCoordinator setURLLoader:self]; |
4366 } | 4356 } |
4367 [_contentSuggestionsCoordinator setBrowserState:_browserState]; | 4357 [_contentSuggestionsCoordinator setBrowserState:_browserState]; |
4368 [_contentSuggestionsCoordinator start]; | 4358 [_contentSuggestionsCoordinator start]; |
4369 } | 4359 } |
4370 | 4360 |
4371 - (void)showNTPPanel:(NewTabPage::PanelIdentifier)panel { | 4361 - (void)showNTPPanel:(NewTabPage::PanelIdentifier)panel { |
4372 DCHECK(self.visible || self.dismissingModal); | 4362 DCHECK(self.visible || self.dismissingModal); |
4373 GURL url(kChromeUINewTabURL); | 4363 GURL url(kChromeUINewTabURL); |
4374 std::string fragment(NewTabPage::FragmentFromIdentifier(panel)); | 4364 std::string fragment(NewTabPage::FragmentFromIdentifier(panel)); |
4375 if (fragment != "") { | 4365 if (fragment != "") { |
4376 GURL::Replacements replacement; | 4366 GURL::Replacements replacement; |
4377 replacement.SetRefStr(fragment); | 4367 replacement.SetRefStr(fragment); |
4378 url = url.ReplaceComponents(replacement); | 4368 url = url.ReplaceComponents(replacement); |
4379 } | 4369 } |
4380 Tab* tab = [_model currentTab]; | 4370 Tab* tab = [_model currentTab]; |
4381 web::NavigationManager::WebLoadParams params(url); | 4371 web::NavigationManager::WebLoadParams params(url); |
4382 params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; | 4372 params.transition_type = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
4383 [tab navigationManager]->LoadURLWithParams(params); | 4373 [tab navigationManager]->LoadURLWithParams(params); |
4384 } | 4374 } |
4385 | 4375 |
4386 - (void)showRateThisAppDialog { | 4376 - (void)showRateThisAppDialog { |
4387 DCHECK(!_rateThisAppDialog.get()); | 4377 DCHECK(!_rateThisAppDialog); |
4388 | 4378 |
4389 // Store the current timestamp whenever this dialog is shown. | 4379 // Store the current timestamp whenever this dialog is shown. |
4390 _browserState->GetPrefs()->SetInt64(prefs::kRateThisAppDialogLastShownTime, | 4380 _browserState->GetPrefs()->SetInt64(prefs::kRateThisAppDialogLastShownTime, |
4391 base::Time::Now().ToInternalValue()); | 4381 base::Time::Now().ToInternalValue()); |
4392 | 4382 |
4393 // Some versions of iOS7 do not support linking directly to the "Ratings and | 4383 // Some versions of iOS7 do not support linking directly to the "Ratings and |
4394 // Reviews" appstore page. For iOS7 fall back to an alternative URL that | 4384 // Reviews" appstore page. For iOS7 fall back to an alternative URL that |
4395 // links to the main appstore page for the Chrome app. | 4385 // links to the main appstore page for the Chrome app. |
4396 NSURL* storeURL = | 4386 NSURL* storeURL = |
4397 [NSURL URLWithString:(@"itms-apps://itunes.apple.com/WebObjects/" | 4387 [NSURL URLWithString:(@"itms-apps://itunes.apple.com/WebObjects/" |
4398 @"MZStore.woa/wa/" | 4388 @"MZStore.woa/wa/" |
4399 @"viewContentsUserReviews?type=Purple+Software&id=" | 4389 @"viewContentsUserReviews?type=Purple+Software&id=" |
4400 @"535886823&pt=9008&ct=rating")]; | 4390 @"535886823&pt=9008&ct=rating")]; |
4401 | 4391 |
4402 base::RecordAction(base::UserMetricsAction("IOSRateThisAppDialogShown")); | 4392 base::RecordAction(base::UserMetricsAction("IOSRateThisAppDialogShown")); |
4403 [self clearPresentedStateWithCompletion:nil]; | 4393 [self clearPresentedStateWithCompletion:nil]; |
4404 | 4394 |
4405 _rateThisAppDialog.reset( | 4395 _rateThisAppDialog = ios::GetChromeBrowserProvider()->CreateAppRatingPrompt(); |
4406 ios::GetChromeBrowserProvider()->CreateAppRatingPrompt()); | |
4407 [_rateThisAppDialog setAppStoreURL:storeURL]; | 4396 [_rateThisAppDialog setAppStoreURL:storeURL]; |
4408 [_rateThisAppDialog setDelegate:self]; | 4397 [_rateThisAppDialog setDelegate:self]; |
4409 [_rateThisAppDialog show]; | 4398 [_rateThisAppDialog show]; |
4410 } | 4399 } |
4411 | 4400 |
4412 - (void)dismissRateThisAppDialog { | 4401 - (void)dismissRateThisAppDialog { |
4413 if (_rateThisAppDialog.get()) { | 4402 if (_rateThisAppDialog) { |
4414 base::RecordAction(base::UserMetricsAction( | 4403 base::RecordAction(base::UserMetricsAction( |
4415 "IOSRateThisAppDialogDismissedProgramatically")); | 4404 "IOSRateThisAppDialogDismissedProgramatically")); |
4416 [_rateThisAppDialog dismiss]; | 4405 [_rateThisAppDialog dismiss]; |
4417 _rateThisAppDialog.reset(); | 4406 _rateThisAppDialog = nil; |
4418 } | 4407 } |
4419 } | 4408 } |
4420 | 4409 |
4421 #if !defined(NDEBUG) | 4410 #if !defined(NDEBUG) |
4422 - (void)viewSource { | 4411 - (void)viewSource { |
4423 Tab* tab = [_model currentTab]; | 4412 Tab* tab = [_model currentTab]; |
4424 DCHECK(tab); | 4413 DCHECK(tab); |
4425 CRWWebController* webController = tab.webController; | 4414 CRWWebController* webController = tab.webController; |
4426 NSString* script = @"document.documentElement.outerHTML;"; | 4415 NSString* script = @"document.documentElement.outerHTML;"; |
4427 base::WeakNSObject<Tab> weakTab(tab); | 4416 __weak Tab* weakTab = tab; |
4428 base::WeakNSObject<BrowserViewController> weakSelf(self); | 4417 __weak BrowserViewController* weakSelf = self; |
4429 web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) { | 4418 web::JavaScriptResultBlock completionHandlerBlock = ^(id result, NSError*) { |
4430 base::scoped_nsobject<Tab> strongTab(weakTab); | 4419 Tab* strongTab = weakTab; |
4431 if (!strongTab) | 4420 if (!strongTab) |
4432 return; | 4421 return; |
4433 if (![result isKindOfClass:[NSString class]]) | 4422 if (![result isKindOfClass:[NSString class]]) |
4434 result = @"Not an HTML page"; | 4423 result = @"Not an HTML page"; |
4435 std::string base64HTML; | 4424 std::string base64HTML; |
4436 base::Base64Encode(base::SysNSStringToUTF8(result), &base64HTML); | 4425 base::Base64Encode(base::SysNSStringToUTF8(result), &base64HTML); |
4437 GURL URL(std::string("data:text/plain;charset=utf-8;base64,") + base64HTML); | 4426 GURL URL(std::string("data:text/plain;charset=utf-8;base64,") + base64HTML); |
4438 web::Referrer referrer([strongTab url], web::ReferrerPolicyDefault); | 4427 web::Referrer referrer([strongTab url], web::ReferrerPolicyDefault); |
4439 | 4428 |
4440 [[weakSelf tabModel] | 4429 [[weakSelf tabModel] |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4481 | 4470 |
4482 ToolbarController* relinquishedToolbarController = nil; | 4471 ToolbarController* relinquishedToolbarController = nil; |
4483 if ([_toolbarController view].hidden) { | 4472 if ([_toolbarController view].hidden) { |
4484 Tab* currentTab = [_model currentTab]; | 4473 Tab* currentTab = [_model currentTab]; |
4485 if (currentTab && UrlHasChromeScheme(currentTab.url)) { | 4474 if (currentTab && UrlHasChromeScheme(currentTab.url)) { |
4486 // Use the native content controller's toolbar when the BVC's is hidden. | 4475 // Use the native content controller's toolbar when the BVC's is hidden. |
4487 id nativeController = [self nativeControllerForTab:currentTab]; | 4476 id nativeController = [self nativeControllerForTab:currentTab]; |
4488 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)]) { | 4477 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)]) { |
4489 relinquishedToolbarController = | 4478 relinquishedToolbarController = |
4490 [nativeController relinquishedToolbarController]; | 4479 [nativeController relinquishedToolbarController]; |
4491 _relinquishedToolbarOwner.reset(nativeController); | 4480 _relinquishedToolbarOwner = nativeController; |
4492 } | 4481 } |
4493 } | 4482 } |
4494 } else { | 4483 } else { |
4495 relinquishedToolbarController = _toolbarController.get(); | 4484 relinquishedToolbarController = _toolbarController; |
4496 } | 4485 } |
4497 _isToolbarControllerRelinquished = (relinquishedToolbarController != nil); | 4486 _isToolbarControllerRelinquished = (relinquishedToolbarController != nil); |
4498 return relinquishedToolbarController; | 4487 return relinquishedToolbarController; |
4499 } | 4488 } |
4500 | 4489 |
4501 - (void)reparentToolbarController { | 4490 - (void)reparentToolbarController { |
4502 if (_isToolbarControllerRelinquished) { | 4491 if (_isToolbarControllerRelinquished) { |
4503 if ([[_toolbarController view] isDescendantOfView:self.view]) { | 4492 if ([[_toolbarController view] isDescendantOfView:self.view]) { |
4504 // A native content controller's toolbar has been relinquished. | 4493 // A native content controller's toolbar has been relinquished. |
4505 [_relinquishedToolbarOwner reparentToolbarController]; | 4494 [_relinquishedToolbarOwner reparentToolbarController]; |
4506 _relinquishedToolbarOwner.reset(); | 4495 _relinquishedToolbarOwner = nil; |
4507 } else if ([_findBarController isFindInPageShown]) { | 4496 } else if ([_findBarController isFindInPageShown]) { |
4508 [self.view insertSubview:[_toolbarController view] | 4497 [self.view insertSubview:[_toolbarController view] |
4509 belowSubview:[_findBarController view]]; | 4498 belowSubview:[_findBarController view]]; |
4510 } else { | 4499 } else { |
4511 [self.view addSubview:[_toolbarController view]]; | 4500 [self.view addSubview:[_toolbarController view]]; |
4512 } | 4501 } |
4513 if (_contextualSearchPanel) { | 4502 if (_contextualSearchPanel) { |
4514 // Move panel back into its correct place. | 4503 // Move panel back into its correct place. |
4515 [self.view insertSubview:_contextualSearchPanel | 4504 [self.view insertSubview:_contextualSearchPanel |
4516 aboveSubview:[_toolbarController view]]; | 4505 aboveSubview:[_toolbarController view]]; |
(...skipping 20 matching lines...) Expand all Loading... | |
4537 | 4526 |
4538 // Observer method, active tab changed. | 4527 // Observer method, active tab changed. |
4539 - (void)tabModel:(TabModel*)model | 4528 - (void)tabModel:(TabModel*)model |
4540 didChangeActiveTab:(Tab*)newTab | 4529 didChangeActiveTab:(Tab*)newTab |
4541 previousTab:(Tab*)previousTab | 4530 previousTab:(Tab*)previousTab |
4542 atIndex:(NSUInteger)index { | 4531 atIndex:(NSUInteger)index { |
4543 // TODO(rohitrao): tabSelected expects to always be called with a non-nil tab. | 4532 // TODO(rohitrao): tabSelected expects to always be called with a non-nil tab. |
4544 // Currently this observer method is always called with a non-nil |newTab|, | 4533 // Currently this observer method is always called with a non-nil |newTab|, |
4545 // but that may change in the future. Remove this DCHECK when it does. | 4534 // but that may change in the future. Remove this DCHECK when it does. |
4546 DCHECK(newTab); | 4535 DCHECK(newTab); |
4547 if (_infoBarContainer.get()) { | 4536 if (_infoBarContainer) { |
4548 infobars::InfoBarManager* infoBarManager = [newTab infoBarManager]; | 4537 infobars::InfoBarManager* infoBarManager = [newTab infoBarManager]; |
4549 _infoBarContainer->ChangeInfoBarManager(infoBarManager); | 4538 _infoBarContainer->ChangeInfoBarManager(infoBarManager); |
4550 } | 4539 } |
4551 [self updateVoiceSearchBarVisibilityAnimated:NO]; | 4540 [self updateVoiceSearchBarVisibilityAnimated:NO]; |
4552 | 4541 |
4553 [_contextualSearchController setTab:newTab]; | 4542 [_contextualSearchController setTab:newTab]; |
4554 [_paymentRequestManager setWebState:newTab.webState]; | 4543 [_paymentRequestManager setWebState:newTab.webState]; |
4555 | 4544 |
4556 [self tabSelected:newTab]; | 4545 [self tabSelected:newTab]; |
4557 DCHECK_EQ(newTab, [model currentTab]); | 4546 DCHECK_EQ(newTab, [model currentTab]); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4616 // Called when the number of tabs changes. Update the toolbar accordingly. | 4605 // Called when the number of tabs changes. Update the toolbar accordingly. |
4617 - (void)tabModelDidChangeTabCount:(TabModel*)model { | 4606 - (void)tabModelDidChangeTabCount:(TabModel*)model { |
4618 DCHECK(model == _model); | 4607 DCHECK(model == _model); |
4619 [_toolbarController setTabCount:[_model count]]; | 4608 [_toolbarController setTabCount:[_model count]]; |
4620 } | 4609 } |
4621 | 4610 |
4622 #pragma mark - Upgrade Detection | 4611 #pragma mark - Upgrade Detection |
4623 | 4612 |
4624 - (void)showUpgrade:(UpgradeCenter*)center { | 4613 - (void)showUpgrade:(UpgradeCenter*)center { |
4625 // Add an infobar on all the open tabs. | 4614 // Add an infobar on all the open tabs. |
4626 for (Tab* tab in _model.get()) { | 4615 for (Tab* tab in _model) { |
4627 NSString* tabId = tab.tabId; | 4616 NSString* tabId = tab.tabId; |
4628 DCHECK([tab infoBarManager]); | 4617 DCHECK([tab infoBarManager]); |
4629 [center addInfoBarToManager:[tab infoBarManager] forTabId:tabId]; | 4618 [center addInfoBarToManager:[tab infoBarManager] forTabId:tabId]; |
4630 } | 4619 } |
4631 } | 4620 } |
4632 | 4621 |
4633 #pragma mark - ContextualSearchControllerDelegate | 4622 #pragma mark - ContextualSearchControllerDelegate |
4634 | 4623 |
4635 - (void)createTabFromContextualSearchController:(const GURL&)url { | 4624 - (void)createTabFromContextualSearchController:(const GURL&)url { |
4636 Tab* currentTab = [_model currentTab]; | 4625 Tab* currentTab = [_model currentTab]; |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5012 NSString* title = l10n_util::GetNSString(titleMessageId); | 5001 NSString* title = l10n_util::GetNSString(titleMessageId); |
5013 NSString* message = l10n_util::GetNSString(messageId); | 5002 NSString* message = l10n_util::GetNSString(messageId); |
5014 [self showErrorAlertWithStringTitle:title message:message]; | 5003 [self showErrorAlertWithStringTitle:title message:message]; |
5015 } | 5004 } |
5016 | 5005 |
5017 - (void)showErrorAlertWithStringTitle:(NSString*)title | 5006 - (void)showErrorAlertWithStringTitle:(NSString*)title |
5018 message:(NSString*)message { | 5007 message:(NSString*)message { |
5019 // Dismiss current alert. | 5008 // Dismiss current alert. |
5020 [_alertCoordinator stop]; | 5009 [_alertCoordinator stop]; |
5021 | 5010 |
5022 _alertCoordinator.reset([_dependencyFactory alertCoordinatorWithTitle:title | 5011 _alertCoordinator = [_dependencyFactory alertCoordinatorWithTitle:title |
5023 message:message | 5012 message:message |
5024 viewController:self]); | 5013 viewController:self]; |
5025 [_alertCoordinator start]; | 5014 [_alertCoordinator start]; |
5026 } | 5015 } |
5027 | 5016 |
5028 - (void)showSnackbar:(NSString*)message { | 5017 - (void)showSnackbar:(NSString*)message { |
5029 [_dependencyFactory showSnackbarWithMessage:message]; | 5018 [_dependencyFactory showSnackbarWithMessage:message]; |
5030 } | 5019 } |
5031 | 5020 |
5032 #pragma mark - Show Mail Composer methods | 5021 #pragma mark - Show Mail Composer methods |
5033 | 5022 |
5034 - (void)showMailComposer:(id)sender { | 5023 - (void)showMailComposer:(id)sender { |
5035 ShowMailComposerCommand* command = (ShowMailComposerCommand*)sender; | 5024 ShowMailComposerCommand* command = (ShowMailComposerCommand*)sender; |
5036 if (![MFMailComposeViewController canSendMail]) { | 5025 if (![MFMailComposeViewController canSendMail]) { |
5037 NSString* alertTitle = | 5026 NSString* alertTitle = |
5038 l10n_util::GetNSString([command emailNotConfiguredAlertTitleId]); | 5027 l10n_util::GetNSString([command emailNotConfiguredAlertTitleId]); |
5039 NSString* alertMessage = | 5028 NSString* alertMessage = |
5040 l10n_util::GetNSString([command emailNotConfiguredAlertMessageId]); | 5029 l10n_util::GetNSString([command emailNotConfiguredAlertMessageId]); |
5041 [self showErrorAlertWithStringTitle:alertTitle message:alertMessage]; | 5030 [self showErrorAlertWithStringTitle:alertTitle message:alertMessage]; |
5042 return; | 5031 return; |
5043 } | 5032 } |
5044 base::scoped_nsobject<MFMailComposeViewController> mailViewController( | 5033 MFMailComposeViewController* mailViewController = |
5045 [[MFMailComposeViewController alloc] init]); | 5034 [[MFMailComposeViewController alloc] init]; |
5046 [mailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; | 5035 [mailViewController setModalPresentationStyle:UIModalPresentationFormSheet]; |
5047 [mailViewController setToRecipients:[command toRecipients]]; | 5036 [mailViewController setToRecipients:[command toRecipients]]; |
5048 [mailViewController setSubject:[command subject]]; | 5037 [mailViewController setSubject:[command subject]]; |
5049 [mailViewController setMessageBody:[command body] isHTML:NO]; | 5038 [mailViewController setMessageBody:[command body] isHTML:NO]; |
5050 | 5039 |
5051 const base::FilePath& textFile = [command textFileToAttach]; | 5040 const base::FilePath& textFile = [command textFileToAttach]; |
5052 if (!textFile.empty()) { | 5041 if (!textFile.empty()) { |
5053 NSString* filename = base::SysUTF8ToNSString(textFile.value()); | 5042 NSString* filename = base::SysUTF8ToNSString(textFile.value()); |
5054 NSData* data = [NSData dataWithContentsOfFile:filename]; | 5043 NSData* data = [NSData dataWithContentsOfFile:filename]; |
5055 if (data) { | 5044 if (data) { |
(...skipping 22 matching lines...) Expand all Loading... | |
5078 - (void)productViewControllerDidFinish: | 5067 - (void)productViewControllerDidFinish: |
5079 (SKStoreProductViewController*)viewController { | 5068 (SKStoreProductViewController*)viewController { |
5080 [self dismissViewControllerAnimated:YES completion:nil]; | 5069 [self dismissViewControllerAnimated:YES completion:nil]; |
5081 } | 5070 } |
5082 | 5071 |
5083 - (void)openAppStore:(NSString*)appId { | 5072 - (void)openAppStore:(NSString*)appId { |
5084 if (![appId length]) | 5073 if (![appId length]) |
5085 return; | 5074 return; |
5086 NSDictionary* product = | 5075 NSDictionary* product = |
5087 @{SKStoreProductParameterITunesItemIdentifier : appId}; | 5076 @{SKStoreProductParameterITunesItemIdentifier : appId}; |
5088 base::scoped_nsobject<SKStoreProductViewController> storeViewController( | 5077 SKStoreProductViewController* storeViewController = |
5089 [[SKStoreProductViewController alloc] init]); | 5078 [[SKStoreProductViewController alloc] init]; |
5090 [storeViewController setDelegate:self]; | 5079 [storeViewController setDelegate:self]; |
5091 [storeViewController loadProductWithParameters:product completionBlock:nil]; | 5080 [storeViewController loadProductWithParameters:product completionBlock:nil]; |
5092 [self presentViewController:storeViewController animated:YES completion:nil]; | 5081 [self presentViewController:storeViewController animated:YES completion:nil]; |
5093 } | 5082 } |
5094 | 5083 |
5095 #pragma mark - TabDialogDelegate methods | 5084 #pragma mark - TabDialogDelegate methods |
5096 | 5085 |
5097 - (void)cancelDialogForTab:(Tab*)tab { | 5086 - (void)cancelDialogForTab:(Tab*)tab { |
5098 [self.dialogPresenter cancelDialogForWebState:tab.webState]; | 5087 [self.dialogPresenter cancelDialogForWebState:tab.webState]; |
5099 } | 5088 } |
5100 | 5089 |
5101 #pragma mark - FKFeedbackPromptDelegate methods | 5090 #pragma mark - FKFeedbackPromptDelegate methods |
5102 | 5091 |
5103 - (void)userTappedRateApp:(UIView*)view { | 5092 - (void)userTappedRateApp:(UIView*)view { |
5104 base::RecordAction(base::UserMetricsAction("IOSRateThisAppRateChosen")); | 5093 base::RecordAction(base::UserMetricsAction("IOSRateThisAppRateChosen")); |
5105 _rateThisAppDialog.reset(); | 5094 _rateThisAppDialog = nil; |
5106 } | 5095 } |
5107 | 5096 |
5108 - (void)userTappedSendFeedback:(UIView*)view { | 5097 - (void)userTappedSendFeedback:(UIView*)view { |
5109 base::RecordAction(base::UserMetricsAction("IOSRateThisAppFeedbackChosen")); | 5098 base::RecordAction(base::UserMetricsAction("IOSRateThisAppFeedbackChosen")); |
5110 _rateThisAppDialog.reset(); | 5099 _rateThisAppDialog = nil; |
5111 base::scoped_nsobject<GenericChromeCommand> command( | 5100 GenericChromeCommand* command = |
5112 [[GenericChromeCommand alloc] initWithTag:IDC_REPORT_AN_ISSUE]); | 5101 [[GenericChromeCommand alloc] initWithTag:IDC_REPORT_AN_ISSUE]; |
5113 [self chromeExecuteCommand:command]; | 5102 [self chromeExecuteCommand:command]; |
5114 } | 5103 } |
5115 | 5104 |
5116 - (void)userTappedDismiss:(UIView*)view { | 5105 - (void)userTappedDismiss:(UIView*)view { |
5117 base::RecordAction(base::UserMetricsAction("IOSRateThisAppDismissChosen")); | 5106 base::RecordAction(base::UserMetricsAction("IOSRateThisAppDismissChosen")); |
5118 _rateThisAppDialog.reset(); | 5107 _rateThisAppDialog = nil; |
5119 } | 5108 } |
5120 | 5109 |
5121 #pragma mark - VoiceSearchBarDelegate | 5110 #pragma mark - VoiceSearchBarDelegate |
5122 | 5111 |
5123 - (BOOL)isTTSEnabledForVoiceSearchBar:(id<VoiceSearchBar>)voiceSearchBar { | 5112 - (BOOL)isTTSEnabledForVoiceSearchBar:(id<VoiceSearchBar>)voiceSearchBar { |
5124 DCHECK_EQ(_voiceSearchBar.get(), voiceSearchBar); | 5113 DCHECK_EQ(_voiceSearchBar, voiceSearchBar); |
5125 [self ensureVoiceSearchControllerCreated]; | 5114 [self ensureVoiceSearchControllerCreated]; |
5126 return _voiceSearchController->IsTextToSpeechEnabled() && | 5115 return _voiceSearchController->IsTextToSpeechEnabled() && |
5127 _voiceSearchController->IsTextToSpeechSupported(); | 5116 _voiceSearchController->IsTextToSpeechSupported(); |
5128 } | 5117 } |
5129 | 5118 |
5130 - (void)voiceSearchBarDidUpdateButtonState:(id<VoiceSearchBar>)voiceSearchBar { | 5119 - (void)voiceSearchBarDidUpdateButtonState:(id<VoiceSearchBar>)voiceSearchBar { |
5131 DCHECK_EQ(_voiceSearchBar.get(), voiceSearchBar); | 5120 DCHECK_EQ(_voiceSearchBar, voiceSearchBar); |
5132 [self.tabModel.currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 5121 [self.tabModel.currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
5133 } | 5122 } |
5134 | 5123 |
5135 #pragma mark - VoiceSearchPresenter | 5124 #pragma mark - VoiceSearchPresenter |
5136 | 5125 |
5137 - (UIView*)voiceSearchButton { | 5126 - (UIView*)voiceSearchButton { |
5138 return _voiceSearchButton; | 5127 return _voiceSearchButton; |
5139 } | 5128 } |
5140 | 5129 |
5141 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { | 5130 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { |
5142 return [self currentLogoAnimationControllerOwner]; | 5131 return [self currentLogoAnimationControllerOwner]; |
5143 } | 5132 } |
5144 | 5133 |
5145 @end | 5134 @end |
OLD | NEW |