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
|
// Copyright 2019 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_WEBUI_NEW_TAB_PAGE_NEW_TAB_PAGE_UI_H_
#define CHROME_BROWSER_UI_WEBUI_NEW_TAB_PAGE_NEW_TAB_PAGE_UI_H_
#include <string>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/new_tab_page/modules/file_suggestion/drive_suggestion.mojom.h"
#include "chrome/browser/new_tab_page/modules/file_suggestion/microsoft_files.mojom.h"
#include "chrome/browser/new_tab_page/modules/new_tab_page_modules.h"
#include "chrome/browser/new_tab_page/modules/v2/authentication/microsoft_auth.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/google_calendar.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/calendar/outlook_calendar.mojom.h"
#include "chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption.mojom.h"
#include "components/user_education/webui/help_bubble_handler.h"
#include "ui/webui/resources/cr_components/help_bubble/help_bubble.mojom.h"
#include "ui/webui/resources/js/browser_command/browser_command.mojom.h"
#if !defined(OFFICIAL_BUILD)
#include "chrome/browser/ui/webui/new_tab_page/foo/foo.mojom.h" // nogncheck crbug.com/1125897
#endif
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/search/background/ntp_custom_background_service_observer.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_observer.h"
#include "chrome/browser/ui/webui/customize_buttons/customize_buttons.mojom.h"
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page.mojom.h"
#include "chrome/common/webui_url_constants.h"
#include "components/page_image_service/mojom/page_image_service.mojom.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/webui_config.h"
#include "content/public/common/url_constants.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
#include "ui/webui/mojo_web_ui_controller.h"
#include "ui/webui/resources/cr_components/color_change_listener/color_change_listener.mojom.h"
#include "ui/webui/resources/cr_components/most_visited/most_visited.mojom.h"
#include "ui/webui/resources/cr_components/searchbox/searchbox.mojom-forward.h"
namespace base {
class RefCountedMemory;
} // namespace base
namespace content {
class NavigationHandle;
class WebUI;
} // namespace content
namespace page_image_service {
class ImageServiceHandler;
} // namespace page_image_service
namespace ui {
class ColorChangeHandler;
} // namespace ui
class BrowserCommandHandler;
class CustomizeButtonsHandler;
class DriveSuggestionHandler;
#if !defined(OFFICIAL_BUILD)
class FooHandler;
#endif
class GoogleCalendarPageHandler;
class OutlookCalendarPageHandler;
class GURL;
class MicrosoftAuthPageHandler;
class MicrosoftFilesPageHandler;
class MostRelevantTabResumptionPageHandler;
class MostVisitedHandler;
class NewTabPageHandler;
class NtpCustomBackgroundService;
class PrefRegistrySimple;
class PrefService;
class Profile;
class RealboxHandler;
class NewTabPageUI;
class NewTabPageUIConfig : public content::DefaultWebUIConfig<NewTabPageUI> {
public:
NewTabPageUIConfig()
: DefaultWebUIConfig(content::kChromeUIScheme,
chrome::kChromeUINewTabPageHost) {}
// content::WebUIConfig:
std::unique_ptr<content::WebUIController> CreateWebUIController(
content::WebUI* web_ui,
const GURL& url) override;
bool IsWebUIEnabled(content::BrowserContext* browser_context) override;
};
class NewTabPageUI
: public ui::MojoWebUIController,
public new_tab_page::mojom::PageHandlerFactory,
public customize_buttons::mojom::CustomizeButtonsHandlerFactory,
public most_visited::mojom::MostVisitedPageHandlerFactory,
public browser_command::mojom::CommandHandlerFactory,
public help_bubble::mojom::HelpBubbleHandlerFactory,
public NtpCustomBackgroundServiceObserver,
content::WebContentsObserver {
public:
explicit NewTabPageUI(content::WebUI* web_ui);
NewTabPageUI(const NewTabPageUI&) = delete;
NewTabPageUI& operator=(const NewTabPageUI&) = delete;
~NewTabPageUI() override;
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kCustomizeChromeButtonElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kModulesCustomizeIPHAnchorElement);
static bool IsNewTabPageOrigin(const GURL& url);
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
static void ResetProfilePrefs(PrefService* prefs);
static bool IsManagedProfile(Profile* profile);
// Instantiates the implementor of the mojom::PageHandlerFactory mojo
// interface passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<new_tab_page::mojom::PageHandlerFactory>
pending_receiver);
// Instantiates the implementor of the mojom::PageHandler mojo interface
// passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<color_change_listener::mojom::PageHandler>
pending_receiver);
// Instantiates the implementor of the searchbox::mojom::PageHandler mojo
// interface passing the pending receiver that will be internally bound.
void BindInterface(mojo::PendingReceiver<searchbox::mojom::PageHandler>
pending_page_handler);
// Instantiates the implementor of the
// browser_command::mojom::CommandHandlerFactory mojo interface passing
// the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<browser_command::mojom::CommandHandlerFactory>
pending_receiver);
// Instantiates the implementor of the
// customize_buttons::mojom::CustomizeButtonsHandlerFactory mojo interface
// passing the pending receiver that will be internally bound.
void BindInterface(mojo::PendingReceiver<
customize_buttons::mojom::CustomizeButtonsHandlerFactory>
pending_receiver);
// Instantiates the implementor of the
// most_visited::mojom::MostVisitedPageHandlerFactory mojo interface passing
// the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<most_visited::mojom::MostVisitedPageHandlerFactory>
pending_receiver);
// Instantiates the implementor of
// file_suggestion::mojom::DriveSuggestionHandler mojo interface passing the
// pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<file_suggestion::mojom::DriveSuggestionHandler>
pending_receiver);
// Instantiates the implementor of
// npt::calendar::mojom::GoogleCalendarPageHandler mojo interface passing the
// pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<ntp::calendar::mojom::GoogleCalendarPageHandler>
pending_receiver);
// Instantiates the implementor of
// npt::calendar::mojom::OutlookCalendarPageHandler mojo interface passing the
// pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<ntp::calendar::mojom::OutlookCalendarPageHandler>
pending_receiver);
// Instantiates the implementor of
// npt::authentication::mojom::MicrosoftAuthPageHandler mojo
// interface passing the pending receiver that will be internally bound.
void BindInterface(mojo::PendingReceiver<
ntp::authentication::mojom::MicrosoftAuthPageHandler>
pending_receiver);
// Instantiates the implementor of
// file_suggestion::mojom::MicrosoftFilesPageHandler mojo interface
// passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<file_suggestion::mojom::MicrosoftFilesPageHandler>
pending_receiver);
#if !defined(OFFICIAL_BUILD)
// Instantiates the implementor of the foo::mojom::FooHandler mojo interface
// passing the pending receiver that will be internally bound.
void BindInterface(
mojo::PendingReceiver<foo::mojom::FooHandler> pending_receiver);
#endif
void BindInterface(mojo::PendingReceiver<
ntp::most_relevant_tab_resumption::mojom::PageHandler>
pending_page_handler);
void BindInterface(
mojo::PendingReceiver<page_image_service::mojom::PageImageServiceHandler>
pending_page_handler);
void BindInterface(
mojo::PendingReceiver<help_bubble::mojom::HelpBubbleHandlerFactory>
pending_receiver);
void ConnectToParentDocument(
mojo::PendingRemote<new_tab_page::mojom::MicrosoftAuthUntrustedDocument>
child_page);
static base::RefCountedMemory* GetFaviconResourceBytes(
ui::ResourceScaleFactor scale_factor);
private:
// new_tab_page::mojom::PageHandlerFactory:
void CreatePageHandler(
mojo::PendingRemote<new_tab_page::mojom::Page> pending_page,
mojo::PendingReceiver<new_tab_page::mojom::PageHandler>
pending_page_handler) override;
// browser_command::mojom::CommandHandlerFactory
void CreateBrowserCommandHandler(
mojo::PendingReceiver<browser_command::mojom::CommandHandler>
pending_handler) override;
// customize_buttons::mojom::CustomizeButtonsHandlerFactory:
void CreateCustomizeButtonsHandler(
mojo::PendingRemote<customize_buttons::mojom::CustomizeButtonsDocument>
pending_page,
mojo::PendingReceiver<customize_buttons::mojom::CustomizeButtonsHandler>
pending_page_handler) override;
// most_visited::mojom::MostVisitedPageHandlerFactory:
void CreatePageHandler(
mojo::PendingRemote<most_visited::mojom::MostVisitedPage> pending_page,
mojo::PendingReceiver<most_visited::mojom::MostVisitedPageHandler>
pending_page_handler) override;
// help_bubble::mojom::HelpBubbleHandlerFactory:
void CreateHelpBubbleHandler(
mojo::PendingRemote<help_bubble::mojom::HelpBubbleClient> client,
mojo::PendingReceiver<help_bubble::mojom::HelpBubbleHandler> handler)
override;
// NtpCustomBackgroundServiceObserver:
void OnCustomBackgroundImageUpdated() override;
// content::WebContentsObserver:
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void OnColorProviderChanged() override;
bool IsCustomLinksEnabled() const;
bool IsShortcutsVisible() const;
// Callback for when the value of the pref for showing custom links vs. most
// visited sites in the NTP tiles changes.
void OnCustomLinksEnabledPrefChanged();
// Callback for when the value of the pref for showing the NTP tiles changes.
void OnTilesVisibilityPrefChanged();
// Called when the NTP (re)loads. Sets mutable load time data.
void OnLoad();
std::unique_ptr<NewTabPageHandler> page_handler_;
mojo::Receiver<new_tab_page::mojom::PageHandlerFactory>
page_factory_receiver_;
std::unique_ptr<ui::ColorChangeHandler> color_provider_handler_;
std::unique_ptr<CustomizeButtonsHandler> customize_buttons_handler_;
mojo::Receiver<customize_buttons::mojom::CustomizeButtonsHandlerFactory>
customize_buttons_factory_receiver_;
std::unique_ptr<MostVisitedHandler> most_visited_page_handler_;
mojo::Receiver<most_visited::mojom::MostVisitedPageHandlerFactory>
most_visited_page_factory_receiver_;
std::unique_ptr<BrowserCommandHandler> promo_browser_command_handler_;
mojo::Receiver<browser_command::mojom::CommandHandlerFactory>
browser_command_factory_receiver_;
std::unique_ptr<RealboxHandler> realbox_handler_;
std::unique_ptr<user_education::HelpBubbleHandler> help_bubble_handler_;
mojo::Receiver<help_bubble::mojom::HelpBubbleHandlerFactory>
help_bubble_handler_factory_receiver_{this};
#if !defined(OFFICIAL_BUILD)
std::unique_ptr<FooHandler> foo_handler_;
#endif
std::unique_ptr<MostRelevantTabResumptionPageHandler>
most_relevant_tab_resumption_handler_;
std::unique_ptr<page_image_service::ImageServiceHandler>
image_service_handler_;
raw_ptr<Profile> profile_;
raw_ptr<ThemeService> theme_service_;
raw_ptr<NtpCustomBackgroundService> ntp_custom_background_service_;
base::ScopedObservation<NtpCustomBackgroundService,
NtpCustomBackgroundServiceObserver>
ntp_custom_background_service_observation_{this};
// Time the NTP started loading. Used for logging the WebUI NTP's load
// performance.
base::Time navigation_start_time_;
const std::vector<ntp::ModuleIdDetail> module_id_details_;
// Mojo implementations for modules:
std::unique_ptr<DriveSuggestionHandler> drive_handler_;
std::unique_ptr<GoogleCalendarPageHandler> google_calendar_handler_;
std::unique_ptr<MicrosoftAuthPageHandler> microsoft_auth_handler_;
std::unique_ptr<MicrosoftFilesPageHandler> microsoft_files_handler_;
std::unique_ptr<OutlookCalendarPageHandler> outlook_calendar_handler_;
PrefChangeRegistrar pref_change_registrar_;
base::WeakPtrFactory<NewTabPageUI> weak_ptr_factory_{this};
WEB_UI_CONTROLLER_TYPE_DECL();
};
#endif // CHROME_BROWSER_UI_WEBUI_NEW_TAB_PAGE_NEW_TAB_PAGE_UI_H_
|