dom/audiochannel/AudioChannelServiceChild.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

michael@0 1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "AudioChannelServiceChild.h"
michael@0 8
michael@0 9 #include "base/basictypes.h"
michael@0 10
michael@0 11 #include "mozilla/Services.h"
michael@0 12 #include "mozilla/StaticPtr.h"
michael@0 13 #include "mozilla/unused.h"
michael@0 14 #include "mozilla/dom/ContentChild.h"
michael@0 15 #include "mozilla/dom/ContentParent.h"
michael@0 16 #include "nsIObserverService.h"
michael@0 17 #include "nsThreadUtils.h"
michael@0 18
michael@0 19 #ifdef MOZ_WIDGET_GONK
michael@0 20 #include "SpeakerManagerService.h"
michael@0 21 #endif
michael@0 22
michael@0 23 using namespace mozilla;
michael@0 24 using namespace mozilla::dom;
michael@0 25 using namespace mozilla::hal;
michael@0 26
michael@0 27 StaticRefPtr<AudioChannelServiceChild> gAudioChannelServiceChild;
michael@0 28
michael@0 29 // static
michael@0 30 AudioChannelService*
michael@0 31 AudioChannelServiceChild::GetAudioChannelService()
michael@0 32 {
michael@0 33 MOZ_ASSERT(NS_IsMainThread());
michael@0 34
michael@0 35 // If we already exist, exit early
michael@0 36 if (gAudioChannelServiceChild) {
michael@0 37 return gAudioChannelServiceChild;
michael@0 38 }
michael@0 39
michael@0 40 // Create new instance, register, return
michael@0 41 nsRefPtr<AudioChannelServiceChild> service = new AudioChannelServiceChild();
michael@0 42 NS_ENSURE_TRUE(service, nullptr);
michael@0 43
michael@0 44 gAudioChannelServiceChild = service;
michael@0 45 return gAudioChannelServiceChild;
michael@0 46 }
michael@0 47
michael@0 48 void
michael@0 49 AudioChannelServiceChild::Shutdown()
michael@0 50 {
michael@0 51 if (gAudioChannelServiceChild) {
michael@0 52 gAudioChannelServiceChild = nullptr;
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 AudioChannelServiceChild::AudioChannelServiceChild()
michael@0 57 {
michael@0 58 }
michael@0 59
michael@0 60 AudioChannelServiceChild::~AudioChannelServiceChild()
michael@0 61 {
michael@0 62 }
michael@0 63
michael@0 64 AudioChannelState
michael@0 65 AudioChannelServiceChild::GetState(AudioChannelAgent* aAgent, bool aElementHidden)
michael@0 66 {
michael@0 67 AudioChannelAgentData* data;
michael@0 68 if (!mAgents.Get(aAgent, &data)) {
michael@0 69 return AUDIO_CHANNEL_STATE_MUTED;
michael@0 70 }
michael@0 71
michael@0 72 AudioChannelState state = AUDIO_CHANNEL_STATE_MUTED;
michael@0 73 bool oldElementHidden = data->mElementHidden;
michael@0 74
michael@0 75 UpdateChannelType(data->mChannel, CONTENT_PROCESS_ID_MAIN, aElementHidden,
michael@0 76 oldElementHidden);
michael@0 77
michael@0 78 // Update visibility.
michael@0 79 data->mElementHidden = aElementHidden;
michael@0 80
michael@0 81 ContentChild* cc = ContentChild::GetSingleton();
michael@0 82 cc->SendAudioChannelGetState(data->mChannel, aElementHidden, oldElementHidden,
michael@0 83 &state);
michael@0 84 data->mState = state;
michael@0 85 cc->SendAudioChannelChangedNotification();
michael@0 86
michael@0 87 return state;
michael@0 88 }
michael@0 89
michael@0 90 void
michael@0 91 AudioChannelServiceChild::RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
michael@0 92 AudioChannel aChannel,
michael@0 93 bool aWithVideo)
michael@0 94 {
michael@0 95 AudioChannelService::RegisterAudioChannelAgent(aAgent, aChannel, aWithVideo);
michael@0 96
michael@0 97 ContentChild::GetSingleton()->SendAudioChannelRegisterType(aChannel, aWithVideo);
michael@0 98
michael@0 99 nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
michael@0 100 if (obs) {
michael@0 101 obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
michael@0 102 }
michael@0 103 }
michael@0 104
michael@0 105 void
michael@0 106 AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent)
michael@0 107 {
michael@0 108 AudioChannelAgentData *pData;
michael@0 109 if (!mAgents.Get(aAgent, &pData)) {
michael@0 110 return;
michael@0 111 }
michael@0 112
michael@0 113 // We need to keep a copy because unregister will remove the
michael@0 114 // AudioChannelAgentData object from the hashtable.
michael@0 115 AudioChannelAgentData data(*pData);
michael@0 116
michael@0 117 AudioChannelService::UnregisterAudioChannelAgent(aAgent);
michael@0 118
michael@0 119 ContentChild::GetSingleton()->SendAudioChannelUnregisterType(
michael@0 120 data.mChannel, data.mElementHidden, data.mWithVideo);
michael@0 121
michael@0 122 nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
michael@0 123 if (obs) {
michael@0 124 obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
michael@0 125 }
michael@0 126 #ifdef MOZ_WIDGET_GONK
michael@0 127 bool active = AnyAudioChannelIsActive();
michael@0 128 for (uint32_t i = 0; i < mSpeakerManager.Length(); i++) {
michael@0 129 mSpeakerManager[i]->SetAudioChannelActive(active);
michael@0 130 }
michael@0 131 #endif
michael@0 132 }
michael@0 133
michael@0 134 void
michael@0 135 AudioChannelServiceChild::SetDefaultVolumeControlChannel(int32_t aChannel,
michael@0 136 bool aHidden)
michael@0 137 {
michael@0 138 ContentChild *cc = ContentChild::GetSingleton();
michael@0 139 if (cc) {
michael@0 140 cc->SendAudioChannelChangeDefVolChannel(aChannel, aHidden);
michael@0 141 }
michael@0 142 }

mercurial