summaryrefslogtreecommitdiffstats
path: root/netwerk/protocol/res/SubstitutingJARURI.h
blob: fe9208750cb621106c584f6fc4cd5a15fa5245ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef SubstitutingJARURI_h
#define SubstitutingJARURI_h

#include "nsIURL.h"
#include "nsJARURI.h"
#include "nsISerializable.h"

namespace mozilla {
namespace net {

#define NS_SUBSTITUTINGJARURI_IMPL_CID               \
  { /* 8f8c54ed-aba7-4ebf-ba6f-e58aec0aba4c */       \
    0x8f8c54ed, 0xaba7, 0x4ebf, {                    \
      0xba, 0x6f, 0xe5, 0x8a, 0xec, 0x0a, 0xba, 0x4c \
    }                                                \
  }

// Provides a Substituting URI for resource://-like substitutions which
// allows consumers to access the underlying jar resource.
class SubstitutingJARURI : public nsIJARURI,
                           public nsIStandardURL,
                           public nsISerializable {
 protected:
  // Contains the resource://-like URI to be mapped. nsIURI and nsIURL will
  // forward to this.
  nsCOMPtr<nsIURL> mSource;
  // Contains the resolved jar resource, nsIJARURI forwards to this to let
  // consumer acccess the underlying jar resource.
  nsCOMPtr<nsIJARURI> mResolved;
  virtual ~SubstitutingJARURI() = default;

 public:
  SubstitutingJARURI(nsIURL* source, nsIJARURI* resolved);
  // For deserializing
  explicit SubstitutingJARURI() = default;

  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSISERIALIZABLE

  NS_DECLARE_STATIC_IID_ACCESSOR(NS_SUBSTITUTINGJARURI_IMPL_CID)

  NS_FORWARD_SAFE_NSIURL(mSource)
  NS_FORWARD_SAFE_NSIJARURI(mResolved)

  // enum used in a few places to specify how .ref attribute should be handled
  enum RefHandlingEnum { eIgnoreRef, eHonorRef };

  // We cannot forward Equals* methods to |mSource| so we override them here
  NS_IMETHOD EqualsExceptRef(nsIURI* aOther, bool* aResult) override;
  NS_IMETHOD Equals(nsIURI* aOther, bool* aResult) override;

  // Helper to share code between Equals methods.
  virtual nsresult EqualsInternal(nsIURI* aOther,
                                  RefHandlingEnum aRefHandlingMode,
                                  bool* aResult);

  // Forward the rest of nsIURI to mSource
  NS_IMETHOD GetSpec(nsACString& aSpec) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetSpec(aSpec);
  }
  NS_IMETHOD GetPrePath(nsACString& aPrePath) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetPrePath(aPrePath);
  }
  NS_IMETHOD GetScheme(nsACString& aScheme) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetScheme(aScheme);
  }
  NS_IMETHOD GetUserPass(nsACString& aUserPass) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetUserPass(aUserPass);
  }
  NS_IMETHOD GetUsername(nsACString& aUsername) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetUsername(aUsername);
  }
  NS_IMETHOD GetPassword(nsACString& aPassword) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetPassword(aPassword);
  }
  NS_IMETHOD GetHostPort(nsACString& aHostPort) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHostPort(aHostPort);
  }
  NS_IMETHOD GetHost(nsACString& aHost) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHost(aHost);
  }
  NS_IMETHOD GetPort(int32_t* aPort) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetPort(aPort);
  }
  NS_IMETHOD GetPathQueryRef(nsACString& aPathQueryRef) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetPathQueryRef(aPathQueryRef);
  }
  NS_IMETHOD SchemeIs(const char* scheme, bool* _retval) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->SchemeIs(scheme, _retval);
  }
  NS_IMETHOD Resolve(const nsACString& relativePath,
                     nsACString& _retval) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->Resolve(relativePath, _retval);
  }
  NS_IMETHOD GetAsciiSpec(nsACString& aAsciiSpec) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetAsciiSpec(aAsciiSpec);
  }
  NS_IMETHOD GetAsciiHostPort(nsACString& aAsciiHostPort) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetAsciiHostPort(aAsciiHostPort);
  }
  NS_IMETHOD GetAsciiHost(nsACString& aAsciiHost) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetAsciiHost(aAsciiHost);
  }
  NS_IMETHOD GetRef(nsACString& aRef) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetRef(aRef);
  }
  NS_IMETHOD GetSpecIgnoringRef(nsACString& aSpecIgnoringRef) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetSpecIgnoringRef(aSpecIgnoringRef);
  }
  NS_IMETHOD GetHasRef(bool* aHasRef) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHasRef(aHasRef);
  }
  NS_IMETHOD GetFilePath(nsACString& aFilePath) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetFilePath(aFilePath);
  }
  NS_IMETHOD GetQuery(nsACString& aQuery) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetQuery(aQuery);
  }
  NS_IMETHOD GetDisplayHost(nsACString& aDisplayHost) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetDisplayHost(aDisplayHost);
  }
  NS_IMETHOD GetDisplayHostPort(nsACString& aDisplayHostPort) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetDisplayHostPort(aDisplayHostPort);
  }
  NS_IMETHOD GetDisplaySpec(nsACString& aDisplaySpec) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetDisplaySpec(aDisplaySpec);
  }
  NS_IMETHOD GetDisplayPrePath(nsACString& aDisplayPrePath) override {
    return !mSource ? NS_ERROR_NULL_POINTER
                    : mSource->GetDisplayPrePath(aDisplayPrePath);
  }
  NS_IMETHOD Mutate(nsIURIMutator** _retval) override {
    return !mSource ? NS_ERROR_NULL_POINTER : mSource->Mutate(_retval);
  }
  NS_IMETHOD_(void) Serialize(mozilla::ipc::URIParams& aParams) override {
    MOZ_ASSERT(mSource);
    mSource->Serialize(aParams);
  }
};

NS_DEFINE_STATIC_IID_ACCESSOR(SubstitutingJARURI,
                              NS_SUBSTITUTINGJARURI_IMPL_CID)

}  // namespace net
}  // namespace mozilla

#endif /* SubstitutingJARURI_h */