OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "web/InspectorEmulationAgent.h" | 5 #include "web/InspectorEmulationAgent.h" |
6 | 6 |
| 7 #include "core/exported/WebViewBase.h" |
7 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
8 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
9 #include "core/inspector/protocol/DOM.h" | 10 #include "core/inspector/protocol/DOM.h" |
10 #include "core/page/Page.h" | 11 #include "core/page/Page.h" |
11 #include "platform/geometry/DoubleRect.h" | 12 #include "platform/geometry/DoubleRect.h" |
12 #include "platform/graphics/Color.h" | 13 #include "platform/graphics/Color.h" |
13 #include "platform/scheduler/renderer/web_view_scheduler.h" | 14 #include "platform/scheduler/renderer/web_view_scheduler.h" |
14 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
15 #include "public/platform/WebFloatPoint.h" | 16 #include "public/platform/WebFloatPoint.h" |
16 #include "public/platform/WebThread.h" | 17 #include "public/platform/WebThread.h" |
17 #include "web/DevToolsEmulator.h" | 18 #include "web/DevToolsEmulator.h" |
18 #include "web/WebLocalFrameImpl.h" | 19 #include "web/WebLocalFrameImpl.h" |
19 #include "web/WebViewImpl.h" | |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 | 22 |
23 using protocol::Maybe; | 23 using protocol::Maybe; |
24 using protocol::Response; | 24 using protocol::Response; |
25 | 25 |
26 namespace EmulationAgentState { | 26 namespace EmulationAgentState { |
27 static const char kScriptExecutionDisabled[] = "scriptExecutionDisabled"; | 27 static const char kScriptExecutionDisabled[] = "scriptExecutionDisabled"; |
28 static const char kTouchEventEmulationEnabled[] = "touchEventEmulationEnabled"; | 28 static const char kTouchEventEmulationEnabled[] = "touchEventEmulationEnabled"; |
29 static const char kEmulatedMedia[] = "emulatedMedia"; | 29 static const char kEmulatedMedia[] = "emulatedMedia"; |
(...skipping 11 matching lines...) Expand all Loading... |
41 return new InspectorEmulationAgent(web_local_frame_impl, client); | 41 return new InspectorEmulationAgent(web_local_frame_impl, client); |
42 } | 42 } |
43 | 43 |
44 InspectorEmulationAgent::InspectorEmulationAgent( | 44 InspectorEmulationAgent::InspectorEmulationAgent( |
45 WebLocalFrameImpl* web_local_frame_impl, | 45 WebLocalFrameImpl* web_local_frame_impl, |
46 Client* client) | 46 Client* client) |
47 : web_local_frame_impl_(web_local_frame_impl), client_(client) {} | 47 : web_local_frame_impl_(web_local_frame_impl), client_(client) {} |
48 | 48 |
49 InspectorEmulationAgent::~InspectorEmulationAgent() {} | 49 InspectorEmulationAgent::~InspectorEmulationAgent() {} |
50 | 50 |
51 WebViewImpl* InspectorEmulationAgent::GetWebViewImpl() { | 51 WebViewBase* InspectorEmulationAgent::GetWebViewBase() { |
52 return web_local_frame_impl_->ViewImpl(); | 52 return web_local_frame_impl_->ViewImpl(); |
53 } | 53 } |
54 | 54 |
55 void InspectorEmulationAgent::Restore() { | 55 void InspectorEmulationAgent::Restore() { |
56 setScriptExecutionDisabled(state_->booleanProperty( | 56 setScriptExecutionDisabled(state_->booleanProperty( |
57 EmulationAgentState::kScriptExecutionDisabled, false)); | 57 EmulationAgentState::kScriptExecutionDisabled, false)); |
58 setTouchEmulationEnabled( | 58 setTouchEmulationEnabled( |
59 state_->booleanProperty(EmulationAgentState::kTouchEventEmulationEnabled, | 59 state_->booleanProperty(EmulationAgentState::kTouchEventEmulationEnabled, |
60 false), | 60 false), |
61 protocol::Maybe<String>()); | 61 protocol::Maybe<String>()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return Response::Error("Coordinates must be non-negative"); | 99 return Response::Error("Coordinates must be non-negative"); |
100 | 100 |
101 if (scale <= 0) | 101 if (scale <= 0) |
102 return Response::Error("Scale must be positive"); | 102 return Response::Error("Scale must be positive"); |
103 | 103 |
104 state_->setBoolean(EmulationAgentState::kForcedViewportEnabled, true); | 104 state_->setBoolean(EmulationAgentState::kForcedViewportEnabled, true); |
105 state_->setDouble(EmulationAgentState::kForcedViewportX, x); | 105 state_->setDouble(EmulationAgentState::kForcedViewportX, x); |
106 state_->setDouble(EmulationAgentState::kForcedViewportY, y); | 106 state_->setDouble(EmulationAgentState::kForcedViewportY, y); |
107 state_->setDouble(EmulationAgentState::kForcedViewportScale, scale); | 107 state_->setDouble(EmulationAgentState::kForcedViewportScale, scale); |
108 | 108 |
109 GetWebViewImpl()->GetDevToolsEmulator()->ForceViewport(WebFloatPoint(x, y), | 109 GetWebViewBase()->GetDevToolsEmulator()->ForceViewport(WebFloatPoint(x, y), |
110 scale); | 110 scale); |
111 return Response::OK(); | 111 return Response::OK(); |
112 } | 112 } |
113 | 113 |
114 Response InspectorEmulationAgent::resetViewport() { | 114 Response InspectorEmulationAgent::resetViewport() { |
115 state_->setBoolean(EmulationAgentState::kForcedViewportEnabled, false); | 115 state_->setBoolean(EmulationAgentState::kForcedViewportEnabled, false); |
116 GetWebViewImpl()->GetDevToolsEmulator()->ResetViewport(); | 116 GetWebViewBase()->GetDevToolsEmulator()->ResetViewport(); |
117 return Response::OK(); | 117 return Response::OK(); |
118 } | 118 } |
119 | 119 |
120 Response InspectorEmulationAgent::resetPageScaleFactor() { | 120 Response InspectorEmulationAgent::resetPageScaleFactor() { |
121 GetWebViewImpl()->ResetScaleStateImmediately(); | 121 GetWebViewBase()->ResetScaleStateImmediately(); |
122 return Response::OK(); | 122 return Response::OK(); |
123 } | 123 } |
124 | 124 |
125 Response InspectorEmulationAgent::setPageScaleFactor(double page_scale_factor) { | 125 Response InspectorEmulationAgent::setPageScaleFactor(double page_scale_factor) { |
126 GetWebViewImpl()->SetPageScaleFactor(static_cast<float>(page_scale_factor)); | 126 GetWebViewBase()->SetPageScaleFactor(static_cast<float>(page_scale_factor)); |
127 return Response::OK(); | 127 return Response::OK(); |
128 } | 128 } |
129 | 129 |
130 Response InspectorEmulationAgent::setScriptExecutionDisabled(bool value) { | 130 Response InspectorEmulationAgent::setScriptExecutionDisabled(bool value) { |
131 state_->setBoolean(EmulationAgentState::kScriptExecutionDisabled, value); | 131 state_->setBoolean(EmulationAgentState::kScriptExecutionDisabled, value); |
132 GetWebViewImpl()->GetDevToolsEmulator()->SetScriptExecutionDisabled(value); | 132 GetWebViewBase()->GetDevToolsEmulator()->SetScriptExecutionDisabled(value); |
133 return Response::OK(); | 133 return Response::OK(); |
134 } | 134 } |
135 | 135 |
136 Response InspectorEmulationAgent::setTouchEmulationEnabled( | 136 Response InspectorEmulationAgent::setTouchEmulationEnabled( |
137 bool enabled, | 137 bool enabled, |
138 Maybe<String> configuration) { | 138 Maybe<String> configuration) { |
139 state_->setBoolean(EmulationAgentState::kTouchEventEmulationEnabled, enabled); | 139 state_->setBoolean(EmulationAgentState::kTouchEventEmulationEnabled, enabled); |
140 GetWebViewImpl()->GetDevToolsEmulator()->SetTouchEventEmulationEnabled( | 140 GetWebViewBase()->GetDevToolsEmulator()->SetTouchEventEmulationEnabled( |
141 enabled); | 141 enabled); |
142 return Response::OK(); | 142 return Response::OK(); |
143 } | 143 } |
144 | 144 |
145 Response InspectorEmulationAgent::setEmulatedMedia(const String& media) { | 145 Response InspectorEmulationAgent::setEmulatedMedia(const String& media) { |
146 state_->setString(EmulationAgentState::kEmulatedMedia, media); | 146 state_->setString(EmulationAgentState::kEmulatedMedia, media); |
147 GetWebViewImpl()->GetPage()->GetSettings().SetMediaTypeOverride(media); | 147 GetWebViewBase()->GetPage()->GetSettings().SetMediaTypeOverride(media); |
148 return Response::OK(); | 148 return Response::OK(); |
149 } | 149 } |
150 | 150 |
151 Response InspectorEmulationAgent::setCPUThrottlingRate(double throttling_rate) { | 151 Response InspectorEmulationAgent::setCPUThrottlingRate(double throttling_rate) { |
152 client_->SetCPUThrottlingRate(throttling_rate); | 152 client_->SetCPUThrottlingRate(throttling_rate); |
153 return Response::OK(); | 153 return Response::OK(); |
154 } | 154 } |
155 | 155 |
156 Response InspectorEmulationAgent::setVirtualTimePolicy(const String& policy, | 156 Response InspectorEmulationAgent::setVirtualTimePolicy(const String& policy, |
157 Maybe<int> budget) { | 157 Maybe<int> budget) { |
(...skipping 27 matching lines...) Expand all Loading... |
185 void InspectorEmulationAgent::VirtualTimeBudgetExpired() { | 185 void InspectorEmulationAgent::VirtualTimeBudgetExpired() { |
186 web_local_frame_impl_->View()->Scheduler()->SetVirtualTimePolicy( | 186 web_local_frame_impl_->View()->Scheduler()->SetVirtualTimePolicy( |
187 WebViewScheduler::VirtualTimePolicy::PAUSE); | 187 WebViewScheduler::VirtualTimePolicy::PAUSE); |
188 GetFrontend()->virtualTimeBudgetExpired(); | 188 GetFrontend()->virtualTimeBudgetExpired(); |
189 } | 189 } |
190 | 190 |
191 Response InspectorEmulationAgent::setDefaultBackgroundColorOverride( | 191 Response InspectorEmulationAgent::setDefaultBackgroundColorOverride( |
192 Maybe<protocol::DOM::RGBA> color) { | 192 Maybe<protocol::DOM::RGBA> color) { |
193 if (!color.isJust()) { | 193 if (!color.isJust()) { |
194 // Clear the override and state. | 194 // Clear the override and state. |
195 GetWebViewImpl()->ClearBaseBackgroundColorOverride(); | 195 GetWebViewBase()->ClearBaseBackgroundColorOverride(); |
196 state_->remove(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA); | 196 state_->remove(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA); |
197 return Response::OK(); | 197 return Response::OK(); |
198 } | 198 } |
199 | 199 |
200 blink::protocol::DOM::RGBA* rgba = color.fromJust(); | 200 blink::protocol::DOM::RGBA* rgba = color.fromJust(); |
201 state_->setValue(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA, | 201 state_->setValue(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA, |
202 rgba->toValue()); | 202 rgba->toValue()); |
203 // Clamping of values is done by Color() constructor. | 203 // Clamping of values is done by Color() constructor. |
204 int alpha = lroundf(255.0f * rgba->getA(1.0f)); | 204 int alpha = lroundf(255.0f * rgba->getA(1.0f)); |
205 GetWebViewImpl()->SetBaseBackgroundColorOverride( | 205 GetWebViewBase()->SetBaseBackgroundColorOverride( |
206 Color(rgba->getR(), rgba->getG(), rgba->getB(), alpha).Rgb()); | 206 Color(rgba->getR(), rgba->getG(), rgba->getB(), alpha).Rgb()); |
207 return Response::OK(); | 207 return Response::OK(); |
208 } | 208 } |
209 | 209 |
210 DEFINE_TRACE(InspectorEmulationAgent) { | 210 DEFINE_TRACE(InspectorEmulationAgent) { |
211 visitor->Trace(web_local_frame_impl_); | 211 visitor->Trace(web_local_frame_impl_); |
212 InspectorBaseAgent::Trace(visitor); | 212 InspectorBaseAgent::Trace(visitor); |
213 } | 213 } |
214 | 214 |
215 } // namespace blink | 215 } // namespace blink |
OLD | NEW |