DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (4a108e94d3e2)

VCS Links

Line Code
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et 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 nsLocation_h__
#define nsLocation_h__

#include "nsIDOMLocation.h"
#include "nsString.h"
#include "nsIWeakReferenceUtils.h"
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
#include "js/TypeDecls.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/URLSearchParams.h"
#include "nsPIDOMWindow.h"

class nsIURI;
class nsIDocShell;
class nsIDocShellLoadInfo;

//*****************************************************************************
// nsLocation: Script "location" object
//*****************************************************************************

class nsLocation final : public nsIDOMLocation
                           , public nsWrapperCache
                           , public mozilla::dom::URLSearchParamsObserver
{
  typedef mozilla::ErrorResult ErrorResult;

public:
  nsLocation(nsPIDOMWindow* aWindow, nsIDocShell *aDocShell);

  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsLocation,
                                                         nsIDOMLocation)

  void SetDocShell(nsIDocShell *aDocShell);
  nsIDocShell *GetDocShell();

  // nsIDOMLocation
  NS_DECL_NSIDOMLOCATION

  // WebIDL API:
  void Assign(const nsAString& aUrl, ErrorResult& aError)
  {
    aError = Assign(aUrl);
  }
  void Replace(const nsAString& aUrl, ErrorResult& aError)
  {
    aError = Replace(aUrl);
  }
  void Reload(bool aForceget, ErrorResult& aError)
  {
    aError = Reload(aForceget);
  }
  void GetHref(nsAString& aHref, ErrorResult& aError)
  {
    aError = GetHref(aHref);
  }
  void SetHref(const nsAString& aHref, ErrorResult& aError)
  {
    aError = SetHref(aHref);
  }
  void GetOrigin(nsAString& aOrigin, ErrorResult& aError)
  {
    aError = GetOrigin(aOrigin);
  }
  void GetProtocol(nsAString& aProtocol, ErrorResult& aError)
  {
    aError = GetProtocol(aProtocol);
  }
  void SetProtocol(const nsAString& aProtocol, ErrorResult& aError)
  {
    aError = SetProtocol(aProtocol);
  }
  void GetUsername(nsAString& aUsername, ErrorResult& aError);
  void SetUsername(const nsAString& aUsername, ErrorResult& aError);
  void GetPassword(nsAString& aPassword, ErrorResult& aError);
  void SetPassword(const nsAString& aPassword, ErrorResult& aError);
  void GetHost(nsAString& aHost, ErrorResult& aError)
  {
    aError = GetHost(aHost);
  }
  void SetHost(const nsAString& aHost, ErrorResult& aError)
  {
    aError = SetHost(aHost);
  }
  void GetHostname(nsAString& aHostname, ErrorResult& aError)
  {
    aError = GetHostname(aHostname);
  }
  void SetHostname(const nsAString& aHostname, ErrorResult& aError)
  {
    aError = SetHostname(aHostname);
  }
  void GetPort(nsAString& aPort, ErrorResult& aError)
  {
    aError = GetPort(aPort);
  }
  void SetPort(const nsAString& aPort, ErrorResult& aError)
  {
    aError = SetPort(aPort);
  }
  void GetPathname(nsAString& aPathname, ErrorResult& aError)
  {
    aError = GetPathname(aPathname);
  }
  void SetPathname(const nsAString& aPathname, ErrorResult& aError)
  {
    aError = SetPathname(aPathname);
  }
  void GetSearch(nsAString& aSeach, ErrorResult& aError)
  {
    aError = GetSearch(aSeach);
  }
  void SetSearch(const nsAString& aSeach, ErrorResult& aError)
  {
    aError = SetSearch(aSeach);
  }

  mozilla::dom::URLSearchParams* SearchParams();

  void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams);

  void GetHash(nsAString& aHash, ErrorResult& aError)
  {
    aError = GetHash(aHash);
  }
  void SetHash(const nsAString& aHash, ErrorResult& aError)
  {
    aError = SetHash(aHash);
  }
  void Stringify(nsAString& aRetval, ErrorResult& aError)
  {
    GetHref(aRetval, aError);
  }
  nsPIDOMWindow* GetParentObject() const
  {
    return mInnerWindow;
  }
  virtual JSObject* WrapObject(JSContext* aCx) override;

  // URLSearchParamsObserver
  void URLSearchParamsUpdated(mozilla::dom::URLSearchParams* aSearchParams) override;

protected:
  virtual ~nsLocation();

  nsresult SetSearchInternal(const nsAString& aSearch);
  void UpdateURLSearchParams();
  void RemoveURLSearchParams();

  mozilla::dom::URLSearchParams* GetDocShellSearchParams();

  // In the case of jar: uris, we sometimes want the place the jar was
  // fetched from as the URI instead of the jar: uri itself.  Pass in
  // true for aGetInnermostURI when that's the case.
  nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
  nsresult GetWritableURI(nsIURI** aURL);
  nsresult SetURI(nsIURI* aURL, bool aReplace = false);
  nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
                           bool aReplace);
  nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
                              bool aReplace);

  nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
  nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
  bool CallerSubsumes();

  nsString mCachedHash;
  nsCOMPtr<nsPIDOMWindow> mInnerWindow;
  nsRefPtr<mozilla::dom::URLSearchParams> mSearchParams;
  nsWeakPtr mDocShell;
};

#endif // nsLocation_h__