diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index db1f9935230..5380d52ad69 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -244,6 +244,7 @@ void App::OnSelectCertificate( void App::OnLogin(LoginHandler* login_handler) { bool prevent_default = Emit( "login", login_handler->request(), login_handler->auth_info(), + api::WebContents::CreateFrom(isolate(), login_handler->GetWebContents()), base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler))); // Default behavior is to alwasy cancel the auth. diff --git a/atom/browser/login_handler.cc b/atom/browser/login_handler.cc index ededcd0c851..ca6e5de57df 100644 --- a/atom/browser/login_handler.cc +++ b/atom/browser/login_handler.cc @@ -6,7 +6,10 @@ #include "atom/browser/browser.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_frame_host.h" #include "content/public/browser/resource_dispatcher_host.h" +#include "content/public/browser/resource_request_info.h" +#include "content/public/browser/web_contents.h" #include "net/base/auth.h" #include "net/url_request/url_request.h" @@ -27,7 +30,12 @@ void ResetLoginHandlerForRequest(net::URLRequest* request) { LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request) - : auth_info_(auth_info), request_(request) { + : auth_info_(auth_info), + request_(request), + render_process_host_id_(0), + render_frame_id_(0) { + content::ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderFrame( + &render_process_host_id_, &render_frame_id_); BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(&Browser::RequestLogin, base::Unretained(Browser::Get()), @@ -37,6 +45,14 @@ LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, LoginHandler::~LoginHandler() { } +content::WebContents* LoginHandler::GetWebContents() const { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( + render_process_host_id_, render_frame_id_); + return content::WebContents::FromRenderFrameHost(rfh); +} + void LoginHandler::Login(const base::string16& username, const base::string16& password) { DCHECK_CURRENTLY_ON(BrowserThread::UI); diff --git a/atom/browser/login_handler.h b/atom/browser/login_handler.h index 60e0a7a5298..899bc8ca450 100644 --- a/atom/browser/login_handler.h +++ b/atom/browser/login_handler.h @@ -8,6 +8,10 @@ #include "base/strings/string16.h" #include "content/public/browser/resource_dispatcher_host_login_delegate.h" +namespace content { +class WebContents; +} + namespace net { class AuthChallengeInfo; class URLRequest; @@ -20,6 +24,10 @@ class LoginHandler : public content::ResourceDispatcherHostLoginDelegate { public: LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); + // Returns the WebContents associated with the request, must be called on UI + // thread. + content::WebContents* GetWebContents() const; + // The auth is cancelled, must be called on UI thread. void CancelAuth(); @@ -47,6 +55,10 @@ class LoginHandler : public content::ResourceDispatcherHostLoginDelegate { // This should only be accessed on the IO loop. net::URLRequest* request_; + // Cached from the net::URLRequest, in case it goes NULL on us. + int render_process_host_id_; + int render_frame_id_; + DISALLOW_COPY_AND_ASSIGN(LoginHandler); }; diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index 0ab9f272041..b6f3a2c1cc0 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -17,7 +17,7 @@ v8::Local Converter::ToV8( dict.Set("url", val->url().spec()); dict.Set("referrer", val->referrer()); return mate::ConvertToV8(isolate, dict); -}; +} // static v8::Local Converter::ToV8( @@ -29,6 +29,6 @@ v8::Local Converter::ToV8( dict.Set("port", static_cast(val->challenger.port())); dict.Set("realm", val->realm); return mate::ConvertToV8(isolate, dict); -}; +} } // namespace mate