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

Side by Side Diff: webkit/support/platform_support_win.cc

Issue 18429012: Don't load resources for test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 4 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 | « webkit/support/platform_support_mac.mm ('k') | webkit/support/test_webkit_platform_support.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 (c) 2012 The Chromium Authors. All rights reserved. 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 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/support/platform_support.h" 5 #include "webkit/support/platform_support.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "base/win/resource_util.h" 14 #include "base/win/resource_util.h"
15 #include "grit/blink_resources.h" 15 #include "grit/blink_resources.h"
16 #include "grit/webkit_resources.h" 16 #include "grit/webkit_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "webkit/support/test_webkit_platform_support.h" 18 #include "webkit/support/test_webkit_platform_support.h"
19 19
20 #define MAX_LOADSTRING 100
21
22 namespace {
23
24 base::FilePath GetResourceFilePath(const char* ascii_name) {
25 base::FilePath path;
26 PathService::Get(base::DIR_EXE, &path);
27 path = path.AppendASCII("DumpRenderTree_resources");
28 return path.AppendASCII(ascii_name);
29 }
30
31 base::StringPiece GetRawDataResource(HMODULE module, int resource_id) {
32 void* data_ptr;
33 size_t data_size;
34 return base::win::GetDataResourceFromModule(module, resource_id, &data_ptr,
35 &data_size)
36 ? base::StringPiece(static_cast<char*>(data_ptr), data_size)
37 : base::StringPiece();
38 }
39
40 base::StringPiece ResourceProvider(int key) {
41 return GetRawDataResource(::GetModuleHandle(NULL), key);
42 }
43
44 } // namespace
45 20
46 namespace webkit_support { 21 namespace webkit_support {
47 22
48 // TODO(tkent): Implement some of the followings for platform-dependent tasks
49 // such as loading resource.
50
51 void BeforeInitialize() { 23 void BeforeInitialize() {
52 } 24 }
53 25
54 void AfterInitialize() { 26 void AfterInitialize() {
55 // TODO(dpranke): update other resource loading to use the pak
56 // instead of loading resources directly compiled in.
57 base::FilePath path;
58 PathService::Get(base::DIR_EXE, &path);
59 path = path.AppendASCII("DumpRenderTree.pak");
60 ResourceBundle::InitSharedInstanceWithPakPath(path);
61 } 27 }
62 28
63 void BeforeShutdown() { 29 void BeforeShutdown() {
64 ResourceBundle::CleanupSharedInstance();
65 } 30 }
66 31
67 void AfterShutdown() { 32 void AfterShutdown() {
68 } 33 }
69 34
70 } // namespace webkit_support 35 } // namespace webkit_support
71 36
72 base::string16 TestWebKitPlatformSupport::GetLocalizedString(int message_id) {
73 wchar_t localized[MAX_LOADSTRING];
74 int length = ::LoadString(::GetModuleHandle(NULL), message_id,
75 localized, MAX_LOADSTRING);
76 if (!length && ::GetLastError() == ERROR_RESOURCE_NAME_NOT_FOUND) {
77 NOTREACHED();
78 return L"No string for this identifier!";
79 }
80 return base::string16(localized, length);
81 }
82
83 base::StringPiece TestWebKitPlatformSupport::GetDataResource(
84 int resource_id,
85 ui::ScaleFactor scale_factor) {
86 switch (resource_id) {
87 case IDR_BROKENIMAGE: {
88 // Use webkit's broken image icon (16x16)
89 static std::string broken_image_data;
90 if (broken_image_data.empty()) {
91 base::FilePath path = GetResourceFilePath("missingImage.gif");
92 bool success = file_util::ReadFileToString(path, &broken_image_data);
93 if (!success) {
94 LOG(FATAL) << "Failed reading: " << path.value();
95 }
96 }
97 return broken_image_data;
98 }
99 case IDR_TEXTAREA_RESIZER: {
100 // Use webkit's text area resizer image.
101 static std::string resize_corner_data;
102 if (resize_corner_data.empty()) {
103 base::FilePath path = GetResourceFilePath("textAreaResizeCorner.png");
104 bool success = file_util::ReadFileToString(path, &resize_corner_data);
105 if (!success) {
106 LOG(FATAL) << "Failed reading: " << path.value();
107 }
108 }
109 return resize_corner_data;
110 }
111 }
112
113 // TODO(flackr): Pass scale_factor to ResourceProvider.
114 return ResourceProvider(resource_id);
115 }
OLDNEW
« no previous file with comments | « webkit/support/platform_support_mac.mm ('k') | webkit/support/test_webkit_platform_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698