M116 stage 5

This commit is contained in:
Alexander Frick 2023-09-04 05:43:31 -05:00
parent c6548d1dfb
commit 6a9420570d
7 changed files with 5129 additions and 657 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@
#include <map>
#include <memory>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
@ -15,7 +16,6 @@
#include "base/command_line.h"
#include "base/containers/fixed_flat_set.h"
#include "base/dcheck_is_on.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
@ -66,6 +66,8 @@
#include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/reporting/legacy_tech/legacy_tech_service.h"
#include "chrome/browser/enterprise/reporting/prefs.h"
#include "chrome/browser/enterprise/util/managed_browser_utils.h"
#include "chrome/browser/extensions/chrome_extension_cookies.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h"
@ -193,7 +195,6 @@
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chromeos/components/kiosk/kiosk_utils.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/blocked_content/popup_blocker.h"
#include "components/browsing_topics/browsing_topics_service.h"
@ -251,12 +252,12 @@
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/privacy_sandbox/privacy_sandbox_prefs.h"
#include "components/privacy_sandbox/privacy_sandbox_settings.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/content/browser/browser_url_loader_throttle.h"
#include "components/safe_browsing/content/browser/password_protection/password_protection_commit_deferring_condition.h"
#include "components/safe_browsing/content/browser/safe_browsing_navigation_throttle.h"
#include "components/safe_browsing/content/browser/ui_manager.h"
#include "components/safe_browsing/core/browser/hashprefix_realtime/hash_realtime_service.h"
#include "components/safe_browsing/core/browser/hashprefix_realtime/hash_realtime_utils.h"
#include "components/safe_browsing/core/browser/ping_manager.h"
#include "components/safe_browsing/core/browser/realtime/policy_engine.h"
#include "components/safe_browsing/core/browser/realtime/url_lookup_service.h"
@ -313,7 +314,6 @@
#include "content/public/common/content_descriptors.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/window_container_type.mojom-shared.h"
#include "device/vr/buildflags/buildflags.h"
#include "extensions/buildflags/buildflags.h"
@ -334,6 +334,7 @@
#include "printing/buildflags/buildflags.h"
#include "sandbox/policy/mojom/sandbox.mojom.h"
#include "sandbox/policy/switches.h"
#include "services/device/public/cpp/geolocation/geolocation_manager.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
@ -387,7 +388,6 @@
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/constants/ash_switches.h"
#include "ash/public/cpp/new_window_delegate.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/webui/camera_app_ui/url_constants.h"
#include "ash/webui/scanning/url_constants.h"
@ -408,20 +408,18 @@
#include "chrome/browser/ash/login/startup_utils.h"
#include "chrome/browser/ash/net/network_health/network_health_manager.h"
#include "chrome/browser/ash/net/system_proxy_manager.h"
#include "chrome/browser/ash/os_url_handler.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ash/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
#include "chrome/browser/ash/system/input_device_settings.h"
#include "chrome/browser/ash/system_extensions/system_extensions_profile_utils.h"
#include "chrome/browser/ash/system_extensions/system_extensions_provider.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ash/url_handler.h"
#include "chrome/browser/speech/tts_chromeos.h"
#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
#include "chrome/browser/ui/ash/system_web_apps/system_web_app_ui_utils.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/webui/ash/kerberos/kerberos_in_browser_dialog.h"
#include "chromeos/ash/services/network_health/public/cpp/network_health_helper.h"
#include "chromeos/crosapi/cpp/lacros_startup_state.h"
#include "components/crash/core/app/breakpad_linux.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
@ -610,7 +608,6 @@
#include "extensions/browser/guest_view/web_view/web_view_permission_helper.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
#include "extensions/browser/process_map.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/background_info.h"
@ -1647,8 +1644,6 @@ void ChromeContentBrowserClient::RegisterProfilePrefs(
registry->RegisterBooleanPref(
policy::policy_prefs::kIsolatedAppsDeveloperModeAllowed, true);
registry->RegisterBooleanPref(policy::policy_prefs::kEventPathEnabled, false);
registry->RegisterBooleanPref(
prefs::kStrictMimetypeCheckForWorkerScriptsEnabled, true);
@ -1661,6 +1656,15 @@ void ChromeContentBrowserClient::RegisterProfilePrefs(
policy::policy_prefs::kSendMouseEventsDisabledFormControlsEnabled, true);
registry->RegisterBooleanPref(prefs::kDataUrlInSvgUseEnabled, false);
registry->RegisterBooleanPref(
policy::policy_prefs::kBeforeunloadEventCancelByPreventDefaultEnabled,
true);
registry->RegisterBooleanPref(
policy::policy_prefs::
kAllowBackForwardCacheForCacheControlNoStorePageEnabled,
true);
#if BUILDFLAG(IS_CHROMEOS)
registry->RegisterListPref(prefs::kMandatoryExtensionsForIncognitoNavigation);
#endif
@ -2732,6 +2736,16 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
command_line->AppendSwitch(blink::switches::kDataUrlInSvgUseEnabled);
}
if (prefs->HasPrefPath(
policy::policy_prefs::
kAllowBackForwardCacheForCacheControlNoStorePageEnabled) &&
!prefs->GetBoolean(
policy::policy_prefs::
kAllowBackForwardCacheForCacheControlNoStorePageEnabled)) {
command_line->AppendSwitch(
switches::kDisableBackForwardCacheForCacheControlNoStorePage);
}
#if !BUILDFLAG(IS_ANDROID)
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile);
@ -2764,14 +2778,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
command_line->AppendSwitch(switches::kDisableScrollToTextFragment);
}
// Override EventPath feature if its Enterprise Policy is specified.
if (prefs->HasPrefPath(policy::policy_prefs::kEventPathEnabled)) {
command_line->AppendSwitchASCII(
blink::switches::kEventPathPolicy,
prefs->GetBoolean(policy::policy_prefs::kEventPathEnabled)
? blink::switches::kEventPathPolicy_ForceEnable
: blink::switches::kEventPathPolicy_ForceDisable);
}
// Override OffsetParentNewSpecBehavior feature if its Enterprise policy
// is specified.
if (prefs->HasPrefPath(
@ -2799,6 +2805,12 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
kSendMouseEventsDisabledFormControlsPolicy_ForceDisable);
}
if (!prefs->GetList(enterprise_reporting::kCloudLegacyTechReportAllowlist)
.empty()) {
command_line->AppendSwitch(
blink::switches::kLegacyTechReportPolicyEnabled);
}
// The IntensiveWakeUpThrottling feature is typically managed via a
// base::Feature, but it has a managed policy override. The override is
// communicated to blink via a custom command-line flag. See
@ -3347,6 +3359,31 @@ bool ChromeContentBrowserClient::IsInterestGroupAPIAllowed(
return allowed;
}
bool ChromeContentBrowserClient::IsPrivacySandboxReportingDestinationAttested(
content::BrowserContext* browser_context,
const url::Origin& destination_origin,
content::PrivacySandboxInvokingAPI invoking_api) {
Profile* profile = Profile::FromBrowserContext(browser_context);
auto* privacy_sandbox_settings =
PrivacySandboxSettingsFactory::GetForProfile(profile);
DCHECK(privacy_sandbox_settings);
privacy_sandbox::PrivacySandboxAttestationsGatedAPI gated_api;
switch (invoking_api) {
case content::PrivacySandboxInvokingAPI::kProtectedAudience:
gated_api = privacy_sandbox::PrivacySandboxAttestationsGatedAPI::
kProtectedAudience;
break;
case content::PrivacySandboxInvokingAPI::kSharedStorage:
gated_api =
privacy_sandbox::PrivacySandboxAttestationsGatedAPI::kSharedStorage;
break;
}
return privacy_sandbox_settings->IsEventReportingDestinationAttested(
destination_origin, gated_api);
}
void ChromeContentBrowserClient::OnAuctionComplete(
content::RenderFrameHost* render_frame_host,
content::InterestGroupManager::InterestGroupDataKey winner_data_key) {
@ -3386,6 +3423,7 @@ bool ChromeContentBrowserClient::IsAttributionReportingOperationAllowed(
return allowed;
}
case AttributionReportingOperation::kSourceVerboseDebugReport:
case AttributionReportingOperation::kOsSourceVerboseDebugReport:
DCHECK(source_origin);
DCHECK(reporting_origin);
return privacy_sandbox_settings->IsAttributionReportingAllowed(
@ -3405,6 +3443,7 @@ bool ChromeContentBrowserClient::IsAttributionReportingOperationAllowed(
return allowed;
}
case AttributionReportingOperation::kTriggerVerboseDebugReport:
case AttributionReportingOperation::kOsTriggerVerboseDebugReport:
DCHECK(destination_origin);
DCHECK(reporting_origin);
return privacy_sandbox_settings->IsAttributionReportingAllowed(
@ -3514,7 +3553,7 @@ std::string ChromeContentBrowserClient::GetGeolocationApiKey() {
#if BUILDFLAG(IS_MAC)
device::GeolocationManager*
ChromeContentBrowserClient::GetGeolocationManager() {
return g_browser_process->geolocation_manager();
return device::GeolocationManager::GetInstance();
}
#endif
@ -3639,24 +3678,23 @@ bool UpdatePreferredColorScheme(WebPreferences* web_prefs,
ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme());
#endif // BUILDFLAG(IS_ANDROID)
bool force_light = false;
// Force a light preferred color scheme on certain URLs if kWebUIDarkMode is
// disabled; some of the UI is not yet correctly themed.
if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) {
// Update based on last committed url.
force_light = force_light || url.SchemeIs(content::kChromeUIScheme);
force_light = force_light || IsPdfExtensionOrigin(url::Origin::Create(url));
}
// Reauth WebUI doesn't support dark mode yet because it shares the dialog
// with GAIA web contents that is not correctly themed.
force_light =
force_light || (url.SchemeIs(content::kChromeUIScheme) &&
url.host_piece() == chrome::kChromeUISigninReauthHost);
const bool force_light =
url.SchemeIs(content::kChromeUIScheme) &&
url.host_piece() == chrome::kChromeUISigninReauthHost;
if (force_light) {
web_prefs->preferred_color_scheme =
blink::mojom::PreferredColorScheme::kLight;
} else if (url.SchemeIs(content::kChromeUIScheme)) {
// If color scheme is not forced, WebUI should track the color mode of the
// ColorProvider associated with `web_contents`.
web_prefs->preferred_color_scheme =
web_contents->GetColorMode() ==
ui::ColorProviderManager::ColorMode::kLight
? blink::mojom::PreferredColorScheme::kLight
: blink::mojom::PreferredColorScheme::kDark;
}
return old_preferred_color_scheme != web_prefs->preferred_color_scheme;
@ -3710,11 +3748,6 @@ base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
return base::OnceClosure();
}
GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
DCHECK(requesting_url.is_valid())
<< "Invalid URL string: https://"
<< cert_request_info->host_and_port.ToString();
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
#if BUILDFLAG(IS_CHROMEOS_ASH)
@ -3745,6 +3778,10 @@ base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate(
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
GURL requesting_url = chrome::enterprise_util::GetRequestingUrl(
cert_request_info->host_and_port);
DCHECK(requesting_url.is_valid()) << "Invalid URL string: " << requesting_url;
net::ClientCertIdentityList matching_certificates, nonmatching_certificates;
chrome::enterprise_util::AutoSelectCertificates(
profile, requesting_url, std::move(client_certs), &matching_certificates,
@ -4337,6 +4374,12 @@ base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
}
base::FilePath ChromeContentBrowserClient::GetGraphiteDawnDiskCacheDirectory() {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
return user_data_dir.Append(FILE_PATH_LITERAL("GraphiteDawnCache"));
}
base::FilePath ChromeContentBrowserClient::GetNetLogDefaultDirectory() {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
@ -5380,25 +5423,14 @@ base::FilePath ChromeContentBrowserClient::GetLoggingFileName(
return logging::GetLogFileName(command_line);
}
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
ChromeContentBrowserClient::CreateURLLoaderThrottles(
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
std::unique_ptr<blink::URLLoaderThrottle>
ChromeContentBrowserClient::MaybeCreateSafeBrowsingURLLoaderThrottle(
const network::ResourceRequest& request,
content::BrowserContext* browser_context,
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
DCHECK(browser_context);
Profile* profile = Profile::FromBrowserContext(browser_context);
DCHECK(profile);
ChromeNavigationUIData* chrome_navigation_ui_data =
static_cast<ChromeNavigationUIData*>(navigation_ui_data);
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
int frame_tree_node_id,
Profile* profile) {
bool matches_enterprise_allowlist = safe_browsing::IsURLAllowlistedByPolicy(
request.url, *profile->GetPrefs());
if (!matches_enterprise_allowlist) {
@ -5433,8 +5465,12 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
? safe_browsing::ChromePingManagerFactory::GetForBrowserContext(
profile)
: nullptr;
safe_browsing::hash_realtime_utils::HashRealTimeSelection
hash_realtime_selection =
safe_browsing::hash_realtime_utils::DetermineHashRealTimeSelection(
profile->IsOffTheRecord(), profile->GetPrefs());
result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create(
return safe_browsing::BrowserURLLoaderThrottle::Create(
base::BindOnce(
&ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate,
base::Unretained(this),
@ -5445,24 +5481,16 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
wc_getter, frame_tree_node_id,
url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr,
hash_realtime_service ? hash_realtime_service->GetWeakPtr() : nullptr,
ping_manager ? ping_manager->GetWeakPtr() : nullptr));
ping_manager ? ping_manager->GetWeakPtr() : nullptr,
hash_realtime_selection);
}
return nullptr;
}
#endif
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
result.push_back(
std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
wc_getter.Run()));
#endif
if (chrome_navigation_ui_data &&
chrome_navigation_ui_data->is_no_state_prefetching()) {
result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
chrome_navigation_ui_data->prerender_histogram_prefix(),
GetPrerenderCanceler(wc_getter)));
}
#if BUILDFLAG(IS_ANDROID)
std::tuple<std::string /*client_data_header*/, bool /*is_custom_tab*/>
GetClientDataHeader(int frame_tree_node_id) {
std::string client_data_header;
bool is_custom_tab = false;
if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) {
@ -5472,8 +5500,9 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
auto* client_data_header_observer =
customtabs::ClientDataHeaderWebContentsObserver::FromWebContents(
web_contents);
if (client_data_header_observer)
if (client_data_header_observer) {
client_data_header = client_data_header_observer->header();
}
auto* delegate =
TabAndroid::FromWebContents(web_contents)
@ -5485,8 +5514,15 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
}
}
}
return {client_data_header, is_custom_tab};
}
#endif
std::unique_ptr<blink::URLLoaderThrottle> CreateGoogleURLLoaderThrottle(
#if BUILDFLAG(IS_ANDROID)
const std::string& client_data_header,
#endif
Profile* profile) {
#if BUILDFLAG(ENABLE_BOUND_SESSION_CREDENTIALS)
BoundSessionCookieRefreshService* bound_session_cookie_refresh_service =
BoundSessionCookieRefreshServiceFactory::GetForProfile(profile);
@ -5513,14 +5549,68 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
profile->GetPrefs()->GetInteger(
policy::policy_prefs::kForceYouTubeRestrict),
profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps));
result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
return std::make_unique<GoogleURLLoaderThrottle>(
#if BUILDFLAG(IS_ANDROID)
client_data_header,
#endif
#if BUILDFLAG(ENABLE_BOUND_SESSION_CREDENTIALS)
std::move(bound_session_request_throttled_listener),
#endif
std::move(dynamic_params)));
std::move(dynamic_params));
}
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
ChromeContentBrowserClient::CreateURLLoaderThrottles(
const network::ResourceRequest& request,
content::BrowserContext* browser_context,
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
DCHECK(browser_context);
Profile* profile = Profile::FromBrowserContext(browser_context);
DCHECK(profile);
ChromeNavigationUIData* chrome_navigation_ui_data =
static_cast<ChromeNavigationUIData*>(navigation_ui_data);
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
if (auto safe_browsing_throttle = MaybeCreateSafeBrowsingURLLoaderThrottle(
request, browser_context, wc_getter, frame_tree_node_id, profile);
safe_browsing_throttle) {
result.push_back(std::move(safe_browsing_throttle));
}
#endif
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
result.push_back(
std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>(
wc_getter.Run()));
#endif
if (chrome_navigation_ui_data &&
chrome_navigation_ui_data->is_no_state_prefetching()) {
result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>(
chrome_navigation_ui_data->prerender_histogram_prefix(),
GetPrerenderCanceler(wc_getter)));
}
#if BUILDFLAG(IS_ANDROID)
auto [client_data_header, is_custom_tab] =
GetClientDataHeader(frame_tree_node_id);
#endif
if (auto google_throttle = CreateGoogleURLLoaderThrottle(
#if BUILDFLAG(IS_ANDROID)
client_data_header,
#endif
profile);
google_throttle) {
result.push_back(std::move(google_throttle));
}
{
auto* factory =
@ -5553,6 +5643,45 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
return result;
}
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
ChromeContentBrowserClient::CreateURLLoaderThrottlesForKeepAlive(
const network::ResourceRequest& request,
content::BrowserContext* browser_context,
const base::RepeatingCallback<content::WebContents*()>& wc_getter,
int frame_tree_node_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result;
DCHECK(browser_context);
Profile* profile = Profile::FromBrowserContext(browser_context);
DCHECK(profile);
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
if (auto safe_browsing_throttle = MaybeCreateSafeBrowsingURLLoaderThrottle(
request, browser_context, wc_getter, frame_tree_node_id, profile);
safe_browsing_throttle) {
result.push_back(std::move(safe_browsing_throttle));
}
#endif
#if BUILDFLAG(IS_ANDROID)
auto [client_data_header, unused_is_custom_tab] =
GetClientDataHeader(frame_tree_node_id);
#endif
if (auto google_throttle = CreateGoogleURLLoaderThrottle(
#if BUILDFLAG(IS_ANDROID)
client_data_header,
#endif
profile);
google_throttle) {
result.push_back(std::move(google_throttle));
}
return result;
}
void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
int frame_tree_node_id,
ukm::SourceIdObj ukm_source_id,
@ -5943,7 +6072,8 @@ bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
header_client,
bool* bypass_redirect_checks,
bool* disable_secure_dns,
network::mojom::URLLoaderFactoryOverridePtr* factory_override) {
network::mojom::URLLoaderFactoryOverridePtr* factory_override,
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner) {
bool use_proxy = false;
#if BUILDFLAG(ENABLE_EXTENSIONS)
@ -5958,7 +6088,7 @@ bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
web_request_api->MaybeProxyURLLoaderFactory(
browser_context, frame, render_process_id, type,
std::move(navigation_id), ukm_source_id, factory_receiver,
header_client, request_initiator);
header_client, navigation_response_task_runner, request_initiator);
if (bypass_redirect_checks)
*bypass_redirect_checks = use_proxy_for_web_request;
use_proxy |= use_proxy_for_web_request;
@ -5986,7 +6116,9 @@ bool ChromeContentBrowserClient::WillCreateURLLoaderFactory(
std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
content::NavigationUIData* navigation_ui_data,
int frame_tree_node_id) {
int frame_tree_node_id,
int64_t navigation_id,
scoped_refptr<base::SequencedTaskRunner> navigation_response_task_runner) {
std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>>
interceptors;
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
@ -6005,8 +6137,8 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors(
}
#endif
interceptors.push_back(
std::make_unique<SearchPrefetchURLLoaderInterceptor>(frame_tree_node_id));
interceptors.push_back(std::make_unique<SearchPrefetchURLLoaderInterceptor>(
frame_tree_node_id, navigation_id, navigation_response_task_runner));
if (base::FeatureList::IsEnabled(features::kHttpsFirstModeV2)) {
auto https_upgrades_interceptor =
@ -6719,6 +6851,25 @@ ChromeContentBrowserClient::GetUrlLookupService(
return nullptr;
}
void ChromeContentBrowserClient::ReportLegacyTechEvent(
content::RenderFrameHost* render_frame_host,
const std::string type,
const GURL& url,
const std::string& filename,
uint64_t line,
uint64_t column) {
WebContents* web_contents =
WebContents::FromRenderFrameHost(render_frame_host);
DCHECK(web_contents);
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
if (!profile) {
return;
}
enterprise_reporting::LegacyTechServiceFactory::GetForProfile(profile)
->ReportEvent(type, url, filename, line, column);
}
bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() {
// We require --user-data-dir flag too so that no dangerous changes are made
// in the user's regular profile.
@ -6804,27 +6955,8 @@ std::string ChromeContentBrowserClient::GetUserAgentBasedOnPolicy(
embedder_support::UserAgentReductionEnterprisePolicyState
user_agent_reduction =
embedder_support::GetUserAgentReductionFromPrefs(prefs);
switch (user_agent_reduction) {
case embedder_support::UserAgentReductionEnterprisePolicyState::
kForceDisabled:
return embedder_support::GetFullUserAgent(force_major_version_to_minor);
case embedder_support::UserAgentReductionEnterprisePolicyState::
kForceEnabled:
return embedder_support::GetReducedUserAgent(
force_major_version_to_minor);
case embedder_support::UserAgentReductionEnterprisePolicyState::kDefault:
default:
return embedder_support::GetUserAgent(force_major_version_to_minor,
user_agent_reduction);
}
}
std::string ChromeContentBrowserClient::GetFullUserAgent() {
return embedder_support::GetFullUserAgent();
}
std::string ChromeContentBrowserClient::GetReducedUserAgent() {
return embedder_support::GetReducedUserAgent();
return embedder_support::GetUserAgent(force_major_version_to_minor,
user_agent_reduction);
}
blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() {
@ -6903,8 +7035,6 @@ ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext(
if (pdf_ocr_controller && pdf_ocr_controller->IsEnabled()) {
ax_mode.set_mode(ui::AXMode::kPDFOcr, true);
}
// TODO(crbug.com/1393069): Destroy PdfOcrController when unused (i.e.
// when a screen reader gets turned off later).
}
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
return ax_mode;
@ -7521,22 +7651,26 @@ ChromeContentBrowserClient::GetAlternativeErrorPageOverrideInfo(
}
}
// TODO(b/247618374): Lacros implementation
#if BUILDFLAG(IS_CHROMEOS_ASH)
if (ash::features::IsCaptivePortalErrorPageEnabled()) {
auto alternative_error_page_override_info =
content::mojom::AlternativeErrorPageOverrideInfo::New();
// Use the alternative error page dictionary to provide additional
// suggestions in the default error page.
alternative_error_page_override_info->alternative_error_page_params.Set(
error_page::kOverrideErrorPage, base::Value(false));
bool is_portal_state =
ash::network_health::NetworkHealthManager::GetInstance()
->helper()
->IsWiFiPortalState();
alternative_error_page_override_info->alternative_error_page_params.Set(
error_page::kIsPortalStateKey, base::Value(is_portal_state));
return alternative_error_page_override_info;
using PortalState = chromeos::network_config::mojom::PortalState;
auto portal_state = ash::network_health::NetworkHealthManager::GetInstance()
->helper()
->WiFiPortalState();
if (portal_state != PortalState::kUnknown) {
auto alternative_error_page_override_info =
content::mojom::AlternativeErrorPageOverrideInfo::New();
bool is_portal_state = portal_state == PortalState::kPortal ||
portal_state == PortalState::kPortalSuspected ||
portal_state == PortalState::kProxyAuthRequired;
// Use the alternative error page dictionary to provide additional
// suggestions in the default error page.
alternative_error_page_override_info->alternative_error_page_params.Set(
error_page::kOverrideErrorPage, base::Value(false));
alternative_error_page_override_info->alternative_error_page_params.Set(
error_page::kIsPortalStateKey, base::Value(is_portal_state));
return alternative_error_page_override_info;
}
}
#endif
@ -7544,105 +7678,13 @@ ChromeContentBrowserClient::GetAlternativeErrorPageOverrideInfo(
}
bool ChromeContentBrowserClient::OpenExternally(
content::RenderFrameHost* opener,
const GURL& url,
WindowOpenDisposition disposition) {
#if BUILDFLAG(IS_CHROMEOS_ASH)
// This code is all about the following: When Lacros is the only browser, we
// must not open full-blown Ash browser windows.
if (!crosapi::lacros_startup_state::IsLacrosPrimaryEnabled()) {
// We're running neither Lacros-Primary nor Lacros-Only, nothing to do.
return false;
}
if (chromeos::IsKioskSession()) {
// Kiosk sessions already hide the navigation bar and block window creation.
// Moreover, they don't support SWAs which we might end up trying to run
// below.
return false;
}
if (disposition == WindowOpenDisposition::NEW_POPUP) {
// Some applications still open popup windows that need to stay in Ash:
// - Gallery (chrome://media-app), see OPEN_IN_SANDBOXED_VIEWER in
// ash/webui/media_app_ui/resources/js/launch.js.
// - nassh, see showLoginPopup in nassh/js/nassh_relay_corp.js.
return false;
}
// Handle capturing system apps directly, as otherwise an additional empty
// browser window could be created.
Profile* profile = Profile::FromBrowserContext(opener->GetBrowserContext());
const absl::optional<ash::SystemWebAppType> capturing_system_app_type =
ash::GetCapturingSystemAppForURL(profile, url);
if (capturing_system_app_type) {
ash::SystemAppLaunchParams swa_params;
swa_params.url = url;
ash::LaunchSystemWebAppAsync(profile, capturing_system_app_type.value(),
swa_params);
return true;
}
const bool from_webui = opener->GetWebUI() != nullptr;
const bool is_lacros_only = !crosapi::browser_util::IsAshWebBrowserEnabled();
// If Lacros is the only browser, we forcibly open various URLs (mostly
// chrome://) in the OS_URL_HANDLER SWA.
if (is_lacros_only &&
// Terminal's tabs must remain in the Terminal SWA.
// TODO(neis): Actually limit this exception to Terminal if possible.
// Also, remove Terminal from ChromeWebUIControllerFactory's
// GetListOfAcceptableURLs or at least make TryLaunchOsUrlHandler return
// false for it somehow.
!url.SchemeIs(content::kChromeUIUntrustedScheme) &&
ash::TryLaunchOsUrlHandler(url)) {
return true;
}
// If Lacros is the primary browser, we intercept requests from Ash WebUIs and
// redirect them to Lacros via crosapi. This is to make window.open and <a
// href target="_blank"> links in WebUIs (e.g. ChromeOS Settings app) open in
// Lacros rather than in Ash. NOTE: This is breaking change for calls to
// window.open, as the return value will always be null. By excluding popups
// and devtools:// and chrome:// URLs, we exclude the existing uses of
// window.open that make use of the return value (these will have to be dealt
// with separately) as well as some existing links that currently must remain
// in Ash.
// If Lacros is the only browser, we do this even for non-WebUI sources.
bool should_open_in_lacros =
(is_lacros_only || from_webui) &&
!url.SchemeIs(content::kChromeDevToolsScheme) &&
!url.SchemeIs(content::kChromeUIScheme) &&
// Terminal's tabs must remain in Ash.
!url.SchemeIs(content::kChromeUIUntrustedScheme) &&
// OS Settings's Accessibility section links to chrome-extensions://
// URLs for Text-to-Speech engines that are installed in Ash.
!url.SchemeIs(extensions::kExtensionScheme);
if (should_open_in_lacros) {
ash::NewWindowDelegate::GetPrimary()->OpenUrl(
url, ash::NewWindowDelegate::OpenUrlFrom::kUserInteraction,
ash::NewWindowDelegate::Disposition::kNewForegroundTab);
return true;
}
// If Lacros is the only browser, we should get here only in exceptional
// cases. Some of these exceptions may not even be needed anymore. Record a
// crash dump for various cases so that we can better understand the
// situation. For now, continue as usual afterwards (i.e. don't handle the
// request here).
if (is_lacros_only &&
// We know that Terminal still needs to open Ash windows, no need to dump.
!(url.SchemeIs(content::kChromeUIUntrustedScheme) && url.has_host() &&
url.host() == "terminal")) {
SCOPED_CRASH_KEY_STRING32("CCBC", "OpenExternally",
url.possibly_invalid_spec());
base::debug::DumpWithoutCrashing();
LOG(WARNING) << "Allowing Ash window creation for url " << url;
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
return ash::TryOpenUrl(url, disposition);
#else
return false;
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
}
void ChromeContentBrowserClient::OnSharedStorageWorkletHostCreated(
@ -7788,3 +7830,17 @@ bool ChromeContentBrowserClient::DoesGaiaOriginRequireDedicatedProcess() {
return true;
#endif // !BUILDFLAG(IS_ANDROID)
}
bool ChromeContentBrowserClient::CanBackForwardCachedPageReceiveCookieChanges(
content::BrowserContext& browser_context,
const GURL& url,
const net::SiteForCookies& site_for_cookies,
const absl::optional<url::Origin>& top_frame_origin,
const net::CookieSettingOverrides overrides) {
scoped_refptr<content_settings::CookieSettings> cookie_settings =
CookieSettingsFactory::GetForProfile(
Profile::FromBrowserContext(&browser_context));
CHECK(cookie_settings);
return cookie_settings->IsFullCookieAccessAllowed(
url, site_for_cookies, top_frame_origin, overrides);
}

View File

@ -43,11 +43,13 @@
#include "chrome/browser/reading_list/reading_list_model_factory.h"
#include "chrome/browser/search/search.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/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_base.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/session_service_lookup.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/sharing_hub/sharing_hub_features.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/ui/accelerator_utils.h"
#include "chrome/browser/ui/autofill/payments/iban_bubble_controller_impl.h"
@ -131,6 +133,7 @@
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/browser/translate_manager.h"
#include "components/user_education/common/feature_promo_controller.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "components/zoom/page_zoom.h"
@ -751,7 +754,7 @@ base::WeakPtr<content::NavigationHandle> OpenCurrentURL(Browser* browser) {
return nullptr;
}
GURL url(location_bar->GetDestinationURL());
GURL url(location_bar->navigation_params().destination_url);
TRACE_EVENT1("navigation", "chrome::OpenCurrentURL", "url", url);
if (ShouldInterceptChromeURLNavigationInIncognito(browser, url)) {
@ -759,19 +762,21 @@ base::WeakPtr<content::NavigationHandle> OpenCurrentURL(Browser* browser) {
return nullptr;
}
NavigateParams params(browser, url, location_bar->GetPageTransition());
params.disposition = location_bar->GetWindowOpenDisposition();
NavigateParams params(browser, url,
location_bar->navigation_params().transition);
params.disposition = location_bar->navigation_params().disposition;
// Use ADD_INHERIT_OPENER so that all pages opened by the omnibox at least
// inherit the opener. In some cases the tabstrip will determine the group
// should be inherited, in which case the group is inherited instead of the
// opener.
params.tabstrip_add_types =
AddTabTypes::ADD_FORCE_INDEX | AddTabTypes::ADD_INHERIT_OPENER;
params.input_start = location_bar->GetMatchSelectionTimestamp();
params.input_start =
location_bar->navigation_params().match_selection_timestamp;
params.is_using_https_as_default_scheme =
location_bar->IsInputTypedUrlWithoutScheme();
location_bar->navigation_params().url_typed_without_scheme;
params.url_typed_with_http_scheme =
location_bar->IsInputTypedUrlWithHttpScheme();
location_bar->navigation_params().url_typed_with_http_scheme;
auto result = Navigate(&params);
#if BUILDFLAG(ENABLE_EXTENSIONS)
@ -1404,28 +1409,39 @@ void ShowVirtualCardEnrollBubble(Browser* browser) {
controller->ReshowBubble();
}
void Translate(Browser* browser) {
if (!browser->window()->IsActive())
void ShowTranslateBubble(Browser* browser) {
if (!browser->window()->IsActive()) {
return;
}
WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
ChromeTranslateClient* chrome_translate_client =
ChromeTranslateClient::FromWebContents(web_contents);
if (!chrome_translate_client) {
return;
}
// The Translate bubble will not show if a text field is focused, so we clear
// focus here as the user has intentionally opened the bubble.
web_contents->ClearFocusedElement();
std::string source_language;
std::string target_language;
chrome_translate_client->GetTranslateLanguages(web_contents, &source_language,
&target_language);
translate::TranslateStep step = translate::TRANSLATE_STEP_BEFORE_TRANSLATE;
if (chrome_translate_client) {
if (chrome_translate_client->GetLanguageState().translation_pending())
step = translate::TRANSLATE_STEP_TRANSLATING;
else if (chrome_translate_client->GetLanguageState().translation_error())
step = translate::TRANSLATE_STEP_TRANSLATE_ERROR;
else if (chrome_translate_client->GetLanguageState().IsPageTranslated())
step = translate::TRANSLATE_STEP_AFTER_TRANSLATE;
auto* language_state =
chrome_translate_client->GetTranslateManager()->GetLanguageState();
if (language_state->translation_pending()) {
step = translate::TRANSLATE_STEP_TRANSLATING;
} else if (language_state->translation_error()) {
step = translate::TRANSLATE_STEP_TRANSLATE_ERROR;
} else if (language_state->IsPageTranslated()) {
step = translate::TRANSLATE_STEP_AFTER_TRANSLATE;
}
browser->window()->ShowTranslateBubble(
web_contents, step, source_language, target_language,
@ -1437,6 +1453,8 @@ void ManagePasswordsForPage(Browser* browser) {
feature_engagement::kIPHPasswordsManagementBubbleAfterSaveFeature);
browser->window()->CloseFeaturePromo(
feature_engagement::kIPHPasswordsManagementBubbleDuringSigninFeature);
browser->window()->CloseFeaturePromo(
feature_engagement::kIPHPasswordManagerShortcutFeature);
WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
ManagePasswordsUIController* controller =
@ -1445,12 +1463,27 @@ void ManagePasswordsForPage(Browser* browser) {
->ShowManagePasswordsBubble(!controller->IsAutomaticallyOpeningBubble());
}
bool CanSendTabToSelf(const Browser* browser) {
return send_tab_to_self::ShouldDisplayEntryPoint(
browser->tab_strip_model()->GetActiveWebContents());
}
void SendTabToSelfFromPageAction(Browser* browser) {
WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
send_tab_to_self::ShowBubble(web_contents);
}
bool CanGenerateQrCode(const Browser* browser) {
return !sharing_hub::SharingIsDisabledByPolicy(browser->profile()) &&
qrcode_generator::QRCodeGeneratorBubbleController::
IsGeneratorAvailable(browser->tab_strip_model()
->GetActiveWebContents()
->GetController()
.GetLastCommittedEntry()
->GetURL());
}
void GenerateQRCodeFromPageAction(Browser* browser) {
WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
@ -2025,13 +2058,19 @@ void ExecLensRegionSearch(Browser* browser) {
GURL url = contents->GetController().GetLastCommittedEntry()->GetURL();
if (lens::IsRegionSearchEnabled(browser, profile, service, url)) {
const bool is_google_dsp = search::DefaultSearchProviderIsGoogle(profile);
const lens::AmbientSearchEntryPoint entry_point =
is_google_dsp ? lens::AmbientSearchEntryPoint::
CONTEXT_MENU_SEARCH_REGION_WITH_GOOGLE_LENS
: lens::AmbientSearchEntryPoint::
CONTEXT_MENU_SEARCH_REGION_WITH_WEB;
auto lens_region_search_controller_data =
std::make_unique<lens::LensRegionSearchControllerData>();
lens_region_search_controller_data->lens_region_search_controller =
std::make_unique<lens::LensRegionSearchController>(browser);
lens_region_search_controller_data->lens_region_search_controller->Start(
contents, lens::features::IsLensFullscreenSearchEnabled(),
search::DefaultSearchProviderIsGoogle(profile));
is_google_dsp, entry_point);
browser->SetUserData(lens::LensRegionSearchControllerData::kDataKey,
std::move(lens_region_search_controller_data));
}

View File

@ -47,6 +47,23 @@ if (is_ios) {
}
outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
}
if (use_blink) {
bundle_data("components_tests_distiller_bundle_data") {
testonly = true
sources = [
"//third_party/chaijs/chai.js",
"//third_party/dom_distiller_js/dist/test/data/out/domdistillerjstest.js",
"//third_party/dom_distiller_js/dist/test/data/war/test.html",
"//third_party/mocha/mocha.js",
"dom_distiller/core/javascript/dom_distiller_viewer.js",
"dom_distiller/core/javascript/domdistiller.js",
"dom_distiller/core/javascript/extract_features.js",
]
outputs = [ "{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}" ]
}
}
}
# Omit Lacros because it allows //components to depend on //chrome, which in
@ -190,7 +207,6 @@ test("components_unittests") {
"//components/power_bookmarks/core:unit_tests",
"//components/power_bookmarks/storage:unit_tests",
"//components/power_metrics:unit_tests",
"//components/power_scheduler:unit_tests",
"//components/prefs:unit_tests",
"//components/profile_metrics:unit_tests",
"//components/proxy_config:unit_tests",
@ -204,6 +220,7 @@ test("components_unittests") {
"//components/reporting/storage:unit_tests",
"//components/reporting/util:unit_tests",
"//components/safe_browsing/core/browser:safe_browsing_metrics_collector_unittest",
"//components/safe_browsing/core/browser/hashprefix_realtime:unit_tests",
"//components/safe_browsing/core/browser/password_protection:unit_tests",
"//components/safe_search_api:unit_tests",
"//components/saved_tab_groups:unit_tests",
@ -374,6 +391,7 @@ test("components_unittests") {
"//components/query_tiles:unit_tests",
"//components/reporting/resources:unit_tests",
"//components/services/heap_profiling:unit_tests",
"//components/services/storage:tests",
"//components/tracing:unit_tests",
"//components/translate/content/browser:unit_tests",
"//components/translate/content/renderer:unit_tests",
@ -411,6 +429,9 @@ test("components_unittests") {
"//components/translate/ios/browser:unit_tests",
"//components/ukm/ios:unit_tests",
]
if (use_blink) {
deps += [ ":components_tests_distiller_bundle_data" ]
}
} else { #!is_ios
deps += [
"//components/background_sync:unit_tests",
@ -433,6 +454,7 @@ test("components_unittests") {
"//components/permissions:unit_tests",
"//components/permissions/prediction_service:unit_tests",
"//components/privacy_sandbox:unit_tests",
"//components/privacy_sandbox/privacy_sandbox_attestations:unit_tests",
"//components/session_proto_db:unit_tests",
# TODO(chromium: 1169835) components / reporting / storage / resources: unit_tests
@ -441,7 +463,6 @@ test("components_unittests") {
"//components/safe_browsing/content/browser/triggers:unit_tests",
"//components/safe_browsing/content/browser/web_ui:unit_tests",
"//components/safe_browsing/core/browser:token_fetcher_unit_tests",
"//components/safe_browsing/core/browser/hashprefix_realtime:unit_tests",
"//components/safe_browsing/core/browser/realtime:unit_tests",
"//components/safe_browsing/core/browser/tailored_security_service:unit_tests",
"//components/safe_browsing/core/browser/utils:unit_tests",
@ -450,7 +471,6 @@ test("components_unittests") {
"//components/security_interstitials/content:unit_tests",
"//components/services/paint_preview_compositor:unit_tests",
"//components/services/quarantine:unit_tests",
"//components/services/storage:tests",
"//components/site_engagement/content:unit_tests",
"//components/site_isolation:unit_tests",
"//components/spellcheck/browser:unit_tests",
@ -906,7 +926,13 @@ if (use_blink) {
}
if (is_ios) {
deps += [ ":components_tests_pak_bundle_data" ]
deps += [
":components_tests_distiller_bundle_data",
":components_tests_pak_bundle_data",
"test:dom_distiller_test_bundle_data",
"test:url_rewrite_test_bundle_data",
"//content/test:content_test_bundle_data",
]
}
if (enable_pdf) {

View File

@ -26,7 +26,6 @@
#include "components/omnibox/browser/location_bar_model.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_edit_model_delegate.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/search/search.h"
@ -170,8 +169,7 @@ std::u16string OmniboxView::SanitizeTextForPaste(const std::u16string& text) {
OmniboxView::~OmniboxView() = default;
bool OmniboxView::IsEditingOrEmpty() const {
return (model() && model()->user_input_in_progress()) ||
(GetOmniboxTextLength() == 0);
return model()->user_input_in_progress() || GetOmniboxTextLength() == 0;
}
// TODO (manukh) OmniboxView::GetIcon is very similar to
@ -192,19 +190,10 @@ ui::ImageModel OmniboxView::GetIcon(int dip_size,
return ui::ImageModel();
#else
if (!model()) {
AutocompleteMatch fake_match;
fake_match.type = AutocompleteMatchType::URL_WHAT_YOU_TYPED;
const gfx::VectorIcon& vector_icon = fake_match.GetVectorIcon(false);
return ui::ImageModel::FromVectorIcon(vector_icon, color_current_page_icon,
dip_size);
}
if (model()->ShouldShowCurrentPageIcon()) {
LocationBarModel* location_bar_model =
edit_model_delegate_->GetLocationBarModel();
return ui::ImageModel::FromVectorIcon(location_bar_model->GetVectorIcon(),
color_current_page_icon, dip_size);
return ui::ImageModel::FromVectorIcon(
GetLocationBarModel()->GetVectorIcon(), color_current_page_icon,
dip_size);
}
gfx::Image favicon;
@ -215,9 +204,16 @@ ui::ImageModel OmniboxView::GetIcon(int dip_size,
// search queries with the chrome refresh feature.
// (DISABLED BY Alex313031).
} else if (match.type != AutocompleteMatchType::HISTORY_CLUSTER) {
// For site suggestions, display site's favicon.
favicon = model()->client()->GetFaviconForPageUrl(
match.destination_url, std::move(on_icon_fetched));
// The starter pack suggestions are a unique case. These suggestions
// normally use a favicon image that cannot be styled further by client
// code. In order to apply custom styling to the icon (e.g. colors), we
// ignore this favicon in favor of using a vector icon which has better
// styling support.
if (!AutocompleteMatch::IsStarterPackType(match.type)) {
// For site suggestions, display site's favicon.
favicon = model()->client()->GetFaviconForPageUrl(
match.destination_url, std::move(on_icon_fetched));
}
}
if (!favicon.IsEmpty())
@ -232,8 +228,18 @@ ui::ImageModel OmniboxView::GetIcon(int dip_size,
const bool is_bookmarked =
bookmark_model && bookmark_model->IsBookmarked(match.destination_url);
const gfx::VectorIcon& vector_icon = match.GetVectorIcon(is_bookmarked);
const auto& color = match.type == AutocompleteMatchType::HISTORY_CLUSTER
// For starter pack suggestions, use template url to generate proper vector
// icon.
const TemplateURL* turl =
match.associated_keyword
? model()
->client()
->GetTemplateURLService()
->GetTemplateURLForKeyword(match.associated_keyword->keyword)
: nullptr;
const gfx::VectorIcon& vector_icon = match.GetVectorIcon(is_bookmarked, turl);
const auto& color = (match.type == AutocompleteMatchType::HISTORY_CLUSTER ||
match.type == AutocompleteMatchType::STARTER_PACK)
? color_bright_vectors
: color_vectors;
return ui::ImageModel::FromVectorIcon(vector_icon, color, dip_size);
@ -245,9 +251,7 @@ void OmniboxView::SetUserText(const std::u16string& text) {
}
void OmniboxView::SetUserText(const std::u16string& text, bool update_popup) {
if (model()) {
model()->SetUserText(text);
}
model()->SetUserText(text);
SetWindowTextAndCaretPos(text, text.length(), update_popup, true);
}
@ -258,9 +262,7 @@ void OmniboxView::RevertAll() {
if (base::FeatureList::IsEnabled(omnibox::kRevertModelBeforeClosingPopup)) {
// This will clear the model's `user_input_in_progress_`.
if (model()) {
model()->Revert();
}
model()->Revert();
// This will stop the `AutocompleteController`. This should happen after
// `user_input_in_progress_` is cleared above; otherwise, closing the popup
@ -271,18 +273,14 @@ void OmniboxView::RevertAll() {
} else {
// Same as above, but in reverse order.
CloseOmniboxPopup();
if (model()) {
model()->Revert();
}
model()->Revert();
}
TextChanged();
}
void OmniboxView::CloseOmniboxPopup() {
if (model()) {
model()->StopAutocomplete();
}
model()->StopAutocomplete();
}
bool OmniboxView::IsImeShowingPopup() const {
@ -351,16 +349,13 @@ OmniboxView::StateChanges OmniboxView::GetStateChanges(const State& before,
return state_changes;
}
OmniboxView::OmniboxView(OmniboxEditModelDelegate* edit_model_delegate,
std::unique_ptr<OmniboxClient> client)
: edit_model_delegate_(edit_model_delegate) {
// `client` can be nullptr in tests.
// TODO(crbug.com/1404748): Verify if this can actually happen and prevent it
// such that checking `model()` before use is no longer necessary.
if (client) {
controller_ = std::make_unique<OmniboxController>(
/*view=*/this, edit_model_delegate, std::move(client));
}
OmniboxView::OmniboxView(std::unique_ptr<OmniboxClient> client)
: controller_(std::make_unique<OmniboxController>(
/*view=*/this,
std::move(client))) {}
const LocationBarModel* OmniboxView::GetLocationBarModel() const {
return model() ? model()->client()->GetLocationBarModel() : nullptr;
}
OmniboxEditModel* OmniboxView::model() {
@ -369,15 +364,12 @@ OmniboxEditModel* OmniboxView::model() {
}
const OmniboxEditModel* OmniboxView::model() const {
// `controller_` can be nullptr in tests.
return controller_ ? controller_->edit_model() : nullptr;
return controller_->edit_model();
}
void OmniboxView::TextChanged() {
EmphasizeURLComponents();
if (model()) {
model()->OnChanged();
}
model()->OnChanged();
}
void OmniboxView::UpdateTextStyle(

File diff suppressed because it is too large Load Diff

View File

@ -100,6 +100,8 @@ component("views_examples_lib") {
"toggle_button_example.h",
"tree_view_example.cc",
"tree_view_example.h",
"typography_example.cc",
"typography_example.h",
"vector_example.cc",
"vector_example.h",
"views_examples_export.h",