2001-02-21 01:43:56 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-02-21 02:27:48 +03:00
|
|
|
#include "imgRequestProxy.h"
|
2017-10-25 01:22:55 +03:00
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
#include "Image.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "ImageLogging.h"
|
2013-04-06 01:14:34 +04:00
|
|
|
#include "ImageOps.h"
|
2019-02-13 22:13:55 +03:00
|
|
|
#include "ImageTypes.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "imgINotificationObserver.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "imgLoader.h"
|
2021-01-04 17:20:22 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/Telemetry.h" // for Telemetry
|
2017-07-19 21:15:11 +03:00
|
|
|
#include "mozilla/dom/DocGroup.h" // for DocGroup
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "nsCRTGlue.h"
|
|
|
|
#include "nsError.h"
|
2001-05-08 08:01:28 +04:00
|
|
|
|
2017-10-25 01:22:55 +03:00
|
|
|
using namespace mozilla;
|
2012-01-06 20:02:27 +04:00
|
|
|
using namespace mozilla::image;
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
// The split of imgRequestProxy and imgRequestProxyStatic means that
|
|
|
|
// certain overridden functions need to be usable in the destructor.
|
|
|
|
// Since virtual functions can't be used in that way, this class
|
|
|
|
// provides a behavioural trait for each class to use instead.
|
|
|
|
class ProxyBehaviour {
|
|
|
|
public:
|
2016-11-16 18:39:43 +03:00
|
|
|
virtual ~ProxyBehaviour() = default;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
virtual already_AddRefed<mozilla::image::Image> GetImage() const = 0;
|
|
|
|
virtual bool HasImage() const = 0;
|
2014-11-15 07:10:47 +03:00
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker() const = 0;
|
2012-10-19 23:39:38 +04:00
|
|
|
virtual imgRequest* GetOwner() const = 0;
|
|
|
|
virtual void SetOwner(imgRequest* aOwner) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RequestBehaviour : public ProxyBehaviour {
|
|
|
|
public:
|
|
|
|
RequestBehaviour() : mOwner(nullptr), mOwnerHasImage(false) {}
|
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
already_AddRefed<mozilla::image::Image> GetImage() const override;
|
|
|
|
bool HasImage() const override;
|
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const override;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
imgRequest* GetOwner() const override { return mOwner; }
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
void SetOwner(imgRequest* aOwner) override {
|
2012-10-19 23:39:38 +04:00
|
|
|
mOwner = aOwner;
|
2013-04-26 07:30:29 +04:00
|
|
|
|
|
|
|
if (mOwner) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> ownerProgressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
mOwnerHasImage = ownerProgressTracker && ownerProgressTracker->HasImage();
|
2013-04-26 07:30:29 +04:00
|
|
|
} else {
|
|
|
|
mOwnerHasImage = false;
|
|
|
|
}
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// We maintain the following invariant:
|
|
|
|
// The proxy is registered at most with a single imgRequest as an observer,
|
|
|
|
// and whenever it is, mOwner points to that object. This helps ensure that
|
|
|
|
// imgRequestProxy::~imgRequestProxy unregisters the proxy as an observer
|
|
|
|
// from whatever request it was registered with (if any). This, in turn,
|
|
|
|
// means that imgRequest::mObservers will not have any stale pointers in it.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequest> mOwner;
|
2012-10-19 23:39:38 +04:00
|
|
|
|
|
|
|
bool mOwnerHasImage;
|
|
|
|
};
|
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
already_AddRefed<mozilla::image::Image> RequestBehaviour::GetImage() const {
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!mOwnerHasImage) {
|
2012-10-19 23:39:38 +04:00
|
|
|
return nullptr;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
return progressTracker->GetImage();
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
already_AddRefed<ProgressTracker> RequestBehaviour::GetProgressTracker() const {
|
2012-10-19 23:39:38 +04:00
|
|
|
// NOTE: It's possible that our mOwner has an Image that it didn't notify
|
|
|
|
// us about, if we were Canceled before its Image was constructed.
|
|
|
|
// (Canceling removes us as an observer, so mOwner has no way to notify us).
|
2014-11-15 07:10:47 +03:00
|
|
|
// That's why this method uses mOwner->GetProgressTracker() instead of just
|
|
|
|
// mOwner->mProgressTracker -- we might have a null mImage and yet have an
|
|
|
|
// mOwner with a non-null mImage (and a null mProgressTracker pointer).
|
|
|
|
return mOwner->GetProgressTracker();
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
|
|
|
|
2011-06-10 01:11:57 +04:00
|
|
|
NS_IMPL_ADDREF(imgRequestProxy)
|
|
|
|
NS_IMPL_RELEASE(imgRequestProxy)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(imgRequestProxy)
|
2020-05-11 17:43:05 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, PreloaderBase)
|
2011-06-10 01:11:57 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(imgIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
|
2020-05-11 17:43:05 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONCRETE(imgRequestProxy)
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsITimedChannel, TimedChannel() != nullptr)
|
2011-06-10 01:11:57 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2001-02-22 05:06:24 +03:00
|
|
|
imgRequestProxy::imgRequestProxy()
|
2012-10-19 23:39:38 +04:00
|
|
|
: mBehaviour(new RequestBehaviour),
|
2012-07-30 18:20:58 +04:00
|
|
|
mURI(nullptr),
|
|
|
|
mListener(nullptr),
|
2001-07-17 05:14:40 +04:00
|
|
|
mLoadFlags(nsIRequest::LOAD_NORMAL),
|
2010-08-26 10:21:34 +04:00
|
|
|
mLockCount(0),
|
2010-09-08 04:33:02 +04:00
|
|
|
mAnimationConsumers(0),
|
2022-11-20 03:22:20 +03:00
|
|
|
mCancelable(true),
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanceled(false),
|
|
|
|
mIsInLoadGroup(false),
|
2017-11-01 13:59:10 +03:00
|
|
|
mForceDispatchLoadGroup(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef(false),
|
|
|
|
mDecodeRequested(false),
|
2018-02-07 15:27:27 +03:00
|
|
|
mPendingNotify(false),
|
2018-02-07 15:27:27 +03:00
|
|
|
mValidating(false),
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
mHadListener(false) {
|
2001-02-21 01:43:56 +03:00
|
|
|
/* member initializers and constructor code */
|
2017-07-25 18:14:00 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::imgRequestProxy");
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2001-02-21 02:27:48 +03:00
|
|
|
imgRequestProxy::~imgRequestProxy() {
|
2001-02-21 01:43:56 +03:00
|
|
|
/* destructor code */
|
2015-03-25 20:59:00 +03:00
|
|
|
MOZ_ASSERT(!mListener, "Someone forgot to properly cancel this request!");
|
2018-07-11 18:06:40 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mLockCount, "Someone forgot to unlock on time?");
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
ClearAnimationConsumers();
|
|
|
|
|
2006-06-01 22:35:21 +04:00
|
|
|
// Explicitly set mListener to null to ensure that the RemoveProxy
|
|
|
|
// call below can't send |this| to an arbitrary listener while |this|
|
2008-03-19 22:07:59 +03:00
|
|
|
// is being destroyed. This is all belt-and-suspenders in view of the
|
|
|
|
// above assert.
|
|
|
|
NullOutListener();
|
2001-03-06 07:46:20 +03:00
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
/* Call RemoveProxy with a successful status. This will keep the
|
|
|
|
channel, if still downloading data, from being canceled if 'this' is
|
|
|
|
the last observer. This allows the image to continue to download and
|
|
|
|
be cached even if no one is using it currently.
|
|
|
|
*/
|
|
|
|
mCanceled = true;
|
|
|
|
RemoveFromOwner(NS_OK);
|
2017-07-25 18:14:00 +03:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
RemoveFromLoadGroup();
|
2017-07-25 18:14:00 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::~imgRequestProxy");
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult imgRequestProxy::Init(imgRequest* aOwner, nsILoadGroup* aLoadGroup,
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
nsIURI* aURI,
|
2015-03-25 20:59:00 +03:00
|
|
|
imgINotificationObserver* aObserver) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!GetOwner() && !mListener,
|
|
|
|
"imgRequestProxy is already initialized");
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request", aOwner);
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mAnimationConsumers == 0, "Cannot have animation before Init");
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2012-12-20 01:28:54 +04:00
|
|
|
mBehaviour->SetOwner(aOwner);
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
mListener = aObserver;
|
2017-07-19 21:15:11 +03:00
|
|
|
// Make sure to addref mListener before the AddToOwner call below, since
|
2008-03-19 22:07:59 +03:00
|
|
|
// that call might well want to release it if the imgRequest has
|
|
|
|
// already seen OnStopRequest.
|
|
|
|
if (mListener) {
|
2017-07-19 21:15:12 +03:00
|
|
|
mHadListener = true;
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef = true;
|
2008-03-19 22:07:59 +03:00
|
|
|
NS_ADDREF(mListener);
|
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
mLoadGroup = aLoadGroup;
|
2010-05-11 07:27:41 +04:00
|
|
|
mURI = aURI;
|
2001-03-06 07:46:20 +03:00
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
// Note: AddToOwner won't send all the On* notifications immediately
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
AddToOwner();
|
2002-01-15 08:23:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult imgRequestProxy::ChangeOwner(imgRequest* aNewOwner) {
|
|
|
|
MOZ_ASSERT(GetOwner(), "Cannot ChangeOwner on a proxy without an owner!");
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2012-10-22 20:44:53 +04:00
|
|
|
if (mCanceled) {
|
2015-03-25 20:59:00 +03:00
|
|
|
// Ensure that this proxy has received all notifications to date
|
|
|
|
// before we clean it up when removing it from the old owner below.
|
2012-10-22 20:44:53 +04:00
|
|
|
SyncNotifyListener();
|
|
|
|
}
|
|
|
|
|
2010-05-15 00:47:59 +04:00
|
|
|
// If we're holding locks, unlock the old image.
|
2010-08-26 10:21:34 +04:00
|
|
|
// Note that UnlockImage decrements mLockCount each time it's called.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldLockCount = mLockCount;
|
2015-03-25 20:59:00 +03:00
|
|
|
while (mLockCount) {
|
2010-05-15 00:47:59 +04:00
|
|
|
UnlockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
// If we're holding animation requests, undo them.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldAnimationConsumers = mAnimationConsumers;
|
2010-09-08 04:33:02 +04:00
|
|
|
ClearAnimationConsumers();
|
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
GetOwner()->RemoveProxy(this, NS_OK);
|
2012-10-22 20:44:53 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
mBehaviour->SetOwner(aNewOwner);
|
2018-02-07 15:27:27 +03:00
|
|
|
MOZ_ASSERT(!GetValidator(), "New owner cannot be validating!");
|
2012-10-22 20:44:53 +04:00
|
|
|
|
|
|
|
// If we were locked, apply the locks here
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < oldLockCount; i++) {
|
2012-10-22 20:44:53 +04:00
|
|
|
LockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2011-01-26 21:52:42 +03:00
|
|
|
// If we had animation requests, restore them here. Note that we
|
|
|
|
// do this *after* RemoveProxy, which clears out animation consumers
|
|
|
|
// (see bug 601723).
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < oldAnimationConsumers; i++) {
|
2011-01-26 21:52:42 +03:00
|
|
|
IncrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2011-01-26 21:52:42 +03:00
|
|
|
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
AddToOwner();
|
2018-02-07 15:27:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2022-09-28 06:56:57 +03:00
|
|
|
NS_IMETHODIMP imgRequestProxy::GetTriggeringPrincipal(
|
|
|
|
nsIPrincipal** aTriggeringPrincipal) {
|
|
|
|
MOZ_ASSERT(GetOwner());
|
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal =
|
|
|
|
GetOwner()->GetTriggeringPrincipal();
|
|
|
|
triggeringPrincipal.forget(aTriggeringPrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
void imgRequestProxy::MarkValidating() {
|
|
|
|
MOZ_ASSERT(GetValidator());
|
|
|
|
mValidating = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void imgRequestProxy::ClearValidating() {
|
|
|
|
MOZ_ASSERT(mValidating);
|
|
|
|
MOZ_ASSERT(!GetValidator());
|
|
|
|
mValidating = false;
|
2002-01-15 08:23:33 +03:00
|
|
|
|
2015-10-30 02:37:42 +03:00
|
|
|
// If we'd previously requested a synchronous decode, request a decode on the
|
|
|
|
// new image.
|
|
|
|
if (mDecodeRequested) {
|
2018-02-07 15:27:27 +03:00
|
|
|
mDecodeRequested = false;
|
2016-11-26 10:56:26 +03:00
|
|
|
StartDecoding(imgIContainer::FLAG_NONE);
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2022-05-20 12:02:32 +03:00
|
|
|
bool imgRequestProxy::HasDecodedPixels() {
|
|
|
|
if (IsValidating()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Image> image = GetImage();
|
|
|
|
if (image) {
|
|
|
|
return image->HasDecodedPixels();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-15 14:14:51 +03:00
|
|
|
nsresult imgRequestProxy::DispatchWithTargetIfAvailable(
|
|
|
|
already_AddRefed<nsIRunnable> aEvent) {
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::DispatchWithTargetIfAvailable");
|
2021-10-08 22:29:37 +03:00
|
|
|
return NS_DispatchToMainThread(
|
|
|
|
CreateRenderBlockingRunnable(std::move(aEvent)));
|
2017-08-15 14:14:51 +03:00
|
|
|
}
|
|
|
|
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
void imgRequestProxy::AddToOwner() {
|
2018-02-07 15:27:27 +03:00
|
|
|
imgRequest* owner = GetOwner();
|
|
|
|
if (!owner) {
|
2017-07-19 21:15:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
owner->AddProxy(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void imgRequestProxy::RemoveFromOwner(nsresult aStatus) {
|
|
|
|
imgRequest* owner = GetOwner();
|
|
|
|
if (owner) {
|
|
|
|
if (mValidating) {
|
|
|
|
imgCacheValidator* validator = owner->GetValidator();
|
|
|
|
MOZ_ASSERT(validator);
|
|
|
|
validator->RemoveProxy(this);
|
|
|
|
mValidating = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
owner->RemoveProxy(this, aStatus);
|
|
|
|
}
|
2017-07-19 21:15:11 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void imgRequestProxy::AddToLoadGroup() {
|
2003-05-14 09:42:06 +04:00
|
|
|
NS_ASSERTION(!mIsInLoadGroup, "Whaa, we're already in the loadgroup!");
|
2017-11-01 13:59:10 +03:00
|
|
|
MOZ_ASSERT(!mForceDispatchLoadGroup);
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* While in theory there could be a dispatch outstanding to remove this
|
|
|
|
request from the load group, in practice we only add to the load group
|
|
|
|
(when previously not in a load group) at initialization. */
|
2003-05-14 09:42:06 +04:00
|
|
|
if (!mIsInLoadGroup && mLoadGroup) {
|
2017-11-01 13:59:10 +03:00
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::AddToLoadGroup");
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInLoadGroup = true;
|
2003-05-14 09:42:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
void imgRequestProxy::RemoveFromLoadGroup() {
|
|
|
|
if (!mIsInLoadGroup || !mLoadGroup) {
|
2003-05-14 09:42:06 +04:00
|
|
|
return;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* Sometimes we may not be able to remove ourselves from the load group in
|
|
|
|
the current context. This is because our listeners are not re-entrant (e.g.
|
|
|
|
we are in the middle of CancelAndForgetObserver or SyncClone). */
|
|
|
|
if (mForceDispatchLoadGroup) {
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::RemoveFromLoadGroup -- dispatch");
|
|
|
|
|
|
|
|
/* We take away the load group from the request temporarily; this prevents
|
|
|
|
additional dispatches via RemoveFromLoadGroup occurring, as well as
|
|
|
|
MoveToBackgroundInLoadGroup from removing and readding. This is safe
|
|
|
|
because we know that once we get here, blocking the load group at all is
|
|
|
|
unnecessary. */
|
|
|
|
mIsInLoadGroup = false;
|
2018-05-30 22:15:35 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup = std::move(mLoadGroup);
|
2017-11-01 13:59:10 +03:00
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
DispatchWithTargetIfAvailable(NS_NewRunnableFunction(
|
|
|
|
"imgRequestProxy::RemoveFromLoadGroup", [self, loadGroup]() -> void {
|
|
|
|
loadGroup->RemoveRequest(self, nullptr, NS_OK);
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::RemoveFromLoadGroup");
|
|
|
|
|
2003-05-14 09:42:06 +04:00
|
|
|
/* calling RemoveFromLoadGroup may cause the document to finish
|
|
|
|
loading, which could result in our death. We need to make sure
|
|
|
|
that we stay alive long enough to fight another battle... at
|
2017-11-01 13:59:10 +03:00
|
|
|
least until we exit this function. */
|
2003-05-14 09:42:06 +04:00
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadGroup->RemoveRequest(this, nullptr, NS_OK);
|
2017-11-01 13:59:10 +03:00
|
|
|
mLoadGroup = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsInLoadGroup = false;
|
2017-11-01 13:59:10 +03:00
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
void imgRequestProxy::MoveToBackgroundInLoadGroup() {
|
|
|
|
/* Even if we are still in the load group, we may have taken away the load
|
|
|
|
group reference itself because we are in the process of leaving the group.
|
|
|
|
In that case, there is no need to background the request. */
|
|
|
|
if (!mLoadGroup) {
|
|
|
|
return;
|
2005-10-04 02:27:20 +04:00
|
|
|
}
|
2003-05-14 09:42:06 +04:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
/* There is no need to dispatch if we only need to add ourselves to the load
|
|
|
|
group without removal. It is the removal which causes the problematic
|
|
|
|
callbacks (see RemoveFromLoadGroup). */
|
|
|
|
if (mIsInLoadGroup && mForceDispatchLoadGroup) {
|
|
|
|
LOG_FUNC(gImgLog,
|
|
|
|
"imgRequestProxy::MoveToBackgroundInLoadGroup -- dispatch");
|
|
|
|
|
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
DispatchWithTargetIfAvailable(NS_NewRunnableFunction(
|
|
|
|
"imgRequestProxy::MoveToBackgroundInLoadGroup",
|
|
|
|
[self]() -> void { self->MoveToBackgroundInLoadGroup(); }));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_FUNC(gImgLog, "imgRequestProxy::MoveToBackgroundInLoadGroup");
|
|
|
|
nsCOMPtr<imgIRequest> kungFuDeathGrip(this);
|
|
|
|
if (mIsInLoadGroup) {
|
|
|
|
mLoadGroup->RemoveRequest(this, nullptr, NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoadFlags |= nsIRequest::LOAD_BACKGROUND;
|
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
|
|
|
}
|
2001-05-08 08:01:28 +04:00
|
|
|
|
2001-03-06 07:46:20 +03:00
|
|
|
/** nsIRequest / imgIRequest methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetName(nsACString& aName) {
|
2002-03-21 01:50:33 +03:00
|
|
|
aName.Truncate();
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
if (mURI) {
|
2010-05-11 07:27:41 +04:00
|
|
|
mURI->GetSpec(aName);
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
return NS_OK;
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::IsPending(bool* _retval) { return NS_ERROR_NOT_IMPLEMENTED; }
|
2001-03-06 07:46:20 +03:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetStatus(nsresult* aStatus) {
|
2009-01-30 22:13:52 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
|
2022-09-08 12:11:18 +03:00
|
|
|
NS_IMETHODIMP imgRequestProxy::SetCanceledReason(const nsACString& aReason) {
|
|
|
|
return SetCanceledReasonImpl(aReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP imgRequestProxy::GetCanceledReason(nsACString& aReason) {
|
|
|
|
return GetCanceledReasonImpl(aReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP imgRequestProxy::CancelWithReason(nsresult aStatus,
|
|
|
|
const nsACString& aReason) {
|
|
|
|
return CancelWithReasonImpl(aStatus, aReason);
|
|
|
|
}
|
|
|
|
|
2022-11-20 03:22:20 +03:00
|
|
|
void imgRequestProxy::SetCancelable(bool aCancelable) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mCancelable = aCancelable;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Cancel(nsresult status) {
|
|
|
|
if (mCanceled) {
|
2001-02-22 05:06:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-02-22 05:06:24 +03:00
|
|
|
|
2022-11-20 03:22:20 +03:00
|
|
|
if (NS_WARN_IF(!mCancelable)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::Cancel");
|
2001-02-23 11:36:51 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanceled = true;
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2008-12-20 01:35:50 +03:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new imgCancelRunnable(this, status);
|
2017-08-15 14:14:51 +03:00
|
|
|
return DispatchWithTargetIfAvailable(ev.forget());
|
2008-12-20 01:35:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void imgRequestProxy::DoCancel(nsresult status) {
|
2018-02-07 15:27:27 +03:00
|
|
|
RemoveFromOwner(status);
|
2017-11-01 13:59:10 +03:00
|
|
|
RemoveFromLoadGroup();
|
2008-03-19 22:07:59 +03:00
|
|
|
NullOutListener();
|
2008-12-20 01:35:50 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::CancelAndForgetObserver(nsresult aStatus) {
|
2011-10-15 00:15:56 +04:00
|
|
|
// If mCanceled is true but mListener is non-null, that means
|
|
|
|
// someone called Cancel() on us but the imgCancelRunnable is still
|
|
|
|
// pending. We still need to null out mListener before returning
|
|
|
|
// from this function in this case. That means we want to do the
|
|
|
|
// RemoveProxy call right now, because we need to deliver the
|
|
|
|
// onStopRequest.
|
2015-03-25 20:59:00 +03:00
|
|
|
if (mCanceled && !mListener) {
|
2008-12-20 01:35:50 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2008-12-20 01:35:50 +03:00
|
|
|
|
2022-11-20 03:22:20 +03:00
|
|
|
if (NS_WARN_IF(!mCancelable)) {
|
|
|
|
MOZ_ASSERT(mCancelable,
|
|
|
|
"Shouldn't try to cancel non-cancelable requests via "
|
|
|
|
"CancelAndForgetObserver");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::CancelAndForgetObserver");
|
2008-12-20 01:35:50 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mCanceled = true;
|
2017-11-07 14:42:47 +03:00
|
|
|
mForceDispatchLoadGroup = true;
|
2018-02-07 15:27:27 +03:00
|
|
|
RemoveFromOwner(aStatus);
|
2017-11-01 13:59:10 +03:00
|
|
|
RemoveFromLoadGroup();
|
|
|
|
mForceDispatchLoadGroup = false;
|
2010-03-08 22:34:52 +03:00
|
|
|
|
2008-12-20 01:35:50 +03:00
|
|
|
NullOutListener();
|
2006-06-01 22:35:21 +04:00
|
|
|
|
2001-04-13 09:37:29 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2012-10-05 00:02:15 +04:00
|
|
|
NS_IMETHODIMP
|
2016-11-26 10:56:26 +03:00
|
|
|
imgRequestProxy::StartDecoding(uint32_t aFlags) {
|
2018-02-07 15:27:28 +03:00
|
|
|
// Flag this, so we know to request after validation if pending.
|
|
|
|
if (IsValidating()) {
|
|
|
|
mDecodeRequested = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-05 00:02:15 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-24 05:37:45 +03:00
|
|
|
if (image) {
|
2016-11-26 10:56:26 +03:00
|
|
|
return image->StartDecoding(aFlags);
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
2015-10-30 02:37:42 +03:00
|
|
|
GetOwner()->StartDecoding();
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-10-05 00:02:15 +04:00
|
|
|
}
|
|
|
|
|
2016-12-23 10:07:45 +03:00
|
|
|
bool imgRequestProxy::StartDecodingWithResult(uint32_t aFlags) {
|
2018-02-07 15:27:28 +03:00
|
|
|
// Flag this, so we know to request after validation if pending.
|
|
|
|
if (IsValidating()) {
|
|
|
|
mDecodeRequested = true;
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-23 10:07:45 +03:00
|
|
|
|
|
|
|
RefPtr<Image> image = GetImage();
|
|
|
|
if (image) {
|
|
|
|
return image->StartDecodingWithResult(aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->StartDecoding();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:04:45 +03:00
|
|
|
imgIContainer::DecodeResult imgRequestProxy::RequestDecodeWithResult(
|
|
|
|
uint32_t aFlags) {
|
2018-11-08 20:45:50 +03:00
|
|
|
if (IsValidating()) {
|
|
|
|
mDecodeRequested = true;
|
2020-04-21 00:04:45 +03:00
|
|
|
return imgIContainer::DECODE_REQUESTED;
|
2018-11-08 20:45:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Image> image = GetImage();
|
|
|
|
if (image) {
|
|
|
|
return image->RequestDecodeWithResult(aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetOwner()) {
|
|
|
|
GetOwner()->StartDecoding();
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:04:45 +03:00
|
|
|
return imgIContainer::DECODE_REQUESTED;
|
2018-11-08 20:45:50 +03:00
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::LockImage() {
|
2010-08-26 10:21:34 +04:00
|
|
|
mLockCount++;
|
2019-05-02 02:05:47 +03:00
|
|
|
RefPtr<Image> image =
|
|
|
|
GetOwner() && GetOwner()->ImageAvailable() ? GetImage() : nullptr;
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return image->LockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-08-26 10:21:34 +04:00
|
|
|
return NS_OK;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::UnlockImage() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "calling unlock but no locks!");
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2010-08-26 10:21:34 +04:00
|
|
|
mLockCount--;
|
2019-05-02 02:05:47 +03:00
|
|
|
RefPtr<Image> image =
|
|
|
|
GetOwner() && GetOwner()->ImageAvailable() ? GetImage() : nullptr;
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return image->UnlockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-08-26 10:21:34 +04:00
|
|
|
return NS_OK;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2012-03-10 10:29:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::RequestDiscard() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return image->RequestDiscard();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2012-03-10 10:29:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::IncrementAnimationConsumers() {
|
|
|
|
mAnimationConsumers++;
|
2019-05-02 02:05:47 +03:00
|
|
|
RefPtr<Image> image =
|
|
|
|
GetOwner() && GetOwner()->ImageAvailable() ? GetImage() : nullptr;
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
image->IncrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::DecrementAnimationConsumers() {
|
|
|
|
// We may get here if some responsible code called Increment,
|
|
|
|
// then called us, but we have meanwhile called ClearAnimationConsumers
|
|
|
|
// because we needed to get rid of them earlier (see
|
|
|
|
// imgRequest::RemoveProxy), and hence have nothing left to
|
|
|
|
// decrement. (In such a case we got rid of the animation consumers
|
|
|
|
// early, but not the observer.)
|
|
|
|
if (mAnimationConsumers > 0) {
|
|
|
|
mAnimationConsumers--;
|
2019-05-02 02:05:47 +03:00
|
|
|
RefPtr<Image> image =
|
|
|
|
GetOwner() && GetOwner()->ImageAvailable() ? GetImage() : nullptr;
|
2015-03-25 20:59:00 +03:00
|
|
|
if (image) {
|
2013-09-28 22:28:44 +04:00
|
|
|
image->DecrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void imgRequestProxy::ClearAnimationConsumers() {
|
2015-03-25 20:59:00 +03:00
|
|
|
while (mAnimationConsumers > 0) {
|
2010-09-08 04:33:02 +04:00
|
|
|
DecrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
2001-03-06 07:46:20 +03:00
|
|
|
imgRequestProxy::Suspend() { return NS_ERROR_NOT_IMPLEMENTED; }
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
2001-03-06 07:46:20 +03:00
|
|
|
imgRequestProxy::Resume() { return NS_ERROR_NOT_IMPLEMENTED; }
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetLoadGroup(nsILoadGroup** loadGroup) {
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
NS_IF_ADDREF(*loadGroup = mLoadGroup.get());
|
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetLoadGroup(nsILoadGroup* loadGroup) {
|
2017-11-01 13:59:09 +03:00
|
|
|
if (loadGroup != mLoadGroup) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Switching load groups is unsupported!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetLoadFlags(nsLoadFlags* flags) {
|
2001-07-17 05:14:40 +04:00
|
|
|
*flags = mLoadFlags;
|
fix for at least bugs 6074,72087,74506,75190,75180,74165,69857,75576,75326,75417,75474 r=waterson, sr=brendan
2001-04-13 06:42:56 +04:00
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetLoadFlags(nsLoadFlags flags) {
|
2001-07-17 05:14:40 +04:00
|
|
|
mLoadFlags = flags;
|
|
|
|
return NS_OK;
|
2001-04-10 10:01:08 +04:00
|
|
|
}
|
|
|
|
|
2020-01-07 23:20:38 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetTRRMode(nsIRequest::TRRMode* aTRRMode) {
|
|
|
|
return GetTRRModeImpl(aTRRMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetTRRMode(nsIRequest::TRRMode aTRRMode) {
|
|
|
|
return SetTRRModeImpl(aTRRMode);
|
|
|
|
}
|
|
|
|
|
2001-03-06 07:46:20 +03:00
|
|
|
/** imgIRequest methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImage(imgIContainer** aImage) {
|
2013-09-28 22:28:44 +04:00
|
|
|
NS_ENSURE_TRUE(aImage, NS_ERROR_NULL_POINTER);
|
2010-08-24 02:44:07 +04:00
|
|
|
// It's possible that our owner has an image but hasn't notified us of it -
|
|
|
|
// that'll happen if we get Canceled before the owner instantiates its image
|
|
|
|
// (because Canceling unregisters us as a listener on mOwner). If we're
|
|
|
|
// in that situation, just grab the image off of mOwner.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2013-09-28 22:28:44 +04:00
|
|
|
nsCOMPtr<imgIContainer> imageToReturn;
|
2015-03-24 05:37:45 +03:00
|
|
|
if (image) {
|
2018-10-02 00:38:01 +03:00
|
|
|
imageToReturn = image;
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
|
|
|
if (!imageToReturn && GetOwner()) {
|
|
|
|
imageToReturn = GetOwner()->GetImage();
|
|
|
|
}
|
|
|
|
if (!imageToReturn) {
|
2001-03-25 15:57:25 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-24 05:37:45 +03:00
|
|
|
}
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
imageToReturn.swap(*aImage);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2021-11-27 14:47:37 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetProviderId(uint32_t* aId) {
|
|
|
|
NS_ENSURE_TRUE(aId, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
nsresult rv = GetImage(getter_AddRefs(image));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aId = image->GetProviderId();
|
|
|
|
} else {
|
|
|
|
*aId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImageStatus(uint32_t* aStatus) {
|
2018-02-07 15:27:28 +03:00
|
|
|
if (IsValidating()) {
|
|
|
|
// We are currently validating the image, and so our status could revert if
|
|
|
|
// we discard the cache. We should also be deferring notifications, such
|
|
|
|
// that the caller will be notified when validation completes. Rather than
|
|
|
|
// risk misleading the caller, return nothing.
|
|
|
|
*aStatus = imgIRequest::STATUS_NONE;
|
|
|
|
} else {
|
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
|
|
|
*aStatus = progressTracker->GetImageStatus();
|
|
|
|
}
|
2001-03-25 15:57:25 +04:00
|
|
|
|
2001-10-12 10:43:52 +04:00
|
|
|
return NS_OK;
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImageErrorCode(nsresult* aStatus) {
|
|
|
|
if (!GetOwner()) {
|
2014-07-19 05:47:11 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2014-07-19 05:47:11 +04:00
|
|
|
|
|
|
|
*aStatus = GetOwner()->GetImageErrorCode();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetURI(nsIURI** aURI) {
|
2013-09-28 22:28:42 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread to convert URI");
|
2018-06-06 03:42:57 +03:00
|
|
|
nsCOMPtr<nsIURI> uri = mURI;
|
2013-09-28 22:28:42 +04:00
|
|
|
uri.forget(aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-13 11:31:24 +03:00
|
|
|
nsresult imgRequestProxy::GetFinalURI(nsIURI** aURI) {
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!GetOwner()) {
|
2014-11-11 01:06:24 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2014-11-11 01:06:24 +03:00
|
|
|
|
2017-11-13 11:31:24 +03:00
|
|
|
return GetOwner()->GetFinalURI(aURI);
|
2014-11-11 01:06:24 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetNotificationObserver(imgINotificationObserver** aObserver) {
|
2012-10-12 20:11:22 +04:00
|
|
|
*aObserver = mListener;
|
|
|
|
NS_IF_ADDREF(*aObserver);
|
2001-03-23 02:16:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetMimeType(char** aMimeType) {
|
|
|
|
if (!GetOwner()) {
|
2001-10-12 11:59:21 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-10-12 11:59:21 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
const char* type = GetOwner()->GetMimeType();
|
|
|
|
if (!type) {
|
2001-10-12 11:59:21 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2001-10-12 11:59:21 +04:00
|
|
|
|
2018-08-28 08:58:54 +03:00
|
|
|
*aMimeType = NS_xstrdup(type);
|
2001-10-12 11:59:21 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:00:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetFileName(nsACString& aFileName) {
|
|
|
|
if (!GetOwner()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOwner()->GetFileName(aFileName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy* imgRequestProxy::NewClonedProxy() {
|
2012-10-12 20:11:22 +04:00
|
|
|
return new imgRequestProxy();
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::Clone(imgINotificationObserver* aObserver,
|
|
|
|
imgIRequest** aClone) {
|
2012-10-12 16:43:01 +04:00
|
|
|
nsresult result;
|
|
|
|
imgRequestProxy* proxy;
|
2017-07-19 21:15:11 +03:00
|
|
|
result = PerformClone(aObserver, nullptr, /* aSyncNotify */ true, &proxy);
|
2012-10-12 16:43:01 +04:00
|
|
|
*aClone = proxy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
nsresult imgRequestProxy::SyncClone(imgINotificationObserver* aObserver,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aLoadingDocument,
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy** aClone) {
|
|
|
|
return PerformClone(aObserver, aLoadingDocument,
|
|
|
|
/* aSyncNotify */ true, aClone);
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:43:01 +04:00
|
|
|
nsresult imgRequestProxy::Clone(imgINotificationObserver* aObserver,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aLoadingDocument,
|
2012-10-12 16:43:01 +04:00
|
|
|
imgRequestProxy** aClone) {
|
2017-07-19 21:15:11 +03:00
|
|
|
return PerformClone(aObserver, aLoadingDocument,
|
|
|
|
/* aSyncNotify */ false, aClone);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
nsresult imgRequestProxy::PerformClone(imgINotificationObserver* aObserver,
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aLoadingDocument,
|
2017-07-19 21:15:11 +03:00
|
|
|
bool aSyncNotify,
|
2015-03-25 20:59:00 +03:00
|
|
|
imgRequestProxy** aClone) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aClone, "Null out param");
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_SCOPE(gImgLog, "imgRequestProxy::Clone");
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aClone = nullptr;
|
2017-07-19 21:15:11 +03:00
|
|
|
RefPtr<imgRequestProxy> clone = NewClonedProxy();
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
if (aLoadingDocument) {
|
|
|
|
loadGroup = aLoadingDocument->GetDocumentLoadGroup();
|
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
// It is important to call |SetLoadFlags()| before calling |Init()| because
|
|
|
|
// |Init()| adds the request to the loadgroup.
|
2006-06-01 22:35:21 +04:00
|
|
|
// When a request is added to a loadgroup, its load flags are merged
|
|
|
|
// with the load flags of the loadgroup.
|
|
|
|
// XXXldb That's not true anymore. Stuff from imgLoader adds the
|
|
|
|
// request to the loadgroup.
|
2004-03-09 06:57:51 +03:00
|
|
|
clone->SetLoadFlags(mLoadFlags);
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
nsresult rv = clone->Init(mBehaviour->GetOwner(), loadGroup, mURI, aObserver);
|
2015-03-25 20:59:00 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2004-03-09 06:57:51 +03:00
|
|
|
return rv;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
|
2010-05-11 07:27:41 +04:00
|
|
|
// Assign to *aClone before calling Notify so that if the caller expects to
|
|
|
|
// only be notified for requests it's already holding pointers to it won't be
|
|
|
|
// surprised.
|
2010-05-15 00:47:59 +04:00
|
|
|
NS_ADDREF(*aClone = clone);
|
2004-09-21 02:46:22 +04:00
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
imgCacheValidator* validator = GetValidator();
|
|
|
|
if (validator) {
|
2017-07-19 21:15:11 +03:00
|
|
|
// Note that if we have a validator, we don't want to issue notifications at
|
2017-11-01 13:59:10 +03:00
|
|
|
// here because we want to defer until that completes. AddProxy will add us
|
|
|
|
// to the load group; we cannot avoid that in this case, because we don't
|
|
|
|
// know when the validation will complete, and if it will cause us to
|
|
|
|
// discard our cached state anyways. We are probably already blocked by the
|
|
|
|
// original LoadImage(WithChannel) request in any event.
|
2018-02-07 15:27:27 +03:00
|
|
|
clone->MarkValidating();
|
|
|
|
validator->AddProxy(clone);
|
2017-07-19 21:15:11 +03:00
|
|
|
} else {
|
2017-11-01 13:59:10 +03:00
|
|
|
// We only want to add the request to the load group of the owning document
|
|
|
|
// if it is still in progress. Some callers cannot handle a supurious load
|
|
|
|
// group removal (e.g. print preview) so we must be careful. On the other
|
|
|
|
// hand, if after cloning, the original request proxy is cancelled /
|
|
|
|
// destroyed, we need to ensure that any clones still block the load group
|
|
|
|
// if it is incomplete.
|
|
|
|
bool addToLoadGroup = mIsInLoadGroup;
|
|
|
|
if (!addToLoadGroup) {
|
|
|
|
RefPtr<ProgressTracker> tracker = clone->GetProgressTracker();
|
|
|
|
addToLoadGroup =
|
|
|
|
tracker && !(tracker->GetProgress() & FLAG_LOAD_COMPLETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addToLoadGroup) {
|
|
|
|
clone->AddToLoadGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSyncNotify) {
|
|
|
|
// This is wrong!!! We need to notify asynchronously, but there's code
|
|
|
|
// that assumes that we don't. This will be fixed in bug 580466. Note that
|
|
|
|
// if we have a validator, we won't issue notifications anyways because
|
|
|
|
// they are deferred, so there is no point in requesting.
|
|
|
|
clone->mForceDispatchLoadGroup = true;
|
|
|
|
clone->SyncNotifyListener();
|
|
|
|
clone->mForceDispatchLoadGroup = false;
|
|
|
|
} else {
|
|
|
|
// Without a validator, we can request asynchronous notifications
|
|
|
|
// immediately. If there was a validator, this would override the deferral
|
|
|
|
// and that would be incorrect.
|
|
|
|
clone->NotifyListener();
|
|
|
|
}
|
2017-07-19 21:15:11 +03:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-23 02:16:52 +03:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetImagePrincipal(nsIPrincipal** aPrincipal) {
|
|
|
|
if (!GetOwner()) {
|
2007-11-09 05:55:41 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2007-11-09 05:55:41 +03:00
|
|
|
|
2016-08-10 11:12:30 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = GetOwner()->GetPrincipal();
|
|
|
|
principal.forget(aPrincipal);
|
2010-05-11 07:27:41 +04:00
|
|
|
return NS_OK;
|
2007-11-09 05:55:41 +03:00
|
|
|
}
|
|
|
|
|
2019-06-04 09:31:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetHadCrossOriginRedirects(bool* aHadCrossOriginRedirects) {
|
|
|
|
*aHadCrossOriginRedirects = false;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITimedChannel> timedChannel = TimedChannel();
|
|
|
|
if (timedChannel) {
|
|
|
|
bool allRedirectsSameOrigin = false;
|
|
|
|
*aHadCrossOriginRedirects =
|
|
|
|
NS_SUCCEEDED(
|
|
|
|
timedChannel->GetAllRedirectsSameOrigin(&allRedirectsSameOrigin)) &&
|
|
|
|
!allRedirectsSameOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetMultipart(bool* aMultipart) {
|
|
|
|
if (!GetOwner()) {
|
2012-05-19 23:32:37 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2012-05-19 23:32:37 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
*aMultipart = GetOwner()->GetMultipart();
|
2012-05-19 23:32:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetCORSMode(int32_t* aCorsMode) {
|
|
|
|
if (!GetOwner()) {
|
2011-07-14 22:47:34 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
*aCorsMode = GetOwner()->GetCORSMode();
|
2023-03-23 00:55:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) {
|
|
|
|
if (!GetOwner()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2011-07-14 22:47:34 +04:00
|
|
|
|
2023-03-23 00:55:08 +03:00
|
|
|
nsCOMPtr<nsIReferrerInfo> referrerInfo = GetOwner()->GetReferrerInfo();
|
|
|
|
referrerInfo.forget(aReferrerInfo);
|
2011-07-14 22:47:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-22 14:52:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::BoostPriority(uint32_t aCategory) {
|
|
|
|
NS_ENSURE_STATE(GetOwner() && !mCanceled);
|
|
|
|
GetOwner()->BoostPriority(aCategory);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 23:58:01 +03:00
|
|
|
/** nsISupportsPriority methods **/
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetPriority(int32_t* priority) {
|
2012-10-19 23:39:38 +04:00
|
|
|
NS_ENSURE_STATE(GetOwner());
|
|
|
|
*priority = GetOwner()->Priority();
|
2005-02-21 23:58:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::SetPriority(int32_t priority) {
|
2012-10-19 23:39:38 +04:00
|
|
|
NS_ENSURE_STATE(GetOwner() && !mCanceled);
|
|
|
|
GetOwner()->AdjustPriority(this, priority - GetOwner()->Priority());
|
2005-02-21 23:58:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::AdjustPriority(int32_t priority) {
|
2013-02-16 05:00:03 +04:00
|
|
|
// We don't require |!mCanceled| here. This may be called even if we're
|
|
|
|
// cancelled, because it's invoked as part of the process of removing an image
|
|
|
|
// from the load group.
|
|
|
|
NS_ENSURE_STATE(GetOwner());
|
2012-10-19 23:39:38 +04:00
|
|
|
GetOwner()->AdjustPriority(this, priority);
|
2005-02-21 23:58:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
static const char* NotificationTypeToString(int32_t aType) {
|
|
|
|
switch (aType) {
|
|
|
|
case imgINotificationObserver::SIZE_AVAILABLE:
|
|
|
|
return "SIZE_AVAILABLE";
|
|
|
|
case imgINotificationObserver::FRAME_UPDATE:
|
|
|
|
return "FRAME_UPDATE";
|
|
|
|
case imgINotificationObserver::FRAME_COMPLETE:
|
|
|
|
return "FRAME_COMPLETE";
|
|
|
|
case imgINotificationObserver::LOAD_COMPLETE:
|
|
|
|
return "LOAD_COMPLETE";
|
|
|
|
case imgINotificationObserver::DECODE_COMPLETE:
|
|
|
|
return "DECODE_COMPLETE";
|
|
|
|
case imgINotificationObserver::DISCARD:
|
|
|
|
return "DISCARD";
|
|
|
|
case imgINotificationObserver::UNLOCKED_DRAW:
|
|
|
|
return "UNLOCKED_DRAW";
|
|
|
|
case imgINotificationObserver::IS_ANIMATED:
|
|
|
|
return "IS_ANIMATED";
|
|
|
|
case imgINotificationObserver::HAS_TRANSPARENCY:
|
|
|
|
return "HAS_TRANSPARENCY";
|
|
|
|
default:
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Notification list should be exhaustive");
|
2015-01-07 12:35:20 +03:00
|
|
|
return "(unknown notification)";
|
2003-03-17 19:09:02 +03:00
|
|
|
}
|
2001-02-21 01:43:56 +03:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
void imgRequestProxy::Notify(int32_t aType,
|
|
|
|
const mozilla::gfx::IntRect* aRect) {
|
2015-01-07 12:35:20 +03:00
|
|
|
MOZ_ASSERT(aType != imgINotificationObserver::LOAD_COMPLETE,
|
|
|
|
"Should call OnLoadComplete");
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::Notify", "type",
|
2015-01-07 12:35:20 +03:00
|
|
|
NotificationTypeToString(aType));
|
2013-02-25 04:59:22 +04:00
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
if (!mListener || mCanceled) {
|
|
|
|
return;
|
2013-02-25 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
// Make sure the listener stays alive while we notify.
|
|
|
|
nsCOMPtr<imgINotificationObserver> listener(mListener);
|
2014-11-17 22:16:45 +03:00
|
|
|
|
2016-07-18 19:44:45 +03:00
|
|
|
listener->Notify(this, aType, aRect);
|
2011-11-10 01:39:15 +04:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:35:20 +03:00
|
|
|
void imgRequestProxy::OnLoadComplete(bool aLastPart) {
|
2018-06-06 03:42:57 +03:00
|
|
|
LOG_FUNC_WITH_PARAM(gImgLog, "imgRequestProxy::OnLoadComplete", "uri", mURI);
|
2015-05-11 23:42:30 +03:00
|
|
|
|
2008-03-21 09:13:11 +03:00
|
|
|
// There's all sorts of stuff here that could kill us (the OnStopRequest call
|
|
|
|
// on the listener, the removal from the loadgroup, the release of the
|
|
|
|
// listener, etc). Don't let them do it.
|
2017-07-19 21:15:11 +03:00
|
|
|
RefPtr<imgRequestProxy> self(this);
|
|
|
|
|
2013-02-13 23:57:16 +04:00
|
|
|
if (mListener && !mCanceled) {
|
2006-06-01 22:35:21 +04:00
|
|
|
// Hold a ref to the listener while we call it, just in case.
|
2016-07-18 19:44:45 +03:00
|
|
|
nsCOMPtr<imgINotificationObserver> listener(mListener);
|
|
|
|
listener->Notify(this, imgINotificationObserver::LOAD_COMPLETE, nullptr);
|
2005-10-04 02:27:20 +04:00
|
|
|
}
|
|
|
|
|
2006-06-01 22:35:21 +04:00
|
|
|
// If we're expecting more data from a multipart channel, re-add ourself
|
|
|
|
// to the loadgroup so that the document doesn't lose track of the load.
|
2005-10-04 02:27:20 +04:00
|
|
|
// If the request is already a background request and there's more data
|
|
|
|
// coming, we can just leave the request in the loadgroup as-is.
|
2014-11-18 01:29:56 +03:00
|
|
|
if (aLastPart || (mLoadFlags & nsIRequest::LOAD_BACKGROUND) == 0) {
|
2017-11-01 13:59:10 +03:00
|
|
|
if (aLastPart) {
|
|
|
|
RemoveFromLoadGroup();
|
2020-05-11 17:43:05 +03:00
|
|
|
|
|
|
|
nsresult errorCode = NS_OK;
|
|
|
|
// if the load is cross origin without CORS, or the CORS access is
|
|
|
|
// rejected, always fire load event to avoid leaking site information for
|
|
|
|
// <link rel=preload>.
|
|
|
|
// XXXedgar, currently we don't do the same thing for <img>.
|
|
|
|
imgRequest* request = GetOwner();
|
|
|
|
if (!request || !(request->IsDeniedCrossSiteCORSRequest() ||
|
|
|
|
request->IsCrossSiteNoCORSRequest())) {
|
|
|
|
uint32_t status = imgIRequest::STATUS_NONE;
|
|
|
|
GetImageStatus(&status);
|
|
|
|
if (status & imgIRequest::STATUS_ERROR) {
|
|
|
|
errorCode = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotifyStop(errorCode);
|
2017-11-01 13:59:10 +03:00
|
|
|
} else {
|
|
|
|
// More data is coming, so change the request to be a background request
|
|
|
|
// and put it back in the loadgroup.
|
|
|
|
MoveToBackgroundInLoadGroup();
|
2005-10-04 02:27:20 +04:00
|
|
|
}
|
|
|
|
}
|
2008-03-19 22:07:59 +03:00
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
if (mListenerIsStrongRef && aLastPart) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(mListener, "How did that happen?");
|
2008-03-19 22:07:59 +03:00
|
|
|
// Drop our strong ref to the listener now that we're done with
|
|
|
|
// everything. Note that this can cancel us and other fun things
|
|
|
|
// like that. Don't add anything in this method after this point.
|
2012-10-12 20:11:22 +04:00
|
|
|
imgINotificationObserver* obs = mListener;
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef = false;
|
2008-03-19 22:07:59 +03:00
|
|
|
NS_RELEASE(obs);
|
|
|
|
}
|
2001-03-06 07:46:20 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void imgRequestProxy::NullOutListener() {
|
2010-09-08 04:33:02 +04:00
|
|
|
// If we have animation consumers, then they don't matter anymore
|
2015-03-25 20:59:00 +03:00
|
|
|
if (mListener) {
|
2010-09-08 04:33:02 +04:00
|
|
|
ClearAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2008-03-19 22:07:59 +03:00
|
|
|
if (mListenerIsStrongRef) {
|
|
|
|
// Releasing could do weird reentery stuff, so just play it super-safe
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgINotificationObserver> obs;
|
2008-03-19 22:07:59 +03:00
|
|
|
obs.swap(mListener);
|
2011-10-17 18:59:28 +04:00
|
|
|
mListenerIsStrongRef = false;
|
2008-03-19 22:07:59 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2008-03-19 22:07:59 +03:00
|
|
|
}
|
|
|
|
}
|
2009-12-11 07:02:13 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxy::GetStaticRequest(imgIRequest** aReturn) {
|
2020-07-22 23:29:00 +03:00
|
|
|
RefPtr<imgRequestProxy> proxy =
|
|
|
|
GetStaticRequest(static_cast<Document*>(nullptr));
|
|
|
|
if (proxy != this) {
|
|
|
|
RefPtr<Image> image = GetImage();
|
|
|
|
if (image && image->HasError()) {
|
|
|
|
// image/test/unit/test_async_notification_404.js needs this, but ideally
|
|
|
|
// this special case can be removed from the scripted codepath.
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
proxy.forget(aReturn);
|
|
|
|
return NS_OK;
|
2012-10-12 16:43:01 +04:00
|
|
|
}
|
|
|
|
|
2020-07-22 23:29:00 +03:00
|
|
|
already_AddRefed<imgRequestProxy> imgRequestProxy::GetStaticRequest(
|
|
|
|
Document* aLoadingDocument) {
|
2020-08-02 18:29:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!aLoadingDocument ||
|
|
|
|
aLoadingDocument->IsStaticDocument());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = GetImage();
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool animated;
|
2012-10-12 20:11:21 +04:00
|
|
|
if (!image || (NS_SUCCEEDED(image->GetAnimated(&animated)) && !animated)) {
|
2010-05-11 07:27:41 +04:00
|
|
|
// Early exit - we're not animated, so we don't have to do anything.
|
2020-07-22 23:29:00 +03:00
|
|
|
return do_AddRef(this);
|
2013-03-11 05:43:38 +04:00
|
|
|
}
|
2010-05-15 00:47:59 +04:00
|
|
|
|
2013-03-11 05:43:38 +04:00
|
|
|
// We are animated. We need to create a frozen version of this image.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> frozenImage = ImageOps::Freeze(image);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2010-05-15 00:47:59 +04:00
|
|
|
// Create a static imgRequestProxy with our new extracted frame.
|
2012-10-12 20:11:20 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
|
|
|
GetImagePrincipal(getter_AddRefs(currentPrincipal));
|
2019-06-04 09:31:42 +03:00
|
|
|
bool hadCrossOriginRedirects = true;
|
|
|
|
GetHadCrossOriginRedirects(&hadCrossOriginRedirects);
|
2022-09-28 06:56:58 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal = GetTriggeringPrincipal();
|
2023-02-13 18:02:07 +03:00
|
|
|
RefPtr<imgRequestProxy> req =
|
|
|
|
new imgRequestProxyStatic(frozenImage, currentPrincipal,
|
|
|
|
triggeringPrincipal, hadCrossOriginRedirects);
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
req->Init(nullptr, nullptr, mURI, nullptr);
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2020-07-22 23:29:00 +03:00
|
|
|
return req.forget();
|
2009-12-11 07:02:13 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void imgRequestProxy::NotifyListener() {
|
2010-07-29 01:52:14 +04:00
|
|
|
// It would be nice to notify the observer directly in the status tracker
|
|
|
|
// instead of through the proxy, but there are several places we do extra
|
|
|
|
// processing when we receive notifications (like OnStopRequest()), and we
|
|
|
|
// need to check mCanceled everywhere too.
|
2010-05-11 07:27:41 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2012-10-19 23:39:38 +04:00
|
|
|
if (GetOwner()) {
|
2010-07-29 01:52:14 +04:00
|
|
|
// Send the notifications to our listener asynchronously.
|
2014-11-15 07:10:47 +03:00
|
|
|
progressTracker->Notify(this);
|
2010-07-29 01:52:14 +04:00
|
|
|
} else {
|
|
|
|
// We don't have an imgRequest, so we can only notify the clone of our
|
|
|
|
// current state, but we still have to do that asynchronously.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(HasImage(), "if we have no imgRequest, we should have an Image");
|
2014-11-15 07:10:47 +03:00
|
|
|
progressTracker->NotifyCurrentState(this);
|
2010-07-29 01:52:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
void imgRequestProxy::SyncNotifyListener() {
|
2010-07-29 01:52:14 +04:00
|
|
|
// It would be nice to notify the observer directly in the status tracker
|
|
|
|
// instead of through the proxy, but there are several places we do extra
|
|
|
|
// processing when we receive notifications (like OnStopRequest()), and we
|
|
|
|
// need to check mCanceled everywhere too.
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
progressTracker->SyncNotify(this);
|
2010-08-24 02:44:07 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:21 +04:00
|
|
|
void imgRequestProxy::SetHasImage() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
MOZ_ASSERT(progressTracker);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> image = progressTracker->GetImage();
|
2013-09-28 22:28:44 +04:00
|
|
|
MOZ_ASSERT(image);
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
// Force any private status related to the owner to reflect
|
|
|
|
// the presence of an image;
|
|
|
|
mBehaviour->SetOwner(mBehaviour->GetOwner());
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2010-08-26 10:21:34 +04:00
|
|
|
// Apply any locks we have
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < mLockCount; ++i) {
|
2012-10-12 20:11:21 +04:00
|
|
|
image->LockImage();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
|
|
|
|
// Apply any animation consumers we have
|
2015-03-25 20:59:00 +03:00
|
|
|
for (uint32_t i = 0; i < mAnimationConsumers; i++) {
|
2012-10-12 20:11:21 +04:00
|
|
|
image->IncrementAnimationConsumers();
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2010-08-24 02:44:07 +04:00
|
|
|
}
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
already_AddRefed<ProgressTracker> imgRequestProxy::GetProgressTracker() const {
|
|
|
|
return mBehaviour->GetProgressTracker();
|
2012-10-12 20:11:21 +04:00
|
|
|
}
|
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
already_AddRefed<mozilla::image::Image> imgRequestProxy::GetImage() const {
|
2012-10-19 23:39:38 +04:00
|
|
|
return mBehaviour->GetImage();
|
|
|
|
}
|
|
|
|
|
2013-09-28 22:28:44 +04:00
|
|
|
bool RequestBehaviour::HasImage() const {
|
2015-03-25 20:59:00 +03:00
|
|
|
if (!mOwnerHasImage) {
|
2013-09-28 22:28:44 +04:00
|
|
|
return false;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = GetProgressTracker();
|
2014-11-15 07:10:47 +03:00
|
|
|
return progressTracker ? progressTracker->HasImage() : false;
|
2013-09-28 22:28:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool imgRequestProxy::HasImage() const { return mBehaviour->HasImage(); }
|
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
imgRequest* imgRequestProxy::GetOwner() const { return mBehaviour->GetOwner(); }
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2018-02-07 15:27:27 +03:00
|
|
|
imgCacheValidator* imgRequestProxy::GetValidator() const {
|
|
|
|
imgRequest* owner = GetOwner();
|
|
|
|
if (!owner) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return owner->GetValidator();
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:12:44 +03:00
|
|
|
nsITimedChannel* imgRequestProxy::TimedChannel() {
|
|
|
|
if (!GetOwner()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return GetOwner()->GetTimedChannel();
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:20 +04:00
|
|
|
////////////////// imgRequestProxyStatic methods
|
|
|
|
|
2012-10-19 23:39:38 +04:00
|
|
|
class StaticBehaviour : public ProxyBehaviour {
|
|
|
|
public:
|
2014-09-02 20:20:24 +04:00
|
|
|
explicit StaticBehaviour(mozilla::image::Image* aImage) : mImage(aImage) {}
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
already_AddRefed<mozilla::image::Image> GetImage() const override {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::image::Image> image = mImage;
|
2013-09-28 22:28:44 +04:00
|
|
|
return image.forget();
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
bool HasImage() const override { return mImage; }
|
2012-10-12 20:11:20 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() const override {
|
2014-11-15 07:10:47 +03:00
|
|
|
return mImage->GetProgressTracker();
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
imgRequest* GetOwner() const override { return nullptr; }
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2016-11-16 18:41:47 +03:00
|
|
|
void SetOwner(imgRequest* aOwner) override {
|
2015-03-25 20:59:00 +03:00
|
|
|
MOZ_ASSERT(!aOwner,
|
|
|
|
"We shouldn't be giving static requests a non-null owner.");
|
2012-10-19 23:39:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Our image. We have to hold a strong reference here, because that's normally
|
|
|
|
// the job of the underlying request.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::image::Image> mImage;
|
2012-10-19 23:39:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
imgRequestProxyStatic::imgRequestProxyStatic(mozilla::image::Image* aImage,
|
2022-09-28 06:56:58 +03:00
|
|
|
nsIPrincipal* aImagePrincipal,
|
|
|
|
nsIPrincipal* aTriggeringPrincipal,
|
2019-06-04 09:31:42 +03:00
|
|
|
bool aHadCrossOriginRedirects)
|
2022-09-28 06:56:58 +03:00
|
|
|
: mImagePrincipal(aImagePrincipal),
|
|
|
|
mTriggeringPrincipal(aTriggeringPrincipal),
|
2019-06-04 09:31:42 +03:00
|
|
|
mHadCrossOriginRedirects(aHadCrossOriginRedirects) {
|
2015-10-17 13:53:28 +03:00
|
|
|
mBehaviour = mozilla::MakeUnique<StaticBehaviour>(aImage);
|
2012-10-12 20:11:21 +04:00
|
|
|
}
|
2012-10-12 20:11:21 +04:00
|
|
|
|
2015-03-25 20:59:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxyStatic::GetImagePrincipal(nsIPrincipal** aPrincipal) {
|
2022-09-28 06:56:58 +03:00
|
|
|
if (!mImagePrincipal) {
|
2012-10-19 23:39:38 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-25 20:59:00 +03:00
|
|
|
}
|
2022-09-28 06:56:58 +03:00
|
|
|
NS_ADDREF(*aPrincipal = mImagePrincipal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-19 23:39:38 +04:00
|
|
|
|
2022-09-28 06:56:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxyStatic::GetTriggeringPrincipal(nsIPrincipal** aPrincipal) {
|
|
|
|
NS_IF_ADDREF(*aPrincipal = mTriggeringPrincipal);
|
2012-10-19 23:39:38 +04:00
|
|
|
return NS_OK;
|
2012-10-12 20:11:21 +04:00
|
|
|
}
|
2012-10-12 20:11:22 +04:00
|
|
|
|
2019-06-04 09:31:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
imgRequestProxyStatic::GetHadCrossOriginRedirects(
|
|
|
|
bool* aHadCrossOriginRedirects) {
|
|
|
|
*aHadCrossOriginRedirects = mHadCrossOriginRedirects;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:15:11 +03:00
|
|
|
imgRequestProxy* imgRequestProxyStatic::NewClonedProxy() {
|
|
|
|
nsCOMPtr<nsIPrincipal> currentPrincipal;
|
|
|
|
GetImagePrincipal(getter_AddRefs(currentPrincipal));
|
2022-09-28 06:56:58 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
|
|
|
|
GetTriggeringPrincipal(getter_AddRefs(triggeringPrincipal));
|
2019-06-04 09:31:42 +03:00
|
|
|
bool hadCrossOriginRedirects = true;
|
|
|
|
GetHadCrossOriginRedirects(&hadCrossOriginRedirects);
|
2017-07-19 21:15:11 +03:00
|
|
|
RefPtr<mozilla::image::Image> image = GetImage();
|
2022-09-28 06:56:58 +03:00
|
|
|
return new imgRequestProxyStatic(image, currentPrincipal, triggeringPrincipal,
|
2019-06-04 09:31:42 +03:00
|
|
|
hadCrossOriginRedirects);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|