Bug 949325 - C++ wrapper to support DataStore API on the worker (part 2-6, a proxy to run HasDataStoreSupport() on the main thread). r=khuey

This commit is contained in:
Gene Lian 2014-03-12 17:03:05 +08:00
Родитель 8e6024c408
Коммит 96ce5c1c53
2 изменённых файлов: 67 добавлений и 8 удалений

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

@ -94,6 +94,9 @@
#include "nsIPrivateBrowsingChannel.h"
#include "nsIDocShell.h"
#include "WorkerPrivate.h"
#include "WorkerRunnable.h"
namespace mozilla {
namespace dom {
@ -2299,9 +2302,9 @@ Navigator::HasInputMethodSupport(JSContext* /* unused */,
/* static */
bool
Navigator::HasDataStoreSupport(JSContext* cx, JSObject* aGlobal)
Navigator::HasDataStoreSupport(nsIPrincipal* aPrincipal)
{
JS::Rooted<JSObject*> global(cx, aGlobal);
workers::AssertIsOnMainThread();
// First of all, the general pref has to be turned on.
bool enabled = false;
@ -2315,6 +2318,64 @@ Navigator::HasDataStoreSupport(JSContext* cx, JSObject* aGlobal)
return true;
}
uint16_t status;
if (NS_FAILED(aPrincipal->GetAppStatus(&status))) {
return false;
}
// Only support DataStore API for certified apps for now.
return status == nsIPrincipal::APP_STATUS_CERTIFIED;
}
// A WorkerMainThreadRunnable to synchronously dispatch the call of
// HasDataStoreSupport() from the worker thread to the main thread.
class HasDataStoreSupportRunnable MOZ_FINAL
: public workers::WorkerMainThreadRunnable
{
public:
bool mResult;
HasDataStoreSupportRunnable(workers::WorkerPrivate* aWorkerPrivate)
: workers::WorkerMainThreadRunnable(aWorkerPrivate)
, mResult(false)
{
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
}
protected:
virtual bool
MainThreadRun() MOZ_OVERRIDE
{
workers::AssertIsOnMainThread();
mResult = Navigator::HasDataStoreSupport(mWorkerPrivate->GetPrincipal());
return true;
}
};
/* static */
bool
Navigator::HasDataStoreSupport(JSContext* aCx, JSObject* aGlobal)
{
// If the caller is on the worker thread, dispatch this to the main thread.
if (!NS_IsMainThread()) {
workers::WorkerPrivate* workerPrivate =
workers::GetWorkerPrivateFromContext(aCx);
workerPrivate->AssertIsOnWorkerThread();
nsRefPtr<HasDataStoreSupportRunnable> runnable =
new HasDataStoreSupportRunnable(workerPrivate);
runnable->Dispatch(aCx);
return runnable->mResult;
}
workers::AssertIsOnMainThread();
JS::Rooted<JSObject*> global(aCx, aGlobal);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(global);
if (!win) {
return false;
@ -2325,12 +2386,7 @@ Navigator::HasDataStoreSupport(JSContext* cx, JSObject* aGlobal)
return false;
}
uint16_t status;
if (NS_FAILED(doc->NodePrincipal()->GetAppStatus(&status))) {
return false;
}
return status == nsIPrincipal::APP_STATUS_CERTIFIED;
return HasDataStoreSupport(doc->NodePrincipal());
}
/* static */

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

@ -27,6 +27,7 @@ class nsIDOMNavigatorSystemMessages;
class nsDOMCameraManager;
class nsDOMDeviceStorage;
class nsIDOMBlob;
class nsIPrincipal;
namespace mozilla {
namespace dom {
@ -304,6 +305,8 @@ public:
static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal);
static bool HasDataStoreSupport(nsIPrincipal* aPrincipal);
static bool HasDataStoreSupport(JSContext* cx, JSObject* aGlobal);
static bool HasDownloadsSupport(JSContext* aCx, JSObject* aGlobal);