| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/screen_orientation/ScreenOrientationInspectorAgent.h" | |
| 6 | |
| 7 #include "core/frame/LocalFrame.h" | |
| 8 #include "modules/screen_orientation/ScreenOrientation.h" | |
| 9 #include "modules/screen_orientation/ScreenOrientationController.h" | |
| 10 #include "platform/inspector_protocol/TypeBuilder.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 namespace ScreenOrientationInspectorAgentState { | |
| 15 static const char angle[] = "angle"; | |
| 16 static const char type[] = "type"; | |
| 17 static const char overrideEnabled[] = "overrideEnabled"; | |
| 18 } | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 WebScreenOrientationType WebScreenOrientationTypeFromString(const String& type) | |
| 23 { | |
| 24 if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilde
r::ScreenOrientation::OrientationType::PortraitPrimary)) | |
| 25 return WebScreenOrientationPortraitPrimary; | |
| 26 if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilde
r::ScreenOrientation::OrientationType::PortraitSecondary)) | |
| 27 return WebScreenOrientationPortraitSecondary; | |
| 28 if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilde
r::ScreenOrientation::OrientationType::LandscapePrimary)) | |
| 29 return WebScreenOrientationLandscapePrimary; | |
| 30 if (type == protocol::TypeBuilder::getEnumConstantValue(protocol::TypeBuilde
r::ScreenOrientation::OrientationType::LandscapeSecondary)) | |
| 31 return WebScreenOrientationLandscapeSecondary; | |
| 32 return WebScreenOrientationUndefined; | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 // static | |
| 38 PassOwnPtrWillBeRawPtr<ScreenOrientationInspectorAgent> ScreenOrientationInspect
orAgent::create(LocalFrame& frame) | |
| 39 { | |
| 40 return adoptPtrWillBeNoop(new ScreenOrientationInspectorAgent(frame)); | |
| 41 } | |
| 42 | |
| 43 ScreenOrientationInspectorAgent::~ScreenOrientationInspectorAgent() | |
| 44 { | |
| 45 } | |
| 46 | |
| 47 ScreenOrientationInspectorAgent::ScreenOrientationInspectorAgent(LocalFrame& fra
me) | |
| 48 : InspectorBaseAgent<ScreenOrientationInspectorAgent, protocol::Frontend::Sc
reenOrientation>("ScreenOrientation") | |
| 49 , m_frame(&frame) | |
| 50 { | |
| 51 } | |
| 52 | |
| 53 DEFINE_TRACE(ScreenOrientationInspectorAgent) | |
| 54 { | |
| 55 visitor->trace(m_frame); | |
| 56 InspectorBaseAgent<ScreenOrientationInspectorAgent, protocol::Frontend::Scre
enOrientation>::trace(visitor); | |
| 57 } | |
| 58 | |
| 59 void ScreenOrientationInspectorAgent::setScreenOrientationOverride(ErrorString*
error, int angle, const String& typeString) | |
| 60 { | |
| 61 if (angle < 0 || angle >= 360) { | |
| 62 *error = "Angle should be in [0; 360) interval"; | |
| 63 return; | |
| 64 } | |
| 65 WebScreenOrientationType type = WebScreenOrientationTypeFromString(typeStrin
g); | |
| 66 if (type == WebScreenOrientationUndefined) { | |
| 67 *error = "Wrong type value"; | |
| 68 return; | |
| 69 } | |
| 70 ScreenOrientationController* controller = ScreenOrientationController::from(
*m_frame); | |
| 71 if (!controller) { | |
| 72 *error = "Cannot connect to orientation controller"; | |
| 73 return; | |
| 74 } | |
| 75 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, t
rue); | |
| 76 m_state->setNumber(ScreenOrientationInspectorAgentState::angle, angle); | |
| 77 m_state->setNumber(ScreenOrientationInspectorAgentState::type, type); | |
| 78 controller->setOverride(type, angle); | |
| 79 } | |
| 80 | |
| 81 void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString
* error) | |
| 82 { | |
| 83 ScreenOrientationController* controller = ScreenOrientationController::from(
*m_frame); | |
| 84 if (!controller) { | |
| 85 *error = "Cannot connect to orientation controller"; | |
| 86 return; | |
| 87 } | |
| 88 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f
alse); | |
| 89 controller->clearOverride(); | |
| 90 } | |
| 91 | |
| 92 void ScreenOrientationInspectorAgent::disable(ErrorString*) | |
| 93 { | |
| 94 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f
alse); | |
| 95 if (ScreenOrientationController* controller = ScreenOrientationController::f
rom(*m_frame)) | |
| 96 controller->clearOverride(); | |
| 97 } | |
| 98 | |
| 99 void ScreenOrientationInspectorAgent::restore() | |
| 100 { | |
| 101 if (m_state->booleanProperty(ScreenOrientationInspectorAgentState::overrideE
nabled, false)) { | |
| 102 long longType = static_cast<long>(WebScreenOrientationUndefined); | |
| 103 m_state->getNumber(ScreenOrientationInspectorAgentState::type, &longType
); | |
| 104 WebScreenOrientationType type = static_cast<WebScreenOrientationType>(lo
ngType); | |
| 105 int angle = 0; | |
| 106 m_state->getNumber(ScreenOrientationInspectorAgentState::angle, &angle); | |
| 107 if (ScreenOrientationController* controller = ScreenOrientationControlle
r::from(*m_frame)) | |
| 108 controller->setOverride(type, angle); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 } // namespace blink | |
| OLD | NEW |