| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/screen_orientation/ScreenOrientation.h" | 5 #include "modules/screen_orientation/ScreenOrientation.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 { | 118 { |
| 119 } | 119 } |
| 120 | 120 |
| 121 const WTF::AtomicString& ScreenOrientation::interfaceName() const | 121 const WTF::AtomicString& ScreenOrientation::interfaceName() const |
| 122 { | 122 { |
| 123 return EventTargetNames::ScreenOrientation; | 123 return EventTargetNames::ScreenOrientation; |
| 124 } | 124 } |
| 125 | 125 |
| 126 ExecutionContext* ScreenOrientation::getExecutionContext() const | 126 ExecutionContext* ScreenOrientation::getExecutionContext() const |
| 127 { | 127 { |
| 128 if (!m_frame) | 128 if (!frame()) |
| 129 return 0; | 129 return 0; |
| 130 return m_frame->document(); | 130 return frame()->document(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 String ScreenOrientation::type() const | 133 String ScreenOrientation::type() const |
| 134 { | 134 { |
| 135 return orientationTypeToString(m_type); | 135 return orientationTypeToString(m_type); |
| 136 } | 136 } |
| 137 | 137 |
| 138 unsigned short ScreenOrientation::angle() const | 138 unsigned short ScreenOrientation::angle() const |
| 139 { | 139 { |
| 140 return m_angle; | 140 return m_angle; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ScreenOrientation::setType(WebScreenOrientationType type) | 143 void ScreenOrientation::setType(WebScreenOrientationType type) |
| 144 { | 144 { |
| 145 m_type = type; | 145 m_type = type; |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ScreenOrientation::setAngle(unsigned short angle) | 148 void ScreenOrientation::setAngle(unsigned short angle) |
| 149 { | 149 { |
| 150 m_angle = angle; | 150 m_angle = angle; |
| 151 } | 151 } |
| 152 | 152 |
| 153 ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lo
ckString) | 153 ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lo
ckString) |
| 154 { | 154 { |
| 155 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(state); | 155 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(state); |
| 156 ScriptPromise promise = resolver->promise(); | 156 ScriptPromise promise = resolver->promise(); |
| 157 | 157 |
| 158 Document* document = m_frame ? m_frame->document() : 0; | 158 Document* document = frame() ? frame()->document() : 0; |
| 159 | 159 |
| 160 if (!document || !controller()) { | 160 if (!document || !controller()) { |
| 161 DOMException* exception = DOMException::create(InvalidStateError, "The o
bject is no longer associated to a document."); | 161 DOMException* exception = DOMException::create(InvalidStateError, "The o
bject is no longer associated to a document."); |
| 162 resolver->reject(exception); | 162 resolver->reject(exception); |
| 163 return promise; | 163 return promise; |
| 164 } | 164 } |
| 165 | 165 |
| 166 if (document->isSandboxed(SandboxOrientationLock)) { | 166 if (document->isSandboxed(SandboxOrientationLock)) { |
| 167 DOMException* exception = DOMException::create(SecurityError, "The docum
ent is sandboxed and lacks the 'allow-orientation-lock' flag."); | 167 DOMException* exception = DOMException::create(SecurityError, "The docum
ent is sandboxed and lacks the 'allow-orientation-lock' flag."); |
| 168 resolver->reject(exception); | 168 resolver->reject(exception); |
| 169 return promise; | 169 return promise; |
| 170 } | 170 } |
| 171 | 171 |
| 172 controller()->lock(stringToOrientationLock(lockString), new LockOrientationC
allback(resolver)); | 172 controller()->lock(stringToOrientationLock(lockString), new LockOrientationC
allback(resolver)); |
| 173 return promise; | 173 return promise; |
| 174 } | 174 } |
| 175 | 175 |
| 176 void ScreenOrientation::unlock() | 176 void ScreenOrientation::unlock() |
| 177 { | 177 { |
| 178 if (!controller()) | 178 if (!controller()) |
| 179 return; | 179 return; |
| 180 | 180 |
| 181 controller()->unlock(); | 181 controller()->unlock(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 ScreenOrientationController* ScreenOrientation::controller() | 184 ScreenOrientationController* ScreenOrientation::controller() |
| 185 { | 185 { |
| 186 if (!m_frame) | 186 if (!frame()) |
| 187 return 0; | 187 return 0; |
| 188 | 188 |
| 189 return ScreenOrientationController::from(*m_frame); | 189 return ScreenOrientationController::from(*frame()); |
| 190 } | 190 } |
| 191 | 191 |
| 192 DEFINE_TRACE(ScreenOrientation) | 192 DEFINE_TRACE(ScreenOrientation) |
| 193 { | 193 { |
| 194 EventTargetWithInlineData::trace(visitor); | 194 EventTargetWithInlineData::trace(visitor); |
| 195 DOMWindowProperty::trace(visitor); | 195 DOMWindowProperty::trace(visitor); |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace blink | 198 } // namespace blink |
| OLD | NEW |