#include "chrome/browser/ui/commerce/commerce_ui_tab_helper.h"
#include "base/check_is_test.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/feature_engagement/tracker_factory.h"
#include "chrome/browser/profiles/profile.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/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/commerce/commerce_page_action_controller.h"
#include "chrome/browser/ui/commerce/discounts_page_action_controller.h"
#include "chrome/browser/ui/commerce/price_tracking_page_action_controller.h"
#include "chrome/browser/ui/commerce/product_specifications_page_action_controller.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/commerce/price_insights_icon_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_registry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_ui.h"
#include "chrome/browser/ui/views/side_panel/side_panel_web_ui_view.h"
#include "chrome/browser/ui/webui/commerce/shopping_insights_side_panel_ui.h"
#include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/commerce/core/commerce_constants.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/commerce_utils.h"
#include "components/commerce/core/feature_utils.h"
#include "components/commerce/core/metrics/discounts_metric_collector.h"
#include "components/commerce/core/metrics/metrics_utils.h"
#include "components/commerce/core/price_tracking_utils.h"
#include "components/image_fetcher/core/image_fetcher.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/views/vector_icons.h"
#include "ui/views/view_class_properties.h"
#include "url/gurl.h"
SidePanelWebUIViewT_ShoppingInsightsSidePanelUI;
ShoppingContextualFeature;
BEGIN_TEMPLATE_METADATA(…)
namespace commerce {
namespace {
void UpdatePageActionIconView(content::WebContents* web_contents,
PageActionIconType type) { … }
}
CommerceUiTabHelper::CommerceUiTabHelper(
content::WebContents* content,
ShoppingService* shopping_service,
bookmarks::BookmarkModel* model,
image_fetcher::ImageFetcher* image_fetcher,
SidePanelRegistry* side_panel_registry)
: … { … }
CommerceUiTabHelper::~CommerceUiTabHelper() = default;
void CommerceUiTabHelper::RegisterProfilePrefs(
PrefRegistrySimple* registry) { … }
void CommerceUiTabHelper::UpdateUiForShoppingServiceReady(
ShoppingService* service) { … }
void CommerceUiTabHelper::DidFinishNavigation(
content::NavigationHandle* navigation_handle) { … }
bool CommerceUiTabHelper::ShouldIgnoreSameUrlNavigation() { … }
bool CommerceUiTabHelper::IsSameDocumentWithSameCommittedUrl(
content::NavigationHandle* navigation_handle) { … }
void CommerceUiTabHelper::WebContentsDestroyed() { … }
void CommerceUiTabHelper::TriggerUpdateForIconView() { … }
void CommerceUiTabHelper::UpdatePriceInsightsIconView() { … }
void CommerceUiTabHelper::SetImageFetcherForTesting(
image_fetcher::ImageFetcher* image_fetcher) { … }
bool CommerceUiTabHelper::ShouldShowDiscountsIconView() { … }
bool CommerceUiTabHelper::ShouldShowPriceTrackingIconView() { … }
bool CommerceUiTabHelper::ShouldShowPriceInsightsIconView() { … }
bool CommerceUiTabHelper::ShouldShowProductSpecificationsIconView() { … }
void CommerceUiTabHelper::HandleProductInfoResponse(
const GURL& url,
const std::optional<const ProductInfo>& info) { … }
void CommerceUiTabHelper::HandlePriceInsightsInfoResponse(
const GURL& url,
const std::optional<PriceInsightsInfo>& info) { … }
void CommerceUiTabHelper::MaybeComputePageActionToExpand() { … }
void CommerceUiTabHelper::SetPriceTrackingState(
bool enable,
bool is_new_bookmark,
base::OnceCallback<void(bool)> callback) { … }
void CommerceUiTabHelper::OnPriceInsightsIconClicked() { … }
const gfx::Image& CommerceUiTabHelper::GetProductImage() { … }
const GURL& CommerceUiTabHelper::GetProductImageURL() { … }
bool CommerceUiTabHelper::IsPriceTracking() { … }
bool CommerceUiTabHelper::IsInRecommendedSet() { … }
std::u16string CommerceUiTabHelper::GetProductSpecificationsLabel(
bool is_added) { … }
const std::vector<DiscountInfo>& CommerceUiTabHelper::GetDiscounts() { … }
void CommerceUiTabHelper::UpdatePriceTrackingIconView() { … }
void CommerceUiTabHelper::UpdateProductSpecificationsIconView() { … }
void CommerceUiTabHelper::MakeShoppingInsightsSidePanelAvailable() { … }
void CommerceUiTabHelper::MakeShoppingInsightsSidePanelUnavailable() { … }
std::unique_ptr<views::View>
CommerceUiTabHelper::CreateShoppingInsightsWebView() { … }
SidePanelUI* CommerceUiTabHelper::GetSidePanelUI() const { … }
const std::optional<bool>&
CommerceUiTabHelper::GetPendingTrackingStateForTesting() { … }
const std::optional<PriceInsightsInfo>&
CommerceUiTabHelper::GetPriceInsightsInfo() { … }
void CommerceUiTabHelper::UpdateDiscountsIconView() { … }
bool CommerceUiTabHelper::IsShowingDiscountsIcon() { … }
void CommerceUiTabHelper::ComputePageActionToExpand() { … }
PriceInsightsIconView::PriceInsightsIconLabelType
CommerceUiTabHelper::GetPriceInsightsIconLabelTypeForPage() { … }
bool CommerceUiTabHelper::ShouldExpandPageActionIcon(
PageActionIconType type) { … }
bool CommerceUiTabHelper::IsPageActionIconExpanded(PageActionIconType type) { … }
void CommerceUiTabHelper::OnPriceTrackingIconClicked() { … }
void CommerceUiTabHelper::OnProductSpecificationsIconClicked() { … }
void CommerceUiTabHelper::OnDiscountsCouponCodeCopied() { … }
bool CommerceUiTabHelper::IsDiscountsCouponCodeCopied() { … }
bool CommerceUiTabHelper::ShouldAutoShowDiscountsBubble(uint64_t discount_id,
bool is_merchant_wide) { … }
void CommerceUiTabHelper::DiscountsBubbleShown(uint64_t discount_id) { … }
void CommerceUiTabHelper::RecordIconMetrics(PageActionIconType page_action,
bool from_icon_use) { … }
void CommerceUiTabHelper::RecordPriceInsightsIconMetrics(bool from_icon_use) { … }
void CommerceUiTabHelper::MaybeRecordShoppingInformationUKM(
std::optional<PageActionIconType> page_action_type) { … }
PriceTrackingPageActionController*
CommerceUiTabHelper::GetPriceTrackingControllerForTesting() { … }
void CommerceUiTabHelper::OnPageActionControllerNotification(
base::RepeatingClosure page_action_icon_update_callback) { … }
base::RepeatingClosure
CommerceUiTabHelper::GetPageActionControllerNotificationCallback(
base::RepeatingClosure page_action_icon_update_callback) { … }
void CommerceUiTabHelper::SetPriceTrackingControllerForTesting(
std::unique_ptr<PriceTrackingPageActionController> controller) { … }
}