diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f27c37ab8919..4a9c19c55f91 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -993,6 +993,10 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { return; } + if (guest_delegate_ && !guest_delegate_->Attached()) { + return; + } + content::NavigationController::LoadURLParams params(url); GURL http_referrer; diff --git a/atom/browser/web_view_guest_delegate.cc b/atom/browser/web_view_guest_delegate.cc index 2d16504c59f9..c8aee6a2e8d3 100644 --- a/atom/browser/web_view_guest_delegate.cc +++ b/atom/browser/web_view_guest_delegate.cc @@ -110,7 +110,12 @@ void WebViewGuestDelegate::DidFinishNavigation( } } +void WebViewGuestDelegate::DidDetach() { + attached_ = false; +} + void WebViewGuestDelegate::DidAttach(int guest_proxy_routing_id) { + attached_ = true; api_web_contents_->Emit("did-attach"); embedder_zoom_controller_ = WebContentsZoomController::FromWebContents(embedder_web_contents_); diff --git a/atom/browser/web_view_guest_delegate.h b/atom/browser/web_view_guest_delegate.h index 0d97d8095068..777639df1f51 100644 --- a/atom/browser/web_view_guest_delegate.h +++ b/atom/browser/web_view_guest_delegate.h @@ -47,6 +47,9 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, // and normal sizes. void SetSize(const SetSizeParams& params); + // Return true if attached. + bool Attached() const { return attached_; } + protected: // content::WebContentsObserver: void DidFinishNavigation( @@ -54,6 +57,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; @@ -116,6 +120,9 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate, // Whether the guest view is inside a plugin document. bool is_full_page_plugin_; + // Whether attached. + bool attached_; + api::WebContents* api_web_contents_; DISALLOW_COPY_AND_ASSIGN(WebViewGuestDelegate);