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

Side by Side Diff: ui/display/fake_display_snapshot.cc

Issue 2437053002: Catch bad display sizes. (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/display/fake_display_snapshot_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/display/fake_display_snapshot.h" 5 #include "ui/display/fake_display_snapshot.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <sstream> 9 #include <sstream>
10 #include <utility> 10 #include <utility>
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 int height = 0; 90 int height = 0;
91 std::string refresh_rate_str; 91 std::string refresh_rate_str;
92 92
93 // Check against regex and extract values. 93 // Check against regex and extract values.
94 if (!RE2::FullMatch(str, "(\\d+)x(\\d+)(?:%(\\d+\\.?\\d*))?", &width, &height, 94 if (!RE2::FullMatch(str, "(\\d+)x(\\d+)(?:%(\\d+\\.?\\d*))?", &width, &height,
95 &refresh_rate_str)) { 95 &refresh_rate_str)) {
96 LOG(ERROR) << "Invalid display mode string \"" << str << "\""; 96 LOG(ERROR) << "Invalid display mode string \"" << str << "\"";
97 return nullptr; 97 return nullptr;
98 } 98 }
99 99
100 if (width <= 0 || height <= 0) {
101 LOG(ERROR) << "Resolution " << width << "x" << height << " is invalid";
102 return nullptr;
103 }
104
100 // Refresh rate is optional and will be be 60 if not specified. 105 // Refresh rate is optional and will be be 60 if not specified.
101 double refresh_rate = 60.0f; 106 double refresh_rate = 60.0f;
102 if (!refresh_rate_str.empty() && 107 if (!refresh_rate_str.empty() &&
103 !base::StringToDouble(refresh_rate_str, &refresh_rate)) { 108 !base::StringToDouble(refresh_rate_str, &refresh_rate)) {
104 LOG(ERROR) << "Unable to parse display mode \"" << str << "\""; 109 LOG(ERROR) << "Unable to parse display mode \"" << str << "\"";
105 return nullptr; 110 return nullptr;
106 } 111 }
107 112
108 return base::MakeUnique<ui::DisplayMode>(gfx::Size(width, height), false, 113 return base::MakeUnique<ui::DisplayMode>(gfx::Size(width, height), false,
109 static_cast<float>(refresh_rate)); 114 static_cast<float>(refresh_rate));
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 " physical_size=%s, type=%s name=\"%s\" modes=(%s)", 377 " physical_size=%s, type=%s name=\"%s\" modes=(%s)",
373 display_id_, 378 display_id_,
374 current_mode_ ? current_mode_->ToString().c_str() : "nullptr", 379 current_mode_ ? current_mode_->ToString().c_str() : "nullptr",
375 native_mode_ ? native_mode_->ToString().c_str() : "nullptr", 380 native_mode_ ? native_mode_->ToString().c_str() : "nullptr",
376 origin_.ToString().c_str(), physical_size_.ToString().c_str(), 381 origin_.ToString().c_str(), physical_size_.ToString().c_str(),
377 DisplayConnectionTypeString(type_).c_str(), display_name_.c_str(), 382 DisplayConnectionTypeString(type_).c_str(), display_name_.c_str(),
378 ModeListString(modes_).c_str()); 383 ModeListString(modes_).c_str());
379 } 384 }
380 385
381 } // namespace display 386 } // namespace display
OLDNEW
« no previous file with comments | « no previous file | ui/display/fake_display_snapshot_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698