Fix navigation to debug URLs

This commit is contained in:
Marshall Greenblatt 2020-02-14 16:58:58 -05:00
parent 71768ea6c3
commit a141082b91
6 changed files with 57 additions and 26 deletions

View File

@ -1107,9 +1107,8 @@ typedef enum {
TT_LINK = 0,
///
// Source is some other "explicit" navigation action such as creating a new
// browser or using the LoadURL function. This is also the default value
// for navigations where the actual type is unknown.
// Source is some other "explicit" navigation. This is the default value for
// navigations where the actual type is unknown. See also TT_DIRECT_LOAD_FLAG.
///
TT_EXPLICIT = 1,
@ -1161,9 +1160,15 @@ typedef enum {
///
// Used the Forward or Back function to navigate among browsing history.
// Will be ORed to the transition type for the original load.
///
TT_FORWARD_BACK_FLAG = 0x01000000,
///
// Loaded a URL directly via CreateBrowser, LoadURL or LoadRequest.
///
TT_DIRECT_LOAD_FLAG = 0x02000000,
///
// The beginning of a navigation chain.
///

View File

@ -381,7 +381,8 @@ CefRefPtr<CefBrowserHostImpl> CefBrowserHostImpl::Create(
create_params.extension_host_type);
} else if (!create_params.url.is_empty()) {
browser->LoadMainFrameURL(create_params.url.spec(), content::Referrer(),
ui::PAGE_TRANSITION_TYPED, std::string());
CefFrameHostImpl::kPageTransitionExplicit,
std::string());
}
return browser.get();

View File

@ -158,13 +158,13 @@ void CefFrameHostImpl::GetText(CefRefPtr<CefStringVisitor> visitor) {
}
void CefFrameHostImpl::LoadRequest(CefRefPtr<CefRequest> request) {
CefNavigateParams params(GURL(), ui::PAGE_TRANSITION_TYPED);
CefNavigateParams params(GURL(), kPageTransitionExplicit);
static_cast<CefRequestImpl*>(request.get())->Get(params);
Navigate(params);
}
void CefFrameHostImpl::LoadURL(const CefString& url) {
LoadURLWithExtras(url, content::Referrer(), ui::PAGE_TRANSITION_TYPED,
LoadURLWithExtras(url, content::Referrer(), kPageTransitionExplicit,
std::string());
}
@ -533,6 +533,11 @@ const int64_t CefFrameHostImpl::kFocusedFrameId = -2;
const int64_t CefFrameHostImpl::kUnspecifiedFrameId = -3;
const int64_t CefFrameHostImpl::kInvalidFrameId = -4;
// This equates to (TT_EXPLICIT | TT_DIRECT_LOAD_FLAG).
const ui::PageTransition CefFrameHostImpl::kPageTransitionExplicit =
static_cast<ui::PageTransition>(ui::PAGE_TRANSITION_TYPED |
ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
int64 CefFrameHostImpl::GetFrameId() const {
base::AutoLock lock_scope(state_lock_);
return is_main_frame_ ? kMainFrameId : frame_id_;

View File

@ -138,6 +138,11 @@ class CefFrameHostImpl : public CefFrame {
static const int64_t kUnspecifiedFrameId;
static const int64_t kInvalidFrameId;
// PageTransition type for explicit navigations. This must pass the check in
// ContentBrowserClient::IsExplicitNavigation for debug URLs (HandleDebugURL)
// to work as expected.
static const ui::PageTransition kPageTransitionExplicit;
private:
int64 GetFrameId() const;
CefRefPtr<CefBrowserHostImpl> GetBrowserHostImpl() const;

View File

@ -26,6 +26,14 @@ const char kHNav3[] = "http://tests-hnav.com/nav3.html";
const char kHistoryNavMsg[] = "NavigationTest.HistoryNav";
const char kHistoryNavTestCmdKey[] = "nav-history-test";
const cef_transition_type_t kTransitionExplicitLoad =
static_cast<cef_transition_type_t>(TT_EXPLICIT | TT_DIRECT_LOAD_FLAG);
// TT_FORWARD_BACK_FLAG is added to the original transition flags.
const cef_transition_type_t kTransitionExplicitForwardBack =
static_cast<cef_transition_type_t>(kTransitionExplicitLoad |
TT_FORWARD_BACK_FLAG);
enum NavAction { NA_LOAD = 1, NA_BACK, NA_FORWARD, NA_CLEAR };
typedef struct {
@ -237,10 +245,11 @@ class NavigationEntryVisitor : public CefNavigationEntryVisitor {
entry->GetOriginalURL().ToString().c_str());
EXPECT_STREQ(expected_title.c_str(), entry->GetTitle().ToString().c_str());
const auto transition_type = entry->GetTransitionType();
if (expected_forwardback_[index])
EXPECT_EQ(TT_EXPLICIT | TT_FORWARD_BACK_FLAG, entry->GetTransitionType());
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
else
EXPECT_EQ(TT_EXPLICIT, entry->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
EXPECT_FALSE(entry->HasPostData());
EXPECT_GT(entry->GetCompletionTime().GetTimeT(), 0);
@ -355,11 +364,12 @@ class HistoryNavTestHandler : public TestHandler {
EXPECT_STREQ(item.target, url.c_str());
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
const auto transition_type = request->GetTransitionType();
if (item.action == NA_LOAD) {
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
} else if (item.action == NA_BACK || item.action == NA_FORWARD) {
EXPECT_EQ(TT_EXPLICIT | TT_FORWARD_BACK_FLAG,
request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
}
if (nav_ > 0) {
@ -382,11 +392,12 @@ class HistoryNavTestHandler : public TestHandler {
const NavListItem& item = kHNavList[nav_];
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
const auto transition_type = request->GetTransitionType();
if (item.action == NA_LOAD) {
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
} else if (item.action == NA_BACK || item.action == NA_FORWARD) {
EXPECT_EQ(TT_EXPLICIT | TT_FORWARD_BACK_FLAG,
request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
}
got_before_resource_load_[nav_].yes();
@ -429,9 +440,9 @@ class HistoryNavTestHandler : public TestHandler {
got_load_start_[nav_].yes();
if (item.action == NA_LOAD) {
EXPECT_EQ(TT_EXPLICIT, transition_type);
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
} else if (item.action == NA_BACK || item.action == NA_FORWARD) {
EXPECT_EQ(TT_EXPLICIT | TT_FORWARD_BACK_FLAG, transition_type);
EXPECT_EQ(kTransitionExplicitForwardBack, transition_type);
}
std::string url1 = browser->GetMainFrame()->GetURL();
@ -827,7 +838,7 @@ class RedirectTestHandler : public TestHandler {
std::string url = request->GetURL();
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
if (url == kRNav1) {
got_nav1_before_resource_load_.yes();
@ -891,7 +902,7 @@ class RedirectTestHandler : public TestHandler {
// Should only be called for the final loaded URL.
std::string url = frame->GetURL();
EXPECT_EQ(TT_EXPLICIT, transition_type);
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
if (url == kRNav4) {
got_nav4_load_start_.yes();
@ -1457,7 +1468,7 @@ class OrderNavTestHandler : public TestHandler {
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
got_before_browse_popup_.yes();
} else {
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
EXPECT_GT(browser->GetIdentifier(), 0);
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
got_before_browse_main_.yes();
@ -1486,7 +1497,7 @@ class OrderNavTestHandler : public TestHandler {
EXPECT_GT(browser->GetIdentifier(), 0);
EXPECT_EQ(browser_id_popup_, browser->GetIdentifier());
} else {
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
EXPECT_GT(browser->GetIdentifier(), 0);
EXPECT_EQ(browser_id_main_, browser->GetIdentifier());
}
@ -1517,7 +1528,7 @@ class OrderNavTestHandler : public TestHandler {
EXPECT_EQ(TT_LINK, transition_type);
state_popup_.OnLoadStart(browser, frame);
} else {
EXPECT_EQ(TT_EXPLICIT, transition_type);
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
state_main_.OnLoadStart(browser, frame);
}
}
@ -1835,7 +1846,7 @@ class LoadNavTestHandler : public TestHandler {
bool is_redirect) override {
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
if (mode_ == LOAD || request->GetURL() == kLoadNav1) {
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, request->GetTransitionType());
EXPECT_FALSE(user_gesture);
} else {
EXPECT_EQ(TT_LINK, request->GetTransitionType());
@ -1896,10 +1907,12 @@ class LoadNavTestHandler : public TestHandler {
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> callback) override {
EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType());
const auto transition_type = request->GetTransitionType();
if (mode_ == LOAD || request->GetURL() == kLoadNav1)
EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType());
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
else
EXPECT_EQ(TT_LINK, request->GetTransitionType());
EXPECT_EQ(TT_LINK, transition_type);
EXPECT_GT(browser_id_current_, 0);
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
@ -1916,7 +1929,7 @@ class LoadNavTestHandler : public TestHandler {
EXPECT_EQ(browser_id_current_, browser->GetIdentifier());
if (mode_ == LOAD || frame->GetURL() == kLoadNav1)
EXPECT_EQ(TT_EXPLICIT, transition_type);
EXPECT_EQ(kTransitionExplicitLoad, transition_type);
else
EXPECT_EQ(TT_LINK, transition_type);

View File

@ -374,6 +374,8 @@ TEST(RequestTest, SendRecv) {
namespace {
const char kTypeTestOrigin[] = "http://tests-requesttt.com/";
const cef_transition_type_t kTransitionExplicitLoad =
static_cast<cef_transition_type_t>(TT_EXPLICIT | TT_DIRECT_LOAD_FLAG);
static struct TypeExpected {
const char* file;
@ -383,7 +385,7 @@ static struct TypeExpected {
int expected_count;
} g_type_expected[] = {
// Initial main frame load due to browser creation.
{"main.html", true, TT_EXPLICIT, RT_MAIN_FRAME, 1},
{"main.html", true, kTransitionExplicitLoad, RT_MAIN_FRAME, 1},
// Sub frame load.
{"sub.html", true, TT_AUTO_SUBFRAME, RT_SUB_FRAME, 1},