Bug 968879 - Use [Pref] annotations to enable web speech interfaces; r=smaug

This commit is contained in:
Ehsan Akhgari 2014-02-06 15:00:37 -05:00
Родитель 8e0775b1ce
Коммит 38c067be0b
29 изменённых файлов: 27 добавлений и 164 удалений

Просмотреть файл

@ -1,32 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "EnableWebSpeechRecognitionCheck.h"
#include "mozilla/Preferences.h"
namespace {
bool gPrefInitialized = false;
bool gWebSpeechEnabled = false;
}
namespace mozilla {
namespace dom {
/* static */ bool
EnableWebSpeechRecognitionCheck::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
{
if (!gPrefInitialized) {
Preferences::AddBoolVarCache(&gWebSpeechEnabled, "media.webspeech.recognition.enable");
gPrefInitialized = true;
}
return gWebSpeechEnabled;
}
}
}

Просмотреть файл

@ -1,24 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#ifndef EnableWebSpeechRecognitionCheck_h
#define EnableWebSpeechRecognitionCheck_h
#include "js/TypeDecls.h"
namespace mozilla {
namespace dom {
class EnableWebSpeechRecognitionCheck
{
public:
static bool PrefEnabled(JSContext* aCx, JSObject* aGlobal);
};
}
}
#endif

Просмотреть файл

@ -16,16 +16,13 @@
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "EnableWebSpeechRecognitionCheck.h"
namespace mozilla {
namespace dom {
class GlobalObject;
class SpeechGrammar MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableWebSpeechRecognitionCheck
public nsWrapperCache
{
public:
SpeechGrammar(nsISupports* aParent);

Просмотреть файл

@ -7,7 +7,6 @@
#ifndef mozilla_dom_SpeechGrammarList_h
#define mozilla_dom_SpeechGrammarList_h
#include "EnableWebSpeechRecognitionCheck.h"
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
@ -26,8 +25,7 @@ class SpeechGrammar;
template<typename> class Optional;
class SpeechGrammarList MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableWebSpeechRecognitionCheck
public nsWrapperCache
{
public:
SpeechGrammarList(nsISupports* aParent);

Просмотреть файл

@ -23,7 +23,6 @@
#include "mozilla/WeakPtr.h"
#include "mozilla/Preferences.h"
#include "EnableWebSpeechRecognitionCheck.h"
#include "SpeechGrammarList.h"
#include "SpeechRecognitionResultList.h"
#include "SpeechStreamListener.h"
@ -56,7 +55,6 @@ PRLogModuleInfo* GetSpeechRecognitionLog();
class SpeechRecognition MOZ_FINAL : public nsDOMEventTargetHelper,
public nsIObserver,
public EnableWebSpeechRecognitionCheck,
public SupportsWeakPtr<SpeechRecognition>
{
public:

Просмотреть файл

@ -15,16 +15,13 @@
#include "mozilla/Attributes.h"
#include "EnableWebSpeechRecognitionCheck.h"
namespace mozilla {
namespace dom {
class SpeechRecognition;
class SpeechRecognitionAlternative MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableWebSpeechRecognitionCheck
public nsWrapperCache
{
public:
SpeechRecognitionAlternative(SpeechRecognition* aParent);

Просмотреть файл

@ -16,15 +16,13 @@
#include "mozilla/Attributes.h"
#include "EnableWebSpeechRecognitionCheck.h"
#include "SpeechRecognitionAlternative.h"
namespace mozilla {
namespace dom {
class SpeechRecognitionResult MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableWebSpeechRecognitionCheck
public nsWrapperCache
{
public:
SpeechRecognitionResult(SpeechRecognition* aParent);

Просмотреть файл

@ -15,7 +15,6 @@
#include "mozilla/Attributes.h"
#include "EnableWebSpeechRecognitionCheck.h"
#include "SpeechRecognitionResult.h"
namespace mozilla {
@ -24,8 +23,7 @@ namespace dom {
class SpeechRecognition;
class SpeechRecognitionResultList MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableWebSpeechRecognitionCheck
public nsWrapperCache
{
public:
SpeechRecognitionResultList(SpeechRecognition* aParent);

Просмотреть файл

@ -24,7 +24,6 @@ EXPORTS.mozilla.dom += [
]
UNIFIED_SOURCES += [
'EnableWebSpeechRecognitionCheck.cpp',
'endpointer.cc',
'energy_endpointer.cc',
'energy_endpointer_params.cc',

Просмотреть файл

@ -1,33 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "EnableSpeechSynthesisCheck.h"
#include "mozilla/Preferences.h"
namespace {
bool gPrefInitialized = false;
bool gWebSpeechEnabled = false;
}
namespace mozilla {
namespace dom {
/* static */ bool
EnableSpeechSynthesisCheck::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
{
if (!gPrefInitialized) {
Preferences::AddBoolVarCache(&gWebSpeechEnabled, "media.webspeech.synth.enabled");
gPrefInitialized = true;
}
return gWebSpeechEnabled;
}
}
}

Просмотреть файл

@ -1,26 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#ifndef mozilla_dom_EnableSpeechSynthesisCheck_h
#define mozilla_dom_EnableSpeechSynthesisCheck_h
#include "js/TypeDecls.h"
namespace mozilla {
namespace dom {
// This is a helper class which enables Web Speech to be enabled or disabled
// as whole. Individual Web Speech object classes should inherit from this.
class EnableSpeechSynthesisCheck
{
public:
static bool PrefEnabled(JSContext* aCx = nullptr, JSObject* aGlobal = nullptr);
};
}
}
#endif

Просмотреть файл

@ -13,7 +13,6 @@
#include "nsRefPtrHashtable.h"
#include "js/TypeDecls.h"
#include "EnableSpeechSynthesisCheck.h"
#include "SpeechSynthesisUtterance.h"
#include "SpeechSynthesisVoice.h"
@ -25,8 +24,7 @@ namespace dom {
class nsSpeechTask;
class SpeechSynthesis MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableSpeechSynthesisCheck
public nsWrapperCache
{
public:
SpeechSynthesis(nsPIDOMWindow* aParent);

Просмотреть файл

@ -12,7 +12,6 @@
#include "nsString.h"
#include "js/TypeDecls.h"
#include "EnableSpeechSynthesisCheck.h"
#include "nsSpeechTask.h"
namespace mozilla {
@ -22,8 +21,7 @@ class SpeechSynthesisVoice;
class SpeechSynthesis;
class nsSynthVoiceRegistry;
class SpeechSynthesisUtterance MOZ_FINAL : public nsDOMEventTargetHelper,
public EnableSpeechSynthesisCheck
class SpeechSynthesisUtterance MOZ_FINAL : public nsDOMEventTargetHelper
{
friend class SpeechSynthesis;
friend class nsSpeechTask;

Просмотреть файл

@ -12,7 +12,6 @@
#include "nsWrapperCache.h"
#include "js/TypeDecls.h"
#include "EnableSpeechSynthesisCheck.h"
#include "nsISpeechService.h"
namespace mozilla {
@ -22,8 +21,7 @@ class nsSynthVoiceRegistry;
class SpeechSynthesis;
class SpeechSynthesisVoice MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableSpeechSynthesisCheck
public nsWrapperCache
{
friend class nsSynthVoiceRegistry;
friend class SpeechSynthesis;

Просмотреть файл

@ -16,7 +16,6 @@ if CONFIG['MOZ_WEBSPEECH']:
]
EXPORTS.mozilla.dom += [
'EnableSpeechSynthesisCheck.h',
'ipc/SpeechSynthesisChild.h',
'ipc/SpeechSynthesisParent.h',
'nsSpeechTask.h',
@ -27,7 +26,6 @@ if CONFIG['MOZ_WEBSPEECH']:
]
UNIFIED_SOURCES += [
'EnableSpeechSynthesisCheck.cpp',
'ipc/SpeechSynthesisChild.cpp',
'ipc/SpeechSynthesisParent.cpp',
'nsSpeechTask.cpp',

Просмотреть файл

@ -3571,7 +3571,7 @@ nsGlobalWindow::GetSpeechSynthesis(nsISupports** aSpeechSynthesis)
{
ErrorResult rv;
nsCOMPtr<nsISupports> speechSynthesis;
if (SpeechSynthesis::PrefEnabled()) {
if (Preferences::GetBool("media.webspeech.synth.enabled")) {
speechSynthesis = GetSpeechSynthesis(rv);
}
speechSynthesis.forget(aSpeechSynthesis);

Просмотреть файл

@ -793,11 +793,7 @@ var interfaceNamesInGlobalScope =
// IMPORTANT: Do not change this list without review from a DOM peer!
"SmartCardEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
"SpeechRecognitionError",
// IMPORTANT: Do not change this list without review from a DOM peer!
"SpeechRecognitionEvent",
// IMPORTANT: Do not change this list without review from a DOM peer!
"SpeechSynthesisEvent",
{name: "SpeechSynthesisEvent", b2g: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "SpeechSynthesis", b2g: true},
// IMPORTANT: Do not change this list without review from a DOM peer!

Просмотреть файл

@ -11,7 +11,7 @@
*/
[Constructor,
Func="mozilla::dom::SpeechGrammar::PrefEnabled"]
Pref="media.webspeech.recognition.enable"]
interface SpeechGrammar {
[Throws]
attribute DOMString src;

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechGrammarList::PrefEnabled"]
[Pref="media.webspeech.recognition.enable"]
interface SpeechGrammarList {
readonly attribute unsigned long length;
[Throws]

Просмотреть файл

@ -11,7 +11,7 @@
*/
[Constructor,
Func="mozilla::dom::SpeechRecognition::PrefEnabled"]
Pref="media.webspeech.recognition.enable"]
interface SpeechRecognition : EventTarget {
// recognition parameters
[Throws]

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechRecognitionAlternative::PrefEnabled"]
[Pref="media.webspeech.recognition.enable"]
interface SpeechRecognitionAlternative {
readonly attribute DOMString transcript;
readonly attribute float confidence;

Просмотреть файл

@ -15,7 +15,8 @@ enum SpeechRecognitionErrorCode {
"language-not-supported"
};
[Constructor(DOMString type, optional SpeechRecognitionErrorInit eventInitDict)]
[Pref="media.webspeech.recognition.enable",
Constructor(DOMString type, optional SpeechRecognitionErrorInit eventInitDict)]
interface SpeechRecognitionError : Event
{
readonly attribute SpeechRecognitionErrorCode error;

Просмотреть файл

@ -5,7 +5,9 @@
*/
interface nsISupports;
[Constructor(DOMString type, optional SpeechRecognitionEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
[Pref="media.webspeech.recognition.enable",
Constructor(DOMString type, optional SpeechRecognitionEventInit eventInitDict),
HeaderFile="GeneratedEventClasses.h"]
interface SpeechRecognitionEvent : Event
{
readonly attribute unsigned long resultIndex;

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechRecognitionResult::PrefEnabled"]
[Pref="media.webspeech.recognition.enable"]
interface SpeechRecognitionResult {
readonly attribute unsigned long length;
getter SpeechRecognitionAlternative item(unsigned long index);

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechRecognitionResultList::PrefEnabled"]
[Pref="media.webspeech.recognition.enable"]
interface SpeechRecognitionResultList {
readonly attribute unsigned long length;
getter SpeechRecognitionResult item(unsigned long index);

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechSynthesis::PrefEnabled"]
[Pref="media.webspeech.synth.enabled"]
interface SpeechSynthesis {
readonly attribute boolean pending;
readonly attribute boolean speaking;

Просмотреть файл

@ -10,7 +10,9 @@
* liability, trademark and document use rules apply.
*/
[Constructor(DOMString type, optional SpeechSynthesisEventInit eventInitDict), HeaderFile="GeneratedEventClasses.h"]
[Constructor(DOMString type, optional SpeechSynthesisEventInit eventInitDict),
HeaderFile="GeneratedEventClasses.h",
Pref="media.webspeech.synth.enabled"]
interface SpeechSynthesisEvent : Event
{
readonly attribute unsigned long charIndex;

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechSynthesisUtterance::PrefEnabled",
[Pref="media.webspeech.synth.enabled",
Constructor,
Constructor(DOMString text)]
interface SpeechSynthesisUtterance : EventTarget {

Просмотреть файл

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Func="mozilla::dom::SpeechSynthesisVoice::PrefEnabled"]
[Pref="media.webspeech.synth.enabled"]
interface SpeechSynthesisVoice {
readonly attribute DOMString voiceURI;
readonly attribute DOMString name;