Index: ui/gfx/color_profile_win.cc |
diff --git a/ui/gfx/color_profile_win.cc b/ui/gfx/color_profile_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a363c5be57eea43b40f55b0d417680e5fc960ace |
--- /dev/null |
+++ b/ui/gfx/color_profile_win.cc |
@@ -0,0 +1,55 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/gfx/color_profile.h" |
+ |
+#include <stdio.h> |
+#include <windows.h> |
+ |
+#include "base/file_util.h" |
+#include "base/sys_byteorder.h" |
+ |
+// Max profile size is 4M. |
+#define MAX_PROFILE_LENGTH (4 * 1000 * 1000) |
+ |
+namespace { |
+ |
+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.
|
+ uint32 length; |
+ |
+ memcpy(&length, data.data(), sizeof(length)); |
+ |
+ return base::NetToHost32(length); |
+} |
+ |
+} // namespace |
+ |
+namespace gfx { |
+ |
+void ColorProfile::ReadProfile(gfx::NativeViewId parent_window, |
+ std::vector<char>* profile) { |
+ HDC screen_dc = GetDC(NULL); |
+ DWORD path_len = MAX_PATH; |
+ WCHAR path[MAX_PATH]; |
+ |
+ BOOL res = GetICMProfile(screen_dc, |
+ &path_len, |
+ reinterpret_cast<LPWSTR>(&path)); |
+ ReleaseDC(NULL, screen_dc); |
+ if (!res) |
+ return; |
+ std::string profileData; |
+ if (!file_util::ReadFileToString(FilePath(path), &profileData)) |
+ return; |
+ 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
|
+ return; |
+ size_t length = ReadLengthFromString(profileData); |
+ if (length == 0 || length + sizeof(uint32) > profileData.size()) |
+ return; |
+ const char* dataBuffer = profileData.data() + sizeof(uint32); |
+ profile->assign(dataBuffer, dataBuffer + length); |
+} |
+ |
+} // namespace gfx |
+ |