Backed out changeset eb3d458624eb (bug 1214148)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Tue, 15 Dec 2015 14:48:44 +0100
changeset 317123 98dc080d53ca3f5c9414008a27ae16f06fb65e24
parent 317122 1c4b9f6f5dfa917426bcf559ee78c6dc54157bef
child 317124 39f2a4d3cdb6c830616ee64ea4635f19cc499f28
push id8643
push usermconley@mozilla.com
push dateTue, 22 Dec 2015 18:28:20 +0000
bugs1214148
milestone45.0a2
backs outeb3d458624eb3a62e8aebfaed322a63314153d3e
Backed out changeset eb3d458624eb (bug 1214148)
dom/audiochannel/AudioChannelAgent.cpp
dom/audiochannel/AudioChannelAgent.h
dom/browser-element/mochitest/browserElement_AudioChannel.js
dom/browser-element/mochitest/browserElement_AudioChannel_nested.js
dom/browser-element/mochitest/browserElement_AudioPlayback.js
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -1,21 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "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"
 
 using namespace mozilla::dom;
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(AudioChannelAgent)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AudioChannelAgent)
@@ -77,91 +73,16 @@ AudioChannelAgent::InitWithWeakCallback(
                                         int32_t aChannelType,
                                         nsIAudioChannelAgentCallback *aCallback)
 {
   return InitInternal(aWindow, aChannelType, aCallback,
                       /* useWeakRef = */ true);
 }
 
 nsresult
-AudioChannelAgent::FindCorrectWindow(nsIDOMWindow* aWindow)
-{
-  nsCOMPtr<nsPIDOMWindow> 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<nsIDocument> doc = window->GetExtantDoc();
-  if (!doc) {
-    return NS_OK;
-  }
-
-  nsCOMPtr<nsIPrincipal> 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<nsIAppsService> 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,
                                 bool aUseWeakRef)
 {
   // We syncd the enum of channel type between nsIAudioChannelAgent.idl and
   // AudioChannelBinding.h the same.
   MOZ_ASSERT(int(AUDIO_AGENT_CHANNEL_NORMAL) == int(AudioChannel::Normal) &&
              int(AUDIO_AGENT_CHANNEL_CONTENT) == int(AudioChannel::Content) &&
@@ -182,19 +103,28 @@ AudioChannelAgent::InitInternal(nsIDOMWi
   if (NS_WARN_IF(!aWindow)) {
     return NS_OK;
   }
 
   nsCOMPtr<nsPIDOMWindow> pInnerWindow = do_QueryInterface(aWindow);
   MOZ_ASSERT(pInnerWindow->IsInnerWindow());
   mInnerWindowID = pInnerWindow->WindowID();
 
-  nsresult rv = FindCorrectWindow(aWindow);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+  nsCOMPtr<nsPIDOMWindow> 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;
 
   if (aUseWeakRef) {
     mWeakCallback = do_GetWeakReference(aCallback);
   } else {
     mCallback = aCallback;
--- a/dom/audiochannel/AudioChannelAgent.h
+++ b/dom/audiochannel/AudioChannelAgent.h
@@ -51,18 +51,16 @@ private:
   already_AddRefed<nsIAudioChannelAgentCallback> GetCallback();
 
   nsresult InitInternal(nsIDOMWindow* aWindow, int32_t aAudioAgentType,
                         nsIAudioChannelAgentCallback* aCallback,
                         bool aUseWeakRef);
 
   void Shutdown();
 
-  nsresult FindCorrectWindow(nsIDOMWindow* aWindow);
-
   nsCOMPtr<nsPIDOMWindow> mWindow;
   nsCOMPtr<nsIAudioChannelAgentCallback> mCallback;
 
   nsWeakPtr mWeakCallback;
 
   int32_t mAudioChannelType;
   uint64_t mInnerWindowID;
   bool mIsRegToService;
--- a/dom/browser-element/mochitest/browserElement_AudioChannel.js
+++ b/dom/browser-element/mochitest/browserElement_AudioChannel.js
@@ -187,15 +187,12 @@ function runTests() {
     return;
   }
 
   var test = tests.shift();
   test();
 }
 
 
-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);
 });
 
--- a/dom/browser-element/mochitest/browserElement_AudioChannel_nested.js
+++ b/dom/browser-element/mochitest/browserElement_AudioChannel_nested.js
@@ -67,13 +67,10 @@ function runTests() {
     {'type': 'browser', 'allow': 1, 'context': context},
     {'type': 'embed-apps', 'allow': 1, 'context': context}
   ], function() {
     iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AudioChannel_nested.html';
   });
 }
 
 addEventListener('testready', function() {
-  SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]},
-                            function() {
-    SimpleTest.executeSoon(runTests);
-  });
+  SimpleTest.executeSoon(runTests);
 });
--- a/dom/browser-element/mochitest/browserElement_AudioPlayback.js
+++ b/dom/browser-element/mochitest/browserElement_AudioPlayback.js
@@ -63,14 +63,9 @@ function runTest() {
     ok(false,
        'mozbrowseraudioplaybackchange should dispatch to the correct browser');
   });
 
   // Load a simple page to get the process started.
   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);