From 722626cf1e63959646b61cf374e63e0324e80cef Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Wed, 26 Oct 2022 23:57:46 -0700 Subject: [PATCH] up to build-chromium. we will see how that goes --- .gitignore | 1 + ...le-GlobalMediaControlsCastStartStop.patch} | 0 ...RT-roll-src-third_party-ffmpeg-m102.patch} | 0 ...ERT-roll-src-third_party-ffmpeg-m106.patch | 55 + .../angle-wayland-include-protocol.patch | 38 + .../ozone-add-va-api-support-to-wayland.patch | 128 ++ .../remove-main-main10-profile-limit.patch | 39 + .../remove-no-opaque-pointers-flag.patch | 18 - ...e-VirtualCursor-standard-layout-type.patch | 238 --- ...pp-avoid-CFI-faults-with-is_cfi-true.patch | 38 + aur-patches/wayland-egl.patch | 22 - makefile | 54 +- .../chrome/browser/ui/tabs/tab_menu_model.cc | 156 ++ .../views/location_bar/location_bar_view.cc | 1478 +++++++++++++++++ .../browser/ui/views/toolbar/toolbar_view.cc | 959 +++++++++++ michael-patches/michael-customizations.patch | 131 +- 16 files changed, 2983 insertions(+), 372 deletions(-) rename aur-patches/{enable-GlobalMediaControlsCastStartStop.patch => REVERT-enable-GlobalMediaControlsCastStartStop.patch} (100%) rename aur-patches/{roll-src-third_party-ffmpeg.patch => REVERT-roll-src-third_party-ffmpeg-m102.patch} (100%) create mode 100644 aur-patches/REVERT-roll-src-third_party-ffmpeg-m106.patch create mode 100644 aur-patches/angle-wayland-include-protocol.patch create mode 100644 aur-patches/ozone-add-va-api-support-to-wayland.patch create mode 100644 aur-patches/remove-main-main10-profile-limit.patch delete mode 100644 aur-patches/remove-no-opaque-pointers-flag.patch delete mode 100644 aur-patches/sql-make-VirtualCursor-standard-layout-type.patch create mode 100644 aur-patches/unbundle-jsoncpp-avoid-CFI-faults-with-is_cfi-true.patch delete mode 100644 aur-patches/wayland-egl.patch create mode 100644 michael-patches-tempfiles/chrome/browser/ui/tabs/tab_menu_model.cc create mode 100644 michael-patches-tempfiles/chrome/browser/ui/views/location_bar/location_bar_view.cc create mode 100644 michael-patches-tempfiles/chrome/browser/ui/views/toolbar/toolbar_view.cc diff --git a/.gitignore b/.gitignore index a96320b..d6c15c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ archive aur-ungoogled-chromium cache +chromium-patches chromium-downloads chromium-launcher chromium-src** diff --git a/aur-patches/enable-GlobalMediaControlsCastStartStop.patch b/aur-patches/REVERT-enable-GlobalMediaControlsCastStartStop.patch similarity index 100% rename from aur-patches/enable-GlobalMediaControlsCastStartStop.patch rename to aur-patches/REVERT-enable-GlobalMediaControlsCastStartStop.patch diff --git a/aur-patches/roll-src-third_party-ffmpeg.patch b/aur-patches/REVERT-roll-src-third_party-ffmpeg-m102.patch similarity index 100% rename from aur-patches/roll-src-third_party-ffmpeg.patch rename to aur-patches/REVERT-roll-src-third_party-ffmpeg-m102.patch diff --git a/aur-patches/REVERT-roll-src-third_party-ffmpeg-m106.patch b/aur-patches/REVERT-roll-src-third_party-ffmpeg-m106.patch new file mode 100644 index 0000000..b2a1137 --- /dev/null +++ b/aur-patches/REVERT-roll-src-third_party-ffmpeg-m106.patch @@ -0,0 +1,55 @@ +From ded379824f5de39357b6b1894578101aba5cdf05 Mon Sep 17 00:00:00 2001 +From: Eugene Zemtsov +Date: Fri, 29 Jul 2022 04:41:04 +0000 +Subject: [PATCH] Roll src/third_party/ffmpeg/ 880df5ede..b71ecd02b (279 + commits) + +https://chromium.googlesource.com/chromium/third_party/ffmpeg.git/+log/880df5ede50a..b71ecd02b479 + +$ git log 880df5ede..b71ecd02b --date=short --no-merges --format='%ad %ae %s' +2022-07-27 eugene Roll for M106 +2022-07-25 andreas.rheinhardt avcodec/x86/pngdsp: Remove obsolete ff_add_bytes_l2_mmx() +2022-07-22 andreas.rheinhardt avcodec/hevcdec: Output MD5-message in one piece +2022-07-24 epirat07 configure: properly require libx264 if enabled +2022-07-24 zane avformat/argo_cvg: expose loop/reverb/checksum via metadata +(...) +2022-05-03 leo.izen avcodec/libjxldec: properly tag output colorspace +2022-06-25 ffmpeg avfilter/Makefile: always make colorspace.o +2022-03-02 brad avutil/ppc/cpu: Use proper header for OpenBSD PPC CPU detection +2022-06-24 jamrial avformat/http: include version.h +2022-05-16 mbonda-at-nvidia.com AV1 VDPAU hwaccel Decode support + +Created with: + roll-dep src/third_party/ffmpeg + +ffmpeg usage fix: + Switch from AVFrame::pkt_duration to AVFrame::duration, + AVFrame::pkt_duration is deprecated + +Bug: 1344646 +Change-Id: Iaa3abf48ef81dae6d282bca8f0fa2a8dffeeba25 +Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3788638 +Reviewed-by: Will Cassella +Commit-Queue: Eugene Zemtsov +Cr-Commit-Position: refs/heads/main@{#1029623} +--- + media/filters/audio_file_reader.cc | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc +index e1be5aa9a5b..951c003956f 100644 +--- a/media/filters/audio_file_reader.cc ++++ b/media/filters/audio_file_reader.cc +@@ -243,10 +243,10 @@ bool AudioFileReader::OnNewFrame( + // silence from being output. In the case where we are also discarding some + // portion of the packet (as indicated by a negative pts), we further want to + // adjust the duration downward by however much exists before zero. +- if (audio_codec_ == AudioCodec::kAAC && frame->pkt_duration) { ++ if (audio_codec_ == AudioCodec::kAAC && frame->duration) { + const base::TimeDelta pkt_duration = ConvertFromTimeBase( + glue_->format_context()->streams[stream_index_]->time_base, +- frame->pkt_duration + std::min(static_cast(0), frame->pts)); ++ frame->duration + std::min(static_cast(0), frame->pts)); + const base::TimeDelta frame_duration = + base::Seconds(frames_read / static_cast(sample_rate_)); + diff --git a/aur-patches/angle-wayland-include-protocol.patch b/aur-patches/angle-wayland-include-protocol.patch new file mode 100644 index 0000000..1245b17 --- /dev/null +++ b/aur-patches/angle-wayland-include-protocol.patch @@ -0,0 +1,38 @@ +diff -upr third_party/angle.orig/BUILD.gn third_party/angle/BUILD.gn +--- third_party/angle.orig/BUILD.gn 2022-08-17 19:38:11.000000000 +0000 ++++ third_party/angle/BUILD.gn 2022-08-18 11:04:09.061751111 +0000 +@@ -489,6 +489,12 @@ config("angle_vulkan_wayland_config") { + if (angle_enable_vulkan && angle_use_wayland && + defined(vulkan_wayland_include_dirs)) { + include_dirs = vulkan_wayland_include_dirs ++ } else if (angle_enable_vulkan && angle_use_wayland) { ++ include_dirs = [ ++ "$wayland_gn_dir/src/src", ++ "$wayland_gn_dir/include/src", ++ "$wayland_gn_dir/include/protocol", ++ ] + } + } + +@@ -1073,6 +1079,7 @@ if (angle_use_wayland) { + include_dirs = [ + "$wayland_dir/egl", + "$wayland_dir/src", ++ "$wayland_gn_dir/include/protocol", + ] + } + +diff -upr third_party/angle.orig/src/third_party/volk/BUILD.gn third_party/angle/src/third_party/volk/BUILD.gn +--- third_party/angle.orig/src/third_party/volk/BUILD.gn 2022-08-17 19:38:12.000000000 +0000 ++++ third_party/angle/src/third_party/volk/BUILD.gn 2022-08-18 11:04:36.499828006 +0000 +@@ -21,6 +21,9 @@ source_set("volk") { + configs += [ "$angle_root:angle_no_cfi_icall" ] + public_deps = [ "$angle_vulkan_headers_dir:vulkan_headers" ] + if (angle_use_wayland) { +- include_dirs = [ "$wayland_dir/src" ] ++ include_dirs = [ ++ "$wayland_dir/src", ++ "$wayland_gn_dir/include/protocol", ++ ] + } + } diff --git a/aur-patches/ozone-add-va-api-support-to-wayland.patch b/aur-patches/ozone-add-va-api-support-to-wayland.patch new file mode 100644 index 0000000..550029c --- /dev/null +++ b/aur-patches/ozone-add-va-api-support-to-wayland.patch @@ -0,0 +1,128 @@ +From: Maksim Sisov +Date: Wed, 20 Jan 2021 09:50:22 +0200 +Subject: [PATCH] ozone/wayland: add VA-API support. + +This patch ads VA-API support utilizing old VA-API path used for +ChromeOS, which can be buggy on some devices (currently tested +on Intel Gen8 and Gen9 with Gen8 having some minor bugs). + +It's known that a new VA-API is being developed atm and once it's ready, +we will switch to a new path, which should be more stable. + +Upstream-Status: Inappropriate + +The patch is based on the old va-api path. ChromeOS +team is working on the new path, which will be also employed +by Wayland later. + +--- +diff --git a/media/gpu/vaapi/vaapi_picture_factory.cc b/media/gpu/vaapi/vaapi_picture_factory.cc +index 62e3a42..bde9c2d 100644 +--- a/media/gpu/vaapi/vaapi_picture_factory.cc ++++ b/media/gpu/vaapi/vaapi_picture_factory.cc +@@ -105,7 +105,7 @@ uint32_t VaapiPictureFactory::GetGLTextureTarget() { + } + + gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() { +-#if BUILDFLAG(USE_VAAPI_X11) ++#if BUILDFLAG(IS_LINUX) + return gfx::BufferFormat::RGBX_8888; + #else + return gfx::BufferFormat::YUV_420_BIPLANAR; +diff --git a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc +index 941f24c..a9c8035 100644 +--- a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc ++++ b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc +@@ -4,6 +4,7 @@ + + #include "media/gpu/vaapi/vaapi_picture_native_pixmap.h" + ++#include "media/gpu/macros.h" + #include "media/gpu/vaapi/va_surface.h" + #include "media/gpu/vaapi/vaapi_wrapper.h" + #include "ui/gfx/buffer_format_util.h" +@@ -40,7 +41,21 @@ VaapiPictureNativePixmap::~VaapiPictureNativePixmap() = default; + bool VaapiPictureNativePixmap::DownloadFromSurface( + scoped_refptr va_surface) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); +- return vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_); ++ if (!vaapi_wrapper_->SyncSurface(va_surface->id())) { ++ VLOGF(1) << "Cannot sync VPP input surface"; ++ return false; ++ } ++ if (!vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_)) { ++ VLOGF(1) << "Cannot convert decoded image into output buffer"; ++ return false; ++ } ++ ++ // Sync target surface since the buffer is returning to client. ++ if (!vaapi_wrapper_->SyncSurface(va_surface_->id())) { ++ VLOGF(1) << "Cannot sync VPP output surface"; ++ return false; ++ } ++ return true; + } + + bool VaapiPictureNativePixmap::AllowOverlay() const { +diff --git a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc +index bf791d8..9e394eb 100644 +--- a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc ++++ b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc +@@ -560,12 +560,12 @@ void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange( + requested_visible_rect_ = visible_rect; + if (buffer_allocation_mode_ == BufferAllocationMode::kSuperReduced) { + // Add one to the reference frames for the one being currently egressed. +- requested_num_reference_frames_ = num_reference_frames + 1; ++ requested_num_reference_frames_ = num_reference_frames + 4; + requested_num_pics_ = num_pics - num_reference_frames; + } else if (buffer_allocation_mode_ == BufferAllocationMode::kReduced) { + // Add one to the reference frames for the one being currently egressed, + // and an extra allocation for both |client_| and |decoder_|. +- requested_num_reference_frames_ = num_reference_frames + 2; ++ requested_num_reference_frames_ = num_reference_frames + 5; + requested_num_pics_ = num_pics - num_reference_frames + 1; + } else { + requested_num_reference_frames_ = 0; +diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc +index 35378d1..68969d2 100644 +--- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc ++++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc +@@ -32,7 +32,9 @@ GbmPixmapWayland::GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager) + buffer_id_(buffer_manager->AllocateBufferID()) {} + + GbmPixmapWayland::~GbmPixmapWayland() { +- if (created_wl_buffer_) ++ // gfx::BufferUsage::SCANOUT_VDA_WRITE doesn't result in creation of ++ // wl_buffers. ++ if (created_wl_buffer_ && usage_ != gfx::BufferUsage::SCANOUT_VDA_WRITE) + buffer_manager_->DestroyBuffer(buffer_id_); + } + +diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h +index 9e8b2fa..9918508 100644 +--- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h ++++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h +@@ -92,6 +92,9 @@ class GbmPixmapWayland : public gfx::NativePixmap { + + // Says a wl_buffer has been created and must removed. + bool created_wl_buffer_ = false; ++ ++ // Tells the usage of this pixmap. ++ gfx::BufferUsage usage_ = gfx::BufferUsage::SCANOUT; + }; + + } // namespace ui +diff --git a/ui/ozone/platform/wayland/ozone_platform_wayland.cc b/ui/ozone/platform/wayland/ozone_platform_wayland.cc +index c13bd3a..04fa160 100644 +--- a/ui/ozone/platform/wayland/ozone_platform_wayland.cc ++++ b/ui/ozone/platform/wayland/ozone_platform_wayland.cc +@@ -297,6 +297,9 @@ class OzonePlatformWayland : public OzonePlatform, + properties->supports_global_screen_coordinates = + features::IsWaylandScreenCoordinatesEnabled(); + ++ // Let the media know this platform supports va-api. ++ properties->supports_vaapi = true; ++ + initialised = true; + } + diff --git a/aur-patches/remove-main-main10-profile-limit.patch b/aur-patches/remove-main-main10-profile-limit.patch new file mode 100644 index 0000000..1b1611a --- /dev/null +++ b/aur-patches/remove-main-main10-profile-limit.patch @@ -0,0 +1,39 @@ +diff --git a/media/base/supported_types.cc b/media/base/supported_types.cc +index c2efcdb..cc28d84 100644 +--- a/media/base/supported_types.cc ++++ b/media/base/supported_types.cc +@@ -205,34 +205,7 @@ bool IsHevcProfileSupported(const VideoType& type) { + return false; + + #if BUILDFLAG(ENABLE_PLATFORM_HEVC) +-#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX) +-#if BUILDFLAG(IS_CHROMEOS_LACROS) +- // TODO(b/171813538): For Lacros, the supplemental profile cache will be +- // asking lacros-gpu, but we will be doing decoding in ash-gpu. Until the +- // codec detection is plumbed through to ash-gpu we can do this extra check +- // for HEVC support. +- if (base::CommandLine::ForCurrentProcess()->HasSwitch( +- switches::kLacrosEnablePlatformHevc)) { +- return true; +- } +-#endif // BUILDFLAG(IS_CHROMEOS_LACROS) +- return GetSupplementalProfileCache()->IsProfileSupported(type.profile); +-#elif BUILDFLAG(IS_MAC) +- if (__builtin_available(macOS 11.0, *)) +- return base::FeatureList::IsEnabled(kPlatformHEVCDecoderSupport) && +- (type.profile == HEVCPROFILE_MAIN || +- type.profile == HEVCPROFILE_MAIN10 || +- type.profile == HEVCPROFILE_MAIN_STILL_PICTURE || +- type.profile == HEVCPROFILE_REXT); +- return false; +-#elif BUILDFLAG(IS_ANDROID) +- // Technically android 5.0 mandates support for only HEVC main profile, +- // however some platforms (like chromecast) have had more profiles supported +- // so we'll see what happens if we just enable them all. +- return base::FeatureList::IsEnabled(kPlatformHEVCDecoderSupport); +-#else + return true; +-#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX) + #else + return false; + #endif // BUILDFLAG(ENABLE_PLATFORM_HEVC) diff --git a/aur-patches/remove-no-opaque-pointers-flag.patch b/aur-patches/remove-no-opaque-pointers-flag.patch deleted file mode 100644 index a8eba73..0000000 --- a/aur-patches/remove-no-opaque-pointers-flag.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- chromium-102.0.5005.61/build/config/compiler/BUILD.gn.orig 2022-05-19 10:35:52.991415777 +0000 -+++ chromium-102.0.5005.61/build/config/compiler/BUILD.gn 2022-05-19 10:36:11.102017131 +0000 -@@ -1538,15 +1538,6 @@ config("default_warnings") { - cflags += [ "-Wno-deprecated-non-prototype" ] - } - -- if (!is_nacl && !(is_chromeos || -- default_toolchain == "//build/toolchain/cros:target")) { -- # TODO(https://crbug.com/1316298): Re-enable once test failure is figured out -- cflags += [ -- "-Xclang", -- "-no-opaque-pointers", -- ] -- } -- - if (is_fuchsia) { - # TODO(https://bugs.chromium.org/p/fuchsia/issues/detail?id=77383) - cflags += [ "-Wno-deprecated-copy" ] diff --git a/aur-patches/sql-make-VirtualCursor-standard-layout-type.patch b/aur-patches/sql-make-VirtualCursor-standard-layout-type.patch deleted file mode 100644 index 3364d41..0000000 --- a/aur-patches/sql-make-VirtualCursor-standard-layout-type.patch +++ /dev/null @@ -1,238 +0,0 @@ -From 144479ad7b4287bee4067f95e4218f614798a865 Mon Sep 17 00:00:00 2001 -From: Stephan Hartmann -Date: Sun, 16 Jan 2022 19:15:26 +0000 -Subject: [PATCH] sql: make VirtualCursor standard layout type - -sql::recover::VirtualCursor needs to be a standard layout type, but -has members of type std::unique_ptr. However, std::unique_ptr is not -guaranteed to be standard layout. Compiling with clang combined with -gcc-11 libstdc++ fails because of this. - -Bug: 1189788 -Change-Id: Ia6dc388cc5ef1c0f2afc75f8ca45b9f12687ca9c ---- - sql/recover_module/btree.cc | 18 ++++++++++++------ - sql/recover_module/btree.h | 21 +++++++++++++++------ - sql/recover_module/cursor.cc | 24 ++++++++++++------------ - sql/recover_module/cursor.h | 2 +- - sql/recover_module/pager.cc | 5 ++--- - sql/recover_module/pager.h | 6 +++--- - 6 files changed, 45 insertions(+), 31 deletions(-) - -diff --git a/sql/recover_module/btree.cc b/sql/recover_module/btree.cc -index cc9420e5c05..f12d8fa32a2 100644 ---- a/sql/recover_module/btree.cc -+++ b/sql/recover_module/btree.cc -@@ -136,16 +136,22 @@ static_assert(std::is_trivially_destructible::value, - "Move the destructor to the .cc file if it's non-trival"); - #endif // !DCHECK_IS_ON() - --LeafPageDecoder::LeafPageDecoder(DatabasePageReader* db_reader) noexcept -- : page_id_(db_reader->page_id()), -- db_reader_(db_reader), -- cell_count_(ComputeCellCount(db_reader)), -- next_read_index_(0), -- last_record_size_(0) { -+LeafPageDecoder::LeafPageDecoder() noexcept = default; -+ -+void LeafPageDecoder::Initialize(DatabasePageReader* db_reader) { -+ page_id_ = db_reader->page_id(); -+ db_reader_ = db_reader; -+ cell_count_ = ComputeCellCount(db_reader); -+ next_read_index_ = 0; -+ last_record_size_ = 0; - DCHECK(IsOnValidPage(db_reader)); - DCHECK(DatabasePageReader::IsValidPageId(page_id_)); - } - -+void LeafPageDecoder::Reset() { -+ db_reader_ = nullptr; -+} -+ - bool LeafPageDecoder::TryAdvance() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(CanAdvance()); -diff --git a/sql/recover_module/btree.h b/sql/recover_module/btree.h -index eaa087a5c52..df0e0c937c0 100644 ---- a/sql/recover_module/btree.h -+++ b/sql/recover_module/btree.h -@@ -101,9 +101,7 @@ class LeafPageDecoder { - public: - // Creates a decoder for a DatabasePageReader's last read page. - // -- // |db_reader| must have been used to read an inner page of a table B-tree. -- // |db_reader| must outlive this instance. -- explicit LeafPageDecoder(DatabasePageReader* db_reader) noexcept; -+ LeafPageDecoder() noexcept; - ~LeafPageDecoder() noexcept = default; - - LeafPageDecoder(const LeafPageDecoder&) = delete; -@@ -151,6 +149,17 @@ class LeafPageDecoder { - // read as long as CanAdvance() returns true. - bool TryAdvance(); - -+ // Initialize with DatabasePageReader -+ // |db_reader| must have been used to read an inner page of a table B-tree. -+ // |db_reader| must outlive this instance. -+ void Initialize(DatabasePageReader* db_reader); -+ -+ // Reset internal DatabasePageReader -+ void Reset(); -+ -+ // True if DatabasePageReader is valid -+ bool IsValid() { return (db_reader_ != nullptr); } -+ - // True if the given reader may point to an inner page in a table B-tree. - // - // The last ReadPage() call on |db_reader| must have succeeded. -@@ -164,14 +173,14 @@ class LeafPageDecoder { - static int ComputeCellCount(DatabasePageReader* db_reader); - - // The number of the B-tree page this reader is reading. -- const int64_t page_id_; -+ int64_t page_id_; - // Used to read the tree page. - // - // Raw pointer usage is acceptable because this instance's owner is expected - // to ensure that the DatabasePageReader outlives this. -- DatabasePageReader* const db_reader_; -+ DatabasePageReader* db_reader_; - // Caches the ComputeCellCount() value for this reader's page. -- const int cell_count_ = ComputeCellCount(db_reader_); -+ int cell_count_; - - // The reader's cursor state. - // -diff --git a/sql/recover_module/cursor.cc b/sql/recover_module/cursor.cc -index 4f827edf1b4..240de4999fe 100644 ---- a/sql/recover_module/cursor.cc -+++ b/sql/recover_module/cursor.cc -@@ -28,7 +28,7 @@ VirtualCursor::~VirtualCursor() { - int VirtualCursor::First() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - inner_decoders_.clear(); -- leaf_decoder_ = nullptr; -+ leaf_decoder_.Reset(); - - AppendPageDecoder(table_->root_page_id()); - return Next(); -@@ -38,18 +38,18 @@ int VirtualCursor::Next() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - record_reader_.Reset(); - -- while (!inner_decoders_.empty() || leaf_decoder_.get()) { -- if (leaf_decoder_.get()) { -- if (!leaf_decoder_->CanAdvance()) { -+ while (!inner_decoders_.empty() || leaf_decoder_.IsValid()) { -+ if (leaf_decoder_.IsValid()) { -+ if (!leaf_decoder_.CanAdvance()) { - // The leaf has been exhausted. Remove it from the DFS stack. -- leaf_decoder_ = nullptr; -+ leaf_decoder_.Reset(); - continue; - } -- if (!leaf_decoder_->TryAdvance()) -+ if (!leaf_decoder_.TryAdvance()) - continue; - -- if (!payload_reader_.Initialize(leaf_decoder_->last_record_size(), -- leaf_decoder_->last_record_offset())) { -+ if (!payload_reader_.Initialize(leaf_decoder_.last_record_size(), -+ leaf_decoder_.last_record_offset())) { - continue; - } - if (!record_reader_.Initialize()) -@@ -101,13 +101,13 @@ int VirtualCursor::ReadColumn(int column_index, - int64_t VirtualCursor::RowId() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(record_reader_.IsInitialized()); -- DCHECK(leaf_decoder_.get()); -- return leaf_decoder_->last_record_rowid(); -+ DCHECK(leaf_decoder_.IsValid()); -+ return leaf_decoder_.last_record_rowid(); - } - - void VirtualCursor::AppendPageDecoder(int page_id) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -- DCHECK(leaf_decoder_.get() == nullptr) -+ DCHECK(!leaf_decoder_.IsValid()) - << __func__ - << " must only be called when the current path has no leaf decoder"; - -@@ -115,7 +115,7 @@ void VirtualCursor::AppendPageDecoder(int page_id) { - return; - - if (LeafPageDecoder::IsOnValidPage(&db_reader_)) { -- leaf_decoder_ = std::make_unique(&db_reader_); -+ leaf_decoder_.Initialize(&db_reader_); - return; - } - -diff --git a/sql/recover_module/cursor.h b/sql/recover_module/cursor.h -index 845b7852648..cc4e85f83f9 100644 ---- a/sql/recover_module/cursor.h -+++ b/sql/recover_module/cursor.h -@@ -130,7 +130,7 @@ class VirtualCursor { - std::vector> inner_decoders_; - - // Decodes the leaf page containing records. -- std::unique_ptr leaf_decoder_; -+ LeafPageDecoder leaf_decoder_; - - SEQUENCE_CHECKER(sequence_checker_); - }; -diff --git a/sql/recover_module/pager.cc b/sql/recover_module/pager.cc -index 58e75de2704..69d98cef98d 100644 ---- a/sql/recover_module/pager.cc -+++ b/sql/recover_module/pager.cc -@@ -23,8 +23,7 @@ static_assert(DatabasePageReader::kMaxPageId <= std::numeric_limits::max(), - "ints are not appropriate for representing page IDs"); - - DatabasePageReader::DatabasePageReader(VirtualTable* table) -- : page_data_(std::make_unique(table->page_size())), -- table_(table) { -+ : page_data_(table->page_size()), table_(table) { - DCHECK(table != nullptr); - DCHECK(IsValidPageSize(table->page_size())); - } -@@ -58,7 +57,7 @@ int DatabasePageReader::ReadPage(int page_id) { - "The |read_offset| computation above may overflow"); - - int sqlite_status = -- RawRead(sqlite_file, read_size, read_offset, page_data_.get()); -+ RawRead(sqlite_file, read_size, read_offset, page_data_.data()); - - // |page_id_| needs to be set to kInvalidPageId if the read failed. - // Otherwise, future ReadPage() calls with the previous |page_id_| value -diff --git a/sql/recover_module/pager.h b/sql/recover_module/pager.h -index 07cac3cb989..d08f0932fab 100644 ---- a/sql/recover_module/pager.h -+++ b/sql/recover_module/pager.h -@@ -6,8 +6,8 @@ - #define SQL_RECOVER_MODULE_PAGER_H_ - - #include --#include - #include -+#include - - #include "base/check_op.h" - #include "base/memory/raw_ptr.h" -@@ -72,7 +72,7 @@ class DatabasePageReader { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK_NE(page_id_, kInvalidPageId) - << "Successful ReadPage() required before accessing pager state"; -- return page_data_.get(); -+ return page_data_.data(); - } - - // The number of bytes in the page read by the last ReadPage() call. -@@ -139,7 +139,7 @@ class DatabasePageReader { - int page_id_ = kInvalidPageId; - // Stores the bytes of the last page successfully read by ReadPage(). - // The content is undefined if the last call to ReadPage() did not succeed. -- const std::unique_ptr page_data_; -+ std::vector page_data_; - // Raw pointer usage is acceptable because this instance's owner is expected - // to ensure that the VirtualTable outlives this. - const raw_ptr table_; diff --git a/aur-patches/unbundle-jsoncpp-avoid-CFI-faults-with-is_cfi-true.patch b/aur-patches/unbundle-jsoncpp-avoid-CFI-faults-with-is_cfi-true.patch new file mode 100644 index 0000000..7bf1b5c --- /dev/null +++ b/aur-patches/unbundle-jsoncpp-avoid-CFI-faults-with-is_cfi-true.patch @@ -0,0 +1,38 @@ +From ed8d931e35f81d8566835a579caf7d61368f85b7 Mon Sep 17 00:00:00 2001 +From: Evangelos Foutras +Date: Tue, 27 Sep 2022 22:20:41 +0000 +Subject: [PATCH] unbundle/jsoncpp: avoid CFI faults with is_cfi=true + +Ensure jsoncpp symbols have public visibility and are thus excluded from +CFI checks and whole-program optimization. This is achieved by defining +JSON_DLL_BUILD which in turn causes json/config.h to define JSON_API as +__attribute__((visibility("default"))). The latter macro is used to tag +jsoncpp classes and namespace functions throughout jsoncpp's headers. + +BUG=1365218 + +Change-Id: I56277737b7d9ecaeb5e17c8d21a2e55f3d5d5bc9 +Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3919652 +Reviewed-by: Thomas Anderson +Commit-Queue: Thomas Anderson +Cr-Commit-Position: refs/heads/main@{#1052077} +--- + build/linux/unbundle/jsoncpp.gn | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/build/linux/unbundle/jsoncpp.gn b/build/linux/unbundle/jsoncpp.gn +index 544f9d13c9..e84a0ef27a 100644 +--- a/build/linux/unbundle/jsoncpp.gn ++++ b/build/linux/unbundle/jsoncpp.gn +@@ -3,6 +3,11 @@ import("//build/shim_headers.gni") + + pkg_config("jsoncpp_config") { + packages = [ "jsoncpp" ] ++ ++ # Defining JSON_DLL_BUILD applies public visibility to jsoncpp classes ++ # thus deactivating CFI checks for them. This avoids CFI violations in ++ # virtual calls to system jsoncpp library (https://crbug.com/1365218). ++ defines = [ "JSON_DLL_BUILD" ] + } + + shim_headers("jsoncpp_shim") { diff --git a/aur-patches/wayland-egl.patch b/aur-patches/wayland-egl.patch deleted file mode 100644 index 58a0798..0000000 --- a/aur-patches/wayland-egl.patch +++ /dev/null @@ -1,22 +0,0 @@ ---- a/ui/gl/gl_image_native_pixmap.cc 2020-05-18 11:40:06.000000000 -0700 -+++ b/ui/gl/gl_image_native_pixmap.cc 2020-05-22 02:07:16.007770442 -0700 -@@ -288,6 +288,8 @@ - std::move(scoped_fd)); - } - -+ handle.planes[0].size = size_.GetArea(); -+ - return handle; - #endif // !defined(OS_FUCHSIA) - } ---- a/gpu/command_buffer/service/error_state.cc 2020-05-18 11:39:22.000000000 -0700 -+++ b/gpu/command_buffer/service/error_state.cc 2020-05-22 13:43:09.181180388 -0700 -@@ -115,6 +115,8 @@ - // buffer. - error = GL_NO_ERROR; - } -+ if (error == GL_INVALID_ENUM) -+ error = GL_NO_ERROR; - return error; - } - diff --git a/makefile b/makefile index 32db5b3..677c6a5 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,19 @@ # Build requires gn and ninja # also clang, clang++, ar, nm +update-repos: + # launcher + cd ungoogled-chromium && git pull + # installer from AUR (for patch/build reference) + cd aur-ungoogled-chromium && git pull + # extra patches (used by aur-ungoogled-chromium) + cd chromium-patches && git pull + +update-aur-patches: + rm -rf aur-patches + mkdir aur-patches + cp aur-ungoogled-chromium/*.patch aur-patches + # ungoogled-chromium way retrieve: mkdir -p chromium-downloads @@ -19,33 +32,42 @@ checkout: apply-aur-mods: cd chromium-src && ../aur-mods.sh +## MANUALLY ## +# Copy the "patch" lines from aur-ungoogled-chromium/PKGBUILD into the following target +# add cd chromium-src && before each line +# rename "../patches" to "../chromium-patches" +# rename "../" to "../aur-patches" apply-aur-patches: # Use the --oauth2-client-id= and --oauth2-client-secret= switches for # setting GOOGLE_DEFAULT_CLIENT_ID and GOOGLE_DEFAULT_CLIENT_SECRET at # runtime -- this allows signing into Chromium without baked-in values cd chromium-src && patch -Np1 -i ../aur-patches/use-oauth2-client-switches-as-default.patch - # Remove '-Xclang -no-opaque-pointers' flag not supported by our clang - cd chromium-src && patch -Np1 -i ../aur-patches/remove-no-opaque-pointers-flag.patch - # Upstream fixes + cd chromium-src && patch -Np1 -i ../aur-patches/unbundle-jsoncpp-avoid-CFI-faults-with-is_cfi-true.patch # Revert kGlobalMediaControlsCastStartStop enabled by default # https://crbug.com/1314342 - cd chromium-src && patch -Rp1 -F3 -i ../aur-patches/enable-GlobalMediaControlsCastStartStop.patch + cd chromium-src && patch -Rp1 -F3 -i ../aur-patches/REVERT-enable-GlobalMediaControlsCastStartStop.patch - # https://chromium-review.googlesource.com/c/chromium/src/+/3488058 - #archived cd chromium-src && patch -Np1 -i ../aur-patches/chromium-libxml-unbundle.patch - # Revert ffmpeg roll requiring new channel layout API support # https://crbug.com/1325301 - cd chromium-src && patch -Rp1 -i ../aur-patches/roll-src-third_party-ffmpeg.patch + cd chromium-src && patch -Rp1 -i ../aur-patches/REVERT-roll-src-third_party-ffmpeg-m102.patch + # Revert switch from AVFrame::pkt_duration to AVFrame::duration + cd chromium-src && patch -Rp1 -i ../aur-patches/REVERT-roll-src-third_party-ffmpeg-m106.patch - # https://chromium-review.googlesource.com/c/chromium/src/+/2862724 - cd chromium-src && patch -Np1 -i ../aur-patches/sql-make-VirtualCursor-standard-layout-type.patch + # https://crbug.com/angleproject/7582 + cd chromium-src && patch -Np0 -i ../aur-patches/angle-wayland-include-protocol.patch - # Wayland/EGL regression (crbug #1071528 #1071550) - cd chromium-src && patch -Np1 -i ../aur-patches/wayland-egl.patch + # Fixes for building with libstdc++ instead of libc++ + cd chromium-src && patch -Np1 -i ../chromium-patches/chromium-103-VirtualCursor-std-layout.patch + cd chromium-src && patch -Np1 -i ../chromium-patches/chromium-106-AutofillPopupControllerImpl-namespace.patch + + # Enable vaapi on wayland + cd chromium-src && patch -Np1 -i ../aur-patches/ozone-add-va-api-support-to-wayland.patch + + # Remove HEVC profile limits + cd chromium-src && patch -Np1 -i ../aur-patches/remove-main-main10-profile-limit.patch # Ungoogled Chromium Steps prune-binaries: @@ -55,8 +77,16 @@ apply-ungoogle-patches: ./ungoogled-chromium/utils/patches.py apply chromium-src ./ungoogled-chromium/patches apply-michael-patches: + cd chromium-src && git init + cd chromium-src && git add chrome + cd chromium-src && git commit -m 'chrome' cd chromium-src && patch -Np1 -i ../michael-patches/michael-customizations.patch +# only needed if patches need updates i.e. hunks failed +update-michael-patches: + cd chromium-src && git diff -p > ../michael-patches/michael-customizations.patch + +# may warn/info about "path has no substitutions" a few (10-20) times subst-domains: mkdir -p chromium-src/cache ./ungoogled-chromium/utils/domain_substitution.py apply \ diff --git a/michael-patches-tempfiles/chrome/browser/ui/tabs/tab_menu_model.cc b/michael-patches-tempfiles/chrome/browser/ui/tabs/tab_menu_model.cc new file mode 100644 index 0000000..a5afac8 --- /dev/null +++ b/michael-patches-tempfiles/chrome/browser/ui/tabs/tab_menu_model.cc @@ -0,0 +1,156 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/tabs/tab_menu_model.h" + +#include "base/command_line.h" +#include "base/i18n/rtl.h" +#include "base/metrics/user_metrics.h" +#include "build/build_config.h" +#include "chrome/app/vector_icons/vector_icons.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h" +#include "chrome/browser/ui/tabs/existing_tab_group_sub_menu_model.h" +#include "chrome/browser/ui/tabs/existing_window_sub_menu_model.h" +#include "chrome/browser/ui/tabs/tab_menu_model_delegate.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" +#include "chrome/browser/ui/tabs/tab_utils.h" +#include "chrome/browser/ui/ui_features.h" +#include "chrome/common/chrome_features.h" +#include "chrome/grit/generated_resources.h" +#include "components/feed/feed_feature_list.h" +#include "components/reading_list/features/reading_list_switches.h" +#include "ui/base/l10n/l10n_util.h" + +using base::UserMetricsAction; + +TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate, + TabMenuModelDelegate* tab_menu_model_delegate, + TabStripModel* tab_strip, + int index) + : ui::SimpleMenuModel(delegate), + tab_menu_model_delegate_(tab_menu_model_delegate) { + Build(tab_strip, index); +} + +TabMenuModel::~TabMenuModel() = default; + +void TabMenuModel::Build(TabStripModel* tab_strip, int index) { + std::vector indices; + if (tab_strip->IsTabSelected(index)) { + const ui::ListSelectionModel::SelectedIndices& sel = + tab_strip->selection_model().selected_indices(); + indices = std::vector(sel.begin(), sel.end()); + } else { + indices = {index}; + } + + int num_tabs = indices.size(); + AddItemWithStringId(TabStripModel::CommandNewTabToRight, + base::i18n::IsRTL() ? IDS_TAB_CXMENU_NEWTABTOLEFT + : IDS_TAB_CXMENU_NEWTABTORIGHT); + // Add to Reading List + // if (!tab_strip->profile()->IsGuestSession()) { + // AddItem( + // TabStripModel::CommandAddToReadLater, + // l10n_util::GetPluralStringFUTF16(IDS_TAB_CXMENU_READ_LATER, num_tabs)); + // SetEnabledAt(GetItemCount() - 1, + // tab_strip->IsReadLaterSupportedForAny(indices)); + // } + // Change Tab Group + // if (ExistingTabGroupSubMenuModel::ShouldShowSubmenu( + // tab_strip, index, tab_menu_model_delegate_)) { + // // Create submenu with existing groups + // add_to_existing_group_submenu_ = + // std::make_unique( + // delegate(), tab_menu_model_delegate_, tab_strip, index); + // AddSubMenu(TabStripModel::CommandAddToExistingGroup, + // l10n_util::GetPluralStringFUTF16(IDS_TAB_CXMENU_ADD_TAB_TO_GROUP, + // num_tabs), + // add_to_existing_group_submenu_.get()); + // if (base::FeatureList::IsEnabled(features::kTabGroupsNewBadgePromo)) + // SetIsNewFeatureAt(GetItemCount() - 1, true); + // } else { + // AddItem(TabStripModel::CommandAddToNewGroup, + // l10n_util::GetPluralStringFUTF16( + // IDS_TAB_CXMENU_ADD_TAB_TO_NEW_GROUP, num_tabs)); + // SetElementIdentifierAt(GetItemCount() - 1, kAddToNewGroupItemIdentifier); + // if (base::FeatureList::IsEnabled(features::kTabGroupsNewBadgePromo)) + // SetIsNewFeatureAt(GetItemCount() - 1, true); + // } + + // for (const auto& selection : indices) { + // if (tab_strip->GetTabGroupForTab(selection).has_value()) { + // AddItemWithStringId(TabStripModel::CommandRemoveFromGroup, + // IDS_TAB_CXMENU_REMOVE_TAB_FROM_GROUP); + // break; + // } + // } + + // New Window / Move to other Window + if (ExistingWindowSubMenuModel::ShouldShowSubmenu(tab_strip->profile())) { + // Create submenu with existing windows + add_to_existing_window_submenu_ = ExistingWindowSubMenuModel::Create( + delegate(), tab_menu_model_delegate_, tab_strip, index); + AddSubMenu(TabStripModel::CommandMoveToExistingWindow, + l10n_util::GetPluralStringFUTF16( + IDS_TAB_CXMENU_MOVETOANOTHERWINDOW, num_tabs), + add_to_existing_window_submenu_.get()); + } else { + AddItem(TabStripModel::CommandMoveTabsToNewWindow, + l10n_util::GetPluralStringFUTF16( + IDS_TAB_CXMENU_MOVE_TABS_TO_NEW_WINDOW, num_tabs)); + } + + AddSeparator(ui::NORMAL_SEPARATOR); + // AddItemWithStringId(TabStripModel::CommandCloseTab, IDS_TAB_CXMENU_CLOSETAB); + AddItemWithStringId(TabStripModel::CommandCloseOtherTabs, + IDS_TAB_CXMENU_CLOSEOTHERTABS); + AddItemWithStringId(TabStripModel::CommandCloseTabsToRight, + base::i18n::IsRTL() ? IDS_TAB_CXMENU_CLOSETABSTOLEFT + : IDS_TAB_CXMENU_CLOSETABSTORIGHT); + + AddSeparator(ui::NORMAL_SEPARATOR); + // AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD); + // AddItemWithStringId(TabStripModel::CommandDuplicate, + // IDS_TAB_CXMENU_DUPLICATE); + bool will_pin = tab_strip->WillContextMenuPin(index); + AddItemWithStringId( + TabStripModel::CommandTogglePinned, + will_pin ? IDS_TAB_CXMENU_PIN_TAB : IDS_TAB_CXMENU_UNPIN_TAB); + const bool will_mute = !chrome::AreAllSitesMuted(*tab_strip, indices); + AddItem(TabStripModel::CommandToggleSiteMuted, + will_mute ? l10n_util::GetPluralStringFUTF16( + IDS_TAB_CXMENU_SOUND_MUTE_SITE, num_tabs) + : l10n_util::GetPluralStringFUTF16( + IDS_TAB_CXMENU_SOUND_UNMUTE_SITE, num_tabs)); + if (base::FeatureList::IsEnabled(feed::kWebUiFeed)) { + const TabWebFeedFollowState follow_state = + chrome::GetAggregatedFollowStateOfAllSites(*tab_strip, indices); + if (follow_state == TabWebFeedFollowState::kNotFollowed) { + AddItemWithStringId(TabStripModel::CommandFollowSite, + IDS_TAB_CXMENU_FOLLOW_SITE); + } else if (follow_state == TabWebFeedFollowState::kFollowed) { + AddItemWithStringId(TabStripModel::CommandUnfollowSite, + IDS_TAB_CXMENU_UNFOLLOW_SITE); + } + } + if (send_tab_to_self::ShouldDisplayEntryPoint( + tab_strip->GetWebContentsAt(index))) { + AddSeparator(ui::NORMAL_SEPARATOR); +#if BUILDFLAG(IS_MAC) + AddItem(TabStripModel::CommandSendTabToSelf, + l10n_util::GetStringUTF16(IDS_CONTEXT_MENU_SEND_TAB_TO_SELF)); +#else + AddItemWithIcon( + TabStripModel::CommandSendTabToSelf, + l10n_util::GetStringUTF16(IDS_CONTEXT_MENU_SEND_TAB_TO_SELF), + ui::ImageModel::FromVectorIcon(kLaptopAndSmartphoneIcon)); +#endif + } +} + +DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(TabMenuModel, + kAddToNewGroupItemIdentifier); diff --git a/michael-patches-tempfiles/chrome/browser/ui/views/location_bar/location_bar_view.cc b/michael-patches-tempfiles/chrome/browser/ui/views/location_bar/location_bar_view.cc new file mode 100644 index 0000000..0939f1e --- /dev/null +++ b/michael-patches-tempfiles/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -0,0 +1,1478 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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/location_bar/location_bar_view.h" + +#include +#include +#include +#include + +#include "base/bind.h" +#include "base/containers/adapters.h" +#include "base/feature_list.h" +#include "base/i18n/rtl.h" +#include "base/metrics/field_trial_params.h" +#include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" +#include "build/chromeos_buildflags.h" +#include "chrome/app/chrome_command_ids.h" +#include "chrome/app/vector_icons/vector_icons.h" +#include "chrome/browser/accuracy_tips/accuracy_service_factory.h" +#include "chrome/browser/apps/intent_helper/intent_picker_features.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/browser_process_platform_part.h" +#include "chrome/browser/command_updater.h" +#include "chrome/browser/extensions/api/omnibox/omnibox_api.h" +#include "chrome/browser/extensions/extension_ui_util.h" +#include "chrome/browser/extensions/tab_helper.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h" +#include "chrome/browser/sharing/features.h" +#include "chrome/browser/sharing/sms/sms_flags.h" +#include "chrome/browser/sharing_hub/sharing_hub_features.h" +#include "chrome/browser/ssl/security_state_tab_helper.h" +#include "chrome/browser/themes/theme_properties.h" +#include "chrome/browser/themes/theme_service.h" +#include "chrome/browser/themes/theme_service_factory.h" +#include "chrome/browser/translate/chrome_translate_client.h" +#include "chrome/browser/translate/translate_service.h" +#include "chrome/browser/ui/autofill/payments/local_card_migration_bubble_controller_impl.h" +#include "chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/color/chrome_color_id.h" +#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" +#include "chrome/browser/ui/layout_constants.h" +#include "chrome/browser/ui/omnibox/chrome_omnibox_client.h" +#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" +#include "chrome/browser/ui/side_search/side_search_utils.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/browser/ui/views/autofill/payments/local_card_migration_icon_view.h" +#include "chrome/browser/ui/views/chrome_layout_provider.h" +#include "chrome/browser/ui/views/chrome_typography.h" +#include "chrome/browser/ui/views/frame/browser_view.h" +#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" +#include "chrome/browser/ui/views/location_bar/intent_chip_button.h" +#include "chrome/browser/ui/views/location_bar/location_bar_layout.h" +#include "chrome/browser/ui/views/location_bar/location_icon_view.h" +#include "chrome/browser/ui/views/location_bar/selected_keyword_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_container.h" +#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h" +#include "chrome/browser/ui/views/page_action/page_action_icon_params.h" +#include "chrome/browser/ui/views/page_info/page_info_bubble_view.h" +#include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" +#include "chrome/browser/ui/views/permissions/permission_chip.h" +#include "chrome/browser/ui/views/permissions/permission_quiet_chip.h" +#include "chrome/browser/ui/views/permissions/permission_request_chip.h" +#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_icon_view.h" +#include "chrome/browser/ui/views/sharing_hub/sharing_hub_icon_view.h" +#include "chrome/browser/ui/web_applications/app_browser_controller.h" +#include "chrome/common/chrome_features.h" +#include "chrome/grit/chromium_strings.h" +#include "chrome/grit/generated_resources.h" +#include "components/autofill/core/common/autofill_features.h" +#include "components/autofill/core/common/autofill_payments_features.h" +#include "components/content_settings/core/common/features.h" +#include "components/dom_distiller/core/dom_distiller_features.h" +#include "components/favicon/content/content_favicon_driver.h" +#include "components/omnibox/browser/location_bar_model.h" +#include "components/omnibox/browser/omnibox_edit_model.h" +#include "components/omnibox/browser/omnibox_field_trial.h" +#include "components/omnibox/browser/omnibox_popup_view.h" +#include "components/omnibox/browser/vector_icons.h" +#include "components/omnibox/common/omnibox_features.h" +#include "components/prefs/pref_service.h" +#include "components/safe_browsing/core/common/features.h" +#include "components/search_engines/template_url.h" +#include "components/search_engines/template_url_service.h" +#include "components/security_state/core/security_state.h" +#include "components/strings/grit/components_strings.h" +#include "components/translate/core/browser/language_state.h" +#include "components/variations/variations_associated_data.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/render_widget_host_view.h" +#include "content/public/browser/web_contents.h" +#include "content/public/common/content_features.h" +#include "content/public/common/url_constants.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/common/feature_switch.h" +#include "third_party/blink/public/common/features.h" +#include "third_party/metrics_proto/omnibox_event.pb.h" +#include "ui/accessibility/ax_enums.mojom.h" +#include "ui/accessibility/ax_node_data.h" +#include "ui/base/clipboard/clipboard.h" +#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/ime/input_method.h" +#include "ui/base/ime/virtual_keyboard_controller.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/metadata/metadata_impl_macros.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_features.h" +#include "ui/color/color_provider.h" +#include "ui/compositor/layer.h" +#include "ui/compositor/paint_recorder.h" +#include "ui/events/event.h" +#include "ui/gfx/animation/slide_animation.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/geometry/skia_conversions.h" +#include "ui/gfx/image/image.h" +#include "ui/gfx/paint_vector_icon.h" +#include "ui/gfx/scoped_canvas.h" +#include "ui/gfx/text_utils.h" +#include "ui/gfx/vector_icon_types.h" +#include "ui/views/background.h" +#include "ui/views/border.h" +#include "ui/views/button_drag_utils.h" +#include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/button/image_button_factory.h" +#include "ui/views/controls/focus_ring.h" +#include "ui/views/controls/highlight_path_generator.h" +#include "ui/views/controls/label.h" +#include "ui/views/style/typography.h" +#include "ui/views/view_utils.h" +#include "ui/views/widget/widget.h" + +namespace { + +int IncrementalMinimumWidth(const views::View* view) { + return (view && view->GetVisible()) ? view->GetMinimumSize().width() : 0; +} + +// Whether the omnibox enables either of 2 prefix autocompletion features. +bool OmniboxPrefixRichAutocompletionEnabled() { + return OmniboxFieldTrial::kRichAutocompletionAutocompleteNonPrefixAll.Get() || + OmniboxFieldTrial:: + kRichAutocompletionAutocompleteNonPrefixShortcutProvider.Get(); +} + +} // namespace + +using content::WebContents; +using metrics::OmniboxEventProto; +using views::View; + +// LocationBarView ----------------------------------------------------------- + +LocationBarView::LocationBarView(Browser* browser, + Profile* profile, + CommandUpdater* command_updater, + Delegate* delegate, + bool is_popup_mode) + : AnimationDelegateViews(this), + ChromeOmniboxEditController(browser, profile, command_updater), + browser_(browser), + profile_(profile), + delegate_(delegate), + is_popup_mode_(is_popup_mode) { + set_suppress_default_focus_handling(); + if (!is_popup_mode_) { + views::FocusRing::Install(this); + views::FocusRing::Get(this)->SetHasFocusPredicate([](View* view) -> bool { + DCHECK(views::IsViewClass(view)); + auto* v = static_cast(view); + + // Show focus ring when the Omnibox is visibly focused and the popup is + // closed. + return v->omnibox_view_->model()->is_caret_visible() && + !v->GetOmniboxPopupView()->IsOpen(); + }); + + views::FocusRing::Get(this)->SetPathGenerator( + std::make_unique()); + +#if BUILDFLAG(IS_MAC) + geolocation_permission_observation_.Observe( + g_browser_process->platform_part()->geolocation_manager()); +#endif + + if (base::FeatureList::IsEnabled(safe_browsing::kAccuracyTipsFeature)) { + if (auto* accuracy_service = + AccuracyServiceFactory::GetForProfile(profile)) + accuracy_service_observation_.Observe(accuracy_service); + } + } +} + +LocationBarView::~LocationBarView() = default; + +void LocationBarView::Init() { + // We need to be in a Widget, otherwise GetNativeTheme() may change and we're + // not prepared for that. + DCHECK(GetWidget()); + + // Note that children with layers are *not* clipped, because focus rings have + // to draw outside the parent's bounds. + SetPaintToLayer(); + layer()->SetFillsBoundsOpaquely(false); + + CreateChip(); + + const gfx::FontList& font_list = views::style::GetFont( + CONTEXT_OMNIBOX_PRIMARY, views::style::STYLE_PRIMARY); + + auto location_icon_view = + std::make_unique(font_list, this, this); + location_icon_view->set_drag_controller(this); + location_icon_view_ = AddChildView(std::move(location_icon_view)); + + // Initialize the Omnibox view. + auto omnibox_view = std::make_unique( + this, std::make_unique(this, profile_), + is_popup_mode_, this, font_list); + omnibox_view->Init(); + omnibox_view_ = AddChildView(std::move(omnibox_view)); + // LocationBarView directs mouse button events from + // |omnibox_additional_text_view_| to |omnibox_view_| so that e.g., clicking + // the former will focus the latter. In order to receive |ShowContextMenu()| + // requests, LocationBarView must have a context menu controller. + set_context_menu_controller(omnibox_view_->context_menu_controller()); + + RefreshBackground(); + + // Initialize the IME autocomplete labels which are visible only when IME is + // turned on. Use the same font with the omnibox and highlighted background. + const auto* const color_provider = GetColorProvider(); + auto CreateImeAutocompletionLabel = + [&](gfx::HorizontalAlignment horizontal_alignment) { + auto label = std::make_unique( + std::u16string(), views::Label::CustomFont{font_list}); + label->SetHorizontalAlignment(horizontal_alignment); + label->SetElideBehavior(gfx::NO_ELIDE); + label->SetAutoColorReadabilityEnabled(false); + label->SetBackground(views::CreateSolidBackground( + color_provider->GetColor(kColorLocationBarBackground))); + label->SetEnabledColor(color_provider->GetColor(kColorOmniboxText)); + label->SetVisible(false); + return label; + }; + + if (OmniboxPrefixRichAutocompletionEnabled()) { + ime_prefix_autocomplete_view_ = + AddChildView(CreateImeAutocompletionLabel(gfx::ALIGN_RIGHT)); + } + ime_inline_autocomplete_view_ = + AddChildView(CreateImeAutocompletionLabel(gfx::ALIGN_LEFT)); + + // Initiate the Omnibox additional-text label. + if (OmniboxFieldTrial::RichAutocompletionShowAdditionalText()) { + auto omnibox_additional_text_view = std::make_unique( + std::u16string(), ChromeTextContext::CONTEXT_OMNIBOX_DEEMPHASIZED, + views::style::STYLE_LINK); + omnibox_additional_text_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); + omnibox_additional_text_view->SetFontList(font_list); + omnibox_additional_text_view->SetVisible(false); + omnibox_additional_text_view_ = + AddChildView(std::move(omnibox_additional_text_view)); + } + + selected_keyword_view_ = AddChildView(std::make_unique( + this, TemplateURLServiceFactory::GetForProfile(profile_), font_list)); + + if (apps::features::LinkCapturingUiUpdateEnabled()) { + intent_chip_ = + AddChildView(std::make_unique(browser_, this)); + } + + SkColor icon_color = color_provider->GetColor(kColorOmniboxResultsIcon); + + std::vector> models = + ContentSettingImageModel::GenerateContentSettingImageModels(); + for (auto& model : models) { + auto image_view = std::make_unique( + std::move(model), this, this, font_list); + image_view->SetIconColor(icon_color); + image_view->SetVisible(false); + content_setting_views_.push_back(AddChildView(std::move(image_view))); + } + + PageActionIconParams params; + // |browser_| may be null when LocationBarView is used for non-Browser windows + // such as PresentationReceiverWindowView, which do not support page actions. + if (browser_) { + // Page action icons that participate in label animations should be added + // first so that they appear on the left side of the icon container. + // TODO(crbug.com/1318890): Improve the ordering heuristics for page action + // icons and determine a way to handle simultaneous icon animations. + if (side_search::IsDSESupportEnabled(profile_) && + side_search::IsEnabledForBrowser(browser_)) { + params.types_enabled.push_back(PageActionIconType::kSideSearch); + } + params.types_enabled.push_back(PageActionIconType::kSendTabToSelf); + params.types_enabled.push_back(PageActionIconType::kClickToCall); + if (!base::FeatureList::IsEnabled(kDisableQRGenerator)) + params.types_enabled.push_back(PageActionIconType::kQRCodeGenerator); + if (base::FeatureList::IsEnabled(kWebOTPCrossDevice)) + params.types_enabled.push_back(PageActionIconType::kSmsRemoteFetcher); + params.types_enabled.push_back(PageActionIconType::kManagePasswords); + if (!apps::features::LinkCapturingUiUpdateEnabled()) + params.types_enabled.push_back(PageActionIconType::kIntentPicker); + params.types_enabled.push_back(PageActionIconType::kPwaInstall); + params.types_enabled.push_back(PageActionIconType::kFind); + params.types_enabled.push_back(PageActionIconType::kTranslate); + params.types_enabled.push_back(PageActionIconType::kZoom); + params.types_enabled.push_back(PageActionIconType::kFileSystemAccess); + + if (dom_distiller::IsDomDistillerEnabled() && browser_->is_type_normal()) { + params.types_enabled.push_back(PageActionIconType::kReaderMode); + } + params.types_enabled.push_back(PageActionIconType::kCookieControls); + params.types_enabled.push_back( + PageActionIconType::kPaymentsOfferNotification); + } + // Add icons only when feature is not enabled. Otherwise icons will + // be added to the ToolbarPageActionIconContainerView. + params.types_enabled.push_back(PageActionIconType::kSaveCard); + params.types_enabled.push_back(PageActionIconType::kLocalCardMigration); + params.types_enabled.push_back( + PageActionIconType::kVirtualCardManualFallback); + params.types_enabled.push_back(PageActionIconType::kVirtualCardEnroll); + + if (base::FeatureList::IsEnabled( + autofill::features::kAutofillAddressProfileSavePrompt)) { + // TODO(crbug.com/1167060): Place this in the proper order upon having + // final mocks. + params.types_enabled.push_back(PageActionIconType::kSaveAutofillAddress); + } + // Remove sharing hub icon + // if (browser_) { + // if (sharing_hub::HasPageAction(profile_, is_popup_mode_)) + // params.types_enabled.push_back(PageActionIconType::kSharingHub); + // } + if (browser_ && !is_popup_mode_) + params.types_enabled.push_back(PageActionIconType::kBookmarkStar); + + params.icon_color = icon_color; + params.between_icon_spacing = 0; + params.font_list = &font_list; + params.browser = browser_; + params.command_updater = command_updater(); + params.icon_label_bubble_delegate = this; + params.page_action_icon_delegate = this; + page_action_icon_container_ = + AddChildView(std::make_unique(params)); + page_action_icon_controller_ = page_action_icon_container_->controller(); + + auto clear_all_button = views::CreateVectorImageButton(base::BindRepeating( + static_cast( + &OmniboxView::SetUserText), + base::Unretained(omnibox_view_), std::u16string())); + clear_all_button->SetTooltipText( + l10n_util::GetStringUTF16(IDS_OMNIBOX_CLEAR_ALL)); + clear_all_button_ = AddChildView(std::move(clear_all_button)); + RefreshClearAllButtonIcon(); + + // Initialize the location entry. We do this to avoid a black flash which is + // visible when the location entry has just been initialized. + Update(nullptr); + + hover_animation_.SetSlideDuration(base::Milliseconds(200)); + + is_initialized_ = true; +} + +bool LocationBarView::IsInitialized() const { + return is_initialized_; +} + +int LocationBarView::GetBorderRadius() const { + return ChromeLayoutProvider::Get()->GetCornerRadiusMetric( + views::Emphasis::kMaximum, size()); +} + +std::unique_ptr LocationBarView::CreateRoundRectBackground( + SkColor background_color, + SkColor stroke_color, + SkBlendMode blend_mode, + bool antialias) const { + const int radius = GetBorderRadius(); + auto painter = + stroke_color == SK_ColorTRANSPARENT + ? views::Painter::CreateSolidRoundRectPainter( + background_color, radius, gfx::Insets(), blend_mode, antialias) + : views::Painter::CreateRoundRectWith1PxBorderPainter( + background_color, stroke_color, radius, blend_mode, antialias); + std::unique_ptr background = + CreateBackgroundFromPainter(std::move(painter)); + background->SetNativeControlColor(background_color); + return background; +} + +gfx::Point LocationBarView::GetOmniboxViewOrigin() const { + gfx::Point origin(omnibox_view_->origin()); + origin.set_x(GetMirroredXInView(origin.x())); + views::View::ConvertPointToScreen(this, &origin); + return origin; +} + +void LocationBarView::SetImePrefixAutocompletion(const std::u16string& text) { + DCHECK(OmniboxPrefixRichAutocompletionEnabled() || text.empty()); + if (OmniboxPrefixRichAutocompletionEnabled()) + SetOmniboxAdjacentText(ime_prefix_autocomplete_view_, text); +} + +std::u16string LocationBarView::GetImePrefixAutocompletion() const { + return OmniboxPrefixRichAutocompletionEnabled() + ? ime_prefix_autocomplete_view_->GetText() + : u""; +} + +void LocationBarView::SetImeInlineAutocompletion(const std::u16string& text) { + SetOmniboxAdjacentText(ime_inline_autocomplete_view_, text); +} + +std::u16string LocationBarView::GetImeInlineAutocompletion() const { + return ime_inline_autocomplete_view_->GetText(); +} + +void LocationBarView::SetOmniboxAdditionalText(const std::u16string& text) { + DCHECK(OmniboxFieldTrial::IsRichAutocompletionEnabled() || text.empty()); + if (!OmniboxFieldTrial::RichAutocompletionShowAdditionalText()) + return; + + std::u16string adjusted_text; + if (!text.empty()) { + const int message_id = + OmniboxFieldTrial::kRichAutocompletionAdditionalTextWithParenthesis + .Get() + ? IDS_OMNIBOX_ADDITIONAL_TEXT_PARENTHESIS_TEMPLATE + : IDS_OMNIBOX_ADDITIONAL_TEXT_DASH_TEMPLATE; + adjusted_text = text; + base::i18n::AdjustStringForLocaleDirection(&adjusted_text); + adjusted_text = l10n_util::GetStringFUTF16(message_id, u"", adjusted_text); + } + SetOmniboxAdjacentText(omnibox_additional_text_view_, adjusted_text); +} + +std::u16string LocationBarView::GetOmniboxAdditionalText() const { + return OmniboxFieldTrial::RichAutocompletionShowAdditionalText() + ? omnibox_additional_text_view_->GetText() + : u""; +} + +void LocationBarView::SetOmniboxAdjacentText(views::Label* label, + const std::u16string& text) { + if (text == label->GetText()) + return; + label->SetText(text); + label->SetVisible(!text.empty()); + OnPropertyChanged(&label, views::kPropertyEffectsLayout); +} + +void LocationBarView::SelectAll() { + omnibox_view_->SelectAll(true); +} + +void LocationBarView::FocusLocation(bool is_user_initiated) { + omnibox_view_->SetFocus(is_user_initiated); +} + +void LocationBarView::Revert() { + omnibox_view_->RevertAll(); +} + +OmniboxView* LocationBarView::GetOmniboxView() { + return omnibox_view_; +} + +bool LocationBarView::HasFocus() const { + return omnibox_view_ && omnibox_view_->model()->has_focus(); +} + +void LocationBarView::GetAccessibleNodeData(ui::AXNodeData* node_data) { + node_data->role = ax::mojom::Role::kGroup; +} + +gfx::Size LocationBarView::GetMinimumSize() const { + const int height = GetLayoutConstant(LOCATION_BAR_HEIGHT); + if (!IsInitialized()) + return gfx::Size(0, height); + + const int inset_width = GetInsets().width(); + const int padding = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); + const int leading_width = GetMinimumLeadingWidth(); + const int omnibox_width = omnibox_view_->GetMinimumSize().width(); + const int trailing_width = GetMinimumTrailingWidth(); + + // The minimum width of the location bar is defined to be the greater of the + // minimum width of the location text field and the space required for the + // other child views. This ensures that the location bar can shrink + // significantly when the browser window is small and the toolbar is crowded + // but also keeps the minimum size relatively stable when the number and size + // of location bar child views changes (i.e. when there are multiple status + // indicators and a large security chip vs. just the location text). + int alt_width = leading_width + padding + trailing_width; + int width = inset_width + std::max(omnibox_width, alt_width); + + return gfx::Size(width, height); +} + +gfx::Size LocationBarView::CalculatePreferredSize() const { + const int height = GetLayoutConstant(LOCATION_BAR_HEIGHT); + if (!IsInitialized()) + return gfx::Size(0, height); + + const int inset_width = GetInsets().width(); + const int padding = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); + const int leading_width = GetMinimumLeadingWidth(); + const int omnibox_width = omnibox_view_->GetMinimumSize().width(); + const int trailing_width = GetMinimumTrailingWidth(); + + // The preferred size (unlike the minimum size) of the location bar is roughly + // the combined size of all child views including the omnibox/location field. + // While the location bar can scale down to its minimum size, it will continue + // to displace lower-priority views such as visible extensions if it cannot + // achieve its preferred size. + // + // It might be useful to track the preferred size of the location bar to see + // how much visual clutter users are experiencing on a regular basis, + // especially as we add more indicators to the bar. + int width = inset_width + omnibox_width; + if (leading_width > 0) + width += leading_width + padding; + if (trailing_width > 0) + width += trailing_width + padding; + + return gfx::Size(width, height); +} + +void LocationBarView::OnKeywordFaviconFetched(const gfx::Image& icon) { + DCHECK(!icon.IsEmpty()); + selected_keyword_view_->SetCustomImage(icon); +} + +void LocationBarView::Layout() { + if (!IsInitialized()) + return; + + selected_keyword_view_->SetVisible(false); + + const int edge_padding = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); + + // The text should be indented only if these are all true: + // - The popup is open. + // - The location icon view does *not* have a label. + // - The selected keyword view is *not* shown. + // + // In most cases, we only care that the popup is open, in which case we + // indent to align with the text in the popup. But there's two edge cases: + // - If there is text in the location icon view (which can happen with zero + // suggest, which continues to show security or EV cert text at the same + // time as the popup is open), the text in the omnibox can't align with + // the text of the suggestions, so the indent just moves the text for no + // apparent reason. + // - If there is a selected keyword label (i.e. "Search Google") shown, we + // already indent this label to align with the suggestions text, so + // further indenting the textfield just moves the text for no apparent + // reason. + // + // TODO(jdonnelly): The better solution may be to remove the location icon + // text when zero suggest triggers. + const bool should_indent = GetOmniboxPopupView()->IsOpen() && + !location_icon_view_->ShouldShowLabel() && + !ShouldShowKeywordBubble(); + + // We have an odd indent value because this is what matches the odd text + // indent value in OmniboxMatchCellView. + constexpr int kTextJogIndentDp = 11; + int leading_edit_item_padding = should_indent ? kTextJogIndentDp : 0; + + // We always subtract the left padding of the OmniboxView itself to allow for + // an extended I-beam click target without affecting actual layout. + leading_edit_item_padding -= omnibox_view_->GetInsets().left(); + + LocationBarLayout leading_decorations(LocationBarLayout::Position::kLeftEdge, + leading_edit_item_padding); + LocationBarLayout trailing_decorations( + LocationBarLayout::Position::kRightEdge, edge_padding); + + const std::u16string keyword(omnibox_view_->model()->keyword()); + // In some cases (e.g. fullscreen mode) we may have 0 height. We still want + // to position our child views in this case, because other things may be + // positioned relative to them (e.g. the "bookmark added" bubble if the user + // hits ctrl-d). + const int vertical_padding = GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING); + const int location_height = std::max(height() - (vertical_padding * 2), 0); + // The largest fraction of the omnibox that can be taken by the EV or search + // label/chip. + const double kLeadingDecorationMaxFraction = 0.5; + + if (chip_ && chip_->GetVisible() && !ShouldShowKeywordBubble()) { + leading_decorations.AddDecoration(vertical_padding, location_height, false, + 0, edge_padding, chip_); + } + + if (ShouldShowKeywordBubble()) { + location_icon_view_->SetVisible(false); + leading_decorations.AddDecoration(vertical_padding, location_height, false, + kLeadingDecorationMaxFraction, + edge_padding, selected_keyword_view_); + if (selected_keyword_view_->GetKeyword() != keyword) { + selected_keyword_view_->SetKeyword(keyword); + const TemplateURL* template_url = + TemplateURLServiceFactory::GetForProfile(profile_) + ->GetTemplateURLForKeyword(keyword); + gfx::Image image; + if (template_url && + (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION)) { + image = extensions::OmniboxAPI::Get(profile_)->GetOmniboxIcon( + template_url->GetExtensionId()); + } else if (template_url && template_url->type() == TemplateURL::NORMAL && + OmniboxFieldTrial::IsExperimentalKeywordModeEnabled()) { + image = + omnibox_view() + ->model() + ->client() + ->GetFaviconForKeywordSearchProvider( + template_url, + base::BindOnce(&LocationBarView::OnKeywordFaviconFetched, + base::Unretained(this))); + } + selected_keyword_view_->SetCustomImage(image); + } + } else if (location_icon_view_->GetShowText()) { + leading_decorations.AddDecoration(vertical_padding, location_height, false, + kLeadingDecorationMaxFraction, + edge_padding, location_icon_view_); + } else { + leading_decorations.AddDecoration(vertical_padding, location_height, false, + 0, edge_padding, location_icon_view_); + } + + auto add_trailing_decoration = [&trailing_decorations, vertical_padding, + location_height, edge_padding](View* view) { + if (view->GetVisible()) { + trailing_decorations.AddDecoration(vertical_padding, location_height, + false, 0, edge_padding, view); + } + }; + + add_trailing_decoration(page_action_icon_container_); + for (ContentSettingImageView* view : base::Reversed(content_setting_views_)) { + add_trailing_decoration(view); + } + + if (intent_chip_) + add_trailing_decoration(intent_chip_); + + add_trailing_decoration(clear_all_button_); + + // Perform layout. + int entry_width = width(); + leading_decorations.LayoutPass1(&entry_width); + trailing_decorations.LayoutPass1(&entry_width); + leading_decorations.LayoutPass2(&entry_width); + trailing_decorations.LayoutPass2(&entry_width); + + // Compute widths needed for location bar. + int location_needed_width = omnibox_view_->GetUnelidedTextWidth(); + + int available_width = entry_width - location_needed_width; + // The bounds must be wide enough for all the decorations to fit, so if + // |entry_width| is negative, enlarge by the necessary extra space. + gfx::Rect location_bounds(0, vertical_padding, + std::max(width(), width() - entry_width), + location_height); + leading_decorations.LayoutPass3(&location_bounds, &available_width); + trailing_decorations.LayoutPass3(&location_bounds, &available_width); + + // |omnibox_view_| has an opaque background, so ensure it doesn't paint atop + // the rounded ends. + location_bounds.Intersect(GetLocalBoundsWithoutEndcaps()); + + if ((!OmniboxPrefixRichAutocompletionEnabled() || + !ime_prefix_autocomplete_view_->GetVisible()) && + !ime_inline_autocomplete_view_->GetVisible() && + (!OmniboxFieldTrial::RichAutocompletionShowAdditionalText() || + !omnibox_additional_text_view_->GetVisible())) { + // Short circuit the below logic when the additional views aren't visible. + // This is necessary as resizing the omnibox can throw off it's scroll, + // i.e., which chars are visible when its text overflows its width. + // TODO(manukh): The omnibox 1) sets its text, then 2) sets its scroll, and + // lastly 3) asks the location bar to update its layout. Step (3) may + // resize the omnibox; doing so after (2) can dirty the scroll. This + // workaround handles most cases by avoiding omnibox resizing when possible + // but it's not foolproof. E.g., accepting IME autocompletion will result + // in an incorrect scroll until the next update. Look into doing (3) before + // (2) to more robustly handle these edge cases. + omnibox_view_->SetBoundsRect(location_bounds); + + } else { + // A helper to allocate the remaining location bar width preferring calls in + // the order they're made; e.g. if there's 100px remaining, and + // `reserve_width()` is invoked with '70' and '70', the first caller will + // receive 70px and the 2nd caller will receive 30px; subsequent callers + // will receive 0px. + int remaining_width = location_bounds.width(); + const auto reserve_width = [&](int desired_width) { + int width = std::min(desired_width, remaining_width); + remaining_width -= width; + return width; + }; + // A helper to request from `reserve_width()` the width needed for `label`. + const auto reserve_label_width = [&](views::Label* label) { + if (!label || !label->GetVisible()) + return 0; + int text_width = + gfx::GetStringWidth(label->GetText(), label->font_list()); + return reserve_width(text_width + label->GetInsets().width()); + }; + + // Distribute `remaining_width` among the 4 views. + int omnibox_width = reserve_width(location_needed_width); + int ime_inline_autocomplete_width = + reserve_label_width(ime_inline_autocomplete_view_); + int ime_prefix_autocomplete_width = + reserve_label_width(ime_prefix_autocomplete_view_); + int omnibox_additional_text_width = + reserve_label_width(omnibox_additional_text_view_); + + // A helper to position `view` to the right of the previous positioned + // `view`. + int current_x = location_bounds.x(); + const auto position_view = [&](views::View* view, int width) { + if (!view || !view->GetVisible()) + return; + view->SetBounds(current_x, location_bounds.y(), width, + location_bounds.height()); + current_x = view->bounds().right(); + }; + + // Position the 4 views + position_view(ime_prefix_autocomplete_view_, ime_prefix_autocomplete_width); + position_view(omnibox_view_, omnibox_width); + position_view(ime_inline_autocomplete_view_, ime_inline_autocomplete_width); + position_view(omnibox_additional_text_view_, omnibox_additional_text_width); + } + + View::Layout(); +} + +void LocationBarView::OnThemeChanged() { + views::View::OnThemeChanged(); + // ToolbarView::Init() adds |this| to the view hierarchy before initializing, + // which will trigger an early theme change. + if (!IsInitialized()) + return; + + const SkColor icon_color = + GetColorProvider()->GetColor(kColorOmniboxResultsIcon); + page_action_icon_controller_->SetIconColor(icon_color); + for (ContentSettingImageView* image_view : content_setting_views_) + image_view->SetIconColor(icon_color); + + RefreshBackground(); + RefreshClearAllButtonIcon(); +} + +void LocationBarView::ChildPreferredSizeChanged(views::View* child) { + Layout(); + SchedulePaint(); +} + +void LocationBarView::Update(WebContents* contents) { + RefreshContentSettingViews(); + + RefreshPageActionIconViews(); + location_icon_view_->Update(/*suppress_animations=*/contents); + if (intent_chip_) + intent_chip_->Update(); + + if (contents) + omnibox_view_->OnTabChanged(contents); + else + omnibox_view_->Update(); + + PageActionIconView* send_tab_to_self_icon = + page_action_icon_controller_->GetIconView( + PageActionIconType::kSendTabToSelf); + if (send_tab_to_self_icon) + send_tab_to_self_icon->SetVisible(false); + + PageActionIconView* qr_generator_icon = + page_action_icon_controller_->GetIconView( + PageActionIconType::kQRCodeGenerator); + if (qr_generator_icon) + qr_generator_icon->SetVisible(false); + + OnChanged(); // NOTE: Calls Layout(). +} + +void LocationBarView::ResetTabState(WebContents* contents) { + omnibox_view_->ResetTabState(contents); +} + +bool LocationBarView::ActivateFirstInactiveBubbleForAccessibility() { + return page_action_icon_controller_ + ->ActivateFirstInactiveBubbleForAccessibility(); +} + +bool LocationBarView::IsChipActive() { + return chip_ && chip_->IsActive(); +} + +void LocationBarView::CreateChip() { + DCHECK(!chip_); + + if (!browser_) + return; + + if (web_app::AppBrowserController::IsWebApp(browser_)) + return; + + chip_ = AddChildViewAt(std::make_unique(), 0); +} + +PermissionChip* LocationBarView::DisplayChip( + permissions::PermissionPrompt::Delegate* delegate, + bool should_bubble_start_open) { + DCHECK(delegate); + DCHECK(chip_); + + chip_->SetupChip(std::make_unique( + browser(), delegate, should_bubble_start_open)); + + return chip_; +} + +PermissionChip* LocationBarView::DisplayQuietChip( + permissions::PermissionPrompt::Delegate* delegate, + bool should_expand) { + DCHECK(delegate); + DCHECK(chip_); + + chip_->SetupChip(std::make_unique(browser(), delegate, + should_expand)); + + return chip_; +} + +void LocationBarView::FinalizeChip() { + DCHECK(chip_); + chip_->Finalize(); + InvalidateLayout(); +} + +void LocationBarView::UpdateWithoutTabRestore() { + Update(nullptr); +} + +LocationBarModel* LocationBarView::GetLocationBarModel() { + return delegate_->GetLocationBarModel(); +} + +WebContents* LocationBarView::GetWebContents() { + return delegate_->GetWebContents(); +} + +SkColor LocationBarView::GetIconLabelBubbleSurroundingForegroundColor() const { + return GetColorProvider()->GetColor(kColorOmniboxText); +} + +SkColor LocationBarView::GetIconLabelBubbleBackgroundColor() const { + return GetColorProvider()->GetColor(kColorLocationBarBackground); +} + +bool LocationBarView::ShouldHideContentSettingImage() { + // Content setting icons are hidden at the same time as page action icons. + return ShouldHidePageActionIcons(); +} + +content::WebContents* LocationBarView::GetContentSettingWebContents() { + return GetWebContents(); +} + +ContentSettingBubbleModelDelegate* +LocationBarView::GetContentSettingBubbleModelDelegate() { + return delegate_->GetContentSettingBubbleModelDelegate(); +} + +void LocationBarView::OnSystemPermissionUpdated( + device::LocationSystemPermissionStatus new_status) { + UpdateContentSettingsIcons(); +} + +void LocationBarView::OnAccuracyTipShown() { + location_icon_view_->Update(/*suppress_animations=*/false); +} + +void LocationBarView::OnAccuracyTipClosed() { + location_icon_view_->Update(/*suppress_animations=*/false); +} + +WebContents* LocationBarView::GetWebContentsForPageActionIconView() { + return GetWebContents(); +} + +bool LocationBarView::ShouldHidePageActionIcons() const { + if (!omnibox_view_) + return false; + + // When the user is typing in the omnibox, the page action icons are no longer + // associated with the current omnibox text, so hide them. + if (omnibox_view_->model()->user_input_in_progress()) + return true; + + // Also hide them if the popup is open for any other reason, e.g. ZeroSuggest. + // The page action icons are not relevant to the displayed suggestions. + return omnibox_view_->model()->PopupIsOpen(); +} + +// static +bool LocationBarView::IsVirtualKeyboardVisible(views::Widget* widget) { + if (auto* input_method = widget->GetInputMethod()) { + auto* keyboard = input_method->GetVirtualKeyboardController(); + return keyboard && keyboard->IsKeyboardVisible(); + } + return false; +} + +// static +int LocationBarView::GetAvailableTextHeight() { + return std::max(0, GetLayoutConstant(LOCATION_BAR_HEIGHT) - + 2 * GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING)); +} + +// static +int LocationBarView::GetAvailableDecorationTextHeight() { + const int bubble_padding = + GetLayoutConstant(LOCATION_BAR_CHILD_INTERIOR_PADDING) + + GetLayoutConstant(LOCATION_BAR_BUBBLE_FONT_VERTICAL_PADDING); + return std::max( + 0, LocationBarView::GetAvailableTextHeight() - (bubble_padding * 2)); +} + +int LocationBarView::GetMinimumLeadingWidth() const { + // If the keyword bubble is showing, the view can collapse completely. + if (ShouldShowKeywordBubble()) + return 0; + + if (location_icon_view_->GetShowText()) + return location_icon_view_->GetMinimumLabelTextWidth(); + + return GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + + location_icon_view_->GetMinimumSize().width(); +} + +int LocationBarView::GetMinimumTrailingWidth() const { + int trailing_width = IncrementalMinimumWidth(page_action_icon_container_); + + for (auto* content_setting_view : content_setting_views_) + trailing_width += IncrementalMinimumWidth(content_setting_view); + + return trailing_width; +} + +gfx::Rect LocationBarView::GetLocalBoundsWithoutEndcaps() const { + const int border_radius = height() / 2; + gfx::Rect bounds_without_endcaps(GetLocalBounds()); + bounds_without_endcaps.Inset(gfx::Insets::VH(0, border_radius)); + return bounds_without_endcaps; +} + +void LocationBarView::RefreshBackground() { + // Match the background color to the popup if the Omnibox is visibly focused. + SkColor background_color, border_color; + const auto* const color_provider = GetColorProvider(); + if (omnibox_view_->model()->is_caret_visible()) { + background_color = border_color = + color_provider->GetColor(kColorOmniboxResultsBackground); + } else { + const SkColor normal = + color_provider->GetColor(kColorLocationBarBackground); + const SkColor hovered = + color_provider->GetColor(kColorLocationBarBackgroundHovered); + const double opacity = hover_animation_.GetCurrentValue(); + background_color = gfx::Tween::ColorValueBetween(opacity, normal, hovered); + border_color = color_provider->GetColor(kColorLocationBarBorder); + } + + if (is_popup_mode_) { + SetBackground(views::CreateSolidBackground(background_color)); + } else { + SkColor stroke_color = SK_ColorTRANSPARENT; + + if (GetNativeTheme()->UserHasContrastPreference()) { + // High contrast schemes get a border stroke even on a rounded omnibox. + stroke_color = border_color; + } + + SetBackground(CreateRoundRectBackground(background_color, stroke_color)); + } + + // Keep the views::Textfield in sync. It needs an opaque background to + // correctly enable subpixel AA. + omnibox_view_->SetBackgroundColor(background_color); + + SchedulePaint(); +} + +bool LocationBarView::RefreshContentSettingViews() { + if (web_app::AppBrowserController::IsWebApp(browser_)) { + // For hosted apps, the location bar is normally hidden and icons appear in + // the window frame instead. + GetWidget()->non_client_view()->ResetWindowControls(); + } + + bool visibility_changed = false; + for (auto* v : content_setting_views_) { + const bool was_visible = v->GetVisible(); + v->Update(); + if (was_visible != v->GetVisible()) + visibility_changed = true; + } + return visibility_changed; +} + +void LocationBarView::RefreshPageActionIconViews() { + if (web_app::AppBrowserController::IsWebApp(browser_)) { + // For hosted apps, the location bar is normally hidden and icons appear in + // the window frame instead. + GetWidget()->non_client_view()->ResetWindowControls(); + } + + page_action_icon_controller_->UpdateAll(); +} + +void LocationBarView::RefreshClearAllButtonIcon() { + const bool touch_ui = ui::TouchUiController::Get()->touch_ui(); + const gfx::VectorIcon& icon = + touch_ui ? omnibox::kClearIcon : kTabCloseNormalIcon; + const ui::ColorProvider* cp = GetColorProvider(); + SetImageFromVectorIconWithColor( + clear_all_button_, icon, + cp->GetColor(kColorLocationBarClearAllButtonIcon), + cp->GetColor(kColorLocationBarClearAllButtonIconDisabled)); + clear_all_button_->SetBorder(views::CreateEmptyBorder( + GetLayoutInsets(LOCATION_BAR_ICON_INTERIOR_PADDING))); +} + +bool LocationBarView::ShouldShowKeywordBubble() const { + return omnibox_view_->model()->is_keyword_selected(); +} + +OmniboxPopupView* LocationBarView::GetOmniboxPopupView() { + DCHECK(IsInitialized()); + return omnibox_view_->model()->get_popup_view(); +} + +void LocationBarView::OnPageInfoBubbleClosed( + views::Widget::ClosedReason closed_reason, + bool reload_prompt) { + // If we're closing the bubble because the user pressed ESC or because the + // user clicked Close (rather than the user clicking directly on something + // else), we should refocus the location bar. This lets the user tab into the + // "You should reload this page" infobar rather than dumping them back out + // into a stale webpage. + if (!reload_prompt) + return; + if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed && + closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) { + return; + } + + FocusLocation(false); +} + +GURL LocationBarView::GetDestinationURL() const { + return destination_url(); +} + +bool LocationBarView::IsInputTypedUrlWithoutScheme() const { + return destination_url_entered_without_scheme(); +} + +WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const { + return disposition(); +} + +ui::PageTransition LocationBarView::GetPageTransition() const { + return transition(); +} + +base::TimeTicks LocationBarView::GetMatchSelectionTimestamp() const { + return match_selection_timestamp(); +} + +void LocationBarView::AcceptInput() { + AcceptInput(base::TimeTicks()); +} + +void LocationBarView::AcceptInput(base::TimeTicks match_selection_timestamp) { + omnibox_view_->model()->AcceptInput(WindowOpenDisposition::CURRENT_TAB, + match_selection_timestamp); +} + +void LocationBarView::FocusSearch() { + // This is called by keyboard accelerator, so it's user-initiated. + omnibox_view_->SetFocus(/*is_user_initiated=*/true); + omnibox_view_->EnterKeywordModeForDefaultSearchProvider(); +} + +void LocationBarView::UpdateContentSettingsIcons() { + if (RefreshContentSettingViews()) { + Layout(); + SchedulePaint(); + } +} + +inline void LocationBarView::UpdateQRCodeGeneratorIcon() { + PageActionIconView* icon = page_action_icon_controller_->GetIconView( + PageActionIconType::kQRCodeGenerator); + if (icon) + icon->Update(); +} + +inline bool LocationBarView::UpdateSendTabToSelfIcon() { + PageActionIconView* icon = page_action_icon_controller_->GetIconView( + PageActionIconType::kSendTabToSelf); + if (!icon) + return false; + bool was_visible = icon->GetVisible(); + icon->Update(); + return was_visible != icon->GetVisible(); +} + +void LocationBarView::SaveStateToContents(WebContents* contents) { + omnibox_view_->SaveStateToTab(contents); +} + +const OmniboxView* LocationBarView::GetOmniboxView() const { + return omnibox_view_; +} + +LocationBarTesting* LocationBarView::GetLocationBarForTesting() { + return this; +} + +bool LocationBarView::TestContentSettingImagePressed(size_t index) { + if (index >= content_setting_views_.size()) + return false; + + views::View* image_view = content_setting_views_[index]; + if (!image_view->GetVisible()) + return false; + + image_view->OnKeyPressed( + ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE)); + image_view->OnKeyReleased( + ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_SPACE, ui::EF_NONE)); + return true; +} + +bool LocationBarView::IsContentSettingBubbleShowing(size_t index) { + return index < content_setting_views_.size() && + content_setting_views_[index]->IsBubbleShowing(); +} + +void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { + RefreshBackground(); +} + +bool LocationBarView::GetNeedsNotificationWhenVisibleBoundsChange() const { + return true; +} + +void LocationBarView::OnVisibleBoundsChanged() { + OmniboxPopupView* popup = GetOmniboxPopupView(); + if (popup->IsOpen()) + popup->UpdatePopupAppearance(); +} + +void LocationBarView::OnFocus() { + // This is only called when the user explicitly focuses the location bar. + // Renderer-initiated focuses go through the `FocusLocation()` call instead. + omnibox_view_->SetFocus(/*is_user_initiated=*/true); +} + +void LocationBarView::OnPaintBorder(gfx::Canvas* canvas) { + if (!is_popup_mode_) + return; // The border is painted by our Background. + + gfx::Rect bounds(GetContentsBounds()); + const SkColor border_color = + GetColorProvider()->GetColor(kColorLocationBarBorderOpaque); + canvas->DrawLine(gfx::PointF(bounds.x(), bounds.y()), + gfx::PointF(bounds.right(), bounds.y()), border_color); + canvas->DrawLine(gfx::PointF(bounds.x(), bounds.bottom() - 1), + gfx::PointF(bounds.right(), bounds.bottom() - 1), + border_color); +} + +bool LocationBarView::OnMousePressed(const ui::MouseEvent& event) { + return omnibox_view_->OnMousePressed( + AdjustMouseEventLocationForOmniboxView(event)); +} + +bool LocationBarView::OnMouseDragged(const ui::MouseEvent& event) { + return omnibox_view_->OnMouseDragged( + AdjustMouseEventLocationForOmniboxView(event)); +} + +void LocationBarView::OnMouseReleased(const ui::MouseEvent& event) { + omnibox_view_->OnMouseReleased(AdjustMouseEventLocationForOmniboxView(event)); +} + +void LocationBarView::OnMouseMoved(const ui::MouseEvent& event) { + OnOmniboxHovered(true); +} + +void LocationBarView::OnMouseExited(const ui::MouseEvent& event) { + OnOmniboxHovered(false); +} + +void LocationBarView::ShowContextMenu(const gfx::Point& p, + ui::MenuSourceType source_type) { + omnibox_view_->ShowContextMenu(p, source_type); +} + +void LocationBarView::WriteDragDataForView(views::View* sender, + const gfx::Point& press_pt, + OSExchangeData* data) { + DCHECK_NE(GetDragOperationsForView(sender, press_pt), + ui::DragDropTypes::DRAG_NONE); + + WebContents* web_contents = GetWebContents(); + favicon::FaviconDriver* favicon_driver = + favicon::ContentFaviconDriver::FromWebContents(web_contents); + gfx::ImageSkia favicon = favicon_driver->GetFavicon().AsImageSkia(); + button_drag_utils::SetURLAndDragImage(web_contents->GetVisibleURL(), + web_contents->GetTitle(), favicon, + nullptr, data); +} + +int LocationBarView::GetDragOperationsForView(views::View* sender, + const gfx::Point& p) { + DCHECK_EQ(location_icon_view_, sender); + WebContents* web_contents = delegate_->GetWebContents(); + return (web_contents && web_contents->GetVisibleURL().is_valid() && + (!GetOmniboxView()->IsEditingOrEmpty())) + ? (ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK) + : ui::DragDropTypes::DRAG_NONE; +} + +bool LocationBarView::CanStartDragForView(View* sender, + const gfx::Point& press_pt, + const gfx::Point& p) { + return true; +} + +void LocationBarView::AnimationProgressed(const gfx::Animation* animation) { + DCHECK_EQ(animation, &hover_animation_); + RefreshBackground(); +} + +void LocationBarView::AnimationEnded(const gfx::Animation* animation) { + DCHECK_EQ(animation, &hover_animation_); + AnimationProgressed(animation); +} + +void LocationBarView::AnimationCanceled(const gfx::Animation* animation) { + DCHECK_EQ(animation, &hover_animation_); + AnimationProgressed(animation); +} + +void LocationBarView::OnChildViewRemoved(View* observed_view, View* child) { + views::AnimationDelegateViews::OnChildViewRemoved(observed_view, child); + PreferredSizeChanged(); +} + +void LocationBarView::OnChanged() { + location_icon_view_->Update(/*suppress_animations=*/false); + clear_all_button_->SetVisible( + omnibox_view_ && omnibox_view_->model()->user_input_in_progress() && + !omnibox_view_->GetText().empty() && + IsVirtualKeyboardVisible(GetWidget())); + Layout(); + SchedulePaint(); + UpdateSendTabToSelfIcon(); + UpdateQRCodeGeneratorIcon(); + UpdateChipVisibility(); +} + +void LocationBarView::OnPopupVisibilityChanged() { + RefreshBackground(); + + // The location icon may change when the popup visibility changes. + // The page action icons and content setting images may be hidden now. + // This will also schedule a paint and re-layout. + UpdateWithoutTabRestore(); + + // The focus ring may be hidden or shown when the popup visibility changes. + if (views::FocusRing::Get(this)) + views::FocusRing::Get(this)->SchedulePaint(); + + // We indent the textfield when the popup is open to align to suggestions. + omnibox_view_->NotifyAccessibilityEvent(ax::mojom::Event::kControlsChanged, + true); +} + +const LocationBarModel* LocationBarView::GetLocationBarModel() const { + return delegate_->GetLocationBarModel(); +} + +void LocationBarView::OnOmniboxFocused() { + if (views::FocusRing::Get(this)) + views::FocusRing::Get(this)->SchedulePaint(); + + // Only show hover animation in unfocused steady state. Since focusing + // the omnibox is intentional, snapping is better than transitioning here. + hover_animation_.Reset(); + + UpdateSendTabToSelfIcon(); + UpdateQRCodeGeneratorIcon(); + RefreshBackground(); +} + +void LocationBarView::OnOmniboxBlurred() { + if (views::FocusRing::Get(this)) + views::FocusRing::Get(this)->SchedulePaint(); + UpdateSendTabToSelfIcon(); + UpdateQRCodeGeneratorIcon(); + RefreshBackground(); +} + +void LocationBarView::OnOmniboxHovered(bool is_hovering) { + if (is_hovering) { + // Only show the hover animation when omnibox is in unfocused steady state. + if (!omnibox_view_->HasFocus()) + hover_animation_.Show(); + } else { + hover_animation_.Hide(); + } +} + +void LocationBarView::FocusAndSelectAll() { + FocusLocation(true); +} + +void LocationBarView::OnTouchUiChanged() { + const gfx::FontList& font_list = views::style::GetFont( + CONTEXT_OMNIBOX_PRIMARY, views::style::STYLE_PRIMARY); + location_icon_view_->SetFontList(font_list); + omnibox_view_->SetFontList(font_list); + if (OmniboxPrefixRichAutocompletionEnabled()) + ime_prefix_autocomplete_view_->SetFontList(font_list); + ime_inline_autocomplete_view_->SetFontList(font_list); + if (OmniboxFieldTrial::RichAutocompletionShowAdditionalText()) + omnibox_additional_text_view_->SetFontList(font_list); + selected_keyword_view_->SetFontList(font_list); + for (ContentSettingImageView* view : content_setting_views_) + view->SetFontList(font_list); + page_action_icon_controller_->SetFontList(font_list); + location_icon_view_->Update(/*suppress_animations=*/false); + PreferredSizeChanged(); +} + +bool LocationBarView::IsEditingOrEmpty() const { + return omnibox_view_ && omnibox_view_->IsEditingOrEmpty(); +} + +void LocationBarView::OnLocationIconPressed(const ui::MouseEvent& event) { + if (event.IsOnlyMiddleMouseButton() && + ui::Clipboard::IsSupportedClipboardBuffer( + ui::ClipboardBuffer::kSelection)) { + std::u16string text; + ui::Clipboard::GetForCurrentThread()->ReadText( + ui::ClipboardBuffer::kSelection, /* data_dst = */ nullptr, &text); + text = OmniboxView::SanitizeTextForPaste(text); + + if (!GetOmniboxView()->model()->CanPasteAndGo(text)) { + return; + } + + GetOmniboxView()->model()->PasteAndGo(text, event.time_stamp()); + } +} + +void LocationBarView::OnLocationIconDragged(const ui::MouseEvent& event) { + GetOmniboxView()->CloseOmniboxPopup(); +} + +SkColor LocationBarView::GetSecurityChipColor( + security_state::SecurityLevel security_level) const { + ui::ColorId id = kColorOmniboxSecurityChipDefault; + if (security_level == security_state::SECURE_WITH_POLICY_INSTALLED_CERT) + id = kColorOmniboxTextDimmed; + else if (security_level == security_state::SECURE) + id = kColorOmniboxSecurityChipSecure; + else if (security_level == security_state::DANGEROUS) + id = kColorOmniboxSecurityChipDangerous; + return GetColorProvider()->GetColor(id); +} + +bool LocationBarView::ShowPageInfoDialog() { + WebContents* contents = GetWebContents(); + if (!contents) + return false; + + content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); + if (!entry || entry->IsInitialEntry()) + return false; + + DCHECK(GetWidget()); + + auto initialized_callback = + GetPageInfoDialogCreatedCallbackForTesting() + ? std::move(GetPageInfoDialogCreatedCallbackForTesting()) + : base::DoNothing(); + + views::BubbleDialogDelegateView* bubble = + PageInfoBubbleView::CreatePageInfoBubble( + this, gfx::Rect(), GetWidget()->GetNativeWindow(), contents, + entry->GetVirtualURL(), std::move(initialized_callback), + base::BindOnce(&LocationBarView::OnPageInfoBubbleClosed, + weak_factory_.GetWeakPtr())); + bubble->SetHighlightedButton(location_icon_view_); + bubble->GetWidget()->Show(); + return true; +} + +ui::ImageModel LocationBarView::GetLocationIcon( + LocationIconView::Delegate::IconFetchedCallback on_icon_fetched) const { + return omnibox_view_ + ? omnibox_view_->GetIcon(GetLayoutConstant(LOCATION_BAR_ICON_SIZE), + location_icon_view_->GetForegroundColor(), + std::move(on_icon_fetched)) + : ui::ImageModel(); +} + +void LocationBarView::UpdateChipVisibility() { + if (!IsChipActive()) { + return; + } + + if (IsEditingOrEmpty()) { + // If a user starts typing, a permission request should be ignored and the + // chip finalized. + chip_->Finalize(); + } +} + +ui::MouseEvent LocationBarView::AdjustMouseEventLocationForOmniboxView( + const ui::MouseEvent& event) const { + ui::MouseEvent adjusted(event); + adjusted.ConvertLocationToTarget(this, omnibox_view_.get()); + return adjusted; +} + +bool LocationBarView::GetPopupMode() const { + return is_popup_mode_; +} + +BEGIN_METADATA(LocationBarView, views::View) +ADD_READONLY_PROPERTY_METADATA(int, BorderRadius) +ADD_READONLY_PROPERTY_METADATA(gfx::Point, OmniboxViewOrigin) +ADD_PROPERTY_METADATA(std::u16string, ImePrefixAutocompletion) +ADD_PROPERTY_METADATA(std::u16string, ImeInlineAutocompletion) +ADD_PROPERTY_METADATA(std::u16string, OmniboxAdditionalText) +ADD_READONLY_PROPERTY_METADATA(int, MinimumLeadingWidth) +ADD_READONLY_PROPERTY_METADATA(int, MinimumTrailingWidth) +ADD_READONLY_PROPERTY_METADATA(gfx::Rect, LocalBoundsWithoutEndcaps) +ADD_READONLY_PROPERTY_METADATA(bool, PopupMode) +END_METADATA diff --git a/michael-patches-tempfiles/chrome/browser/ui/views/toolbar/toolbar_view.cc b/michael-patches-tempfiles/chrome/browser/ui/views/toolbar/toolbar_view.cc new file mode 100644 index 0000000..bf25de0 --- /dev/null +++ b/michael-patches-tempfiles/chrome/browser/ui/views/toolbar/toolbar_view.cc @@ -0,0 +1,959 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// 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/toolbar/toolbar_view.h" + +#include +#include + +#include "base/bind.h" +#include "base/command_line.h" +#include "base/containers/fixed_flat_map.h" +#include "base/feature_list.h" +#include "base/i18n/number_formatting.h" +#include "base/metrics/user_metrics.h" +#include "base/ranges/algorithm.h" +#include "base/strings/utf_string_conversions.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/apps/intent_helper/intent_picker_features.h" +#include "chrome/browser/command_updater.h" +#include "chrome/browser/download/bubble/download_bubble_prefs.h" +#include "chrome/browser/media/router/media_router_feature.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profiles_state.h" +#include "chrome/browser/share/share_features.h" +#include "chrome/browser/themes/theme_properties.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_content_setting_bubble_model_delegate.h" +#include "chrome/browser/ui/browser_tabstrip.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/color/chrome_color_id.h" +#include "chrome/browser/ui/global_error/global_error_service.h" +#include "chrome/browser/ui/global_error/global_error_service_factory.h" +#include "chrome/browser/ui/intent_picker_tab_helper.h" +#include "chrome/browser/ui/layout_constants.h" +#include "chrome/browser/ui/side_search/side_search_utils.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/browser/ui/toolbar/chrome_labs_prefs.h" +#include "chrome/browser/ui/ui_features.h" +#include "chrome/browser/ui/view_ids.h" +#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" +#include "chrome/browser/ui/views/download/bubble/download_toolbar_button_view.h" +#include "chrome/browser/ui/views/extensions/extension_popup.h" +#include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h" +#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h" +#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" +#include "chrome/browser/ui/views/frame/browser_view.h" +#include "chrome/browser/ui/views/frame/top_container_background.h" +#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_contextual_menu.h" +#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_view.h" +#include "chrome/browser/ui/views/location_bar/intent_chip_button.h" +#include "chrome/browser/ui/views/location_bar/star_view.h" +#include "chrome/browser/ui/views/media_router/cast_toolbar_button.h" +#include "chrome/browser/ui/views/page_action/page_action_icon_container.h" +#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h" +#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_toolbar_icon_view.h" +#include "chrome/browser/ui/views/side_search/side_search_browser_controller.h" +#include "chrome/browser/ui/views/tabs/tab_strip.h" +#include "chrome/browser/ui/views/toolbar/app_menu.h" +#include "chrome/browser/ui/views/toolbar/back_forward_button.h" +#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h" +#include "chrome/browser/ui/views/toolbar/chrome_labs_bubble_view_model.h" +#include "chrome/browser/ui/views/toolbar/chrome_labs_button.h" +#include "chrome/browser/ui/views/toolbar/chrome_labs_utils.h" +#include "chrome/browser/ui/views/toolbar/home_button.h" +#include "chrome/browser/ui/views/toolbar/reload_button.h" +#include "chrome/browser/ui/views/toolbar/side_panel_toolbar_button.h" +#include "chrome/browser/ui/views/toolbar/toolbar_button.h" +#include "chrome/browser/ui/web_applications/app_browser_controller.h" +#include "chrome/browser/upgrade_detector/upgrade_detector.h" +#include "chrome/common/chrome_features.h" +#include "chrome/common/pref_names.h" +#include "chrome/grit/chromium_strings.h" +#include "chrome/grit/generated_resources.h" +#include "chrome/grit/theme_resources.h" +#include "components/autofill/core/common/autofill_payments_features.h" +#include "components/omnibox/browser/omnibox_view.h" +#include "components/prefs/pref_service.h" +#include "components/safe_browsing/core/common/features.h" +#include "components/send_tab_to_self/features.h" +#include "components/signin/public/base/signin_buildflags.h" +#include "components/strings/grit/components_strings.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" +#include "media/base/media_switches.h" +#include "ui/accessibility/ax_node_data.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/metadata/metadata_impl_macros.h" +#include "ui/base/theme_provider.h" +#include "ui/base/window_open_disposition.h" +#include "ui/color/color_id.h" +#include "ui/color/color_provider.h" +#include "ui/compositor/layer.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/image/canvas_image_source.h" +#include "ui/gfx/paint_vector_icon.h" +#include "ui/gfx/scoped_canvas.h" +#include "ui/views/accessibility/view_accessibility.h" +#include "ui/views/cascading_property.h" +#include "ui/views/layout/fill_layout.h" +#include "ui/views/layout/flex_layout.h" +#include "ui/views/view_class_properties.h" +#include "ui/views/widget/tooltip_manager.h" +#include "ui/views/widget/widget.h" +#include "ui/views/window/non_client_view.h" + +#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) +#include "chrome/browser/recovery/recovery_install_global_error_factory.h" +#endif + +#if BUILDFLAG(IS_WIN) +#include "chrome/browser/ui/views/critical_notification_bubble_view.h" +#endif + +#if !BUILDFLAG(IS_CHROMEOS_ASH) +#include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" +#include "chrome/browser/ui/dialogs/outdated_upgrade_bubble.h" +#endif + +#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) +#include "chrome/browser/ui/views/frame/webui_tab_strip_container_view.h" +#endif // BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) + +#if defined(USE_AURA) +#include "ui/aura/window_occlusion_tracker.h" +#endif + +using base::UserMetricsAction; +using content::WebContents; + +namespace { + +// Gets the display mode for a given browser. +ToolbarView::DisplayMode GetDisplayMode(Browser* browser) { +#if BUILDFLAG(IS_CHROMEOS_ASH) + if (browser->is_type_custom_tab()) + return ToolbarView::DisplayMode::CUSTOM_TAB; +#endif + + // Checked in this order because even tabbed PWAs use the CUSTOM_TAB + // display mode. + if (web_app::AppBrowserController::IsWebApp(browser)) + return ToolbarView::DisplayMode::CUSTOM_TAB; + + if (browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)) + return ToolbarView::DisplayMode::NORMAL; + + return ToolbarView::DisplayMode::LOCATION; +} + +auto& GetViewCommandMap() { + static constexpr auto kViewCommandMap = base::MakeFixedFlatMap( + {{VIEW_ID_BACK_BUTTON, IDC_BACK}, + {VIEW_ID_FORWARD_BUTTON, IDC_FORWARD}, + {VIEW_ID_HOME_BUTTON, IDC_HOME}, + {VIEW_ID_RELOAD_BUTTON, IDC_RELOAD}, + {VIEW_ID_AVATAR_BUTTON, IDC_SHOW_AVATAR_MENU}}); + return kViewCommandMap; +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, public: + +ToolbarView::ToolbarView(Browser* browser, BrowserView* browser_view) + : AnimationDelegateViews(this), + browser_(browser), + browser_view_(browser_view), + app_menu_icon_controller_(browser->profile(), this), + display_mode_(GetDisplayMode(browser)) { + SetID(VIEW_ID_TOOLBAR); + + UpgradeDetector::GetInstance()->AddObserver(this); + + if (display_mode_ == DisplayMode::NORMAL) { + SetBackground(std::make_unique(browser_view)); + + for (const auto& view_and_command : GetViewCommandMap()) + chrome::AddCommandObserver(browser_, view_and_command.second, this); + } + views::SetCascadingColorProviderColor(this, views::kCascadingBackgroundColor, + kColorToolbar); +} + +ToolbarView::~ToolbarView() { + UpgradeDetector::GetInstance()->RemoveObserver(this); + + if (display_mode_ != DisplayMode::NORMAL) + return; + + for (const auto& view_and_command : GetViewCommandMap()) + chrome::RemoveCommandObserver(browser_, view_and_command.second, this); +} + +void ToolbarView::Init() { +#if defined(USE_AURA) + // Avoid generating too many occlusion tracking calculation events before this + // function returns. The occlusion status will be computed only once once this + // function returns. + // See crbug.com/1183894#c2 + aura::WindowOcclusionTracker::ScopedPause pause_occlusion; +#endif + auto location_bar = std::make_unique( + browser_, browser_->profile(), browser_->command_controller(), this, + display_mode_ != DisplayMode::NORMAL); + // Make sure the toolbar shows by default. + size_animation_.Reset(1); + + if (display_mode_ != DisplayMode::NORMAL) { + location_bar_ = AddChildView(std::move(location_bar)); + location_bar_->Init(); + + if (display_mode_ == DisplayMode::CUSTOM_TAB) { + custom_tab_bar_ = + AddChildView(std::make_unique(browser_view_, this)); + } + + SetLayoutManager(std::make_unique()); + initialized_ = true; + return; + } + + const auto callback = [](Browser* browser, int command, + const ui::Event& event) { + chrome::ExecuteCommandWithDisposition( + browser, command, ui::DispositionFromEventFlags(event.flags())); + }; + + std::unique_ptr back = std::make_unique( + BackForwardButton::Direction::kBack, + base::BindRepeating(callback, browser_, IDC_BACK), browser_); + + std::unique_ptr forward = std::make_unique( + BackForwardButton::Direction::kForward, + base::BindRepeating(callback, browser_, IDC_FORWARD), browser_); + + std::unique_ptr reload = + std::make_unique(browser_->command_controller()); + + PrefService* const prefs = browser_->profile()->GetPrefs(); + std::unique_ptr home = std::make_unique( + base::BindRepeating(callback, browser_, IDC_HOME), prefs); + + std::unique_ptr extensions_container; + + // Do not create the extensions or browser actions container if it is a guest + // profile (only regular and incognito profiles host extensions). + if (!browser_->profile()->IsGuestSession()) { + extensions_container = + std::make_unique(browser_); + } + std::unique_ptr cast; + if (media_router::MediaRouterEnabled(browser_->profile())) + cast = media_router::CastToolbarButton::Create(browser_); + + std::unique_ptr media_button; + if (base::FeatureList::IsEnabled(media::kGlobalMediaControls)) { + media_button = std::make_unique( + browser_view_, MediaToolbarButtonContextualMenu::Create(browser_)); + } + + std::unique_ptr download_button; + if (download::IsDownloadBubbleEnabled(browser_->profile())) { + download_button = + std::make_unique(browser_view_); + } + + std::unique_ptr + send_tab_to_self_button; + if (!browser_->profile()->IsOffTheRecord()) { + send_tab_to_self_button = + std::make_unique( + browser_view_); + } + + std::unique_ptr side_panel_button; + if (browser_view_->right_aligned_side_panel()) { + side_panel_button = std::make_unique(browser_); + } + + // Always add children in order from left to right, for accessibility. + back_ = AddChildView(std::move(back)); + forward_ = AddChildView(std::move(forward)); + reload_ = AddChildView(std::move(reload)); + home_ = AddChildView(std::move(home)); + + // The side search button (if enabled) should sit between the location bar and + // the other navigation buttons. + if (browser_view_->side_search_controller() && + !side_search::IsDSESupportEnabled(browser_->profile())) { + left_side_panel_button_ = AddChildView( + browser_view_->side_search_controller()->CreateToolbarButton()); + } + + location_bar_ = AddChildView(std::move(location_bar)); + + if (extensions_container) + extensions_container_ = AddChildView(std::move(extensions_container)); + + if (base::FeatureList::IsEnabled(features::kChromeLabs)) { + chrome_labs_model_ = std::make_unique(); + UpdateChromeLabsNewBadgePrefs(browser_->profile(), + chrome_labs_model_.get()); + if (ChromeLabsButton::ShouldShowButton(chrome_labs_model_.get(), + browser_->profile())) { + chrome_labs_button_ = AddChildView(std::make_unique( + browser_view_, chrome_labs_model_.get())); + + show_chrome_labs_button_.Init( + chrome_labs_prefs::kBrowserLabsEnabled, prefs, + base::BindRepeating(&ToolbarView::OnChromeLabsPrefChanged, + base::Unretained(this))); + // Set the visibility for the button based on initial enterprise policy + // value. Only call OnChromeLabsPrefChanged if there is a change from the + // initial value. + chrome_labs_button_->SetVisible(show_chrome_labs_button_.GetValue()); + } + } + + if (cast) + cast_ = AddChildView(std::move(cast)); + + if (media_button) + media_button_ = AddChildView(std::move(media_button)); + + if (download_button) + download_button_ = AddChildView(std::move(download_button)); + + if (send_tab_to_self_button) + send_tab_to_self_button_ = AddChildView(std::move(send_tab_to_self_button)); + + // if (side_panel_button) + // side_panel_button_ = AddChildView(std::move(side_panel_button)); + + avatar_ = AddChildView(std::make_unique(browser_view_)); + + const base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + const std::string flag_value = + command_line.GetSwitchValueASCII("show-avatar-button"); + + bool in_incognito_or_guest_mode = browser_->profile()->IsOffTheRecord() || + browser_->profile()->IsGuestSession(); + + bool show_avatar_toolbar_button = true; +#if BUILDFLAG(IS_CHROMEOS_ASH) + // ChromeOS only badges Incognito and Guest icons in the browser window. + show_avatar_toolbar_button = in_incognito_or_guest_mode; +#elif BUILDFLAG(IS_CHROMEOS_LACROS) + show_avatar_toolbar_button = !profiles::IsPublicSession(); +#endif + + if (flag_value == "always") + show_avatar_toolbar_button = true; + else if (flag_value == "incognito-and-guest") + show_avatar_toolbar_button = in_incognito_or_guest_mode; + else if (flag_value == "never") + show_avatar_toolbar_button = false; + + // Always disable avatar / account icon + avatar_->SetVisible(false); + + auto app_menu_button = std::make_unique(this); + app_menu_button->SetFlipCanvasOnPaintForRTLUI(true); + app_menu_button->SetAccessibleName( + l10n_util::GetStringUTF16(IDS_ACCNAME_APP)); + app_menu_button->SetTooltipText( + l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP)); + app_menu_button->SetID(VIEW_ID_APP_MENU); + app_menu_button_ = AddChildView(std::move(app_menu_button)); + + LoadImages(); + + // Start global error services now so we set the icon on the menu correctly. +#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) + RecoveryInstallGlobalErrorFactory::GetForProfile(browser_->profile()); +#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) + + // Set the button icon based on the system state. Do this after + // |app_menu_button_| has been added as a bubble may be shown that needs + // the widget (widget found by way of app_menu_button_->GetWidget()). + app_menu_icon_controller_.UpdateDelegate(); + + location_bar_->Init(); + + show_home_button_.Init( + prefs::kShowHomeButton, prefs, + base::BindRepeating(&ToolbarView::OnShowHomeButtonChanged, + base::Unretained(this))); + + home_->SetVisible(show_home_button_.GetValue()); + + InitLayout(); + + for (auto* button : std::array{back_, forward_, reload_, + home_, avatar_}) { + if (button) + button->set_tag(GetViewCommandMap().at(button->GetID())); + } + + initialized_ = true; +} + +void ToolbarView::AnimationEnded(const gfx::Animation* animation) { + if (animation->GetCurrentValue() == 0) + SetToolbarVisibility(false); + browser()->window()->ToolbarSizeChanged(/*is_animating=*/false); +} + +void ToolbarView::AnimationProgressed(const gfx::Animation* animation) { + browser()->window()->ToolbarSizeChanged(/*is_animating=*/true); +} + +void ToolbarView::Update(WebContents* tab) { + if (location_bar_) + location_bar_->Update(tab); + + if (extensions_container_) + extensions_container_->UpdateAllIcons(); + + if (reload_) + reload_->SetMenuEnabled(chrome::IsDebuggerAttachedToCurrentTab(browser_)); +} + +void ToolbarView::SetToolbarVisibility(bool visible) { + SetVisible(visible); + views::View* bar = display_mode_ == DisplayMode::CUSTOM_TAB + ? static_cast(custom_tab_bar_) + : static_cast(location_bar_); + + bar->SetVisible(visible); +} + +void ToolbarView::UpdateCustomTabBarVisibility(bool visible, bool animate) { + DCHECK_EQ(display_mode_, DisplayMode::CUSTOM_TAB); + + if (!animate) { + size_animation_.Reset(visible ? 1.0 : 0.0); + SetToolbarVisibility(visible); + browser()->window()->ToolbarSizeChanged(/*is_animating=*/false); + return; + } + + if (visible) { + SetToolbarVisibility(true); + size_animation_.Show(); + } else { + size_animation_.Hide(); + } +} + +void ToolbarView::UpdateForWebUITabStrip() { +#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) + if (browser_view_->webui_tab_strip() && app_menu_button_) { + const size_t insertion_index = GetIndexOf(app_menu_button_).value(); + AddChildViewAt(browser_view_->webui_tab_strip()->CreateNewTabButton(), + insertion_index); + AddChildViewAt(browser_view_->webui_tab_strip()->CreateTabCounter(), + insertion_index); + LoadImages(); + } +#endif // BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) +} + +void ToolbarView::ResetTabState(WebContents* tab) { + if (location_bar_) + location_bar_->ResetTabState(tab); +} + +void ToolbarView::SetPaneFocusAndFocusAppMenu() { + if (app_menu_button_) + SetPaneFocus(app_menu_button_); +} + +bool ToolbarView::GetAppMenuFocused() const { + return app_menu_button_ && app_menu_button_->HasFocus(); +} + +void ToolbarView::ShowIntentPickerBubble( + std::vector app_info, + bool show_stay_in_chrome, + bool show_remember_selection, + IntentPickerBubbleView::BubbleType bubble_type, + const absl::optional& initiating_origin, + IntentPickerResponse callback) { + views::Button* highlighted_button = nullptr; + if (bubble_type == IntentPickerBubbleView::BubbleType::kClickToCall) { + highlighted_button = + + GetPageActionIconView(PageActionIconType::kClickToCall); + } else if (apps::features::LinkCapturingUiUpdateEnabled()) { + highlighted_button = GetIntentChipButton(); + } else { + highlighted_button = + GetPageActionIconView(PageActionIconType::kIntentPicker); + } + + if (!highlighted_button) + return; + + IntentPickerBubbleView::ShowBubble( + location_bar(), highlighted_button, bubble_type, GetWebContents(), + std::move(app_info), show_stay_in_chrome, show_remember_selection, + initiating_origin, std::move(callback)); +} + +void ToolbarView::ShowBookmarkBubble( + const GURL& url, + bool already_bookmarked, + bookmarks::BookmarkBubbleObserver* observer) { + views::View* const anchor_view = location_bar(); + PageActionIconView* const bookmark_star_icon = + GetPageActionIconView(PageActionIconType::kBookmarkStar); + + std::unique_ptr delegate; + Profile* profile = browser_->profile(); +#if !BUILDFLAG(IS_CHROMEOS_ASH) + delegate = std::make_unique(profile); +#endif + BookmarkBubbleView::ShowBubble(anchor_view, bookmark_star_icon, observer, + std::move(delegate), profile, url, + already_bookmarked); +} + +ExtensionsToolbarButton* ToolbarView::GetExtensionsButton() const { + return extensions_container_->GetExtensionsButton(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, LocationBarView::Delegate implementation: + +WebContents* ToolbarView::GetWebContents() { + return browser_->tab_strip_model()->GetActiveWebContents(); +} + +LocationBarModel* ToolbarView::GetLocationBarModel() { + return browser_->location_bar_model(); +} + +const LocationBarModel* ToolbarView::GetLocationBarModel() const { + return browser_->location_bar_model(); +} + +ContentSettingBubbleModelDelegate* +ToolbarView::GetContentSettingBubbleModelDelegate() { + return browser_->content_setting_bubble_model_delegate(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, CommandObserver implementation: + +void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { + DCHECK(display_mode_ == DisplayMode::NORMAL); + const std::array kButtons{back_, forward_, reload_, home_, + avatar_}; + auto* button = *base::ranges::find(kButtons, id, &views::Button::tag); + DCHECK(button); + button->SetEnabled(enabled); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, UpgradeObserver implementation: +void ToolbarView::OnOutdatedInstall() { + ShowOutdatedInstallNotification(true); +} + +void ToolbarView::OnOutdatedInstallNoAutoUpdate() { + ShowOutdatedInstallNotification(false); +} + +void ToolbarView::OnCriticalUpgradeInstalled() { + ShowCriticalNotification(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, ui::AcceleratorProvider implementation: + +bool ToolbarView::GetAcceleratorForCommandId( + int command_id, + ui::Accelerator* accelerator) const { + return GetWidget()->GetAccelerator(command_id, accelerator); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, views::View overrides: + +gfx::Size ToolbarView::CalculatePreferredSize() const { + gfx::Size size; + switch (display_mode_) { + case DisplayMode::CUSTOM_TAB: + size = custom_tab_bar_->GetPreferredSize(); + break; + case DisplayMode::LOCATION: + size = location_bar_->GetPreferredSize(); + break; + case DisplayMode::NORMAL: + size = View::CalculatePreferredSize(); + // Because there are odd cases where something causes one of the views in + // the toolbar to report an unreasonable height (see crbug.com/985909), we + // cap the height at the size of known child views (location bar and back + // button) plus margins. + // TODO(crbug.com/1033627): Figure out why the height reports incorrectly + // on some installations. + if (layout_manager_ && location_bar_->GetVisible()) { + const int max_height = + std::max(location_bar_->GetPreferredSize().height(), + back_->GetPreferredSize().height()) + + layout_manager_->interior_margin().height(); + size.SetToMin({size.width(), max_height}); + } + } + size.set_height(size.height() * size_animation_.GetCurrentValue()); + return size; +} + +gfx::Size ToolbarView::GetMinimumSize() const { + gfx::Size size; + switch (display_mode_) { + case DisplayMode::CUSTOM_TAB: + size = custom_tab_bar_->GetMinimumSize(); + break; + case DisplayMode::LOCATION: + size = location_bar_->GetMinimumSize(); + break; + case DisplayMode::NORMAL: + size = View::GetMinimumSize(); + // Because there are odd cases where something causes one of the views in + // the toolbar to report an unreasonable height (see crbug.com/985909), we + // cap the height at the size of known child views (location bar and back + // button) plus margins. + // TODO(crbug.com/1033627): Figure out why the height reports incorrectly + // on some installations. + if (layout_manager_ && location_bar_->GetVisible()) { + const int max_height = + std::max(location_bar_->GetMinimumSize().height(), + back_->GetMinimumSize().height()) + + layout_manager_->interior_margin().height(); + size.SetToMin({size.width(), max_height}); + } + } + size.set_height(size.height() * size_animation_.GetCurrentValue()); + return size; +} + +void ToolbarView::Layout() { + // If we have not been initialized yet just do nothing. + if (!initialized_) + return; + + if (display_mode_ == DisplayMode::CUSTOM_TAB) { + custom_tab_bar_->SetBounds(0, 0, width(), + custom_tab_bar_->GetPreferredSize().height()); + location_bar_->SetVisible(false); + return; + } + + if (display_mode_ == DisplayMode::LOCATION) { + location_bar_->SetBounds(0, 0, width(), + location_bar_->GetPreferredSize().height()); + return; + } + + LayoutCommon(); + + // Call super implementation to ensure layout manager and child layouts + // happen. + AccessiblePaneView::Layout(); +} + +void ToolbarView::OnThemeChanged() { + views::AccessiblePaneView::OnThemeChanged(); + if (!initialized_) + return; + + if (display_mode_ == DisplayMode::NORMAL) + LoadImages(); + + SchedulePaint(); +} + +bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { + const views::View* focused_view = focus_manager()->GetFocusedView(); + if (focused_view && (focused_view->GetID() == VIEW_ID_OMNIBOX)) + return false; // Let the omnibox handle all accelerator events. + return AccessiblePaneView::AcceleratorPressed(accelerator); +} + +void ToolbarView::ChildPreferredSizeChanged(views::View* child) { + InvalidateLayout(); + if (size() != GetPreferredSize()) + PreferredSizeChanged(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ToolbarView, private: + +// Override this so that when the user presses F6 to rotate toolbar panes, +// the location bar gets focus, not the first control in the toolbar - and +// also so that it selects all content in the location bar. +views::View* ToolbarView::GetDefaultFocusableChild() { + return location_bar_; +} + +void ToolbarView::GetAccessibleNodeData(ui::AXNodeData* node_data) { + node_data->role = ax::mojom::Role::kToolbar; +} + +void ToolbarView::InitLayout() { + const int default_margin = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); + // TODO(dfried): rename this constant. + const int location_bar_margin = GetLayoutConstant(TOOLBAR_STANDARD_SPACING); + const views::FlexSpecification account_container_flex_rule = + views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum, + views::MaximumFlexSizeRule::kPreferred) + .WithOrder(1); + const views::FlexSpecification location_bar_flex_rule = + views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum, + views::MaximumFlexSizeRule::kUnbounded) + .WithOrder(2); + constexpr int kExtensionsFlexOrder = 3; + + layout_manager_ = SetLayoutManager(std::make_unique()); + + layout_manager_->SetOrientation(views::LayoutOrientation::kHorizontal) + .SetCrossAxisAlignment(views::LayoutAlignment::kCenter) + .SetCollapseMargins(true) + .SetDefault(views::kMarginsKey, gfx::Insets::VH(0, default_margin)); + + location_bar_->SetProperty(views::kFlexBehaviorKey, location_bar_flex_rule); + location_bar_->SetProperty(views::kMarginsKey, + gfx::Insets::VH(0, location_bar_margin)); + + if (extensions_container_) { + const views::FlexSpecification extensions_flex_rule = + views::FlexSpecification( + extensions_container_->GetAnimatingLayoutManager() + ->GetDefaultFlexRule()) + .WithOrder(kExtensionsFlexOrder); + + extensions_container_->SetProperty(views::kFlexBehaviorKey, + extensions_flex_rule); + } + + LayoutCommon(); +} + +void ToolbarView::LayoutCommon() { + DCHECK(display_mode_ == DisplayMode::NORMAL); + + const gfx::Insets interior_margin = + GetLayoutInsets(browser_view_->webui_tab_strip() + ? LayoutInset::WEBUI_TAB_STRIP_TOOLBAR_INTERIOR_MARGIN + : LayoutInset::TOOLBAR_INTERIOR_MARGIN); + layout_manager_->SetInteriorMargin(interior_margin); + + // Extend buttons to the window edge if we're either in a maximized or + // fullscreen window. This makes the buttons easier to hit, see Fitts' law. + const bool extend_buttons_to_edge = + browser_->window() && + (browser_->window()->IsMaximized() || browser_->window()->IsFullscreen()); + back_->SetLeadingMargin(extend_buttons_to_edge ? interior_margin.left() : 0); + app_menu_button_->SetTrailingMargin( + extend_buttons_to_edge ? interior_margin.right() : 0); + + // Cast button visibility is controlled externally. +} + +// AppMenuIconController::Delegate: +void ToolbarView::UpdateTypeAndSeverity( + AppMenuIconController::TypeAndSeverity type_and_severity) { + // There's no app menu in tabless windows. + if (!app_menu_button_) + return; + + std::u16string accname_app = l10n_util::GetStringUTF16(IDS_ACCNAME_APP); + if (type_and_severity.type == + AppMenuIconController::IconType::UPGRADE_NOTIFICATION) { + accname_app = l10n_util::GetStringFUTF16( + IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app); + } + app_menu_button_->SetAccessibleName(accname_app); + app_menu_button_->SetTypeAndSeverity(type_and_severity); +} + +SkColor ToolbarView::GetDefaultColorForSeverity( + AppMenuIconController::Severity severity) const { + ui::ColorId color_id; + switch (severity) { + case AppMenuIconController::Severity::NONE: + return GetColorProvider()->GetColor(kColorToolbarButtonIcon); + case AppMenuIconController::Severity::LOW: + color_id = ui::kColorAlertLowSeverity; + break; + case AppMenuIconController::Severity::MEDIUM: + color_id = ui::kColorAlertMediumSeverity; + break; + case AppMenuIconController::Severity::HIGH: + color_id = ui::kColorAlertHighSeverity; + break; + } + return GetColorProvider()->GetColor(color_id); +} + +ExtensionsToolbarContainer* ToolbarView::GetExtensionsToolbarContainer() { + return extensions_container_; +} + +gfx::Size ToolbarView::GetToolbarButtonSize() const { + const int size = GetLayoutConstant(LayoutConstant::TOOLBAR_BUTTON_HEIGHT); + return gfx::Size(size, size); +} + +views::View* ToolbarView::GetDefaultExtensionDialogAnchorView() { + if (extensions_container_) + return extensions_container_->GetExtensionsButton(); + return GetAppMenuButton(); +} + +PageActionIconView* ToolbarView::GetPageActionIconView( + PageActionIconType type) { + return location_bar()->page_action_icon_controller()->GetIconView(type); +} + +AppMenuButton* ToolbarView::GetAppMenuButton() { + if (app_menu_button_) + return app_menu_button_; + + return custom_tab_bar_ ? custom_tab_bar_->custom_tab_menu_button() : nullptr; +} + +gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_bottom) { + if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) + return gfx::Rect(); + + if (!location_bar_->IsDrawn()) + return gfx::Rect(); + + gfx::Rect bounds = + location_bar_->ConvertRectToWidget(location_bar_->GetLocalBounds()); + return gfx::Rect(bounds.x(), bounds.bottom(), bounds.width(), + contents_bottom - bounds.bottom()); +} + +void ToolbarView::FocusToolbar() { + SetPaneFocus(nullptr); +} + +views::AccessiblePaneView* ToolbarView::GetAsAccessiblePaneView() { + return this; +} + +views::View* ToolbarView::GetAnchorView(PageActionIconType type) { + return location_bar_; +} + +void ToolbarView::ZoomChangedForActiveTab(bool can_show_bubble) { + location_bar_->page_action_icon_controller()->ZoomChangedForActiveTab( + can_show_bubble); +} + +SidePanelToolbarButton* ToolbarView::GetSidePanelButton() { + return side_panel_button_; +} + +AvatarToolbarButton* ToolbarView::GetAvatarToolbarButton() { + if (avatar_) + return avatar_; + + return nullptr; +} + +ToolbarButton* ToolbarView::GetBackButton() { + return back_; +} + +ReloadButton* ToolbarView::GetReloadButton() { + return reload_; +} + +IntentChipButton* ToolbarView::GetIntentChipButton() { + return location_bar()->intent_chip(); +} + +BrowserRootView::DropIndex ToolbarView::GetDropIndex( + const ui::DropTargetEvent& event) { + return {browser_->tab_strip_model()->active_index(), false}; +} + +BrowserRootView::DropTarget* ToolbarView::GetDropTarget( + gfx::Point loc_in_local_coords) { + return HitTestPoint(loc_in_local_coords) ? this : nullptr; +} + +views::View* ToolbarView::GetViewForDrop() { + return this; +} + +void ToolbarView::OnChromeLabsPrefChanged() { + chrome_labs_button_->SetVisible(show_chrome_labs_button_.GetValue()); + GetViewAccessibility().AnnounceText(l10n_util::GetStringUTF16( + chrome_labs_button_->GetVisible() + ? IDS_ACCESSIBLE_TEXT_CHROMELABS_BUTTON_ADDED_BY_ENTERPRISE_POLICY + : IDS_ACCESSIBLE_TEXT_CHROMELABS_BUTTON_REMOVED_BY_ENTERPRISE_POLICY)); +} + +void ToolbarView::LoadImages() { + DCHECK_EQ(display_mode_, DisplayMode::NORMAL); + + if (extensions_container_) + extensions_container_->UpdateAllIcons(); +} + +void ToolbarView::ShowCriticalNotification() { +#if BUILDFLAG(IS_WIN) + views::BubbleDialogDelegateView::CreateBubble( + new CriticalNotificationBubbleView(app_menu_button_)) + ->Show(); +#endif +} + +void ToolbarView::ShowOutdatedInstallNotification(bool auto_update_enabled) { +#if !BUILDFLAG(IS_CHROMEOS_ASH) + // TODO(pbos): Can this move outside ToolbarView completely? + ShowOutdatedUpgradeBubble(browser_, auto_update_enabled); +#endif +} + +void ToolbarView::OnShowHomeButtonChanged() { + home_->SetVisible(show_home_button_.GetValue()); + Layout(); + SchedulePaint(); +} + +void ToolbarView::OnTouchUiChanged() { + if (display_mode_ == DisplayMode::NORMAL) { + // Update the internal margins for touch layout. + // TODO(dfried): I think we can do better than this by making the touch UI + // code cleaner. + const int default_margin = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); + const int location_bar_margin = GetLayoutConstant(TOOLBAR_STANDARD_SPACING); + layout_manager_->SetDefault(views::kMarginsKey, + gfx::Insets::VH(0, default_margin)); + location_bar_->SetProperty(views::kMarginsKey, + gfx::Insets::VH(0, location_bar_margin)); + + LoadImages(); + PreferredSizeChanged(); + } +} + +BEGIN_METADATA(ToolbarView, views::AccessiblePaneView) +ADD_READONLY_PROPERTY_METADATA(bool, AppMenuFocused) +END_METADATA diff --git a/michael-patches/michael-customizations.patch b/michael-patches/michael-customizations.patch index c2adbe7..8c4e60d 100644 --- a/michael-patches/michael-customizations.patch +++ b/michael-patches/michael-customizations.patch @@ -1,30 +1,24 @@ diff --git a/chrome/browser/ui/tabs/tab_menu_model.cc b/chrome/browser/ui/tabs/tab_menu_model.cc -index 08b078d90..a2cdc60be 100644 +index 8d557554..a5afac82 100644 --- a/chrome/browser/ui/tabs/tab_menu_model.cc +++ b/chrome/browser/ui/tabs/tab_menu_model.cc -@@ -49,47 +49,51 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { - } - - int num_tabs = indices.size(); -+ // New Tab +@@ -51,42 +51,45 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { AddItemWithStringId(TabStripModel::CommandNewTabToRight, base::i18n::IsRTL() ? IDS_TAB_CXMENU_NEWTABTOLEFT : IDS_TAB_CXMENU_NEWTABTORIGHT); -- if (reading_list::switches::IsReadingListEnabled() && -- !tab_strip->profile()->IsGuestSession()) { +- if (!tab_strip->profile()->IsGuestSession()) { - AddItem( - TabStripModel::CommandAddToReadLater, - l10n_util::GetPluralStringFUTF16(IDS_TAB_CXMENU_READ_LATER, num_tabs)); - SetEnabledAt(GetItemCount() - 1, - tab_strip->IsReadLaterSupportedForAny(indices)); -- if (base::FeatureList::IsEnabled(features::kReadLaterNewBadgePromo)) -- SetIsNewFeatureAt(GetItemCount() - 1, true); - } -- if (ExistingTabGroupSubMenuModel::ShouldShowSubmenu(tab_strip, index)) { +- if (ExistingTabGroupSubMenuModel::ShouldShowSubmenu( +- tab_strip, index, tab_menu_model_delegate_)) { - // Create submenu with existing groups - add_to_existing_group_submenu_ = -- std::make_unique(delegate(), tab_strip, -- index); +- std::make_unique( +- delegate(), tab_menu_model_delegate_, tab_strip, index); - AddSubMenu(TabStripModel::CommandAddToExistingGroup, - l10n_util::GetPluralStringFUTF16(IDS_TAB_CXMENU_ADD_TAB_TO_GROUP, - num_tabs), @@ -39,31 +33,21 @@ index 08b078d90..a2cdc60be 100644 - if (base::FeatureList::IsEnabled(features::kTabGroupsNewBadgePromo)) - SetIsNewFeatureAt(GetItemCount() - 1, true); - } -- -- for (const auto& selection : indices) { -- if (tab_strip->GetTabGroupForTab(selection).has_value()) { -- AddItemWithStringId(TabStripModel::CommandRemoveFromGroup, -- IDS_TAB_CXMENU_REMOVE_TAB_FROM_GROUP); -- break; -- } -- } -+ // Add to reading list (removed) -+ // if (reading_list::switches::IsReadingListEnabled() && -+ // !tab_strip->profile()->IsGuestSession()) { ++ // Add to Reading List ++ // if (!tab_strip->profile()->IsGuestSession()) { + // AddItem( + // TabStripModel::CommandAddToReadLater, + // l10n_util::GetPluralStringFUTF16(IDS_TAB_CXMENU_READ_LATER, num_tabs)); + // SetEnabledAt(GetItemCount() - 1, + // tab_strip->IsReadLaterSupportedForAny(indices)); -+ // if (base::FeatureList::IsEnabled(features::kReadLaterNewBadgePromo)) -+ // SetIsNewFeatureAt(GetItemCount() - 1, true); + // } -+ // Change tab group (removed) -+ // if (ExistingTabGroupSubMenuModel::ShouldShowSubmenu(tab_strip, index)) { ++ // Change Tab Group ++ // if (ExistingTabGroupSubMenuModel::ShouldShowSubmenu( ++ // tab_strip, index, tab_menu_model_delegate_)) { + // // Create submenu with existing groups + // add_to_existing_group_submenu_ = -+ // std::make_unique(delegate(), tab_strip, -+ // index); ++ // std::make_unique( ++ // delegate(), tab_menu_model_delegate_, tab_strip, index); + // AddSubMenu(TabStripModel::CommandAddToExistingGroup, + // l10n_util::GetPluralStringFUTF16(IDS_TAB_CXMENU_ADD_TAB_TO_GROUP, + // num_tabs), @@ -78,7 +62,14 @@ index 08b078d90..a2cdc60be 100644 + // if (base::FeatureList::IsEnabled(features::kTabGroupsNewBadgePromo)) + // SetIsNewFeatureAt(GetItemCount() - 1, true); + // } -+ // + +- for (const auto& selection : indices) { +- if (tab_strip->GetTabGroupForTab(selection).has_value()) { +- AddItemWithStringId(TabStripModel::CommandRemoveFromGroup, +- IDS_TAB_CXMENU_REMOVE_TAB_FROM_GROUP); +- break; +- } +- } + // for (const auto& selection : indices) { + // if (tab_strip->GetTabGroupForTab(selection).has_value()) { + // AddItemWithStringId(TabStripModel::CommandRemoveFromGroup, @@ -87,11 +78,11 @@ index 08b078d90..a2cdc60be 100644 + // } + // } -+ // New Window / Move to other window ++ // New Window / Move to other Window if (ExistingWindowSubMenuModel::ShouldShowSubmenu(tab_strip->profile())) { // Create submenu with existing windows add_to_existing_window_submenu_ = ExistingWindowSubMenuModel::Create( -@@ -105,9 +109,17 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { +@@ -102,9 +105,17 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { } AddSeparator(ui::NORMAL_SEPARATOR); @@ -112,9 +103,9 @@ index 08b078d90..a2cdc60be 100644 bool will_pin = tab_strip->WillContextMenuPin(index); AddItemWithStringId( TabStripModel::CommandTogglePinned, -@@ -159,14 +171,6 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { +@@ -139,14 +150,6 @@ void TabMenuModel::Build(TabStripModel* tab_strip, int index) { + ui::ImageModel::FromVectorIcon(kLaptopAndSmartphoneIcon)); #endif - } } - - AddSeparator(ui::NORMAL_SEPARATOR); @@ -128,7 +119,7 @@ index 08b078d90..a2cdc60be 100644 DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(TabMenuModel, diff --git a/chrome/browser/ui/views/frame/tab_strip_region_view.cc b/chrome/browser/ui/views/frame/tab_strip_region_view.cc -index 1e741368e..fac2b5f51 100644 +index 5ecd2cb5..5e71050d 100644 --- a/chrome/browser/ui/views/frame/tab_strip_region_view.cc +++ b/chrome/browser/ui/views/frame/tab_strip_region_view.cc @@ -142,7 +142,8 @@ TabStripRegionView::TabStripRegionView(std::unique_ptr tab_strip) { @@ -142,71 +133,47 @@ index 1e741368e..fac2b5f51 100644 tab_search_button->SetTooltipText( l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_SEARCH)); diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc -index 03e8c0fb9..2acc440b1 100644 +index 25792a74..0939f1e7 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc -@@ -354,14 +354,15 @@ void LocationBarView::Init() { - params.types_enabled.push_back(PageActionIconType::kSaveAutofillAddress); - } +@@ -339,10 +339,11 @@ void LocationBarView::Init() { + // final mocks. + params.types_enabled.push_back(PageActionIconType::kSaveAutofillAddress); } - if (browser_) { --#if BUILDFLAG(IS_CHROMEOS_ASH) -- params.types_enabled.push_back(PageActionIconType::kSharingHub); --#else -- if (sharing_hub::SharingHubOmniboxEnabled(profile_) && !is_popup_mode_) +- if (sharing_hub::HasPageAction(profile_, is_popup_mode_)) - params.types_enabled.push_back(PageActionIconType::kSharingHub); --#endif - } -+ // Remove sharing hub icon -+// if (browser_) { -+// #if BUILDFLAG(IS_CHROMEOS_ASH) -+// params.types_enabled.push_back(PageActionIconType::kSharingHub); -+// #else -+// if (sharing_hub::SharingHubOmniboxEnabled(profile_) && !is_popup_mode_) -+// params.types_enabled.push_back(PageActionIconType::kSharingHub); -+// #endif -+// } ++ // Remove sharing hub icon ++ // if (browser_) { ++ // if (sharing_hub::HasPageAction(profile_, is_popup_mode_)) ++ // params.types_enabled.push_back(PageActionIconType::kSharingHub); ++ // } if (browser_ && !is_popup_mode_) params.types_enabled.push_back(PageActionIconType::kBookmarkStar); diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.cc b/chrome/browser/ui/views/toolbar/toolbar_view.cc -index 76fce2124..cfe392364 100644 +index dade217a..bf25de0b 100644 --- a/chrome/browser/ui/views/toolbar/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar/toolbar_view.cc -@@ -378,20 +378,22 @@ void ToolbarView::Init() { +@@ -335,8 +335,8 @@ void ToolbarView::Init() { if (send_tab_to_self_button) send_tab_to_self_button_ = AddChildView(std::move(send_tab_to_self_button)); - if (side_panel_button) - side_panel_button_ = AddChildView(std::move(side_panel_button)); -- -- if (toolbar_account_icon_container) { -- toolbar_account_icon_container_ = -- AddChildView(std::move(toolbar_account_icon_container)); -- avatar_ = toolbar_account_icon_container_->avatar_button(); -- } else { -- // TODO(crbug.com/932818): Remove this once the -- // |kAutofillEnableToolbarStatusChip| is fully launched. -- avatar_ = -- AddChildView(std::make_unique(browser_view_)); -- avatar_->SetVisible(show_avatar_toolbar_button); -- } -+ // Remove side panel + // if (side_panel_button) + // side_panel_button_ = AddChildView(std::move(side_panel_button)); -+ -+ // Remove toolbar -+ // if (toolbar_account_icon_container) { -+ // toolbar_account_icon_container_ = -+ // AddChildView(std::move(toolbar_account_icon_container)); -+ // avatar_ = toolbar_account_icon_container_->avatar_button(); -+ // } else { -+ // // TODO(crbug.com/932818): Remove this once the -+ // // |kAutofillEnableToolbarStatusChip| is fully launched. -+ // avatar_ = -+ // AddChildView(std::make_unique(browser_view_)); -+ // avatar_->SetVisible(show_avatar_toolbar_button); -+ // } + + avatar_ = AddChildView(std::make_unique(browser_view_)); + +@@ -363,7 +363,8 @@ void ToolbarView::Init() { + else if (flag_value == "never") + show_avatar_toolbar_button = false; + +- avatar_->SetVisible(show_avatar_toolbar_button); ++ // Always disable avatar / account icon ++ avatar_->SetVisible(false); auto app_menu_button = std::make_unique(this); app_menu_button->SetFlipCanvasOnPaintForRTLUI(true);