OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 "base/values.h" | |
6 #include "chrome/test/chromedriver/chrome/device_metrics.h" | |
7 #include "chrome/test/chromedriver/chrome/devtools_client.h" | |
8 #include "chrome/test/chromedriver/chrome/mobile_emulation_override_manager.h" | |
9 #include "chrome/test/chromedriver/chrome/status.h" | |
10 | |
11 MobileEmulationOverrideManager::MobileEmulationOverrideManager( | |
12 DevToolsClient* client, | |
13 const DeviceMetrics* device_metrics) | |
14 : client_(client), overridden_device_metrics_(device_metrics) { | |
15 if (overridden_device_metrics_) | |
16 client_->AddListener(this); | |
17 } | |
18 | |
19 MobileEmulationOverrideManager::~MobileEmulationOverrideManager() { | |
20 } | |
21 | |
22 Status MobileEmulationOverrideManager::OnConnected(DevToolsClient* client) { | |
23 return ApplyOverrideIfNeeded(); | |
24 } | |
25 | |
26 Status MobileEmulationOverrideManager::OnEvent( | |
27 DevToolsClient* client, | |
28 const std::string& method, | |
29 const base::DictionaryValue& params) { | |
30 if (method == "Page.frameNavigated") { | |
31 const base::Value* unused_value; | |
32 if (!params.Get("frame.parentId", &unused_value)) | |
33 return ApplyOverrideIfNeeded(); | |
34 } | |
35 return Status(kOk); | |
36 } | |
37 | |
38 Status MobileEmulationOverrideManager::ApplyOverrideIfNeeded() { | |
39 if (overridden_device_metrics_ == NULL) | |
40 return Status(kOk); | |
41 | |
42 base::DictionaryValue params; | |
43 params.SetInteger("width", overridden_device_metrics_->width); | |
44 params.SetInteger("height", overridden_device_metrics_->height); | |
45 params.SetDouble("deviceScaleFactor", | |
46 overridden_device_metrics_->device_scale_factor); | |
47 params.SetBoolean("emulateViewport", | |
pfeldman
2014/05/20 18:57:29
Note that you are using undocumented API that is a
dgozman
2014/05/20 19:01:40
Yes, I want to do this to emphasize it's not only
srawlins
2014/05/20 19:36:15
@pfeldman, @dgozman: SGTM. We can update chromedri
| |
48 overridden_device_metrics_->emulate_viewport); | |
49 params.SetBoolean("fitWindow", overridden_device_metrics_->fit_window); | |
50 params.SetBoolean("textAutosizing", | |
51 overridden_device_metrics_->text_autosizing); | |
52 params.SetDouble("fontScaleFactor", | |
53 overridden_device_metrics_->font_scale_factor); | |
54 return client_->SendCommand("Page.setDeviceMetricsOverride", params); | |
55 } | |
OLD | NEW |