diff options
Diffstat (limited to 'chromium/chrome/browser/ui/webui/ntp')
7 files changed, 57 insertions, 68 deletions
diff --git a/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 8b3cd017605..b1c4b61fe52 100644 --- a/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -22,6 +22,7 @@ #include "base/stl_util.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "base/time/time.h" #include "base/values.h" #include "chrome/browser/apps/app_service/app_icon_source.h" #include "chrome/browser/apps/app_service/app_launch_params.h" @@ -53,13 +54,12 @@ #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/web_applications/components/app_registry_controller.h" -#include "chrome/browser/web_applications/components/app_shortcut_manager.h" -#include "chrome/browser/web_applications/components/file_handler_manager.h" #include "chrome/browser/web_applications/components/install_finalizer.h" #include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h" #include "chrome/browser/web_applications/extensions/bookmark_app_finalizer_utils.h" #include "chrome/browser/web_applications/extensions/bookmark_app_util.h" +#include "chrome/browser/web_applications/os_integration_manager.h" #include "chrome/browser/web_applications/web_app_icon_manager.h" #include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/common/buildflags.h" @@ -969,15 +969,12 @@ void AppLauncherHandler::HandleInstallAppLocally(const base::ListValue* args) { web_app_provider_->registry_controller().SetAppIsLocallyInstalled(app_id, true); - web_app::AppShortcutManager& shortcut_manager = - web_app_provider_->shortcut_manager(); - if (shortcut_manager.CanCreateShortcuts()) { - shortcut_manager.CreateShortcuts( - app_id, /*add_to_desktop=*/true, - base::BindOnce( - &AppLauncherHandler::OnShortcutsCreatedRegisterOsIntegration, - weak_ptr_factory_.GetWeakPtr(), app_id)); - } + web_app_provider_->registry_controller().SetAppInstallTime(app_id, + base::Time::Now()); + web_app_provider_->os_integration_manager().InstallOsHooks( + app_id, base::BindOnce(&AppLauncherHandler::OnOsHooksInstalled, + weak_ptr_factory_.GetWeakPtr(), app_id)); + // Use the appAdded to update the app icon's color to no longer be // greyscale. std::unique_ptr<base::DictionaryValue> app_info = GetWebAppInfo(app_id); @@ -1198,13 +1195,10 @@ void AppLauncherHandler::PromptToEnableApp(const std::string& extension_id) { extension_enable_flow_->StartForWebContents(web_ui()->GetWebContents()); } -void AppLauncherHandler::OnShortcutsCreatedRegisterOsIntegration( - const web_app::AppId& app_id, - bool shortcuts_created) { +void AppLauncherHandler::OnOsHooksInstalled(const web_app::AppId& app_id, + bool shortcuts_created) { LOCAL_HISTOGRAM_BOOLEAN("Apps.Launcher.InstallLocallyShortcutsCreated", shortcuts_created); - web_app_provider_->file_handler_manager().EnableAndRegisterOsFileHandlers( - app_id); } void AppLauncherHandler::OnExtensionUninstallDialogClosed( diff --git a/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.h b/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.h index c5d99409710..6efbad522c7 100644 --- a/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.h +++ b/chromium/chrome/browser/ui/webui/ntp/app_launcher_handler.h @@ -174,10 +174,8 @@ class AppLauncherHandler // Prompts the user to re-enable the app for |extension_id|. void PromptToEnableApp(const std::string& extension_id); - // Registers file handlers for |app_id|, after shortcuts have been - // created. - void OnShortcutsCreatedRegisterOsIntegration(const web_app::AppId& app_id, - bool shortcuts_created); + // Records result to UMA after OS Hooks are installed. + void OnOsHooksInstalled(const web_app::AppId& app_id, bool shortcuts_created); // ExtensionUninstallDialog::Delegate: void OnExtensionUninstallDialogClosed(bool did_start_uninstall, @@ -264,7 +262,7 @@ class AppLauncherHandler // Used for favicon loading tasks. base::CancelableTaskTracker cancelable_task_tracker_; - // Used to register file handlers after shortcuts have been created. + // Used for passing callbacks. base::WeakPtrFactory<AppLauncherHandler> weak_ptr_factory_{this}; DISALLOW_COPY_AND_ASSIGN(AppLauncherHandler); diff --git a/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc b/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc index 41fd80239ea..d072d8378c1 100644 --- a/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc +++ b/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.cc @@ -62,10 +62,9 @@ void CookieControlsHandler::HandleObserveCookieControlsSettingsChanges( SendCookieControlsUIChanges(); } -const char* CookieControlsHandler::GetEnforcementIcon(Profile* profile) { - CookieControlsService* service = - CookieControlsServiceFactory::GetForProfile(profile); - switch (service->GetCookieControlsEnforcement()) { +const char* CookieControlsHandler::GetEnforcementIcon( + CookieControlsEnforcement enforcement) { + switch (enforcement) { case CookieControlsEnforcement::kEnforcedByPolicy: return kPolicyIcon; case CookieControlsEnforcement::kEnforcedByExtension: @@ -86,11 +85,11 @@ void CookieControlsHandler::OnThirdPartyCookieBlockingPolicyChanged() { } void CookieControlsHandler::SendCookieControlsUIChanges() { - Profile* profile = Profile::FromWebUI(web_ui()); base::DictionaryValue dict; dict.SetBoolKey("enforced", service_->ShouldEnforceCookieControls()); dict.SetBoolKey("checked", service_->GetToggleCheckedValue()); - dict.SetStringKey("icon", CookieControlsHandler::GetEnforcementIcon(profile)); + dict.SetStringKey( + "icon", GetEnforcementIcon(service_->GetCookieControlsEnforcement())); bool use_new_cookie_page = base::FeatureList::IsEnabled(features::kPrivacySettingsRedesign); dict.SetString("cookieSettingsUrl", diff --git a/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.h b/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.h index f7dbf79d4bd..ff781518a0b 100644 --- a/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.h +++ b/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.h @@ -16,7 +16,7 @@ namespace base { class ListValue; } // namespace base -// Handles requests for prefs::kCookieControlsMode retrival/update. +// Communicates with the incognito ntp to show a third-party cookie control. class CookieControlsHandler : public content::WebUIMessageHandler, public CookieControlsService::Observer { public: @@ -30,7 +30,7 @@ class CookieControlsHandler : public content::WebUIMessageHandler, void HandleCookieControlsToggleChanged(const base::ListValue* args); void HandleObserveCookieControlsSettingsChanges(const base::ListValue* args); - static const char* GetEnforcementIcon(Profile* profile); + static const char* GetEnforcementIcon(CookieControlsEnforcement enforcement); // CookieControlsService::Observer void OnThirdPartyCookieBlockingPrefChanged() override; diff --git a/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.cc b/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.cc index 6d549a735e1..466de0c664d 100644 --- a/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.cc +++ b/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.cc @@ -30,6 +30,7 @@ #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" +#include "services/network/public/mojom/content_security_policy.mojom.h" #include "ui/base/l10n/l10n_util.h" #include "ui/native_theme/native_theme.h" #include "url/gurl.h" @@ -59,7 +60,10 @@ NewTabUI::NewTabUI(content::WebUI* web_ui) : content::WebUIController(web_ui) { if (!profile->IsGuestSession()) { web_ui->AddMessageHandler(std::make_unique<ThemeHandler>()); - web_ui->AddMessageHandler(std::make_unique<CookieControlsHandler>(profile)); + if (profile->IsOffTheRecord()) { + web_ui->AddMessageHandler( + std::make_unique<CookieControlsHandler>(profile)); + } } // content::URLDataSource assumes the ownership of the html source. @@ -187,23 +191,23 @@ bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() { return false; } -std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyScriptSrc() { - // 'unsafe-inline' and google resources are added to script-src. - return "script-src chrome://resources 'self' 'unsafe-eval' 'unsafe-inline' " - "*.google.com *.gstatic.com;"; -} - -std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyStyleSrc() { - return "style-src 'self' chrome://resources 'unsafe-inline' chrome://theme;"; -} - -std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyImgSrc() { - return "img-src chrome-search://thumb chrome-search://thumb2 " - "chrome-search://theme chrome://theme data:;"; -} +std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicy( + network::mojom::CSPDirectiveName directive) { + if (directive == network::mojom::CSPDirectiveName::ScriptSrc) { + // 'unsafe-inline' and google resources are added to script-src. + return "script-src chrome://resources 'self' 'unsafe-eval' 'unsafe-inline' " + "*.google.com *.gstatic.com;"; + } else if (directive == network::mojom::CSPDirectiveName::StyleSrc) { + return "style-src 'self' chrome://resources 'unsafe-inline' " + "chrome://theme;"; + } else if (directive == network::mojom::CSPDirectiveName::ImgSrc) { + return "img-src chrome-search://thumb chrome-search://thumb2 " + "chrome-search://theme chrome://theme data:;"; + } else if (directive == network::mojom::CSPDirectiveName::ChildSrc) { + return "child-src chrome-search://most-visited;"; + } -std::string NewTabUI::NewTabHTMLSource::GetContentSecurityPolicyChildSrc() { - return "child-src chrome-search://most-visited;"; + return content::URLDataSource::GetContentSecurityPolicy(directive); } NewTabUI::NewTabHTMLSource::~NewTabHTMLSource() {} diff --git a/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.h b/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.h index 97e6443b656..fe04e036f11 100644 --- a/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.h +++ b/chromium/chrome/browser/ui/webui/ntp/new_tab_ui.h @@ -62,10 +62,8 @@ class NewTabUI : public content::WebUIController { content::URLDataSource::GotDataCallback callback) override; std::string GetMimeType(const std::string&) override; bool ShouldReplaceExistingSource() override; - std::string GetContentSecurityPolicyScriptSrc() override; - std::string GetContentSecurityPolicyStyleSrc() override; - std::string GetContentSecurityPolicyImgSrc() override; - std::string GetContentSecurityPolicyChildSrc() override; + std::string GetContentSecurityPolicy( + network::mojom::CSPDirectiveName directive) override; private: // Pointer back to the original profile. diff --git a/chromium/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chromium/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index f796da4afea..89cd233b135 100644 --- a/chromium/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chromium/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -98,8 +98,8 @@ SkColor GetThemeColor(const ui::ThemeProvider& tp, int id) { // If web contents are being inverted because the system is in high-contrast // mode, any system theme colors we use must be inverted too to cancel out. return ui::NativeTheme::GetInstanceForNativeUi() - ->GetHighContrastColorScheme() == - ui::NativeTheme::HighContrastColorScheme::kDark + ->GetPlatformHighContrastColorScheme() == + ui::NativeTheme::PlatformHighContrastColorScheme::kDark ? color_utils::InvertColor(color) : color; } @@ -295,6 +295,13 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { ? "true" : "false"; + // Ensure passing off-the-record profile; |profile_| is not an OTR profile. + DCHECK(!profile_->IsOffTheRecord()); + DCHECK(profile_->HasPrimaryOTRProfile()); + CookieControlsService* cookie_controls_service = + CookieControlsServiceFactory::GetForProfile( + profile_->GetPrimaryOTRProfile()); + replacements["incognitoTabDescription"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_SUBTITLE); replacements["incognitoTabHeading"] = @@ -308,29 +315,18 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() { replacements["learnMoreLink"] = kLearnMoreIncognitoUrl; replacements["title"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_TITLE); replacements["hideCookieControls"] = - CookieControlsServiceFactory::GetForProfile(profile_) - ->ShouldHideCookieControlsUI() - ? "hidden" - : ""; + cookie_controls_service->ShouldHideCookieControlsUI() ? "hidden" : ""; replacements["cookieControlsTitle"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_THIRD_PARTY_COOKIE); replacements["cookieControlsDescription"] = l10n_util::GetStringUTF8(IDS_NEW_TAB_OTR_THIRD_PARTY_COOKIE_SUBLABEL); - // Ensure passing off-the-record profile; |profile_| might not be incognito. - DCHECK(profile_->HasPrimaryOTRProfile()); replacements["cookieControlsToggleChecked"] = - CookieControlsServiceFactory::GetForProfile( - profile_->GetPrimaryOTRProfile()) - ->GetToggleCheckedValue() - ? "checked" - : ""; + cookie_controls_service->GetToggleCheckedValue() ? "checked" : ""; replacements["hideTooltipIcon"] = - CookieControlsServiceFactory::GetForProfile(profile_) - ->ShouldEnforceCookieControls() - ? "" - : "hidden"; + cookie_controls_service->ShouldEnforceCookieControls() ? "" : "hidden"; replacements["cookieControlsToolTipIcon"] = - CookieControlsHandler::GetEnforcementIcon(profile_); + CookieControlsHandler::GetEnforcementIcon( + cookie_controls_service->GetCookieControlsEnforcement()); replacements["cookieControlsTooltipText"] = l10n_util::GetStringUTF8( IDS_NEW_TAB_OTR_COOKIE_CONTROLS_CONTROLLED_TOOLTIP_TEXT); |