OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Implements the Chrome Extensions Cookies API. | 5 // Implements the Chrome Extensions Cookies API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" | 7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 18 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
19 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 19 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" |
20 #include "chrome/browser/extensions/event_router.h" | 20 #include "chrome/browser/extensions/event_router.h" |
21 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_iterator.h" |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/extensions/api/cookies.h" | 26 #include "chrome/common/extensions/api/cookies.h" |
27 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "extensions/common/error_utils.h" | 30 #include "extensions/common/error_utils.h" |
31 #include "net/cookies/canonical_cookie.h" | 31 #include "net/cookies/canonical_cookie.h" |
32 #include "net/cookies/cookie_monster.h" | 32 #include "net/cookies/cookie_monster.h" |
33 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
34 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 if (include_incognito() && profile()->HasOffTheRecordProfile()) { | 506 if (include_incognito() && profile()->HasOffTheRecordProfile()) { |
507 incognito_profile = profile()->GetOffTheRecordProfile(); | 507 incognito_profile = profile()->GetOffTheRecordProfile(); |
508 if (incognito_profile) | 508 if (incognito_profile) |
509 incognito_tab_ids.reset(new ListValue()); | 509 incognito_tab_ids.reset(new ListValue()); |
510 } | 510 } |
511 DCHECK(original_profile != incognito_profile); | 511 DCHECK(original_profile != incognito_profile); |
512 | 512 |
513 // Iterate through all browser instances, and for each browser, | 513 // Iterate through all browser instances, and for each browser, |
514 // add its tab IDs to either the regular or incognito tab ID list depending | 514 // add its tab IDs to either the regular or incognito tab ID list depending |
515 // whether the browser is regular or incognito. | 515 // whether the browser is regular or incognito. |
516 for (BrowserList::const_iterator iter = BrowserList::begin(); | 516 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
517 iter != BrowserList::end(); ++iter) { | 517 Browser* browser = *it; |
518 Browser* browser = *iter; | |
519 if (browser->profile() == original_profile) { | 518 if (browser->profile() == original_profile) { |
520 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); | 519 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); |
521 } else if (incognito_tab_ids.get() && | 520 } else if (incognito_tab_ids.get() && |
522 browser->profile() == incognito_profile) { | 521 browser->profile() == incognito_profile) { |
523 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get()); | 522 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get()); |
524 } | 523 } |
525 } | 524 } |
526 // Return a list of all cookie stores with at least one open tab. | 525 // Return a list of all cookie stores with at least one open tab. |
527 std::vector<linked_ptr<CookieStore> > cookie_stores; | 526 std::vector<linked_ptr<CookieStore> > cookie_stores; |
528 if (original_tab_ids->GetSize() > 0) { | 527 if (original_tab_ids->GetSize() > 0) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 return &g_factory.Get(); | 564 return &g_factory.Get(); |
566 } | 565 } |
567 | 566 |
568 void CookiesAPI::OnListenerAdded( | 567 void CookiesAPI::OnListenerAdded( |
569 const extensions::EventListenerInfo& details) { | 568 const extensions::EventListenerInfo& details) { |
570 cookies_event_router_.reset(new CookiesEventRouter(profile_)); | 569 cookies_event_router_.reset(new CookiesEventRouter(profile_)); |
571 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 570 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
572 } | 571 } |
573 | 572 |
574 } // namespace extensions | 573 } // namespace extensions |
OLD | NEW |