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.
#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"
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()),
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);
#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;
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();
// 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);
};
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(
dict.Set("port", static_cast<uint32_t>(val->challenger.port()));
dict.Set("realm", val->realm);
return mate::ConvertToV8(isolate, dict);
-};
+}
} // namespace mate