Chromium Code Reviews| 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 "config.h" | |
| 6 #include "modules/screen_orientation/ScreenOrientationInspectorAgent.h" | |
| 7 | |
| 8 #include "core/InspectorTypeBuilder.h" | |
| 9 #include "core/frame/LocalFrame.h" | |
| 10 #include "core/inspector/InspectorState.h" | |
| 11 #include "modules/screen_orientation/ScreenOrientation.h" | |
| 12 #include "modules/screen_orientation/ScreenOrientationController.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 namespace ScreenOrientationInspectorAgentState { | |
| 17 static const char angle[] = "angle"; | |
| 18 static const char type[] = "type"; | |
| 19 static const char overrideEnabled[] = "overrideEnabled"; | |
| 20 } | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 WebScreenOrientationType WebScreenOrientationTypeFromString(const String& type) | |
| 25 { | |
| 26 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::PortraitPrimary)) | |
| 27 return WebScreenOrientationPortraitPrimary; | |
| 28 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::PortraitSecondary)) | |
| 29 return WebScreenOrientationPortraitSecondary; | |
| 30 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::LandscapePrimary)) | |
| 31 return WebScreenOrientationLandscapePrimary; | |
| 32 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::LandscapeSecondary)) | |
| 33 return WebScreenOrientationLandscapeSecondary; | |
| 34 return WebScreenOrientationUndefined; | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 // static | |
| 40 PassOwnPtrWillBeRawPtr<ScreenOrientationInspectorAgent> ScreenOrientationInspect orAgent::create(LocalFrame& frame) | |
| 41 { | |
| 42 return adoptPtrWillBeNoop(new ScreenOrientationInspectorAgent(frame)); | |
| 43 } | |
| 44 | |
| 45 ScreenOrientationInspectorAgent::~ScreenOrientationInspectorAgent() | |
| 46 { | |
| 47 } | |
| 48 | |
| 49 ScreenOrientationInspectorAgent::ScreenOrientationInspectorAgent(LocalFrame& fra me) | |
| 50 : InspectorBaseAgent<ScreenOrientationInspectorAgent, InspectorFrontend::Scr eenOrientation>("ScreenOrientation") | |
| 51 , m_frame(frame) | |
| 52 { | |
| 53 } | |
| 54 | |
| 55 ScreenOrientationController& ScreenOrientationInspectorAgent::controller() | |
| 56 { | |
| 57 return *ScreenOrientationController::from(m_frame); | |
| 58 } | |
| 59 | |
| 60 void ScreenOrientationInspectorAgent::setScreenOrientationOverride(ErrorString* error, int angle, const String& typeString) | |
| 61 { | |
| 62 if (angle < -360 || angle > 360) { | |
| 63 *error = "Angle should be between -360 and 360"; | |
|
mlamouri (slow - plz ping)
2015/06/24 16:51:06
No, it should be between in [ 0; 360 [ (ie. >=0 &&
dgozman
2015/06/25 12:21:26
Fixed.
| |
| 64 return; | |
| 65 } | |
| 66 WebScreenOrientationType type = WebScreenOrientationTypeFromString(typeStrin g); | |
| 67 if (type == WebScreenOrientationUndefined) { | |
| 68 *error = "Wrong type value"; | |
| 69 return; | |
| 70 } | |
| 71 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, t rue); | |
| 72 m_state->setLong(ScreenOrientationInspectorAgentState::angle, angle); | |
| 73 m_state->setLong(ScreenOrientationInspectorAgentState::type, type); | |
| 74 controller().setOverride(type, angle); | |
| 75 } | |
| 76 | |
| 77 void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString * error) | |
| 78 { | |
| 79 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f alse); | |
| 80 controller().clearOverride(); | |
| 81 } | |
| 82 | |
| 83 void ScreenOrientationInspectorAgent::disable(ErrorString*) | |
| 84 { | |
| 85 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f alse); | |
| 86 controller().clearOverride(); | |
| 87 } | |
| 88 | |
| 89 void ScreenOrientationInspectorAgent::restore() | |
| 90 { | |
| 91 if (m_state->getBoolean(ScreenOrientationInspectorAgentState::overrideEnable d)) { | |
| 92 WebScreenOrientationType type = static_cast<WebScreenOrientationType>(m_ state->getLong(ScreenOrientationInspectorAgentState::type)); | |
| 93 int angle = m_state->getLong(ScreenOrientationInspectorAgentState::angle ); | |
| 94 controller().setOverride(type, angle); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 void ScreenOrientationInspectorAgent::didCommitLoadForLocalFrame(LocalFrame* fra me) | |
| 99 { | |
| 100 if (*frame == m_frame) { | |
| 101 // New document in main frame - apply override there. | |
| 102 // No need to cleanup previous one, as it's already gone. | |
|
mlamouri (slow - plz ping)
2015/06/24 16:51:06
I'm confused. What are you trying to do here?
dgozman
2015/06/25 12:21:26
That is a leftover from Page-based solution. Remov
| |
| 103 restore(); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 } // namespace blink | |
| OLD | NEW |