Change WebContents::IsLoadingMainFrame to compare SiteInstances

(per @deepak1556's recommendation)

Also updates tests to cover the situation where navigating between pages from the same potential "site" and adds generalized tests for `isLoadingMainFrame()`.
This commit is contained in:
Rob Brackett 2016-04-19 22:05:09 -07:00
parent 942971b01a
commit d3e879cd7f
3 changed files with 69 additions and 64 deletions

View file

@ -220,8 +220,7 @@ WebContents::WebContents(content::WebContents* web_contents)
embedder_(nullptr),
type_(REMOTE),
request_id_(0),
background_throttling_(true),
is_loading_main_frame_(false) {
background_throttling_(true) {
AttachAsUserData(web_contents);
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
}
@ -230,8 +229,7 @@ WebContents::WebContents(v8::Isolate* isolate,
const mate::Dictionary& options)
: embedder_(nullptr),
request_id_(0),
background_throttling_(true),
is_loading_main_frame_(false) {
background_throttling_(true) {
// Read options.
options.Get("backgroundThrottling", &background_throttling_);
@ -545,32 +543,12 @@ void WebContents::DocumentLoadedInFrame(
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) {
bool is_main_frame = !render_frame_host->GetParent();
if (is_main_frame)
is_loading_main_frame_ = false;
Emit("did-frame-finish-load", is_main_frame);
if (is_main_frame)
Emit("did-finish-load");
}
void WebContents::DidStartProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url,
bool is_error_page,
bool is_iframe_srcdoc) {
if (!render_frame_host->GetParent())
is_loading_main_frame_ = true;
}
void WebContents::DidCommitProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
const GURL& url,
ui::PageTransition transition_type) {
if (!render_frame_host->GetParent())
is_loading_main_frame_ = true;
}
void WebContents::DidFailProvisionalLoad(
content::RenderFrameHost* render_frame_host,
const GURL& url,
@ -578,8 +556,6 @@ void WebContents::DidFailProvisionalLoad(
const base::string16& description,
bool was_ignored_by_handler) {
bool is_main_frame = !render_frame_host->GetParent();
if (is_main_frame)
is_loading_main_frame_ = false;
Emit("did-fail-provisional-load", code, description, url, is_main_frame);
Emit("did-fail-load", code, description, url, is_main_frame);
}
@ -818,7 +794,11 @@ bool WebContents::IsLoading() const {
}
bool WebContents::IsLoadingMainFrame() const {
return is_loading_main_frame_;
// Comparing site instances works because Electron always creates a new site
// instance when navigating, regardless of origin. See AtomBrowserClient.
return (web_contents()->GetLastCommittedURL().is_empty() ||
web_contents()->GetSiteInstance() !=
web_contents()->GetPendingSiteInstance()) && IsLoading();
}
bool WebContents::IsWaitingForResponse() const {