diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f27c37ab891..a23d2817b87 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_->IsAttached()) { + 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 2d16504c59f..1fc79a6a342 100644 --- a/atom/browser/web_view_guest_delegate.cc +++ b/atom/browser/web_view_guest_delegate.cc @@ -28,6 +28,7 @@ WebViewGuestDelegate::WebViewGuestDelegate() guest_host_(nullptr), auto_size_enabled_(false), is_full_page_plugin_(false), + attached_(false), api_web_contents_(nullptr) {} WebViewGuestDelegate::~WebViewGuestDelegate() { @@ -110,7 +111,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 0d97d809506..2e2941b5a35 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 IsAttached() 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);