diff --git a/dom/audiochannel/AudioChannelAgent.cpp b/dom/audiochannel/AudioChannelAgent.cpp index 31a6cc14032a..ac46b5c049b6 100644 --- a/dom/audiochannel/AudioChannelAgent.cpp +++ b/dom/audiochannel/AudioChannelAgent.cpp @@ -6,11 +6,7 @@ #include "AudioChannelAgent.h" #include "AudioChannelService.h" -#include "mozilla/Preferences.h" -#include "nsIAppsService.h" -#include "nsIDocument.h" #include "nsIDOMWindow.h" -#include "nsIPrincipal.h" #include "nsPIDOMWindow.h" #include "nsXULAppAPI.h" @@ -81,81 +77,6 @@ AudioChannelAgent::InitWithWeakCallback(nsIDOMWindow* aWindow, /* useWeakRef = */ true); } -nsresult -AudioChannelAgent::FindCorrectWindow(nsIDOMWindow* aWindow) -{ - nsCOMPtr window = do_QueryInterface(aWindow); - MOZ_ASSERT(window->IsInnerWindow()); - - mWindow = window->GetScriptableTop(); - if (NS_WARN_IF(!mWindow)) { - return NS_OK; - } - - mWindow = mWindow->GetOuterWindow(); - if (NS_WARN_IF(!mWindow)) { - return NS_ERROR_FAILURE; - } - - // From here we do an hack for nested iframes. - // The system app doesn't have access to the nested iframe objects so it - // cannot control the volume of the agents running in nested apps. What we do - // here is to assign those Agents to the top scriptable window of the parent - // iframe (what is controlled by the system app). - // For doing this we go recursively back into the chain of windows until we - // find apps that are not the system one. - window = mWindow->GetParent(); - if (!window || window == mWindow) { - return NS_OK; - } - - window = window->GetCurrentInnerWindow(); - if (!window) { - return NS_OK; - } - - nsCOMPtr doc = window->GetExtantDoc(); - if (!doc) { - return NS_OK; - } - - nsCOMPtr principal = doc->NodePrincipal(); - - uint32_t appId; - nsresult rv = principal->GetAppId(&appId); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - if (appId == nsIScriptSecurityManager::NO_APP_ID || - appId == nsIScriptSecurityManager::UNKNOWN_APP_ID) { - return NS_OK; - } - - nsCOMPtr appsService = do_GetService(APPS_SERVICE_CONTRACTID); - if (NS_WARN_IF(!appsService)) { - return NS_ERROR_FAILURE; - } - - nsAdoptingString systemAppManifest = - mozilla::Preferences::GetString("b2g.system_manifest_url"); - if (!systemAppManifest) { - return NS_OK; - } - - uint32_t systemAppId; - rv = appsService->GetAppLocalIdByManifestURL(systemAppManifest, &systemAppId); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - if (systemAppId == appId) { - return NS_OK; - } - - return FindCorrectWindow(window); -} - nsresult AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType, nsIAudioChannelAgentCallback *aCallback, @@ -187,9 +108,18 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType, MOZ_ASSERT(pInnerWindow->IsInnerWindow()); mInnerWindowID = pInnerWindow->WindowID(); - nsresult rv = FindCorrectWindow(aWindow); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; + nsCOMPtr topWindow = pInnerWindow->GetScriptableTop(); + if (NS_WARN_IF(!topWindow)) { + return NS_OK; + } + + mWindow = do_QueryInterface(topWindow); + if (mWindow) { + mWindow = mWindow->GetOuterWindow(); + } + + if (NS_WARN_IF(!mWindow)) { + return NS_ERROR_FAILURE; } mAudioChannelType = aChannelType; diff --git a/dom/audiochannel/AudioChannelAgent.h b/dom/audiochannel/AudioChannelAgent.h index 9487b33aef97..74271199ec8a 100644 --- a/dom/audiochannel/AudioChannelAgent.h +++ b/dom/audiochannel/AudioChannelAgent.h @@ -56,8 +56,6 @@ private: void Shutdown(); - nsresult FindCorrectWindow(nsIDOMWindow* aWindow); - nsCOMPtr mWindow; nsCOMPtr mCallback; diff --git a/dom/browser-element/mochitest/browserElement_AudioChannel.js b/dom/browser-element/mochitest/browserElement_AudioChannel.js index 38ff10a2b622..d5e8a3da9c03 100644 --- a/dom/browser-element/mochitest/browserElement_AudioChannel.js +++ b/dom/browser-element/mochitest/browserElement_AudioChannel.js @@ -192,10 +192,7 @@ function runTests() { } -addEventListener('testready', function() { - SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]}, - function() { - SimpleTest.executeSoon(runTests); - }); +addEventListener('load', function() { + SimpleTest.executeSoon(runTests); }); diff --git a/dom/browser-element/mochitest/browserElement_AudioChannel_nested.js b/dom/browser-element/mochitest/browserElement_AudioChannel_nested.js index 226d6377ff0b..54b0d4047561 100644 --- a/dom/browser-element/mochitest/browserElement_AudioChannel_nested.js +++ b/dom/browser-element/mochitest/browserElement_AudioChannel_nested.js @@ -72,8 +72,5 @@ function runTests() { } addEventListener('testready', function() { - SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]}, - function() { - SimpleTest.executeSoon(runTests); - }); + SimpleTest.executeSoon(runTests); }); diff --git a/dom/browser-element/mochitest/browserElement_AudioPlayback.js b/dom/browser-element/mochitest/browserElement_AudioPlayback.js index 8a8b5e7a828f..42dba665c8ab 100644 --- a/dom/browser-element/mochitest/browserElement_AudioPlayback.js +++ b/dom/browser-element/mochitest/browserElement_AudioPlayback.js @@ -68,9 +68,4 @@ function runTest() { iframe.src = browserElementTestHelpers.emptyPage1; } -addEventListener('testready', function() { - SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]}, - function() { - SimpleTest.executeSoon(runTest); - }); -}); +addEventListener('testready', runTest);