Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 "nsDeviceProtocolHandler.h"
7 : #include "nsDeviceChannel.h"
8 : #include "nsAutoPtr.h"
9 : #include "nsSimpleURI.h"
10 :
11 : namespace mozilla {
12 : namespace net {
13 :
14 : //-----------------------------------------------------------------------------
15 0 : NS_IMPL_ISUPPORTS(nsDeviceProtocolHandler,
16 : nsIProtocolHandler)
17 :
18 : nsresult
19 0 : nsDeviceProtocolHandler::Init(){
20 0 : return NS_OK;
21 : }
22 :
23 : NS_IMETHODIMP
24 0 : nsDeviceProtocolHandler::GetScheme(nsACString &aResult)
25 : {
26 0 : aResult.AssignLiteral("moz-device");
27 0 : return NS_OK;
28 : }
29 :
30 : NS_IMETHODIMP
31 0 : nsDeviceProtocolHandler::GetDefaultPort(int32_t *aResult)
32 : {
33 0 : *aResult = -1; // no port for moz_device: URLs
34 0 : return NS_OK;
35 : }
36 :
37 : NS_IMETHODIMP
38 0 : nsDeviceProtocolHandler::GetProtocolFlags(uint32_t *aResult)
39 : {
40 0 : *aResult = URI_NORELATIVE | URI_NOAUTH | URI_DANGEROUS_TO_LOAD;
41 0 : return NS_OK;
42 : }
43 :
44 : NS_IMETHODIMP
45 0 : nsDeviceProtocolHandler::NewURI(const nsACString &spec,
46 : const char *originCharset,
47 : nsIURI *baseURI,
48 : nsIURI **result)
49 : {
50 0 : RefPtr<nsSimpleURI> uri = new nsSimpleURI();
51 :
52 0 : nsresult rv = uri->SetSpec(spec);
53 0 : NS_ENSURE_SUCCESS(rv, rv);
54 :
55 0 : uri.forget(result);
56 0 : return NS_OK;
57 : }
58 :
59 : NS_IMETHODIMP
60 0 : nsDeviceProtocolHandler::NewChannel2(nsIURI* aURI,
61 : nsILoadInfo* aLoadInfo,
62 : nsIChannel** aResult)
63 : {
64 0 : RefPtr<nsDeviceChannel> channel = new nsDeviceChannel();
65 0 : nsresult rv = channel->Init(aURI);
66 0 : NS_ENSURE_SUCCESS(rv, rv);
67 :
68 : // set the loadInfo on the new channel
69 0 : rv = channel->SetLoadInfo(aLoadInfo);
70 0 : NS_ENSURE_SUCCESS(rv, rv);
71 :
72 0 : channel.forget(aResult);
73 0 : return NS_OK;
74 : }
75 :
76 : NS_IMETHODIMP
77 0 : nsDeviceProtocolHandler::NewChannel(nsIURI* aURI, nsIChannel **aResult)
78 : {
79 0 : return NewChannel2(aURI, nullptr, aResult);
80 : }
81 :
82 : NS_IMETHODIMP
83 0 : nsDeviceProtocolHandler::AllowPort(int32_t port,
84 : const char *scheme,
85 : bool *aResult)
86 : {
87 : // don't override anything.
88 0 : *aResult = false;
89 0 : return NS_OK;
90 : }
91 :
92 : } // namespace net
93 : } // namespace mozilla
|