summaryrefslogtreecommitdiffstats
path: root/dom/offline/nsDOMOfflineResourceList.cpp
blob: feb010074f2364ac477afe77314b9e108ac3ec43 (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
/* -*- 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/. */

#include "nsDOMOfflineResourceList.h"
#include "nsError.h"
#include "mozilla/Components.h"
#include "mozilla/dom/DOMStringList.h"
#include "nsNetUtil.h"
#include "nsNetCID.h"
#include "nsServiceManagerUtils.h"
#include "nsICookieJarSettings.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsContentUtils.h"
#include "nsILoadContext.h"
#include "nsIObserverService.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebNavigation.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/OfflineResourceListBinding.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/Preferences.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/StaticPrefs_browser.h"

#include "nsXULAppAPI.h"
#define IS_CHILD_PROCESS() (GeckoProcessType_Default != XRE_GetProcessType())

using namespace mozilla;
using namespace mozilla::dom;

//
// nsDOMOfflineResourceList
//

NS_IMPL_CYCLE_COLLECTION_WEAK_INHERITED(nsDOMOfflineResourceList,
                                        DOMEventTargetHelper)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMOfflineResourceList)
  NS_INTERFACE_MAP_ENTRY(nsIObserver)
  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)

NS_IMPL_ADDREF_INHERITED(nsDOMOfflineResourceList, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(nsDOMOfflineResourceList, DOMEventTargetHelper)

nsDOMOfflineResourceList::nsDOMOfflineResourceList(
    nsIURI* aManifestURI, nsIURI* aDocumentURI, nsIPrincipal* aLoadingPrincipal,
    nsPIDOMWindowInner* aWindow)
    : DOMEventTargetHelper(aWindow) {}

nsDOMOfflineResourceList::~nsDOMOfflineResourceList() { ClearCachedKeys(); }

JSObject* nsDOMOfflineResourceList::WrapObject(
    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
  return OfflineResourceList_Binding::Wrap(aCx, this, aGivenProto);
}

void nsDOMOfflineResourceList::Disconnect() {}

already_AddRefed<DOMStringList> nsDOMOfflineResourceList::GetMozItems(
    ErrorResult& aRv) {
  if (IS_CHILD_PROCESS()) {
    aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
    return nullptr;
  }

  RefPtr<DOMStringList> items = new DOMStringList();
  return items.forget();
}

bool nsDOMOfflineResourceList::MozHasItem(const nsAString& aURI,
                                          ErrorResult& aRv) {
  return false;
}

uint32_t nsDOMOfflineResourceList::GetMozLength(ErrorResult& aRv) {
  if (IS_CHILD_PROCESS()) {
    aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
    return 0;
  }

  return 0;
}

void nsDOMOfflineResourceList::MozItem(uint32_t aIndex, nsAString& aURI,
                                       ErrorResult& aRv) {
  aRv.Throw(NS_ERROR_NOT_AVAILABLE);
}

void nsDOMOfflineResourceList::IndexedGetter(uint32_t aIndex, bool& aFound,
                                             nsAString& aURI,
                                             ErrorResult& aRv) {
  if (IS_CHILD_PROCESS()) {
    aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
    return;
  }

  aFound = false;
}

void nsDOMOfflineResourceList::MozAdd(const nsAString& aURI, ErrorResult& aRv) {
}

void nsDOMOfflineResourceList::MozRemove(const nsAString& aURI,
                                         ErrorResult& aRv) {}

uint16_t nsDOMOfflineResourceList::GetStatus(ErrorResult& aRv) {
  return OfflineResourceList_Binding::UNCACHED;
}

void nsDOMOfflineResourceList::Update(ErrorResult& aRv) {}

void nsDOMOfflineResourceList::SwapCache(ErrorResult& aRv) {}

void nsDOMOfflineResourceList::FirePendingEvents() {}

void nsDOMOfflineResourceList::SendEvent(const nsAString& aEventName) {}

//
// nsDOMOfflineResourceList::nsIObserver
//
NS_IMETHODIMP
nsDOMOfflineResourceList::Observe(nsISupports* aSubject, const char* aTopic,
                                  const char16_t* aData) {
  return NS_OK;
}

nsresult nsDOMOfflineResourceList::GetCacheKey(const nsAString& aURI,
                                               nsCString& aKey) {
  nsCOMPtr<nsIURI> requestedURI;
  nsresult rv = NS_NewURI(getter_AddRefs(requestedURI), aURI);
  NS_ENSURE_SUCCESS(rv, rv);

  return GetCacheKey(requestedURI, aKey);
}

nsresult nsDOMOfflineResourceList::GetCacheKey(nsIURI* aURI, nsCString& aKey) {
  nsresult rv = aURI->GetAsciiSpec(aKey);
  NS_ENSURE_SUCCESS(rv, rv);

  // url fragments aren't used in cache keys
  nsAutoCString::const_iterator specStart, specEnd;
  aKey.BeginReading(specStart);
  aKey.EndReading(specEnd);
  if (FindCharInReadable('#', specStart, specEnd)) {
    aKey.BeginReading(specEnd);
    aKey = Substring(specEnd, specStart);
  }

  return NS_OK;
}

nsresult nsDOMOfflineResourceList::CacheKeys() { return NS_OK; }

void nsDOMOfflineResourceList::ClearCachedKeys() {}