Wrap passed 'url' and 'referrer' in an 'request' object.
This commit is contained in:
parent
abd3e86fb1
commit
4bdd1b88ad
2 changed files with 17 additions and 5 deletions
|
@ -39,6 +39,19 @@ void EmitEventInUI(const std::string& event, const std::string& parameter) {
|
||||||
node::MakeCallback(g_protocol_object, "emit", arraysize(argv), argv);
|
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() {
|
net::URLRequestJobFactoryImpl* GetRequestJobFactory() {
|
||||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||||
// Get the job factory.
|
// Get the job factory.
|
||||||
|
@ -158,8 +171,7 @@ class AdapterRequestJob : public net::URLRequestJob {
|
||||||
// Call the JS handler.
|
// Call the JS handler.
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
v8::Handle<v8::Value> argv[] = {
|
v8::Handle<v8::Value> argv[] = {
|
||||||
v8::String::New(request()->url().spec().c_str()),
|
ConvertURLRequestToV8Object(request()),
|
||||||
v8::String::New(request()->referrer().c_str()),
|
|
||||||
};
|
};
|
||||||
v8::Handle<v8::Value> result = g_handlers[request()->url().scheme()]->Call(
|
v8::Handle<v8::Value> result = g_handlers[request()->url().scheme()]->Call(
|
||||||
v8::Context::GetCurrent()->Global(), arraysize(argv), argv);
|
v8::Context::GetCurrent()->Global(), arraysize(argv), argv);
|
||||||
|
|
|
@ -12,9 +12,9 @@ describe 'protocol API', ->
|
||||||
protocol.unregisterProtocol 'test1'
|
protocol.unregisterProtocol 'test1'
|
||||||
|
|
||||||
it 'calls the callback when scheme is visited', (done) ->
|
it 'calls the callback when scheme is visited', (done) ->
|
||||||
protocol.registerProtocol 'test2', (url, referrer) ->
|
protocol.registerProtocol 'test2', (request) ->
|
||||||
assert.equal url, 'test2://test2'
|
assert.equal request.url, 'test2://test2'
|
||||||
assert.equal referrer, window.location.toString()
|
assert.equal request.referrer, window.location.toString()
|
||||||
protocol.unregisterProtocol 'test2'
|
protocol.unregisterProtocol 'test2'
|
||||||
done()
|
done()
|
||||||
$.get 'test2://test2', ->
|
$.get 'test2://test2', ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue