| Index: Source/modules/wake_lock/WakeLock.cpp
|
| diff --git a/Source/modules/wake_lock/WakeLock.cpp b/Source/modules/wake_lock/WakeLock.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f52669d118818b86cfd4231cb305375f5a147e2e
|
| --- /dev/null
|
| +++ b/Source/modules/wake_lock/WakeLock.cpp
|
| @@ -0,0 +1,84 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "modules/wake_lock/WakeLock.h"
|
| +
|
| +#include "core/dom/Document.h"
|
| +#include "modules/wake_lock/WakeLockController.h"
|
| +#include "modules/wake_lock/WakeLockPromiseResolver.h"
|
| +#include "public/platform/WebWakeLockType.h"
|
| +
|
| +namespace blink {
|
| +
|
| +static WebWakeLockType stringToWakeLockType(const AtomicString& wakeLockString)
|
| +{
|
| + WebWakeLockType type = WebWakeLockGuard;
|
| + if (wakeLockString == "screen")
|
| + type = WebWakeLockScreen;
|
| + else if (wakeLockString == "system")
|
| + type = WebWakeLockSystem;
|
| + else
|
| + ASSERT_NOT_REACHED();
|
| + return type;
|
| +}
|
| +
|
| +PassRefPtrWillBeRawPtr<WakeLock> WakeLock::create(ExecutionContext* context)
|
| +{
|
| + RefPtrWillBeRawPtr<WakeLock> wakeLock = adoptRefWillBeNoop(new WakeLock(context));
|
| + wakeLock->suspendIfNeeded();
|
| + return wakeLock.release();
|
| +}
|
| +
|
| +WakeLock::WakeLock(ExecutionContext* context)
|
| + : ActiveDOMObject(context)
|
| +{
|
| + ScriptWrappable::init(this);
|
| +}
|
| +
|
| +WakeLock::~WakeLock()
|
| +{
|
| +}
|
| +
|
| +Document* WakeLock::document() const
|
| +{
|
| + return toDocument(executionContext());
|
| +}
|
| +
|
| +Page* WakeLock::page() const
|
| +{
|
| + return document() ? document()->page() : 0;
|
| +}
|
| +
|
| +ScriptPromise WakeLock::request(ScriptState* scriptState, const AtomicString& stringType)
|
| +{
|
| + WebWakeLockType type = stringToWakeLockType(stringType);
|
| + if (WakeLockController* controller = WakeLockController::from(page()))
|
| + return controller->requestWakeLock(scriptState, type);
|
| +
|
| + WakeLockPromiseResolverOwnPtr resolver = WakeLockPromiseResolver::create(scriptState, type);
|
| + resolver->reject();
|
| + return resolver->promise();
|
| +}
|
| +
|
| +ScriptPromise WakeLock::release(ScriptState* scriptState, const AtomicString& stringType)
|
| +{
|
| + WebWakeLockType type = stringToWakeLockType(stringType);
|
| + if (WakeLockController* controller = WakeLockController::from(page()))
|
| + return controller->requestWakeUnlock(scriptState, type);
|
| +
|
| + WakeLockPromiseResolverOwnPtr resolver = WakeLockPromiseResolver::create(scriptState, type);
|
| + resolver->reject();
|
| + return resolver->promise();
|
| +}
|
| +
|
| +bool WakeLock::isHeld(const AtomicString& type)
|
| +{
|
| + if (WakeLockController* controller = WakeLockController::from(page()))
|
| + return controller->isHeld(stringToWakeLockType(type));
|
| +
|
| + return false;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|