Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 "ui/gfx/color_profile.h" | |
| 6 | |
| 7 #include <stdio.h> | |
| 8 #include <windows.h> | |
| 9 | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/sys_byteorder.h" | |
| 12 | |
| 13 // Max profile size is 4M. | |
| 14 #define MAX_PROFILE_LENGTH (4 * 1000 * 1000) | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 size_t ReadLengthFromString(const std::string& data) { | |
|
Evan Stade
2012/06/20 02:41:47
comment this function
tpayne
2012/06/20 02:46:54
Done.
| |
| 19 uint32 length; | |
| 20 | |
| 21 memcpy(&length, data.data(), sizeof(length)); | |
| 22 | |
| 23 return base::NetToHost32(length); | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace gfx { | |
| 29 | |
| 30 void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, | |
| 31 std::vector<char>* profile) { | |
| 32 HDC screen_dc = GetDC(NULL); | |
| 33 DWORD path_len = MAX_PATH; | |
| 34 WCHAR path[MAX_PATH]; | |
| 35 | |
| 36 BOOL res = GetICMProfile(screen_dc, | |
| 37 &path_len, | |
| 38 reinterpret_cast<LPWSTR>(&path)); | |
| 39 ReleaseDC(NULL, screen_dc); | |
| 40 if (!res) | |
| 41 return; | |
| 42 std::string profileData; | |
| 43 if (!file_util::ReadFileToString(FilePath(path), &profileData)) | |
| 44 return; | |
| 45 if (profileData.size() > MAX_PROFILE_LENGTH) | |
|
Evan Stade
2012/06/20 02:41:47
put this check with the rest of the length checks
tpayne
2012/06/20 02:46:54
I'd prefer to bail out as soon as possible. No nee
Evan Stade
2012/06/20 02:56:58
there's a slight difference: you're effectively ma
| |
| 46 return; | |
| 47 size_t length = ReadLengthFromString(profileData); | |
| 48 if (length == 0 || length + sizeof(uint32) > profileData.size()) | |
| 49 return; | |
| 50 const char* dataBuffer = profileData.data() + sizeof(uint32); | |
| 51 profile->assign(dataBuffer, dataBuffer + length); | |
| 52 } | |
| 53 | |
| 54 } // namespace gfx | |
| 55 | |
| OLD | NEW |