зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1218337 - Part 1 of 1: Introduced permission 'speech-recognition' and used it in place of the app-check. r=smaug
--HG-- extra : rebase_source : 052f21d58396df9a3def0f52c81d600aa16384c3
This commit is contained in:
Родитель
9e69cfc3dd
Коммит
9d27aa2f03
|
@ -116,6 +116,11 @@ this.PermissionsTable = { geolocation: {
|
|||
privileged: DENY_ACTION,
|
||||
certified: ALLOW_ACTION
|
||||
},
|
||||
"speech-recognition": {
|
||||
app: DENY_ACTION,
|
||||
privileged: ALLOW_ACTION,
|
||||
certified: ALLOW_ACTION
|
||||
},
|
||||
telephony: {
|
||||
app: DENY_ACTION,
|
||||
privileged: DENY_ACTION,
|
||||
|
|
|
@ -21,8 +21,11 @@
|
|||
#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"
|
||||
|
@ -160,11 +163,26 @@ SpeechRecognition::WrapObject(JSContext* aCx, JS::Handle<JSObject*> 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>
|
||||
|
|
Загрузка…
Ссылка в новой задаче