@@ -143,7 +143,6 @@ Window::Window(int id,
143
143
// Set ID for Shell
144
144
shell_->set_id (id);
145
145
146
- result_.reset (new base::ListValue);
147
146
}
148
147
149
148
Window::~Window () {
@@ -281,88 +280,102 @@ void Window::CookieGet(const base::ListValue& arguments, bool get_all) {
281
280
const base::DictionaryValue* details = NULL ;
282
281
std::string url;
283
282
284
- store_context_ = context_getter;
283
+ CookieAPIContext* api_context = new CookieAPIContext;
284
+ api_context->store_context_ = context_getter;
285
+
285
286
arguments.GetDictionary (0 , &details);
286
287
if (details) {
287
- details_.reset (details->DeepCopyWithoutEmptyChildren ());
288
+ api_context-> details_ .reset (details->DeepCopyWithoutEmptyChildren ());
288
289
details->GetString (" url" , &url);
289
290
}
290
- url_ = GURL (url);
291
+
292
+ api_context->url_ = GURL (url);
293
+ api_context->result_ .reset (new base::ListValue);
291
294
292
295
if (get_all) {
293
296
bool rv = BrowserThread::PostTask (
294
297
BrowserThread::IO, FROM_HERE,
295
- base::Bind (&Window::GetAllCookieOnIOThread, base::Unretained (this )));
298
+ base::Bind (&Window::GetAllCookieOnIOThread,
299
+ base::Unretained (this ),
300
+ make_scoped_refptr (api_context)));
296
301
DCHECK (rv);
297
302
}else {
298
303
bool rv = BrowserThread::PostTask (
299
304
BrowserThread::IO, FROM_HERE,
300
- base::Bind (&Window::GetCookieOnIOThread, base::Unretained (this )));
305
+ base::Bind (&Window::GetCookieOnIOThread,
306
+ base::Unretained (this ),
307
+ make_scoped_refptr (api_context)));
301
308
DCHECK (rv);
302
309
}
303
310
}
304
311
305
- void Window::GetAllCookieOnIOThread () {
312
+ void Window::GetAllCookieOnIOThread (CookieAPIContext* api_context ) {
306
313
DCHECK (BrowserThread::CurrentlyOn (BrowserThread::IO));
307
314
net::CookieStore* cookie_store =
308
- store_context_->GetURLRequestContext ()->cookie_store ();
315
+ api_context-> store_context_ ->GetURLRequestContext ()->cookie_store ();
309
316
GetCookieListFromStore (
310
- cookie_store, url_,
311
- base::Bind (&Window::GetAllCookieCallback, base::Unretained (this )));
317
+ cookie_store, api_context->url_ ,
318
+ base::Bind (&Window::GetAllCookieCallback, base::Unretained (this ),
319
+ make_scoped_refptr (api_context)));
312
320
}
313
321
314
- void Window::GetCookieOnIOThread () {
322
+ void Window::GetCookieOnIOThread (CookieAPIContext* api_context ) {
315
323
DCHECK (BrowserThread::CurrentlyOn (BrowserThread::IO));
316
324
net::CookieStore* cookie_store =
317
- store_context_->GetURLRequestContext ()->cookie_store ();
325
+ api_context-> store_context_ ->GetURLRequestContext ()->cookie_store ();
318
326
GetCookieListFromStore (
319
- cookie_store, url_,
320
- base::Bind (&Window::GetCookieCallback, base::Unretained (this )));
327
+ cookie_store, api_context->url_ ,
328
+ base::Bind (&Window::GetCookieCallback, base::Unretained (this ),
329
+ make_scoped_refptr (api_context)));
321
330
}
322
331
323
- void Window::GetAllCookieCallback (const net::CookieList& cookie_list) {
332
+ void Window::GetAllCookieCallback (CookieAPIContext* api_context,
333
+ const net::CookieList& cookie_list) {
324
334
net::CookieList::const_iterator it;
325
- result_->Clear ();
335
+ api_context-> result_ ->Clear ();
326
336
for (it = cookie_list.begin (); it != cookie_list.end (); ++it) {
327
- if (MatchesCookie (details_.get (), *it)) {
328
- result_->Append (PopulateCookieObject (*it));
337
+ if (MatchesCookie (api_context-> details_ .get (), *it)) {
338
+ api_context-> result_ ->Append (PopulateCookieObject (*it));
329
339
}
330
340
}
331
341
332
342
bool rv = BrowserThread::PostTask (
333
343
BrowserThread::UI, FROM_HERE,
334
- base::Bind (&Window::RespondOnUIThread, base::Unretained (this )));
344
+ base::Bind (&Window::RespondOnUIThread, base::Unretained (this ),
345
+ make_scoped_refptr (api_context)));
335
346
DCHECK (rv);
336
347
}
337
348
338
- void Window::GetCookieCallback (const net::CookieList& cookie_list) {
349
+ void Window::GetCookieCallback (CookieAPIContext* api_context,
350
+ const net::CookieList& cookie_list) {
339
351
net::CookieList::const_iterator it;
340
352
std::string name;
341
- details_->GetString (" name" , &name);
353
+ api_context-> details_ ->GetString (" name" , &name);
342
354
343
- result_->Clear ();
355
+ api_context-> result_ ->Clear ();
344
356
345
357
for (it = cookie_list.begin (); it != cookie_list.end (); ++it) {
346
358
// Return the first matching cookie. Relies on the fact that the
347
359
// CookieMonster returns them in canonical order (longest path, then
348
360
// earliest creation time).
349
361
350
362
if (it->Name () == name) {
351
- result_->Append (PopulateCookieObject (*it));
363
+ api_context-> result_ ->Append (PopulateCookieObject (*it));
352
364
break ;
353
365
}
354
366
}
355
367
356
368
bool rv = BrowserThread::PostTask (
357
369
BrowserThread::UI, FROM_HERE,
358
- base::Bind (&Window::RespondOnUIThread, base::Unretained (this )));
370
+ base::Bind (&Window::RespondOnUIThread, base::Unretained (this ),
371
+ make_scoped_refptr (api_context)));
359
372
DCHECK (rv);
360
373
}
361
374
362
- void Window::RespondOnUIThread () {
375
+ void Window::RespondOnUIThread (CookieAPIContext* api_context ) {
363
376
DCHECK (BrowserThread::CurrentlyOn (BrowserThread::UI));
364
377
base::ListValue ret;
365
- ret.Append (result_.release ());
378
+ ret.Append (api_context-> result_ .release ());
366
379
dispatcher_host ()->SendEvent (this , " __nw_gotcookie" , ret);
367
380
}
368
381
0 commit comments