chrome: Add support for persist_session_cookies (fixes issue #3291)

This change configures session restore behavior for the NEXT application
restart by setting the "session.restore_on_startup" preference based on the
[CefSettings|CefRequestContextSettings].persist_session_cookies value.
This commit is contained in:
Marshall Greenblatt 2022-03-22 20:42:03 -04:00
parent 5ec45e5f7f
commit 9d52d72ae5
2 changed files with 25 additions and 5 deletions

View File

@ -8,9 +8,11 @@
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/keep_alive/profile_keep_alive_types.h"
#include "chrome/browser/profiles/keep_alive/scoped_profile_keep_alive.h"
#include "chrome/browser/profiles/off_the_record_profile_impl.h"
#include "chrome/common/pref_names.h"
ChromeBrowserContext::ChromeBrowserContext(
const CefRequestContextSettings& settings)
@ -140,6 +142,15 @@ void ChromeBrowserContext::ProfileCreated(Profile* profile,
parent_profile->NotifyOffTheRecordProfileCreated(otr_profile);
}
if (!profile_->IsOffTheRecord()) {
// Configure the desired profile restore behavior for the next application
// restart (checked via ProfileImpl::ShouldRestoreOldSessionCookies).
profile_->GetPrefs()->SetInteger(
prefs::kRestoreOnStartup, !!settings_.persist_session_cookies
? SessionStartupPref::kPrefValueLast
: SessionStartupPref::kPrefValueNewTab);
}
if (!init_callbacks_.empty()) {
for (auto& callback : init_callbacks_) {
std::move(callback).Run();

View File

@ -45,7 +45,7 @@ index cff1df2490bb6..864a03a2e29c9 100644
bool BrowserCommandController::IsWebAppOrCustomTab() const {
diff --git chrome/browser/ui/views/frame/browser_frame.cc chrome/browser/ui/views/frame/browser_frame.cc
index 6b644bf006532..9ae5bd273b6dc 100644
index 6b644bf006532..4b5082a6a2dfe 100644
--- chrome/browser/ui/views/frame/browser_frame.cc
+++ chrome/browser/ui/views/frame/browser_frame.cc
@@ -74,15 +74,23 @@ bool IsUsingGtkTheme(Profile* profile) {
@ -87,7 +87,16 @@ index 6b644bf006532..9ae5bd273b6dc 100644
return browser_frame_view_->GetTopInset(false);
}
@@ -177,15 +191,21 @@ void BrowserFrame::GetWindowPlacement(gfx::Rect* bounds,
@@ -172,20 +186,30 @@ bool BrowserFrame::ShouldDrawFrameHeader() const {
void BrowserFrame::GetWindowPlacement(gfx::Rect* bounds,
ui::WindowShowState* show_state) const {
+ if (!native_browser_frame_) {
+ *show_state = ui::SHOW_STATE_DEFAULT;
+ return;
+ }
return native_browser_frame_->GetWindowPlacement(bounds, show_state);
}
content::KeyboardEventProcessingResult BrowserFrame::PreHandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) {
@ -109,7 +118,7 @@ index 6b644bf006532..9ae5bd273b6dc 100644
browser_frame_view_->OnBrowserViewInitViewsComplete();
}
@@ -246,6 +266,8 @@ const ui::ThemeProvider* BrowserFrame::GetThemeProvider() const {
@@ -246,6 +270,8 @@ const ui::ThemeProvider* BrowserFrame::GetThemeProvider() const {
ui::ColorProviderManager::InitializerSupplier* BrowserFrame::GetCustomTheme()
const {
@ -118,7 +127,7 @@ index 6b644bf006532..9ae5bd273b6dc 100644
Browser* browser = browser_view_->browser();
// If this is an incognito profile, there should never be a custom theme.
if (browser->profile()->IsIncognitoProfile())
@@ -374,7 +396,8 @@ void BrowserFrame::SelectNativeTheme() {
@@ -374,7 +400,8 @@ void BrowserFrame::SelectNativeTheme() {
// Select between regular, dark and GTK theme.
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
@ -128,7 +137,7 @@ index 6b644bf006532..9ae5bd273b6dc 100644
// No matter if we are using the default theme or not we always use the dark
// ui instance.
SetNativeTheme(ui::NativeTheme::GetInstanceForDarkUI());
@@ -387,7 +410,8 @@ void BrowserFrame::SelectNativeTheme() {
@@ -387,7 +414,8 @@ void BrowserFrame::SelectNativeTheme() {
// display_override so the web contents can blend with the overlay by using
// the developer-provided theme color for a better experience. Context:
// https://crbug.com/1219073.