Bug 932418: Don't create and throw away prompt when setting cookie string. r=bz

This commit is contained in:
Ben Kelly 2013-12-02 12:47:57 -05:00
parent 319194253b
commit 4de61de388
5 changed files with 4 additions and 51 deletions

View File

@ -27,7 +27,6 @@
#include "nsViewManager.h"
#include "nsIAtom.h"
#include "nsGkAtoms.h"
#include "nsIDOMWindow.h"
#include "nsNetCID.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsIApplicationCache.h"
@ -35,7 +34,6 @@
#include "nsIApplicationCacheChannel.h"
#include "nsIScriptSecurityManager.h"
#include "nsICookieService.h"
#include "nsIPrompt.h"
#include "nsContentUtils.h"
#include "nsNodeInfoManager.h"
#include "nsIAppShell.h"
@ -290,8 +288,7 @@ nsContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
if (aHeader == nsGkAtoms::setcookie) {
// Note: Necko already handles cookies set via the channel. We can't just
// call SetCookie on the channel because we want to do some security checks
// here and want to use the prompt associated to our current window, not
// the window where the channel was dispatched.
// here.
nsCOMPtr<nsICookieService> cookieServ =
do_GetService(NS_COOKIESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
@ -309,19 +306,13 @@ nsContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
rv = mDocument->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
NS_ENSURE_TRUE(codebaseURI, rv);
nsCOMPtr<nsIPrompt> prompt;
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mDocument->GetWindow());
if (window) {
window->GetPrompter(getter_AddRefs(prompt));
}
nsCOMPtr<nsIChannel> channel;
if (mParser) {
mParser->GetChannel(getter_AddRefs(channel));
}
rv = cookieServ->SetCookieString(codebaseURI,
prompt,
nullptr,
NS_ConvertUTF16toUTF8(aValue).get(),
channel);
if (NS_FAILED(rv)) {

View File

@ -78,7 +78,6 @@
#include "nsArrayUtils.h"
#include "nsIEffectiveTLDService.h"
#include "nsIPrompt.h"
//AHMED 12-2
#include "nsBidiUtils.h"
@ -1233,12 +1232,6 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie, ErrorResult& rv)
// not having a cookie service isn't an error
nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
if (service && mDocumentURI) {
nsCOMPtr<nsIPrompt> prompt;
nsCOMPtr<nsPIDOMWindow> window = GetWindow();
if (window) {
window->GetPrompter(getter_AddRefs(prompt));
}
// The for getting the URI matches nsNavigator::GetCookieEnabled
nsCOMPtr<nsIURI> codebaseURI;
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
@ -1251,7 +1244,7 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie, ErrorResult& rv)
}
NS_ConvertUTF16toUTF8 cookie(aCookie);
service->SetCookieString(codebaseURI, prompt, cookie.get(), mChannel);
service->SetCookieString(codebaseURI, nullptr, cookie.get(), mChannel);
}
}

View File

@ -2678,15 +2678,12 @@ _setvalueforurl(NPP instance, NPNURLVariable variable, const char *url,
if (NS_FAILED(rv))
return NPERR_GENERIC_ERROR;
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, channel);
rv = cookieService->SetCookieString(uriIn, nullptr, cookie, channel);
cookie[len] = c;
if (NS_SUCCEEDED(rv))
return NPERR_NO_ERROR;

View File

@ -422,32 +422,6 @@ nsresult nsPluginHost::UserAgent(const char **retstring)
return res;
}
nsresult nsPluginHost::GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt **aPrompt)
{
nsresult rv;
nsCOMPtr<nsIPrompt> prompt;
nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
if (wwatch) {
nsCOMPtr<nsIDOMWindow> domWindow;
if (aOwner) {
nsCOMPtr<nsIDocument> document;
aOwner->GetDocument(getter_AddRefs(document));
if (document) {
domWindow = document->GetWindow();
}
}
if (!domWindow) {
wwatch->GetWindowByName(NS_LITERAL_STRING("_content").get(), nullptr, getter_AddRefs(domWindow));
}
rv = wwatch->GetNewPrompter(domWindow, getter_AddRefs(prompt));
}
NS_IF_ADDREF(*aPrompt = prompt);
return rv;
}
nsresult nsPluginHost::GetURL(nsISupports* pluginInst,
const char* url,
const char* target,

View File

@ -164,8 +164,6 @@ public:
// that does Java)
static bool IsJavaMIMEType(const char *aType);
static nsresult GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt **aPrompt);
static nsresult PostPluginUnloadEvent(PRLibrary* aLibrary);
void PluginCrashed(nsNPAPIPlugin* plugin,