Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1083)

Unified Diff: Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp

Issue 209333008: [DevTools] Support device orientation override on device with sensors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebaselined test Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/device_orientation/DeviceOrientationInspectorAgent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp
diff --git a/Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp b/Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp
index 1b0ca14280a96d71e4dc0e7e937a1e22e0f33a70..e49ad92e5365d2707927e6c3c8ee8d54e5370653 100644
--- a/Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp
+++ b/Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp
@@ -8,6 +8,7 @@
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/inspector/InspectorController.h"
+#include "core/inspector/InspectorState.h"
#include "core/page/Page.h"
#include "modules/device_orientation/DeviceOrientationController.h"
@@ -15,6 +16,13 @@
namespace WebCore {
+namespace DeviceOrientationInspectorAgentState {
+static const char alpha[] = "alpha";
timvolodine 2014/03/27 00:04:30 I think you need to indent this, because the scope
dgozman 2014/03/27 09:30:33 There are similar namespaces in the code without a
+static const char beta[] = "beta";
+static const char gamma[] = "gamma";
+static const char overrideEnabled[] = "overrideEnabled";
+}
+
void DeviceOrientationInspectorAgent::provideTo(Page& page)
{
OwnPtr<DeviceOrientationInspectorAgent> deviceOrientationAgent(adoptPtr(new DeviceOrientationInspectorAgent(page)));
@@ -31,16 +39,48 @@ DeviceOrientationInspectorAgent::DeviceOrientationInspectorAgent(Page& page)
{
}
-void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString* error, double alpha, double beta, double gamma)
+DeviceOrientationController& DeviceOrientationInspectorAgent::controller()
{
ASSERT(m_page.mainFrame()->document());
- DeviceOrientationController& controller = DeviceOrientationController::from(*m_page.mainFrame()->document());
- controller.didChangeDeviceOrientation(DeviceOrientationData::create(true, alpha, true, beta, true, gamma).get());
+ return DeviceOrientationController::from(*m_page.mainFrame()->document());
+}
+
+void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString* error, double alpha, double beta, double gamma)
+{
+ m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, true);
+ m_state->setDouble(DeviceOrientationInspectorAgentState::alpha, alpha);
+ m_state->setDouble(DeviceOrientationInspectorAgentState::beta, beta);
+ m_state->setDouble(DeviceOrientationInspectorAgentState::gamma, gamma);
+ controller().setOverride(DeviceOrientationData::create(true, alpha, true, beta, true, gamma).get());
}
void DeviceOrientationInspectorAgent::clearDeviceOrientationOverride(ErrorString* error)
{
- setDeviceOrientationOverride(error, 0, 0, 0);
+ m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, false);
+ controller().clearOverride();
+}
+
+void DeviceOrientationInspectorAgent::clearFrontend()
+{
+ m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, false);
+ controller().clearOverride();
+}
+
+void DeviceOrientationInspectorAgent::restore()
+{
+ if (m_state->getBoolean(DeviceOrientationInspectorAgentState::overrideEnabled)) {
+ double alpha = m_state->getDouble(DeviceOrientationInspectorAgentState::alpha);
+ double beta = m_state->getDouble(DeviceOrientationInspectorAgentState::beta);
+ double gamma = m_state->getDouble(DeviceOrientationInspectorAgentState::gamma);
+ controller().setOverride(DeviceOrientationData::create(true, alpha, true, beta, true, gamma).get());
+ }
+}
+
+void DeviceOrientationInspectorAgent::didCommitLoadForMainFrame()
+{
+ // New document in main frame - apply override there.
+ // No need to cleanup previous one, as it's already gone.
+ restore();
}
} // namespace WebCore
« no previous file with comments | « Source/modules/device_orientation/DeviceOrientationInspectorAgent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698