Bug 729173 - Part 3: Hook up MobileConnection to the Navigator object

This commit is contained in:
Philipp von Weitershausen 2012-04-19 18:33:25 -03:00
parent 71e0a3dc57
commit 701bbcd8e7
3 changed files with 42 additions and 1 deletions

View File

@ -78,6 +78,7 @@
#include "nsIWebNavigation.h"
#include "mozilla/ClearOnShutdown.h"
#include "Connection.h"
#include "MobileConnection.h"
#ifdef MOZ_B2G_RIL
#include "TelephonyFactory.h"
@ -195,6 +196,11 @@ Navigator::Invalidate()
mConnection = nsnull;
}
if (mMobileConnection) {
mMobileConnection->Shutdown();
mMobileConnection = nsnull;
}
#ifdef MOZ_B2G_BT
if (mBluetooth) {
mBluetooth = nsnull;
@ -1139,6 +1145,37 @@ Navigator::GetMozConnection(nsIDOMMozConnection** aConnection)
return NS_OK;
}
NS_IMETHODIMP
Navigator::GetMozMobileConnection(nsIDOMMozMobileConnection** aMobileConnection)
{
*aMobileConnection = nsnull;
if (!mMobileConnection) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK);
// Chrome is always allowed access, so do the permission check only
// for non-chrome pages.
if (!nsContentUtils::IsCallerChrome()) {
nsCOMPtr<nsIDocument> doc = do_QueryInterface(window->GetExtantDocument());
NS_ENSURE_TRUE(doc, NS_OK);
nsCOMPtr<nsIURI> uri;
doc->NodePrincipal()->GetURI(getter_AddRefs(uri));
if (!nsContentUtils::URIIsChromeOrInPref(uri, "dom.mobileconnection.whitelist")) {
return NS_OK;
}
}
mMobileConnection = new network::MobileConnection();
mMobileConnection->Init(window);
}
NS_ADDREF(*aMobileConnection = mMobileConnection);
return NS_OK;
}
#ifdef MOZ_B2G_BT
//*****************************************************************************
// nsNavigator::nsIDOMNavigatorBluetooth

View File

@ -87,6 +87,7 @@ class SmsManager;
namespace network {
class Connection;
class MobileConnection;
} // namespace Connection;
namespace power {
@ -158,6 +159,7 @@ private:
nsCOMPtr<nsIDOMTelephony> mTelephony;
#endif
nsRefPtr<network::Connection> mConnection;
nsRefPtr<network::MobileConnection> mMobileConnection;
#ifdef MOZ_B2G_BT
nsCOMPtr<nsIDOMBluetoothAdapter> mBluetooth;
#endif

View File

@ -37,9 +37,11 @@
#include "nsISupports.idl"
interface nsIDOMMozConnection;
interface nsIDOMMozMobileConnection;
[scriptable, uuid(1dd6773e-30dc-419b-9766-b05458fd96c8)]
[scriptable, uuid(fb7c3429-aa2c-4ccc-948a-467c0de29fff)]
interface nsIDOMMozNavigatorNetwork : nsISupports
{
readonly attribute nsIDOMMozConnection mozConnection;
readonly attribute nsIDOMMozMobileConnection mozMobileConnection;
};