Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
make sure guest webcontents don't load until they are attached. This …
Browse files Browse the repository at this point in the history
…is a temporary workaround to handle load failures that otherwise would not be caught by the current navigation controls
  • Loading branch information
bridiver committed Jun 3, 2016
1 parent bcfdf66 commit 0d905b6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,14 @@ void WebContents::AddNewContents(content::WebContents* source,
}

bool WebContents::ShouldResumeRequestsForCreatedWindow() {
return false;
}

bool WebContents::IsAttached() {
if (guest_delegate_)
return guest_delegate_->ShouldResumeRequestsForCreatedWindow();
return guest_delegate_->IsAttached();

return true;
return owner_window() != nullptr;
}

content::WebContents* WebContents::OpenURLFromTab(
Expand All @@ -451,11 +455,12 @@ content::WebContents* WebContents::OpenURLFromTab(
return nullptr;

auto api_web_contents = CreateFrom(isolate(), source);
if (api_web_contents->ShouldResumeRequestsForCreatedWindow()) {
if (api_web_contents->IsAttached()) {
CommonWebContentsDelegate::OpenURLFromTab(source, params);
} else {
api_web_contents->delayed_open_url_params_.reset(
new content::OpenURLParams(params));
return nullptr;
}

return source;
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
bool user_gesture,
bool* was_blocked) override;
bool ShouldResumeRequestsForCreatedWindow() override;
bool IsAttached();
content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) override;
Expand Down
6 changes: 5 additions & 1 deletion atom/browser/web_view_guest_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void WebViewGuestDelegate::DidCommitProvisionalLoadForFrame(
api_web_contents_->Emit("load-commit", url, !render_frame_host->GetParent());
}

bool WebViewGuestDelegate::ShouldResumeRequestsForCreatedWindow() {
bool WebViewGuestDelegate::IsAttached() {
return guest_proxy_routing_id_ != -1;
}

Expand All @@ -200,6 +200,10 @@ void WebViewGuestDelegate::SetGuestHost(content::GuestHost* guest_host) {
guest_host_ = guest_host;
}

void WebViewGuestDelegate::DidDetach() {
guest_proxy_routing_id_ = -1;
}

void WebViewGuestDelegate::WillAttach(
content::WebContents* embedder_web_contents,
int element_instance_id,
Expand Down
3 changes: 2 additions & 1 deletion atom/browser/web_view_guest_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
// This value is only valid after attachment or first navigation.
int proxy_routing_id() const { return guest_proxy_routing_id_; }

bool ShouldResumeRequestsForCreatedWindow();
bool IsAttached();

protected:
// content::WebContentsObserver:
Expand All @@ -68,6 +68,7 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,

// content::BrowserPluginGuestDelegate:
void DidAttach(int guest_proxy_routing_id) final;
void DidDetach() final;
content::WebContents* GetOwnerWebContents() const final;
void GuestSizeChanged(const gfx::Size& new_size) final;
void SetGuestHost(content::GuestHost* guest_host) final;
Expand Down

0 comments on commit 0d905b6

Please sign in to comment.