Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / device_orientation / DeviceOrientationInspectorAgent.cpp
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/device_orientation/DeviceOrientationInspectorAgent.h"
7
8 #include "core/dom/Document.h"
9 #include "core/frame/Frame.h"
10 #include "core/inspector/InspectorController.h"
11 #include "core/page/Page.h"
12
13 #include "modules/device_orientation/DeviceOrientationController.h"
14 #include "modules/device_orientation/DeviceOrientationData.h"
15
16 namespace WebCore {
17
18 void DeviceOrientationInspectorAgent::provideTo(Page* page)
19 {
20     OwnPtr<DeviceOrientationInspectorAgent> deviceOrientationAgent(adoptPtr(new DeviceOrientationInspectorAgent(page)));
21     page->inspectorController().registerModuleAgent(deviceOrientationAgent.release());
22 }
23
24 DeviceOrientationInspectorAgent::~DeviceOrientationInspectorAgent()
25 {
26 }
27
28 DeviceOrientationInspectorAgent::DeviceOrientationInspectorAgent(Page* page)
29     : InspectorBaseAgent<DeviceOrientationInspectorAgent>("DeviceOrientation")
30     , m_page(page)
31 {
32 }
33
34 void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString* error, double alpha, double beta, double gamma)
35 {
36     DeviceOrientationController* controller = DeviceOrientationController::from(m_page->mainFrame()->document());
37     if (!controller) {
38         *error = "Internal error: unable to override device orientation";
39         return;
40     }
41     controller->didChangeDeviceOrientation(DeviceOrientationData::create(true, alpha, true, beta, true, gamma).get());
42 }
43
44 void DeviceOrientationInspectorAgent::clearDeviceOrientationOverride(ErrorString* error)
45 {
46     setDeviceOrientationOverride(error, 0, 0, 0);
47 }
48
49 } // namespace WebCore