Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsThreadUtils.h"
9 #include "FakeSpeechRecognitionService.h"
11 #include "SpeechRecognition.h"
12 #include "SpeechRecognitionAlternative.h"
13 #include "SpeechRecognitionResult.h"
14 #include "SpeechRecognitionResultList.h"
15 #include "nsIObserverService.h"
16 #include "mozilla/Services.h"
18 namespace mozilla {
20 using namespace dom;
22 NS_IMPL_ISUPPORTS(FakeSpeechRecognitionService, nsISpeechRecognitionService, nsIObserver)
24 FakeSpeechRecognitionService::FakeSpeechRecognitionService()
25 {
26 }
28 FakeSpeechRecognitionService::~FakeSpeechRecognitionService()
29 {
30 }
32 NS_IMETHODIMP
33 FakeSpeechRecognitionService::Initialize(WeakPtr<SpeechRecognition> aSpeechRecognition)
34 {
35 mRecognition = aSpeechRecognition;
36 nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
37 obs->AddObserver(this, SPEECH_RECOGNITION_TEST_EVENT_REQUEST_TOPIC, false);
38 obs->AddObserver(this, SPEECH_RECOGNITION_TEST_END_TOPIC, false);
39 return NS_OK;
40 }
42 NS_IMETHODIMP
43 FakeSpeechRecognitionService::ProcessAudioSegment(AudioSegment* aAudioSegment)
44 {
45 return NS_OK;
46 }
48 NS_IMETHODIMP
49 FakeSpeechRecognitionService::SoundEnd()
50 {
51 return NS_OK;
52 }
54 NS_IMETHODIMP
55 FakeSpeechRecognitionService::Abort()
56 {
57 return NS_OK;
58 }
60 NS_IMETHODIMP
61 FakeSpeechRecognitionService::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
62 {
63 MOZ_ASSERT(mRecognition->mTestConfig.mFakeRecognitionService,
64 "Got request to fake recognition service event, but "
65 TEST_PREFERENCE_FAKE_RECOGNITION_SERVICE " is not set");
67 if (!strcmp(aTopic, SPEECH_RECOGNITION_TEST_END_TOPIC)) {
68 nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
69 obs->RemoveObserver(this, SPEECH_RECOGNITION_TEST_EVENT_REQUEST_TOPIC);
70 obs->RemoveObserver(this, SPEECH_RECOGNITION_TEST_END_TOPIC);
72 return NS_OK;
73 }
75 const nsDependentString eventName = nsDependentString(aData);
77 if (eventName.EqualsLiteral("EVENT_RECOGNITIONSERVICE_ERROR")) {
78 mRecognition->DispatchError(SpeechRecognition::EVENT_RECOGNITIONSERVICE_ERROR,
79 SpeechRecognitionErrorCode::Network, // TODO different codes?
80 NS_LITERAL_STRING("RECOGNITIONSERVICE_ERROR test event"));
82 } else if (eventName.EqualsLiteral("EVENT_RECOGNITIONSERVICE_FINAL_RESULT")) {
83 nsRefPtr<SpeechEvent> event =
84 new SpeechEvent(mRecognition,
85 SpeechRecognition::EVENT_RECOGNITIONSERVICE_FINAL_RESULT);
87 event->mRecognitionResultList = BuildMockResultList();
88 NS_DispatchToMainThread(event);
89 }
91 return NS_OK;
92 }
94 SpeechRecognitionResultList*
95 FakeSpeechRecognitionService::BuildMockResultList()
96 {
97 SpeechRecognitionResultList* resultList = new SpeechRecognitionResultList(mRecognition);
98 SpeechRecognitionResult* result = new SpeechRecognitionResult(mRecognition);
99 SpeechRecognitionAlternative* alternative = new SpeechRecognitionAlternative(mRecognition);
101 alternative->mTranscript = NS_LITERAL_STRING("Mock final result");
102 alternative->mConfidence = 0.0f;
104 result->mItems.AppendElement(alternative);
105 resultList->mItems.AppendElement(result);
107 return resultList;
108 }
110 } // namespace mozilla