зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1299500 - Get rid of DeviceStorage API - part 3 - DeviceStorageAreaListener, r=ehsan
This commit is contained in:
Родитель
78b899978b
Коммит
364dd3bee4
|
@ -33,7 +33,6 @@
|
|||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "BatteryManager.h"
|
||||
#include "mozilla/dom/DeviceStorageAreaListener.h"
|
||||
#include "mozilla/dom/GamepadServiceTest.h"
|
||||
#include "mozilla/dom/PowerManager.h"
|
||||
#include "mozilla/dom/WakeLock.h"
|
||||
|
@ -219,7 +218,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeviceStorageAreaListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDisplaysPromises)
|
||||
|
@ -305,10 +303,6 @@ Navigator::Invalidate()
|
|||
mMediaKeySystemAccessManager = nullptr;
|
||||
}
|
||||
|
||||
if (mDeviceStorageAreaListener) {
|
||||
mDeviceStorageAreaListener = nullptr;
|
||||
}
|
||||
|
||||
if (mGamepadServiceTest) {
|
||||
mGamepadServiceTest->Shutdown();
|
||||
mGamepadServiceTest = nullptr;
|
||||
|
@ -1038,20 +1032,6 @@ Navigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
|||
mWindow->GetOuterWindow());
|
||||
}
|
||||
|
||||
DeviceStorageAreaListener*
|
||||
Navigator::GetDeviceStorageAreaListener(ErrorResult& aRv)
|
||||
{
|
||||
if (!mDeviceStorageAreaListener) {
|
||||
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
mDeviceStorageAreaListener = new DeviceStorageAreaListener(mWindow);
|
||||
}
|
||||
|
||||
return mDeviceStorageAreaListener;
|
||||
}
|
||||
|
||||
already_AddRefed<nsDOMDeviceStorage>
|
||||
Navigator::FindDeviceStorage(const nsAString& aName, const nsAString& aType)
|
||||
{
|
||||
|
|
|
@ -75,7 +75,6 @@ class Connection;
|
|||
} // namespace network
|
||||
|
||||
class PowerManager;
|
||||
class DeviceStorageAreaListener;
|
||||
class Presentation;
|
||||
class LegacyMozTCPSocket;
|
||||
class VRDisplay;
|
||||
|
@ -196,7 +195,6 @@ public:
|
|||
void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
|
||||
already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
|
||||
ErrorResult& aRv);
|
||||
DeviceStorageAreaListener* GetDeviceStorageAreaListener(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<nsDOMDeviceStorage> GetDeviceStorage(const nsAString& aType,
|
||||
ErrorResult& aRv);
|
||||
|
@ -327,7 +325,6 @@ private:
|
|||
RefPtr<time::TimeManager> mTimeManager;
|
||||
RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
RefPtr<DeviceStorageAreaListener> mDeviceStorageAreaListener;
|
||||
RefPtr<Presentation> mPresentation;
|
||||
RefPtr<GamepadServiceTest> mGamepadServiceTest;
|
||||
nsTArray<RefPtr<Promise> > mVRGetDisplaysPromises;
|
||||
|
|
|
@ -1,141 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 "mozilla/dom/DeviceStorageAreaListener.h"
|
||||
#include "mozilla/dom/DeviceStorageAreaListenerBinding.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "DeviceStorage.h"
|
||||
#include "nsIObserverService.h"
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
#include "nsIVolume.h"
|
||||
#include "nsIVolumeService.h"
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class VolumeStateObserver final : public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
explicit VolumeStateObserver(DeviceStorageAreaListener* aListener)
|
||||
: mDeviceStorageAreaListener(aListener) {}
|
||||
void ForgetListener() { mDeviceStorageAreaListener = nullptr; }
|
||||
|
||||
private:
|
||||
~VolumeStateObserver() {};
|
||||
|
||||
// This reference is non-owning and it's cleared by
|
||||
// DeviceStorageAreaListener's destructor.
|
||||
DeviceStorageAreaListener* MOZ_NON_OWNING_REF mDeviceStorageAreaListener;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(VolumeStateObserver, nsIObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
VolumeStateObserver::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const char16_t *aData)
|
||||
{
|
||||
if (!mDeviceStorageAreaListener) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
|
||||
nsCOMPtr<nsIVolume> vol = do_QueryInterface(aSubject);
|
||||
MOZ_ASSERT(vol);
|
||||
|
||||
int32_t state;
|
||||
nsresult rv = vol->GetState(&state);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsString volName;
|
||||
vol->GetName(volName);
|
||||
|
||||
switch (state) {
|
||||
case nsIVolume::STATE_MOUNTED:
|
||||
mDeviceStorageAreaListener->DispatchStorageAreaChangedEvent(
|
||||
volName,
|
||||
DeviceStorageAreaChangedEventOperation::Added);
|
||||
break;
|
||||
default:
|
||||
mDeviceStorageAreaListener->DispatchStorageAreaChangedEvent(
|
||||
volName,
|
||||
DeviceStorageAreaChangedEventOperation::Removed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(DeviceStorageAreaListener, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(DeviceStorageAreaListener, DOMEventTargetHelper)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(DeviceStorageAreaListener)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
||||
|
||||
DeviceStorageAreaListener::DeviceStorageAreaListener(nsPIDOMWindowInner* aWindow)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
{
|
||||
MOZ_ASSERT(aWindow);
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
mVolumeStateObserver = new VolumeStateObserver(this);
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->AddObserver(mVolumeStateObserver, NS_VOLUME_STATE_CHANGED, false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DeviceStorageAreaListener::~DeviceStorageAreaListener()
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->RemoveObserver(mVolumeStateObserver, NS_VOLUME_STATE_CHANGED);
|
||||
}
|
||||
#endif
|
||||
mVolumeStateObserver->ForgetListener();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
DeviceStorageAreaListener::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return DeviceStorageAreaListenerBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
DeviceStorageAreaListener::DispatchStorageAreaChangedEvent(
|
||||
const nsString& aStorageName,
|
||||
DeviceStorageAreaChangedEventOperation aOperation)
|
||||
{
|
||||
StateMapType::const_iterator iter = mStorageAreaStateMap.find(aStorageName);
|
||||
if (iter == mStorageAreaStateMap.end() &&
|
||||
aOperation != DeviceStorageAreaChangedEventOperation::Added) {
|
||||
// The operation of the first event to dispatch should be "Added".
|
||||
return;
|
||||
}
|
||||
if (iter != mStorageAreaStateMap.end() &&
|
||||
iter->second == aOperation) {
|
||||
// No need to disptach the event if the state is unchanged.
|
||||
return;
|
||||
}
|
||||
|
||||
mStorageAreaStateMap[aStorageName] = aOperation;
|
||||
|
||||
nsDOMDeviceStorage::InvalidateVolumeCaches();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -1,47 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 mozilla_dom_DeviceStorageAreaListener_h
|
||||
#define mozilla_dom_DeviceStorageAreaListener_h
|
||||
|
||||
#include <map>
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/dom/DeviceStorageAreaChangedEvent.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class VolumeStateObserver;
|
||||
|
||||
class DeviceStorageAreaListener final : public DOMEventTargetHelper
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
IMPL_EVENT_HANDLER(storageareachanged)
|
||||
|
||||
explicit DeviceStorageAreaListener(nsPIDOMWindowInner* aWindow);
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
private:
|
||||
friend class VolumeStateObserver;
|
||||
|
||||
typedef std::map<nsString, DeviceStorageAreaChangedEventOperation> StateMapType;
|
||||
StateMapType mStorageAreaStateMap;
|
||||
|
||||
RefPtr<VolumeStateObserver> mVolumeStateObserver;
|
||||
|
||||
~DeviceStorageAreaListener();
|
||||
|
||||
void DispatchStorageAreaChangedEvent(
|
||||
const nsString& aStorageName,
|
||||
DeviceStorageAreaChangedEventOperation aOperation);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_DeviceStorageAreaListener_h
|
|
@ -14,10 +14,6 @@ EXPORTS += [
|
|||
'nsDeviceStorage.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'DeviceStorageAreaListener.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom.devicestorage += [
|
||||
'DeviceStorageRequestChild.h',
|
||||
'DeviceStorageRequestParent.h',
|
||||
|
@ -25,7 +21,6 @@ EXPORTS.mozilla.dom.devicestorage += [
|
|||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'DeviceStorageAreaListener.cpp',
|
||||
'DeviceStorageRequestChild.cpp',
|
||||
'DeviceStorageRequestParent.cpp',
|
||||
'DeviceStorageStatics.cpp',
|
||||
|
|
|
@ -2780,9 +2780,6 @@ void nsDOMDeviceStorage::InvalidateVolumeCaches()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Currently there is only the one volume cache. DeviceStorageAreaListener
|
||||
// calls this function any time it detects a volume was added or removed.
|
||||
|
||||
sVolumeNameCache = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
[Pref="device.storage.enabled"]
|
||||
interface DeviceStorageAreaListener : EventTarget {
|
||||
// Fired when a storage area is added or removed.
|
||||
attribute EventHandler onstorageareachanged;
|
||||
};
|
|
@ -245,11 +245,6 @@ partial interface Navigator {
|
|||
readonly attribute boolean cpuHasSSE2;
|
||||
};
|
||||
|
||||
partial interface Navigator {
|
||||
[Throws, Pref="device.storage.enabled"]
|
||||
readonly attribute DeviceStorageAreaListener deviceStorageAreaListener;
|
||||
};
|
||||
|
||||
// nsIDOMNavigatorDeviceStorage
|
||||
partial interface Navigator {
|
||||
[Throws, Pref="device.storage.enabled"]
|
||||
|
|
|
@ -485,7 +485,6 @@ WEBIDL_FILES = [
|
|||
'DesktopNotification.webidl',
|
||||
'DeviceMotionEvent.webidl',
|
||||
'DeviceStorage.webidl',
|
||||
'DeviceStorageAreaListener.webidl',
|
||||
'Directory.webidl',
|
||||
'Document.webidl',
|
||||
'DocumentFragment.webidl',
|
||||
|
|
Загрузка…
Ссылка в новой задаче