/src/mozilla-central/dom/file/uri/FontTableURIProtocolHandler.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "FontTableURIProtocolHandler.h" |
8 | | #include "mozilla/ModuleUtils.h" |
9 | | #include "nsNetUtil.h" |
10 | | |
11 | | using namespace mozilla; |
12 | | using namespace mozilla::dom; |
13 | | |
14 | | /* static */ nsresult |
15 | | FontTableURIProtocolHandler::GenerateURIString(nsACString& aUri) |
16 | 0 | { |
17 | 0 | nsresult rv; |
18 | 0 | nsCOMPtr<nsIUUIDGenerator> uuidgen = |
19 | 0 | do_GetService("@mozilla.org/uuid-generator;1", &rv); |
20 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
21 | 0 |
|
22 | 0 | nsID id; |
23 | 0 | rv = uuidgen->GenerateUUIDInPlace(&id); |
24 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
25 | 0 |
|
26 | 0 | char chars[NSID_LENGTH]; |
27 | 0 | id.ToProvidedString(chars); |
28 | 0 |
|
29 | 0 | aUri = FONTTABLEURI_SCHEME; |
30 | 0 | aUri.Append(':'); |
31 | 0 |
|
32 | 0 | aUri += Substring(chars + 1, chars + NSID_LENGTH - 2); |
33 | 0 |
|
34 | 0 | return NS_OK; |
35 | 0 | } |
36 | | |
37 | 0 | FontTableURIProtocolHandler::FontTableURIProtocolHandler() = default; |
38 | 0 | FontTableURIProtocolHandler::~FontTableURIProtocolHandler() = default; |
39 | | |
40 | | NS_IMPL_ISUPPORTS(FontTableURIProtocolHandler, nsIProtocolHandler, |
41 | | nsISupportsWeakReference) |
42 | | |
43 | | NS_IMETHODIMP |
44 | | FontTableURIProtocolHandler::GetDefaultPort(int32_t *result) |
45 | 0 | { |
46 | 0 | *result = -1; |
47 | 0 | return NS_OK; |
48 | 0 | } |
49 | | |
50 | | NS_IMETHODIMP |
51 | | FontTableURIProtocolHandler::GetProtocolFlags(uint32_t *result) |
52 | 0 | { |
53 | 0 | *result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_SUBSUMERS | |
54 | 0 | URI_NON_PERSISTABLE | URI_IS_LOCAL_RESOURCE; |
55 | 0 | return NS_OK; |
56 | 0 | } |
57 | | |
58 | | NS_IMETHODIMP |
59 | | FontTableURIProtocolHandler::GetFlagsForURI(nsIURI *aURI, uint32_t *aResult) |
60 | 0 | { |
61 | 0 | return FontTableURIProtocolHandler::GetProtocolFlags(aResult); |
62 | 0 | } |
63 | | |
64 | | |
65 | | NS_IMETHODIMP |
66 | | FontTableURIProtocolHandler::NewChannel2(nsIURI* uri, |
67 | | nsILoadInfo* aLoadInfo, |
68 | | nsIChannel** result) |
69 | 0 | { |
70 | 0 | return NS_ERROR_DOM_BAD_URI; |
71 | 0 | } |
72 | | |
73 | | NS_IMETHODIMP |
74 | | FontTableURIProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) |
75 | 0 | { |
76 | 0 | return NS_ERROR_DOM_BAD_URI; |
77 | 0 | } |
78 | | |
79 | | NS_IMETHODIMP |
80 | | FontTableURIProtocolHandler::AllowPort(int32_t port, const char *scheme, |
81 | | bool *_retval) |
82 | 0 | { |
83 | 0 | *_retval = false; |
84 | 0 | return NS_OK; |
85 | 0 | } |
86 | | |
87 | | NS_IMETHODIMP |
88 | | FontTableURIProtocolHandler::GetScheme(nsACString &result) |
89 | 0 | { |
90 | 0 | result.AssignLiteral(FONTTABLEURI_SCHEME); |
91 | 0 | return NS_OK; |
92 | 0 | } |
93 | | |
94 | | NS_IMETHODIMP |
95 | | FontTableURIProtocolHandler::NewURI(const nsACString& aSpec, |
96 | | const char *aCharset, |
97 | | nsIURI *aBaseURI, |
98 | | nsIURI **aResult) |
99 | 0 | { |
100 | 0 | nsresult rv; |
101 | 0 | nsCOMPtr<nsIURI> uri; |
102 | 0 |
|
103 | 0 | // Either you got here via a ref or a fonttable: uri |
104 | 0 | if (aSpec.Length() && aSpec.CharAt(0) == '#') { |
105 | 0 | rv = NS_MutateURI(aBaseURI) |
106 | 0 | .SetRef(aSpec) |
107 | 0 | .Finalize(uri); |
108 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
109 | 0 | } else { |
110 | 0 | // Relative URIs (other than #ref) are not meaningful within the |
111 | 0 | // fonttable: scheme. |
112 | 0 | // If aSpec is a relative URI -other- than a bare #ref, |
113 | 0 | // this will leave uri empty, and we'll return a failure code below. |
114 | 0 | rv = NS_MutateURI(new mozilla::net::nsSimpleURI::Mutator()) |
115 | 0 | .SetSpec(aSpec) |
116 | 0 | .Finalize(uri); |
117 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
118 | 0 | } |
119 | 0 |
|
120 | 0 | bool schemeIs; |
121 | 0 | if (NS_FAILED(uri->SchemeIs(FONTTABLEURI_SCHEME, &schemeIs)) || !schemeIs) { |
122 | 0 | NS_WARNING("Non-fonttable spec in FontTableURIProtocolHandler"); |
123 | 0 | return NS_ERROR_NOT_AVAILABLE; |
124 | 0 | } |
125 | 0 |
|
126 | 0 | uri.forget(aResult); |
127 | 0 | return NS_OK; |
128 | 0 | } |
129 | | |
130 | | #define NS_FONTTABLEPROTOCOLHANDLER_CID \ |
131 | | { 0x3fc8f04e, 0xd719, 0x43ca, \ |
132 | | { 0x9a, 0xd0, 0x18, 0xee, 0x32, 0x02, 0x11, 0xf2 } } |
133 | | |
134 | | NS_GENERIC_FACTORY_CONSTRUCTOR(FontTableURIProtocolHandler) |
135 | | |
136 | | NS_DEFINE_NAMED_CID(NS_FONTTABLEPROTOCOLHANDLER_CID); |
137 | | |
138 | | static const mozilla::Module::CIDEntry FontTableURIProtocolHandlerCIDs[] = { |
139 | | { &kNS_FONTTABLEPROTOCOLHANDLER_CID, false, nullptr, FontTableURIProtocolHandlerConstructor }, |
140 | | { nullptr } |
141 | | }; |
142 | | |
143 | | static const mozilla::Module::ContractIDEntry FontTableURIProtocolHandlerContracts[] = { |
144 | | { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX FONTTABLEURI_SCHEME, &kNS_FONTTABLEPROTOCOLHANDLER_CID }, |
145 | | { nullptr } |
146 | | }; |
147 | | |
148 | | static const mozilla::Module FontTableURIProtocolHandlerModule = { |
149 | | mozilla::Module::kVersion, |
150 | | FontTableURIProtocolHandlerCIDs, |
151 | | FontTableURIProtocolHandlerContracts |
152 | | }; |
153 | | |
154 | | NSMODULE_DEFN(FontTableURIProtocolHandler) = &FontTableURIProtocolHandlerModule; |