forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser_view.cc
5328 lines (4600 loc) · 200 KB
/
browser_view.cc
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 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/browser_view.h"
#include <stdint.h>
#include <memory>
#include <set>
#include <utility>
#include "base/auto_reset.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/download/bubble/download_bubble_prefs.h"
#include "chrome/browser/extensions/browser_extension_window_controller.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/feature_engagement/tracker_factory.h"
#include "chrome/browser/headless/headless_mode_util.h"
#include "chrome/browser/native_window_notification_source.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/segmentation_platform/segmentation_platform_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/sharing_hub/sharing_hub_features.h"
#include "chrome/browser/signin/chrome_signin_helper.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/autofill/autofill_bubble_base.h"
#include "chrome/browser/ui/autofill/payments/save_card_ui.h"
#include "chrome/browser/ui/bookmarks/bookmark_stats.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window_state.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/performance_controls/high_efficiency_opt_in_iph_controller.h"
#include "chrome/browser/ui/qrcode_generator/qrcode_generator_bubble_controller.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/browser/ui/sad_tab_helper.h"
#include "chrome/browser/ui/sharing_hub/sharing_hub_bubble_controller.h"
#include "chrome/browser/ui/sharing_hub/sharing_hub_bubble_view.h"
#include "chrome/browser/ui/side_panel/side_panel_ui.h"
#include "chrome/browser/ui/side_search/side_search_utils.h"
#include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h"
#include "chrome/browser/ui/sync/one_click_signin_links_delegate_impl.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/accelerator_table.h"
#include "chrome/browser/ui/views/accessibility/accessibility_focus_highlight.h"
#include "chrome/browser/ui/views/accessibility/caret_browsing_dialog_delegate.h"
#include "chrome/browser/ui/views/autofill/autofill_bubble_handler_impl.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
#include "chrome/browser/ui/views/color_provider_browser_helper.h"
#include "chrome/browser/ui/views/download/bubble/download_toolbar_button_view.h"
#include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
#include "chrome/browser/ui/views/download/download_shelf_view.h"
#include "chrome/browser/ui/views/exclusive_access_bubble_views.h"
#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/eye_dropper/eye_dropper.h"
#include "chrome/browser/ui/views/find_bar_host.h"
#include "chrome/browser/ui/views/frame/app_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_actions.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
#include "chrome/browser/ui/views/frame/contents_layout_manager.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/frame/native_browser_frame.h"
#include "chrome/browser/ui/views/frame/tab_strip_region_view.h"
#include "chrome/browser/ui/views/frame/top_container_loading_bar.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/frame/web_contents_close_handler.h"
#include "chrome/browser/ui/views/fullscreen_control/fullscreen_control_host.h"
#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_view.h"
#include "chrome/browser/ui/views/hats/hats_next_web_dialog.h"
#include "chrome/browser/ui/views/incognito_clear_browsing_data_dialog_coordinator.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/location_bar/intent_chip_button.h"
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/star_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "chrome/browser/ui/views/profiles/avatar_toolbar_button.h"
#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
#include "chrome/browser/ui/views/profiles/profile_menu_coordinator.h"
#include "chrome/browser/ui/views/qrcode_generator/qrcode_generator_bubble.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_bubble_view.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_device_picker_bubble_view.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_icon_view.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_promo_bubble_view.h"
#include "chrome/browser/ui/views/sharing/sharing_dialog_view.h"
#include "chrome/browser/ui/views/sharing_hub/screenshot/screenshot_captured_bubble.h"
#include "chrome/browser/ui/views/sharing_hub/sharing_hub_bubble_view_impl.h"
#include "chrome/browser/ui/views/sharing_hub/sharing_hub_icon_view.h"
#include "chrome/browser/ui/views/side_panel/side_panel.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_registry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_rounded_corner.h"
#include "chrome/browser/ui/views/side_panel/side_panel_toolbar_container.h"
#include "chrome/browser/ui/views/side_panel/side_panel_util.h"
#include "chrome/browser/ui/views/status_bubble_views.h"
#include "chrome/browser/ui/views/sync/one_click_signin_dialog_view.h"
#include "chrome/browser/ui/views/tab_contents/chrome_web_contents_view_focus_helper.h"
#include "chrome/browser/ui/views/tab_search_bubble_host.h"
#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/new_tab_button.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_search_button.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/theme_copying_widget.h"
#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs_button.h"
#include "chrome/browser/ui/views/toolbar/reload_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views/translate/translate_bubble_controller.h"
#include "chrome/browser/ui/views/translate/translate_bubble_view.h"
#include "chrome/browser/ui/views/update_recommended_message_box.h"
#include "chrome/browser/ui/views/upgrade_notification_controller.h"
#include "chrome/browser/ui/views/user_education/browser_feature_promo_controller.h"
#include "chrome/browser/ui/views/user_education/browser_user_education_service.h"
#include "chrome/browser/ui/views/web_apps/frame_toolbar/web_app_frame_toolbar_view.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/browser/user_education/user_education_service.h"
#include "chrome/browser/user_education/user_education_service_factory.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "chromeos/components/mgs/managed_guest_session_utils.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/feature_engagement/public/event_constants.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/javascript_dialogs/app_modal_dialog_controller.h"
#include "components/javascript_dialogs/app_modal_dialog_queue.h"
#include "components/javascript_dialogs/app_modal_dialog_view.h"
#include "components/omnibox/browser/omnibox_popup_view.h"
#include "components/omnibox/browser/omnibox_view.h"
#include "components/performance_manager/public/features.h"
#include "components/permissions/permission_request_manager.h"
#include "components/prefs/pref_service.h"
#include "components/reading_list/core/reading_list_pref_names.h"
#include "components/safe_browsing/core/browser/password_protection/metrics_util.h"
#include "components/segmentation_platform/embedder/default_model/device_switcher_model.h"
#include "components/segmentation_platform/public/constants.h"
#include "components/segmentation_platform/public/input_context.h"
#include "components/segmentation_platform/public/prediction_options.h"
#include "components/segmentation_platform/public/segmentation_platform_service.h"
#include "components/services/screen_ai/buildflags/buildflags.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "components/sync/service/sync_service.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/browser/translate_manager.h"
#include "components/user_education/common/feature_promo_handle.h"
#include "components/user_education/common/help_bubble_factory_registry.h"
#include "components/user_education/views/help_bubble_view.h"
#include "components/version_info/channel.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "components/webapps/browser/banners/app_banner_manager.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/permission_controller.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "extensions/common/command.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_mode_observer.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/base/theme_provider.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/window_open_disposition.h"
#include "ui/base/window_open_disposition_utils.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/content_accelerators/accelerator_util.h"
#include "ui/display/screen.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/scrollbar_size.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/accessibility/view_accessibility_utils.h"
#include "ui/views/background.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/separator.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/focus/external_focus_tracker.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/views_features.h"
#include "ui/views/widget/native_widget.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/sublevel_manager.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view_chromeos.h"
#include "chrome/browser/ui/views/frame/top_controls_slide_controller_chromeos.h"
#include "chromeos/ui/frame/caption_buttons/frame_size_button.h"
#include "chromeos/ui/wm/desks/desks_helper.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_switches.h"
#include "ash/public/cpp/accelerators.h"
#include "ash/public/cpp/metrics_util.h"
#include "chrome/browser/ash/crosapi/browser_util.h"
#include "chrome/browser/ui/ash/window_properties.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "ui/compositor/throughput_tracker.h"
#else
#include "chrome/browser/ui/signin/signin_view_controller.h"
#endif // !BUILDFLAG(IS_CHROMEOS_ASH)
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/fullscreen_util_mac.h"
#include "components/remote_cocoa/app_shim/application_bridge.h"
#include "components/remote_cocoa/browser/application_host.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "chrome/browser/promos/promos_utils.h"
#include "chrome/browser/ui/views/promos/ios_promo_password_bubble.h"
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
#if defined(USE_AURA)
#include "chrome/browser/ui/views/theme_profile_key.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "chrome/browser/taskbar/taskbar_decorator_win.h"
#include "chrome/browser/win/jumplist.h"
#include "chrome/browser/win/jumplist_factory.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/win/hwnd_util.h"
#include "ui/native_theme/native_theme_win.h"
#include "ui/views/win/scoped_fullscreen_visibility.h"
// To avoid conflicts with the macro from the Windows SDK...
#undef LoadAccelerators
#endif
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
#include "chrome/browser/accessibility/pdf_ocr_controller.h"
#include "chrome/browser/accessibility/pdf_ocr_controller_factory.h"
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
#include "chrome/browser/ui/views/frame/webui_tab_strip_container_view.h"
#endif // BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
using base::UserMetricsAction;
using content::NativeWebKeyboardEvent;
using content::WebContents;
using web_modal::WebContentsModalDialogHost;
namespace {
// The name of a key to store on the window handle so that other code can
// locate this object using just the handle.
const char* const kBrowserViewKey = "__BROWSER_VIEW__";
#if BUILDFLAG(IS_CHROMEOS_ASH)
// UMA histograms that record animation smoothness for tab loading animation.
constexpr char kTabLoadingSmoothnessHistogramName[] =
"Chrome.Tabs.AnimationSmoothness.TabLoading";
void RecordTabLoadingSmoothness(int smoothness) {
UMA_HISTOGRAM_PERCENTAGE(kTabLoadingSmoothnessHistogramName, smoothness);
}
#endif
// See SetDisableRevealerDelayForTesting().
bool g_disable_revealer_delay_for_testing = false;
#if DCHECK_IS_ON()
std::string FocusListToString(views::View* view) {
std::ostringstream result;
base::flat_set<views::View*> seen_views;
while (view) {
if (base::Contains(seen_views, view)) {
result << "*CYCLE TO " << view->GetClassName() << "*";
break;
}
seen_views.insert(view);
result << view->GetClassName() << " ";
view = view->GetNextFocusableView();
}
return result.str();
}
void CheckFocusListForCycles(views::View* const start_view) {
views::View* view = start_view;
base::flat_set<views::View*> seen_views;
while (view) {
DCHECK(!base::Contains(seen_views, view)) << FocusListToString(start_view);
seen_views.insert(view);
views::View* next_view = view->GetNextFocusableView();
if (next_view) {
DCHECK_EQ(view, next_view->GetPreviousFocusableView())
<< view->GetClassName();
}
view = next_view;
}
}
#endif // DCHECK_IS_ON()
bool GetGestureCommand(ui::GestureEvent* event, int* command) {
DCHECK(command);
*command = 0;
#if BUILDFLAG(IS_MAC)
if (event->details().type() == ui::ET_GESTURE_SWIPE) {
if (event->details().swipe_left()) {
*command = IDC_BACK;
return true;
} else if (event->details().swipe_right()) {
*command = IDC_FORWARD;
return true;
}
}
#endif // BUILDFLAG(IS_MAC)
return false;
}
bool WidgetHasChildModalDialog(views::Widget* parent_widget) {
views::Widget::Widgets widgets;
views::Widget::GetAllChildWidgets(parent_widget->GetNativeView(), &widgets);
for (auto* widget : widgets) {
if (widget == parent_widget)
continue;
if (widget->IsModal())
return true;
}
return false;
}
// Return the DevTools docked placement. It infers the docked placement from
// the bounds of contents_webview relative to the local bounds of the container
// that holds both contents_webview and devtools_webview.
BrowserView::DevToolsDockedPlacement GetDevToolsDockedPlacement(
const gfx::Rect& contents_webview_bounds,
const gfx::Rect& local_webview_container_bounds) {
// If contents_webview has the same bounds as webview_container, it either
// means that devtools are not open or devtools are open in a separate
// window (not docked).
if (contents_webview_bounds == local_webview_container_bounds) {
return BrowserView::DevToolsDockedPlacement::kNone;
}
if (contents_webview_bounds.x() > 0 && contents_webview_bounds.y() == 0 &&
contents_webview_bounds.x() + contents_webview_bounds.width() ==
local_webview_container_bounds.width()) {
return BrowserView::DevToolsDockedPlacement::kLeft;
} else if (contents_webview_bounds.origin().IsOrigin() &&
contents_webview_bounds.height() ==
local_webview_container_bounds.height()) {
return BrowserView::DevToolsDockedPlacement::kRight;
} else if (contents_webview_bounds.width() ==
local_webview_container_bounds.width()) {
return BrowserView::DevToolsDockedPlacement::kBottom;
}
return BrowserView::DevToolsDockedPlacement::kUnknown;
}
bool IsManagedGuestSession() {
#if BUILDFLAG(IS_CHROMEOS)
return chromeos::IsManagedGuestSession();
#else
return false;
#endif
}
// Overlay view that owns TopContainerView in some cases (such as during
// immersive fullscreen reveal).
class TopContainerOverlayView : public views::View {
public:
METADATA_HEADER(TopContainerOverlayView);
explicit TopContainerOverlayView(base::WeakPtr<BrowserView> browser_view)
: browser_view_(std::move(browser_view)) {}
~TopContainerOverlayView() override = default;
void ChildPreferredSizeChanged(views::View* child) override {
// When a child of BrowserView changes its preferred size, it
// invalidates the BrowserView's layout as well. When a child is
// reparented under this overlay view, this doesn't happen since the
// overlay view is owned by NonClientView.
//
// BrowserView's layout logic still applies in this case. To ensure
// it is used, we must invalidate BrowserView's layout.
if (browser_view_)
browser_view_->InvalidateLayout();
}
private:
// The BrowserView this overlay is created for. WeakPtr is used since
// this view is held in a different hierarchy.
base::WeakPtr<BrowserView> browser_view_;
};
BEGIN_METADATA(TopContainerOverlayView, views::View)
END_METADATA
// A view targeter for the overlay view, which makes sure the overlay view
// itself is never a target for events, but its children (i.e. top_container)
// may be.
class OverlayViewTargeterDelegate : public views::ViewTargeterDelegate {
public:
OverlayViewTargeterDelegate() = default;
OverlayViewTargeterDelegate(const OverlayViewTargeterDelegate&) = delete;
OverlayViewTargeterDelegate& operator=(const OverlayViewTargeterDelegate&) =
delete;
~OverlayViewTargeterDelegate() override = default;
bool DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const override {
const auto& children = target->children();
const auto hits_child = [target, rect](const views::View* child) {
gfx::RectF child_rect(rect);
views::View::ConvertRectToTarget(target, child, &child_rect);
return child->HitTestRect(gfx::ToEnclosingRect(child_rect));
};
return base::ranges::any_of(children, hits_child);
}
};
// This class uses a solid background instead of a views::Separator. The latter
// is not guaranteed to fill its bounds and assumes being painted on an opaque
// background (which is why it'd be OK to only partially fill its bounds). This
// needs to fill its bounds to have the entire BrowserView painted.
class ContentsSeparator : public views::View {
public:
METADATA_HEADER(ContentsSeparator);
ContentsSeparator() {
SetBackground(
views::CreateThemedSolidBackground(kColorToolbarContentAreaSeparator));
// BrowserViewLayout will respect either the height or width of this,
// depending on orientation, not simultaneously both.
SetPreferredSize(
gfx::Size(views::Separator::kThickness, views::Separator::kThickness));
}
};
BEGIN_METADATA(ContentsSeparator, views::View)
END_METADATA
bool ShouldShowWindowIcon(const Browser* browser,
bool app_uses_window_controls_overlay) {
#if BUILDFLAG(IS_CHROMEOS)
// For Chrome OS only, trusted windows (apps and settings) do not show a
// window icon, crbug.com/119411. Child windows (i.e. popups) do show an icon.
if (browser->is_trusted_source() || app_uses_window_controls_overlay)
return false;
#endif
return browser->SupportsWindowFeature(Browser::FEATURE_TITLEBAR);
}
#if BUILDFLAG(IS_MAC)
void GetAnyTabAudioStates(const Browser* browser,
bool* any_tab_playing_audio,
bool* any_tab_playing_muted_audio) {
const TabStripModel* model = browser->tab_strip_model();
for (int i = 0; i < model->count(); i++) {
auto* contents = model->GetWebContentsAt(i);
auto* helper = RecentlyAudibleHelper::FromWebContents(contents);
if (helper && helper->WasRecentlyAudible()) {
if (contents->IsAudioMuted())
*any_tab_playing_muted_audio = true;
else
*any_tab_playing_audio = true;
}
}
}
#endif // BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_MAC)
// OverlayWidget is a child Widget of BrowserFrame used during immersive
// fullscreen on macOS that hosts the top container. Its native Window and View
// interface with macOS fullscreen APIs allowing separation of the top container
// and web contents.
// Currently the only explicit reason for OverlayWidget to be its own subclass
// is to support GetAccelerator() forwarding.
class OverlayWidget : public ThemeCopyingWidget {
public:
explicit OverlayWidget(views::Widget* role_model)
: ThemeCopyingWidget(role_model) {}
OverlayWidget(const OverlayWidget&) = delete;
OverlayWidget& operator=(const OverlayWidget&) = delete;
~OverlayWidget() override = default;
// OverlayWidget hosts the top container. Views within the top container look
// up accelerators by asking their hosting Widget. In non-immersive fullscreen
// that would be the BrowserFrame. Give top chrome what it expects and forward
// GetAccelerator() calls to OverlayWidget's parent (BrowserFrame).
bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator) const override {
DCHECK(parent());
return parent()->GetAccelerator(cmd_id, accelerator);
}
};
// TabContainerOverlayView is a view that hosts the TabStripRegionView during
// immersive fullscreen. The TopContainerView usually draws the background for
// the tab strip. Since the tab strip has been reparented we need to handle
// drawing the background here.
class TabContainerOverlayView : public views::View {
public:
METADATA_HEADER(TabContainerOverlayView);
explicit TabContainerOverlayView(base::WeakPtr<BrowserView> browser_view)
: browser_view_(std::move(browser_view)) {}
~TabContainerOverlayView() override = default;
// views::View override
void OnPaintBackground(gfx::Canvas* canvas) override {
SkColor frame_color = browser_view_->frame()->GetFrameView()->GetFrameColor(
BrowserFrameActiveState::kUseCurrent);
canvas->DrawColor(frame_color);
auto* theme_service =
ThemeServiceFactory::GetForProfile(browser_view_->browser()->profile());
if (!theme_service->UsingSystemTheme()) {
auto* non_client_frame_view = browser_view_->frame()->GetFrameView();
non_client_frame_view->PaintThemedFrame(canvas);
}
}
private:
// The BrowserView this overlay is created for. WeakPtr is used since
// this view is held in a different hierarchy.
base::WeakPtr<BrowserView> browser_view_;
};
BEGIN_METADATA(TabContainerOverlayView, views::View)
END_METADATA
#endif // BUILDFLAG(IS_MAC)
} // namespace
///////////////////////////////////////////////////////////////////////////////
// Delegate implementation for BrowserViewLayout. Usually just forwards calls
// into BrowserView.
class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate {
public:
explicit BrowserViewLayoutDelegateImpl(BrowserView* browser_view)
: browser_view_(browser_view) {}
BrowserViewLayoutDelegateImpl(const BrowserViewLayoutDelegateImpl&) = delete;
BrowserViewLayoutDelegateImpl& operator=(
const BrowserViewLayoutDelegateImpl&) = delete;
~BrowserViewLayoutDelegateImpl() override = default;
bool ShouldDrawTabStrip() const override {
return browser_view_->ShouldDrawTabStrip();
}
bool GetBorderlessModeEnabled() const override {
return browser_view_->IsBorderlessModeEnabled();
}
gfx::Rect GetBoundsForTabStripRegionInBrowserView() const override {
const gfx::Size tabstrip_minimum_size =
browser_view_->tab_strip_region_view()->GetMinimumSize();
gfx::RectF bounds_f(browser_view_->frame()->GetBoundsForTabStripRegion(
tabstrip_minimum_size));
views::View::ConvertRectToTarget(browser_view_->parent(), browser_view_,
&bounds_f);
return gfx::ToEnclosingRect(bounds_f);
}
gfx::Rect GetBoundsForWebAppFrameToolbarInBrowserView() const override {
const gfx::Size web_app_frame_toolbar_preferred_size =
browser_view_->web_app_frame_toolbar()->GetPreferredSize();
gfx::RectF bounds_f(browser_view_->frame()->GetBoundsForWebAppFrameToolbar(
web_app_frame_toolbar_preferred_size));
views::View::ConvertRectToTarget(browser_view_->parent(), browser_view_,
&bounds_f);
return gfx::ToEnclosingRect(bounds_f);
}
void LayoutWebAppWindowTitle(
const gfx::Rect& available_space,
views::Label& window_title_label) const override {
browser_view_->frame()->LayoutWebAppWindowTitle(available_space,
window_title_label);
}
int GetTopInsetInBrowserView() const override {
// BrowserView should fill the full window when window controls overlay
// is enabled or when immersive fullscreen with tabs is enabled.
if (browser_view_->IsWindowControlsOverlayEnabled() ||
browser_view_->IsBorderlessModeEnabled()) {
return 0;
}
#if BUILDFLAG(IS_MAC)
if (browser_view_->UsesImmersiveFullscreenTabbedMode() &&
browser_view_->immersive_mode_controller()->IsEnabled()) {
return 0;
}
#endif
return browser_view_->frame()->GetTopInset() - browser_view_->y();
}
bool IsToolbarVisible() const override {
return browser_view_->IsToolbarVisible();
}
bool IsBookmarkBarVisible() const override {
return browser_view_->IsBookmarkBarVisible();
}
bool IsContentsSeparatorEnabled() const override {
// Web app windows manage their own separator.
// TODO(crbug.com/1012979): Make PWAs set the visibility of the ToolbarView
// based on whether it is visible instead of setting the height to 0px. This
// will enable BrowserViewLayout to hide the contents separator on its own
// using the same logic used by normal BrowserViews.
return !browser_view_->browser()->app_controller();
}
ExclusiveAccessBubbleViews* GetExclusiveAccessBubble() const override {
return browser_view_->exclusive_access_bubble();
}
bool IsTopControlsSlideBehaviorEnabled() const override {
return browser_view_->GetTopControlsSlideBehaviorEnabled();
}
float GetTopControlsSlideBehaviorShownRatio() const override {
return browser_view_->GetTopControlsSlideBehaviorShownRatio();
}
bool SupportsWindowFeature(Browser::WindowFeature feature) const override {
return browser_view_->browser()->SupportsWindowFeature(feature);
}
gfx::NativeView GetHostView() const override {
return browser_view_->GetWidget()->GetNativeView();
}
gfx::NativeView GetHostViewForAnchoring() const override {
return browser_view_->GetWidgetForAnchoring()->GetNativeView();
}
bool BrowserIsSystemWebApp() const override {
#if BUILDFLAG(IS_CHROMEOS_ASH)
return browser_view_->browser()->app_controller()->system_app();
#else
return false;
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
}
bool BrowserIsWebApp() const override {
return browser_view_->GetIsWebAppType();
}
bool BrowserIsTypeApp() const override {
return browser_view_->browser()->is_type_app();
}
bool BrowserIsTypeNormal() const override {
return browser_view_->browser()->is_type_normal();
}
bool HasFindBarController() const override {
return browser_view_->browser()->HasFindBarController();
}
void MoveWindowForFindBarIfNecessary() const override {
auto* const controller = browser_view_->browser()->GetFindBarController();
return controller->find_bar()->MoveWindowIfNecessary();
}
bool IsWindowControlsOverlayEnabled() const override {
return browser_view_->IsWindowControlsOverlayEnabled();
}
void UpdateWindowControlsOverlay(
const gfx::Rect& available_titlebar_area) const override {
content::WebContents* web_contents = browser_view_->GetActiveWebContents();
if (!web_contents) {
return;
}
// The rect passed to WebContents is directly exposed to websites. In case
// of an empty rectangle, this should be exposed as 0,0 0x0 rather than
// whatever coordinates might be in rect.
web_contents->UpdateWindowControlsOverlay(
available_titlebar_area.IsEmpty()
? gfx::Rect()
: browser_view_->GetMirroredRect(available_titlebar_area));
}
bool ShouldLayoutTabStrip() const override {
#if BUILDFLAG(IS_MAC)
// The tab strip is hosted in a separate widget in immersive fullscreen on
// macOS.
if (browser_view_->UsesImmersiveFullscreenTabbedMode() &&
browser_view_->immersive_mode_controller()->IsEnabled()) {
return false;
}
#endif
return true;
}
int GetExtraInfobarOffset() const override {
#if BUILDFLAG(IS_MAC)
if (browser_view_->UsesImmersiveFullscreenMode() &&
browser_view_->immersive_mode_controller()->IsEnabled()) {
return browser_view_->immersive_mode_controller()
->GetExtraInfobarOffset();
}
#endif
return 0;
}
private:
raw_ptr<BrowserView> browser_view_;
};
///////////////////////////////////////////////////////////////////////////////
// BrowserView::AccessibilityModeObserver:
class BrowserView::AccessibilityModeObserver : public ui::AXModeObserver {
public:
explicit AccessibilityModeObserver(BrowserView* browser_view)
: browser_view_(browser_view) {
ui::AXPlatformNode::AddAXModeObserver(this);
}
~AccessibilityModeObserver() override {
ui::AXPlatformNode::RemoveAXModeObserver(this);
}
private:
// ui::AXModeObserver:
void OnAXModeAdded(ui::AXMode mode) override {
// This will have the effect of turning tablet mode off if a screen reader
// is enabled while Chrome is already open. It will not return the browser
// to tablet mode if the user kills their screen reader. This has to happen
// asynchronously since AXMode changes can happen while AXTree updates or
// notifications are in progress, and |MaybeInitializeWebUITabStrip| can
// destroy things synchronously.
if (mode.has_mode(ui::AXMode::kScreenReader)) {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&BrowserView::MaybeInitializeWebUITabStrip,
browser_view_->GetAsWeakPtr()));
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
// TODO(crbug.com/1442928): Check if PdfOcrController is correctly
// created on windows, macOS, and linux when screen reader is on.
if (features::IsPdfOcrEnabled()) {
screen_ai::PdfOcrControllerFactory::GetForProfile(
browser_view_->GetProfile());
}
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
}
}
const raw_ptr<BrowserView> browser_view_;
};
///////////////////////////////////////////////////////////////////////////////
// BrowserView, public:
BrowserView::BrowserView(std::unique_ptr<Browser> browser)
: views::ClientView(nullptr, nullptr),
browser_(std::move(browser)),
accessibility_mode_observer_(
std::make_unique<AccessibilityModeObserver>(this)) {
// Store the actions so that the access is available for other classes.
if (base::FeatureList::IsEnabled(features::kSidePanelPinning)) {
browser_->SetUserData(BrowserActions::UserDataKey(),
std::make_unique<BrowserActions>(*browser_));
}
SetShowIcon(
::ShouldShowWindowIcon(browser_.get(), AppUsesWindowControlsOverlay()));
// In forced app mode, all size controls are always disabled. Otherwise, use
// `create_params` to enable/disable specific size controls.
if (chrome::IsRunningInForcedAppMode()) {
SetHasWindowSizeControls(false);
} else if (GetIsPictureInPictureType()) {
// Picture in picture windows must always have a title, can never minimize,
// and can never maximize regardless of what the params say.
SetShowTitle(true);
SetCanMinimize(false);
SetCanMaximize(false);
SetCanFullscreen(false);
SetCanResize(true);
} else {
SetCanResize(browser_->create_params().can_resize);
SetCanMaximize(browser_->create_params().can_maximize);
SetCanFullscreen(browser_->create_params().can_fullscreen);
SetCanMinimize(true);
}
SetProperty(views::kElementIdentifierKey, kBrowserViewElementId);
// In order to do feature promos, the browser must have a UI and not be an
// "off-the-record" or in a demo or guest mode.
bool is_profile_type_without_iph =
GetIncognito() || GetGuestSession() || IsManagedGuestSession() ||
profiles::IsDemoSession() || profiles::IsChromeAppKioskSession();
#if BUILDFLAG(IS_CHROMEOS_LACROS)
is_profile_type_without_iph |= profiles::IsWebKioskSession();
#endif
if (!headless::IsHeadlessMode() && !is_profile_type_without_iph) {
if (UserEducationService* const user_education_service =
UserEducationServiceFactory::GetForBrowserContext(GetProfile())) {
RegisterChromeHelpBubbleFactories(
user_education_service->help_bubble_factory_registry());
MaybeRegisterChromeFeaturePromos(
user_education_service->feature_promo_registry());
MaybeRegisterChromeTutorials(user_education_service->tutorial_registry());
feature_promo_controller_ =
std::make_unique<BrowserFeaturePromoController>(
this,
feature_engagement::TrackerFactory::GetForBrowserContext(
GetProfile()),
&user_education_service->feature_promo_registry(),
&user_education_service->help_bubble_factory_registry(),
&user_education_service->feature_promo_storage_service(),
&user_education_service->tutorial_service());
}
}
browser_->tab_strip_model()->AddObserver(this);
immersive_mode_controller_ = chrome::CreateImmersiveModeController(this);
// Top container holds tab strip region and toolbar and lives at the front of
// the view hierarchy.
std::unique_ptr<TabMenuModelFactory> tab_menu_model_factory;
if (browser_->app_controller()) {
tab_menu_model_factory =
browser_->app_controller()->GetTabMenuModelFactory();
UpdateWindowControlsOverlayEnabled();
UpdateBorderlessModeEnabled();
}
// Initialize Blink's 'resizable' CSS @media feature state.
OnWidgetSizeConstraintsChanged(GetWidget());
// TabStrip takes ownership of the controller.
auto tabstrip_controller = std::make_unique<BrowserTabStripController>(
browser_->tab_strip_model(), this, std::move(tab_menu_model_factory));
BrowserTabStripController* tabstrip_controller_ptr =
tabstrip_controller.get();
auto tabstrip = std::make_unique<TabStrip>(std::move(tabstrip_controller));
tabstrip_ = tabstrip.get();
tabstrip_controller_ptr->InitFromModel(tabstrip_);
top_container_ = AddChildView(std::make_unique<TopContainerView>(this));
if (GetIsWebAppType()) {
web_app_frame_toolbar_ = top_container_->AddChildView(
std::make_unique<WebAppFrameToolbarView>(this));
if (ShouldShowWindowTitle()) {
web_app_window_title_ = top_container_->AddChildView(
std::make_unique<views::Label>(GetWindowTitle()));
web_app_window_title_->SetID(VIEW_ID_WINDOW_TITLE);
}
}
tab_strip_region_view_ = top_container_->AddChildView(
std::make_unique<TabStripRegionView>(std::move(tabstrip)));
ColorProviderBrowserHelper::CreateForBrowser(browser_.get());
// Create WebViews early so |webui_tab_strip_| can observe their size.
auto devtools_web_view =
std::make_unique<views::WebView>(browser_->profile());
devtools_web_view->SetID(VIEW_ID_DEV_TOOLS_DOCKED);
devtools_web_view->SetVisible(false);
auto contents_web_view =
std::make_unique<ContentsWebView>(browser_->profile());
contents_web_view->SetID(VIEW_ID_TAB_CONTAINER);
auto contents_container = std::make_unique<views::View>();
devtools_web_view_ =
contents_container->AddChildView(std::move(devtools_web_view));
contents_web_view_ =
contents_container->AddChildView(std::move(contents_web_view));
contents_web_view_->set_is_primary_web_contents_for_window(true);
contents_container->SetLayoutManager(std::make_unique<ContentsLayoutManager>(
devtools_web_view_, contents_web_view_));
toolbar_ = top_container_->AddChildView(
std::make_unique<ToolbarView>(browser_.get(), this));
contents_separator_ =
top_container_->AddChildView(std::make_unique<ContentsSeparator>());
web_contents_close_handler_ =
std::make_unique<WebContentsCloseHandler>(contents_web_view_);
contents_container_ = AddChildView(std::move(contents_container));
set_contents_view(contents_container_);
right_aligned_side_panel_separator_ =