Fixed extension's newtab is not loaded when it's restored during the startup
fix https://github.com/brave/brave-browser/issues/30890 As we sanitize serialzed navigation(https://github.com/brave/brave-browser/issues/30890), encoded page state is empty for all chrome url. So, new page state is created with virtual url when it's restored during the startup. ContentSerializedNavigationBuilder::ToNavigationEntry() set new page state if it's empty. When new page state is created, navigation's virtual url is created. If url is re-written when NavigationEntryImpl is created, that re-written url is ignored. To fix this, including url info only for chrome url's encoded page state.
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
#include "net/dns/mock_host_resolver.h"
|
||||
#include "services/network/public/cpp/network_switches.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/page_state/page_state.h"
|
||||
#include "third_party/blink/public/common/page_state/page_state_serialization.h"
|
||||
|
||||
using BraveSesstionRestoreBrowserTest = InProcessBrowserTest;
|
||||
using BraveSessionRestoreBrowserTest = InProcessBrowserTest;
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(BraveSesstionRestoreBrowserTest, Serialization) {
|
||||
IN_PROC_BROWSER_TEST_F(BraveSessionRestoreBrowserTest, Serialization) {
|
||||
auto* tab_model = browser()->tab_strip_model();
|
||||
auto* web_contents = tab_model->GetActiveWebContents();
|
||||
SessionService* const session_service =
|
||||
@@ -53,7 +55,12 @@ IN_PROC_BROWSER_TEST_F(BraveSesstionRestoreBrowserTest, Serialization) {
|
||||
const auto& serialized_navigation = windows[0]->tabs[0]->navigations[1];
|
||||
EXPECT_EQ(serialized_navigation.virtual_url(),
|
||||
GURL("chrome://newtab/"));
|
||||
EXPECT_TRUE(serialized_navigation.encoded_page_state().empty());
|
||||
|
||||
// Check encoded data is not empty but clean state only with url info.
|
||||
EXPECT_EQ(blink::PageState::CreateFromURL(GURL("chrome://newtab/"))
|
||||
.ToEncodedData(),
|
||||
serialized_navigation.encoded_page_state());
|
||||
EXPECT_FALSE(serialized_navigation.encoded_page_state().empty());
|
||||
loop.Quit();
|
||||
}));
|
||||
loop.Run();
|
||||
|
||||
@@ -17,8 +17,18 @@
|
||||
namespace sessions {
|
||||
std::string ContentSerializedNavigationDriver::GetSanitizedPageStateForPickle(
|
||||
const sessions::SerializedNavigationEntry* navigation) const {
|
||||
if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme))
|
||||
return std::string();
|
||||
if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme)) {
|
||||
// chrome url can be re-written when it's restored during the tab but
|
||||
// re-written url is ignored when encoded page state is empty.
|
||||
// In ContentSerializedNavigationBuilder::ToNavigationEntry(), re-written
|
||||
// url created by NavigationEntry's ctor is ignored by creating new page
|
||||
// state with navigation's virtual_url. Sanitize all but make url info
|
||||
// persisted. Use original_request_url as it's used when NavigationEntry is
|
||||
// created.
|
||||
return blink::PageState::CreateFromURL(navigation->original_request_url())
|
||||
.ToEncodedData();
|
||||
}
|
||||
|
||||
return GetSanitizedPageStateForPickle_ChromiumImpl(navigation);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "components/sessions/core/serialized_navigation_entry.h"
|
||||
#include "components/sessions/core/serialized_navigation_entry_test_helper.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/blink/public/common/page_state/page_state.h"
|
||||
#include "third_party/blink/public/common/page_state/page_state_serialization.h"
|
||||
|
||||
namespace sessions {
|
||||
|
||||
@@ -24,7 +26,10 @@ TEST(BraveContentSerializedNavigationDriverTest,
|
||||
EXPECT_EQ(std::string(), driver->GetSanitizedPageStateForPickle(&navigation));
|
||||
|
||||
navigation.set_virtual_url(GURL("chrome://wallet"));
|
||||
EXPECT_EQ(std::string(), driver->GetSanitizedPageStateForPickle(&navigation));
|
||||
// Check encoded data is not empty but clean state only with url info.
|
||||
EXPECT_EQ(blink::PageState::CreateFromURL(navigation.original_request_url())
|
||||
.ToEncodedData(),
|
||||
driver->GetSanitizedPageStateForPickle(&navigation));
|
||||
}
|
||||
|
||||
// Tests that PageState data is left unsanitized when post data is absent.
|
||||
@@ -39,7 +44,10 @@ TEST(BraveContentSerializedNavigationDriverTest,
|
||||
EXPECT_EQ(test_data::kEncodedPageState,
|
||||
driver->GetSanitizedPageStateForPickle(&navigation));
|
||||
navigation.set_virtual_url(GURL("chrome://wallet"));
|
||||
EXPECT_EQ(std::string(), driver->GetSanitizedPageStateForPickle(&navigation));
|
||||
// Check encoded data is not empty but clean state only with url info.
|
||||
EXPECT_EQ(blink::PageState::CreateFromURL(navigation.original_request_url())
|
||||
.ToEncodedData(),
|
||||
driver->GetSanitizedPageStateForPickle(&navigation));
|
||||
}
|
||||
|
||||
} // namespace sessions
|
||||
|
||||
Reference in New Issue
Block a user