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.
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 | #ifndef mozilla_dom_audiochannelservice_h__ |
michael@0 | 8 | #define mozilla_dom_audiochannelservice_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | #include "nsIObserver.h" |
michael@0 | 12 | #include "nsTArray.h" |
michael@0 | 13 | #include "nsITimer.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "AudioChannelCommon.h" |
michael@0 | 16 | #include "AudioChannelAgent.h" |
michael@0 | 17 | #include "nsAttrValue.h" |
michael@0 | 18 | #include "nsClassHashtable.h" |
michael@0 | 19 | #include "mozilla/dom/AudioChannelBinding.h" |
michael@0 | 20 | |
michael@0 | 21 | class nsPIDOMWindow; |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | namespace dom { |
michael@0 | 25 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 26 | class SpeakerManagerService; |
michael@0 | 27 | #endif |
michael@0 | 28 | class AudioChannelService |
michael@0 | 29 | : public nsIObserver |
michael@0 | 30 | , public nsITimerCallback |
michael@0 | 31 | { |
michael@0 | 32 | public: |
michael@0 | 33 | NS_DECL_ISUPPORTS |
michael@0 | 34 | NS_DECL_NSIOBSERVER |
michael@0 | 35 | NS_DECL_NSITIMERCALLBACK |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Returns the AudioChannelServce singleton. Only to be called from main |
michael@0 | 39 | * thread. |
michael@0 | 40 | * |
michael@0 | 41 | * @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise. |
michael@0 | 42 | */ |
michael@0 | 43 | static AudioChannelService* GetAudioChannelService(); |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Shutdown the singleton. |
michael@0 | 47 | */ |
michael@0 | 48 | static void Shutdown(); |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Any audio channel agent that starts playing should register itself to |
michael@0 | 52 | * this service, sharing the AudioChannel. |
michael@0 | 53 | */ |
michael@0 | 54 | virtual void RegisterAudioChannelAgent(AudioChannelAgent* aAgent, |
michael@0 | 55 | AudioChannel aChannel, |
michael@0 | 56 | bool aWithVideo); |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Any audio channel agent that stops playing should unregister itself to |
michael@0 | 60 | * this service. |
michael@0 | 61 | */ |
michael@0 | 62 | virtual void UnregisterAudioChannelAgent(AudioChannelAgent* aAgent); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Return the state to indicate this agent should keep playing/ |
michael@0 | 66 | * fading volume/muted. |
michael@0 | 67 | */ |
michael@0 | 68 | virtual AudioChannelState GetState(AudioChannelAgent* aAgent, |
michael@0 | 69 | bool aElementHidden); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Return true if there is a content channel active in this process |
michael@0 | 73 | * or one of its subprocesses. |
michael@0 | 74 | */ |
michael@0 | 75 | virtual bool ContentOrNormalChannelIsActive(); |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Return true if a normal or content channel is active for the given |
michael@0 | 79 | * process ID. |
michael@0 | 80 | */ |
michael@0 | 81 | virtual bool ProcessContentOrNormalChannelIsActive(uint64_t aChildID); |
michael@0 | 82 | |
michael@0 | 83 | /*** |
michael@0 | 84 | * AudioChannelManager calls this function to notify the default channel used |
michael@0 | 85 | * to adjust volume when there is no any active channel. if aChannel is -1, |
michael@0 | 86 | * the default audio channel will be used. Otherwise aChannel is casted to |
michael@0 | 87 | * AudioChannel enum. |
michael@0 | 88 | */ |
michael@0 | 89 | virtual void SetDefaultVolumeControlChannel(int32_t aChannel, |
michael@0 | 90 | bool aHidden); |
michael@0 | 91 | |
michael@0 | 92 | bool AnyAudioChannelIsActive(); |
michael@0 | 93 | |
michael@0 | 94 | void RefreshAgentsVolume(nsPIDOMWindow* aWindow); |
michael@0 | 95 | |
michael@0 | 96 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 97 | void RegisterSpeakerManager(SpeakerManagerService* aSpeakerManager) |
michael@0 | 98 | { |
michael@0 | 99 | if (!mSpeakerManager.Contains(aSpeakerManager)) { |
michael@0 | 100 | mSpeakerManager.AppendElement(aSpeakerManager); |
michael@0 | 101 | } |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | void UnregisterSpeakerManager(SpeakerManagerService* aSpeakerManager) |
michael@0 | 105 | { |
michael@0 | 106 | mSpeakerManager.RemoveElement(aSpeakerManager); |
michael@0 | 107 | } |
michael@0 | 108 | #endif |
michael@0 | 109 | |
michael@0 | 110 | static const nsAttrValue::EnumTable* GetAudioChannelTable(); |
michael@0 | 111 | static AudioChannel GetAudioChannel(const nsAString& aString); |
michael@0 | 112 | static AudioChannel GetDefaultAudioChannel(); |
michael@0 | 113 | static void GetAudioChannelString(AudioChannel aChannel, nsAString& aString); |
michael@0 | 114 | static void GetDefaultAudioChannelString(nsAString& aString); |
michael@0 | 115 | |
michael@0 | 116 | protected: |
michael@0 | 117 | void Notify(); |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Send the audio-channel-changed notification for the given process ID if |
michael@0 | 121 | * needed. |
michael@0 | 122 | */ |
michael@0 | 123 | void SendAudioChannelChangedNotification(uint64_t aChildID); |
michael@0 | 124 | |
michael@0 | 125 | /* Register/Unregister IPC types: */ |
michael@0 | 126 | void RegisterType(AudioChannel aChannel, uint64_t aChildID, bool aWithVideo); |
michael@0 | 127 | void UnregisterType(AudioChannel aChannel, bool aElementHidden, |
michael@0 | 128 | uint64_t aChildID, bool aWithVideo); |
michael@0 | 129 | void UnregisterTypeInternal(AudioChannel aChannel, bool aElementHidden, |
michael@0 | 130 | uint64_t aChildID, bool aWithVideo); |
michael@0 | 131 | |
michael@0 | 132 | AudioChannelState GetStateInternal(AudioChannel aChannel, uint64_t aChildID, |
michael@0 | 133 | bool aElementHidden, |
michael@0 | 134 | bool aElementWasHidden); |
michael@0 | 135 | |
michael@0 | 136 | /* Update the internal type value following the visibility changes */ |
michael@0 | 137 | void UpdateChannelType(AudioChannel aChannel, uint64_t aChildID, |
michael@0 | 138 | bool aElementHidden, bool aElementWasHidden); |
michael@0 | 139 | |
michael@0 | 140 | /* Send the default-volume-channel-changed notification */ |
michael@0 | 141 | void SetDefaultVolumeControlChannelInternal(int32_t aChannel, |
michael@0 | 142 | bool aHidden, uint64_t aChildID); |
michael@0 | 143 | |
michael@0 | 144 | AudioChannelService(); |
michael@0 | 145 | virtual ~AudioChannelService(); |
michael@0 | 146 | |
michael@0 | 147 | enum AudioChannelInternalType { |
michael@0 | 148 | AUDIO_CHANNEL_INT_NORMAL = 0, |
michael@0 | 149 | AUDIO_CHANNEL_INT_NORMAL_HIDDEN, |
michael@0 | 150 | AUDIO_CHANNEL_INT_CONTENT, |
michael@0 | 151 | AUDIO_CHANNEL_INT_CONTENT_HIDDEN, |
michael@0 | 152 | AUDIO_CHANNEL_INT_NOTIFICATION, |
michael@0 | 153 | AUDIO_CHANNEL_INT_NOTIFICATION_HIDDEN, |
michael@0 | 154 | AUDIO_CHANNEL_INT_ALARM, |
michael@0 | 155 | AUDIO_CHANNEL_INT_ALARM_HIDDEN, |
michael@0 | 156 | AUDIO_CHANNEL_INT_TELEPHONY, |
michael@0 | 157 | AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN, |
michael@0 | 158 | AUDIO_CHANNEL_INT_RINGER, |
michael@0 | 159 | AUDIO_CHANNEL_INT_RINGER_HIDDEN, |
michael@0 | 160 | AUDIO_CHANNEL_INT_PUBLICNOTIFICATION, |
michael@0 | 161 | AUDIO_CHANNEL_INT_PUBLICNOTIFICATION_HIDDEN, |
michael@0 | 162 | AUDIO_CHANNEL_INT_LAST |
michael@0 | 163 | }; |
michael@0 | 164 | |
michael@0 | 165 | bool ChannelsActiveWithHigherPriorityThan(AudioChannelInternalType aType); |
michael@0 | 166 | |
michael@0 | 167 | bool CheckVolumeFadedCondition(AudioChannelInternalType aType, |
michael@0 | 168 | bool aElementHidden); |
michael@0 | 169 | |
michael@0 | 170 | AudioChannelInternalType GetInternalType(AudioChannel aChannel, |
michael@0 | 171 | bool aElementHidden); |
michael@0 | 172 | |
michael@0 | 173 | class AudioChannelAgentData { |
michael@0 | 174 | public: |
michael@0 | 175 | AudioChannelAgentData(AudioChannel aChannel, |
michael@0 | 176 | bool aElementHidden, |
michael@0 | 177 | AudioChannelState aState, |
michael@0 | 178 | bool aWithVideo) |
michael@0 | 179 | : mChannel(aChannel) |
michael@0 | 180 | , mElementHidden(aElementHidden) |
michael@0 | 181 | , mState(aState) |
michael@0 | 182 | , mWithVideo(aWithVideo) |
michael@0 | 183 | {} |
michael@0 | 184 | |
michael@0 | 185 | AudioChannel mChannel; |
michael@0 | 186 | bool mElementHidden; |
michael@0 | 187 | AudioChannelState mState; |
michael@0 | 188 | const bool mWithVideo; |
michael@0 | 189 | }; |
michael@0 | 190 | |
michael@0 | 191 | static PLDHashOperator |
michael@0 | 192 | NotifyEnumerator(AudioChannelAgent* aAgent, |
michael@0 | 193 | AudioChannelAgentData* aData, void *aUnused); |
michael@0 | 194 | |
michael@0 | 195 | static PLDHashOperator |
michael@0 | 196 | RefreshAgentsVolumeEnumerator(AudioChannelAgent* aAgent, |
michael@0 | 197 | AudioChannelAgentData* aUnused, |
michael@0 | 198 | void *aPtr); |
michael@0 | 199 | |
michael@0 | 200 | static PLDHashOperator |
michael@0 | 201 | CountWindowEnumerator(AudioChannelAgent* aAgent, |
michael@0 | 202 | AudioChannelAgentData* aUnused, |
michael@0 | 203 | void *aPtr); |
michael@0 | 204 | |
michael@0 | 205 | // This returns the number of agents from this aWindow. |
michael@0 | 206 | uint32_t CountWindow(nsIDOMWindow* aWindow); |
michael@0 | 207 | |
michael@0 | 208 | nsClassHashtable< nsPtrHashKey<AudioChannelAgent>, AudioChannelAgentData > mAgents; |
michael@0 | 209 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 210 | nsTArray<SpeakerManagerService*> mSpeakerManager; |
michael@0 | 211 | #endif |
michael@0 | 212 | nsTArray<uint64_t> mChannelCounters[AUDIO_CHANNEL_INT_LAST]; |
michael@0 | 213 | |
michael@0 | 214 | int32_t mCurrentHigherChannel; |
michael@0 | 215 | int32_t mCurrentVisibleHigherChannel; |
michael@0 | 216 | |
michael@0 | 217 | nsTArray<uint64_t> mWithVideoChildIDs; |
michael@0 | 218 | |
michael@0 | 219 | // mPlayableHiddenContentChildID stores the ChildID of the process which can |
michael@0 | 220 | // play content channel(s) in the background. |
michael@0 | 221 | // A background process contained content channel(s) will become playable: |
michael@0 | 222 | // 1. When this background process registers its content channel(s) in |
michael@0 | 223 | // AudioChannelService and there is no foreground process with registered |
michael@0 | 224 | // content channel(s). |
michael@0 | 225 | // 2. When this process goes from foreground into background and there is |
michael@0 | 226 | // no foreground process with registered content channel(s). |
michael@0 | 227 | // A background process contained content channel(s) will become non-playable: |
michael@0 | 228 | // 1. When there is a foreground process registering its content channel(s) |
michael@0 | 229 | // in AudioChannelService. |
michael@0 | 230 | // ps. Currently this condition is never satisfied because the default value |
michael@0 | 231 | // of visibility status of each channel during registering is hidden = true. |
michael@0 | 232 | // 2. When there is a process with registered content channel(s) goes from |
michael@0 | 233 | // background into foreground. |
michael@0 | 234 | // 3. When this process unregisters all hidden content channels. |
michael@0 | 235 | // 4. When this process shuts down. |
michael@0 | 236 | uint64_t mPlayableHiddenContentChildID; |
michael@0 | 237 | |
michael@0 | 238 | bool mDisabled; |
michael@0 | 239 | |
michael@0 | 240 | nsCOMPtr<nsITimer> mDeferTelChannelTimer; |
michael@0 | 241 | bool mTimerElementHidden; |
michael@0 | 242 | uint64_t mTimerChildID; |
michael@0 | 243 | |
michael@0 | 244 | uint64_t mDefChannelChildID; |
michael@0 | 245 | |
michael@0 | 246 | // This is needed for IPC comunication between |
michael@0 | 247 | // AudioChannelServiceChild and this class. |
michael@0 | 248 | friend class ContentParent; |
michael@0 | 249 | friend class ContentChild; |
michael@0 | 250 | }; |
michael@0 | 251 | |
michael@0 | 252 | } // namespace dom |
michael@0 | 253 | } // namespace mozilla |
michael@0 | 254 | |
michael@0 | 255 | #endif |