Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/Location.h
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
#ifndef mozilla_dom_Location_h
8
#define mozilla_dom_Location_h
9
10
#include "js/TypeDecls.h"
11
#include "mozilla/ErrorResult.h"
12
#include "nsCycleCollectionParticipant.h"
13
#include "nsIWeakReferenceUtils.h"
14
#include "nsPIDOMWindow.h"
15
#include "nsString.h"
16
#include "nsWrapperCache.h"
17
18
class nsIDocShell;
19
class nsIURI;
20
21
namespace mozilla {
22
namespace dom {
23
24
//*****************************************************************************
25
// Location: Script "location" object
26
//*****************************************************************************
27
28
class Location final : public nsISupports
29
                     , public nsWrapperCache
30
{
31
public:
32
  Location(nsPIDOMWindowInner* aWindow, nsIDocShell *aDocShell);
33
34
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Location)
36
37
  // WebIDL API:
38
  void Assign(const nsAString& aUrl,
39
              nsIPrincipal& aSubjectPrincipal,
40
              ErrorResult& aError);
41
42
  void Replace(const nsAString& aUrl,
43
               nsIPrincipal& aSubjectPrincipal,
44
               ErrorResult& aError);
45
46
  void Reload(bool aForceget,
47
              nsIPrincipal& aSubjectPrincipal,
48
              ErrorResult& aError)
49
0
  {
50
0
    if (!CallerSubsumes(&aSubjectPrincipal)) {
51
0
      aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
52
0
      return;
53
0
    }
54
0
55
0
    aError = Reload(aForceget);
56
0
  }
57
58
  void GetHref(nsAString& aHref,
59
               nsIPrincipal& aSubjectPrincipal,
60
               ErrorResult& aError)
61
0
  {
62
0
    if (!CallerSubsumes(&aSubjectPrincipal)) {
63
0
      aError.Throw(NS_ERROR_DOM_SECURITY_ERR);
64
0
      return;
65
0
    }
66
0
67
0
    aError = GetHref(aHref);
68
0
  }
69
70
  void SetHref(const nsAString& aHref,
71
               ErrorResult& aError);
72
73
  void GetOrigin(nsAString& aOrigin,
74
                 nsIPrincipal& aSubjectPrincipal,
75
                 ErrorResult& aError);
76
77
  void GetProtocol(nsAString& aProtocol,
78
                   nsIPrincipal& aSubjectPrincipal,
79
                   ErrorResult& aError);
80
81
  void SetProtocol(const nsAString& aProtocol,
82
                   nsIPrincipal& aSubjectPrincipal,
83
                   ErrorResult& aError);
84
85
  void GetHost(nsAString& aHost,
86
               nsIPrincipal& aSubjectPrincipal,
87
               ErrorResult& aError);
88
89
  void SetHost(const nsAString& aHost,
90
               nsIPrincipal& aSubjectPrincipal,
91
               ErrorResult& aError);
92
93
  void GetHostname(nsAString& aHostname,
94
                   nsIPrincipal& aSubjectPrincipal,
95
                   ErrorResult& aError);
96
97
  void SetHostname(const nsAString& aHostname,
98
                   nsIPrincipal& aSubjectPrincipal,
99
                   ErrorResult& aError);
100
101
  void GetPort(nsAString& aPort,
102
               nsIPrincipal& aSubjectPrincipal,
103
               ErrorResult& aError);
104
105
  void SetPort(const nsAString& aPort,
106
               nsIPrincipal& aSubjectPrincipal,
107
               ErrorResult& aError);
108
109
  void GetPathname(nsAString& aPathname,
110
                   nsIPrincipal& aSubjectPrincipal,
111
                   ErrorResult& aError);
112
113
  void SetPathname(const nsAString& aPathname,
114
                   nsIPrincipal& aSubjectPrincipal,
115
                   ErrorResult& aError);
116
117
  void GetSearch(nsAString& aSeach,
118
                 nsIPrincipal& aSubjectPrincipal,
119
                 ErrorResult& aError);
120
121
  void SetSearch(const nsAString& aSeach,
122
                 nsIPrincipal& aSubjectPrincipal,
123
                 ErrorResult& aError);
124
125
  void GetHash(nsAString& aHash,
126
               nsIPrincipal& aSubjectPrincipal,
127
               ErrorResult& aError);
128
129
  void SetHash(const nsAString& aHash,
130
               nsIPrincipal& aSubjectPrincipal,
131
               ErrorResult& aError);
132
133
  void Stringify(nsAString& aRetval,
134
                 nsIPrincipal& aSubjectPrincipal,
135
                 ErrorResult& aError)
136
0
  {
137
0
    // GetHref checks CallerSubsumes.
138
0
    GetHref(aRetval, aSubjectPrincipal, aError);
139
0
  }
140
141
  nsPIDOMWindowInner* GetParentObject() const
142
0
  {
143
0
    return mInnerWindow;
144
0
  }
145
146
  virtual JSObject* WrapObject(JSContext* aCx,
147
                               JS::Handle<JSObject*> aGivenProto) override;
148
149
  // Non WebIDL methods:
150
151
  nsresult GetHref(nsAString& aHref);
152
153
  nsresult ToString(nsAString& aString)
154
0
  {
155
0
    return GetHref(aString);
156
0
  }
157
158
  nsresult Reload(bool aForceget);
159
160
protected:
161
  virtual ~Location();
162
163
  // In the case of jar: uris, we sometimes want the place the jar was
164
  // fetched from as the URI instead of the jar: uri itself.  Pass in
165
  // true for aGetInnermostURI when that's the case.
166
  // Note, this method can return NS_OK with a null value for aURL. This happens
167
  // if the docShell is null.
168
  nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
169
  nsresult SetURI(nsIURI* aURL, bool aReplace = false);
170
  nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
171
                           bool aReplace);
172
  nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
173
                              bool aReplace);
174
175
  nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
176
  nsresult CheckURL(nsIURI *url, nsDocShellLoadInfo** aLoadInfo);
177
  bool CallerSubsumes(nsIPrincipal* aSubjectPrincipal);
178
179
  nsString mCachedHash;
180
  nsCOMPtr<nsPIDOMWindowInner> mInnerWindow;
181
  nsWeakPtr mDocShell;
182
};
183
184
} // dom namespace
185
} // mozilla namespace
186
187
#endif // mozilla_dom_Location_h