mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 722850 - Part 4: Make plugins provide the channel of the owning document when manipulating cookies. r=bsmedberg
This commit is contained in:
parent
1128fac362
commit
f4d73f416d
@ -669,6 +669,23 @@ GetPrivacyFromNPP(NPP npp, bool* aPrivate)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static already_AddRefed<nsIChannel>
|
||||
GetChannelFromNPP(NPP npp)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc = GetDocumentFromNPP(npp);
|
||||
if (!doc)
|
||||
return nullptr;
|
||||
nsCOMPtr<nsPIDOMWindow> domwindow = doc->GetWindow();
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
if (domwindow) {
|
||||
nsCOMPtr<nsIDocShell> docShell = domwindow->GetDocShell();
|
||||
if (docShell) {
|
||||
docShell->GetCurrentDocumentChannel(getter_AddRefs(channel));
|
||||
}
|
||||
}
|
||||
return channel.forget();
|
||||
}
|
||||
|
||||
static NPIdentifier
|
||||
doGetIdentifier(JSContext *cx, const NPUTF8* name)
|
||||
{
|
||||
@ -2640,7 +2657,9 @@ _getvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
|
||||
return NPERR_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
if (NS_FAILED(cookieService->GetCookieString(uri, nullptr, value)) ||
|
||||
nsCOMPtr<nsIChannel> channel = GetChannelFromNPP(instance);
|
||||
|
||||
if (NS_FAILED(cookieService->GetCookieString(uri, channel, value)) ||
|
||||
!*value) {
|
||||
return NPERR_GENERIC_ERROR;
|
||||
}
|
||||
@ -2693,10 +2712,12 @@ _setvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
|
||||
nsCOMPtr<nsIPrompt> prompt;
|
||||
nsPluginHost::GetPrompt(nullptr, getter_AddRefs(prompt));
|
||||
|
||||
nsCOMPtr<nsIChannel> channel = GetChannelFromNPP(instance);
|
||||
|
||||
char *cookie = (char*)value;
|
||||
char c = cookie[len];
|
||||
cookie[len] = '\0';
|
||||
rv = cookieService->SetCookieString(uriIn, prompt, cookie, nullptr);
|
||||
rv = cookieService->SetCookieString(uriIn, prompt, cookie, channel);
|
||||
cookie[len] = c;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return NPERR_NO_ERROR;
|
||||
|
@ -44,6 +44,9 @@ function runTests() {
|
||||
is(state1, false, "Browser returned incorrect private mode state.");
|
||||
is(state2, false, "Browser returned incorrect private mode state.");
|
||||
|
||||
pluginElement1.setCookie("foo");
|
||||
is(pluginElement1.getCookie(), "foo", "Cookie was set and retrieved correctly in public mode.");
|
||||
|
||||
// change private mode pref
|
||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
||||
var keepCurrentSession;
|
||||
@ -76,10 +79,18 @@ function runTests() {
|
||||
is(officialState1, state1, "Private mode reported and queried is inconsistent.");
|
||||
is(officialState2, state2, "Private mode reported and queried is inconsistent.");
|
||||
|
||||
// It would be nice to assert that we don't see the public cookie in private mode,
|
||||
// but the NPAPI complains when the resulting string is empty.
|
||||
// is(pluginElement1.getCookie(), "", "Public cookie was not retrieved in private mode.");
|
||||
pluginElement1.setCookie("bar");
|
||||
is(pluginElement1.getCookie(), "bar", "Cookie was set and retrieved correctly in private mode.");
|
||||
|
||||
// reset preference states
|
||||
privateBrowsing.privateBrowsingEnabled = false;
|
||||
prefs.setBoolPref("browser.privatebrowsing.keep_current_session", keepCurrentSession);
|
||||
|
||||
is(pluginElement1.getCookie(), "foo", "Private cookie was not retrieved in public mode.");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
]]>
|
||||
|
Loading…
Reference in New Issue
Block a user