mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
Also pass "webContents" in "login" event
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ v8::Local<v8::Value> Converter<const net::URLRequest*>::ToV8(
|
||||
dict.Set("url", val->url().spec());
|
||||
dict.Set("referrer", val->referrer());
|
||||
return mate::ConvertToV8(isolate, dict);
|
||||
};
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> Converter<const net::AuthChallengeInfo*>::ToV8(
|
||||
@@ -29,6 +29,6 @@ v8::Local<v8::Value> Converter<const net::AuthChallengeInfo*>::ToV8(
|
||||
dict.Set("port", static_cast<uint32_t>(val->challenger.port()));
|
||||
dict.Set("realm", val->realm);
|
||||
return mate::ConvertToV8(isolate, dict);
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace mate
|
||||
|
||||
Reference in New Issue
Block a user