Part 1 of fix for bug 560273 (Stop using DOM tearoffs from quickstubs) - add nsINode::GetBaseURI. r=sicking.

--HG--
extra : rebase_source : 5a07f12d9d13d92b796fd5f2cb182b069c3f87bf
This commit is contained in:
Peter Van der Beken 2010-04-19 17:40:15 +02:00
Родитель df91a46a76
Коммит ac35089169
33 изменённых файлов: 82 добавлений и 120 удалений

Просмотреть файл

@ -637,16 +637,6 @@ public:
*/
nsIContent *GetFlattenedTreeParent() const;
/**
* Get the base URI for any relative URIs within this piece of
* content. Generally, this is the document's base URI, but certain
* content carries a local base for backward compatibility, and XML
* supports setting a per-node base URI.
*
* @return the base URI
*/
virtual already_AddRefed<nsIURI> GetBaseURI() const = 0;
/**
* API to check if this is a link that's traversed in response to user input
* (e.g. a click event). Specializations for HTML/SVG/generic XML allow for

Просмотреть файл

@ -241,10 +241,17 @@ public:
* unless it's overridden by SetBaseURI, HTML <base> tags, etc.). The
* returned URI could be null if there is no document URI.
*/
nsIURI* GetBaseURI() const
nsIURI* GetDocBaseURI() const
{
return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
}
virtual already_AddRefed<nsIURI> GetBaseURI() const
{
nsCOMPtr<nsIURI> uri = GetDocBaseURI();
return uri.forget();
}
virtual nsresult SetBaseURI(nsIURI* aURI) = 0;
/**

Просмотреть файл

@ -955,6 +955,19 @@ public:
NS_NOTREACHED("SetScriptTypeID not implemented");
return NS_ERROR_NOT_IMPLEMENTED;
}
/**
* Get the base URI for any relative URIs within this piece of
* content. Generally, this is the document's base URI, but certain
* content carries a local base for backward compatibility, and XML
* supports setting a per-node base URI.
*
* @return the base URI
*/
virtual already_AddRefed<nsIURI> GetBaseURI() const = 0;
void GetBaseURI(nsAString &aURI) const;
protected:
// Override this function to create a custom slots class.

Просмотреть файл

@ -801,7 +801,7 @@ nsContentSink::ProcessStyleLink(nsIContent* aElement,
nsCOMPtr<nsIURI> url;
nsresult rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull,
mDocument->GetBaseURI());
mDocument->GetDocBaseURI());
if (NS_FAILED(rv)) {
// The URI is bad, move along, don't propagate the error (for now)
@ -910,7 +910,7 @@ nsContentSink::PrefetchHref(const nsAString &aHref,
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), aHref,
charset.IsEmpty() ? nsnull : PromiseFlatCString(charset).get(),
mDocument->GetBaseURI());
mDocument->GetDocBaseURI());
if (uri) {
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aSource);
prefetchService->PrefetchURI(uri, mDocumentURI, domNode, aExplicit);

Просмотреть файл

@ -908,7 +908,8 @@ nsContentUtils::GetOfflineAppManifest(nsIDocument *aDocument, nsIURI **aURI)
}
nsContentUtils::NewURIWithDocumentCharset(aURI, manifestSpec,
aDocument, aDocument->GetBaseURI());
aDocument,
aDocument->GetDocBaseURI());
}
/* static */

Просмотреть файл

@ -503,15 +503,20 @@ nsDOMAttribute::IsSupported(const nsAString& aFeature,
aFeature, aVersion, aReturn);
}
already_AddRefed<nsIURI>
nsDOMAttribute::GetBaseURI() const
{
nsINode *parent = GetContentInternal();
return parent ? parent->GetBaseURI() : nsnull;
}
NS_IMETHODIMP
nsDOMAttribute::GetBaseURI(nsAString &aURI)
{
aURI.Truncate();
nsresult rv = NS_OK;
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(GetContentInternal()));
if (node)
rv = node->GetBaseURI(aURI);
return rv;
nsINode::GetBaseURI(aURI);
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

@ -115,6 +115,7 @@ public:
return nsContentUtils::GetContextForEventHandlers(this, aRv);
}
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual already_AddRefed<nsIURI> GetBaseURI() const;
static void Initialize();
static void Shutdown();

Просмотреть файл

@ -498,7 +498,7 @@ nsDOMParser::Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
return NS_ERROR_UNEXPECTED;
}
baseURI = doc->GetBaseURI();
baseURI = doc->GetDocBaseURI();
documentURI = doc->GetDocumentURI();
}

Просмотреть файл

@ -2298,9 +2298,9 @@ nsDocument::StopDocumentLoad()
void
nsDocument::SetDocumentURI(nsIURI* aURI)
{
nsCOMPtr<nsIURI> oldBase = nsIDocument::GetBaseURI();
nsCOMPtr<nsIURI> oldBase = GetDocBaseURI();
mDocumentURI = NS_TryToMakeImmutable(aURI);
nsIURI* newBase = nsIDocument::GetBaseURI();
nsIURI* newBase = GetDocBaseURI();
PRBool equalBases = PR_FALSE;
if (oldBase && newBase) {
@ -4804,7 +4804,7 @@ nsDocument::LoadBindingDocument(const nsAString& aURI)
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURI,
mCharacterSet.get(),
static_cast<nsIDocument *>(this)->GetBaseURI());
GetDocBaseURI());
NS_ENSURE_SUCCESS(rv, rv);
// Figure out the right principal to use
@ -5721,12 +5721,7 @@ nsDocument::IsSupported(const nsAString& aFeature, const nsAString& aVersion,
NS_IMETHODIMP
nsDocument::GetBaseURI(nsAString &aURI)
{
nsCAutoString spec;
if (nsIDocument::GetBaseURI()) {
nsIDocument::GetBaseURI()->GetSpec(spec);
}
CopyUTF8toUTF16(spec, aURI);
nsINode::GetBaseURI(aURI);
return NS_OK;
}

Просмотреть файл

@ -202,21 +202,6 @@ nsGenericDOMDataNode::IsSupported(const nsAString& aFeature,
aFeature, aVersion, aReturn);
}
nsresult
nsGenericDOMDataNode::GetBaseURI(nsAString& aURI)
{
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsCAutoString spec;
if (baseURI) {
baseURI->GetSpec(spec);
}
CopyUTF8toUTF16(spec, aURI);
return NS_OK;
}
nsresult
nsGenericDOMDataNode::LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
@ -830,16 +815,9 @@ nsGenericDOMDataNode::GetBaseURI() const
return parent->GetBaseURI();
}
nsIURI *uri;
nsIDocument *doc = GetOwnerDoc();
if (doc) {
NS_IF_ADDREF(uri = doc->GetBaseURI());
}
else {
uri = nsnull;
}
return uri;
return doc ? doc->GetBaseURI() : nsnull;
}
PRBool

Просмотреть файл

@ -133,7 +133,6 @@ public:
nsresult IsSupported(const nsAString& aFeature,
const nsAString& aVersion,
PRBool* aReturn);
nsresult GetBaseURI(nsAString& aURI);
nsresult LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix);

Просмотреть файл

@ -588,6 +588,19 @@ nsINode::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
return rv;
}
void
nsINode::GetBaseURI(nsAString &aURI) const
{
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsCAutoString spec;
if (baseURI) {
baseURI->GetSpec(spec);
}
CopyUTF8toUTF16(spec, aURI);
}
//----------------------------------------------------------------------
PRInt32
@ -749,14 +762,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNode3Tearoff)
NS_IMETHODIMP
nsNode3Tearoff::GetBaseURI(nsAString& aURI)
{
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
nsCAutoString spec;
if (baseURI) {
baseURI->GetSpec(spec);
}
CopyUTF8toUTF16(spec, aURI);
mContent->GetBaseURI(aURI);
return NS_OK;
}
@ -3210,10 +3216,7 @@ nsGenericElement::GetBaseURI() const
GetAttr(kNameSpaceID_XML, nsGkAtoms::base, value);
if (value.IsEmpty()) {
// No xml:base, so we just use the parent's base URL
nsIURI *base = nsnull;
parentBase.swap(base);
return base;
return parentBase.forget();
}
nsCOMPtr<nsIURI> ourBase;
@ -3226,16 +3229,7 @@ nsGenericElement::GetBaseURI() const
nsIScriptSecurityManager::STANDARD);
}
nsIURI *base;
if (NS_FAILED(rv)) {
base = parentBase;
} else {
base = ourBase;
}
NS_IF_ADDREF(base);
return base;
return NS_SUCCEEDED(rv) ? ourBase.forget() : parentBase.forget();
}
PRBool

Просмотреть файл

@ -1969,7 +1969,7 @@ CreateFontStyleRule(const nsAString& aFont,
nsIPrincipal* principal = aNode->NodePrincipal();
nsIDocument* document = aNode->GetOwnerDoc();
nsIURI* docURL = document->GetDocumentURI();
nsIURI* baseURL = document->GetBaseURI();
nsIURI* baseURL = document->GetDocBaseURI();
nsresult rv = parser.ParseStyleAttribute(styleAttr, docURL, baseURL,
principal, aResult);

Просмотреть файл

@ -77,7 +77,7 @@ PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument,
nsCOMPtr<nsIURI> handlerURI;
PRBool equals = PR_FALSE;
nsIURI *docURI = aDocument->GetDocumentURI();
nsIURI *baseURI = aDocument->GetBaseURI();
nsIURI *baseURI = aDocument->GetDocBaseURI();
rv = NS_NewURI( getter_AddRefs(handlerURI), handlerURIStr, nsnull, baseURI);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIURL> handlerURL(do_QueryInterface(handlerURI));

Просмотреть файл

@ -1869,7 +1869,7 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes,
nsIDocument* doc = presContext->Document();
nsCOMPtr<nsIURI> uri;
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(
getter_AddRefs(uri), spec, doc, doc->GetBaseURI());
getter_AddRefs(uri), spec, doc, doc->GetDocBaseURI());
if (NS_SUCCEEDED(rv)) {
// Note that this should generally succeed here, due to the way
// |spec| is created. Maybe we should just add an nsStringBuffer

Просмотреть файл

@ -1395,26 +1395,6 @@ nsHTMLDocument::GetElementsByTagName(const nsAString& aTagname,
return nsDocument::GetElementsByTagName(tmp, aReturn);
}
NS_IMETHODIMP
nsHTMLDocument::GetBaseURI(nsAString &aURI)
{
aURI.Truncate();
nsIURI *uri = mDocumentBaseURI; // WEAK
if (!uri) {
uri = mDocumentURI;
}
if (uri) {
nsCAutoString spec;
uri->GetSpec(spec);
CopyUTF8toUTF16(spec, aURI);
}
return NS_OK;
}
// nsIDOM3Document interface implementation
NS_IMETHODIMP
nsHTMLDocument::GetXmlEncoding(nsAString& aXmlEncoding)

Просмотреть файл

@ -138,9 +138,6 @@ public:
// nsIDOMNode interface
NS_FORWARD_NSIDOMNODE(nsDocument::)
// nsIDOM3Node interface
NS_IMETHOD GetBaseURI(nsAString& aBaseURI);
// nsIDOMHTMLDocument interface
NS_IMETHOD GetTitle(nsAString & aTitle);
NS_IMETHOD SetTitle(const nsAString & aTitle);

Просмотреть файл

@ -1001,7 +1001,7 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI,
nsCOMPtr<nsIURI> bindingURI;
rv = NS_NewURI(getter_AddRefs(bindingURI), value,
doc->GetDocumentCharacterSet().get(),
doc->GetBaseURI());
doc->GetDocBaseURI());
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 count = aDontExtendURIs.Length();

Просмотреть файл

@ -180,7 +180,9 @@ nsXMLStylesheetPI::GetStyleSheetURL(PRBool* aIsInline)
nsCAutoString charset;
nsIDocument *document = GetOwnerDoc();
if (document) {
baseURL = mOverriddenBaseURI ? mOverriddenBaseURI.get() : document->GetBaseURI();
baseURL = mOverriddenBaseURI ?
mOverriddenBaseURI.get() :
document->GetDocBaseURI();
charset = document->GetDocumentCharacterSet();
} else {
baseURL = mOverriddenBaseURI;

Просмотреть файл

@ -751,7 +751,7 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
nsCOMPtr<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull,
mDocument->GetBaseURI());
mDocument->GetDocBaseURI());
NS_ENSURE_SUCCESS(rv, rv);
// Do security check

Просмотреть файл

@ -341,7 +341,7 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
nsCAutoString charset;
if (callingDoc) {
baseURI = callingDoc->GetBaseURI();
baseURI = callingDoc->GetDocBaseURI();
charset = callingDoc->GetDocumentCharacterSet();
}

Просмотреть файл

@ -238,7 +238,7 @@ URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode)
}
aNewDoc->Reset(channel, loadGroup);
aNewDoc->SetPrincipal(sourcePrincipal);
aNewDoc->SetBaseURI(sourceDoc->GetBaseURI());
aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI());
// Copy charset
aNewDoc->SetDocumentCharacterSetSource(

Просмотреть файл

@ -265,7 +265,7 @@ txMozillaXMLOutput::endDocument(nsresult aResult)
nsCOMPtr<nsIRefreshURI> refURI =
do_QueryInterface(win->GetDocShell());
if (refURI) {
refURI->SetupRefreshURIFromHeader(mDocument->GetBaseURI(),
refURI->SetupRefreshURIFromHeader(mDocument->GetDocBaseURI(),
mRefreshString);
}
}

Просмотреть файл

@ -9254,7 +9254,7 @@ nsDocShell::AddState(nsIVariant *aData, const nsAString& aTitle,
else {
// 2a: Resolve aURL relative to mURI
nsIURI* docBaseURI = document->GetBaseURI();
nsIURI* docBaseURI = document->GetDocBaseURI();
if (!docBaseURI)
return NS_ERROR_FAILURE;

Просмотреть файл

@ -5177,7 +5177,7 @@ nsGlobalWindow::FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
contextWindow->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc));
if (doc)
baseURL = doc->GetBaseURI();
baseURL = doc->GetDocBaseURI();
// use the base URI to build what would have been the popup's URI
nsCOMPtr<nsIIOService> ios(do_GetService(NS_IOSERVICE_CONTRACTID));
@ -8986,7 +8986,7 @@ nsGlobalWindow::BuildURIfromBase(const char *aURL, nsIURI **aBuiltURI,
sourceWindow->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
if (doc) {
baseURI = doc->GetBaseURI();
baseURI = doc->GetDocBaseURI();
charset = doc->GetDocumentCharacterSet();
}
}

Просмотреть файл

@ -921,7 +921,7 @@ nsLocation::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL)
nsCOMPtr<nsIDocument> doc;
nsresult rv = GetSourceDocument(cx, getter_AddRefs(doc));
if (doc) {
NS_IF_ADDREF(*sourceURL = doc->GetBaseURI());
*sourceURL = doc->GetBaseURI().get();
} else {
*sourceURL = nsnull;
}

Просмотреть файл

@ -434,7 +434,7 @@ nsDOMWorkerScriptLoader::RunInternal()
principal = parentDoc->NodePrincipal();
NS_ENSURE_STATE(principal);
baseURI = parentDoc->GetBaseURI();
baseURI = parentDoc->GetDocBaseURI();
}
}
else {

Просмотреть файл

@ -1387,7 +1387,7 @@ nsWindowWatcher::URIfromURL(const char *aURL,
nsCOMPtr<nsIDocument> doc;
doc = do_QueryInterface(domDoc);
if (doc) {
baseURI = doc->GetBaseURI();
baseURI = doc->GetDocBaseURI();
}
}
}

Просмотреть файл

@ -357,7 +357,7 @@ nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext)
if (!document) return NS_OK; // No doc means don't submit, see Bug 28988
// Resolve url to an absolute url
nsIURI *baseURI = document->GetBaseURI();
nsIURI *baseURI = document->GetDocBaseURI();
if (!baseURI) {
NS_ERROR("No Base URL found in Form Submit!\n");
return NS_OK; // No base URL -> exit early, see Bug 30721

Просмотреть файл

@ -3070,7 +3070,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentBase(const char* *result)
nsIDocument* doc = mContent->GetOwnerDoc();
NS_ASSERTION(doc, "Must have an owner doc");
rv = doc->GetBaseURI()->GetSpec(mDocumentBase);
rv = doc->GetDocBaseURI()->GetSpec(mDocumentBase);
}
if (NS_SUCCEEDED(rv))
*result = ToNewCString(mDocumentBase);

Просмотреть файл

@ -4194,7 +4194,7 @@ nsresult nsPluginHost::NewPluginURLStream(const nsString& aURL,
rv = owner->GetDocument(getter_AddRefs(doc));
if (NS_SUCCEEDED(rv) && doc) {
// Create an absolute URL
rv = NS_MakeAbsoluteURI(absUrl, aURL, doc->GetBaseURI());
rv = NS_MakeAbsoluteURI(absUrl, aURL, doc->GetDocBaseURI());
}
}
@ -4314,7 +4314,7 @@ nsPluginHost::DoURLLoadSecurityCheck(nsIPluginInstance *aInstance,
// Create an absolute URL for the target in case the target is relative
nsCOMPtr<nsIURI> targetURL;
NS_NewURI(getter_AddRefs(targetURL), aURL, doc->GetBaseURI());
NS_NewURI(getter_AddRefs(targetURL), aURL, doc->GetDocBaseURI());
if (!targetURL)
return NS_ERROR_FAILURE;

Просмотреть файл

@ -829,7 +829,7 @@ nsHtml5TreeOpExecutor::InitializeDocWriteParserState(nsAHtml5TreeBuilderState* a
already_AddRefed<nsIURI>
nsHtml5TreeOpExecutor::ConvertIfNotPreloadedYet(const nsAString& aURL)
{
nsIURI* base = mDocument->GetBaseURI();
nsIURI* base = mDocument->GetDocBaseURI();
const nsCString& charset = mDocument->GetDocumentCharacterSet();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, charset.get(), base);

Просмотреть файл

@ -339,7 +339,7 @@ nsPreloadURIs::PreloadURIs(const nsAutoTArray<nsSpeculativeScriptThread::Prefetc
// parsing off the main thread, this is hard to emulate. For now, just load
// the URIs using the document's base URI at the potential cost of being
// wrong and having to re-load a given relative URI later.
nsIURI *base = doc->GetBaseURI();
nsIURI *base = doc->GetDocBaseURI();
const nsCString &charset = doc->GetDocumentCharacterSet();
nsSpeculativeScriptThread::PreloadedType &alreadyPreloaded =
aScriptThread->GetPreloadedURIs();