Bug 915604: Hide RIL DOM APIs from regular Web pages. r=khuey, f=emk

This commit is contained in:
Vicamo Yang 2013-10-18 04:51:27 +08:00
parent 921cc9ae29
commit c4bf3de5f9
11 changed files with 78 additions and 55 deletions

View File

@ -388,9 +388,6 @@ pref("dom.ipc.browser_frames.oop_by_default", false);
// SMS/MMS
pref("dom.sms.enabled", true);
pref("dom.sms.strict7BitEncoding", false); // Disabled by default.
pref("dom.sms.requestStatusReport", true); // Enabled by default.
pref("dom.mms.requestStatusReport", true); // Enabled by default.
//The waiting time in network manager.
pref("network.gonk.ms-release-mms-connection", 30000);
@ -434,7 +431,6 @@ pref("services.push.udp.wakeupEnabled", true);
// NetworkStats
#ifdef MOZ_B2G_RIL
pref("dom.mozNetworkStats.enabled", true);
pref("ril.cellbroadcast.disabled", false);
pref("dom.webapps.firstRunWithSIM", true);
#endif
@ -730,10 +726,6 @@ pref("font.size.inflation.disabledInMasterProcess", true);
// consumption when applications are sent to the background.
pref("memory.free_dirty_pages", true);
// UAProfile settings
pref("wap.UAProf.url", "");
pref("wap.UAProf.tagname", "x-wap-profile");
pref("layout.imagevisibility.enabled", false);
pref("layout.imagevisibility.numscrollportwidths", 1);
pref("layout.imagevisibility.numscrollportheights", 1);
@ -824,6 +816,19 @@ pref("gfx.canvas.azure.accelerated", true);
// Enable Telephony API
pref("dom.telephony.enabled", true);
// Cell Broadcast API
pref("dom.cellbroadcast.enabled", true);
pref("ril.cellbroadcast.disabled", false);
// ICC API
pref("dom.icc.enabled", true);
// Mobile Connection API
pref("dom.mobileconnection.enabled", true);
// Voice Mail API
pref("dom.voicemail.enabled", true);
// The url of the page used to display network error details.
pref("b2g.neterror.url", "app://system.gaiamobile.org/net_error.html");

View File

@ -1716,8 +1716,13 @@ Navigator::HasCameraSupport(JSContext* /* unused */, JSObject* aGlobal)
bool
Navigator::HasTelephonySupport(JSContext* /* unused */, JSObject* aGlobal)
{
// First of all, the general pref has to be turned on.
bool enabled = false;
Preferences::GetBool("dom.telephony.enabled", &enabled);
NS_ENSURE_TRUE(enabled, false);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win && Telephony::CheckPermission(win);
return win && CheckPermission(win, "telephony");
}
/* static */
@ -1725,6 +1730,11 @@ bool
Navigator::HasMobileConnectionSupport(JSContext* /* unused */,
JSObject* aGlobal)
{
// First of all, the general pref has to be turned on.
bool enabled = false;
Preferences::GetBool("dom.mobileconnection.enabled", &enabled);
NS_ENSURE_TRUE(enabled, false);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win && (CheckPermission(win, "mobileconnection") ||
CheckPermission(win, "mobilenetwork"));
@ -1735,6 +1745,11 @@ bool
Navigator::HasCellBroadcastSupport(JSContext* /* unused */,
JSObject* aGlobal)
{
// First of all, the general pref has to be turned on.
bool enabled = false;
Preferences::GetBool("dom.cellbroadcast.enabled", &enabled);
NS_ENSURE_TRUE(enabled, false);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win && CheckPermission(win, "cellbroadcast");
}
@ -1744,6 +1759,11 @@ bool
Navigator::HasVoicemailSupport(JSContext* /* unused */,
JSObject* aGlobal)
{
// First of all, the general pref has to be turned on.
bool enabled = false;
Preferences::GetBool("dom.voicemail.enabled", &enabled);
NS_ENSURE_TRUE(enabled, false);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win && CheckPermission(win, "voicemail");
}
@ -1753,6 +1773,11 @@ bool
Navigator::HasIccManagerSupport(JSContext* /* unused */,
JSObject* aGlobal)
{
// First of all, the general pref has to be turned on.
bool enabled = false;
Preferences::GetBool("dom.icc.enabled", &enabled);
NS_ENSURE_TRUE(enabled, false);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win && CheckPermission(win, "mobileconnection");
}

View File

@ -719,25 +719,3 @@ Telephony::EnqueueEnumerationAck()
NS_WARNING("Failed to dispatch to current thread!");
}
}
/* static */
bool
Telephony::CheckPermission(nsPIDOMWindow* aWindow)
{
MOZ_ASSERT(aWindow && aWindow->IsInnerWindow());
nsCOMPtr<nsIPermissionManager> permMgr =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
NS_ENSURE_TRUE(permMgr, false);
uint32_t permission;
nsresult rv =
permMgr->TestPermissionFromWindow(aWindow, "telephony", &permission);
NS_ENSURE_SUCCESS(rv, false);
if (permission != nsIPermissionManager::ALLOW_ACTION) {
return false;
}
return true;
}

View File

@ -106,8 +106,6 @@ public:
static already_AddRefed<Telephony>
Create(nsPIDOMWindow* aOwner, ErrorResult& aRv);
static bool CheckPermission(nsPIDOMWindow* aOwner);
void
AddCall(TelephonyCall* aCall)
{

View File

@ -100,7 +100,7 @@ var interfaceNamesInGlobalScope =
{name: "BluetoothStatusChangedEvent", b2g: true},
{name: "BoxObject", xbl: true},
{name: "BrowserFeedWriter", desktop: true},
{name: "CallEvent", b2g: true},
{name: "CallEvent", b2g: true, pref: "dom.telephony.enabled"},
"CameraCapabilities",
"CameraControl",
"CameraManager",
@ -109,7 +109,7 @@ var interfaceNamesInGlobalScope =
"CanvasRenderingContext2D",
"CaretPosition",
"CDATASection",
{name: "CFStateChangeEvent", b2g: true},
{name: "CFStateChangeEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
"ChannelMergerNode",
"ChannelSplitterNode",
"CharacterData",
@ -147,7 +147,7 @@ var interfaceNamesInGlobalScope =
"CustomEvent",
"DataChannel",
"DataContainerEvent",
{name: "DataErrorEvent", b2g: true},
{name: "DataErrorEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
{name: "DataStore", b2g: true, release: false},
{name: "DataStoreChangeEvent", b2g: true, release: false},
{name: "DataStoreCursor", b2g: true, release: false},
@ -277,7 +277,7 @@ var interfaceNamesInGlobalScope =
"HTMLUListElement",
"HTMLUnknownElement",
"HTMLVideoElement",
{name: "IccCardLockError", b2g: true},
{name: "IccCardLockError", b2g: true, pref: "dom.icc.enabled"},
"IDBCursor",
"IDBCursorWithValue",
"IDBDatabase",
@ -317,24 +317,24 @@ var interfaceNamesInGlobalScope =
"MouseScrollEvent",
{name: "MozActivity", b2g: true},
"MozApplicationEvent",
{name: "MozCellBroadcast", b2g: true},
{name: "MozCellBroadcastEvent", b2g: true},
{name: "MozCellBroadcast", b2g: true, pref: "dom.cellbroadcast.enabled"},
{name: "MozCellBroadcastEvent", b2g: true, pref: "dom.cellbroadcast.enabled"},
"MozConnection",
"mozContact",
"MozContactChangeEvent",
"MozCSSKeyframeRule",
"MozCSSKeyframesRule",
{name: "MozEmergencyCbModeEvent", b2g: true},
{name: "MozIccManager", b2g: true},
{name: "MozEmergencyCbModeEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
{name: "MozIccManager", b2g: true, pref: "dom.icc.enabled"},
{name: "MozInputContext", b2g: true},
{name: "MozInputMethodManager", b2g: true},
"MozMmsEvent",
"MozMmsMessage",
{name: "MozMobileConnection", b2g: true},
{name: "MozMobileConnection", b2g: true, pref: "dom.mobileconnection.enabled"},
"MozMobileMessageManager",
"MozMobileMessageThread",
"MozNamedAttrMap",
{name: "MozOtaStatusEvent", b2g: true},
{name: "MozOtaStatusEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
"MozPowerManager",
"mozRTCIceCandidate",
"mozRTCPeerConnection",
@ -344,10 +344,10 @@ var interfaceNamesInGlobalScope =
"MozSmsFilter",
"MozSmsMessage",
"MozSmsSegmentInfo",
{name: "MozStkCommandEvent", b2g: true},
{name: "MozStkCommandEvent", b2g: true, pref: "dom.icc.enabled"},
{name: "MozTimeManager", b2g: true},
{name: "MozVoicemail", b2g: true},
{name: "MozVoicemailEvent", b2g: true},
{name: "MozVoicemail", b2g: true, pref: "dom.voicemail.enabled"},
{name: "MozVoicemailEvent", b2g: true, pref: "dom.voicemail.enabled"},
"MozWakeLock",
{name: "MozWifiConnectionInfoEvent", b2g: true},
{name: "MozWifiStatusChangeEvent", b2g: true},
@ -530,9 +530,9 @@ var interfaceNamesInGlobalScope =
"SVGViewElement",
"SVGZoomAndPan",
"SVGZoomEvent",
{name: "Telephony", b2g: true},
{name: "TelephonyCall", b2g: true},
{name: "TelephonyCallGroup", b2g: true},
{name: "Telephony", b2g: true, pref: "dom.telephony.enabled"},
{name: "TelephonyCall", b2g: true, pref: "dom.telephony.enabled"},
{name: "TelephonyCallGroup", b2g: true, pref: "dom.telephony.enabled"},
"Text",
"TextDecoder",
"TextEncoder",
@ -554,7 +554,7 @@ var interfaceNamesInGlobalScope =
"URL",
{name: "UserDataHandler", xbl: true},
"UserProximityEvent",
{name: "USSDReceivedEvent", b2g: true},
{name: "USSDReceivedEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
"ValidityState",
"VideoStreamTrack",
"WaveShaperNode",
@ -600,6 +600,7 @@ var interfaceNamesInGlobalScope =
// IMPORTANT: Do not change this list without review from a DOM peer!
function createInterfaceMap(isXBLScope) {
var prefs = SpecialPowers.Services.prefs;
var version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
var isNightly = version.endsWith("a1");
var isRelease = !version.contains("a");
@ -617,7 +618,8 @@ function createInterfaceMap(isXBLScope) {
(entry.xbl === !isXBLScope) ||
(entry.desktop === !isDesktop) ||
(entry.b2g === !isB2G) ||
(entry.release === !isRelease)) {
(entry.release === !isRelease) ||
(entry.pref && !prefs.getBoolPref(entry.pref))) {
interfaceMap[entry.name] = false;
} else {
interfaceMap[entry.name] = shouldExpect;

View File

@ -8,6 +8,7 @@
* unacknowledged general CBS messages to be broadcast to all receivers within
* a particular region.
*/
[Pref="dom.cellbroadcast.enabled"]
interface MozCellBroadcast : EventTarget
{
/**

View File

@ -5,7 +5,7 @@
*/
interface MozCellBroadcastMessage;
[Constructor(DOMString type, optional MozCellBroadcastEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
[Constructor(DOMString type, optional MozCellBroadcastEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h", Pref="dom.cellbroadcast.enabled"]
interface MozCellBroadcastEvent : Event
{
readonly attribute MozCellBroadcastMessage? message;

View File

@ -7,6 +7,7 @@
// nsIDOMMozVoicemailStatus
interface MozVoicemailStatus;
[Pref="dom.voicemail.enabled"]
interface MozVoicemail : EventTarget
{
/**

View File

@ -5,7 +5,7 @@
*/
interface MozVoicemailStatus;
[Constructor(DOMString type, optional MozVoicemailEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
[Constructor(DOMString type, optional MozVoicemailEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h", Pref="dom.voicemail.enabled"]
interface MozVoicemailEvent : Event
{
readonly attribute MozVoicemailStatus? status;

View File

@ -4,7 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
[Constructor(DOMString type, optional USSDReceivedEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
[Constructor(DOMString type, optional USSDReceivedEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h", Pref="dom.icc.enabled"]
interface USSDReceivedEvent : Event
{
readonly attribute DOMString? message;

View File

@ -4281,6 +4281,7 @@ pref("dom.sms.enabled", false);
// 7-bit default alphabet.
pref("dom.sms.strict7BitEncoding", false);
pref("dom.sms.requestStatusReport", true);
pref("dom.mms.requestStatusReport", true);
// WebContacts
pref("dom.mozContacts.enabled", false);
@ -4397,7 +4398,7 @@ pref("dom.browserElement.maxScreenshotDelayMS", 2000);
// Whether we should show the placeholder when the element is focused but empty.
pref("dom.placeholder.show_on_focus", true);
// UAProfile settings
// MMS UA Profile settings
pref("wap.UAProf.url", "");
pref("wap.UAProf.tagname", "x-wap-profile");
@ -4453,6 +4454,18 @@ pref("dom.datastore.enabled", false);
// Telephony API
pref("dom.telephony.enabled", false);
// Cell Broadcast API
pref("dom.cellbroadcast.enabled", false);
// ICC API
pref("dom.icc.enabled", false);
// Mobile Connection API
pref("dom.mobileconnection.enabled", false);
// Voice Mail API
pref("dom.voicemail.enabled", false);
// DOM Inter-App Communication API.
pref("dom.inter-app-communication-api.enabled", false);