]> khamidou — GitHub mirrors - electron.git/commitdiff
Also pass "webContents" in "login" event
authorCheng Zhao <zcbenz@gmail.com>
Wed, 28 Oct 2015 12:21:56 +0000 (20:21 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 28 Oct 2015 12:23:18 +0000 (20:23 +0800)
atom/browser/api/atom_api_app.cc
atom/browser/login_handler.cc
atom/browser/login_handler.h
atom/common/native_mate_converters/content_converter.cc

index db1f9935230924597194bb2c0cb575a7fd46a795..5380d52ad693acbf1a4e510ea3ec3290c478c500 100644 (file)
@@ -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.
index ededcd0c85138de293549ff2f8960e6325534b9b..ca6e5de57df097106cfaa158d8a3f60a091ff598 100644 (file)
@@ -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);
index 60e0a7a5298dfa97d11847a22626a709326625d6..899bc8ca450e3b47d42e77afcd37410f00130a7a 100644 (file)
@@ -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);
 };
 
index 0ab9f272041e54257a193780323fb83f49fa08e5..b6f3a2c1cc033d72edfa2ea8abe478f8c1f3b481 100644 (file)
@@ -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