Bug 1492014 get WorkletLoadInfo from global instead of thread in Console r=baku

Depends on D6106

Differential Revision: https://phabricator.services.mozilla.com/D6107

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Karl Tomlinson 2018-09-18 09:29:15 +00:00
Родитель 49a69c3443
Коммит 1bbf3f704b
5 изменённых файлов: 30 добавлений и 15 удалений

Просмотреть файл

@ -541,10 +541,12 @@ protected:
explicit ConsoleWorkletRunnable(Console* aConsole)
: Runnable("dom::console::ConsoleWorkletRunnable")
, mConsole(aConsole)
, mWorkletThread(WorkletThread::Get())
{
WorkletThread::AssertIsOnWorkletThread();
MOZ_ASSERT(mWorkletThread);
nsCOMPtr<WorkletGlobalScope> global = do_QueryInterface(mConsole->mGlobal);
MOZ_ASSERT(global);
mWorkletImpl = global->Impl();
MOZ_ASSERT(mWorkletImpl);
}
~ConsoleWorkletRunnable() override = default;
@ -557,7 +559,7 @@ protected:
if (NS_IsMainThread()) {
RunOnMainThread();
RefPtr<ConsoleWorkletRunnable> runnable(this);
return mWorkletThread->DispatchRunnable(runnable.forget());
return mWorkletImpl->DispatchRunnable(runnable.forget());
}
WorkletThread::AssertIsOnWorkletThread();
@ -579,7 +581,7 @@ protected:
// This must be released on the worker thread.
RefPtr<Console> mConsole;
RefPtr<WorkletThread> mWorkletThread;
RefPtr<WorkletImpl> mWorkletImpl;
};
// This runnable appends a CallData object into the Console queue running on
@ -592,12 +594,6 @@ public:
{
WorkletThread::AssertIsOnWorkletThread();
RefPtr<WorkletThread> workletThread = WorkletThread::Get();
MOZ_ASSERT(workletThread);
aConsoleData->SetIDs(workletThread->GetWorkletLoadInfo().OuterWindowID(),
workletThread->GetWorkletLoadInfo().InnerWindowID());
RefPtr<ConsoleCallDataWorkletRunnable> runnable =
new ConsoleCallDataWorkletRunnable(aConsole, aConsoleData);
@ -619,6 +615,9 @@ private:
MOZ_ASSERT(aCallData);
aCallData->AssertIsOnOwningThread();
const WorkletLoadInfo& loadInfo = mWorkletImpl->LoadInfo();
mCallData->SetIDs(loadInfo.OuterWindowID(), loadInfo.InnerWindowID());
// Marking this CallData as in use.
mCallData->mStatus = ConsoleCallData::eInUse;
}
@ -634,8 +633,7 @@ private:
AutoSafeJSContext cx;
JSObject* sandbox =
mConsole->GetOrCreateSandbox(cx,
mWorkletThread->GetWorkletLoadInfo().Principal());
mConsole->GetOrCreateSandbox(cx, mWorkletImpl->LoadInfo().Principal());
JS::Rooted<JSObject*> global(cx, sandbox);
if (NS_WARN_IF(!global)) {
return;
@ -918,8 +916,7 @@ private:
AutoSafeJSContext cx;
JSObject* sandbox =
mConsole->GetOrCreateSandbox(cx,
mWorkletThread->GetWorkletLoadInfo().Principal());
mConsole->GetOrCreateSandbox(cx, mWorkletImpl->LoadInfo().Principal());
JS::Rooted<JSObject*> global(cx, sandbox);
if (NS_WARN_IF(!global)) {
return;
@ -1580,7 +1577,9 @@ Console::MethodInternal(JSContext* aCx, MethodName aMethodName,
#endif
}
} else if (WorkletThread::IsOnWorkletThread()) {
oa = WorkletThread::Get()->GetWorkletLoadInfo().OriginAttributesRef();
nsCOMPtr<WorkletGlobalScope> global = do_QueryInterface(mGlobal);
MOZ_ASSERT(global);
oa = global->Impl()->LoadInfo().OriginAttributesRef();
} else {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);

Просмотреть файл

@ -497,6 +497,7 @@ private:
friend class ConsoleProfileWorkletRunnable;
friend class ConsoleRunnable;
friend class ConsoleWorkerRunnable;
friend class ConsoleWorkletRunnable;
};
} // namespace dom

Просмотреть файл

@ -56,6 +56,8 @@ public:
already_AddRefed<Console>
GetConsole(JSContext* aCx, ErrorResult& aRv);
WorkletImpl* Impl() const { return mImpl; }
void
Dump(const Optional<nsAString>& aString) const;

Просмотреть файл

@ -135,4 +135,12 @@ WorkletImpl::TerminateThread()
mWorkletLoadInfo.mPrincipal = nullptr;
}
nsresult
WorkletImpl::DispatchRunnable(already_AddRefed<nsIRunnable> aRunnable)
{
// TODO: bug 1492011 re ConsoleWorkletRunnable.
MOZ_ASSERT(mWorkletThread);
return mWorkletThread->DispatchRunnable(std::move(aRunnable));
}
} // namespace mozilla

Просмотреть файл

@ -12,6 +12,7 @@
class nsPIDOMWindowInner;
class nsIPrincipal;
class nsIRunnable;
namespace mozilla {
@ -91,8 +92,12 @@ public:
already_AddRefed<dom::WorkletGlobalScope> CreateGlobalScope(JSContext* aCx);
// Any thread.
const WorkletLoadInfo& LoadInfo() const { return mWorkletLoadInfo; }
// Use DispatchRunnable only when the thread is known to already exist.
nsresult DispatchRunnable(already_AddRefed<nsIRunnable> aRunnable);
private:
WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
WorkletType aWorkletType);