| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "webkit/tools/test_shell/test_shell.h" | 5 #include "webkit/tools/test_shell/test_shell.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug_on_start.h" | 8 #include "base/debug_on_start.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 const std::wstring& file_name) { | 190 const std::wstring& file_name) { |
| 191 scoped_ptr<skia::BitmapPlatformDevice> device; | 191 scoped_ptr<skia::BitmapPlatformDevice> device; |
| 192 if (!web_frame->CaptureImage(&device, true)) | 192 if (!web_frame->CaptureImage(&device, true)) |
| 193 return std::string(); | 193 return std::string(); |
| 194 | 194 |
| 195 const SkBitmap& src_bmp = device->accessBitmap(false); | 195 const SkBitmap& src_bmp = device->accessBitmap(false); |
| 196 | 196 |
| 197 // Encode image. | 197 // Encode image. |
| 198 std::vector<unsigned char> png; | 198 std::vector<unsigned char> png; |
| 199 SkAutoLockPixels src_bmp_lock(src_bmp); | 199 SkAutoLockPixels src_bmp_lock(src_bmp); |
| 200 PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_BGRA; |
| 200 #if defined(OS_WIN) || defined(OS_LINUX) | 201 #if defined(OS_WIN) || defined(OS_LINUX) |
| 201 bool discard_transparency = true; | 202 bool discard_transparency = true; |
| 202 PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_BGRA; | |
| 203 #elif defined(OS_MACOSX) | 203 #elif defined(OS_MACOSX) |
| 204 // the expected PNGs in webkit have an alpha channel. We must not discard | 204 // the expected PNGs in webkit have an alpha channel. We shouldn't discard |
| 205 // the transparency else the checksums won't match. | 205 // the transparency for reference purposes, though the hashes will still |
| 206 // match. |
| 206 bool discard_transparency = false; | 207 bool discard_transparency = false; |
| 207 PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_RGBA; | |
| 208 #endif | 208 #endif |
| 209 PNGEncoder::Encode( | 209 PNGEncoder::Encode( |
| 210 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), | 210 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), |
| 211 color_format, src_bmp.width(), src_bmp.height(), | 211 color_format, src_bmp.width(), src_bmp.height(), |
| 212 static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); | 212 static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); |
| 213 | 213 |
| 214 // Write to disk. | 214 // Write to disk. |
| 215 file_util::WriteFile(file_name, reinterpret_cast<const char *>(&png[0]), | 215 file_util::WriteFile(file_name, reinterpret_cast<const char *>(&png[0]), |
| 216 png.size()); | 216 png.size()); |
| 217 | 217 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 return net::GetPreferredExtensionForMimeType(mime_type, ext); | 490 return net::GetPreferredExtensionForMimeType(mime_type, ext); |
| 491 } | 491 } |
| 492 | 492 |
| 493 std::string GetDataResource(int resource_id) { | 493 std::string GetDataResource(int resource_id) { |
| 494 switch (resource_id) { | 494 switch (resource_id) { |
| 495 case IDR_BROKENIMAGE: { | 495 case IDR_BROKENIMAGE: { |
| 496 // Use webkit's broken image icon (16x16) | 496 // Use webkit's broken image icon (16x16) |
| 497 static std::string broken_image_data; | 497 static std::string broken_image_data; |
| 498 if (broken_image_data.empty()) { | 498 if (broken_image_data.empty()) { |
| 499 FilePath path = GetResourcesFilePath(); | 499 FilePath path = GetResourcesFilePath(); |
| 500 #if defined(OS_WIN) || defined(OS_LINUX) |
| 500 path = path.Append(FILE_PATH_LITERAL("missingImage.gif")); | 501 path = path.Append(FILE_PATH_LITERAL("missingImage.gif")); |
| 502 #elif defined(OS_MACOSX) |
| 503 // In order to match WebKit's colors for the missing image, we have to |
| 504 // use a PNG. The GIF doesn't have the color range needed to correctly |
| 505 // match the TIFF they use in Safari. |
| 506 path = path.Append(FILE_PATH_LITERAL("missingImage.png")); |
| 507 #endif |
| 501 bool success = file_util::ReadFileToString(path.ToWStringHack(), | 508 bool success = file_util::ReadFileToString(path.ToWStringHack(), |
| 502 &broken_image_data); | 509 &broken_image_data); |
| 503 if (!success) { | 510 if (!success) { |
| 504 LOG(FATAL) << "Failed reading: " << path.value(); | 511 LOG(FATAL) << "Failed reading: " << path.value(); |
| 505 } | 512 } |
| 506 } | 513 } |
| 507 return broken_image_data; | 514 return broken_image_data; |
| 508 } | 515 } |
| 509 case IDR_FEED_PREVIEW: | 516 case IDR_FEED_PREVIEW: |
| 510 // It is necessary to return a feed preview template that contains | 517 // It is necessary to return a feed preview template that contains |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 605 |
| 599 uint64 VisitedLinkHash(const char* canonical_url, size_t length) { | 606 uint64 VisitedLinkHash(const char* canonical_url, size_t length) { |
| 600 return 0; | 607 return 0; |
| 601 } | 608 } |
| 602 | 609 |
| 603 bool IsLinkVisited(uint64 link_hash) { | 610 bool IsLinkVisited(uint64 link_hash) { |
| 604 return false; | 611 return false; |
| 605 } | 612 } |
| 606 | 613 |
| 607 } // namespace webkit_glue | 614 } // namespace webkit_glue |
| OLD | NEW |