M116 stage 6

This commit is contained in:
Alexander Frick 2023-09-04 06:02:49 -05:00
parent 6a9420570d
commit cb3d4cd555
7 changed files with 262 additions and 104 deletions

View File

@ -580,6 +580,7 @@ Browser::~Browser() {
// The tab strip should not have any tabs at this point.
//
// TODO(crbug.com/1407055): This DCHECK doesn't always pass.
// TODO(crbug.com/1434387): convert this to CHECK.
DCHECK(tab_strip_model_->empty());
// Destroy the BrowserCommandController before removing the browser, so that
@ -1314,6 +1315,7 @@ void Browser::TabStripEmpty() {
// immediately deletes, where was Close() is a hide, and then delete after
// posting a task.
window_->Close();
is_delete_scheduled_ = true;
// Instant may have visible WebContents that need to be detached before the
// window system closes.
@ -2400,6 +2402,14 @@ void Browser::OnTranslateEnabledChanged(content::WebContents* source) {
// Browser, Command and state updating (private):
void Browser::OnTabInsertedAt(WebContents* contents, int index) {
// If this Browser is about to be deleted, then WebContents should not be
// added to it. This is because scheduling the delete can not be undone, and
// proper cleanup is not done if a WebContents is added once delete it
// scheduled (WebContents is leaked, unload handlers aren't checked...).
// TODO(crbug.com/1434387): this should check that `is_delete_scheduled_` is
// false.
DUMP_WILL_BE_CHECK(!is_delete_scheduled_);
SetAsDelegate(contents, true);
sessions::SessionTabHelper::FromWebContents(contents)->SetWindowID(

View File

@ -415,6 +415,8 @@ class Browser : public TabStripModelObserver,
}
CreationSource creation_source() const { return creation_source_; }
bool is_delete_scheduled() const { return is_delete_scheduled_; }
// |window()| will return NULL if called before |CreateBrowserWindow()|
// is done.
BrowserWindow* window() const { return window_; }
@ -1199,7 +1201,7 @@ class Browser : public TabStripModelObserver,
std::unique_ptr<ScopedProfileKeepAlive> profile_keep_alive_;
// This Browser's window.
raw_ptr<BrowserWindow> window_;
raw_ptr<BrowserWindow, DanglingUntriaged> window_;
std::unique_ptr<TabStripModelDelegate> const tab_strip_model_delegate_;
std::unique_ptr<TabStripModel> const tab_strip_model_;
@ -1344,6 +1346,10 @@ class Browser : public TabStripModelObserver,
WebContentsCollection web_contents_collection_{this};
// If true, the Browser window has been closed and this will be deleted
// shortly (after a PostTask).
bool is_delete_scheduled_ = false;
// The following factory is used for chrome update coalescing.
base::WeakPtrFactory<Browser> chrome_updater_factory_{this};

View File

@ -24,6 +24,10 @@
#include "ui/base/ui_base_features.h"
#include "ui/events/event_constants.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/crosapi/browser_util.h"
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
namespace {
// For ChromeOS only: If you plan on adding a new accelerator and want it
@ -44,7 +48,6 @@ const AcceleratorMapping kAcceleratorMap[] = {
#if !BUILDFLAG(IS_CHROMEOS)
{ui::VKEY_F7, ui::EF_NONE, IDC_CARET_BROWSING_TOGGLE},
#endif
{ui::VKEY_F12, ui::EF_NONE, IDC_DEV_TOOLS_TOGGLE},
{ui::VKEY_ESCAPE, ui::EF_NONE, IDC_CLOSE_FIND_OR_STOP},
#if !BUILDFLAG(IS_MAC)
@ -122,7 +125,7 @@ const AcceleratorMapping kAcceleratorMap[] = {
{ui::VKEY_8, ui::EF_ALT_DOWN, IDC_SELECT_TAB_7},
{ui::VKEY_NUMPAD8, ui::EF_ALT_DOWN, IDC_SELECT_TAB_7},
{ui::VKEY_BROWSER_FAVORITES, ui::EF_NONE, IDC_SHOW_BOOKMARK_BAR},
#endif // BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
#endif // BUILDFLAG(IS_LINUX)
{ui::VKEY_B, ui::EF_SHIFT_DOWN | ui::EF_PLATFORM_ACCELERATOR,
IDC_SHOW_BOOKMARK_BAR},
{ui::VKEY_OEM_MINUS, ui::EF_PLATFORM_ACCELERATOR, IDC_ZOOM_MINUS},
@ -197,9 +200,9 @@ const AcceleratorMapping kAcceleratorMap[] = {
{ui::VKEY_BROWSER_SEARCH, ui::EF_NONE, IDC_FOCUS_SEARCH},
#endif // BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_MAC)
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
{ui::VKEY_I, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, IDC_FEEDBACK},
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_MAC)
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
{ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_PLATFORM_ACCELERATOR,
IDC_NEW_INCOGNITO_WINDOW},
{ui::VKEY_T, ui::EF_PLATFORM_ACCELERATOR, IDC_NEW_TAB},
@ -216,11 +219,6 @@ const AcceleratorMapping kAcceleratorMap[] = {
#if BUILDFLAG(ENABLE_PRINTING)
{ui::VKEY_P, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, IDC_BASIC_PRINT},
#endif // ENABLE_PRINTING
{ui::VKEY_I, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_DEV_TOOLS},
{ui::VKEY_J, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
IDC_DEV_TOOLS_CONSOLE},
{ui::VKEY_C, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
IDC_DEV_TOOLS_INSPECT},
{ui::VKEY_B, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, IDC_FOCUS_BOOKMARKS},
{ui::VKEY_A, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY},
@ -237,7 +235,6 @@ const AcceleratorMapping kAcceleratorMap[] = {
IDC_SHOW_BOOKMARK_MANAGER},
{ui::VKEY_J, ui::EF_CONTROL_DOWN, IDC_SHOW_DOWNLOADS},
{ui::VKEY_H, ui::EF_CONTROL_DOWN, IDC_SHOW_HISTORY},
{ui::VKEY_U, ui::EF_CONTROL_DOWN, IDC_VIEW_SOURCE},
#if !BUILDFLAG(IS_CHROMEOS)
// On Chrome OS, these keys are assigned to change UI scale.
{ui::VKEY_OEM_MINUS, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
@ -256,6 +253,18 @@ const AcceleratorMapping kAcceleratorMap[] = {
#endif
};
const AcceleratorMapping kDevToolsAcceleratorMap[] = {
{ui::VKEY_F12, ui::EF_NONE, IDC_DEV_TOOLS_TOGGLE},
#if !BUILDFLAG(IS_MAC)
{ui::VKEY_I, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_DEV_TOOLS},
{ui::VKEY_J, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
IDC_DEV_TOOLS_CONSOLE},
{ui::VKEY_C, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
IDC_DEV_TOOLS_INSPECT},
{ui::VKEY_U, ui::EF_CONTROL_DOWN, IDC_VIEW_SOURCE},
#endif // !BUILDFLAG(IS_MAC)
};
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Accelerators to enable if features::IsNewShortcutMappingEnabled is false.
const AcceleratorMapping kDisableWithNewMappingAcceleratorMap[] = {
@ -298,14 +307,32 @@ const int kRepeatableCommandIds[] = {
IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB,
};
} // namespace
std::vector<AcceleratorMapping>* GetAcceleratorsPointer() {
static base::NoDestructor<std::vector<AcceleratorMapping>> accelerators;
return accelerators.get();
}
} // namespace
std::vector<AcceleratorMapping> GetAcceleratorList() {
static base::NoDestructor<std::vector<AcceleratorMapping>> accelerators;
std::vector<AcceleratorMapping>* accelerators = GetAcceleratorsPointer();
if (accelerators->empty()) {
accelerators->insert(accelerators->begin(), std::begin(kAcceleratorMap),
std::end(kAcceleratorMap));
bool enable_devtools = true;
#if BUILDFLAG(IS_CHROMEOS_ASH)
// In Ash, DevTools is disabled by default if lacros is the only browser, in
// order not to confuse users by opening Ash browser windows.
enable_devtools = crosapi::browser_util::IsAshDevToolEnabled();
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
if (enable_devtools) {
accelerators->insert(accelerators->begin(),
std::begin(kDevToolsAcceleratorMap),
std::end(kDevToolsAcceleratorMap));
}
// See https://devblogs.microsoft.com/oldnewthing/20040329-00/?p=40003
// Doing this check here and not at the bottom since kUIDebugAcceleratorMap
// contains Ctrl+Alt keys but we don't enable those for the public.
@ -346,6 +373,11 @@ std::vector<AcceleratorMapping> GetAcceleratorList() {
return *accelerators;
}
void ClearAcceleratorListForTesting() {
std::vector<AcceleratorMapping>* accelerators = GetAcceleratorsPointer();
accelerators->clear();
}
bool GetStandardAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
#if BUILDFLAG(IS_MAC)

View File

@ -171,8 +171,40 @@ constexpr int kToolbarDividerSpacing = 9;
constexpr int kBrowserAppMenuRefreshExpandedMargin = 5;
constexpr int kBrowserAppMenuRefreshCollapsedMargin = 2;
// Draws background akin to the tabstrip.
class TabstripLikeBackground : public views::Background {
public:
explicit TabstripLikeBackground(BrowserView* browser_view)
: browser_view_(browser_view) {}
private:
// views::Background:
void Paint(gfx::Canvas* canvas, views::View* view) const override {
bool painted = TopContainerBackground::PaintThemeCustomImage(
canvas, view, browser_view_, /*translate_view_coordinates=*/false);
if (!painted) {
SkColor frame_color =
browser_view_->frame()->GetFrameView()->GetFrameColor(
BrowserFrameActiveState::kUseCurrent);
canvas->DrawColor(frame_color);
}
}
const raw_ptr<BrowserView> browser_view_;
};
} // namespace
class ToolbarView::ContainerView : public views::View {
public:
// Calling PreferredSizeChanged() will trigger the parent's
// ChildPreferredSizeChanged.
// Bubble up calls to ChildPreferredSizeChanged.
void ChildPreferredSizeChanged(View* child) override {
PreferredSizeChanged();
}
};
////////////////////////////////////////////////////////////////////////////////
// ToolbarView, public:
@ -184,14 +216,17 @@ ToolbarView::ToolbarView(Browser* browser, BrowserView* browser_view)
display_mode_(GetDisplayMode(browser)) {
SetID(VIEW_ID_TOOLBAR);
container_view_ = AddChildView(std::make_unique<ContainerView>());
if (display_mode_ == DisplayMode::NORMAL) {
SetBackground(std::make_unique<TopContainerBackground>(browser_view));
container_view_->SetBackground(
std::make_unique<TopContainerBackground>(browser_view));
for (const auto& view_and_command : GetViewCommandMap())
chrome::AddCommandObserver(browser_, view_and_command.second, this);
}
views::SetCascadingColorProviderColor(this, views::kCascadingBackgroundColor,
kColorToolbar);
views::SetCascadingColorProviderColor(
container_view_, views::kCascadingBackgroundColor, kColorToolbar);
}
ToolbarView::~ToolbarView() {
@ -210,6 +245,21 @@ void ToolbarView::Init() {
// See crbug.com/1183894#c2
aura::WindowOcclusionTracker::ScopedPause pause_occlusion;
#endif
// The background views must be behind container_view_.
if (features::IsChromeRefresh2023()) {
background_view_left_ = AddChildViewAt(std::make_unique<View>(), 0);
background_view_left_->SetBackground(
std::make_unique<TabstripLikeBackground>(browser_view_));
background_view_right_ = AddChildViewAt(std::make_unique<View>(), 0);
background_view_right_->SetBackground(
std::make_unique<TabstripLikeBackground>(browser_view_));
active_state_subscription_ =
GetWidget()->RegisterPaintAsActiveChangedCallback(base::BindRepeating(
&ToolbarView::ActiveStateChanged, base::Unretained(this)));
}
auto location_bar = std::make_unique<LocationBarView>(
browser_, browser_->profile(), browser_->command_controller(), this,
display_mode_ != DisplayMode::NORMAL);
@ -223,20 +273,21 @@ void ToolbarView::Init() {
}
if (display_mode_ != DisplayMode::NORMAL) {
location_bar_ = AddChildView(std::move(location_bar));
location_bar_ = container_view_->AddChildView(std::move(location_bar));
location_bar_->Init();
}
if (display_mode_ == DisplayMode::CUSTOM_TAB) {
custom_tab_bar_ =
AddChildView(std::make_unique<CustomTabBarView>(browser_view_, this));
SetLayoutManager(std::make_unique<views::FillLayout>());
custom_tab_bar_ = container_view_->AddChildView(
std::make_unique<CustomTabBarView>(browser_view_, this));
container_view_->SetLayoutManager(std::make_unique<views::FillLayout>());
initialized_ = true;
return;
} else if (display_mode_ == DisplayMode::LOCATION) {
// Add the download button for popups.
if (download_button) {
download_button_ = AddChildView(std::move(download_button));
download_button_ =
container_view_->AddChildView(std::move(download_button));
download_button_->SetPreferredSize(
gfx::Size(location_bar_->GetPreferredSize().height(),
location_bar_->GetPreferredSize().height()));
@ -244,9 +295,9 @@ void ToolbarView::Init() {
// Hide the icon by default; it will show up when there's a download.
download_button_->Hide();
}
SetBackground(
container_view_->SetBackground(
views::CreateThemedSolidBackground(kColorLocationBarBackground));
SetLayoutManager(std::make_unique<views::FlexLayout>())
container_view_->SetLayoutManager(std::make_unique<views::FlexLayout>())
->SetOrientation(views::LayoutOrientation::kHorizontal)
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter)
.SetDefault(views::kFlexBehaviorKey,
@ -328,18 +379,20 @@ void ToolbarView::Init() {
}
// Always add children in order from left to right, for accessibility.
back_ = AddChildView(std::move(back));
forward_ = AddChildView(std::move(forward));
reload_ = AddChildView(std::move(reload));
home_ = AddChildView(std::move(home));
back_ = container_view_->AddChildView(std::move(back));
forward_ = container_view_->AddChildView(std::move(forward));
reload_ = container_view_->AddChildView(std::move(reload));
home_ = container_view_->AddChildView(std::move(home));
location_bar_ = AddChildView(std::move(location_bar));
location_bar_ = container_view_->AddChildView(std::move(location_bar));
if (extensions_container)
extensions_container_ = AddChildView(std::move(extensions_container));
extensions_container_ =
container_view_->AddChildView(std::move(extensions_container));
if (toolbar_divider) {
toolbar_divider_ = AddChildView(std::move(toolbar_divider));
toolbar_divider_ =
container_view_->AddChildView(std::move(toolbar_divider));
toolbar_divider_->SetPreferredSize(
gfx::Size(kToolbarDividerWidth, kToolbarDividerHeight));
}
@ -349,8 +402,9 @@ void ToolbarView::Init() {
UpdateChromeLabsNewBadgePrefs(browser_->profile(),
chrome_labs_model_.get());
if (ShouldShowChromeLabsUI(chrome_labs_model_.get(), browser_->profile())) {
chrome_labs_button_ = AddChildView(std::make_unique<ChromeLabsButton>(
browser_view_, chrome_labs_model_.get()));
chrome_labs_button_ =
container_view_->AddChildView(std::make_unique<ChromeLabsButton>(
browser_view_, chrome_labs_model_.get()));
show_chrome_labs_button_.Init(
chrome_labs_prefs::kBrowserLabsEnabled, prefs,
@ -363,29 +417,33 @@ void ToolbarView::Init() {
}
}
battery_saver_button_ =
AddChildView(std::make_unique<BatterySaverButton>(browser_view_));
battery_saver_button_ = container_view_->AddChildView(
std::make_unique<BatterySaverButton>(browser_view_));
if (cast)
cast_ = AddChildView(std::move(cast));
cast_ = container_view_->AddChildView(std::move(cast));
if (media_button)
media_button_ = AddChildView(std::move(media_button));
media_button_ = container_view_->AddChildView(std::move(media_button));
if (download_button)
download_button_ = AddChildView(std::move(download_button));
download_button_ =
container_view_->AddChildView(std::move(download_button));
if (send_tab_to_self_button)
send_tab_to_self_button_ = AddChildView(std::move(send_tab_to_self_button));
send_tab_to_self_button_ =
container_view_->AddChildView(std::move(send_tab_to_self_button));
if (side_panel_toolbar_container) {
side_panel_container_ =
AddChildView(std::move(side_panel_toolbar_container));
container_view_->AddChildView(std::move(side_panel_toolbar_container));
} else if (side_panel_button) {
side_panel_button_ = AddChildView(std::move(side_panel_button));
side_panel_button_ =
container_view_->AddChildView(std::move(side_panel_button));
}
avatar_ = AddChildView(std::make_unique<AvatarToolbarButton>(browser_view_));
avatar_ = container_view_->AddChildView(
std::make_unique<AvatarToolbarButton>(browser_view_));
bool show_avatar_toolbar_button = true;
#if BUILDFLAG(IS_CHROMEOS_ASH)
// ChromeOS only badges Incognito, Guest, and captive portal signin icons in
@ -418,7 +476,7 @@ void ToolbarView::Init() {
app_menu_button->SetTooltipText(
l10n_util::GetStringUTF16(IDS_APPMENU_TOOLTIP));
app_menu_button->SetID(VIEW_ID_APP_MENU);
app_menu_button_ = AddChildView(std::move(app_menu_button));
app_menu_button_ = container_view_->AddChildView(std::move(app_menu_button));
LoadImages();
@ -507,11 +565,13 @@ void ToolbarView::UpdateCustomTabBarVisibility(bool visible, bool animate) {
void ToolbarView::UpdateForWebUITabStrip() {
#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
if (browser_view_->webui_tab_strip() && app_menu_button_) {
const size_t insertion_index = GetIndexOf(app_menu_button_).value();
AddChildViewAt(browser_view_->webui_tab_strip()->CreateNewTabButton(),
insertion_index);
AddChildViewAt(browser_view_->webui_tab_strip()->CreateTabCounter(),
insertion_index);
const size_t insertion_index =
container_view_->GetIndexOf(app_menu_button_).value();
container_view_->AddChildViewAt(
browser_view_->webui_tab_strip()->CreateNewTabButton(),
insertion_index);
container_view_->AddChildViewAt(
browser_view_->webui_tab_strip()->CreateTabCounter(), insertion_index);
LoadImages();
}
#endif // BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
@ -639,7 +699,7 @@ gfx::Size ToolbarView::CalculatePreferredSize() const {
size = location_bar_->GetPreferredSize();
break;
case DisplayMode::NORMAL:
size = View::CalculatePreferredSize();
size = container_view_->GetPreferredSize();
// Because there are odd cases where something causes one of the views in
// the toolbar to report an unreasonable height (see crbug.com/985909), we
// cap the height at the size of known child views (location bar and back
@ -668,7 +728,7 @@ gfx::Size ToolbarView::GetMinimumSize() const {
size = location_bar_->GetMinimumSize();
break;
case DisplayMode::NORMAL:
size = View::GetMinimumSize();
size = container_view_->GetMinimumSize();
// Because there are odd cases where something causes one of the views in
// the toolbar to report an unreasonable height (see crbug.com/985909), we
// cap the height at the size of known child views (location bar and back
@ -692,6 +752,18 @@ void ToolbarView::Layout() {
if (!initialized_)
return;
// The container view should be the exact same size/position as ToolbarView.
container_view_->SetSize(size());
if (features::IsChromeRefresh2023()) {
// The background views should be behind the top-left and top-right corners
// of the container_view_.
const int corner_radius = GetLayoutConstant(TOOLBAR_CORNER_RADIUS);
background_view_left_->SetBounds(0, 0, corner_radius, corner_radius);
background_view_right_->SetBounds(width() - corner_radius, 0, corner_radius,
corner_radius);
}
if (display_mode_ == DisplayMode::CUSTOM_TAB) {
custom_tab_bar_->SetBounds(0, 0, width(),
custom_tab_bar_->GetPreferredSize().height());
@ -702,11 +774,9 @@ void ToolbarView::Layout() {
if (display_mode_ == DisplayMode::NORMAL) {
LayoutCommon();
#if BUILDFLAG(IS_MAC)
if (features::IsChromeRefresh2023()) {
UpdateClipPath();
}
#endif
}
// Call super implementation to ensure layout manager and child layouts
@ -738,7 +808,12 @@ void ToolbarView::UpdateClipPath() {
SkPathDirection::kCW, local_bounds.width(), corner_radius);
path.lineTo(local_bounds.width(), local_bounds.height());
path.lineTo(0, local_bounds.height());
SetClipPath(path);
container_view_->SetClipPath(path);
}
void ToolbarView::ActiveStateChanged() {
background_view_left_->SchedulePaint();
background_view_right_->SchedulePaint();
}
bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) {
@ -784,7 +859,8 @@ void ToolbarView::InitLayout() {
constexpr int kSidePanelFlexOrder = 3;
constexpr int kExtensionsFlexOrder = 4;
layout_manager_ = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout_manager_ =
container_view_->SetLayoutManager(std::make_unique<views::FlexLayout>());
layout_manager_->SetOrientation(views::LayoutOrientation::kHorizontal)
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter)
@ -846,6 +922,18 @@ void ToolbarView::LayoutCommon() {
views::kMarginsKey,
gfx::Insets::VH(0, kBrowserAppMenuRefreshCollapsedMargin));
}
// The margins of the `avatar_` uses the same constants as the
// `app_menu_button_`.
if (avatar_->IsLabelPresentAndVisible()) {
avatar_->SetProperty(
views::kMarginsKey,
gfx::Insets::VH(0, kBrowserAppMenuRefreshExpandedMargin));
} else {
avatar_->SetProperty(
views::kMarginsKey,
gfx::Insets::VH(0, kBrowserAppMenuRefreshCollapsedMargin));
}
}
layout_manager_->SetInteriorMargin(interior_margin);

View File

@ -5,8 +5,8 @@
#include <windows.h>
#include "base/base64.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram_functions.h"
@ -28,6 +28,10 @@ namespace {
// Contains base64 random key encrypted with DPAPI.
constexpr char kOsCryptEncryptedKeyPrefName[] = "os_crypt.encrypted_key";
// Whether or not an attempt has been made to enable audit for the DPAPI
// encryption backing the random key.
constexpr char kOsCryptAuditEnabledPrefName[] = "os_crypt.audit_enabled";
// AEAD key length in bytes.
constexpr size_t kKeyLength = 256 / 8;
@ -40,14 +44,10 @@ constexpr char kEncryptionVersionPrefix[] = "v10";
// Key prefix for a key encrypted with DPAPI.
constexpr char kDPAPIKeyPrefix[] = "DPAPI";
// Name used for a feature to used named encryption source in DPAPI.
constexpr char kNamedEncryptionSourceName[] = "NamedEncryptionSource";
bool EncryptStringWithDPAPI(const std::string& plaintext,
std::string* ciphertext) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch("disable-encryption")) {
*ciphertext = plaintext;
LOG(WARNING) << "Encryption is disabled via chrome://flags";
return true;
}
DATA_BLOB input;
@ -59,20 +59,13 @@ bool EncryptStringWithDPAPI(const std::string& plaintext,
DATA_BLOB output;
{
SCOPED_UMA_HISTOGRAM_TIMER("OSCrypt.Win.Encrypt.Time");
static BASE_FEATURE(kNamedEncyptionSource, kNamedEncryptionSourceName,
base::FEATURE_ENABLED_BY_DEFAULT);
DWORD flags = 0;
std::string data_description;
if (base::FeatureList::IsEnabled(kNamedEncyptionSource)) {
data_description = version_info::GetProductName();
flags = CRYPTPROTECT_AUDIT;
}
result = ::CryptProtectData(
/*pDataIn=*/&input,
/*szDataDescr=*/base::SysUTF8ToWide(data_description).c_str(),
/*szDataDescr=*/
base::SysUTF8ToWide(version_info::GetProductName()).c_str(),
/*pOptionalEntropy=*/nullptr,
/*pvReserved=*/nullptr,
/*pPromptStruct=*/nullptr, /*dwFlags=*/flags,
/*pPromptStruct=*/nullptr, /*dwFlags=*/CRYPTPROTECT_AUDIT,
/*pDataOut=*/&output);
}
base::UmaHistogramBoolean("OSCrypt.Win.Encrypt.Result", result);
@ -93,7 +86,6 @@ bool DecryptStringWithDPAPI(const std::string& ciphertext,
std::string* plaintext) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch("disable-encryption")) {
*plaintext = ciphertext;
LOG(WARNING) << "Encryption is disabled via chrome://flags";
return true;
}
DATA_BLOB input;
@ -118,6 +110,23 @@ bool DecryptStringWithDPAPI(const std::string& ciphertext,
LocalFree(output.pbData);
return true;
}
// Takes `key` and encrypts it with DPAPI, then stores it in the `local_state`.
// Returns true if the key was successfully encrypted and stored.
bool EncryptAndStoreKey(const std::string& key, PrefService* local_state) {
std::string encrypted_key;
if (!EncryptStringWithDPAPI(key, &encrypted_key)) {
return false;
}
// Add header indicating this key is encrypted with DPAPI.
encrypted_key.insert(0, kDPAPIKeyPrefix);
std::string base64_key;
base::Base64Encode(encrypted_key, &base64_key);
local_state->SetString(kOsCryptEncryptedKeyPrefName, base64_key);
return true;
}
} // namespace
namespace OSCrypt {
@ -234,6 +243,7 @@ bool OSCryptImpl::DecryptString(const std::string& ciphertext,
// static
void OSCryptImpl::RegisterLocalPrefs(PrefRegistrySimple* registry) {
registry->RegisterStringPref(kOsCryptEncryptedKeyPrefName, "");
registry->RegisterBooleanPref(kOsCryptAuditEnabledPrefName, false);
}
bool OSCryptImpl::Init(PrefService* local_state) {
@ -254,15 +264,13 @@ bool OSCryptImpl::Init(PrefService* local_state) {
std::string key;
crypto::RandBytes(base::WriteInto(&key, kKeyLength + 1), kKeyLength);
std::string encrypted_key;
if (!EncryptStringWithDPAPI(key, &encrypted_key))
if (!EncryptAndStoreKey(key, local_state)) {
return false;
}
// This new key is already encrypted with audit flag enabled.
local_state->SetBoolean(kOsCryptAuditEnabledPrefName, true);
// Add header indicating this key is encrypted with DPAPI.
encrypted_key.insert(0, kDPAPIKeyPrefix);
std::string base64_key;
base::Base64Encode(encrypted_key, &base64_key);
local_state->SetString(kOsCryptEncryptedKeyPrefName, base64_key);
encryption_key_.assign(key);
return true;
}
@ -296,6 +304,18 @@ OSCrypt::InitResult OSCryptImpl::InitWithExistingKey(PrefService* local_state) {
return OSCrypt::kDecryptionFailed;
}
if (!local_state->GetBoolean(kOsCryptAuditEnabledPrefName)) {
// In theory, EncryptAndStoreKey could fail if DPAPI fails to encrypt, but
// DPAPI decrypted the old data fine. In this case it's better to leave the
// previously encrypted key, since the code has been able to decrypt it.
// Trying over and over makes no sense so the code explicitly does not
// attempt again, and audit will simply not be enabled in this case.
std::ignore = EncryptAndStoreKey(key, local_state);
// Indicate that an attempt has been made to turn audit flag on, so retry is
// not attempted.
local_state->SetBoolean(kOsCryptAuditEnabledPrefName, true);
}
encryption_key_.assign(key);
return OSCrypt::kSuccess;
}

View File

@ -76,7 +76,6 @@ source_set("browser") {
"//cc/animation",
"//cc/mojo_embedder",
"//cc/paint",
"//components/aggregation_service:mojom",
"//components/attribution_reporting:mojom",
"//components/back_forward_cache:enum",
"//components/browsing_topics/common:common",
@ -98,7 +97,6 @@ source_set("browser") {
"//components/payments/content/icon",
"//components/payments/mojom",
"//components/power_monitor",
"//components/power_scheduler",
"//components/services/filesystem:lib",
"//components/services/screen_ai/buildflags",
"//components/services/storage",
@ -150,6 +148,7 @@ source_set("browser") {
"//content/public/common:common_sources",
"//content/public/common:content_descriptor_keys",
"//content/public/common/zygote:buildflags",
"//content/services/auction_worklet/public/cpp",
"//content/services/auction_worklet/public/mojom",
"//crypto",
"//device/base",
@ -374,8 +373,6 @@ source_set("browser") {
"accessibility/one_shot_accessibility_tree_search.h",
"accessibility/render_accessibility_host.cc",
"accessibility/render_accessibility_host.h",
"accessibility/touch_passthrough_manager.cc",
"accessibility/touch_passthrough_manager.h",
"accessibility/web_ax_platform_tree_manager_delegate.h",
"accessibility/web_contents_accessibility.h",
"after_startup_task_utils.cc",
@ -865,6 +862,8 @@ source_set("browser") {
"devtools/shared_worker_devtools_agent_host.h",
"devtools/shared_worker_devtools_manager.cc",
"devtools/shared_worker_devtools_manager.h",
"devtools/tracing_process_set_monitor.cc",
"devtools/tracing_process_set_monitor.h",
"devtools/web_contents_devtools_agent_host.cc",
"devtools/web_contents_devtools_agent_host.h",
"devtools/worker_devtools_agent_host.cc",
@ -1144,6 +1143,10 @@ source_set("browser") {
"interest_group/auction_url_loader_factory_proxy.h",
"interest_group/auction_worklet_manager.cc",
"interest_group/auction_worklet_manager.h",
"interest_group/bidding_and_auction_serializer.cc",
"interest_group/bidding_and_auction_serializer.h",
"interest_group/bidding_and_auction_server_key_fetcher.cc",
"interest_group/bidding_and_auction_server_key_fetcher.h",
"interest_group/debuggable_auction_worklet.cc",
"interest_group/debuggable_auction_worklet.h",
"interest_group/debuggable_auction_worklet_tracker.cc",
@ -1370,8 +1373,12 @@ source_set("browser") {
"network/network_errors_listing_ui.h",
"network/network_quality_observer_impl.cc",
"network/network_quality_observer_impl.h",
"network/network_service_util_internal.cc",
"network/network_service_util_internal.h",
"network/reporting_service_proxy.cc",
"network/reporting_service_proxy.h",
"network/shared_dictionary_util.cc",
"network/shared_dictionary_util.h",
"network/socket_broker_impl.cc",
"network/socket_broker_impl.h",
"network_context_client_base_impl.cc",
@ -1616,6 +1623,7 @@ source_set("browser") {
"renderer_host/concurrent_navigations_commit_deferring_condition.h",
"renderer_host/cookie_utils.cc",
"renderer_host/cookie_utils.h",
"renderer_host/coop_swap_result.h",
"renderer_host/cross_origin_opener_policy_access_report_manager.cc",
"renderer_host/cross_origin_opener_policy_access_report_manager.h",
"renderer_host/cross_origin_opener_policy_status.cc",
@ -1775,6 +1783,8 @@ source_set("browser") {
"renderer_host/media/media_stream_dispatcher_host.h",
"renderer_host/media/media_stream_manager.cc",
"renderer_host/media/media_stream_manager.h",
"renderer_host/media/media_stream_metrics.cc",
"renderer_host/media/media_stream_metrics.h",
"renderer_host/media/media_stream_power_logger.cc",
"renderer_host/media/media_stream_power_logger.h",
"renderer_host/media/media_stream_provider.h",
@ -2084,6 +2094,8 @@ source_set("browser") {
"shared_storage/shared_storage_document_service_impl.h",
"shared_storage/shared_storage_event_params.cc",
"shared_storage/shared_storage_event_params.h",
"shared_storage/shared_storage_header_observer.cc",
"shared_storage/shared_storage_header_observer.h",
"shared_storage/shared_storage_render_thread_worklet_driver.cc",
"shared_storage/shared_storage_render_thread_worklet_driver.h",
"shared_storage/shared_storage_url_loader_factory_proxy.cc",
@ -2247,8 +2259,6 @@ source_set("browser") {
"web_package/signed_exchange_signature_verifier.h",
"web_package/signed_exchange_utils.cc",
"web_package/signed_exchange_utils.h",
"web_package/subresource_web_bundle_navigation_info.cc",
"web_package/subresource_web_bundle_navigation_info.h",
"web_ui_browser_interface_broker_registry.cc",
"webauth/client_data_json.cc",
"webauth/client_data_json.h",
@ -2314,7 +2324,6 @@ source_set("browser") {
"webui/web_ui_impl.h",
"webui/web_ui_main_frame_observer.cc",
"webui/web_ui_main_frame_observer.h",
"webui/web_ui_managed_interface.cc",
"webui/web_ui_managed_interface.h",
"webui/web_ui_message_handler.cc",
"webui/web_ui_url_loader_factory.cc",
@ -2425,10 +2434,6 @@ source_set("browser") {
"lock_screen/lock_screen_storage_impl.h",
"ml/ml_service_impl_cros.cc",
"ml/ml_service_impl_cros.h",
"smart_card/smart_card_reader_tracker.cc",
"smart_card/smart_card_reader_tracker.h",
"smart_card/smart_card_reader_tracker_impl.cc",
"smart_card/smart_card_reader_tracker_impl.h",
"smart_card/smart_card_service.cc",
"smart_card/smart_card_service.h",
]
@ -2639,14 +2644,21 @@ source_set("browser") {
} else if (is_ios) {
sources += [
"child_process_launcher_helper_ios.cc",
"devtools/protocol/native_input_event_builder_ios.mm",
"renderer_host/browser_compositor_ios.h",
"renderer_host/browser_compositor_ios.mm",
"renderer_host/delegated_frame_host_client_ios.cc",
"renderer_host/delegated_frame_host_client_ios.h",
"renderer_host/input/synthetic_gesture_target_ios.h",
"renderer_host/input/synthetic_gesture_target_ios.mm",
"renderer_host/input/web_input_event_builders_ios.h",
"renderer_host/input/web_input_event_builders_ios.mm",
"renderer_host/native_web_keyboard_event_ios.mm",
"renderer_host/popup_menu_helper_ios.h",
"renderer_host/popup_menu_helper_ios.mm",
"renderer_host/render_widget_host_view_ios.h",
"renderer_host/render_widget_host_view_ios.mm",
"speech/tts_ios.mm",
"web_contents/web_contents_view_ios.h",
"web_contents/web_contents_view_ios.mm",
]
@ -2697,6 +2709,8 @@ source_set("browser") {
"media/capture/mouse_cursor_overlay_controller_mac.mm",
"media/capture/screen_capture_kit_device_mac.h",
"media/capture/screen_capture_kit_device_mac.mm",
"media/capture/screen_capture_kit_fullscreen_module.h",
"media/capture/screen_capture_kit_fullscreen_module.mm",
"media/capture/views_widget_video_capture_device_mac.cc",
"media/capture/views_widget_video_capture_device_mac.h",
]
@ -2798,7 +2812,7 @@ source_set("browser") {
]
}
if (is_android || is_linux || is_chromeos) {
if (is_android || is_linux) {
deps += [ "//content/browser/system_dns_resolution" ]
}
@ -2945,15 +2959,6 @@ source_set("browser") {
configs += [ "//build/config/linux/pangocairo" ]
}
if (is_ios) {
sources += [
"renderer_host/input/web_input_event_builders_ios.h",
"renderer_host/input/web_input_event_builders_ios.mm",
"renderer_host/native_web_keyboard_event_ios.mm",
"speech/tts_ios.mm",
]
}
if (is_android) {
sources += [
"accessibility/accessibility_tree_formatter_android.cc",
@ -2970,6 +2975,8 @@ source_set("browser") {
"accessibility/captioning_controller.h",
"accessibility/web_contents_accessibility_android.cc",
"accessibility/web_contents_accessibility_android.h",
"android/additional_navigation_params_utils.cc",
"android/additional_navigation_params_utils.h",
"android/android_overlay_provider_impl.cc",
"android/android_overlay_provider_impl.h",
"android/app_web_message_port.cc",
@ -2982,7 +2989,7 @@ source_set("browser") {
"android/browser_startup_controller.cc",
"android/browser_startup_controller.h",
"android/client_data_json_android.cc",
"android/content_feature_list.cc",
"android/content_feature_map.cc",
"android/content_startup_flags.cc",
"android/content_startup_flags.h",
"android/content_ui_event_handler.cc",
@ -3002,8 +3009,6 @@ source_set("browser") {
"android/gpu_process_callback.cc",
"android/ime_adapter_android.cc",
"android/ime_adapter_android.h",
"android/impression_utils.cc",
"android/impression_utils.h",
"android/java/gin_java_bound_object.cc",
"android/java/gin_java_bound_object.h",
"android/java/gin_java_bound_object_delegate.cc",
@ -3085,8 +3090,6 @@ source_set("browser") {
"media/android/media_player_renderer_web_contents_observer.h",
"media/android/media_resource_getter_impl.cc",
"media/android/media_resource_getter_impl.h",
"media/capture/screen_capture_device_android.cc",
"media/capture/screen_capture_device_android.h",
"media/key_system_support_android.cc",
"media/key_system_support_android.h",
"media/session/audio_focus_delegate_android.cc",
@ -3148,7 +3151,6 @@ source_set("browser") {
"//device/gamepad/public/mojom",
"//gpu/command_buffer/service:gles2",
"//media",
"//media/capture/content/android",
"//media/capture/video/android",
"//third_party/blink/public/common:font_unique_name_table_proto",
"//third_party/blink/public/mojom:mojom_platform_blink",

@ -1 +1 @@
Subproject commit c7ec859c82f12f5501ba34e0602e0d94bd6d61be
Subproject commit eb3ee8720720c1760ae6a11677f46199c805c547