From 54a023476684aea642d2dba29aec08aa61657d7f Mon Sep 17 00:00:00 2001 From: Noemi Erli Date: Thu, 2 May 2019 06:41:33 +0300 Subject: [PATCH] Backed out 6 changesets (bug 1540573) for failures in test_CSP.html Backed out changeset 599e6e06599d (bug 1540573) Backed out changeset bf725b7daa5b (bug 1540573) Backed out changeset 814c94b26028 (bug 1540573) Backed out changeset 3496ca48f6e0 (bug 1540573) Backed out changeset 2c4303b175ec (bug 1540573) Backed out changeset b49cd2b191ae (bug 1540573) --- dom/html/HTMLMediaElement.cpp | 30 ++------ dom/html/HTMLMediaElement.h | 3 - dom/ipc/ContentChild.cpp | 11 --- dom/ipc/ContentChild.h | 5 -- dom/ipc/ContentParent.cpp | 22 ------ dom/ipc/ContentParent.h | 2 - dom/ipc/PContent.ipdl | 2 - dom/media/ChannelMediaDecoder.cpp | 11 +-- dom/media/FileBlockCache.cpp | 15 ++-- dom/media/FileBlockCache.h | 2 +- dom/media/MediaBlockCacheBase.h | 2 +- dom/media/MediaCache.cpp | 77 ++----------------- dom/media/MemoryBlockCache.h | 4 +- dom/media/VideoUtils.cpp | 45 ----------- dom/media/VideoUtils.h | 4 - mobile/android/app/mobile.js | 10 ++- .../org/mozilla/geckoview/GeckoRuntime.java | 39 ---------- modules/libpref/init/StaticPrefList.h | 41 +++++----- 18 files changed, 56 insertions(+), 269 deletions(-) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 0cf392bc35fd..d518164d73c5 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -2454,27 +2454,6 @@ bool HTMLMediaElement::AllowedToPlay() const { return AutoplayPolicy::IsAllowedToPlay(*this); } -uint32_t HTMLMediaElement::GetPreloadDefault() const { - if (mMediaSource) { - return HTMLMediaElement::PRELOAD_ATTR_METADATA; - } - if (OnCellularConnection()) { - return Preferences::GetInt("media.preload.default.cellular", - HTMLMediaElement::PRELOAD_ATTR_NONE); - } - return Preferences::GetInt("media.preload.default", - HTMLMediaElement::PRELOAD_ATTR_METADATA); -} - -uint32_t HTMLMediaElement::GetPreloadDefaultAuto() const { - if (OnCellularConnection()) { - return Preferences::GetInt("media.preload.auto.cellular", - HTMLMediaElement::PRELOAD_ATTR_METADATA); - } - return Preferences::GetInt("media.preload.auto", - HTMLMediaElement::PRELOAD_ENOUGH); -} - void HTMLMediaElement::UpdatePreloadAction() { PreloadAction nextAction = PRELOAD_UNDEFINED; // If autoplay is set, or we're playing, we should always preload data, @@ -2489,8 +2468,13 @@ void HTMLMediaElement::UpdatePreloadAction() { mAttrs.GetAttr(nsGkAtoms::preload, kNameSpaceID_None); // MSE doesn't work if preload is none, so it ignores the pref when src is // from MSE. - uint32_t preloadDefault = GetPreloadDefault(); - uint32_t preloadAuto = GetPreloadDefaultAuto(); + uint32_t preloadDefault = + mMediaSource + ? HTMLMediaElement::PRELOAD_ATTR_METADATA + : Preferences::GetInt("media.preload.default", + HTMLMediaElement::PRELOAD_ATTR_METADATA); + uint32_t preloadAuto = Preferences::GetInt( + "media.preload.auto", HTMLMediaElement::PRELOAD_ENOUGH); if (!val) { // Attribute is not set. Use the preload action specified by the // media.preload.default pref, or just preload metadata if not present. diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index a99afd09ceb6..e10261e77d96 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -1737,9 +1737,6 @@ class HTMLMediaElement : public nsGenericHTMLElement, virtual void MaybeBeginCloningVisually(){}; - uint32_t GetPreloadDefault() const; - uint32_t GetPreloadDefaultAuto() const; - /** * This function is called by AfterSetAttr and OnAttrSetButNotChanged. * It will not be called if the value is being unset. diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index acd71b0a7895..7e14a1cf0e93 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -2029,17 +2029,6 @@ mozilla::ipc::IPCResult ContentChild::RecvPScriptCacheConstructor( PNeckoChild* ContentChild::AllocPNeckoChild() { return new NeckoChild(); } -mozilla::ipc::IPCResult ContentChild::RecvNetworkLinkTypeChange( - const uint32_t& aType) { - mNetworkLinkType = aType; - nsCOMPtr obs = mozilla::services::GetObserverService(); - if (obs) { - obs->NotifyObservers(nullptr, "contentchild:network-link-type-changed", - nullptr); - } - return IPC_OK(); -} - bool ContentChild::DeallocPNeckoChild(PNeckoChild* necko) { delete necko; return true; diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index c54d0ab6cc7f..d0675b94031f 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -489,9 +489,6 @@ class ContentChild final : public PContentChild, mozilla::ipc::IPCResult RecvRefreshScreens( nsTArray&& aScreens); - mozilla::ipc::IPCResult RecvNetworkLinkTypeChange(const uint32_t& aType); - uint32_t NetworkLinkType() const { return mNetworkLinkType; } - // Get the directory for IndexedDB files. We query the parent for this and // cache the value nsString& GetIndexedDBPath(); @@ -813,8 +810,6 @@ class ContentChild final : public PContentChild, mozilla::Atomic mPendingInputEvents; #endif - uint32_t mNetworkLinkType = 0; - DISALLOW_EVIL_CONSTRUCTORS(ContentChild); }; diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index d3071f452f58..f926f9e3d5db 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -158,7 +158,6 @@ #include "nsIMemoryReporter.h" #include "nsIMozBrowserFrame.h" #include "nsIMutable.h" -#include "nsINetworkLinkService.h" #include "nsIObserverService.h" #include "nsIParentChannel.h" #include "nsIRemoteWindowContext.h" @@ -615,7 +614,6 @@ static const char* sObserverTopics[] = { "cookie-changed", "private-cookie-changed", "clear-site-data-reload-needed", - NS_NETWORK_LINK_TYPE_TOPIC, }; #if defined(XP_MACOSX) && defined(MOZ_SANDBOX) @@ -3122,30 +3120,10 @@ ContentParent::Observe(nsISupports* aSubject, const char* aTopic, } else if (!strcmp(aTopic, "clear-site-data-reload-needed")) { // Rebroadcast "clear-site-data-reload-needed". Unused << SendClearSiteDataReloadNeeded(nsString(aData)); - } else if (!strcmp(aTopic, NS_NETWORK_LINK_TYPE_TOPIC)) { - UpdateNetworkLinkType(); } - return NS_OK; } -void ContentParent::UpdateNetworkLinkType() { - nsresult rv; - nsCOMPtr nls = - do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) { - return; - } - - uint32_t linkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN; - rv = nls->GetLinkType(&linkType); - if (NS_FAILED(rv)) { - return; - } - - Unused << SendNetworkLinkTypeChange(linkType); -} - NS_IMETHODIMP ContentParent::GetInterface(const nsIID& aIID, void** aResult) { NS_ENSURE_ARG_POINTER(aResult); diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 221b71388b7a..6e8620e6e5a5 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -1213,8 +1213,6 @@ class ContentParent final : public PContentParent, void OnBrowsingContextGroupSubscribe(BrowsingContextGroup* aGroup); void OnBrowsingContextGroupUnsubscribe(BrowsingContextGroup* aGroup); - void UpdateNetworkLinkType(); - private: // Released in ActorDestroy; deliberately not exposed to the CC. RefPtr mSelfRef; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index b21502ef3831..b1b381497cbd 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -430,8 +430,6 @@ child: async AudioDefaultDeviceChange(); - async NetworkLinkTypeChange(uint32_t type); - // Re-create the rendering stack for a device reset. async ReinitRenderingForDeviceReset(); diff --git a/dom/media/ChannelMediaDecoder.cpp b/dom/media/ChannelMediaDecoder.cpp index 6ed95cd449a5..b732d1ae4626 100644 --- a/dom/media/ChannelMediaDecoder.cpp +++ b/dom/media/ChannelMediaDecoder.cpp @@ -11,7 +11,6 @@ #include "BaseMediaResource.h" #include "MediaShutdownManager.h" #include "mozilla/StaticPrefs.h" -#include "VideoUtils.h" namespace mozilla { @@ -459,9 +458,8 @@ MediaStatistics ChannelMediaDecoder::GetStatistics( bool ChannelMediaDecoder::ShouldThrottleDownload( const MediaStatistics& aStats) { // We throttle the download if either the throttle override pref is set - // (so that we always throttle at the readahead limit on mobile if using - // a cellular network) or if the download is fast enough that there's no - // concern about playback being interrupted. + // (so that we can always throttle in Firefox on mobile) or if the download + // is fast enough that there's no concern about playback being interrupted. MOZ_ASSERT(NS_IsMainThread()); NS_ENSURE_TRUE(GetStateMachine(), false); @@ -474,9 +472,8 @@ bool ChannelMediaDecoder::ShouldThrottleDownload( return false; } - if (OnCellularConnection() && - Preferences::GetBool( - "media.throttle-cellular-regardless-of-download-rate", false)) { + if (Preferences::GetBool("media.throttle-regardless-of-download-rate", + false)) { return true; } diff --git a/dom/media/FileBlockCache.cpp b/dom/media/FileBlockCache.cpp index f8a6b06bcd7f..4d6cc8bbedcd 100644 --- a/dom/media/FileBlockCache.cpp +++ b/dom/media/FileBlockCache.cpp @@ -125,9 +125,11 @@ void FileBlockCache::Flush() { })); } -size_t FileBlockCache::GetMaxBlocks(size_t aCacheSizeInKB) const { +int32_t FileBlockCache::GetMaxBlocks() const { // We look up the cache size every time. This means dynamic changes // to the pref are applied. + const uint32_t cacheSizeKb = + std::min(StaticPrefs::MediaCacheSize(), uint32_t(INT32_MAX) * 2); // Ensure we can divide BLOCK_SIZE by 1024. static_assert(MediaCacheStream::BLOCK_SIZE % 1024 == 0, "BLOCK_SIZE should be a multiple of 1024"); @@ -138,13 +140,14 @@ size_t FileBlockCache::GetMaxBlocks(size_t aCacheSizeInKB) const { static_assert(MediaCacheStream::BLOCK_SIZE / 1024 <= int64_t(UINT32_MAX), "BLOCK_SIZE / 1024 should be at most UINT32_MAX"); // Since BLOCK_SIZE is a strict multiple of 1024, - // aCacheSizeInKB * 1024 / BLOCK_SIZE == aCacheSizeInKB / (BLOCK_SIZE / - // 1024), but the latter formula avoids a potential overflow from `* 1024`. + // cacheSizeKb * 1024 / BLOCK_SIZE == cacheSizeKb / (BLOCK_SIZE / 1024), + // but the latter formula avoids a potential overflow from `* 1024`. // And because BLOCK_SIZE/1024 is at least 2, the maximum cache size // INT32_MAX*2 will give a maxBlocks that can fit in an int32_t. - constexpr size_t blockSizeKb = size_t(MediaCacheStream::BLOCK_SIZE / 1024); - const size_t maxBlocks = aCacheSizeInKB / blockSizeKb; - return std::max(maxBlocks, size_t(1)); + constexpr uint32_t blockSizeKb = + uint32_t(MediaCacheStream::BLOCK_SIZE / 1024); + const int32_t maxBlocks = int32_t(cacheSizeKb / blockSizeKb); + return std::max(maxBlocks, int32_t(1)); } FileBlockCache::FileBlockCache() diff --git a/dom/media/FileBlockCache.h b/dom/media/FileBlockCache.h index 420f3cf76a27..19188d7eca47 100644 --- a/dom/media/FileBlockCache.h +++ b/dom/media/FileBlockCache.h @@ -68,7 +68,7 @@ class FileBlockCache : public MediaBlockCacheBase { // Maximum number of blocks allowed in this block cache. // Calculated from "media.cache_size" pref. - size_t GetMaxBlocks(size_t aCacheSizeInKB) const override; + int32_t GetMaxBlocks() const override; // Can be called on any thread. This defers to a non-main thread. nsresult WriteBlock(uint32_t aBlockIndex, Span aData1, diff --git a/dom/media/MediaBlockCacheBase.h b/dom/media/MediaBlockCacheBase.h index 97c3a6c1b0fc..3a4c78b6a26c 100644 --- a/dom/media/MediaBlockCacheBase.h +++ b/dom/media/MediaBlockCacheBase.h @@ -56,7 +56,7 @@ class MediaBlockCacheBase { // Maximum number of blocks expected in this block cache. (But allow overflow // to accomodate incoming traffic before MediaCache can handle it.) - virtual size_t GetMaxBlocks(size_t aCacheSizeInKiB) const = 0; + virtual int32_t GetMaxBlocks() const = 0; // Can be called on any thread. This defers to a non-main thread. virtual nsresult WriteBlock(uint32_t aBlockIndex, Span aData1, diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index 559eb77870f5..317972dd67be 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -11,7 +11,6 @@ #include "MediaBlockCacheBase.h" #include "MediaResource.h" #include "MemoryBlockCache.h" -#include "mozilla/Atomics.h" #include "mozilla/Attributes.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/ErrorNames.h" @@ -24,14 +23,12 @@ #include "mozilla/SystemGroup.h" #include "mozilla/Telemetry.h" #include "nsContentUtils.h" -#include "nsINetworkLinkService.h" #include "nsIObserverService.h" #include "nsIPrincipal.h" #include "nsPrintfCString.h" #include "nsProxyRelease.h" #include "nsThreadUtils.h" #include "prio.h" -#include "VideoUtils.h" #include namespace mozilla { @@ -117,6 +114,7 @@ void MediaCacheFlusher::RegisterMediaCache(MediaCache* aMediaCache) { if (!gMediaCacheFlusher) { gMediaCacheFlusher = new MediaCacheFlusher(); + nsCOMPtr observerService = mozilla::services::GetObserverService(); if (observerService) { @@ -124,10 +122,6 @@ void MediaCacheFlusher::RegisterMediaCache(MediaCache* aMediaCache) { true); observerService->AddObserver(gMediaCacheFlusher, "cacheservice:empty-cache", true); - observerService->AddObserver( - gMediaCacheFlusher, "contentchild:network-link-type-changed", true); - observerService->AddObserver(gMediaCacheFlusher, - NS_NETWORK_LINK_TYPE_TOPIC, true); } } @@ -248,10 +242,6 @@ class MediaCache { return mMonitor; } - // Updates the cache size, readahead limit, and resume threshold, based on - // whether we're on a cellular connection or not. Main thread only. - static void UpdateGeometryStatics(); - /** * An iterator that makes it easy to iterate through all streams that * have a given resource ID and are not closed. @@ -292,7 +282,6 @@ class MediaCache { NS_ASSERTION(NS_IsMainThread(), "Only construct MediaCache on main thread"); MOZ_COUNT_CTOR(MediaCache); MediaCacheFlusher::RegisterMediaCache(this); - UpdateGeometryStatics(); } ~MediaCache() { @@ -324,21 +313,6 @@ class MediaCache { MOZ_COUNT_DTOR(MediaCache); } - static size_t CacheSize() { - MOZ_ASSERT(sThread->IsOnCurrentThread()); - return sCacheSizeInKB; - } - - static size_t ReadaheadLimit() { - MOZ_ASSERT(sThread->IsOnCurrentThread()); - return sReadaheadLimit; - } - - static size_t ResumeThreshold() { - MOZ_ASSERT(sThread->IsOnCurrentThread()); - return sResumeThreshold; - } - // Find a free or reusable block and return its index. If there are no // free blocks and no reusable blocks, add a new block to the cache // and return it. Can return -1 on OOM. @@ -477,11 +451,6 @@ class MediaCache { // to access sThread on all threads. static bool sThreadInit; - // Accesson MediaCache thread only. - static size_t sCacheSizeInKB; - static size_t sReadaheadLimit; - static size_t sResumeThreshold; - private: // Used by MediaCacheStream::GetDebugInfo() only for debugging. // Don't add new callers to this function. @@ -501,37 +470,6 @@ StaticRefPtr MediaCache::sThread; /* static */ bool MediaCache::sThreadInit = false; -/* static */ size_t MediaCache::sCacheSizeInKB = 0; -/* static */ size_t MediaCache::sReadaheadLimit = 0; -/* static */ size_t MediaCache::sResumeThreshold = 0; - -void MediaCache::UpdateGeometryStatics() { - NS_ASSERTION(NS_IsMainThread(), - "Only call on main thread"); // JNI required on Android... - bool cacheAggressively = !OnCellularConnection(); - LOG("MediaCache::UpdateGeometryStatics() cacheAggressively=%d", - cacheAggressively); - // Read the prefs on the main thread, and post their value to the MediaCache - // thread. This ensures the values are synchronized. - uint32_t cacheSize = 0, readaheadLimit = 0, resumeThreshold = 0; - if (cacheAggressively) { - cacheSize = StaticPrefs::MediaCacheSize(); - readaheadLimit = StaticPrefs::MediaCacheReadaheadLimit(); - resumeThreshold = StaticPrefs::MediaCacheResumeThreshold(); - } else { - cacheSize = StaticPrefs::MediaCacheCellularSize(); - readaheadLimit = StaticPrefs::MediaCacheCellularReadaheadLimit(); - resumeThreshold = StaticPrefs::MediaCacheCellularResumeThreshold(); - } - nsCOMPtr r = - NS_NewRunnableFunction("MediaCache::UpdateGeometryStatics", [=]() { - sCacheSizeInKB = cacheSize; - sReadaheadLimit = readaheadLimit; - sResumeThreshold = resumeThreshold; - }); - sThread->Dispatch(r.forget()); -} - NS_IMETHODIMP MediaCacheFlusher::Observe(nsISupports* aSubject, char const* aTopic, char16_t const* aData) { @@ -549,10 +487,6 @@ MediaCacheFlusher::Observe(nsISupports* aSubject, char const* aTopic, } return NS_OK; } - if (strcmp(aTopic, "contentchild:network-link-type-changed") == 0 || - strcmp(aTopic, NS_NETWORK_LINK_TYPE_TOPIC) == 0) { - MediaCache::UpdateGeometryStatics(); - } return NS_OK; } @@ -893,8 +827,7 @@ int32_t MediaCache::FindBlockForIncomingData(AutoLock& aLock, TimeStamp aNow, // b) the data we're going to store in the free block is not higher // priority than the data already stored in the free block. // The latter can lead us to go over the cache limit a bit. - if ((mIndex.Length() < - uint32_t(mBlockCache->GetMaxBlocks(MediaCache::CacheSize())) || + if ((mIndex.Length() < uint32_t(mBlockCache->GetMaxBlocks()) || blockIndex < 0 || PredictNextUseForIncomingData(aLock, aStream) >= PredictNextUse(aLock, aNow, blockIndex))) { @@ -1222,7 +1155,7 @@ void MediaCache::Update() { mInUpdate = true; #endif - int32_t maxBlocks = mBlockCache->GetMaxBlocks(MediaCache::CacheSize()); + int32_t maxBlocks = mBlockCache->GetMaxBlocks(); TimeStamp now = TimeStamp::Now(); int32_t freeBlockCount = mFreeBlocks.GetCount(); @@ -1343,8 +1276,8 @@ void MediaCache::Update() { } } - int32_t resumeThreshold = MediaCache::ResumeThreshold(); - int32_t readaheadLimit = MediaCache::ReadaheadLimit(); + int32_t resumeThreshold = StaticPrefs::MediaCacheResumeThreshold(); + int32_t readaheadLimit = StaticPrefs::MediaCacheReadaheadLimit(); for (uint32_t i = 0; i < mStreams.Length(); ++i) { actions.AppendElement(StreamAction{}); diff --git a/dom/media/MemoryBlockCache.h b/dom/media/MemoryBlockCache.h index abebb5125e72..3b854597612e 100644 --- a/dom/media/MemoryBlockCache.h +++ b/dom/media/MemoryBlockCache.h @@ -45,7 +45,7 @@ class MemoryBlockCache : public MediaBlockCacheBase { // Maximum number of blocks allowed in this block cache. // Based on initial content length, and minimum usable block cache. - size_t GetMaxBlocks(size_t) const override { return mMaxBlocks; } + int32_t GetMaxBlocks() const override { return mMaxBlocks; } // Can be called on any thread. virtual nsresult WriteBlock(uint32_t aBlockIndex, Span aData1, @@ -73,7 +73,7 @@ class MemoryBlockCache : public MediaBlockCacheBase { const size_t mInitialContentLength; // Maximum number of blocks that this MemoryBlockCache expects. - const size_t mMaxBlocks; + const int32_t mMaxBlocks; // Mutex which controls access to all members below. Mutex mMutex; diff --git a/dom/media/VideoUtils.cpp b/dom/media/VideoUtils.cpp index dc0631eae5a9..0dddf90e384f 100644 --- a/dom/media/VideoUtils.cpp +++ b/dom/media/VideoUtils.cpp @@ -14,7 +14,6 @@ #include "TimeUnits.h" #include "VorbisUtils.h" #include "mozilla/Base64.h" -#include "mozilla/dom/ContentChild.h" #include "mozilla/SharedThreadPool.h" #include "mozilla/StaticPrefs.h" #include "mozilla/SystemGroup.h" @@ -24,11 +23,9 @@ #include "nsCharSeparatedTokenizer.h" #include "nsContentTypeParser.h" #include "nsIConsoleService.h" -#include "nsINetworkLinkService.h" #include "nsIRandomGenerator.h" #include "nsIServiceManager.h" #include "nsMathUtils.h" -#include "nsNetCID.h" #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" @@ -715,46 +712,4 @@ UniquePtr CreateTrackInfoWithMIMETypeAndContainerTypeExtraParameters( return trackInfo; } -bool OnCellularConnection() { - uint32_t linkType = nsINetworkLinkService::LINK_TYPE_UNKNOWN; - if (XRE_IsContentProcess()) { - mozilla::dom::ContentChild* cpc = - mozilla::dom::ContentChild::GetSingleton(); - if (!cpc) { - NS_WARNING("Can't get ContentChild singleton in content process!"); - return false; - } - linkType = cpc->NetworkLinkType(); - } else { - nsresult rv; - nsCOMPtr nls = - do_GetService(NS_NETWORK_LINK_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) { - NS_WARNING("Can't get nsINetworkLinkService."); - return false; - } - - rv = nls->GetLinkType(&linkType); - if (NS_FAILED(rv)) { - NS_WARNING("Can't get network link type."); - return false; - } - } - - switch (linkType) { - case nsINetworkLinkService::LINK_TYPE_UNKNOWN: - case nsINetworkLinkService::LINK_TYPE_ETHERNET: - case nsINetworkLinkService::LINK_TYPE_USB: - case nsINetworkLinkService::LINK_TYPE_WIFI: - return false; - case nsINetworkLinkService::LINK_TYPE_WIMAX: - case nsINetworkLinkService::LINK_TYPE_2G: - case nsINetworkLinkService::LINK_TYPE_3G: - case nsINetworkLinkService::LINK_TYPE_4G: - return true; - } - - return false; -} - } // end namespace mozilla diff --git a/dom/media/VideoUtils.h b/dom/media/VideoUtils.h index 4611592d5fdf..639183169fef 100644 --- a/dom/media/VideoUtils.h +++ b/dom/media/VideoUtils.h @@ -545,10 +545,6 @@ inline void AppendStringIfNotEmpty(nsACString& aDest, nsACString&& aSrc) { } } -// Returns true if we're running on a cellular connection; 2G, 3G, etc. -// Main thread only. -bool OnCellularConnection(); - } // end namespace mozilla #endif diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index ded15f7a823a..8d77f1243556 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -550,10 +550,12 @@ pref("browser.chrome.toolbar_tips", false); // don't allow meta-refresh when backgrounded pref("browser.meta_refresh_when_inactive.disabled", true); -// On mobile we throttle the download once the readahead_limit is hit -// if we're using a cellular connection, even if the download is slow. -// This is to preserve battery and data. -pref("media.throttle-cellular-regardless-of-download-rate", true); +// prevent video elements from preloading too much data +pref("media.preload.default", 1); // default to preload none +pref("media.preload.auto", 2); // preload metadata if preload=auto +// On mobile we'll throttle the download once the readahead_limit is hit, +// even if the download is slow. This is to preserve battery and data. +pref("media.throttle-regardless-of-download-rate", true); // Number of video frames we buffer while decoding video. // On Android this is decided by a similar value which varies for diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java index f7705e15788c..ec102038ce76 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntime.java @@ -6,11 +6,6 @@ package org.mozilla.geckoview; -import android.arch.lifecycle.ProcessLifecycleOwner; -import android.arch.lifecycle.Lifecycle; -import android.arch.lifecycle.LifecycleObserver; -import android.arch.lifecycle.OnLifecycleEvent; - import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; @@ -31,7 +26,6 @@ import android.util.Log; import org.mozilla.gecko.EventDispatcher; import org.mozilla.gecko.GeckoAppShell; -import org.mozilla.gecko.GeckoNetworkManager; import org.mozilla.gecko.GeckoScreenOrientation; import org.mozilla.gecko.GeckoSystemStateListener; import org.mozilla.gecko.GeckoThread; @@ -99,36 +93,6 @@ public final class GeckoRuntime implements Parcelable { */ public static final String EXTRA_CRASH_FATAL = "fatal"; - private final class LifecycleListener implements LifecycleObserver { - public LifecycleListener() { - } - - @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) - void onCreate() { - Log.d(LOGTAG, "Lifecycle: onCreate"); - } - - @OnLifecycleEvent(Lifecycle.Event.ON_START) - void onStart() { - Log.d(LOGTAG, "Lifecycle: onStart"); - } - - @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) - void onResume() { - Log.d(LOGTAG, "Lifecycle: onResume"); - // Monitor network status and send change notifications to Gecko - // while active. - GeckoNetworkManager.getInstance().start(GeckoAppShell.getApplicationContext()); - } - - @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) - void onPause() { - Log.d(LOGTAG, "Lifecycle: onPause"); - // Stop monitoring network status while inactive. - GeckoNetworkManager.getInstance().stop(); - } - } - private static GeckoRuntime sDefaultRuntime; /** @@ -302,9 +266,6 @@ public final class GeckoRuntime implements Parcelable { // Initialize the system ClipboardManager by accessing it on the main thread. GeckoAppShell.getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE); - - // Add process lifecycle listener to react to backgrounding events. - ProcessLifecycleOwner.get().getLifecycle().addObserver(new LifecycleListener()); return true; } diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index f0d579672c4e..5ea803bd6fd9 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -1441,18 +1441,17 @@ VARCACHE_PREF( // reviewer had an unshakeable preference for that. // File-backed MediaCache size. +#ifdef ANDROID +# define PREF_VALUE 32768 // Measured in KiB +#else +# define PREF_VALUE 512000 // Measured in KiB +#endif VARCACHE_PREF( "media.cache_size", MediaCacheSize, - uint32_t, 512000 // Measured in KiB -) -// Size of file backed MediaCache while on a connection which is cellular (3G, etc), -// and thus assumed to be "expensive". -VARCACHE_PREF( - "media.cache_size.cellular", - MediaCacheCellularSize, - uint32_t, 32768 // Measured in KiB + RelaxedAtomicUint32, PREF_VALUE ) +#undef PREF_VALUE // If a resource is known to be smaller than this size (in kilobytes), a // memory-backed MediaCache may be used; otherwise the (single shared global) @@ -1481,30 +1480,32 @@ VARCACHE_PREF( // When a network connection is suspended, don't resume it until the amount of // buffered data falls below this threshold (in seconds). +#ifdef ANDROID +# define PREF_VALUE 10 // Use a smaller limit to save battery. +#else +# define PREF_VALUE 30 +#endif VARCACHE_PREF( "media.cache_resume_threshold", MediaCacheResumeThreshold, - uint32_t, 30 -) -VARCACHE_PREF( - "media.cache_resume_threshold.cellular", - MediaCacheCellularResumeThreshold, - uint32_t, 10 + RelaxedAtomicInt32, PREF_VALUE ) +#undef PREF_VALUE // Stop reading ahead when our buffered data is this many seconds ahead of the // current playback position. This limit can stop us from using arbitrary // amounts of network bandwidth prefetching huge videos. +#ifdef ANDROID +# define PREF_VALUE 30 // Use a smaller limit to save battery. +#else +# define PREF_VALUE 60 +#endif VARCACHE_PREF( "media.cache_readahead_limit", MediaCacheReadaheadLimit, - uint32_t, 60 -) -VARCACHE_PREF( - "media.cache_readahead_limit.cellular", - MediaCacheCellularReadaheadLimit, - uint32_t, 30 + RelaxedAtomicInt32, PREF_VALUE ) +#undef PREF_VALUE // AudioSink VARCACHE_PREF(