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"
|
|
|
|
#include "nsDesktopNotification.h"
|
|
|
|
#include "nsGeolocation.h"
|
|
|
|
#include "nsIHttpProtocolHandler.h"
|
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIWebContentHandlerRegistrar.h"
|
|
|
|
#include "nsICookiePermission.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#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"
|
2011-11-20 14:23:20 -08:00
|
|
|
#include "SmsManager.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"
|
2012-08-27 10:34:10 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-04-19 14:33:25 -07:00
|
|
|
#include "MobileConnection.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
|
|
|
|
#include "TelephonyFactory.h"
|
|
|
|
#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-07-02 17:16:55 -07:00
|
|
|
#include "nsIDOMGlobalPropertyInitializer.h"
|
|
|
|
|
2012-08-11 04:40:43 -07:00
|
|
|
using namespace mozilla::dom::power;
|
2012-08-22 10:30:27 -07:00
|
|
|
using namespace mozilla::dom::sms;
|
2012-08-11 04:40:43 -07:00
|
|
|
|
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 {
|
|
|
|
|
|
|
|
static const char sJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1";
|
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)
|
|
|
|
: mWindow(do_GetWeakReference(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!");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(Navigator)
|
|
|
|
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)
|
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)
|
|
|
|
#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)
|
|
|
|
#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-09-10 23:05:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorTime)
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Navigator)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(Navigator)
|
|
|
|
NS_IMPL_RELEASE(Navigator)
|
|
|
|
|
|
|
|
void
|
2011-12-01 00:28:16 -08:00
|
|
|
Navigator::Invalidate()
|
2011-11-02 06:44:16 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mWindow = nullptr;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
#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-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
|
|
|
#ifdef MOZ_SYS_MSG
|
|
|
|
if (mMessagesManager) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mMessagesManager = nullptr;
|
2012-07-02 17:16:55 -07:00
|
|
|
}
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
nsPIDOMWindow *
|
|
|
|
Navigator::GetWindow()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
if (!win || !win->GetDocShell()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = win->GetExtantDoc();
|
|
|
|
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);
|
|
|
|
|
|
|
|
return siteSpecificUA->GetUserAgentForURI(codebaseURI, 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)
|
|
|
|
{
|
|
|
|
return NS_GetNavigatorAppName(aAppName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
Navigator::GetMimeTypes(nsIDOMMimeTypeArray** aMimeTypes)
|
|
|
|
{
|
|
|
|
if (!mMimeTypes) {
|
|
|
|
mMimeTypes = new nsMimeTypeArray(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aMimeTypes = mMimeTypes);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetPlugins(nsIDOMPluginArray** aPlugins)
|
|
|
|
{
|
|
|
|
if (!mPlugins) {
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mPlugins = new nsPluginArray(this, win ? win->GetDocShell() : nullptr);
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aPlugins = mPlugins);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Values for the network.cookie.cookieBehavior pref are documented in
|
|
|
|
// nsCookieService.cpp.
|
|
|
|
#define COOKIE_BEHAVIOR_REJECT 2
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetCookieEnabled(bool* aCookieEnabled)
|
|
|
|
{
|
|
|
|
*aCookieEnabled =
|
|
|
|
(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.
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
|
|
|
|
if (!win || !win->GetDocShell()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(win->GetExtantDocument());
|
2011-11-02 06:44:16 -07:00
|
|
|
if (!doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICookiePermission> permMgr =
|
|
|
|
do_GetService(NS_COOKIEPERMISSION_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(permMgr, NS_OK);
|
|
|
|
|
|
|
|
// 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);
|
2011-11-02 06:44:16 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
|
|
|
if (access != nsICookiePermission::ACCESS_DEFAULT) {
|
|
|
|
*aCookieEnabled = access != nsICookiePermission::ACCESS_DENY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetOnLine(bool* aOnline)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aOnline, "Null out param");
|
|
|
|
|
|
|
|
*aOnline = !NS_IsOffline();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> telemetryTimer;
|
|
|
|
// Return true if we have a handler for "application/x-java-vm",
|
|
|
|
// otherwise return false.
|
|
|
|
*aReturn = false;
|
|
|
|
|
|
|
|
if (!mMimeTypes) {
|
|
|
|
mMimeTypes = new nsMimeTypeArray(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshMIMEArray();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count;
|
2011-11-02 06:44:16 -07:00
|
|
|
mMimeTypes->GetLength(&count);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2011-11-02 06:44:16 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsIDOMMimeType* type = mMimeTypes->GetItemAt(i, &rv);
|
2011-11-02 04:04:28 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
nsAutoString mimeString;
|
2011-11-02 04:04:28 -07:00
|
|
|
if (NS_FAILED(type->GetType(mimeString))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mimeString.EqualsLiteral("application/x-java-vm")) {
|
|
|
|
*aReturn = true;
|
|
|
|
break;
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-05 08:24:10 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::TaintEnabled(bool *aReturn)
|
|
|
|
{
|
|
|
|
*aReturn = false;
|
|
|
|
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:
|
|
|
|
VibrateWindowListener(nsIDOMWindow *aWindow, nsIDOMDocument *aDocument)
|
|
|
|
{
|
|
|
|
mWindow = do_GetWeakReference(aWindow);
|
|
|
|
mDocument = do_GetWeakReference(aDocument);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aDocument);
|
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "mozvisibilitychange");
|
|
|
|
target->AddSystemEventListener(visibilitychange,
|
|
|
|
this, /* listener */
|
|
|
|
true, /* use capture */
|
|
|
|
false /* wants untrusted */);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
aEvent->GetTarget(getter_AddRefs(target));
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(target);
|
|
|
|
|
|
|
|
bool hidden = true;
|
|
|
|
if (doc) {
|
|
|
|
doc->GetMozHidden(&hidden);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hidden) {
|
|
|
|
// 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()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target = do_QueryReferent(mDocument);
|
|
|
|
if (!target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_NAMED_LITERAL_STRING(visibilitychange, "mozvisibilitychange");
|
|
|
|
target->RemoveSystemEventListener(visibilitychange, this,
|
|
|
|
true /* use capture */);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a jsval into a vibration duration, checking that the duration is in
|
|
|
|
* bounds (non-negative and not larger than sMaxVibrateMS).
|
|
|
|
*
|
|
|
|
* Returns true on success, false on failure.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
GetVibrationDurationFromJsval(const jsval& 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)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
|
|
|
|
NS_WARNING("The IdleObserver API has been disabled.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aIdleObserver);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED);
|
2012-08-06 09:10:58 -07:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-06-29 01:32:21 -07:00
|
|
|
if (NS_FAILED(win->RegisterIdleObserver(aIdleObserver))) {
|
|
|
|
NS_WARNING("Failed to add idle observer.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RemoveIdleObserver(nsIIdleObserver* aIdleObserver)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsIdleObserverAPIEnabled()) {
|
|
|
|
NS_WARNING("The IdleObserver API has been disabled");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aIdleObserver);
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(win, NS_ERROR_UNEXPECTED);
|
|
|
|
if (NS_FAILED(win->UnregisterIdleObserver(aIdleObserver))) {
|
|
|
|
NS_WARNING("Failed to remove idle observer.");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:26:36 -08:00
|
|
|
NS_IMETHODIMP
|
2012-07-05 03:04:45 -07:00
|
|
|
Navigator::Vibrate(const jsval& aPattern, JSContext* cx)
|
2011-11-10 13:26:36 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(win, NS_OK);
|
|
|
|
|
|
|
|
nsIDOMDocument* domDoc = win->GetExtantDocument();
|
|
|
|
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
bool hidden = true;
|
|
|
|
domDoc->GetMozHidden(&hidden);
|
|
|
|
if (hidden) {
|
|
|
|
// Hidden documents cannot start or stop a vibration.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
JSObject *obj = JSVAL_TO_OBJECT(aPattern);
|
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) {
|
2011-11-10 13:26:36 -08:00
|
|
|
jsval v;
|
2012-05-25 00:18:30 -07:00
|
|
|
int32_t pv;
|
2011-11-10 13:26:36 -08:00
|
|
|
if (JS_GetElement(cx, obj, i, &v) &&
|
|
|
|
GetVibrationDurationFromJsval(v, cx, &pv)) {
|
|
|
|
pattern[i] = pv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The spec says we check sVibratorEnabled after we've done the sanity
|
|
|
|
// checking on the pattern.
|
|
|
|
if (!sVibratorEnabled) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a listener to cancel the vibration if the document becomes hidden,
|
|
|
|
// and remove the old mozvisibility listener, if there was one.
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
gVibrateWindowListener = new VibrateWindowListener(win, domDoc);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow =
|
|
|
|
do_QueryInterface(static_cast<nsIDOMWindow*>(win));
|
|
|
|
hal::Vibrate(pattern, domWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMClientInformation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RegisterContentHandler(const nsAString& aMIMEType,
|
|
|
|
const nsAString& aURI,
|
|
|
|
const nsAString& aTitle)
|
|
|
|
{
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
|
|
|
|
if (!win || !win->GetOuterWindow() || !win->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,
|
2011-12-01 00:28:16 -08:00
|
|
|
win->GetOuterWindow());
|
2011-11-02 06:44:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
|
|
|
const nsAString& aURI,
|
|
|
|
const nsAString& aTitle)
|
|
|
|
{
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
|
|
|
|
if (!win || !win->GetOuterWindow() || !win->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,
|
2011-12-01 00:28:16 -08:00
|
|
|
win->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.
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack = do_GetService(sJSStackContractID);
|
|
|
|
NS_ENSURE_TRUE(stack, NS_ERROR_FAILURE);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
JSContext* cx = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
rv = stack->Peek(&cx);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-17 08:24:38 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
if (!win) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
nsCOMPtr<nsIDocument> doc = win->GetDoc();
|
|
|
|
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)
|
2012-05-21 09:18:30 -07:00
|
|
|
{
|
|
|
|
if (!Preferences::GetBool("device.storage.enabled", false)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
|
|
|
|
|
|
|
if (!win || !win->GetOuterWindow() || !win->GetDocShell()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:32:11 -07:00
|
|
|
nsRefPtr<nsDOMDeviceStorage> storage;
|
|
|
|
nsDOMDeviceStorage::CreateDeviceStoragesFor(win, aType, getter_AddRefs(storage));
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-08-01 23:32:11 -07:00
|
|
|
if (!storage) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-01 23:29:34 -07:00
|
|
|
|
2012-08-01 23:32:11 -07:00
|
|
|
NS_ADDREF(*_retval = storage.get());
|
2012-09-20 12:54:00 -07:00
|
|
|
mDeviceStorageStores.AppendElement(storage);
|
2012-05-21 09:18:30 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorGeolocation
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP Navigator::GetGeolocation(nsIDOMGeoGeolocation** _retval)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2012-07-30 07:20:58 -07:00
|
|
|
*_retval = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
if (!Preferences::GetBool("geo.enabled", true)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mGeolocation) {
|
|
|
|
NS_ADDREF(*_retval = mGeolocation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
2011-11-02 06:44:16 -07:00
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
if (!win || !win->GetOuterWindow() || !win->GetDocShell()) {
|
2011-11-02 06:44:16 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGeolocation = new nsGeolocation();
|
|
|
|
if (!mGeolocation) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
if (NS_FAILED(mGeolocation->Init(win->GetOuterWindow()))) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mGeolocation = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = mGeolocation);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
2012-09-20 12:54:00 -07:00
|
|
|
if (!win || !win->GetOuterWindow() ||
|
|
|
|
win->GetOuterWindow()->GetCurrentInnerWindow() != win) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2012-06-03 00:35:15 -07:00
|
|
|
|
2012-09-20 12:54:00 -07:00
|
|
|
bool privileged = nsContentUtils::IsChromeDoc(win->GetExtantDoc());
|
|
|
|
|
|
|
|
MediaManager* manager = MediaManager::Get();
|
|
|
|
return manager->GetUserMedia(privileged, win, aParams, aOnSuccess, aOnError);
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsINavigatorUserMedia (mozGetUserMediaDevices)
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozGetUserMediaDevices(nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
|
|
|
|
nsIDOMGetUserMediaErrorCallback* aOnError)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
2012-06-03 00:35:15 -07:00
|
|
|
if (!win || !win->GetOuterWindow() ||
|
|
|
|
win->GetOuterWindow()->GetCurrentInnerWindow() != win) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-09-20 12:54:00 -07:00
|
|
|
// Check if the caller is chrome privileged, bail if not
|
|
|
|
if (!nsContentUtils::IsChromeDoc(win->GetExtantDoc())) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaManager* manager = MediaManager::Get();
|
|
|
|
return manager->GetUserMediaDevices(win, aOnSuccess, aOnError);
|
2012-06-03 00:35:15 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 06:44:16 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorDesktopNotification
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP Navigator::GetMozNotification(nsIDOMDesktopNotificationCenter** aRetVal)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRetVal);
|
2012-07-30 07:20:58 -07:00
|
|
|
*aRetVal = nullptr;
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
if (mNotification) {
|
|
|
|
NS_ADDREF(*aRetVal = mNotification);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
2012-03-12 17:56:07 -07:00
|
|
|
NS_ENSURE_TRUE(win && win->GetDocShell(), NS_ERROR_FAILURE);
|
2011-11-02 06:44:16 -07:00
|
|
|
|
2012-03-12 17:56:07 -07:00
|
|
|
mNotification = new nsDesktopNotificationCenter(win);
|
2011-11-02 06:44:16 -07:00
|
|
|
|
|
|
|
NS_ADDREF(*aRetVal = mNotification);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
2012-07-05 03:05:09 -07:00
|
|
|
Navigator::GetBattery(nsIDOMBatteryManager** aBattery)
|
2011-11-02 05:04:39 -07:00
|
|
|
{
|
2011-11-02 08:01:32 -07:00
|
|
|
if (!mBatteryManager) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aBattery = nullptr;
|
2011-11-19 02:37:21 -08:00
|
|
|
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryReferent(mWindow));
|
2012-03-30 18:58:12 -07:00
|
|
|
NS_ENSURE_TRUE(win && win->GetDocShell(), NS_OK);
|
2011-11-19 02:37:21 -08:00
|
|
|
|
2011-11-02 08:01:32 -07:00
|
|
|
mBatteryManager = new battery::BatteryManager();
|
2012-03-12 17:56:07 -07:00
|
|
|
mBatteryManager->Init(win);
|
2011-11-02 08:01:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aBattery = mBatteryManager);
|
2011-11-02 05:04:39 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-19 19:24:00 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozPower(nsIDOMMozPowerManager** aPower)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aPower = nullptr;
|
2012-03-07 03:03:25 -08:00
|
|
|
|
2012-01-19 19:24:00 -08:00
|
|
|
if (!mPowerManager) {
|
2012-08-11 04:40:43 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window, NS_OK);
|
2012-03-07 03:03:25 -08:00
|
|
|
|
2012-08-11 04:40:43 -07:00
|
|
|
mPowerManager = PowerManager::CheckPermissionAndCreateInstance(window);
|
|
|
|
NS_ENSURE_TRUE(mPowerManager, NS_OK);
|
2012-01-19 19:24:00 -08:00
|
|
|
}
|
|
|
|
|
2012-03-14 15:00:29 -07:00
|
|
|
nsCOMPtr<nsIDOMMozPowerManager> power(mPowerManager);
|
2012-03-07 03:03:25 -08:00
|
|
|
power.forget(aPower);
|
2012-01-19 19:24:00 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-07 03:03:25 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::RequestWakeLock(const nsAString &aTopic, nsIDOMMozWakeLock **aWakeLock)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aWakeLock = nullptr;
|
2012-03-07 03:03:25 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(win, NS_OK);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPowerManagerService> pmService =
|
|
|
|
do_GetService(POWERMANAGERSERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(pmService, NS_OK);
|
|
|
|
|
|
|
|
return pmService->NewWakeLock(aTopic, win, aWakeLock);
|
|
|
|
}
|
|
|
|
|
2011-11-20 13:08:33 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorSms
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozSms(nsIDOMMozSmsManager** aSmsManager)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aSmsManager = nullptr;
|
2011-11-24 16:48:57 -08:00
|
|
|
|
2011-11-20 14:23:20 -08:00
|
|
|
if (!mSmsManager) {
|
2011-12-01 00:28:16 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK);
|
2011-11-24 16:48:57 -08:00
|
|
|
|
2012-09-25 06:46:41 -07:00
|
|
|
mSmsManager = SmsManager::CreateInstanceIfAllowed(window);
|
2012-08-22 10:30:27 -07:00
|
|
|
NS_ENSURE_TRUE(mSmsManager, NS_OK);
|
2011-11-20 14:23:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aSmsManager = mSmsManager);
|
2011-11-20 13:08:33 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorTelephony
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozTelephony(nsIDOMTelephony** aTelephony)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMTelephony> telephony = mTelephony;
|
|
|
|
|
|
|
|
if (!telephony) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv = NS_NewTelephony(window, getter_AddRefs(mTelephony));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// mTelephony may be null here!
|
|
|
|
telephony = mTelephony;
|
|
|
|
}
|
|
|
|
|
|
|
|
telephony.forget(aTelephony);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-18 20:27:19 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozVoicemail(nsIDOMMozVoicemail** aVoicemail)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aVoicemail = nullptr;
|
2012-07-18 20:27:19 -07:00
|
|
|
|
|
|
|
if (!mVoicemail) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
2012-08-23 16:31:02 -07:00
|
|
|
NS_ENSURE_TRUE(window, NS_OK);
|
2012-07-18 20:27:19 -07:00
|
|
|
|
2012-10-02 02:08:02 -07:00
|
|
|
if (!CheckPermission("voicemail")) {
|
2012-08-23 16:31:02 -07:00
|
|
|
return NS_OK;
|
2012-07-18 20:27:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_NewVoicemail(window, getter_AddRefs(mVoicemail));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aVoicemail = mVoicemail);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-09 14:28:47 -08:00
|
|
|
#endif // MOZ_B2G_RIL
|
|
|
|
|
2012-01-16 04:23:28 -08:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorNetwork
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozConnection(nsIDOMMozConnection** aConnection)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aConnection = nullptr;
|
2012-01-16 09:14:56 -08:00
|
|
|
|
2012-01-16 04:23:44 -08:00
|
|
|
if (!mConnection) {
|
2012-01-16 09:14:56 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK);
|
|
|
|
|
2012-01-16 04:23:44 -08:00
|
|
|
mConnection = new network::Connection();
|
2012-03-12 17:56:07 -07:00
|
|
|
mConnection->Init(window);
|
2012-01-16 04:23:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aConnection = mConnection);
|
2012-01-16 04:23:28 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aMobileConnection = nullptr;
|
2012-04-19 14:33:25 -07:00
|
|
|
|
|
|
|
if (!mMobileConnection) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
2012-08-16 17:42:26 -07:00
|
|
|
NS_ENSURE_TRUE(window, NS_OK);
|
2012-08-07 22:18:27 -07:00
|
|
|
|
2012-10-02 02:08:02 -07:00
|
|
|
if (!CheckPermission("mobileconnection")) {
|
2012-08-16 17:42:26 -07:00
|
|
|
return NS_OK;
|
2012-08-07 22:18:27 -07:00
|
|
|
}
|
2012-04-19 14:33:25 -07:00
|
|
|
|
|
|
|
mMobileConnection = new network::MobileConnection();
|
|
|
|
mMobileConnection->Init(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aMobileConnection = mMobileConnection);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
{
|
2012-05-23 21:02:23 -07:00
|
|
|
nsCOMPtr<nsIDOMBluetoothManager> bluetooth = mBluetooth;
|
2012-02-20 07:15:19 -08:00
|
|
|
|
|
|
|
if (!bluetooth) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
|
2012-05-23 21:02:23 -07:00
|
|
|
nsresult rv = NS_NewBluetoothManager(window, getter_AddRefs(mBluetooth));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-02-20 07:15:19 -08:00
|
|
|
|
|
|
|
bluetooth = mBluetooth;
|
|
|
|
}
|
|
|
|
|
|
|
|
bluetooth.forget(aBluetooth);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif //MOZ_B2G_BT
|
|
|
|
|
2012-07-02 17:16:55 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorSystemMessages
|
|
|
|
//*****************************************************************************
|
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-07-22 23:53:08 -07:00
|
|
|
nsresult
|
2012-07-02 17:16:55 -07:00
|
|
|
Navigator::EnsureMessagesManager()
|
|
|
|
{
|
|
|
|
if (mMessagesManager) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
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.
|
|
|
|
jsval prop_val = JSVAL_VOID;
|
|
|
|
rv = gpi->Init(window, &prop_val);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mMessagesManager = messageManager.forget();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozHasPendingMessage(const nsAString& aType, bool *aResult)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_SYS_MSG
|
|
|
|
*aResult = false;
|
|
|
|
nsresult rv = EnsureMessagesManager();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mMessagesManager->MozHasPendingMessage(aType, aResult);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::MozSetMessageHandler(const nsAString& aType,
|
|
|
|
nsIDOMSystemMessageCallback *aCallback)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_SYS_MSG
|
|
|
|
nsresult rv = EnsureMessagesManager();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mMessagesManager->MozSetMessageHandler(aType, aCallback);
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-10 23:05:00 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// Navigator::nsIDOMNavigatorTime
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozTime(nsIDOMMozTimeManager** aTime)
|
|
|
|
{
|
2012-09-17 05:59:00 -07:00
|
|
|
*aTime = nullptr;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTimeManager) {
|
|
|
|
mTimeManager = new time::TimeManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aTime = mTimeManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsNavigator::nsIDOMNavigatorCamera
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Navigator::GetMozCameras(nsIDOMCameraManager** aCameraManager)
|
|
|
|
{
|
|
|
|
if (!mCameraManager) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(win, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (!win->GetOuterWindow() || win->GetOuterWindow()->GetCurrentInnerWindow() != win) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-09-21 03:32:18 -07:00
|
|
|
mCameraManager = nsDOMCameraManager::CheckPermissionAndCreateInstance(win);
|
|
|
|
NS_ENSURE_TRUE(mCameraManager, NS_OK);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsDOMCameraManager> cameraManager = mCameraManager;
|
|
|
|
cameraManager.forget(aCameraManager);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
size_t
|
|
|
|
Navigator::SizeOfIncludingThis(nsMallocSizeOfFun 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.
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsGeolocation, bug 674115.
|
|
|
|
// TODO: add SizeOfIncludingThis() to nsDesktopNotificationCenter, bug 674116.
|
|
|
|
|
|
|
|
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!");
|
|
|
|
mWindow = do_GetWeakReference(aInnerWindow);
|
|
|
|
}
|
|
|
|
|
2012-06-03 00:35:15 -07:00
|
|
|
void
|
|
|
|
Navigator::OnNavigation()
|
|
|
|
{
|
2012-07-30 14:59:05 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mWindow);
|
|
|
|
if (!win) {
|
|
|
|
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();
|
2012-07-30 14:59:05 -07:00
|
|
|
manager->OnNavigation(win->WindowID());
|
2012-06-03 00:35:15 -07:00
|
|
|
#endif
|
2012-07-30 14:59:05 -07:00
|
|
|
if (mCameraManager) {
|
|
|
|
mCameraManager->OnNavigation(win->WindowID());
|
|
|
|
}
|
2012-06-03 00:35:15 -07:00
|
|
|
}
|
|
|
|
|
2012-10-02 02:08:02 -07:00
|
|
|
bool
|
|
|
|
Navigator::CheckPermission(const char* type)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
|
|
|
|
NS_ENSURE_TRUE(window, false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
|
|
|
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
|
|
|
|
uint32_t permission = nsIPermissionManager::DENY_ACTION;
|
|
|
|
permMgr->TestPermissionFromWindow(window, type, &permission);
|
|
|
|
return permission == nsIPermissionManager::ALLOW_ACTION;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
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;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aAppName.AssignLiteral("Netscape");
|
|
|
|
return NS_OK;
|
|
|
|
}
|