| 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 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 break; | 75 break; |
| 76 | 76 |
| 77 default: | 77 default: |
| 78 NOTREACHED(); | 78 NOTREACHED(); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void CookiesEventRouter::CookieChanged( | 82 void CookiesEventRouter::CookieChanged( |
| 83 Profile* profile, | 83 Profile* profile, |
| 84 ChromeCookieDetails* details) { | 84 ChromeCookieDetails* details) { |
| 85 scoped_ptr<ListValue> args(new ListValue()); | 85 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 86 DictionaryValue* dict = new DictionaryValue(); | 86 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 87 dict->SetBoolean(keys::kRemovedKey, details->removed); | 87 dict->SetBoolean(keys::kRemovedKey, details->removed); |
| 88 | 88 |
| 89 scoped_ptr<Cookie> cookie( | 89 scoped_ptr<Cookie> cookie( |
| 90 cookies_helpers::CreateCookie(*details->cookie, | 90 cookies_helpers::CreateCookie(*details->cookie, |
| 91 cookies_helpers::GetStoreIdFromProfile(profile_))); | 91 cookies_helpers::GetStoreIdFromProfile(profile_))); |
| 92 dict->Set(keys::kCookieKey, cookie->ToValue().release()); | 92 dict->Set(keys::kCookieKey, cookie->ToValue().release()); |
| 93 | 93 |
| 94 // Map the internal cause to an external string. | 94 // Map the internal cause to an external string. |
| 95 std::string cause; | 95 std::string cause; |
| 96 switch (details->cause) { | 96 switch (details->cause) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 122 args->Append(dict); | 122 args->Append(dict); |
| 123 | 123 |
| 124 GURL cookie_domain = | 124 GURL cookie_domain = |
| 125 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); | 125 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); |
| 126 DispatchEvent(profile, keys::kOnChanged, args.Pass(), cookie_domain); | 126 DispatchEvent(profile, keys::kOnChanged, args.Pass(), cookie_domain); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void CookiesEventRouter::DispatchEvent( | 129 void CookiesEventRouter::DispatchEvent( |
| 130 Profile* profile, | 130 Profile* profile, |
| 131 const std::string& event_name, | 131 const std::string& event_name, |
| 132 scoped_ptr<ListValue> event_args, | 132 scoped_ptr<base::ListValue> event_args, |
| 133 GURL& cookie_domain) { | 133 GURL& cookie_domain) { |
| 134 EventRouter* router = profile ? | 134 EventRouter* router = profile ? |
| 135 extensions::ExtensionSystem::Get(profile)->event_router() : NULL; | 135 extensions::ExtensionSystem::Get(profile)->event_router() : NULL; |
| 136 if (!router) | 136 if (!router) |
| 137 return; | 137 return; |
| 138 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); | 138 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); |
| 139 event->restrict_to_profile = profile; | 139 event->restrict_to_profile = profile; |
| 140 event->event_url = cookie_domain; | 140 event->event_url = cookie_domain; |
| 141 router->BroadcastEvent(event.Pass()); | 141 router->BroadcastEvent(event.Pass()); |
| 142 } | 142 } |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 504 } |
| 505 | 505 |
| 506 void CookiesRemoveFunction::RespondOnUIThread() { | 506 void CookiesRemoveFunction::RespondOnUIThread() { |
| 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 508 SendResponse(true); | 508 SendResponse(true); |
| 509 } | 509 } |
| 510 | 510 |
| 511 bool CookiesGetAllCookieStoresFunction::RunImpl() { | 511 bool CookiesGetAllCookieStoresFunction::RunImpl() { |
| 512 Profile* original_profile = profile(); | 512 Profile* original_profile = profile(); |
| 513 DCHECK(original_profile); | 513 DCHECK(original_profile); |
| 514 scoped_ptr<ListValue> original_tab_ids(new ListValue()); | 514 scoped_ptr<base::ListValue> original_tab_ids(new base::ListValue()); |
| 515 Profile* incognito_profile = NULL; | 515 Profile* incognito_profile = NULL; |
| 516 scoped_ptr<ListValue> incognito_tab_ids; | 516 scoped_ptr<base::ListValue> incognito_tab_ids; |
| 517 if (include_incognito() && profile()->HasOffTheRecordProfile()) { | 517 if (include_incognito() && profile()->HasOffTheRecordProfile()) { |
| 518 incognito_profile = profile()->GetOffTheRecordProfile(); | 518 incognito_profile = profile()->GetOffTheRecordProfile(); |
| 519 if (incognito_profile) | 519 if (incognito_profile) |
| 520 incognito_tab_ids.reset(new ListValue()); | 520 incognito_tab_ids.reset(new base::ListValue()); |
| 521 } | 521 } |
| 522 DCHECK(original_profile != incognito_profile); | 522 DCHECK(original_profile != incognito_profile); |
| 523 | 523 |
| 524 // Iterate through all browser instances, and for each browser, | 524 // Iterate through all browser instances, and for each browser, |
| 525 // add its tab IDs to either the regular or incognito tab ID list depending | 525 // add its tab IDs to either the regular or incognito tab ID list depending |
| 526 // whether the browser is regular or incognito. | 526 // whether the browser is regular or incognito. |
| 527 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 527 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 528 Browser* browser = *it; | 528 Browser* browser = *it; |
| 529 if (browser->profile() == original_profile) { | 529 if (browser->profile() == original_profile) { |
| 530 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); | 530 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 return &g_factory.Get(); | 575 return &g_factory.Get(); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void CookiesAPI::OnListenerAdded( | 578 void CookiesAPI::OnListenerAdded( |
| 579 const extensions::EventListenerInfo& details) { | 579 const extensions::EventListenerInfo& details) { |
| 580 cookies_event_router_.reset(new CookiesEventRouter(profile_)); | 580 cookies_event_router_.reset(new CookiesEventRouter(profile_)); |
| 581 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 581 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace extensions | 584 } // namespace extensions |
| OLD | NEW |