OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/data_pack.h" |
| 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" |
| 11 #include "base/path_service.h" |
| 12 #include "base/string16.h" |
| 13 #include "base/string_piece.h" |
| 14 #include "grit/webkit_resources.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 // Data resources on linux. This is a pointer to the mmapped resources file. |
| 19 base::DataPack* g_resource_data_pack = NULL; |
| 20 |
| 21 } |
| 22 |
7 namespace webkit_support { | 23 namespace webkit_support { |
8 | 24 |
9 // TODO(tkent): Implement some of the followings for platform-dependent tasks | 25 // TODO(tkent): Implement some of the followings for platform-dependent tasks |
10 // such as loading resource. | 26 // such as loading resource. |
11 | 27 |
12 void BeforeInitialize() { | 28 void BeforeInitialize() { |
13 } | 29 } |
14 | 30 |
15 void AfterInitialize() { | 31 void AfterInitialize() { |
| 32 g_resource_data_pack = new base::DataPack; |
| 33 FilePath data_path; |
| 34 PathService::Get(base::DIR_EXE, &data_path); |
| 35 data_path = data_path.Append("DumpRenderTree.pak"); |
| 36 if (!g_resource_data_pack->Load(data_path)) |
| 37 LOG(FATAL) << "failed to load DumpRenderTree.pak"; |
16 } | 38 } |
17 | 39 |
18 void BeforeShutdown() { | 40 void BeforeShutdown() { |
19 } | 41 } |
20 | 42 |
21 void AfterShutdown() { | 43 void AfterShutdown() { |
22 } | 44 } |
23 | 45 |
24 } // namespace webkit_support | 46 } // namespace webkit_support |
| 47 |
| 48 namespace webkit_glue { |
| 49 |
| 50 string16 GetLocalizedString(int message_id) { |
| 51 base::StringPiece res; |
| 52 if (!g_resource_data_pack->GetStringPiece(message_id, &res)) |
| 53 LOG(FATAL) << "failed to load webkit string with id " << message_id; |
| 54 |
| 55 return string16(reinterpret_cast<const char16*>(res.data()), |
| 56 res.length() / 2); |
| 57 } |
| 58 |
| 59 base::StringPiece GetDataResource(int resource_id) { |
| 60 FilePath resources_path; |
| 61 PathService::Get(base::DIR_EXE, &resources_path); |
| 62 resources_path = resources_path.Append("DumpRenderTree_resources"); |
| 63 switch (resource_id) { |
| 64 case IDR_BROKENIMAGE: { |
| 65 static std::string broken_image_data; |
| 66 if (broken_image_data.empty()) { |
| 67 FilePath path = resources_path.Append("missingImage.gif"); |
| 68 bool success = file_util::ReadFileToString(path, &broken_image_data); |
| 69 if (!success) |
| 70 LOG(FATAL) << "Failed reading: " << path.value(); |
| 71 } |
| 72 return broken_image_data; |
| 73 } |
| 74 case IDR_TEXTAREA_RESIZER: { |
| 75 static std::string resize_corner_data; |
| 76 if (resize_corner_data.empty()) { |
| 77 FilePath path = resources_path.Append("textAreaResizeCorner.png"); |
| 78 bool success = file_util::ReadFileToString(path, &resize_corner_data); |
| 79 if (!success) |
| 80 LOG(FATAL) << "Failed reading: " << path.value(); |
| 81 } |
| 82 return resize_corner_data; |
| 83 } |
| 84 } |
| 85 base::StringPiece res; |
| 86 g_resource_data_pack->GetStringPiece(resource_id, &res); |
| 87 return res; |
| 88 } |
| 89 |
| 90 } // namespace webkit_glue |
OLD | NEW |