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 "config.h" | 5 #include "config.h" |
6 #include "modules/screen_orientation/ScreenOrientation.h" | 6 #include "modules/screen_orientation/ScreenOrientation.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
13 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
14 #include "core/frame/UseCounter.h" | |
14 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
15 #include "modules/screen_orientation/LockOrientationCallback.h" | 16 #include "modules/screen_orientation/LockOrientationCallback.h" |
16 #include "modules/screen_orientation/ScreenOrientationController.h" | 17 #include "modules/screen_orientation/ScreenOrientationController.h" |
17 #include "public/platform/WebScreenOrientationType.h" | 18 #include "public/platform/WebScreenOrientationType.h" |
18 | 19 |
19 // This code assumes that WebScreenOrientationType values are included in WebScr eenOrientationLockType. | 20 // This code assumes that WebScreenOrientationType values are included in WebScr eenOrientationLockType. |
20 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ | 21 #define COMPILE_ASSERT_MATCHING_ENUM(enum1, enum2) \ |
21 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>( blink::enum2), mismatching_types) | 22 COMPILE_ASSERT(static_cast<unsigned>(blink::enum1) == static_cast<unsigned>( blink::enum2), mismatching_types) |
22 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien tationLockPortraitPrimary); | 23 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitPrimary, WebScreenOrien tationLockPortraitPrimary); |
23 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri entationLockPortraitSecondary); | 24 COMPILE_ASSERT_MATCHING_ENUM(WebScreenOrientationPortraitSecondary, WebScreenOri entationLockPortraitSecondary); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 120 |
120 ExecutionContext* ScreenOrientation::executionContext() const | 121 ExecutionContext* ScreenOrientation::executionContext() const |
121 { | 122 { |
122 if (!m_frame) | 123 if (!m_frame) |
123 return 0; | 124 return 0; |
124 return m_frame->document(); | 125 return m_frame->document(); |
125 } | 126 } |
126 | 127 |
127 String ScreenOrientation::type() const | 128 String ScreenOrientation::type() const |
128 { | 129 { |
130 if (m_frame) | |
Peter Beverloo
2014/10/02 12:30:07
Please move these to ScreenOrientation.idl using t
| |
131 UseCounter::count(m_frame->document(), UseCounter::ScreenOrientationType ); | |
129 return orientationTypeToString(m_type); | 132 return orientationTypeToString(m_type); |
130 } | 133 } |
131 | 134 |
132 unsigned short ScreenOrientation::angle() const | 135 unsigned short ScreenOrientation::angle() const |
133 { | 136 { |
137 if (m_frame) | |
138 UseCounter::count(m_frame->document(), UseCounter::ScreenOrientationAngl e); | |
134 return m_angle; | 139 return m_angle; |
135 } | 140 } |
136 | 141 |
137 void ScreenOrientation::setType(WebScreenOrientationType type) | 142 void ScreenOrientation::setType(WebScreenOrientationType type) |
138 { | 143 { |
139 m_type = type; | 144 m_type = type; |
140 } | 145 } |
141 | 146 |
142 void ScreenOrientation::setAngle(unsigned short angle) | 147 void ScreenOrientation::setAngle(unsigned short angle) |
143 { | 148 { |
144 m_angle = angle; | 149 m_angle = angle; |
145 } | 150 } |
146 | 151 |
147 ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lo ckString) | 152 ScriptPromise ScreenOrientation::lock(ScriptState* state, const AtomicString& lo ckString) |
148 { | 153 { |
149 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(state ); | 154 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(state ); |
150 ScriptPromise promise = resolver->promise(); | 155 ScriptPromise promise = resolver->promise(); |
151 | 156 |
152 Document* document = m_frame ? m_frame->document() : 0; | 157 Document* document = m_frame ? m_frame->document() : 0; |
158 UseCounter::count(document, UseCounter::ScreenOrientationLock); | |
153 | 159 |
154 if (!document || !controller()) { | 160 if (!document || !controller()) { |
155 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali dStateError, "The object is no longer associated to a document."); | 161 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Invali dStateError, "The object is no longer associated to a document."); |
156 resolver->reject(exception); | 162 resolver->reject(exception); |
157 return promise; | 163 return promise; |
158 } | 164 } |
159 | 165 |
160 if (document->isSandboxed(SandboxOrientationLock)) { | 166 if (document->isSandboxed(SandboxOrientationLock)) { |
161 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag. "); | 167 RefPtrWillBeRawPtr<DOMException> exception = DOMException::create(Securi tyError, "The document is sandboxed and lacks the 'allow-orientation-lock' flag. "); |
162 resolver->reject(exception); | 168 resolver->reject(exception); |
(...skipping 20 matching lines...) Expand all Loading... | |
183 return ScreenOrientationController::from(*m_frame); | 189 return ScreenOrientationController::from(*m_frame); |
184 } | 190 } |
185 | 191 |
186 void ScreenOrientation::trace(Visitor* visitor) | 192 void ScreenOrientation::trace(Visitor* visitor) |
187 { | 193 { |
188 EventTargetWithInlineData::trace(visitor); | 194 EventTargetWithInlineData::trace(visitor); |
189 DOMWindowProperty::trace(visitor); | 195 DOMWindowProperty::trace(visitor); |
190 } | 196 } |
191 | 197 |
192 } // namespace blink | 198 } // namespace blink |
OLD | NEW |