/src/mozilla-central/dom/xslt/base/txURIUtils.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "txURIUtils.h" |
7 | | #include "nsNetUtil.h" |
8 | | #include "nsIDocument.h" |
9 | | #include "nsIHttpChannelInternal.h" |
10 | | #include "nsIPrincipal.h" |
11 | | #include "mozilla/LoadInfo.h" |
12 | | |
13 | | using mozilla::net::LoadInfo; |
14 | | |
15 | | /** |
16 | | * URIUtils |
17 | | * A set of utilities for handling URIs |
18 | | **/ |
19 | | |
20 | | /** |
21 | | * Resolves the given href argument, using the given documentBase |
22 | | * if necessary. |
23 | | * The new resolved href will be appended to the given dest String |
24 | | **/ |
25 | | void URIUtils::resolveHref(const nsAString& href, const nsAString& base, |
26 | 0 | nsAString& dest) { |
27 | 0 | if (base.IsEmpty()) { |
28 | 0 | dest.Append(href); |
29 | 0 | return; |
30 | 0 | } |
31 | 0 | if (href.IsEmpty()) { |
32 | 0 | dest.Append(base); |
33 | 0 | return; |
34 | 0 | } |
35 | 0 | nsCOMPtr<nsIURI> pURL; |
36 | 0 | nsAutoString resultHref; |
37 | 0 | nsresult result = NS_NewURI(getter_AddRefs(pURL), base); |
38 | 0 | if (NS_SUCCEEDED(result)) { |
39 | 0 | NS_MakeAbsoluteURI(resultHref, href, pURL); |
40 | 0 | dest.Append(resultHref); |
41 | 0 | } |
42 | 0 | } //-- resolveHref |
43 | | |
44 | | // static |
45 | | void |
46 | | URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsINode *aSourceNode) |
47 | 0 | { |
48 | 0 | nsCOMPtr<nsIDocument> sourceDoc = aSourceNode->OwnerDoc(); |
49 | 0 | nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal(); |
50 | 0 |
|
51 | 0 | // Copy the channel and loadgroup from the source document. |
52 | 0 | nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup(); |
53 | 0 | nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel(); |
54 | 0 | if (!channel) { |
55 | 0 | // Need to synthesize one |
56 | 0 | nsresult rv = NS_NewChannel(getter_AddRefs(channel), |
57 | 0 | sourceDoc->GetDocumentURI(), |
58 | 0 | sourceDoc, |
59 | 0 | nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL, |
60 | 0 | nsIContentPolicy::TYPE_OTHER, |
61 | 0 | nullptr, // aPerformanceStorage |
62 | 0 | loadGroup, |
63 | 0 | nullptr, // aCallbacks |
64 | 0 | nsIChannel::LOAD_BYPASS_SERVICE_WORKER); |
65 | 0 |
|
66 | 0 | if (NS_FAILED(rv)) { |
67 | 0 | return; |
68 | 0 | } |
69 | 0 | } |
70 | 0 | |
71 | 0 | aNewDoc->Reset(channel, loadGroup); |
72 | 0 | aNewDoc->SetPrincipal(sourcePrincipal); |
73 | 0 | aNewDoc->SetBaseURI(sourceDoc->GetDocBaseURI()); |
74 | 0 |
|
75 | 0 | // Copy charset |
76 | 0 | aNewDoc->SetDocumentCharacterSetSource( |
77 | 0 | sourceDoc->GetDocumentCharacterSetSource()); |
78 | 0 | aNewDoc->SetDocumentCharacterSet(sourceDoc->GetDocumentCharacterSet()); |
79 | 0 | } |