1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_TABS_PUBLIC_TAB_FEATURES_H_
#define CHROME_BROWSER_UI_TABS_PUBLIC_TAB_FEATURES_H_
#include <memory>
#include <vector>
#include "base/callback_list.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "chrome/common/buildflags.h"
class FileSystemAccessPageActionController;
class FromGWSNavigationAndKeepAliveRequestObserver;
class IntentPickerViewPageActionController;
class LensOverlayController;
class LensSearchController;
class MemorySaverChipTabHelper;
class PinnedTranslateActionListener;
class Profile;
class PwaInstallPageActionController;
class ReadAnythingSidePanelController;
class SidePanelRegistry;
class TabResourceUsageTabHelper;
class TabUIHelper;
class TranslatePageActionController;
class QwacWebContentsObserver;
class ManagePasswordsPageActionController;
namespace commerce {
class CommerceUiTabHelper;
class PriceInsightsPageActionViewController;
}
namespace content {
class WebContents;
} // namespace content
namespace contextual_cueing {
class ContextualCueingHelper;
} // namespace contextual_cueing
namespace customize_chrome {
class SidePanelController;
} // namespace customize_chrome
namespace enterprise_data_protection {
class DataProtectionNavigationController;
} // namespace enterprise_data_protection
namespace extensions {
class ExtensionSidePanelManager;
} // namespace extensions
#if BUILDFLAG(ENABLE_GLIC)
namespace glic {
class GlicTabIndicatorHelper;
}
#endif
namespace memory_saver {
class MemorySaverChipController;
}
namespace zoom {
class ZoomViewController;
}
namespace permissions {
class PermissionIndicatorsTabData;
} // namespace permissions
namespace privacy_sandbox {
class PrivacySandboxTabObserver;
class PrivacySandboxIncognitoTabObserver;
} // namespace privacy_sandbox
namespace metrics {
class DwaWebContentsObserver;
} // namespace metrics
namespace sync_sessions {
class SyncSessionsRouterTabHelper;
} // namespace sync_sessions
namespace tab_groups {
class SavedTabGroupWebContentsListener;
} // namespace tab_groups
namespace page_actions {
class PageActionController;
} // namespace page_actions
namespace passage_embeddings {
class EmbedderTabObserver;
} // namespace passage_embeddings
namespace tab_groups {
class CollaborationMessagingTabData;
} // namespace tab_groups
namespace tabs {
class TabAlertController;
class TabInterface;
class TabDialogManager;
class InactiveWindowMouseEventController;
// This class owns the core controllers for features that are scoped to a given
// tab. It can be subclassed by tests to perform dependency injection.
class TabFeatures {
public:
static std::unique_ptr<TabFeatures> CreateTabFeatures();
virtual ~TabFeatures();
TabFeatures(const TabFeatures&) = delete;
TabFeatures& operator=(const TabFeatures&) = delete;
// Call this method to stub out TabFeatures for tests.
using TabFeaturesFactory =
base::RepeatingCallback<std::unique_ptr<TabFeatures>()>;
static void ReplaceTabFeaturesForTesting(TabFeaturesFactory factory);
LensSearchController* lens_search_controller() {
return lens_search_controller_.get();
}
enterprise_data_protection::DataProtectionNavigationController*
data_protection_controller() {
return data_protection_controller_.get();
}
permissions::PermissionIndicatorsTabData* permission_indicators_tab_data() {
return permission_indicators_tab_data_.get();
}
customize_chrome::SidePanelController*
customize_chrome_side_panel_controller() {
return customize_chrome_side_panel_controller_.get();
}
// Note: Temporary until there is a more uniform way to swap out features for
// testing.
customize_chrome::SidePanelController*
SetCustomizeChromeSidePanelControllerForTesting(
std::unique_ptr<customize_chrome::SidePanelController>
customize_chrome_side_panel_controller);
// This side-panel registry is tab-scoped. It is different from the browser
// window scoped SidePanelRegistry.
SidePanelRegistry* side_panel_registry() {
return side_panel_registry_.get();
}
ReadAnythingSidePanelController* read_anything_side_panel_controller() {
return read_anything_side_panel_controller_.get();
}
commerce::CommerceUiTabHelper* commerce_ui_tab_helper() {
return commerce_ui_tab_helper_.get();
}
privacy_sandbox::PrivacySandboxTabObserver* privacy_sandbox_tab_observer() {
return privacy_sandbox_tab_observer_.get();
}
privacy_sandbox::PrivacySandboxIncognitoTabObserver*
privacy_sandbox_incognito_tab_observer() {
return privacy_sandbox_incognito_tab_observer_.get();
}
metrics::DwaWebContentsObserver* dwa_web_contents_observer() {
return dwa_web_contents_observer_.get();
}
extensions::ExtensionSidePanelManager* extension_side_panel_manager() {
return extension_side_panel_manager_.get();
}
tab_groups::SavedTabGroupWebContentsListener*
saved_tab_group_web_contents_listener() const {
return saved_tab_group_web_contents_listener_.get();
}
TabDialogManager* tab_dialog_manager() { return tab_dialog_manager_.get(); }
page_actions::PageActionController* page_action_controller() {
return page_action_controller_.get();
}
IntentPickerViewPageActionController*
intent_picker_view_page_action_controller() {
return intent_picker_view_page_action_controller_.get();
}
FileSystemAccessPageActionController*
file_system_access_page_action_controller() {
return file_system_access_page_action_controller_.get();
}
ManagePasswordsPageActionController*
manage_passwords_page_action_controller() {
return manage_passwords_page_action_controller_.get();
}
tab_groups::CollaborationMessagingTabData*
collaboration_messaging_tab_data() {
return collaboration_messaging_tab_data_.get();
}
zoom::ZoomViewController* zoom_view_controller() {
return zoom_view_controller_.get();
}
memory_saver::MemorySaverChipController* memory_saver_chip_controller() {
return memory_saver_chip_controller_.get();
}
commerce::PriceInsightsPageActionViewController*
commerce_price_insights_page_action_view_controller() {
return commerce_price_insights_page_action_view_controller_.get();
}
LensOverlayController* lens_overlay_controller();
const LensOverlayController* lens_overlay_controller() const;
PwaInstallPageActionController* pwa_install_page_action_controller() {
return pwa_install_page_action_controller_.get();
}
InactiveWindowMouseEventController* inactive_window_mouse_event_controller() {
return inactive_window_mouse_event_controller_.get();
}
TabResourceUsageTabHelper* resource_usage_helper() {
return resource_usage_helper_.get();
}
MemorySaverChipTabHelper* memory_saver_chip_helper() {
return memory_saver_chip_helper_.get();
}
TabUIHelper* tab_ui_helper() { return tab_ui_helper_.get(); }
// Note: Temporary until there is a more uniform way to swap out features for
// testing.
TabResourceUsageTabHelper* SetResourceUsageHelperForTesting(
std::unique_ptr<TabResourceUsageTabHelper> resource_usage_helper);
TabUIHelper* SetTabUIHelperForTesting(
std::unique_ptr<TabUIHelper> tab_ui_helper);
TabAlertController* tab_alert_controller() {
return tab_alert_controller_.get();
}
// Called exactly once to initialize features.
// Can be overridden in tests to initialize nothing.
virtual void Init(TabInterface& tab, Profile* profile);
protected:
TabFeatures();
// Override these methods to stub out individual feature controllers for
// testing.
virtual std::unique_ptr<LensSearchController> CreateLensController(
TabInterface* tab);
virtual std::unique_ptr<commerce::CommerceUiTabHelper>
CreateCommerceUiTabHelper(TabInterface& tab, Profile* profile);
private:
bool initialized_ = false;
// TODO(https://crbug.com/347770670): Delete this code when tab-discarding no
// longer swizzles WebContents.
// Called when the tab's WebContents is discarded.
void WillDiscardContents(tabs::TabInterface* tab,
content::WebContents* old_contents,
content::WebContents* new_contents);
std::unique_ptr<
enterprise_data_protection::DataProtectionNavigationController>
data_protection_controller_;
std::unique_ptr<permissions::PermissionIndicatorsTabData>
permission_indicators_tab_data_;
std::unique_ptr<SidePanelRegistry> side_panel_registry_;
std::unique_ptr<LensSearchController> lens_search_controller_;
// Responsible for the customize chrome tab-scoped side panel.
std::unique_ptr<customize_chrome::SidePanelController>
customize_chrome_side_panel_controller_;
std::unique_ptr<ReadAnythingSidePanelController>
read_anything_side_panel_controller_;
// Responsible for commerce related features.
std::unique_ptr<commerce::CommerceUiTabHelper> commerce_ui_tab_helper_;
// Responsible for updating status indicator of the pinned translate button.
std::unique_ptr<PinnedTranslateActionListener>
pinned_translate_action_listener_;
std::unique_ptr<privacy_sandbox::PrivacySandboxTabObserver>
privacy_sandbox_tab_observer_;
std::unique_ptr<privacy_sandbox::PrivacySandboxIncognitoTabObserver>
privacy_sandbox_incognito_tab_observer_;
std::unique_ptr<metrics::DwaWebContentsObserver>
dwa_web_contents_observer_;
// The tab-scoped extension side-panel manager. There is a separate
// window-scoped extension side-panel manager.
std::unique_ptr<extensions::ExtensionSidePanelManager>
extension_side_panel_manager_;
// Forwards tab-related events to sync.
std::unique_ptr<sync_sessions::SyncSessionsRouterTabHelper>
sync_sessions_router_;
// Responsible for keeping a tab within a tab group in sync with its remote
// tab counterpart from sync.
std::unique_ptr<tab_groups::SavedTabGroupWebContentsListener>
saved_tab_group_web_contents_listener_;
// Manages various tab modal dialogs.
std::unique_ptr<TabDialogManager> tab_dialog_manager_;
// Holds subscriptions for TabInterface callbacks.
std::vector<base::CallbackListSubscription> tab_subscriptions_;
// Responsible for managing the "Intent Picker" page action.
std::unique_ptr<IntentPickerViewPageActionController>
intent_picker_view_page_action_controller_;
// Responsible for managing the "File System Access" page action.
std::unique_ptr<FileSystemAccessPageActionController>
file_system_access_page_action_controller_;
// Responsible for managing all page actions of a tab. Other controllers
// interact with this to have their feature's page action shown.
std::unique_ptr<page_actions::PageActionController> page_action_controller_;
// Responsible for managing the "Manage Passwords" page action.
std::unique_ptr<ManagePasswordsPageActionController>
manage_passwords_page_action_controller_;
// Responsible for managing the "Translate" page action.
std::unique_ptr<TranslatePageActionController>
translate_page_action_controller_;
// Responsible for managing the "PWA Install" page action.
std::unique_ptr<PwaInstallPageActionController>
pwa_install_page_action_controller_;
// Responsible for managing the "Zoom" page action and bubble.
std::unique_ptr<zoom::ZoomViewController> zoom_view_controller_;
// Responsible for managing the commerce "Price insights" page action.
std::unique_ptr<commerce::PriceInsightsPageActionViewController>
commerce_price_insights_page_action_view_controller_;
// Contains the recent collaboration message for a shared tab.
std::unique_ptr<tab_groups::CollaborationMessagingTabData>
collaboration_messaging_tab_data_;
std::unique_ptr<passage_embeddings::EmbedderTabObserver>
embedder_tab_observer_;
#if BUILDFLAG(ENABLE_GLIC)
std::unique_ptr<glic::GlicTabIndicatorHelper> glic_tab_indicator_helper_;
#endif
std::unique_ptr<memory_saver::MemorySaverChipController>
memory_saver_chip_controller_;
std::unique_ptr<InactiveWindowMouseEventController>
inactive_window_mouse_event_controller_;
std::unique_ptr<FromGWSNavigationAndKeepAliveRequestObserver>
from_gws_navigation_and_keep_alive_request_observer_;
std::unique_ptr<TabResourceUsageTabHelper> resource_usage_helper_;
std::unique_ptr<MemorySaverChipTabHelper> memory_saver_chip_helper_;
std::unique_ptr<TabAlertController> tab_alert_controller_;
std::unique_ptr<TabUIHelper> tab_ui_helper_;
std::unique_ptr<QwacWebContentsObserver> qwac_web_contents_observer_;
// Must be the last member.
base::WeakPtrFactory<TabFeatures> weak_factory_{this};
};
} // namespace tabs
#endif // CHROME_BROWSER_UI_TABS_PUBLIC_TAB_FEATURES_H_
|