2011-11-02 06:44:16 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=2 et tw=78: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
// Needs to be first.
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "Navigator.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
#include "nsPluginArray.h"
|
|
|
|
#include "nsMimeTypeArray.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-04-10 07:20:43 -07:00
|
|
|
#include "mozilla/dom/DesktopNotification.h"
|
2011-11-02 06:44:16 -07:00
|
|
|
#include "nsGeolocation.h"
|
|
|
|
#include "nsIHttpProtocolHandler.h"
|
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIWebContentHandlerRegistrar.h"
|
|
|
|
#include "nsICookiePermission.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2012-02-15 16:47:13 -08:00
|
|
|
#include "nsVariant.h"
|
2011-11-02 06:44:16 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
2011-11-02 08:01:32 -07:00
|
|
|
#include "BatteryManager.h"
|
2012-01-19 19:24:00 -08:00
|
|
|
#include "PowerManager.h"
|
2012-03-07 03:03:25 -08:00
|
|
|
#include "nsIDOMWakeLock.h"
|
|
|
|
#include "nsIPowerManagerService.h"
|
2013-03-01 00:38:47 -08:00
|
|
|
#include "mozilla/dom/SmsManager.h"
|
2013-03-08 23:21:47 -08:00
|
|
|
#include "mozilla/dom/MobileMessageManager.h"
|
2011-11-21 07:16:24 -08:00
|
|
|
#include "nsISmsService.h"
|
2011-11-10 13:26:36 -08:00
|
|
|
#include "mozilla/Hal.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2012-10-11 15:56:13 -07:00
|
|
|
#include "nsISiteSpecificUserAgent.h"
|
2011-11-10 13:26:36 -08:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-07-26 12:33:45 -07:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-01-16 04:23:44 -08:00
|
|
|
#include "Connection.h"
|
2013-05-17 13:17:53 -07:00
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "nsDOMEvent.h"
|
2013-06-24 13:07:03 -07:00
|
|
|
#include "nsGlobalWindow.h"
|
2012-08-27 10:34:10 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-04-08 03:34:10 -07:00
|
|
|
#include "IccManager.h"
|
2012-04-19 14:33:25 -07:00
|
|
|
#include "MobileConnection.h"
|
2012-12-03 18:38:25 -08:00
|
|
|
#include "mozilla/dom/CellBroadcast.h"
|
2013-02-05 01:02:15 -08:00
|
|
|
#include "mozilla/dom/Voicemail.h"
|
2012-08-27 10:34:10 -07:00
|
|
|
#endif
|
2012-06-29 01:32:21 -07:00
|
|
|
#include "nsIIdleObserver.h"
|
2012-08-16 17:42:26 -07:00
|
|
|
#include "nsIPermissionManager.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
2012-09-10 23:05:00 -07:00
|
|
|
#include "TimeManager.h"
|
2011-11-02 06:44:16 -07:00
|
|
|
|
2012-06-03 00:35:15 -07:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
#include "MediaManager.h"
|
|
|
|
#endif
|
2012-01-09 14:28:47 -08:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-07-12 07:36:13 -07:00
|
|
|
#include "Telephony.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
#endif
|
2012-02-20 07:15:19 -08:00
|
|
|
#ifdef MOZ_B2G_BT
|
2012-05-23 21:02:23 -07:00
|
|
|
#include "nsIDOMBluetoothManager.h"
|
|
|
|
#include "BluetoothManager.h"
|
2012-02-20 07:15:19 -08:00
|
|
|
#endif
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "nsIDOMCameraManager.h"
|
|
|
|
#include "DOMCameraManager.h"
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2012-11-29 14:52:03 -08:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
#include "AudioChannelManager.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-02 17:16:55 -07:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
2013-07-12 07:35:35 -07:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
|
2013-07-12 07:37:23 -07:00
|
|
|
#include "nsScriptNameSpaceManager.h"
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
#include "mozilla/dom/NavigatorBinding.h"
|
2012-07-02 17:16:55 -07:00
|
|
|
|
2012-08-11 04:40:43 -07:00
|
|
|
using namespace mozilla::dom::power;
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
// This should not be in the namespace.
|
|
|
|
DOMCI_DATA(Navigator, mozilla::dom::Navigator)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2011-11-10 13:26:36 -08:00
|
|
|
static bool sDoNotTrackEnabled = false;
|
|
|
|
static bool sVibratorEnabled = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t sMaxVibrateMS = 0;
|
|
|
|
static uint32_t sMaxVibrateListLen = 0;
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
Navigator::Init()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
|
|
|
|
"privacy.donottrackheader.enabled",
|
|
|
|
false);
|
2011-11-10 13:26:36 -08:00
|
|
|
Preferences::AddBoolVarCache(&sVibratorEnabled,
|
|
|
|
"dom.vibrator.enabled", true);
|
|
|
|
Preferences::AddUintVarCache(&sMaxVibrateMS,
|
|
|
|
"dom.vibrator.max_vibrate_ms", 10000);
|
|
|
|
Preferences::AddUintVarCache(&sMaxVibrateListLen,
|
|
|
|
"dom.vibrator.max_vibrate_list_len", 128);
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
Navigator::Navigator(nsPIDOMWindow* aWindow)
|
2013-06-20 11:34:38 -07:00
|
|
|
: mWindow(aWindow)
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
2011-12-01 00:28:16 -08:00
|
|
|
NS_ASSERTION(aWindow->IsInnerWindow(),
|
|
|
|
"Navigator must get an inner window!");
|
2013-07-12 07:37:23 -07:00
|
|
|
SetIsDOMBinding();
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Navigator::~Navigator()
|
|
|
|
{
|
2011-12-01 00:28:16 -08:00
|
|
|
Invalidate();
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Navigator)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNavigator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMClientInformation)
|
2012-05-21 09:18:30 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDeviceStorage)
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorGeolocation)
|
2012-07-05 03:05:09 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINavigatorBattery)
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDesktopNotification)
|
2011-11-20 13:08:33 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorSms)
|
2013-03-08 23:21:47 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorMobileMessage)
|
2012-06-03 00:35:15 -07:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2012-09-20 12:54:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINavigatorUserMedia)
|
2012-06-03 00:35:15 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorUserMedia)
|
|
|
|
#endif
|
2012-01-09 14:28:47 -08:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorTelephony)
|
2012-02-15 16:47:13 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINavigatorGamepads)
|
2012-01-09 14:28:47 -08:00
|
|
|
#endif
|
2012-01-16 04:23:28 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorNetwork)
|
2012-08-27 10:34:10 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorMobileConnection)
|
2012-12-03 18:38:25 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorCellBroadcast)
|
2013-02-05 01:02:15 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorVoicemail)
|
2013-04-08 03:34:10 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorIccManager)
|
2012-08-27 10:34:10 -07:00
|
|
|
#endif
|
2012-02-20 07:15:19 -08:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorBluetooth)
|
|
|
|
#endif
|
2012-07-30 14:59:05 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorCamera)
|
2012-07-02 17:16:55 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
|
2012-11-05 07:20:03 -08:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2012-09-10 23:05:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorTime)
|
2012-11-29 14:52:03 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMozNavigatorAudioChannelManager)
|
2012-11-05 07:20:03 -08:00
|
|
|
#endif
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Navigator)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Navigator)
|
|
|
|
|
2013-06-28 11:06:39 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Navigator)
|
|
|
|
tmp->Invalidate();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
2013-07-09 06:58:21 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlugins)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMimeTypes)
|
2013-06-28 11:06:39 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGeolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotification)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryManager)
|
|
|
|
// mPowerManager isn't cycle collected
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSmsManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager)
|
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoicemail)
|
|
|
|
#endif
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCellBroadcast)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager)
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBluetooth)
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelManager)
|
|
|
|
#endif
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCameraManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessagesManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeviceStorageStores)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTimeManager)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
void
|
2011-12-01 00:28:16 -08:00
|
|
|
Navigator::Invalidate()
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
2013-06-20 11:34:38 -07:00
|
|
|
// Don't clear mWindow here so we know we've got a non-null mWindow
|
|
|
|
// until we're unlinked.
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
if (mPlugins) {
|
2011-12-01 00:28:16 -08:00
|
|
|
mPlugins->Invalidate();
|
2012-07-30 07:20:58 -07:00
|
|
|
mPlugins = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
mMimeTypes = nullptr;
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
// If there is a page transition, make sure delete the geolocation object.
|
|
|
|
if (mGeolocation) {
|
|
|
|
mGeolocation->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mGeolocation = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mNotification) {
|
|
|
|
mNotification->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mNotification = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
2011-11-02 08:27:06 -07:00
|
|
|
|
|
|
|
if (mBatteryManager) {
|
|
|
|
mBatteryManager->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mBatteryManager = nullptr;
|
2011-11-02 08:27:06 -07:00
|
|
|
}
|
2011-11-20 14:23:20 -08:00
|
|
|
|
2012-03-07 03:03:25 -08:00
|
|
|
if (mPowerManager) {
|
|
|
|
mPowerManager->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mPowerManager = nullptr;
|
2012-03-07 03:03:25 -08:00
|
|
|
}
|
2012-01-19 19:24:00 -08:00
|
|
|
|
2011-11-20 14:23:20 -08:00
|
|
|
if (mSmsManager) {
|
2011-11-24 16:48:57 -08:00
|
|
|
mSmsManager->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mSmsManager = nullptr;
|
2011-11-20 14:23:20 -08:00
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
if (mMobileMessageManager) {
|
|
|
|
mMobileMessageManager->Shutdown();
|
|
|
|
mMobileMessageManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
if (mTelephony) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mTelephony = nullptr;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
|
|
|
|
if (mVoicemail) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mVoicemail = nullptr;
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
#endif
|
2012-01-16 04:23:44 -08:00
|
|
|
|
2012-01-16 09:14:56 -08:00
|
|
|
if (mConnection) {
|
|
|
|
mConnection->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mConnection = nullptr;
|
2012-01-16 09:14:56 -08:00
|
|
|
}
|
2012-02-20 07:15:19 -08:00
|
|
|
|
2012-08-27 10:34:10 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-04-19 14:33:25 -07:00
|
|
|
if (mMobileConnection) {
|
|
|
|
mMobileConnection->Shutdown();
|
2012-07-30 07:20:58 -07:00
|
|
|
mMobileConnection = nullptr;
|
2012-04-19 14:33:25 -07:00
|
|
|
}
|
2012-12-03 18:38:25 -08:00
|
|
|
|
|
|
|
if (mCellBroadcast) {
|
|
|
|
mCellBroadcast = nullptr;
|
|
|
|
}
|
2013-04-08 03:34:10 -07:00
|
|
|
|
|
|
|
if (mIccManager) {
|
|
|
|
mIccManager->Shutdown();
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
2012-08-27 10:34:10 -07:00
|
|
|
#endif
|
2012-04-19 14:33:25 -07:00
|
|
|
|
2012-02-20 07:15:19 -08:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
if (mBluetooth) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mBluetooth = nullptr;
|
2012-02-20 07:15:19 -08:00
|
|
|
}
|
|
|
|
#endif
|
2012-07-02 17:16:55 -07:00
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
mCameraManager = nullptr;
|
|
|
|
|
2012-07-02 17:16:55 -07:00
|
|
|
if (mMessagesManager) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mMessagesManager = nullptr;
|
2012-07-02 17:16:55 -07:00
|
|
|
}
|
|
|
|
|
2012-11-29 14:52:03 -08:00
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
if (mAudioChannelManager) {
|
|
|
|
mAudioChannelManager = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = mDeviceStorageStores.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2012-08-01 23:29:34 -07:00
|
|
|
mDeviceStorageStores[i]->Shutdown();
|
|
|
|
}
|
|
|
|
mDeviceStorageStores.Clear();
|
|
|
|
|
2012-09-10 23:05:00 -07:00
|
|
|
if (mTimeManager) {
|
|
|
|
mTimeManager = nullptr;
|
|
|
|
}
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigator
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetUserAgent(nsAString& aUserAgent)
|
|
|
|
{
|
2012-10-11 15:56:13 -07:00
|
|
|
nsresult rv = NS_GetNavigatorUserAgent(aUserAgent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2012-10-11 15:56:13 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
nsIDocument* doc = mWindow->GetExtantDoc();
|
2012-10-11 15:56:13 -07:00
|
|
|
if (!doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
if (!codebaseURI) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISiteSpecificUserAgent> siteSpecificUA =
|
|
|
|
do_GetService("@mozilla.org/dom/site-specific-user-agent;1");
|
|
|
|
NS_ENSURE_TRUE(siteSpecificUA, NS_OK);
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
return siteSpecificUA->GetUserAgentForURIAndWindow(codebaseURI, mWindow,
|
|
|
|
aUserAgent);
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppCodeName(nsAString& aAppCodeName)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString appName;
|
2011-11-02 06:44:16 -07:00
|
|
|
rv = service->GetAppName(appName);
|
|
|
|
CopyASCIItoUTF16(appName, aAppCodeName);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppVersion(nsAString& aAppVersion)
|
|
|
|
{
|
|
|
|
return NS_GetNavigatorAppVersion(aAppVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetAppName(nsAString& aAppName)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
NS_GetNavigatorAppName(aAppName);
|
|
|
|
return NS_OK;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JS property navigator.language, exposed to web content.
|
|
|
|
* Take first value from Accept-Languages (HTTP header), which is
|
|
|
|
* the "content language" freely set by the user in the Pref window.
|
|
|
|
*
|
|
|
|
* Do not use UI language (chosen app locale) here.
|
|
|
|
* See RFC 2616, Section 15.1.4 "Privacy Issues Connected to Accept Headers"
|
|
|
|
*
|
|
|
|
* "en", "en-US" and "i-cherokee" and "" are valid.
|
|
|
|
* Fallback in case of invalid pref should be "" (empty string), to
|
|
|
|
* let site do fallback, e.g. to site's local language.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetLanguage(nsAString& aLanguage)
|
|
|
|
{
|
|
|
|
// E.g. "de-de, en-us,en".
|
|
|
|
const nsAdoptingString& acceptLang =
|
|
|
|
Preferences::GetLocalizedString("intl.accept_languages");
|
|
|
|
|
|
|
|
// Take everything before the first "," or ";", without trailing space.
|
|
|
|
nsCharSeparatedTokenizer langTokenizer(acceptLang, ',');
|
|
|
|
const nsSubstring &firstLangPart = langTokenizer.nextToken();
|
|
|
|
nsCharSeparatedTokenizer qTokenizer(firstLangPart, ';');
|
|
|
|
aLanguage.Assign(qTokenizer.nextToken());
|
|
|
|
|
|
|
|
// Checks and fixups:
|
|
|
|
// replace "_" with "-" to avoid POSIX/Windows "en_US" notation.
|
|
|
|
if (aLanguage.Length() > 2 && aLanguage[2] == PRUnichar('_')) {
|
|
|
|
aLanguage.Replace(2, 1, PRUnichar('-')); // TODO replace all
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use uppercase for country part, e.g. "en-US", not "en-us", see BCP47
|
|
|
|
// only uppercase 2-letter country codes, not "zh-Hant", "de-DE-x-goethe".
|
|
|
|
if (aLanguage.Length() <= 2) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCharSeparatedTokenizer localeTokenizer(aLanguage, '-');
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pos = 0;
|
2011-11-02 06:44:16 -07:00
|
|
|
bool first = true;
|
|
|
|
while (localeTokenizer.hasMoreTokens()) {
|
|
|
|
const nsSubstring& code = localeTokenizer.nextToken();
|
|
|
|
|
|
|
|
if (code.Length() == 2 && !first) {
|
|
|
|
nsAutoString upper(code);
|
|
|
|
ToUpperCase(upper);
|
|
|
|
aLanguage.Replace(pos, code.Length(), upper);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += code.Length() + 1; // 1 is the separator
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetPlatform(nsAString& aPlatform)
|
|
|
|
{
|
|
|
|
return NS_GetNavigatorPlatform(aPlatform);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetOscpu(nsAString& aOSCPU)
|
|
|
|
{
|
2012-10-25 16:10:53 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.oscpu.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aOSCPU = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString oscpu;
|
2011-11-02 06:44:16 -07:00
|
|
|
rv = service->GetOscpu(oscpu);
|
|
|
|
CopyASCIItoUTF16(oscpu, aOSCPU);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetVendor(nsAString& aVendor)
|
|
|
|
{
|
|
|
|
aVendor.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetVendorSub(nsAString& aVendorSub)
|
|
|
|
{
|
|
|
|
aVendorSub.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProduct(nsAString& aProduct)
|
|
|
|
{
|
2012-07-27 05:09:59 -07:00
|
|
|
aProduct.AssignLiteral("Gecko");
|
|
|
|
return NS_OK;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetProductSub(nsAString& aProductSub)
|
|
|
|
{
|
2012-07-27 05:09:59 -07:00
|
|
|
// Legacy build ID hardcoded for backward compatibility (bug 776376)
|
|
|
|
aProductSub.AssignLiteral("20100101");
|
|
|
|
return NS_OK;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-07-09 06:58:21 -07:00
|
|
|
Navigator::GetMimeTypes(nsISupports** aMimeTypes)
|
2013-07-12 07:35:35 -07:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aMimeTypes = GetMimeTypes(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMimeTypeArray*
|
|
|
|
Navigator::GetMimeTypes(ErrorResult& aRv)
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
|
|
|
if (!mMimeTypes) {
|
2013-07-12 07:35:35 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-09 06:58:21 -07:00
|
|
|
nsWeakPtr win = do_GetWeakReference(mWindow);
|
|
|
|
mMimeTypes = new nsMimeTypeArray(win);
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return mMimeTypes;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-07-09 06:58:21 -07:00
|
|
|
Navigator::GetPlugins(nsISupports** aPlugins)
|
2013-07-12 07:35:35 -07:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aPlugins = static_cast<nsIObserver*>(GetPlugins(rv)));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginArray*
|
|
|
|
Navigator::GetPlugins(ErrorResult& aRv)
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
|
|
|
if (!mPlugins) {
|
2013-07-12 07:35:35 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-09 06:58:21 -07:00
|
|
|
nsWeakPtr win = do_GetWeakReference(mWindow);
|
|
|
|
mPlugins = new nsPluginArray(win);
|
2013-04-10 13:59:45 -07:00
|
|
|
mPlugins->Init();
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return mPlugins;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Values for the network.cookie.cookieBehavior pref are documented in
|
|
|
|
// nsCookieService.cpp.
|
|
|
|
#define COOKIE_BEHAVIOR_REJECT 2
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetCookieEnabled(bool* aCookieEnabled)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
*aCookieEnabled = CookieEnabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::CookieEnabled()
|
|
|
|
{
|
|
|
|
bool cookieEnabled =
|
2011-11-02 06:44:16 -07:00
|
|
|
(Preferences::GetInt("network.cookie.cookieBehavior",
|
|
|
|
COOKIE_BEHAVIOR_REJECT) != COOKIE_BEHAVIOR_REJECT);
|
|
|
|
|
|
|
|
// Check whether an exception overrides the global cookie behavior
|
|
|
|
// Note that the code for getting the URI here matches that in
|
|
|
|
// nsHTMLDocument::SetCookie.
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
2013-07-12 07:35:35 -07:00
|
|
|
return cookieEnabled;
|
2011-12-01 00:28:16 -08:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
2011-11-02 06:44:16 -07:00
|
|
|
if (!doc) {
|
2013-07-12 07:35:35 -07:00
|
|
|
return cookieEnabled;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> codebaseURI;
|
|
|
|
doc->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
|
|
|
|
|
|
|
|
if (!codebaseURI) {
|
|
|
|
// Not a codebase, so technically can't set cookies, but let's
|
|
|
|
// just return the default value.
|
2013-07-12 07:35:35 -07:00
|
|
|
return cookieEnabled;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookiePermission> permMgr =
|
|
|
|
do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
|
2013-07-12 07:35:35 -07:00
|
|
|
NS_ENSURE_TRUE(permMgr, cookieEnabled);
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
// Pass null for the channel, just like the cookie service does.
|
|
|
|
nsCookieAccess access;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = permMgr->CanAccess(codebaseURI, nullptr, &access);
|
2013-07-12 07:35:35 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, cookieEnabled);
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
if (access != nsICookiePermission::ACCESS_DEFAULT) {
|
2013-07-12 07:35:35 -07:00
|
|
|
cookieEnabled = access != nsICookiePermission::ACCESS_DENY;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return cookieEnabled;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetOnLine(bool* aOnline)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aOnline, "Null out param");
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
*aOnline = OnLine();
|
2011-11-02 06:44:16 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
bool
|
|
|
|
Navigator::OnLine()
|
|
|
|
{
|
|
|
|
return !NS_IsOffline();
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetBuildID(nsAString& aBuildID)
|
|
|
|
{
|
2012-10-25 16:10:53 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
Preferences::GetString("general.buildID.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aBuildID = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appInfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
if (!appInfo) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buildID;
|
2011-11-02 06:44:16 -07:00
|
|
|
nsresult rv = appInfo->GetAppBuildID(buildID);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
aBuildID.Truncate();
|
|
|
|
AppendASCIItoUTF16(buildID, aBuildID);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetDoNotTrack(nsAString &aResult)
|
|
|
|
{
|
|
|
|
if (sDoNotTrackEnabled) {
|
|
|
|
aResult.AssignLiteral("yes");
|
|
|
|
} else {
|
|
|
|
aResult.AssignLiteral("unspecified");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::JavaEnabled(bool* aReturn)
|
2013-07-12 07:35:35 -07:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn = JavaEnabled(rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::JavaEnabled(ErrorResult& aRv)
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
|
|
|
Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> telemetryTimer;
|
|
|
|
// Return true if we have a handler for "application/x-java-vm",
|
|
|
|
// otherwise return false.
|
|
|
|
if (!mMimeTypes) {
|
2013-07-12 07:35:35 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-09 06:58:21 -07:00
|
|
|
nsWeakPtr win = do_GetWeakReference(mWindow);
|
|
|
|
mMimeTypes = new nsMimeTypeArray(win);
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RefreshMIMEArray();
|
|
|
|
|
2013-07-09 06:58:21 -07:00
|
|
|
nsMimeType *mimeType =
|
|
|
|
mMimeTypes->NamedItem(NS_LITERAL_STRING("application/x-java-vm"));
|
2011-11-02 04:04:28 -07:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return mimeType && mimeType->GetEnabledPlugin();
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2012-01-05 08:24:10 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::TaintEnabled(bool *aReturn)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
*aReturn = TaintEnabled();
|
2012-01-05 08:24:10 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
void
|
|
|
|
Navigator::RefreshMIMEArray()
|
|
|
|
{
|
|
|
|
if (mMimeTypes) {
|
2011-12-01 00:28:16 -08:00
|
|
|
mMimeTypes->Refresh();
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::HasDesktopNotificationSupport()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("notification.feature.enabled", false);
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:26:36 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class VibrateWindowListener : public nsIDOMEventListener
|
|
|
|
{
|
|
|
|
public:
|
2013-04-23 21:22:37 -07:00
|
|
|
VibrateWindowListener(nsIDOMWindow* aWindow, nsIDocument* aDocument)
|
2011-11-10 13:26:36 -08:00
|
|
|
{
|
|
|
|
mWindow = do_GetWeakReference(aWindow);
|
|
|
|
mDocument = do_GetWeakReference(aDocument);
|
|
|
|
|
2012-11-16 14:22:56 -08:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2013-04-23 21:22:37 -07:00
|
|
|
aDocument->AddSystemEventListener(visibilitychange,
|
|
|
|
this, /* listener */
|
|
|
|
true, /* use capture */
|
|
|
|
false /* wants untrusted */);
|
2011-11-10 13:26:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~VibrateWindowListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveListener();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsWeakPtr mWindow;
|
|
|
|
nsWeakPtr mDocument;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(VibrateWindowListener, nsIDOMEventListener)
|
|
|
|
|
2012-07-26 12:33:45 -07:00
|
|
|
StaticRefPtr<VibrateWindowListener> gVibrateWindowListener;
|
2011-11-10 13:26:36 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VibrateWindowListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2013-04-19 15:18:32 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc =
|
|
|
|
do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
|
2011-11-10 13:26:36 -08:00
|
|
|
|
2013-04-19 15:18:32 -07:00
|
|
|
if (!doc || doc->Hidden()) {
|
2011-11-10 13:26:36 -08:00
|
|
|
// It's important that we call CancelVibrate(), not Vibrate() with an
|
|
|
|
// empty list, because Vibrate() will fail if we're no longer focused, but
|
|
|
|
// CancelVibrate() will succeed, so long as nobody else has started a new
|
|
|
|
// vibration pattern.
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
hal::CancelVibrate(window);
|
|
|
|
RemoveListener();
|
|
|
|
gVibrateWindowListener = NULL;
|
|
|
|
// Careful: The line above might have deleted |this|!
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VibrateWindowListener::RemoveListener()
|
|
|
|
{
|
2013-04-19 15:18:32 -07:00
|
|
|
nsCOMPtr<EventTarget> target = do_QueryReferent(mDocument);
|
2011-11-10 13:26:36 -08:00
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-16 14:22:56 -08:00
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange");
|
2011-11-10 13:26:36 -08:00
|
|
|
target->RemoveSystemEventListener(visibilitychange, this,
|
|
|
|
true /* use capture */);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-11 15:52:10 -07:00
|
|
|
* Converts a JS::Value into a vibration duration, checking that the duration is in
|
2011-11-10 13:26:36 -08:00
|
|
|
* bounds (non-negative and not larger than sMaxVibrateMS).
|
|
|
|
*
|
|
|
|
* Returns true on success, false on failure.
|
|
|
|
*/
|
|
|
|
bool
|
2013-04-11 15:52:10 -07:00
|
|
|
GetVibrationDurationFromJsval(const JS::Value& aJSVal, JSContext* cx,
|
2012-05-25 00:18:30 -07:00
|
|
|
int32_t* aOut)
|
2011-11-10 13:26:36 -08:00
|
|
|
{
|
|
|
|
return JS_ValueToInt32(cx, aJSVal, aOut) &&
|
2012-05-25 00:18:30 -07:00
|
|
|
*aOut >= 0 && static_cast<uint32_t>(*aOut) <= sMaxVibrateMS;
|
2011-11-10 13:26:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2012-06-29 01:32:21 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::AddIdleObserver(nsIIdleObserver* aIdleObserver)
|
|
|
|
{
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
|
|
|
|
2012-06-29 01:32:21 -07:00
|
|
|
if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
|
|
|
|
NS_WARNING("The IdleObserver API has been disabled.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aIdleObserver);
|
|
|
|
|
2012-10-02 02:08:02 -07:00
|
|
|
if (!CheckPermission("idle")) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2012-08-06 09:10:58 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
AddIdleObserver(*aIdleObserver);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::AddIdleObserver(nsIIdleObserver& aIdleObserver)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (NS_FAILED(mWindow->RegisterIdleObserver(&aIdleObserver))) {
|
2012-06-29 01:32:21 -07:00
|
|
|
NS_WARNING("Failed to add idle observer.");
|
|
|
|
}
|
2013-07-12 07:35:35 -07:00
|
|
|
}
|
2012-06-29 01:32:21 -07:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
void
|
|
|
|
Navigator::AddIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
|
|
|
return AddIdleObserver(*obs);
|
2012-06-29 01:32:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RemoveIdleObserver(nsIIdleObserver* aIdleObserver)
|
|
|
|
{
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
|
|
|
|
2012-06-29 01:32:21 -07:00
|
|
|
if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
|
|
|
|
NS_WARNING("The IdleObserver API has been disabled");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aIdleObserver);
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
RemoveIdleObserver(*aIdleObserver);
|
2012-06-29 01:32:21 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
void
|
|
|
|
Navigator::RemoveIdleObserver(nsIIdleObserver& aIdleObserver)
|
2011-11-10 13:26:36 -08:00
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (NS_FAILED(mWindow->UnregisterIdleObserver(&aIdleObserver))) {
|
|
|
|
NS_WARNING("Failed to remove idle observer.");
|
|
|
|
}
|
|
|
|
}
|
2011-11-10 13:26:36 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
void
|
|
|
|
Navigator::RemoveIdleObserver(MozIdleObserver& aIdleObserver, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2011-11-10 13:26:36 -08:00
|
|
|
}
|
2013-07-12 07:35:35 -07:00
|
|
|
CallbackObjectHolder<MozIdleObserver, nsIIdleObserver> holder(&aIdleObserver);
|
|
|
|
nsCOMPtr<nsIIdleObserver> obs = holder.ToXPCOMCallback();
|
|
|
|
return RemoveIdleObserver(*obs);
|
|
|
|
}
|
2011-11-10 13:26:36 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::Vibrate(const JS::Value& aPattern, JSContext* cx)
|
|
|
|
{
|
2012-05-25 00:18:30 -07:00
|
|
|
nsAutoTArray<uint32_t, 8> pattern;
|
2011-11-10 13:26:36 -08:00
|
|
|
|
|
|
|
// null or undefined pattern is an error.
|
|
|
|
if (JSVAL_IS_NULL(aPattern) || JSVAL_IS_VOID(aPattern)) {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JSVAL_IS_PRIMITIVE(aPattern)) {
|
2012-05-25 00:18:30 -07:00
|
|
|
int32_t p;
|
2011-11-10 13:26:36 -08:00
|
|
|
if (GetVibrationDurationFromJsval(aPattern, cx, &p)) {
|
|
|
|
pattern.AppendElement(p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JSObject*> obj(cx, aPattern.toObjectOrNull());
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length;
|
2011-11-10 13:26:36 -08:00
|
|
|
if (!JS_GetArrayLength(cx, obj, &length) || length > sMaxVibrateListLen) {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
pattern.SetLength(length);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JS::Value> v(cx);
|
2012-05-25 00:18:30 -07:00
|
|
|
int32_t pv;
|
2013-05-04 00:52:57 -07:00
|
|
|
if (JS_GetElement(cx, obj, i, v.address()) &&
|
2011-11-10 13:26:36 -08:00
|
|
|
GetVibrationDurationFromJsval(v, cx, &pv)) {
|
|
|
|
pattern[i] = pv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
Vibrate(pattern, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::Vibrate(uint32_t aDuration, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsAutoTArray<uint32_t, 1> pattern;
|
|
|
|
pattern.AppendElement(aDuration);
|
|
|
|
Vibrate(pattern, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::Vibrate(const nsTArray<uint32_t>& aPattern, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetExtantDoc();
|
|
|
|
if (!doc) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (doc->Hidden()) {
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPattern.Length() > sMaxVibrateListLen) {
|
|
|
|
// XXXbz this should be returning false instead
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < aPattern.Length(); ++i) {
|
|
|
|
if (aPattern[i] > sMaxVibrateMS) {
|
|
|
|
// XXXbz this should be returning false instead
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:26:36 -08:00
|
|
|
// The spec says we check sVibratorEnabled after we've done the sanity
|
|
|
|
// checking on the pattern.
|
|
|
|
if (!sVibratorEnabled) {
|
2013-07-12 07:35:35 -07:00
|
|
|
return;
|
2011-11-10 13:26:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a listener to cancel the vibration if the document becomes hidden,
|
2012-11-16 14:22:56 -08:00
|
|
|
// and remove the old visibility listener, if there was one.
|
2011-11-10 13:26:36 -08:00
|
|
|
|
|
|
|
if (!gVibrateWindowListener) {
|
|
|
|
// If gVibrateWindowListener is null, this is the first time we've vibrated,
|
|
|
|
// and we need to register a listener to clear gVibrateWindowListener on
|
|
|
|
// shutdown.
|
|
|
|
ClearOnShutdown(&gVibrateWindowListener);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gVibrateWindowListener->RemoveListener();
|
|
|
|
}
|
2013-06-20 11:34:38 -07:00
|
|
|
gVibrateWindowListener = new VibrateWindowListener(mWindow, doc);
|
2011-11-10 13:26:36 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
hal::Vibrate(aPattern, mWindow);
|
2011-11-10 13:26:36 -08:00
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMClientInformation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RegisterContentHandler(const nsAString& aMIMEType,
|
|
|
|
const nsAString& aURI,
|
|
|
|
const nsAString& aTitle)
|
|
|
|
{
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return registrar->RegisterContentHandler(aMIMEType, aURI, aTitle,
|
2013-06-20 11:34:38 -07:00
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
|
|
|
const nsAString& aURI,
|
|
|
|
const nsAString& aTitle)
|
|
|
|
{
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebContentHandlerRegistrar> registrar =
|
|
|
|
do_GetService(NS_WEBCONTENTHANDLERREGISTRAR_CONTRACTID);
|
|
|
|
if (!registrar) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
|
2013-06-20 11:34:38 -07:00
|
|
|
mWindow->GetOuterWindow());
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozIsLocallyAvailable(const nsAString &aURI,
|
|
|
|
bool aWhenOffline,
|
|
|
|
bool* aIsAvailable)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// This method of checking the cache will only work for http/https urls.
|
|
|
|
bool match;
|
|
|
|
rv = uri->SchemeIs("http", &match);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
rv = uri->SchemeIs("https", &match);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!match) {
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same origin check.
|
2013-04-29 11:16:18 -07:00
|
|
|
JSContext *cx = nsContentUtils::GetCurrentJSContext();
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->CheckSameOrigin(cx, uri);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// These load flags cause an error to be thrown if there is no
|
|
|
|
// valid cache entry, and skip the load if there is.
|
|
|
|
// If the cache is busy, assume that it is not yet available rather
|
|
|
|
// than waiting for it to become available.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t loadFlags = nsIChannel::INHIBIT_CACHING |
|
2011-11-02 06:44:16 -07:00
|
|
|
nsICachingChannel::LOAD_NO_NETWORK_IO |
|
|
|
|
nsICachingChannel::LOAD_ONLY_IF_MODIFIED |
|
|
|
|
nsICachingChannel::LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
|
|
|
|
|
|
|
|
if (aWhenOffline) {
|
|
|
|
loadFlags |= nsICachingChannel::LOAD_CHECK_OFFLINE_CACHE |
|
|
|
|
nsICachingChannel::LOAD_ONLY_FROM_CACHE |
|
|
|
|
nsIRequest::LOAD_FROM_CACHE;
|
|
|
|
}
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
|
|
|
|
2012-09-17 08:24:38 -07:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2013-06-20 11:34:38 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
|
2012-09-17 08:24:38 -07:00
|
|
|
if (doc) {
|
|
|
|
loadGroup = doc->GetDocumentLoadGroup();
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel), uri,
|
2012-09-17 08:24:38 -07:00
|
|
|
nullptr, loadGroup, nullptr, loadFlags);
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
|
|
rv = channel->Open(getter_AddRefs(stream));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
stream->Close();
|
|
|
|
|
|
|
|
nsresult status;
|
|
|
|
rv = channel->GetStatus(&status);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(status)) {
|
|
|
|
*aIsAvailable = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
|
|
|
|
return httpChannel->GetRequestSucceeded(aIsAvailable);
|
|
|
|
}
|
|
|
|
|
2012-05-21 09:18:30 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorDeviceStorage
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2012-08-01 23:32:11 -07:00
|
|
|
NS_IMETHODIMP Navigator::GetDeviceStorage(const nsAString &aType, nsIDOMDeviceStorage** _retval)
|
2013-04-02 12:52:21 -07:00
|
|
|
{
|
2013-04-04 15:21:49 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = nullptr;
|
|
|
|
|
|
|
|
if (!Preferences::GetBool("device.storage.enabled", false)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*_retval = GetDeviceStorage(aType, rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMDeviceStorage*
|
|
|
|
Navigator::GetDeviceStorage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the pref check here.
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 07:35:44 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-05-11 02:10:18 -07:00
|
|
|
}
|
2013-05-11 06:47:37 -07:00
|
|
|
|
2013-05-11 02:10:18 -07:00
|
|
|
nsRefPtr<nsDOMDeviceStorage> storage;
|
2013-06-20 11:34:38 -07:00
|
|
|
nsDOMDeviceStorage::CreateDeviceStorageFor(mWindow, aType,
|
|
|
|
getter_AddRefs(storage));
|
2013-05-11 06:47:37 -07:00
|
|
|
|
2013-05-11 02:10:18 -07:00
|
|
|
if (!storage) {
|
2013-07-12 07:35:44 -07:00
|
|
|
return nullptr;
|
2013-04-02 12:52:21 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 02:10:18 -07:00
|
|
|
mDeviceStorageStores.AppendElement(storage);
|
2013-07-12 07:35:44 -07:00
|
|
|
return storage;
|
2013-04-02 12:52:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Navigator::GetDeviceStorages(const nsAString &aType, nsIVariant** _retval)
|
2012-05-21 09:18:30 -07:00
|
|
|
{
|
2013-04-04 15:21:49 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
*_retval = nullptr;
|
|
|
|
|
2012-05-21 09:18:30 -07:00
|
|
|
if (!Preferences::GetBool("device.storage.enabled", false)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-02 12:52:21 -07:00
|
|
|
nsTArray<nsRefPtr<nsDOMDeviceStorage> > stores;
|
2013-07-12 07:35:44 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
GetDeviceStorages(aType, stores, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2013-04-02 12:52:21 -07:00
|
|
|
nsCOMPtr<nsIWritableVariant> result = do_CreateInstance("@mozilla.org/variant;1");
|
|
|
|
NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (stores.Length() == 0) {
|
|
|
|
result->SetAsEmptyArray();
|
|
|
|
} else {
|
|
|
|
result->SetAsArray(nsIDataType::VTYPE_INTERFACE,
|
|
|
|
&NS_GET_IID(nsIDOMDeviceStorage),
|
|
|
|
stores.Length(),
|
|
|
|
const_cast<void*>(static_cast<const void*>(stores.Elements())));
|
2012-08-01 23:32:11 -07:00
|
|
|
}
|
2013-04-02 12:52:21 -07:00
|
|
|
result.forget(_retval);
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-05-21 09:18:30 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
void
|
|
|
|
Navigator::GetDeviceStorages(const nsAString& aType,
|
|
|
|
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the pref check here.
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores, false);
|
|
|
|
|
|
|
|
mDeviceStorageStores.AppendElements(aStores);
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorGeolocation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP Navigator::GetGeolocation(nsIDOMGeoGeolocation** _retval)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*_retval = GetGeolocation(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2011-11-02 06:44:16 -07:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
Geolocation*
|
|
|
|
Navigator::GetGeolocation(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 06:44:16 -07:00
|
|
|
if (!Preferences::GetBool("geo.enabled", true)) {
|
2013-07-12 07:35:35 -07:00
|
|
|
return nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mGeolocation) {
|
2013-07-12 07:35:35 -07:00
|
|
|
return mGeolocation;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
|
2013-07-12 07:35:35 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
mGeolocation = new Geolocation();
|
2013-06-20 11:34:38 -07:00
|
|
|
if (NS_FAILED(mGeolocation->Init(mWindow->GetOuterWindow()))) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mGeolocation = nullptr;
|
2013-07-12 07:35:35 -07:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return mGeolocation;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 00:35:15 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorUserMedia (mozGetUserMedia)
|
|
|
|
//*****************************************************************************
|
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams,
|
2012-09-20 12:54:00 -07:00
|
|
|
nsIDOMGetUserMediaSuccessCallback* aOnSuccess,
|
|
|
|
nsIDOMGetUserMediaErrorCallback* aOnError)
|
2012-06-03 00:35:15 -07:00
|
|
|
{
|
2012-10-04 16:12:01 -07:00
|
|
|
// Make enabling peerconnection enable getUserMedia() as well
|
|
|
|
if (!(Preferences::GetBool("media.navigator.enabled", false) ||
|
|
|
|
Preferences::GetBool("media.peerconnection.enabled", false))) {
|
2012-06-03 00:35:15 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:37:21 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
MozGetUserMedia(aParams, aOnSuccess, aOnError, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams,
|
|
|
|
MozDOMGetUserMediaSuccessCallback* aOnSuccess,
|
|
|
|
MozDOMGetUserMediaErrorCallback* aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CallbackObjectHolder<MozDOMGetUserMediaSuccessCallback,
|
|
|
|
nsIDOMGetUserMediaSuccessCallback> holder1(aOnSuccess);
|
|
|
|
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onsucces =
|
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
|
|
|
CallbackObjectHolder<MozDOMGetUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(aOnError);
|
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
|
|
|
MozGetUserMedia(aParams, onsucces, onerror, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::MozGetUserMedia(nsIMediaStreamOptions* aParams,
|
|
|
|
nsIDOMGetUserMediaSuccessCallback* aOnSuccess,
|
|
|
|
nsIDOMGetUserMediaErrorCallback* aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the pref check here.
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 07:37:21 -07:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
2012-09-20 12:54:00 -07:00
|
|
|
}
|
2012-06-03 00:35:15 -07:00
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
bool privileged = nsContentUtils::IsChromeDoc(mWindow->GetExtantDoc());
|
2012-09-20 12:54:00 -07:00
|
|
|
|
|
|
|
MediaManager* manager = MediaManager::Get();
|
2013-07-12 07:37:21 -07:00
|
|
|
aRv = manager->GetUserMedia(privileged, mWindow, aParams, aOnSuccess,
|
|
|
|
aOnError);
|
2012-09-20 12:54:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorUserMedia (mozGetUserMediaDevices)
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
|
|
|
|
nsIDOMGetUserMediaErrorCallback* aOnError)
|
|
|
|
{
|
|
|
|
// Check if the caller is chrome privileged, bail if not
|
2013-04-25 12:16:09 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2012-09-20 12:54:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:37:21 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
MozGetUserMediaDevices(aOnSuccess, aOnError, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::MozGetUserMediaDevices(MozGetUserMediaDevicesSuccessCallback* aOnSuccess,
|
|
|
|
MozDOMGetUserMediaErrorCallback* aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback,
|
|
|
|
nsIGetUserMediaDevicesSuccessCallback> holder1(aOnSuccess);
|
|
|
|
nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onsucces =
|
|
|
|
holder1.ToXPCOMCallback();
|
|
|
|
|
|
|
|
CallbackObjectHolder<MozDOMGetUserMediaErrorCallback,
|
|
|
|
nsIDOMGetUserMediaErrorCallback> holder2(aOnError);
|
|
|
|
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onerror = holder2.ToXPCOMCallback();
|
|
|
|
|
|
|
|
MozGetUserMediaDevices(onsucces, onerror, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
|
|
|
|
nsIDOMGetUserMediaErrorCallback* aOnError,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the chromeonly check here.
|
|
|
|
if (!mWindow || !mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-20 12:54:00 -07:00
|
|
|
MediaManager* manager = MediaManager::Get();
|
2013-07-12 07:37:21 -07:00
|
|
|
aRv = manager->GetUserMediaDevices(mWindow, aOnSuccess, aOnError);
|
2012-06-03 00:35:15 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorDesktopNotification
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2013-04-10 07:20:43 -07:00
|
|
|
NS_IMETHODIMP Navigator::GetMozNotification(nsISupports** aRetVal)
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
2013-07-12 07:35:44 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aRetVal = GetMozNotification(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2011-11-02 06:44:16 -07:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
DesktopNotificationCenter*
|
|
|
|
Navigator::GetMozNotification(ErrorResult& aRv)
|
|
|
|
{
|
2011-11-02 06:44:16 -07:00
|
|
|
if (mNotification) {
|
2013-07-12 07:35:44 -07:00
|
|
|
return mNotification;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
if (!mWindow || !mWindow->GetDocShell()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-02 06:44:16 -07:00
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
mNotification = new DesktopNotificationCenter(mWindow);
|
2013-07-12 07:35:44 -07:00
|
|
|
return mNotification;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 05:04:39 -07:00
|
|
|
//*****************************************************************************
|
2012-07-05 03:05:09 -07:00
|
|
|
// Navigator::nsINavigatorBattery
|
2011-11-02 05:04:39 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-05 04:54:49 -08:00
|
|
|
Navigator::GetBattery(nsISupports** aBattery)
|
2011-11-02 05:04:39 -07:00
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aBattery = GetBattery(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2011-11-19 02:37:21 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
battery::BatteryManager*
|
|
|
|
Navigator::GetBattery(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mBatteryManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2011-11-19 02:37:21 -08:00
|
|
|
|
2011-11-02 08:01:32 -07:00
|
|
|
mBatteryManager = new battery::BatteryManager();
|
2013-06-20 11:34:38 -07:00
|
|
|
mBatteryManager->Init(mWindow);
|
2011-11-02 08:01:32 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return mBatteryManager;
|
2011-11-02 05:04:39 -07:00
|
|
|
}
|
|
|
|
|
2012-01-19 19:24:00 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozPower(nsIDOMMozPowerManager** aPower)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
if (!PowerManager::CheckPermission(mWindow)) {
|
|
|
|
*aPower = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aPower = GetMozPower(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-03-07 03:03:25 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
nsIDOMMozPowerManager*
|
|
|
|
Navigator::GetMozPower(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
2012-01-19 19:24:00 -08:00
|
|
|
if (!mPowerManager) {
|
2013-07-12 07:35:35 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mPowerManager = PowerManager::CreateInstance(mWindow);
|
|
|
|
if (!mPowerManager) {
|
|
|
|
// We failed to get the power manager service?
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2012-01-19 19:24:00 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
return mPowerManager;
|
2012-01-19 19:24:00 -08:00
|
|
|
}
|
|
|
|
|
2012-03-07 03:03:25 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RequestWakeLock(const nsAString &aTopic, nsIDOMMozWakeLock **aWakeLock)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
*aWakeLock = RequestWakeLock(aTopic, rv).get();
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-03-07 03:03:25 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
already_AddRefed<nsIDOMMozWakeLock>
|
|
|
|
Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-03-07 03:03:25 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPowerManagerService> pmService =
|
|
|
|
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
2013-07-12 07:35:35 -07:00
|
|
|
// Maybe it went away for some reason... Or maybe we're just called
|
|
|
|
// from our XPCOM method.
|
|
|
|
NS_ENSURE_TRUE(pmService, nullptr);
|
2012-03-07 03:03:25 -08:00
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
nsCOMPtr<nsIDOMMozWakeLock> wakelock;
|
|
|
|
aRv = pmService->NewWakeLock(aTopic, mWindow, getter_AddRefs(wakelock));
|
|
|
|
return wakelock.forget();
|
2012-03-07 03:03:25 -08:00
|
|
|
}
|
|
|
|
|
2011-11-20 13:08:33 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorSms
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozSms(nsIDOMMozSmsManager** aSmsManager)
|
|
|
|
{
|
2013-07-12 07:35:44 -07:00
|
|
|
if (!mSmsManager) {
|
|
|
|
if (!mWindow || !SmsManager::CreationIsAllowed(mWindow)) {
|
|
|
|
*aSmsManager = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2011-11-24 16:48:57 -08:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
NS_IF_ADDREF(*aSmsManager = GetMozSms());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMMozSmsManager*
|
|
|
|
Navigator::GetMozSms()
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
2011-11-20 14:23:20 -08:00
|
|
|
if (!mSmsManager) {
|
2013-07-12 07:35:44 -07:00
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2011-11-24 16:48:57 -08:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
mSmsManager = SmsManager::CreateInstance(mWindow);
|
2011-11-20 14:23:20 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
return mSmsManager;
|
2011-11-20 13:08:33 -08:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorMobileMessage
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozMobileMessage(nsIDOMMozMobileMessageManager** aMobileMessageManager)
|
|
|
|
{
|
2013-07-12 07:35:44 -07:00
|
|
|
if (!HasMobileMessageSupport(mWindow)) {
|
|
|
|
*aMobileMessageManager = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
NS_IF_ADDREF(*aMobileMessageManager = GetMozMobileMessage());
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_OK;
|
2013-07-12 07:35:44 -07:00
|
|
|
}
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
nsIDOMMozMobileMessageManager*
|
|
|
|
Navigator::GetMozMobileMessage()
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
2013-03-08 23:21:47 -08:00
|
|
|
if (!mMobileMessageManager) {
|
2013-07-12 07:35:44 -07:00
|
|
|
// Check that our window has not gone away
|
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-03-08 23:21:47 -08:00
|
|
|
|
|
|
|
mMobileMessageManager = new MobileMessageManager();
|
2013-06-20 11:34:38 -07:00
|
|
|
mMobileMessageManager->Init(mWindow);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
return mMobileMessageManager;
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
2012-12-03 18:38:25 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIMozNavigatorCellBroadcast
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozCellBroadcast(nsIDOMMozCellBroadcast** aCellBroadcast)
|
|
|
|
{
|
2013-07-12 07:36:22 -07:00
|
|
|
if (!mCellBroadcast &&
|
|
|
|
!CheckPermission("cellbroadcast")) {
|
|
|
|
*aCellBroadcast = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-03 18:38:25 -08:00
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aCellBroadcast = GetMozCellBroadcast(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-12-03 18:38:25 -08:00
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
nsIDOMMozCellBroadcast*
|
|
|
|
Navigator::GetMozCellBroadcast(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (!mCellBroadcast) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-12-03 18:38:25 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
aRv = NS_NewCellBroadcast(mWindow, getter_AddRefs(mCellBroadcast));
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-12-03 18:38:25 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
return mCellBroadcast;
|
2012-12-03 18:38:25 -08:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorTelephony
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozTelephony(nsIDOMTelephony** aTelephony)
|
|
|
|
{
|
2013-07-12 07:36:13 -07:00
|
|
|
if (!mTelephony) {
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
2013-07-12 07:36:13 -07:00
|
|
|
if (!telephony::Telephony::CheckPermission(mWindow)) {
|
|
|
|
*aTelephony = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 14:28:47 -08:00
|
|
|
|
2013-07-12 07:36:13 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aTelephony = GetMozTelephony(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMTelephony*
|
|
|
|
Navigator::GetMozTelephony(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (!mTelephony) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mTelephony = telephony::Telephony::Create(mWindow, aRv);
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:13 -07:00
|
|
|
return mTelephony;
|
2012-01-09 14:28:47 -08:00
|
|
|
}
|
|
|
|
|
2013-02-05 01:02:15 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsINavigatorVoicemail
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2012-07-18 20:27:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozVoicemail(nsIDOMMozVoicemail** aVoicemail)
|
|
|
|
{
|
2013-07-12 07:36:22 -07:00
|
|
|
if (!mVoicemail &&
|
|
|
|
!CheckPermission("voicemail")) {
|
|
|
|
*aVoicemail = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aVoicemail = GetMozVoicemail(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMMozVoicemail*
|
|
|
|
Navigator::GetMozVoicemail(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
2012-07-18 20:27:19 -07:00
|
|
|
if (!mVoicemail) {
|
2013-07-12 07:36:22 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
aRv = NS_NewVoicemail(mWindow, getter_AddRefs(mVoicemail));
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
return mVoicemail;
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
2013-04-08 03:34:10 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIMozNavigatorIccManager
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozIccManager(nsIDOMMozIccManager** aIccManager)
|
|
|
|
{
|
2013-07-12 07:36:22 -07:00
|
|
|
if (!mIccManager &&
|
|
|
|
!CheckPermission("mobileconnection")) {
|
|
|
|
*aIccManager = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-04-08 03:34:10 -07:00
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aIccManager = GetMozIccManager(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2013-04-08 03:34:10 -07:00
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
nsIDOMMozIccManager*
|
|
|
|
Navigator::GetMozIccManager(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (!mIccManager) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2013-04-08 03:34:10 -07:00
|
|
|
}
|
2013-07-12 07:36:22 -07:00
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2013-04-08 03:34:10 -07:00
|
|
|
|
|
|
|
mIccManager = new icc::IccManager();
|
2013-06-20 11:34:38 -07:00
|
|
|
mIccManager->Init(mWindow);
|
2013-04-08 03:34:10 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
return mIccManager;
|
2013-04-08 03:34:10 -07:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2012-02-15 16:47:13 -08:00
|
|
|
#ifdef MOZ_GAMEPAD
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorGamepads
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetGamepads(nsIVariant** aRetVal)
|
|
|
|
{
|
2013-07-12 07:36:32 -07:00
|
|
|
ErrorResult rv;
|
2012-02-15 16:47:13 -08:00
|
|
|
nsAutoTArray<nsRefPtr<Gamepad>, 2> gamepads;
|
2013-07-12 07:36:32 -07:00
|
|
|
GetGamepads(gamepads, rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-02-15 16:47:13 -08:00
|
|
|
|
|
|
|
nsRefPtr<nsVariant> out = new nsVariant();
|
|
|
|
NS_ENSURE_STATE(out);
|
|
|
|
|
|
|
|
if (gamepads.Length() == 0) {
|
|
|
|
nsresult rv = out->SetAsEmptyArray();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
out->SetAsArray(nsIDataType::VTYPE_INTERFACE,
|
|
|
|
&NS_GET_IID(nsISupports),
|
|
|
|
gamepads.Length(),
|
|
|
|
const_cast<void*>(static_cast<const void*>(gamepads.Elements())));
|
|
|
|
}
|
|
|
|
out.forget(aRetVal);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-07-12 07:36:32 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
Navigator::GetGamepads(nsTArray<nsRefPtr<Gamepad> >& aGamepads,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(mWindow->GetDocShell());
|
|
|
|
nsGlobalWindow* win = static_cast<nsGlobalWindow*>(mWindow.get());
|
|
|
|
win->GetGamepads(aGamepads);
|
|
|
|
}
|
2012-02-15 16:47:13 -08:00
|
|
|
#endif
|
|
|
|
|
2012-01-16 04:23:28 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorNetwork
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozConnection(nsIDOMMozConnection** aConnection)
|
|
|
|
{
|
2013-07-12 07:35:44 -07:00
|
|
|
NS_IF_ADDREF(*aConnection = GetMozConnection());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-01-16 09:14:56 -08:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
nsIDOMMozConnection*
|
|
|
|
Navigator::GetMozConnection()
|
|
|
|
{
|
2012-01-16 04:23:44 -08:00
|
|
|
if (!mConnection) {
|
2013-07-12 07:35:44 -07:00
|
|
|
NS_ENSURE_TRUE(mWindow, nullptr);
|
|
|
|
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
2012-01-16 09:14:56 -08:00
|
|
|
|
2012-01-16 04:23:44 -08:00
|
|
|
mConnection = new network::Connection();
|
2013-06-20 11:34:38 -07:00
|
|
|
mConnection->Init(mWindow);
|
2012-01-16 04:23:44 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
return mConnection;
|
2012-01-16 04:23:28 -08:00
|
|
|
}
|
|
|
|
|
2012-08-27 10:34:10 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorMobileConnection
|
|
|
|
//*****************************************************************************
|
2012-04-19 14:33:25 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozMobileConnection(nsIDOMMozMobileConnection** aMobileConnection)
|
|
|
|
{
|
2013-07-12 07:36:22 -07:00
|
|
|
if (!mMobileConnection &&
|
|
|
|
!CheckPermission("mobileconnection") &&
|
|
|
|
!CheckPermission("mobilenetwork")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aMobileConnection = GetMozMobileConnection(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-04-19 14:33:25 -07:00
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
nsIDOMMozMobileConnection*
|
|
|
|
Navigator::GetMozMobileConnection(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
2012-04-19 14:33:25 -07:00
|
|
|
if (!mMobileConnection) {
|
2013-07-12 07:36:22 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
2012-08-07 22:18:27 -07:00
|
|
|
}
|
2012-04-19 14:33:25 -07:00
|
|
|
mMobileConnection = new network::MobileConnection();
|
2013-06-20 11:34:38 -07:00
|
|
|
mMobileConnection->Init(mWindow);
|
2012-04-19 14:33:25 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:22 -07:00
|
|
|
return mMobileConnection;
|
2012-04-19 14:33:25 -07:00
|
|
|
}
|
2012-08-27 10:34:10 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
2012-04-19 14:33:25 -07:00
|
|
|
|
2012-02-20 07:15:19 -08:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorBluetooth
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-05-23 21:02:23 -07:00
|
|
|
Navigator::GetMozBluetooth(nsIDOMBluetoothManager** aBluetooth)
|
2012-02-20 07:15:19 -08:00
|
|
|
{
|
2013-07-12 07:36:32 -07:00
|
|
|
if (!mBluetooth) {
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
2013-07-12 07:36:32 -07:00
|
|
|
if (!bluetooth::BluetoothManager::CheckPermission(mWindow)) {
|
|
|
|
*aBluetooth = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 07:15:19 -08:00
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aBluetooth = GetMozBluetooth(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMBluetoothManager*
|
|
|
|
Navigator::GetMozBluetooth(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (!mBluetooth) {
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
mBluetooth = bluetooth::BluetoothManager::Create(mWindow);
|
2012-02-20 07:15:19 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
return mBluetooth;
|
2012-02-20 07:15:19 -08:00
|
|
|
}
|
|
|
|
#endif //MOZ_B2G_BT
|
|
|
|
|
2012-07-02 17:16:55 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorSystemMessages
|
|
|
|
//*****************************************************************************
|
2012-07-22 23:53:08 -07:00
|
|
|
nsresult
|
2012-07-02 17:16:55 -07:00
|
|
|
Navigator::EnsureMessagesManager()
|
|
|
|
{
|
|
|
|
if (mMessagesManager) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-20 11:34:38 -07:00
|
|
|
NS_ENSURE_STATE(mWindow);
|
2012-07-02 17:16:55 -07:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNavigatorSystemMessages> messageManager =
|
|
|
|
do_CreateInstance("@mozilla.org/system-message-manager;1", &rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi =
|
|
|
|
do_QueryInterface(messageManager);
|
|
|
|
NS_ENSURE_TRUE(gpi, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// We don't do anything with the return value.
|
2013-05-29 13:16:04 -07:00
|
|
|
AutoJSContext cx;
|
|
|
|
JS::Rooted<JS::Value> prop_val(cx);
|
2013-06-20 11:34:38 -07:00
|
|
|
rv = gpi->Init(mWindow, prop_val.address());
|
2012-07-02 17:16:55 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mMessagesManager = messageManager.forget();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozHasPendingMessage(const nsAString& aType, bool *aResult)
|
|
|
|
{
|
2013-04-30 06:01:46 -07:00
|
|
|
if (!Preferences::GetBool("dom.sysmsg.enabled", false)) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
*aResult = MozHasPendingMessage(aType, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Navigator::MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
2012-07-02 17:16:55 -07:00
|
|
|
nsresult rv = EnsureMessagesManager();
|
2013-07-12 07:35:44 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-02 17:16:55 -07:00
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
bool result = false;
|
|
|
|
rv = mMessagesManager->MozHasPendingMessage(aType, &result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return result;
|
2012-07-02 17:16:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozSetMessageHandler(const nsAString& aType,
|
|
|
|
nsIDOMSystemMessageCallback *aCallback)
|
|
|
|
{
|
2013-04-30 06:01:46 -07:00
|
|
|
if (!Preferences::GetBool("dom.sysmsg.enabled", false)) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-07-02 17:16:55 -07:00
|
|
|
nsresult rv = EnsureMessagesManager();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mMessagesManager->MozSetMessageHandler(aType, aCallback);
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
void
|
|
|
|
Navigator::MozSetMessageHandler(const nsAString& aType,
|
|
|
|
systemMessageCallback* aCallback,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// The WebIDL binding is responsible for the pref check here.
|
|
|
|
nsresult rv = EnsureMessagesManager();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CallbackObjectHolder<systemMessageCallback, nsIDOMSystemMessageCallback>
|
|
|
|
holder(aCallback);
|
|
|
|
nsCOMPtr<nsIDOMSystemMessageCallback> callback = holder.ToXPCOMCallback();
|
|
|
|
|
|
|
|
rv = mMessagesManager->MozSetMessageHandler(aType, callback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 23:05:00 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorTime
|
|
|
|
//*****************************************************************************
|
2012-11-05 07:20:03 -08:00
|
|
|
#ifdef MOZ_TIME_MANAGER
|
2012-09-10 23:05:00 -07:00
|
|
|
NS_IMETHODIMP
|
2013-06-12 00:00:07 -07:00
|
|
|
Navigator::GetMozTime(nsISupports** aTime)
|
2012-09-10 23:05:00 -07:00
|
|
|
{
|
2012-10-02 02:08:02 -07:00
|
|
|
if (!CheckPermission("time")) {
|
2012-09-10 23:05:00 -07:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aTime = GetMozTime(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
time::TimeManager*
|
|
|
|
Navigator::GetMozTime(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-10 23:05:00 -07:00
|
|
|
if (!mTimeManager) {
|
2013-06-20 11:34:38 -07:00
|
|
|
mTimeManager = new time::TimeManager(mWindow);
|
2012-09-10 23:05:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
return mTimeManager;
|
2012-09-10 23:05:00 -07:00
|
|
|
}
|
2012-11-05 07:20:03 -08:00
|
|
|
#endif
|
2012-09-10 23:05:00 -07:00
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorCamera
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-05-14 03:59:11 -07:00
|
|
|
Navigator::GetMozCameras(nsISupports** aCameraManager)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2013-07-12 07:35:44 -07:00
|
|
|
if (!mCameraManager) {
|
|
|
|
NS_ENSURE_STATE(mWindow);
|
|
|
|
if (!nsDOMCameraManager::CheckPermission(mWindow)) {
|
|
|
|
*aCameraManager = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aCameraManager = static_cast<nsIObserver*>(GetMozCameras(rv)));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMCameraManager*
|
|
|
|
Navigator::GetMozCameras(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
// Callers (either the XPCOM method or the WebIDL binding) are responsible for
|
|
|
|
// the permission check here.
|
2012-07-30 14:59:05 -07:00
|
|
|
if (!mCameraManager) {
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow ||
|
|
|
|
!mWindow->GetOuterWindow() ||
|
|
|
|
mWindow->GetOuterWindow()->GetCurrentInnerWindow() != mWindow) {
|
2013-07-12 07:35:44 -07:00
|
|
|
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return nullptr;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
mCameraManager = nsDOMCameraManager::CreateInstance(mWindow);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
return mCameraManager;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
Navigator::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
2012-02-01 13:58:01 -08:00
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsMimeTypeArray, bug 674113.
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsPluginArray, bug 674114.
|
2013-04-12 11:47:47 -07:00
|
|
|
// TODO: add SizeOfIncludingThis() to Geolocation, bug 674115.
|
2013-04-10 07:20:43 -07:00
|
|
|
// TODO: add SizeOfIncludingThis() to DesktopNotificationCenter, bug 674116.
|
2012-02-01 13:58:01 -08:00
|
|
|
|
|
|
|
return n;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 05:39:55 -08:00
|
|
|
void
|
|
|
|
Navigator::SetWindow(nsPIDOMWindow *aInnerWindow)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInnerWindow->IsInnerWindow(),
|
|
|
|
"Navigator must get an inner window!");
|
2013-06-20 11:34:38 -07:00
|
|
|
mWindow = aInnerWindow;
|
2011-12-28 05:39:55 -08:00
|
|
|
}
|
|
|
|
|
2012-06-03 00:35:15 -07:00
|
|
|
void
|
|
|
|
Navigator::OnNavigation()
|
|
|
|
{
|
2013-06-20 11:34:38 -07:00
|
|
|
if (!mWindow) {
|
2012-07-30 14:59:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-03 00:35:15 -07:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
2012-07-30 14:59:05 -07:00
|
|
|
// Inform MediaManager in case there are live streams or pending callbacks.
|
2012-06-03 00:35:15 -07:00
|
|
|
MediaManager *manager = MediaManager::Get();
|
2013-02-07 19:14:21 -08:00
|
|
|
if (manager) {
|
2013-06-20 11:34:38 -07:00
|
|
|
manager->OnNavigation(mWindow->WindowID());
|
2013-02-07 19:14:21 -08:00
|
|
|
}
|
2012-06-03 00:35:15 -07:00
|
|
|
#endif
|
2012-07-30 14:59:05 -07:00
|
|
|
if (mCameraManager) {
|
2013-06-20 11:34:38 -07:00
|
|
|
mCameraManager->OnNavigation(mWindow->WindowID());
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2012-06-03 00:35:15 -07:00
|
|
|
}
|
|
|
|
|
2012-10-02 02:08:02 -07:00
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(const char* type)
|
|
|
|
{
|
2013-07-12 07:35:35 -07:00
|
|
|
return CheckPermission(mWindow, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType)
|
|
|
|
{
|
|
|
|
if (!aWindow) {
|
2013-06-20 11:34:38 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-02 02:08:02 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
|
|
|
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
2013-07-12 07:35:35 -07:00
|
|
|
permMgr->TestPermissionFromWindow(aWindow, aType, &permission);
|
2012-10-02 02:08:02 -07:00
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
2012-11-29 14:52:03 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorAudioChannelManager
|
|
|
|
//*****************************************************************************
|
|
|
|
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
|
|
|
|
NS_IMETHODIMP
|
2013-02-08 08:34:47 -08:00
|
|
|
Navigator::GetMozAudioChannelManager(nsISupports** aAudioChannelManager)
|
2012-11-29 14:52:03 -08:00
|
|
|
{
|
2013-07-12 07:36:32 -07:00
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aAudioChannelManager = GetMozAudioChannelManager(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2012-11-29 14:52:03 -08:00
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
system::AudioChannelManager*
|
|
|
|
Navigator::GetMozAudioChannelManager(ErrorResult& aRv)
|
|
|
|
{
|
2012-11-29 14:52:03 -08:00
|
|
|
if (!mAudioChannelManager) {
|
2013-07-12 07:36:32 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-11-29 14:52:03 -08:00
|
|
|
mAudioChannelManager = new system::AudioChannelManager();
|
2013-06-20 11:34:38 -07:00
|
|
|
mAudioChannelManager->Init(mWindow);
|
2012-11-29 14:52:03 -08:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
return mAudioChannelManager;
|
2012-11-29 14:52:03 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-12 07:37:23 -07:00
|
|
|
bool
|
|
|
|
Navigator::DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObject,
|
2013-07-15 22:31:03 -07:00
|
|
|
JS::Handle<jsid> aId,
|
|
|
|
JS::MutableHandle<JS::Value> aValue)
|
2013-07-12 07:37:23 -07:00
|
|
|
{
|
|
|
|
if (!JSID_IS_STRING(aId)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScriptNameSpaceManager *nameSpaceManager =
|
|
|
|
nsJSRuntime::GetNameSpaceManager();
|
|
|
|
if (!nameSpaceManager) {
|
|
|
|
return Throw<true>(aCx, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentJSString name(aId);
|
|
|
|
|
|
|
|
const nsGlobalNameStruct* name_struct =
|
|
|
|
nameSpaceManager->LookupNavigatorName(name);
|
|
|
|
if (!name_struct) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name_struct->mType == nsGlobalNameStruct::eTypeNewDOMBinding) {
|
|
|
|
ConstructNavigatorProperty construct = name_struct->mConstructNavigatorProperty;
|
|
|
|
MOZ_ASSERT(construct);
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> naviObj(aCx,
|
|
|
|
js::CheckedUnwrap(aObject,
|
|
|
|
/* stopAtOuter = */ false));
|
|
|
|
if (!naviObj) {
|
|
|
|
return Throw<true>(aCx, NS_ERROR_DOM_SECURITY_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> domObject(aCx);
|
|
|
|
{
|
|
|
|
JSAutoCompartment ac(aCx, naviObj);
|
|
|
|
|
|
|
|
// Check whether our constructor is enabled after we unwrap Xrays, since
|
|
|
|
// we don't want to define an interface on the Xray if it's disabled in
|
|
|
|
// the target global, even if it's enabled in the Xray's global.
|
|
|
|
if (name_struct->mConstructorEnabled &&
|
|
|
|
!(*name_struct->mConstructorEnabled)(aCx, naviObj)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
domObject = construct(aCx, naviObj);
|
|
|
|
if (!domObject) {
|
|
|
|
return Throw<true>(aCx, NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:31:03 -07:00
|
|
|
if (!JS_WrapObject(aCx, domObject.address())) {
|
2013-07-12 07:37:23 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:31:03 -07:00
|
|
|
aValue.setObject(*domObject);
|
2013-07-12 07:37:23 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeNavigatorProperty,
|
|
|
|
"unexpected type");
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> native(do_CreateInstance(name_struct->mCID, &rv));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Throw<true>(aCx, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JS::Value> prop_val(aCx, JS::UndefinedValue()); // Property value.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi(do_QueryInterface(native));
|
|
|
|
|
|
|
|
if (gpi) {
|
|
|
|
if (!mWindow) {
|
|
|
|
return Throw<true>(aCx, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = gpi->Init(mWindow, prop_val.address());
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Throw<true>(aCx, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JSVAL_IS_PRIMITIVE(prop_val) && !JSVAL_IS_NULL(prop_val)) {
|
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
|
|
|
rv = nsContentUtils::WrapNative(aCx, aObject, native, prop_val.address(),
|
|
|
|
getter_AddRefs(holder), true);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Throw<true>(aCx, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JS_WrapValue(aCx, prop_val.address())) {
|
|
|
|
return Throw<true>(aCx, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:31:03 -07:00
|
|
|
aValue.set(prop_val);
|
|
|
|
return true;
|
2013-07-12 07:37:23 -07:00
|
|
|
}
|
|
|
|
|
2013-07-12 07:37:23 -07:00
|
|
|
JSObject*
|
|
|
|
Navigator::WrapObject(JSContext* cx, JS::Handle<JSObject*> scope)
|
|
|
|
{
|
|
|
|
return NavigatorBinding::Wrap(cx, scope, this);
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */)
|
|
|
|
{
|
|
|
|
return battery::BatteryManager::HasSupport();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && PowerManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return CheckPermission(win, "idle");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPowerManagerService> pmService =
|
|
|
|
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
// No service means no wake lock support
|
|
|
|
return !!pmService;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:44 -07:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasSmsSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && SmsManager::CreationIsAllowed(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasMobileMessageSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return HasMobileMessageSupport(win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasMobileMessageSupport(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
#ifndef MOZ_WEBSMS_BACKEND
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// First of all, the general pref has to be turned on.
|
|
|
|
bool enabled = false;
|
|
|
|
Preferences::GetBool("dom.sms.enabled", &enabled);
|
|
|
|
NS_ENSURE_TRUE(enabled, false);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aWindow, false);
|
|
|
|
NS_ENSURE_TRUE(aWindow->GetDocShell(), false);
|
|
|
|
|
|
|
|
if (!CheckPermission(aWindow, "sms")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasCameraSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && nsDOMCameraManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:36:13 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasTelephonySupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && telephony::Telephony::CheckPermission(win);
|
|
|
|
}
|
2013-07-12 07:36:22 -07:00
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasMobileConnectionSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && (CheckPermission(win, "mobileconnection") ||
|
|
|
|
CheckPermission(win, "mobilenetwork"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasCellBroadcastSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "cellbroadcast");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasVoicemailSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "voicemail");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasIccManagerSupport(JSContext* /* unused */,
|
|
|
|
JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "mobileconnection");
|
|
|
|
}
|
2013-07-12 07:36:13 -07:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2013-07-12 07:36:32 -07:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasBluetoothSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && bluetooth::BluetoothManager::CheckPermission(win);
|
|
|
|
}
|
|
|
|
#endif // MOZ_B2G_BT
|
|
|
|
|
|
|
|
#ifdef MOZ_TIME_MANAGER
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
Navigator::HasTimeSupport(JSContext* /* unused */, JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
|
|
|
|
return win && CheckPermission(win, "time");
|
|
|
|
}
|
|
|
|
#endif // MOZ_TIME_MANAGER
|
|
|
|
|
2013-07-12 07:37:21 -07:00
|
|
|
#ifdef MOZ_MEDIA_NAVIGATOR
|
|
|
|
/* static */
|
|
|
|
bool Navigator::HasUserMediaSupport(JSContext* /* unused */,
|
|
|
|
JSObject* /* unused */)
|
|
|
|
{
|
|
|
|
// Make enabling peerconnection enable getUserMedia() as well
|
|
|
|
return Preferences::GetBool("media.navigator.enabled", false) ||
|
|
|
|
Preferences::GetBool("media.peerconnection.enabled", false);
|
|
|
|
}
|
|
|
|
#endif // MOZ_MEDIA_NAVIGATOR
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsPIDOMWindow>
|
|
|
|
Navigator::GetWindowFromGlobal(JSObject* aGlobal)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win =
|
|
|
|
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal));
|
|
|
|
MOZ_ASSERT(!win || win->IsInnerWindow());
|
|
|
|
return win.forget();
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_GetNavigatorUserAgent(nsAString& aUserAgent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString ua;
|
2011-11-02 06:44:16 -07:00
|
|
|
rv = service->GetUserAgent(ua);
|
|
|
|
CopyASCIItoUTF16(ua, aUserAgent);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_GetNavigatorPlatform(nsAString& aPlatform)
|
|
|
|
{
|
2012-10-25 16:10:53 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.platform.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aPlatform = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Sorry for the #if platform ugliness, but Communicator is likewise
|
|
|
|
// hardcoded and we are seeking backward compatibility here (bug 47080).
|
|
|
|
#if defined(_WIN64)
|
|
|
|
aPlatform.AssignLiteral("Win64");
|
|
|
|
#elif defined(WIN32)
|
|
|
|
aPlatform.AssignLiteral("Win32");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__ppc__)
|
|
|
|
aPlatform.AssignLiteral("MacPPC");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__i386__)
|
|
|
|
aPlatform.AssignLiteral("MacIntel");
|
|
|
|
#elif defined(XP_MACOSX) && defined(__x86_64__)
|
|
|
|
aPlatform.AssignLiteral("MacIntel");
|
|
|
|
#elif defined(XP_OS2)
|
|
|
|
aPlatform.AssignLiteral("OS/2");
|
|
|
|
#else
|
|
|
|
// XXX Communicator uses compiled-in build-time string defines
|
|
|
|
// to indicate the platform it was compiled *for*, not what it is
|
|
|
|
// currently running *on* which is what this does.
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString plat;
|
2011-11-02 06:44:16 -07:00
|
|
|
rv = service->GetOscpu(plat);
|
|
|
|
CopyASCIItoUTF16(plat, aPlatform);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsresult
|
|
|
|
NS_GetNavigatorAppVersion(nsAString& aAppVersion)
|
|
|
|
{
|
2012-10-25 16:10:53 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appversion.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppVersion = override;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpProtocolHandler>
|
|
|
|
service(do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString str;
|
2011-11-02 06:44:16 -07:00
|
|
|
rv = service->GetAppVersion(str);
|
|
|
|
CopyASCIItoUTF16(str, aAppVersion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aAppVersion.AppendLiteral(" (");
|
|
|
|
|
|
|
|
rv = service->GetPlatform(str);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AppendASCIItoUTF16(str, aAppVersion);
|
|
|
|
aAppVersion.Append(PRUnichar(')'));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 07:35:35 -07:00
|
|
|
void
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_GetNavigatorAppName(nsAString& aAppName)
|
|
|
|
{
|
2012-10-25 16:10:53 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
const nsAdoptingString& override =
|
|
|
|
mozilla::Preferences::GetString("general.appname.override");
|
|
|
|
|
|
|
|
if (override) {
|
|
|
|
aAppName = override;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aAppName.AssignLiteral("Netscape");
|
|
|
|
}
|