]> khamidou — GitHub mirrors - electron.git/commitdiff
Pass auth_info and request in "login" event
authorCheng Zhao <zcbenz@gmail.com>
Wed, 28 Oct 2015 12:13:06 +0000 (20:13 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 28 Oct 2015 12:13:06 +0000 (20:13 +0800)
atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_protocol.cc
atom/browser/login_handler.h
atom/common/native_mate_converters/content_converter.cc [new file with mode: 0644]
atom/common/native_mate_converters/content_converter.h [new file with mode: 0644]
filenames.gypi

index 436d76fb90225bf308db176027b5aaea7414f7ba..db1f9935230924597194bb2c0cb575a7fd46a795 100644 (file)
@@ -19,6 +19,7 @@
 #include "atom/browser/browser.h"
 #include "atom/browser/login_handler.h"
 #include "atom/common/native_mate_converters/callback.h"
+#include "atom/common/native_mate_converters/content_converter.h"
 #include "atom/common/native_mate_converters/file_path_converter.h"
 #include "atom/common/node_includes.h"
 #include "atom/common/options_switches.h"
@@ -241,9 +242,9 @@ void App::OnSelectCertificate(
 }
 
 void App::OnLogin(LoginHandler* login_handler) {
-  bool prevent_default =
-      Emit("login", base::Bind(&PassLoginInformation,
-                               make_scoped_refptr(login_handler)));
+  bool prevent_default = Emit(
+      "login", login_handler->request(), login_handler->auth_info(),
+      base::Bind(&PassLoginInformation, make_scoped_refptr(login_handler)));
 
   // Default behavior is to alwasy cancel the auth.
   if (!prevent_default)
index 661ab1b5cbdd2199ca4037a4406f9284a1dcd5c3..f6cc6d796557c8fa1aff02f1d64b40078c25cfd7 100644 (file)
 #include "atom/browser/net/url_request_fetch_job.h"
 #include "atom/browser/net/url_request_string_job.h"
 #include "atom/common/native_mate_converters/callback.h"
+#include "atom/common/native_mate_converters/content_converter.h"
 #include "atom/common/node_includes.h"
 #include "native_mate/dictionary.h"
 
 using content::BrowserThread;
 
-namespace mate {
-
-template<>
-struct Converter<const net::URLRequest*> {
-  static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
-                                   const net::URLRequest* val) {
-    return mate::ObjectTemplateBuilder(isolate)
-        .SetValue("method", val->method())
-        .SetValue("url", val->url().spec())
-        .SetValue("referrer", val->referrer())
-        .Build()->NewInstance();
-  }
-};
-
-}  // namespace mate
-
 namespace atom {
 
 namespace api {
index 077e4b6cf9509955fec29f938d8a724599117c7d..60e0a7a5298dfa97d11847a22626a709326625d6 100644 (file)
@@ -26,6 +26,9 @@ class LoginHandler : public content::ResourceDispatcherHostLoginDelegate {
   // Login with |username| and |password|, must be called on UI thread.
   void Login(const base::string16& username, const base::string16& password);
 
+  const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
+  const net::URLRequest* request() const { return request_; }
+
  protected:
   ~LoginHandler() override;
 
diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc
new file mode 100644 (file)
index 0000000..0ab9f27
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/common/native_mate_converters/content_converter.h"
+
+#include "native_mate/dictionary.h"
+#include "net/url_request/url_request.h"
+
+namespace mate {
+
+// static
+v8::Local<v8::Value> Converter<const net::URLRequest*>::ToV8(
+    v8::Isolate* isolate, const net::URLRequest* val) {
+  mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
+  dict.Set("method", val->method());
+  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(
+    v8::Isolate* isolate, const net::AuthChallengeInfo* val) {
+  mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
+  dict.Set("isProxy", val->is_proxy);
+  dict.Set("scheme", val->scheme);
+  dict.Set("host", val->challenger.host());
+  dict.Set("port", static_cast<uint32_t>(val->challenger.port()));
+  dict.Set("realm", val->realm);
+  return mate::ConvertToV8(isolate, dict);
+};
+
+}  // namespace mate
diff --git a/atom/common/native_mate_converters/content_converter.h b/atom/common/native_mate_converters/content_converter.h
new file mode 100644 (file)
index 0000000..0d4d5fe
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_
+#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_
+
+#include "native_mate/converter.h"
+
+namespace net {
+class AuthChallengeInfo;
+class URLRequest;
+}
+
+namespace mate {
+
+template<>
+struct Converter<const net::URLRequest*> {
+  static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
+                                   const net::URLRequest* val);
+};
+
+template<>
+struct Converter<const net::AuthChallengeInfo*> {
+  static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
+                                   const net::AuthChallengeInfo* val);
+};
+
+}  // namespace mate
+
+#endif  // ATOM_COMMON_NATIVE_MATE_CONVERTERS_CONTENT_CONVERTER_H_
index 65bf6b79a2c2c9acde4a374a8860163c396cac9c..f66485edd19d01c78d98706c35b5d3702cc4b55a 100644 (file)
       'atom/common/native_mate_converters/blink_converter.h',
       'atom/common/native_mate_converters/callback.cc',
       'atom/common/native_mate_converters/callback.h',
+      'atom/common/native_mate_converters/content_converter.cc',
+      'atom/common/native_mate_converters/content_converter.h',
       'atom/common/native_mate_converters/file_path_converter.h',
       'atom/common/native_mate_converters/gfx_converter.cc',
       'atom/common/native_mate_converters/gfx_converter.h',