]> khamidou — GitHub mirrors - electron.git/commitdiff
Wrap passed 'url' and 'referrer' in an 'request' object.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 29 Aug 2013 13:12:48 +0000 (21:12 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 29 Aug 2013 13:12:48 +0000 (21:12 +0800)
browser/api/atom_api_protocol.cc
spec/api/protocol.coffee

index 843e15342cd6e8347ba8b05a79ecc48ff945eac7..258081251902b4772ae791b95fcd65a78f8560cf 100644 (file)
@@ -39,6 +39,19 @@ void EmitEventInUI(const std::string& event, const std::string& parameter) {
   node::MakeCallback(g_protocol_object, "emit", arraysize(argv), argv);
 }
 
+// Convert the URLRequest object to V8 object.
+v8::Handle<v8::Object> ConvertURLRequestToV8Object(
+    const net::URLRequest* request) {
+  v8::Local<v8::Object> obj = v8::Object::New();
+  obj->Set(v8::String::New("method"),
+           v8::String::New(request->method().c_str()));
+  obj->Set(v8::String::New("url"),
+           v8::String::New(request->url().spec().c_str()));
+  obj->Set(v8::String::New("referrer"),
+           v8::String::New(request->referrer().c_str()));
+  return obj;
+}
+
 net::URLRequestJobFactoryImpl* GetRequestJobFactory() {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
   // Get the job factory.
@@ -158,8 +171,7 @@ class AdapterRequestJob : public net::URLRequestJob {
     // Call the JS handler.
     v8::HandleScope scope;
     v8::Handle<v8::Value> argv[] = {
-      v8::String::New(request()->url().spec().c_str()),
-      v8::String::New(request()->referrer().c_str()),
+      ConvertURLRequestToV8Object(request()),
     };
     v8::Handle<v8::Value> result = g_handlers[request()->url().scheme()]->Call(
         v8::Context::GetCurrent()->Global(), arraysize(argv), argv);
index 222846f81067958371d461f053da5ab4b72c9380..ab90cb9018a25bf8a40fa013391dc24528d5ebb6 100644 (file)
@@ -12,9 +12,9 @@ describe 'protocol API', ->
       protocol.unregisterProtocol 'test1'
 
     it 'calls the callback when scheme is visited', (done) ->
-      protocol.registerProtocol 'test2', (url, referrer) ->
-        assert.equal url, 'test2://test2'
-        assert.equal referrer, window.location.toString()
+      protocol.registerProtocol 'test2', (request) ->
+        assert.equal request.url, 'test2://test2'
+        assert.equal request.referrer, window.location.toString()
         protocol.unregisterProtocol 'test2'
         done()
       $.get 'test2://test2', ->