Bug 1218337 - Part 1 of 1: Introduced permission 'speech-recognition' and used it in place of the app-check. r=smaug
--- a/dom/apps/PermissionsTable.jsm
+++ b/dom/apps/PermissionsTable.jsm
@@ -111,16 +111,21 @@ this.PermissionsTable = { geolocation:
certified: ALLOW_ACTION,
access: ["read", "write", "create"]
},
sms: {
app: DENY_ACTION,
privileged: DENY_ACTION,
certified: ALLOW_ACTION
},
+ "speech-recognition": {
+ app: DENY_ACTION,
+ privileged: ALLOW_ACTION,
+ certified: ALLOW_ACTION
+ },
telephony: {
app: DENY_ACTION,
privileged: DENY_ACTION,
certified: ALLOW_ACTION
},
browser: {
app: DENY_ACTION,
privileged: ALLOW_ACTION,
--- a/dom/media/webspeech/recognition/SpeechRecognition.cpp
+++ b/dom/media/webspeech/recognition/SpeechRecognition.cpp
@@ -16,18 +16,21 @@
#include "mozilla/dom/MediaStreamError.h"
#include "mozilla/MediaManager.h"
#include "mozilla/Services.h"
#include "AudioSegment.h"
#include "endpointer.h"
#include "mozilla/dom/SpeechRecognitionEvent.h"
+#include "nsContentUtils.h"
#include "nsIDocument.h"
#include "nsIObserverService.h"
+#include "nsIPermissionManager.h"
+#include "nsIPrincipal.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsQueryObject.h"
#include <algorithm>
// Undo the windows.h damage
#if defined(XP_WIN) && defined(GetMessage)
@@ -155,21 +158,36 @@ JSObject*
SpeechRecognition::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return SpeechRecognitionBinding::Wrap(aCx, this, aGivenProto);
}
bool
SpeechRecognition::IsAuthorized(JSContext* aCx, JSObject* aGlobal)
{
- bool inPrivilegedApp = IsInPrivilegedApp(aCx, aGlobal);
+ nsCOMPtr<nsIPrincipal> principal = nsContentUtils::ObjectPrincipal(aGlobal);
+
+ nsresult rv;
+ nsCOMPtr<nsIPermissionManager> mgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return false;
+ }
+
+ uint32_t speechRecognition = nsIPermissionManager::UNKNOWN_ACTION;
+ rv = mgr->TestExactPermissionFromPrincipal(principal, "speech-recognition", &speechRecognition);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return false;
+ }
+
+ bool hasPermission = (speechRecognition == nsIPermissionManager::ALLOW_ACTION);
+
bool enableTests = Preferences::GetBool(TEST_PREFERENCE_ENABLE);
bool enableRecognitionEnable = Preferences::GetBool(TEST_PREFERENCE_RECOGNITION_ENABLE);
bool enableRecognitionForceEnable = Preferences::GetBool(TEST_PREFERENCE_RECOGNITION_FORCE_ENABLE);
- return (inPrivilegedApp || enableRecognitionForceEnable || enableTests) && enableRecognitionEnable;
+ return (hasPermission || enableRecognitionForceEnable || enableTests) && enableRecognitionEnable;
}
already_AddRefed<SpeechRecognition>
SpeechRecognition::Constructor(const GlobalObject& aGlobal,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
if (!win) {