-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
overflow_menu_mediator.mm
1864 lines (1589 loc) · 68.5 KB
/
overflow_menu_mediator.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/overflow_menu_mediator.h"
#import "base/ios/ios_util.h"
#import "base/metrics/histogram_functions.h"
#import "base/metrics/user_metrics.h"
#import "base/metrics/user_metrics_action.h"
#import "base/strings/sys_string_conversions.h"
#import "base/strings/utf_string_conversions.h"
#import "components/bookmarks/browser/bookmark_model.h"
#import "components/bookmarks/common/bookmark_pref_names.h"
#import "components/feature_engagement/public/event_constants.h"
#import "components/feature_engagement/public/feature_constants.h"
#import "components/feature_engagement/public/tracker.h"
#import "components/language/ios/browser/ios_language_detection_tab_helper.h"
#import "components/language/ios/browser/ios_language_detection_tab_helper_observer_bridge.h"
#import "components/prefs/ios/pref_observer_bridge.h"
#import "components/prefs/pref_change_registrar.h"
#import "components/prefs/pref_service.h"
#import "components/profile_metrics/browser_profile_type.h"
#import "components/translate/core/browser/translate_manager.h"
#import "components/translate/core/browser/translate_prefs.h"
#import "ios/chrome/browser/bookmarks/bookmark_model_bridge_observer.h"
#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/commerce/push_notification/push_notification_feature.h"
#import "ios/chrome/browser/find_in_page/abstract_find_tab_helper.h"
#import "ios/chrome/browser/flags/system_flags.h"
#import "ios/chrome/browser/follow/follow_browser_agent.h"
#import "ios/chrome/browser/follow/follow_menu_updater.h"
#import "ios/chrome/browser/follow/follow_tab_helper.h"
#import "ios/chrome/browser/follow/follow_util.h"
#import "ios/chrome/browser/ntp/features.h"
#import "ios/chrome/browser/overlays/public/overlay_presenter.h"
#import "ios/chrome/browser/overlays/public/overlay_presenter_observer_bridge.h"
#import "ios/chrome/browser/overlays/public/overlay_request.h"
#import "ios/chrome/browser/policy/browser_policy_connector_ios.h"
#import "ios/chrome/browser/policy/policy_util.h"
#import "ios/chrome/browser/reading_list/offline_url_utils.h"
#import "ios/chrome/browser/translate/chrome_ios_translate_client.h"
#import "ios/chrome/browser/ui/commands/activity_service_commands.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/bookmarks_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/browser_coordinator_commands.h"
#import "ios/chrome/browser/ui/commands/find_in_page_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/commands/page_info_commands.h"
#import "ios/chrome/browser/ui/commands/price_notifications_commands.h"
#import "ios/chrome/browser/ui/commands/reading_list_add_command.h"
#import "ios/chrome/browser/ui/commands/text_zoom_commands.h"
#import "ios/chrome/browser/ui/default_promo/default_browser_utils.h"
#import "ios/chrome/browser/ui/icons/symbols.h"
#import "ios/chrome/browser/ui/ntp/metrics/feed_metrics_recorder.h"
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/destination_usage_history/destination_usage_history.h"
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/feature_flags.h"
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/overflow_menu_constants.h"
#import "ios/chrome/browser/ui/popup_menu/overflow_menu/overflow_menu_swift.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_utils.h"
#import "ios/chrome/browser/ui/sharing/activity_services/activity_params.h"
#import "ios/chrome/browser/ui/sharing/activity_services/canonical_url_retriever.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/pinned_tabs/features.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/ui/whats_new/whats_new_util.h"
#import "ios/chrome/browser/url/chrome_url_constants.h"
#import "ios/chrome/browser/web/font_size/font_size_tab_helper.h"
#import "ios/chrome/browser/web/web_navigation_browser_agent.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
#import "ios/chrome/browser/window_activities/window_activity_helpers.h"
#import "ios/chrome/grit/ios_strings.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_api.h"
#import "ios/web/common/user_agent.h"
#import "ios/web/public/js_messaging/web_frame.h"
#import "ios/web/public/js_messaging/web_frame_util.h"
#import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/navigation/navigation_manager.h"
#import "ios/web/public/web_client.h"
#import "ios/web/public/web_state.h"
#import "ios/web/public/web_state_observer_bridge.h"
#import "ui/base/l10n/l10n_util.h"
#import "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using base::RecordAction;
using base::UmaHistogramEnumeration;
using base::UserMetricsAction;
using experimental_flags::IsSpotlightDebuggingEnabled;
namespace {
typedef void (^Handler)(void);
OverflowMenuAction* CreateOverflowMenuActionWithString(
NSString* name,
NSString* imageName,
NSString* accessibilityID,
Handler handler) {
DCHECK(!UseSymbols());
return [[OverflowMenuAction alloc] initWithName:name
image:[UIImage imageNamed:imageName]
accessibilityIdentifier:accessibilityID
enterpriseDisabled:NO
handler:handler];
}
OverflowMenuAction* CreateOverflowMenuAction(int nameID,
NSString* imageName,
NSString* accessibilityID,
Handler handler) {
DCHECK(!UseSymbols());
NSString* name = l10n_util::GetNSString(nameID);
return CreateOverflowMenuActionWithString(name, imageName, accessibilityID,
handler);
}
OverflowMenuAction* CreateOverflowMenuActionWithString(
NSString* name,
NSString* symbolName,
bool systemSymbol,
bool monochromeSymbol,
NSString* accessibilityID,
Handler handler) {
DCHECK(UseSymbols());
return [[OverflowMenuAction alloc] initWithName:name
symbolName:symbolName
systemSymbol:systemSymbol
monochromeSymbol:monochromeSymbol
accessibilityIdentifier:accessibilityID
enterpriseDisabled:NO
handler:handler];
}
OverflowMenuAction* CreateOverflowMenuAction(int nameID,
NSString* symbolName,
bool systemSymbol,
bool monochromeSymbol,
NSString* accessibilityID,
Handler handler) {
DCHECK(UseSymbols());
NSString* name = l10n_util::GetNSString(nameID);
return CreateOverflowMenuActionWithString(name, symbolName, systemSymbol,
monochromeSymbol, accessibilityID,
handler);
}
OverflowMenuFooter* CreateOverflowMenuManagedFooter(int nameID,
int linkID,
NSString* imageName,
Handler handler) {
NSString* name = l10n_util::GetNSString(nameID);
NSString* link = l10n_util::GetNSString(linkID);
return [[OverflowMenuFooter alloc] initWithName:name
link:link
image:[UIImage imageNamed:imageName]
accessibilityIdentifier:kTextMenuEnterpriseInfo
handler:handler];
}
} // namespace
@interface OverflowMenuMediator () <BookmarkModelBridgeObserver,
CRWWebStateObserver,
FollowMenuUpdater,
IOSLanguageDetectionTabHelperObserving,
OverlayPresenterObserving,
PrefObserverDelegate,
WebStateListObserving> {
std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
// Observer for the content area overlay events
std::unique_ptr<OverlayPresenterObserver> _overlayPresenterObserver;
// Bridge to register for bookmark changes.
std::unique_ptr<BookmarkModelBridge> _bookmarkModelBridge;
// Bridge to get notified of the language detection event.
std::unique_ptr<language::IOSLanguageDetectionTabHelperObserverBridge>
_iOSLanguageDetectionTabHelperObserverBridge;
// Pref observer to track changes to prefs.
std::unique_ptr<PrefObserverBridge> _prefObserverBridge;
// Registrar for pref changes notifications.
std::unique_ptr<PrefChangeRegistrar> _prefChangeRegistrar;
}
// The destination usage history, which (1) tracks which items from the carousel
// are clicked, and (2) suggests a sorted order for carousel menu items.
@property(nonatomic, strong) DestinationUsageHistory* destinationUsageHistory;
// The current web state.
@property(nonatomic, assign) web::WebState* webState;
// Whether an overlay is currently presented over the web content area.
@property(nonatomic, assign) BOOL webContentAreaShowingOverlay;
// Whether the web content is currently being blocked.
@property(nonatomic, assign) BOOL contentBlocked;
@property(nonatomic, strong) OverflowMenuDestination* bookmarksDestination;
@property(nonatomic, strong) OverflowMenuDestination* downloadsDestination;
@property(nonatomic, strong) OverflowMenuDestination* historyDestination;
@property(nonatomic, strong) OverflowMenuDestination* passwordsDestination;
@property(nonatomic, strong) OverflowMenuDestination* readingListDestination;
@property(nonatomic, strong) OverflowMenuDestination* recentTabsDestination;
@property(nonatomic, strong) OverflowMenuDestination* settingsDestination;
@property(nonatomic, strong) OverflowMenuDestination* siteInfoDestination;
@property(nonatomic, strong) OverflowMenuDestination* whatsNewDestination;
@property(nonatomic, strong)
OverflowMenuDestination* spotlightDebuggerDestination;
@property(nonatomic, strong) OverflowMenuActionGroup* appActionsGroup;
@property(nonatomic, strong) OverflowMenuActionGroup* pageActionsGroup;
@property(nonatomic, strong) OverflowMenuActionGroup* helpActionsGroup;
@property(nonatomic, strong) OverflowMenuAction* reloadAction;
@property(nonatomic, strong) OverflowMenuAction* stopLoadAction;
@property(nonatomic, strong) OverflowMenuAction* openTabAction;
@property(nonatomic, strong) OverflowMenuAction* openIncognitoTabAction;
@property(nonatomic, strong) OverflowMenuAction* openNewWindowAction;
@property(nonatomic, strong) OverflowMenuAction* pinTabAction;
@property(nonatomic, strong) OverflowMenuAction* unpinTabAction;
@property(nonatomic, strong) OverflowMenuAction* clearBrowsingDataAction;
@property(nonatomic, strong) OverflowMenuAction* followAction;
@property(nonatomic, strong) OverflowMenuAction* addBookmarkAction;
@property(nonatomic, strong) OverflowMenuAction* editBookmarkAction;
@property(nonatomic, strong) OverflowMenuAction* readLaterAction;
@property(nonatomic, strong) OverflowMenuAction* openPriceNotificationsAction;
@property(nonatomic, strong) OverflowMenuAction* translateAction;
@property(nonatomic, strong) OverflowMenuAction* requestDesktopAction;
@property(nonatomic, strong) OverflowMenuAction* requestMobileAction;
@property(nonatomic, strong) OverflowMenuAction* findInPageAction;
@property(nonatomic, strong) OverflowMenuAction* textZoomAction;
@property(nonatomic, strong) OverflowMenuAction* reportIssueAction;
@property(nonatomic, strong) OverflowMenuAction* helpAction;
@property(nonatomic, strong) OverflowMenuAction* shareChromeAction;
@end
@implementation OverflowMenuMediator
@synthesize overflowMenuModel = _overflowMenuModel;
- (instancetype)init {
self = [super init];
if (self) {
_webStateObserver = std::make_unique<web::WebStateObserverBridge>(self);
_webStateListObserver = std::make_unique<WebStateListObserverBridge>(self);
_overlayPresenterObserver =
std::make_unique<OverlayPresenterObserverBridge>(self);
}
return self;
}
- (void)disconnect {
// Remove the model link so the other deallocations don't update the model
// and thus the UI as the UI is dismissing.
_overflowMenuModel = nil;
self.webContentAreaOverlayPresenter = nullptr;
if (_engagementTracker) {
if (self.readingListDestination.badge != BadgeTypeNone) {
_engagementTracker->Dismissed(
feature_engagement::kIPHBadgedReadingListFeature);
}
_engagementTracker = nullptr;
}
if (self.webState && self.followAction) {
FollowTabHelper* followTabHelper =
FollowTabHelper::FromWebState(self.webState);
if (followTabHelper) {
followTabHelper->RemoveFollowMenuUpdater();
}
}
self.followBrowserAgent = nullptr;
[self.destinationUsageHistory disconnect];
self.destinationUsageHistory = nil;
self.webState = nullptr;
self.webStateList = nullptr;
self.bookmarkModel = nullptr;
self.browserStatePrefs = nullptr;
self.localStatePrefs = nullptr;
}
#pragma mark - Property getters/setters
- (OverflowMenuModel*)overflowMenuModel {
if (!_overflowMenuModel) {
_overflowMenuModel = [self createModel];
[self updateModel];
}
return _overflowMenuModel;
}
- (void)setIsIncognito:(BOOL)isIncognito {
_isIncognito = isIncognito;
[self updateModel];
}
- (void)setWebState:(web::WebState*)webState {
if (_webState) {
_webState->RemoveObserver(_webStateObserver.get());
}
_webState = webState;
if (_webState) {
[self updateModel];
_webState->AddObserver(_webStateObserver.get());
// Observe the language::IOSLanguageDetectionTabHelper for `_webState`.
_iOSLanguageDetectionTabHelperObserverBridge =
std::make_unique<language::IOSLanguageDetectionTabHelperObserverBridge>(
language::IOSLanguageDetectionTabHelper::FromWebState(_webState),
self);
}
}
- (void)setWebStateList:(WebStateList*)webStateList {
if (_webStateList) {
_webStateList->RemoveObserver(_webStateListObserver.get());
_iOSLanguageDetectionTabHelperObserverBridge.reset();
}
_webStateList = webStateList;
self.webState = (_webStateList) ? _webStateList->GetActiveWebState() : nil;
if (self.webState) {
FollowTabHelper* followTabHelper =
FollowTabHelper::FromWebState(self.webState);
if (followTabHelper) {
followTabHelper->SetFollowMenuUpdater(self);
}
}
if (_webStateList) {
_webStateList->AddObserver(_webStateListObserver.get());
}
}
- (void)setBookmarkModel:(bookmarks::BookmarkModel*)bookmarkModel {
_bookmarkModelBridge.reset();
_bookmarkModel = bookmarkModel;
if (bookmarkModel) {
_bookmarkModelBridge =
std::make_unique<BookmarkModelBridge>(self, bookmarkModel);
}
[self updateModel];
}
- (void)setBrowserStatePrefs:(PrefService*)browserStatePrefs {
_prefObserverBridge.reset();
_prefChangeRegistrar.reset();
_browserStatePrefs = browserStatePrefs;
if (_browserStatePrefs) {
_prefChangeRegistrar = std::make_unique<PrefChangeRegistrar>();
_prefChangeRegistrar->Init(browserStatePrefs);
_prefObserverBridge.reset(new PrefObserverBridge(self));
_prefObserverBridge->ObserveChangesForPreference(
bookmarks::prefs::kEditBookmarksEnabled, _prefChangeRegistrar.get());
}
}
- (void)setLocalStatePrefs:(PrefService*)localStatePrefs {
_localStatePrefs = localStatePrefs;
if (!self.isIncognito) {
_destinationUsageHistory =
[[DestinationUsageHistory alloc] initWithPrefService:localStatePrefs];
}
}
- (void)setEngagementTracker:(feature_engagement::Tracker*)engagementTracker {
_engagementTracker = engagementTracker;
if (!engagementTracker) {
return;
}
[self updateModel];
}
- (void)setWebContentAreaOverlayPresenter:
(OverlayPresenter*)webContentAreaOverlayPresenter {
if (_webContentAreaOverlayPresenter) {
_webContentAreaOverlayPresenter->RemoveObserver(
_overlayPresenterObserver.get());
self.webContentAreaShowingOverlay = NO;
}
_webContentAreaOverlayPresenter = webContentAreaOverlayPresenter;
if (_webContentAreaOverlayPresenter) {
_webContentAreaOverlayPresenter->AddObserver(
_overlayPresenterObserver.get());
self.webContentAreaShowingOverlay =
_webContentAreaOverlayPresenter->IsShowingOverlayUI();
}
}
- (void)setWebContentAreaShowingOverlay:(BOOL)webContentAreaShowingOverlay {
if (_webContentAreaShowingOverlay == webContentAreaShowingOverlay)
return;
_webContentAreaShowingOverlay = webContentAreaShowingOverlay;
[self updateModel];
}
#pragma mark - Model Creation
- (OverflowMenuModel*)createModel {
__weak __typeof(self) weakSelf = self;
if (UseSymbols()) {
// Bookmarks destination.
self.bookmarksDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_BOOKMARKS
destination:overflow_menu::Destination::Bookmarks
symbolName:kBookmarksSymbol
systemSymbol:YES
accessibilityID:kToolsMenuBookmarksId
handler:^{
[weakSelf openBookmarks];
}];
} else {
// Bookmarks destination.
self.bookmarksDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_BOOKMARKS
destination:overflow_menu::Destination::Bookmarks
imageName:@"overflow_menu_destination_bookmarks"
accessibilityID:kToolsMenuBookmarksId
handler:^{
[weakSelf openBookmarks];
}];
}
if (UseSymbols()) {
// Downloads destination.
self.downloadsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_DOWNLOADS
destination:overflow_menu::Destination::Downloads
symbolName:kDownloadSymbol
systemSymbol:YES
accessibilityID:kToolsMenuDownloadsId
handler:^{
[weakSelf openDownloads];
}];
} else {
// Downloads destination.
self.downloadsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_DOWNLOADS
destination:overflow_menu::Destination::Downloads
imageName:@"overflow_menu_destination_downloads"
accessibilityID:kToolsMenuDownloadsId
handler:^{
[weakSelf openDownloads];
}];
}
if (UseSymbols()) {
// History destination.
self.historyDestination =
[self createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_HISTORY
destination:overflow_menu::Destination::History
symbolName:kHistorySymbol
systemSymbol:YES
accessibilityID:kToolsMenuHistoryId
handler:^{
[weakSelf openHistory];
}];
} else {
// History destination.
self.historyDestination =
[self createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_HISTORY
destination:overflow_menu::Destination::History
imageName:@"overflow_menu_destination_history"
accessibilityID:kToolsMenuHistoryId
handler:^{
[weakSelf openHistory];
}];
}
if (UseSymbols()) {
// Passwords destination.
self.passwordsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_PASSWORD_MANAGER
destination:overflow_menu::Destination::Passwords
symbolName:kPasswordSymbol
systemSymbol:NO
accessibilityID:kToolsMenuPasswordsId
handler:^{
[weakSelf openPasswords];
}];
} else {
// Passwords destination.
self.passwordsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_PASSWORD_MANAGER
destination:overflow_menu::Destination::Passwords
imageName:@"overflow_menu_destination_passwords"
accessibilityID:kToolsMenuPasswordsId
handler:^{
[weakSelf openPasswords];
}];
}
if (UseSymbols()) {
// Reading List destination.
self.readingListDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_READING_LIST
destination:overflow_menu::Destination::ReadingList
symbolName:kReadingListSymbol
systemSymbol:NO
accessibilityID:kToolsMenuReadingListId
handler:^{
[weakSelf openReadingList];
}];
} else {
// Reading List destination.
self.readingListDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_READING_LIST
destination:overflow_menu::Destination::ReadingList
imageName:@"overflow_menu_destination_reading_list"
accessibilityID:kToolsMenuReadingListId
handler:^{
[weakSelf openReadingList];
}];
}
if (UseSymbols()) {
// Recent Tabs destination.
self.recentTabsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_RECENT_TABS
destination:overflow_menu::Destination::RecentTabs
symbolName:kRecentTabsSymbol
systemSymbol:NO
accessibilityID:kToolsMenuOtherDevicesId
handler:^{
[weakSelf openRecentTabs];
}];
} else {
// Recent Tabs destination.
self.recentTabsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_RECENT_TABS
destination:overflow_menu::Destination::RecentTabs
imageName:@"overflow_menu_destination_recent_tabs"
accessibilityID:kToolsMenuOtherDevicesId
handler:^{
[weakSelf openRecentTabs];
}];
}
if (UseSymbols()) {
// Settings destination.
self.settingsDestination =
[self createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_SETTINGS
destination:overflow_menu::Destination::Settings
symbolName:kSettingsSymbol
systemSymbol:YES
accessibilityID:kToolsMenuSettingsId
handler:^{
[weakSelf openSettings];
}];
} else {
// Settings destination.
self.settingsDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_SETTINGS
destination:overflow_menu::Destination::Settings
imageName:@"overflow_menu_destination_settings"
accessibilityID:kToolsMenuSettingsId
handler:^{
[weakSelf openSettings];
}];
}
self.spotlightDebuggerDestination = [self destinationForSpotlightDebugger:^{
[weakSelf openSpotlightDebugger];
}];
if (UseSymbols()) {
// WhatsNew destination.
self.whatsNewDestination = [self
createOverflowMenuDestination:IDS_IOS_CONTENT_SUGGESTIONS_WHATS_NEW
destination:overflow_menu::Destination::WhatsNew
symbolName:kCheckmarkSealSymbol
systemSymbol:YES
accessibilityID:kToolsMenuWhatsNewId
handler:^{
[weakSelf openWhatsNew];
}];
} else {
// WhatsNew destination.
self.whatsNewDestination = [self
createOverflowMenuDestination:IDS_IOS_CONTENT_SUGGESTIONS_WHATS_NEW
destination:overflow_menu::Destination::WhatsNew
imageName:@"overflow_menu_destination_whats_new"
accessibilityID:kToolsMenuWhatsNewId
handler:^{
[weakSelf openWhatsNew];
}];
}
if (UseSymbols()) {
// Site Info destination.
self.siteInfoDestination =
[self createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_SITE_INFORMATION
destination:overflow_menu::Destination::SiteInfo
symbolName:kInfoCircleSymbol
systemSymbol:YES
accessibilityID:kToolsMenuSiteInformation
handler:^{
[weakSelf openSiteInformation];
}];
} else {
// Site Info destination.
self.siteInfoDestination = [self
createOverflowMenuDestination:IDS_IOS_TOOLS_MENU_SITE_INFORMATION
destination:overflow_menu::Destination::SiteInfo
imageName:@"overflow_menu_destination_site_info"
accessibilityID:kToolsMenuSiteInformation
handler:^{
[weakSelf openSiteInformation];
}];
}
[self logTranslateAvailability];
if (UseSymbols()) {
self.reloadAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_RELOAD, kArrowClockWiseSymbol, /*systemSymbol=*/NO,
/*monochromeSymbol=*/NO, kToolsMenuReload, ^{
[weakSelf reload];
});
self.stopLoadAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_STOP, kXMarkSymbol, /*systemSymbol=*/YES,
/*monochromeSymbol=*/NO, kToolsMenuStop, ^{
[weakSelf stopLoading];
});
self.openTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_NEW_TAB, kNewTabCircleActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuNewTabId, ^{
[weakSelf openTab];
});
self.openIncognitoTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kIncognitoSymbol,
/*systemSymbol=*/NO, /*monochromeSymbol=*/NO,
kToolsMenuNewIncognitoTabId, ^{
[weakSelf openIncognitoTab];
});
self.openNewWindowAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_NEW_WINDOW, kNewWindowActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuNewWindowId, ^{
[weakSelf openNewWindow];
});
self.pinTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_PIN_TAB, kPinSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuPinTabId, ^{
[weakSelf pinTab];
});
self.unpinTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_UNPIN_TAB, kPinSlashSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuUnpinTabId, ^{
[weakSelf unpinTab];
});
self.clearBrowsingDataAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_CLEAR_BROWSING_DATA, kTrashSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO,
kToolsMenuClearBrowsingData, ^{
[weakSelf openClearBrowsingData];
});
if (GetFollowActionState(self.webState) != FollowActionStateHidden) {
OverflowMenuAction* action = CreateOverflowMenuActionWithString(
l10n_util::GetNSStringF(IDS_IOS_TOOLS_MENU_FOLLOW, u""), kPlusSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuFollow,
^{
});
action.enabled = NO;
self.followAction = action;
}
self.addBookmarkAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_ADD_TO_BOOKMARKS, kAddBookmarkActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuAddToBookmarks,
^{
[weakSelf addOrEditBookmark];
});
self.editBookmarkAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_EDIT_BOOKMARK, kEditActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuEditBookmark,
^{
[weakSelf addOrEditBookmark];
});
self.readLaterAction = CreateOverflowMenuAction(
IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST, kReadLaterActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuReadLater, ^{
[weakSelf addToReadingList];
});
self.openPriceNotificationsAction = CreateOverflowMenuAction(
IDS_IOS_PRICE_NOTIFICATIONS_OVERFLOW_MENU_TITLE, kDownTrendSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO,
kToolsMenuPriceNotifications, ^{
[weakSelf openPriceNotifications];
});
self.translateAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_TRANSLATE, kTranslateSymbol,
/*systemSymbol=*/NO, /*monochromeSymbol=*/NO, kToolsMenuTranslateId, ^{
[weakSelf translatePage];
});
self.requestDesktopAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kDesktopSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/YES,
kToolsMenuRequestDesktopId, ^{
[weakSelf requestDesktopSite];
});
self.requestMobileAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE, kIPhoneSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/YES,
kToolsMenuRequestMobileId, ^{
[weakSelf requestMobileSite];
});
self.findInPageAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kFindInPageActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuFindInPageId,
^{
[weakSelf openFindInPage];
});
self.textZoomAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_TEXT_ZOOM, kZoomTextActionSymbol,
/*systemSymbol=*/YES, /*monochromeSymbol=*/NO, kToolsMenuTextZoom, ^{
[weakSelf openTextZoom];
});
self.reportIssueAction = CreateOverflowMenuAction(
IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kWarningSymbol, /*systemSymbol=*/YES,
/*monochromeSymbol=*/NO, kToolsMenuReportAnIssueId, ^{
[weakSelf reportAnIssue];
});
self.helpAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_HELP_MOBILE, kHelpSymbol, /*systemSymbol=*/YES,
/*monochromeSymbol=*/NO, kToolsMenuHelpId, ^{
[weakSelf openHelp];
});
self.shareChromeAction = CreateOverflowMenuAction(
IDS_IOS_OVERFLOW_MENU_SHARE_CHROME, kShareSymbol, /*systemSymbol=*/YES,
/*monochromeSymbol=*/NO, kToolsMenuShareChromeId, ^{
[weakSelf shareChromeApp];
});
} else {
self.reloadAction = CreateOverflowMenuAction(IDS_IOS_TOOLS_MENU_RELOAD,
@"overflow_menu_action_reload",
kToolsMenuReload, ^{
[weakSelf reload];
});
self.stopLoadAction = CreateOverflowMenuAction(IDS_IOS_TOOLS_MENU_STOP,
@"overflow_menu_action_stop",
kToolsMenuStop, ^{
[weakSelf stopLoading];
});
self.openTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_NEW_TAB, @"overflow_menu_action_new_tab",
kToolsMenuNewTabId, ^{
[weakSelf openTab];
});
self.openIncognitoTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, @"overflow_menu_action_incognito",
kToolsMenuNewIncognitoTabId, ^{
[weakSelf openIncognitoTab];
});
self.openNewWindowAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_NEW_WINDOW, @"overflow_menu_action_new_window",
kToolsMenuNewWindowId, ^{
[weakSelf openNewWindow];
});
self.pinTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_PIN_TAB, @"overflow_menu_action_pin_tab",
kToolsMenuPinTabId, ^{
[weakSelf pinTab];
});
self.unpinTabAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_UNPIN_TAB, @"overflow_menu_action_unpin_tab",
kToolsMenuUnpinTabId, ^{
[weakSelf unpinTab];
});
self.clearBrowsingDataAction =
CreateOverflowMenuAction(IDS_IOS_TOOLS_MENU_CLEAR_BROWSING_DATA,
@"overflow_menu_action_clear_browsing_data",
kToolsMenuClearBrowsingData, ^{
[weakSelf openClearBrowsingData];
});
self.followAction = [self createFollowActionIfNeeded];
self.addBookmarkAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_ADD_TO_BOOKMARKS, @"overflow_menu_action_bookmark",
kToolsMenuAddToBookmarks, ^{
[weakSelf addOrEditBookmark];
});
self.editBookmarkAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_EDIT_BOOKMARK, @"overflow_menu_action_edit_bookmark",
kToolsMenuEditBookmark, ^{
[weakSelf addOrEditBookmark];
});
self.readLaterAction = CreateOverflowMenuAction(
IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST,
@"overflow_menu_action_read_later", kToolsMenuReadLater, ^{
[weakSelf addToReadingList];
});
self.openPriceNotificationsAction = CreateOverflowMenuAction(
IDS_IOS_PRICE_NOTIFICATIONS_OVERFLOW_MENU_TITLE,
@"overflow_menu_action_price_notifications",
kToolsMenuPriceNotifications, ^{
[weakSelf openPriceNotifications];
});
self.translateAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_TRANSLATE, @"overflow_menu_action_translate",
kToolsMenuTranslateId, ^{
[weakSelf translatePage];
});
self.requestDesktopAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE,
@"overflow_menu_action_request_desktop", kToolsMenuRequestDesktopId, ^{
[weakSelf requestDesktopSite];
});
self.requestMobileAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE,
@"overflow_menu_action_request_mobile", kToolsMenuRequestMobileId, ^{
[weakSelf requestMobileSite];
});
self.findInPageAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, @"overflow_menu_action_find_in_page",
kToolsMenuFindInPageId, ^{
[weakSelf openFindInPage];
});
self.textZoomAction = CreateOverflowMenuAction(
IDS_IOS_TOOLS_MENU_TEXT_ZOOM, @"overflow_menu_action_text_zoom",
kToolsMenuTextZoom, ^{
[weakSelf openTextZoom];
});
self.reportIssueAction = CreateOverflowMenuAction(
IDS_IOS_OPTIONS_REPORT_AN_ISSUE, @"overflow_menu_action_report_issue",
kToolsMenuReportAnIssueId, ^{
[weakSelf reportAnIssue];
});
self.helpAction = CreateOverflowMenuAction(IDS_IOS_TOOLS_MENU_HELP_MOBILE,
@"overflow_menu_action_help",
kToolsMenuHelpId, ^{
[weakSelf openHelp];
});
self.shareChromeAction = CreateOverflowMenuAction(
IDS_IOS_OVERFLOW_MENU_SHARE_CHROME,
@"overflow_menu_action_share_chrome", kToolsMenuShareChromeId, ^{
[weakSelf shareChromeApp];
});
}
// The app actions vary based on page state, so they are set in
// `-updateModel`.
self.appActionsGroup =
[[OverflowMenuActionGroup alloc] initWithGroupName:@"app_actions"
actions:@[]
footer:nil];
// The page actions vary based on page state, so they are set in
// `-updateModel`.
self.pageActionsGroup =
[[OverflowMenuActionGroup alloc] initWithGroupName:@"page_actions"
actions:@[]
footer:nil];
// Footer and actions vary based on state, so they're set in -updateModel.
self.helpActionsGroup =
[[OverflowMenuActionGroup alloc] initWithGroupName:@"help_actions"
actions:@[]
footer:nil];
// Destinations and footer vary based on state, so they're set in
// -updateModel.
return [[OverflowMenuModel alloc] initWithDestinations:@[]
actionGroups:@[
self.appActionsGroup,
self.pageActionsGroup,
self.helpActionsGroup,
]];
}
#pragma mark - Private
// Creates an OverflowMenuDestination to be displayed in the destinations
// carousel.
- (OverflowMenuDestination*)
createOverflowMenuDestination:(int)nameID
destination:(overflow_menu::Destination)destination
symbolName:(NSString*)symbolName
systemSymbol:(BOOL)systemSymbol
accessibilityID:(NSString*)accessibilityID
handler:(Handler)handler {
DCHECK(UseSymbols());
__weak __typeof(self) weakSelf = self;
NSString* name = l10n_util::GetNSString(nameID);
auto handlerWithMetrics = ^{
overflow_menu::RecordUmaActionForDestination(destination);
if (IsSmartSortingNewOverflowMenuEnabled()) {
[weakSelf.destinationUsageHistory
trackDestinationClick:destination
numAboveFoldDestinations:weakSelf.numAboveFoldDestinations];
}
handler();
};
OverflowMenuDestination* result =
[[OverflowMenuDestination alloc] initWithName:name
symbolName:symbolName
systemSymbol:systemSymbol
monochromeSymbol:NO
accessibilityIdentifier:accessibilityID
enterpriseDisabled:NO
handler:handlerWithMetrics];
result.destinationName = base::SysUTF8ToNSString(
overflow_menu::StringNameForDestination(destination));
return result;
}
// Creates an OverflowMenuDestination to be displayed in the destinations
// carousel.
- (OverflowMenuDestination*)
createOverflowMenuDestination:(int)nameID
destination:(overflow_menu::Destination)destination
imageName:(NSString*)imageName
accessibilityID:(NSString*)accessibilityID
handler:(Handler)handler {
DCHECK(!UseSymbols());
__weak __typeof(self) weakSelf = self;
NSString* name = l10n_util::GetNSString(nameID);
auto handlerWithMetrics = ^{
overflow_menu::RecordUmaActionForDestination(destination);