зеркало из https://github.com/mozilla/gecko-dev.git
Bug 783408 - 1/4 - Add a method in nsICookieManager2 that returns app's cookies. r=jduell sr=mconnor
This commit is contained in:
Родитель
8bcc76028b
Коммит
1034c194b7
|
@ -3717,6 +3717,65 @@ nsCookieService::GetCookiesFromHost(const nsACString &aHost,
|
|||
return NS_NewArrayEnumerator(aEnumerator, cookieList);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* This structure is used as a in/out parameter when enumerating the cookies
|
||||
* for an app.
|
||||
* It will contain the app id and onlyBrowserElement flag information as input
|
||||
* and will contain the array of matching cookies as output.
|
||||
*/
|
||||
struct GetCookiesForAppStruct {
|
||||
uint32_t appId;
|
||||
bool onlyBrowserElement;
|
||||
nsCOMArray<nsICookie> cookies;
|
||||
|
||||
GetCookiesForAppStruct() MOZ_DELETE;
|
||||
GetCookiesForAppStruct(uint32_t aAppId, bool aOnlyBrowserElement)
|
||||
: appId(aAppId)
|
||||
, onlyBrowserElement(aOnlyBrowserElement)
|
||||
{}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
/* static */ PLDHashOperator
|
||||
nsCookieService::GetCookiesForApp(nsCookieEntry* entry, void* arg)
|
||||
{
|
||||
GetCookiesForAppStruct* data = static_cast<GetCookiesForAppStruct*>(arg);
|
||||
|
||||
if (entry->mAppId != data->appId ||
|
||||
(data->onlyBrowserElement && !entry->mInBrowserElement)) {
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
const nsCookieEntry::ArrayType& cookies = entry->GetCookies();
|
||||
|
||||
for (nsCookieEntry::IndexType i = 0; i < cookies.Length(); ++i) {
|
||||
data->cookies.AppendObject(cookies[i]);
|
||||
}
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieService::GetCookiesForApp(uint32_t aAppId, bool aOnlyBrowserElement,
|
||||
nsISimpleEnumerator** aEnumerator)
|
||||
{
|
||||
if (!mDBState) {
|
||||
NS_WARNING("No DBState! Profile already closed?");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(aAppId != NECKO_NO_APP_ID && aAppId != NECKO_UNKNOWN_APP_ID,
|
||||
NS_ERROR_INVALID_ARG);
|
||||
|
||||
GetCookiesForAppStruct data(aAppId, aOnlyBrowserElement);
|
||||
mDBState->hostTable.EnumerateEntries(GetCookiesForApp, &data);
|
||||
|
||||
return NS_NewArrayEnumerator(aEnumerator, data.cookies);
|
||||
}
|
||||
|
||||
// find an exact cookie specified by host, name, and path that hasn't expired.
|
||||
bool
|
||||
nsCookieService::FindCookie(const nsCookieKey &aKey,
|
||||
|
|
|
@ -283,6 +283,12 @@ class nsCookieService : public nsICookieService
|
|||
void NotifyPurged(nsICookie2* aCookie);
|
||||
already_AddRefed<nsIArray> CreatePurgeList(nsICookie2* aCookie);
|
||||
|
||||
/**
|
||||
* This method is used to iterate the cookie hash table and select the ones
|
||||
* that are part of a specific app.
|
||||
*/
|
||||
static PLDHashOperator GetCookiesForApp(nsCookieEntry* entry, void* arg);
|
||||
|
||||
protected:
|
||||
// cached members.
|
||||
nsCOMPtr<nsIObserverService> mObserverService;
|
||||
|
|
|
@ -12,7 +12,7 @@ interface nsIFile;
|
|||
* Additions to the frozen nsICookieManager
|
||||
*/
|
||||
|
||||
[scriptable, uuid(94628d1d-8b31-4baa-b474-9c872c440f90)]
|
||||
[scriptable, uuid(c0058e11-8ac3-4349-b87c-7332d0bb542c)]
|
||||
interface nsICookieManager2 : nsICookieManager
|
||||
{
|
||||
/**
|
||||
|
@ -107,4 +107,16 @@ interface nsICookieManager2 : nsICookieManager
|
|||
* @param aCookieFile the file to import, usually cookies.txt
|
||||
*/
|
||||
void importCookies(in nsIFile aCookieFile);
|
||||
|
||||
/**
|
||||
* Returns an enumerator of all cookies that are related to a specific app.
|
||||
*
|
||||
* If the onlyBrowserELement parameter is set to true, only cookies part of
|
||||
* a browser element inside the app will be returned. If set to false, all
|
||||
* cookies will be returned, regardless of their browserElement flag.
|
||||
*
|
||||
* This method assumes that appId is a valid app id. It should not be a
|
||||
* special value like UNKNOWN_APP_ID or NO_APP_ID.
|
||||
*/
|
||||
nsISimpleEnumerator getCookiesForApp(in unsigned long appId, in boolean onlyBrowserElement);
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче