2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-11-02 07:33:49 +00:00
|
|
|
|
|
|
|
#include "txURIUtils.h"
|
|
|
|
#include "nsNetUtil.h"
|
2005-11-02 07:38:05 +00:00
|
|
|
#include "nsIDocument.h"
|
2005-11-02 07:38:08 +00:00
|
|
|
#include "nsIPrincipal.h"
|
2014-07-10 06:56:37 +00:00
|
|
|
#include "mozilla/LoadInfo.h"
|
|
|
|
|
|
|
|
using mozilla::LoadInfo;
|
2005-11-02 07:33:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* URIUtils
|
|
|
|
* A set of utilities for handling URIs
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves the given href argument, using the given documentBase
|
|
|
|
* if necessary.
|
|
|
|
* The new resolved href will be appended to the given dest String
|
|
|
|
**/
|
2005-11-02 07:39:22 +00:00
|
|
|
void URIUtils::resolveHref(const nsAString& href, const nsAString& base,
|
|
|
|
nsAString& dest) {
|
2005-11-02 07:38:52 +00:00
|
|
|
if (base.IsEmpty()) {
|
|
|
|
dest.Append(href);
|
2005-11-02 07:33:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-11-02 07:38:52 +00:00
|
|
|
if (href.IsEmpty()) {
|
|
|
|
dest.Append(base);
|
2005-11-02 07:33:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> pURL;
|
2005-11-02 07:39:22 +00:00
|
|
|
nsAutoString resultHref;
|
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz.
Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz.
Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz.
Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst.
Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
2005-11-02 07:38:17 +00:00
|
|
|
nsresult result = NS_NewURI(getter_AddRefs(pURL), base);
|
2005-11-02 07:33:49 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz.
Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz.
Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz.
Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst.
Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
2005-11-02 07:38:17 +00:00
|
|
|
NS_MakeAbsoluteURI(resultHref, href, pURL);
|
2005-11-02 07:38:52 +00:00
|
|
|
dest.Append(resultHref);
|
2005-11-02 07:33:49 +00:00
|
|
|
}
|
|
|
|
} //-- resolveHref
|
|
|
|
|
2005-11-02 07:40:49 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode)
|
|
|
|
{
|
2006-02-02 20:02:34 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aSourceNode);
|
|
|
|
if (!node) {
|
2012-07-30 14:20:58 +00:00
|
|
|
// XXXbz passing nullptr as the first arg to Reset is illegal
|
|
|
|
aNewDoc->Reset(nullptr, nullptr);
|
2005-11-02 07:40:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
nsCOMPtr<nsIDocument> sourceDoc = node->OwnerDoc();
|
2006-04-27 18:21:11 +00:00
|
|
|
nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal();
|
2006-01-10 21:58:25 +00:00
|
|
|
|
2006-01-04 06:38:46 +00:00
|
|
|
// Copy the channel and loadgroup from the source document.
|
2005-11-02 07:41:29 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();
|
2006-01-10 21:58:25 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel();
|
|
|
|
if (!channel) {
|
|
|
|
// Need to synthesize one
|
2014-09-21 16:39:41 +00:00
|
|
|
nsresult rv = NS_NewChannel(getter_AddRefs(channel),
|
2006-01-10 21:58:25 +00:00
|
|
|
sourceDoc->GetDocumentURI(),
|
2014-09-21 16:39:41 +00:00
|
|
|
sourceDoc,
|
|
|
|
nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER,
|
|
|
|
loadGroup);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2006-01-10 21:58:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aNewDoc->Reset(channel, loadGroup);
|
|
|
|
aNewDoc->SetPrincipal(sourcePrincipal);
|
2010-04-19 15:40:15 +00:00
|
|
|
aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI());
|
2005-11-02 07:40:49 +00:00
|
|
|
|
2005-11-02 07:41:33 +00:00
|
|
|
// Copy charset
|
|
|
|
aNewDoc->SetDocumentCharacterSetSource(
|
|
|
|
sourceDoc->GetDocumentCharacterSetSource());
|
2007-05-09 02:47:58 +00:00
|
|
|
aNewDoc->SetDocumentCharacterSet(sourceDoc->GetDocumentCharacterSet());
|
2005-11-02 07:40:49 +00:00
|
|
|
}
|