mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1028187 - Enable IndexedDB for about:looppanel and about:loopconversation, sharing an origin r=bz
This commit is contained in:
parent
72cf0d02b8
commit
348efb07eb
@ -9,6 +9,7 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "nsDOMString.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace browser {
|
||||
@ -19,6 +20,7 @@ struct RedirEntry {
|
||||
const char* id;
|
||||
const char* url;
|
||||
uint32_t flags;
|
||||
const char* idbOriginPostfix;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -78,7 +80,9 @@ static RedirEntry kRedirMap[] = {
|
||||
#endif
|
||||
{ "home", "chrome://browser/content/abouthome/aboutHome.xhtml",
|
||||
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
||||
nsIAboutModule::ALLOW_SCRIPT },
|
||||
nsIAboutModule::ALLOW_SCRIPT |
|
||||
nsIAboutModule::ENABLE_INDEXED_DB,
|
||||
"home" },
|
||||
{ "newtab", "chrome://browser/content/newtab/newTab.xul",
|
||||
nsIAboutModule::ALLOW_SCRIPT },
|
||||
{ "permissions", "chrome://browser/content/preferences/aboutPermissions.xul",
|
||||
@ -101,11 +105,15 @@ static RedirEntry kRedirMap[] = {
|
||||
{ "loopconversation", "chrome://browser/content/loop/conversation.html",
|
||||
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
||||
nsIAboutModule::ALLOW_SCRIPT |
|
||||
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
|
||||
nsIAboutModule::HIDE_FROM_ABOUTABOUT |
|
||||
nsIAboutModule::ENABLE_INDEXED_DB },
|
||||
{ "looppanel", "chrome://browser/content/loop/panel.html",
|
||||
nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
|
||||
nsIAboutModule::ALLOW_SCRIPT |
|
||||
nsIAboutModule::HIDE_FROM_ABOUTABOUT },
|
||||
nsIAboutModule::HIDE_FROM_ABOUTABOUT |
|
||||
nsIAboutModule::ENABLE_INDEXED_DB,
|
||||
// Shares an IndexedDB origin with about:loopconversation.
|
||||
"loopconversation" },
|
||||
#endif
|
||||
};
|
||||
static const int kRedirTotal = ArrayLength(kRedirMap);
|
||||
@ -174,6 +182,29 @@ AboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AboutRedirector::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
|
||||
nsAutoCString name = GetAboutModuleName(aURI);
|
||||
|
||||
for (int i = 0; i < kRedirTotal; i++) {
|
||||
if (name.Equals(kRedirMap[i].id)) {
|
||||
const char* postfix = kRedirMap[i].idbOriginPostfix;
|
||||
if (!postfix) {
|
||||
break;
|
||||
}
|
||||
|
||||
result.AssignASCII(postfix);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
SetDOMStringToNull(result);
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
AboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **result)
|
||||
{
|
||||
|
@ -136,6 +136,13 @@ nsAboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutRedirector::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
||||
{
|
||||
SetDOMStringToNull(result);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include "mozilla/MouseEvents.h"
|
||||
#include "AudioChannelService.h"
|
||||
#include "MessageEvent.h"
|
||||
#include "nsAboutProtocolUtils.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsIFrame.h"
|
||||
@ -10511,6 +10512,39 @@ nsGlobalWindow::GetLocalStorage(nsIDOMStorage ** aLocalStorage)
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
static nsAutoCString
|
||||
GetIndexedDBOriginPostfixForAboutURI(nsIURI *aURI)
|
||||
{
|
||||
nsAutoCString result;
|
||||
|
||||
nsCOMPtr<nsIAboutModule> module;
|
||||
nsresult rv = NS_GetAboutModule(aURI, getter_AddRefs(module));
|
||||
NS_ENSURE_SUCCESS(rv, result);
|
||||
|
||||
uint32_t flags;
|
||||
rv = module->GetURIFlags(aURI, &flags);
|
||||
if (NS_FAILED(rv) || !(flags & nsIAboutModule::ENABLE_INDEXED_DB)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsAutoString postfix;
|
||||
rv = module->GetIndexedDBOriginPostfix(aURI, postfix);
|
||||
if (NS_FAILED(rv) || DOMStringIsNull(postfix)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI);
|
||||
NS_ENSURE_TRUE(origin, result);
|
||||
|
||||
nsAutoCString scheme;
|
||||
rv = origin->GetScheme(scheme);
|
||||
NS_ENSURE_SUCCESS(rv, result);
|
||||
|
||||
result = scheme + NS_LITERAL_CSTRING(":") + NS_ConvertUTF16toUTF8(postfix);
|
||||
ToLowerCase(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
indexedDB::IDBFactory*
|
||||
nsGlobalWindow::GetIndexedDB(ErrorResult& aError)
|
||||
{
|
||||
@ -10522,6 +10556,8 @@ nsGlobalWindow::GetIndexedDB(ErrorResult& aError)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCString origin;
|
||||
|
||||
if (!IsChromeWindow()) {
|
||||
// Whitelist about:home, since it doesn't have a base domain it would not
|
||||
// pass the thirdPartyUtil check, though it should be able to use
|
||||
@ -10531,11 +10567,15 @@ nsGlobalWindow::GetIndexedDB(ErrorResult& aError)
|
||||
if (principal) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
principal->GetURI(getter_AddRefs(uri));
|
||||
bool isAbout = false;
|
||||
if (uri && NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
|
||||
nsAutoCString path;
|
||||
skipThirdPartyCheck = NS_SUCCEEDED(uri->GetPath(path)) &&
|
||||
path.EqualsLiteral("home");
|
||||
|
||||
if (uri) {
|
||||
bool isAbout = false;
|
||||
nsresult rv = uri->SchemeIs("about", &isAbout);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && isAbout) {
|
||||
origin = GetIndexedDBOriginPostfixForAboutURI(uri);
|
||||
skipThirdPartyCheck = !origin.IsEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10559,7 +10599,7 @@ nsGlobalWindow::GetIndexedDB(ErrorResult& aError)
|
||||
}
|
||||
|
||||
// This may be null if being created from a file.
|
||||
aError = indexedDB::IDBFactory::Create(this, nullptr,
|
||||
aError = indexedDB::IDBFactory::Create(this, origin, origin, nullptr,
|
||||
getter_AddRefs(mIndexedDB));
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "nsAboutBlank.h"
|
||||
#include "nsStringStream.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAboutBlank, nsIAboutModule)
|
||||
@ -36,6 +37,13 @@ nsAboutBlank::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutBlank::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
||||
{
|
||||
SetDOMStringToNull(result);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAboutBlank::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "nsAboutBloat.h"
|
||||
#include "nsStringStream.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
@ -124,6 +125,13 @@ nsAboutBloat::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutBloat::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
||||
{
|
||||
SetDOMStringToNull(result);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAboutBloat::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "nsEscape.h"
|
||||
#include "nsAboutProtocolUtils.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "nsDOMString.h"
|
||||
|
||||
#include "nsICacheStorageService.h"
|
||||
#include "nsICacheStorage.h"
|
||||
@ -485,6 +486,13 @@ nsAboutCache::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutCache::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
||||
{
|
||||
SetDOMStringToNull(result);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsAboutCache::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "nsAboutCache.h"
|
||||
#include "nsICacheStorage.h"
|
||||
#include "CacheObserver.h"
|
||||
#include "nsDOMString.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prprf.h"
|
||||
#include "nsEscape.h"
|
||||
@ -108,6 +109,13 @@ nsAboutCacheEntry::GetURIFlags(nsIURI *aURI, uint32_t *result)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutCacheEntry::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result)
|
||||
{
|
||||
SetDOMStringToNull(result);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsAboutCacheEntry
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
interface nsIURI;
|
||||
interface nsIChannel;
|
||||
|
||||
[scriptable, uuid(9575693c-60d9-4332-b6b8-6c29289339cb)]
|
||||
[scriptable, uuid(1d5992c3-28b0-4ec1-9dbb-f5fde7f72199)]
|
||||
interface nsIAboutModule : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -41,12 +41,24 @@ interface nsIAboutModule : nsISupports
|
||||
*/
|
||||
const unsigned long HIDE_FROM_ABOUTABOUT = (1 << 2);
|
||||
|
||||
/**
|
||||
* A flag that indicates whether this about: URI wants Indexed DB enabled.
|
||||
*/
|
||||
const unsigned long ENABLE_INDEXED_DB = (1 << 3);
|
||||
|
||||
/**
|
||||
* A method to get the flags that apply to a given about: URI. The URI
|
||||
* passed in is guaranteed to be one of the URIs that this module
|
||||
* registered to deal with.
|
||||
*/
|
||||
unsigned long getURIFlags(in nsIURI aURI);
|
||||
|
||||
/**
|
||||
* Returns the Indexed DB origin's postfix used for the given about: URI.
|
||||
* If the postfix returned is null then the URI's path (e.g. "home" for
|
||||
* about:home) will be used to construct the origin.
|
||||
*/
|
||||
DOMString getIndexedDBOriginPostfix(in nsIURI aURI);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
Loading…
Reference in New Issue
Block a user