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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 #import <objc/objc-runtime.h> | 9 #import <objc/objc-runtime.h> |
10 | 10 |
11 #include "base/data_pack.h" | 11 #include "base/data_pack.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac_util.h" | 14 #include "base/mac_util.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "grit/webkit_resources.h" | 17 #include "grit/webkit_resources.h" |
18 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" | 18 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" |
19 #import "webkit/tools/test_shell/mac/DumpRenderTreePasteboard.h" | 19 #import "webkit/tools/test_shell/mac/DumpRenderTreePasteboard.h" |
20 | 20 |
21 static base::DataPack* g_resource_data_pack = NULL; | 21 static base::DataPack* g_resource_data_pack = NULL; |
22 | 22 |
23 namespace webkit_support { | 23 namespace webkit_support { |
24 | 24 |
25 static NSAutoreleasePool* autorelease_pool; | 25 static NSAutoreleasePool* autorelease_pool; |
26 | 26 |
27 void BeforeInitialize() { | 27 void BeforeInitialize(bool unit_test_mode) { |
28 // Need to initialize NSAutoreleasePool before InitWebCoreSystemInterface(). | 28 // Need to initialize NSAutoreleasePool before InitWebCoreSystemInterface(). |
29 autorelease_pool = [[NSAutoreleasePool alloc] init]; | 29 autorelease_pool = [[NSAutoreleasePool alloc] init]; |
30 DCHECK(autorelease_pool); | 30 DCHECK(autorelease_pool); |
31 InitWebCoreSystemInterface(); | 31 InitWebCoreSystemInterface(); |
32 } | 32 } |
33 | 33 |
34 #if OBJC_API_VERSION == 2 | 34 #if OBJC_API_VERSION == 2 |
35 static void SwizzleAllMethods(Class imposter, Class original) { | 35 static void SwizzleAllMethods(Class imposter, Class original) { |
36 unsigned int imposterMethodCount = 0; | 36 unsigned int imposterMethodCount = 0; |
37 Method* imposterMethods = | 37 Method* imposterMethods = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 class_poseAs(imposterClass, originalClass); | 86 class_poseAs(imposterClass, originalClass); |
87 #else | 87 #else |
88 // Swizzle instance methods... | 88 // Swizzle instance methods... |
89 SwizzleAllMethods(imposterClass, originalClass); | 89 SwizzleAllMethods(imposterClass, originalClass); |
90 // and then class methods. | 90 // and then class methods. |
91 SwizzleAllMethods(object_getClass(imposterClass), | 91 SwizzleAllMethods(object_getClass(imposterClass), |
92 object_getClass(originalClass)); | 92 object_getClass(originalClass)); |
93 #endif | 93 #endif |
94 } | 94 } |
95 | 95 |
96 void AfterInitialize() { | 96 void AfterInitialize(bool unit_test_mode) { |
| 97 if (unit_test_mode) |
| 98 return; // We don't have a resource pack when running the unit-tests. |
| 99 |
97 // Load a data pack. | 100 // Load a data pack. |
98 g_resource_data_pack = new base::DataPack; | 101 g_resource_data_pack = new base::DataPack; |
99 NSString* resource_path = | 102 NSString* resource_path = |
100 [mac_util::MainAppBundle() pathForResource:@"DumpRenderTree" | 103 [mac_util::MainAppBundle() pathForResource:@"DumpRenderTree" |
101 ofType:@"pak"]; | 104 ofType:@"pak"]; |
102 FilePath resources_pak_path([resource_path fileSystemRepresentation]); | 105 FilePath resources_pak_path([resource_path fileSystemRepresentation]); |
103 if (!g_resource_data_pack->Load(resources_pak_path)) { | 106 if (!g_resource_data_pack->Load(resources_pak_path)) { |
104 LOG(FATAL) << "failed to load DumpRenderTree.pak"; | 107 LOG(FATAL) << "failed to load DumpRenderTree.pak"; |
105 } | 108 } |
106 | 109 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return res; | 223 return res; |
221 } | 224 } |
222 | 225 |
223 default: | 226 default: |
224 break; | 227 break; |
225 } | 228 } |
226 return base::StringPiece(); | 229 return base::StringPiece(); |
227 } | 230 } |
228 | 231 |
229 } // namespace webkit_glue | 232 } // namespace webkit_glue |
OLD | NEW |