ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lockString) { ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(state); ScriptPromise promise = resolver->promise(); Document* document = m_frame ? m_frame->document() : 0; if (!document || !controller()) { DOMException* exception = DOMException::create(InvalidStateError, "The object is no longer associated to a document."); resolver->reject(exception); return promise; } if (document->isSandboxed(SandboxOrientationLock)) { DOMException* exception = DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag."); resolver->reject(exception); return promise; } controller()->lock(stringToOrientationLock(lockString), new LockOrientationCallback(resolver)); return promise; }
ScriptPromise ScreenOrientation::lockOrientation(ScriptState* state, Screen& screen, const AtomicString& lockString) { RefPtr<ScriptPromiseResolverWithContext> resolver = ScriptPromiseResolverWithContext::create(state); ScriptPromise promise = resolver->promise(); ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); Document* document = screenOrientation.document(); if (!document || !screenOrientation.frame()) { RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(InvalidStateError, "The object is no longer associated to a document."); resolver->reject(exception); return promise; } if (document->isSandboxed(SandboxOrientationLock)) { RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(SecurityError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag."); resolver->reject(exception); return promise; } ScreenOrientationController::from(*screenOrientation.frame()).lockOrientation(stringToOrientationLock(lockString), new LockOrientationCallback(resolver)); return promise; }