Skip to content

Commit 3890361

Browse files
committed
Cookie API: Use req id to match call and callback
1 parent b869b13 commit 3890361

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/api/window/window.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "content/nw/src/api/window/window.h"
2222

2323
#include "base/values.h"
24+
#include "base/strings/stringprintf.h"
2425
#include "base/strings/utf_string_conversions.h"
2526
#include "content/nw/src/api/dispatcher_host.h"
2627
#include "content/nw/src/api/menu/menu.h"
@@ -282,8 +283,8 @@ void Window::CookieGet(const base::ListValue& arguments, bool get_all) {
282283

283284
CookieAPIContext* api_context = new CookieAPIContext;
284285
api_context->store_context_ = context_getter;
285-
286-
arguments.GetDictionary(0, &details);
286+
arguments.GetInteger(0, &api_context->req_id_);
287+
arguments.GetDictionary(1, &details);
287288
if (details) {
288289
api_context->details_.reset(details->DeepCopyWithoutEmptyChildren());
289290
details->GetString("url", &url);
@@ -376,7 +377,7 @@ void Window::RespondOnUIThread(CookieAPIContext* api_context) {
376377
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
377378
base::ListValue ret;
378379
ret.Append(api_context->result_.release());
379-
dispatcher_host()->SendEvent(this, "__nw_gotcookie", ret);
380+
dispatcher_host()->SendEvent(this, base::StringPrintf("__nw_gotcookie%d", api_context->req_id_), ret);
380381
}
381382

382383
} // namespace api

src/api/window/window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CookieAPIContext : public base::RefCountedThreadSafe<CookieAPIContext> {
4242
scoped_ptr<base::DictionaryValue> details_;
4343
scoped_ptr<base::ListValue> result_;
4444
GURL url_;
45+
int req_id_;
4546
};
4647

4748

src/api/window_bindings.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ function Window(routing_id, nobind) {
2222

2323
var that = this;
2424
this.cookies = {
25+
req_id : 0,
2526
get : function(details, cb) {
26-
CallObjectMethod(that, 'CookieGet', [ details ]);
27+
this.req_id++;
2728
if (typeof cb == 'function') {
28-
that.once('__nw_gotcookie', function(cookie) {
29+
that.once('__nw_gotcookie' + this.req_id, function(cookie) {
2930
if (cookie.length > 0)
3031
cb(cookie[0]);
3132
else
3233
cb(null);
3334
});
3435
}
36+
CallObjectMethod(that, 'CookieGet', [ this.req_id, details ]);
3537
},
3638
getAll : function(details, cb) {
37-
CallObjectMethod(that, 'CookieGetAll', [ details ]);
39+
this.req_id++;
3840
if (typeof cb == 'function') {
39-
that.once('__nw_gotcookie', function(cookie) {
41+
that.once('__nw_gotcookie' + this.req_id, function(cookie) {
4042
cb(cookie);
4143
});
4244
}
45+
CallObjectMethod(that, 'CookieGetAll', [ this.req_id, details ]);
4346
}
4447
}
4548
}

0 commit comments

Comments
 (0)