| 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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" | 20 #include "chrome/browser/extensions/api/cookies/cookies_api_constants.h" |
| 21 #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" | 21 #include "chrome/browser/extensions/api/cookies/cookies_helpers.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_iterator.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/common/extensions/api/cookies.h" | 25 #include "chrome/common/extensions/api/cookies.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "extensions/browser/event_router.h" | 28 #include "extensions/browser/event_router.h" |
| 29 #include "extensions/common/error_utils.h" | 29 #include "extensions/common/error_utils.h" |
| 30 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/permissions/permissions_data.h" | 31 #include "extensions/common/permissions/permissions_data.h" |
| 32 #include "net/cookies/canonical_cookie.h" | 32 #include "net/cookies/canonical_cookie.h" |
| 33 #include "net/cookies/cookie_constants.h" | 33 #include "net/cookies/cookie_constants.h" |
| 34 #include "net/cookies/cookie_monster.h" | 34 #include "net/cookies/cookie_monster.h" |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) { | 530 if (include_incognito() && GetProfile()->HasOffTheRecordProfile()) { |
| 531 incognito_profile = GetProfile()->GetOffTheRecordProfile(); | 531 incognito_profile = GetProfile()->GetOffTheRecordProfile(); |
| 532 if (incognito_profile) | 532 if (incognito_profile) |
| 533 incognito_tab_ids.reset(new base::ListValue()); | 533 incognito_tab_ids.reset(new base::ListValue()); |
| 534 } | 534 } |
| 535 DCHECK(original_profile != incognito_profile); | 535 DCHECK(original_profile != incognito_profile); |
| 536 | 536 |
| 537 // Iterate through all browser instances, and for each browser, | 537 // Iterate through all browser instances, and for each browser, |
| 538 // add its tab IDs to either the regular or incognito tab ID list depending | 538 // add its tab IDs to either the regular or incognito tab ID list depending |
| 539 // whether the browser is regular or incognito. | 539 // whether the browser is regular or incognito. |
| 540 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 540 for (auto* browser : *BrowserList::GetInstance()) { |
| 541 Browser* browser = *it; | |
| 542 if (browser->profile() == original_profile) { | 541 if (browser->profile() == original_profile) { |
| 543 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); | 542 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); |
| 544 } else if (incognito_tab_ids.get() && | 543 } else if (incognito_tab_ids.get() && |
| 545 browser->profile() == incognito_profile) { | 544 browser->profile() == incognito_profile) { |
| 546 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get()); | 545 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get()); |
| 547 } | 546 } |
| 548 } | 547 } |
| 549 // Return a list of all cookie stores with at least one open tab. | 548 // Return a list of all cookie stores with at least one open tab. |
| 550 std::vector<linked_ptr<cookies::CookieStore>> cookie_stores; | 549 std::vector<linked_ptr<cookies::CookieStore>> cookie_stores; |
| 551 if (original_tab_ids->GetSize() > 0) { | 550 if (original_tab_ids->GetSize() > 0) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { | 582 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { |
| 584 return g_factory.Pointer(); | 583 return g_factory.Pointer(); |
| 585 } | 584 } |
| 586 | 585 |
| 587 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) { | 586 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 588 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); | 587 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); |
| 589 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 588 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 590 } | 589 } |
| 591 | 590 |
| 592 } // namespace extensions | 591 } // namespace extensions |
| OLD | NEW |