1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
|
// 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 "webkit/support/test_webkit_platform_support.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/metrics/stats_counters.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "media/base/media.h"
#include "net/cookies/cookie_monster.h"
#include "net/http/http_cache.h"
#include "net/test/test_server.h"
#include "third_party/hyphen/hyphen.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebAudioDevice.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabase.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
#include "v8/include/v8.h"
#include "webkit/appcache/web_application_cache_host_impl.h"
#include "webkit/database/vfs_backend.h"
#include "webkit/glue/simple_webmimeregistry_impl.h"
#include "webkit/glue/webclipboard_impl.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webkitplatformsupport_impl.h"
#include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
#include "webkit/plugins/npapi/plugin_list.h"
#include "webkit/support/gc_extension.h"
#include "webkit/support/simple_database_system.h"
#include "webkit/support/test_webmessageportchannel.h"
#include "webkit/support/web_audio_device_mock.h"
#include "webkit/support/web_gesture_curve_mock.h"
#include "webkit/support/webkit_support.h"
#include "webkit/support/weburl_loader_mock_factory.h"
#include "webkit/tools/test_shell/mock_webclipboard_impl.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
#include "webkit/tools/test_shell/simple_socket_stream_bridge.h"
#include "webkit/tools/test_shell/simple_webcookiejar_impl.h"
#include "webkit/tools/test_shell/test_shell_request_context.h"
#include "webkit/tools/test_shell/test_shell_webblobregistry_impl.h"
#if defined(OS_WIN)
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/win/WebThemeEngine.h"
#include "webkit/tools/test_shell/test_shell_webthemeengine.h"
#elif defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#endif
using WebKit::WebScriptController;
TestWebKitPlatformSupport::TestWebKitPlatformSupport(bool unit_test_mode,
WebKit::Platform* shadow_platform_delegate)
: unit_test_mode_(unit_test_mode),
shadow_platform_delegate_(shadow_platform_delegate),
hyphen_dictionary_(NULL) {
v8::V8::SetCounterFunction(base::StatsTable::FindLocation);
WebKit::initialize(this);
WebKit::setLayoutTestMode(true);
WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(
WebKit::WebString::fromUTF8("test-shell-resource"));
WebKit::WebSecurityPolicy::registerURLSchemeAsNoAccess(
WebKit::WebString::fromUTF8("test-shell-resource"));
WebKit::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(
WebKit::WebString::fromUTF8("test-shell-resource"));
WebKit::WebSecurityPolicy::registerURLSchemeAsEmptyDocument(
WebKit::WebString::fromUTF8("test-shell-resource"));
WebScriptController::enableV8SingleThreadMode();
WebKit::WebRuntimeFeatures::enableSockets(true);
WebKit::WebRuntimeFeatures::enableApplicationCache(true);
WebKit::WebRuntimeFeatures::enableDatabase(true);
WebKit::WebRuntimeFeatures::enableDataTransferItems(true);
WebKit::WebRuntimeFeatures::enableNotifications(true);
WebKit::WebRuntimeFeatures::enableTouch(true);
WebKit::WebRuntimeFeatures::enableGamepad(true);
// Load libraries for media and enable the media player.
bool enable_media = false;
FilePath module_path;
if (PathService::Get(base::DIR_MODULE, &module_path)) {
#if defined(OS_MACOSX)
if (base::mac::AmIBundled())
module_path = module_path.DirName().DirName().DirName();
#endif
if (media::InitializeMediaLibrary(module_path))
enable_media = true;
}
WebKit::WebRuntimeFeatures::enableMediaPlayer(enable_media);
LOG_IF(WARNING, !enable_media) << "Failed to initialize the media library.\n";
// TODO(joth): Make a dummy geolocation service implemenation for
// test_shell, and set this to true. http://crbug.com/36451
WebKit::WebRuntimeFeatures::enableGeolocation(false);
// Construct and initialize an appcache system for this scope.
// A new empty temp directory is created to house any cached
// content during the run. Upon exit that directory is deleted.
// If we can't create a tempdir, we'll use in-memory storage.
if (!appcache_dir_.CreateUniqueTempDir()) {
LOG(WARNING) << "Failed to create a temp dir for the appcache, "
"using in-memory storage.";
DCHECK(appcache_dir_.path().empty());
}
SimpleAppCacheSystem::InitializeOnUIThread(appcache_dir_.path());
WebKit::WebDatabase::setObserver(&database_system_);
blob_registry_ = new TestShellWebBlobRegistryImpl();
file_utilities_.set_sandbox_enabled(false);
if (!file_system_root_.CreateUniqueTempDir()) {
LOG(WARNING) << "Failed to create a temp dir for the filesystem."
"FileSystem feature will be disabled.";
DCHECK(file_system_root_.path().empty());
}
#if defined(OS_WIN)
// Ensure we pick up the default theme engine.
SetThemeEngine(NULL);
#endif
net::HttpCache::Mode cache_mode = net::HttpCache::NORMAL;
net::CookieMonster::EnableFileScheme();
// Initializing with a default context, which means no on-disk cookie DB,
// and no support for directory listings.
SimpleResourceLoaderBridge::Init(FilePath(), cache_mode, true);
// Test shell always exposes the GC.
webkit_glue::SetJavaScriptFlags(" --expose-gc");
// Expose GCController to JavaScript.
WebScriptController::registerExtension(extensions_v8::GCExtension::Get());
}
TestWebKitPlatformSupport::~TestWebKitPlatformSupport() {
if (hyphen_dictionary_)
hnj_hyphen_free(hyphen_dictionary_);
}
WebKit::WebMimeRegistry* TestWebKitPlatformSupport::mimeRegistry() {
return &mime_registry_;
}
WebKit::WebClipboard* TestWebKitPlatformSupport::clipboard() {
// Mock out clipboard calls so that tests don't mess
// with each other's copies/pastes when running in parallel.
return &mock_clipboard_;
}
WebKit::WebFileUtilities* TestWebKitPlatformSupport::fileUtilities() {
return &file_utilities_;
}
WebKit::WebSandboxSupport* TestWebKitPlatformSupport::sandboxSupport() {
return NULL;
}
WebKit::WebCookieJar* TestWebKitPlatformSupport::cookieJar() {
return &cookie_jar_;
}
WebKit::WebBlobRegistry* TestWebKitPlatformSupport::blobRegistry() {
return blob_registry_.get();
}
WebKit::WebFileSystem* TestWebKitPlatformSupport::fileSystem() {
return &file_system_;
}
bool TestWebKitPlatformSupport::sandboxEnabled() {
return true;
}
WebKit::WebKitPlatformSupport::FileHandle
TestWebKitPlatformSupport::databaseOpenFile(
const WebKit::WebString& vfs_file_name, int desired_flags) {
return SimpleDatabaseSystem::GetInstance()->OpenFile(
vfs_file_name, desired_flags);
}
int TestWebKitPlatformSupport::databaseDeleteFile(
const WebKit::WebString& vfs_file_name, bool sync_dir) {
return SimpleDatabaseSystem::GetInstance()->DeleteFile(
vfs_file_name, sync_dir);
}
long TestWebKitPlatformSupport::databaseGetFileAttributes(
const WebKit::WebString& vfs_file_name) {
return SimpleDatabaseSystem::GetInstance()->GetFileAttributes(
vfs_file_name);
}
long long TestWebKitPlatformSupport::databaseGetFileSize(
const WebKit::WebString& vfs_file_name) {
return SimpleDatabaseSystem::GetInstance()->GetFileSize(vfs_file_name);
}
long long TestWebKitPlatformSupport::databaseGetSpaceAvailableForOrigin(
const WebKit::WebString& origin_identifier) {
return SimpleDatabaseSystem::GetInstance()->GetSpaceAvailable(
origin_identifier);
}
unsigned long long TestWebKitPlatformSupport::visitedLinkHash(
const char* canonicalURL, size_t length) {
return 0;
}
bool TestWebKitPlatformSupport::isLinkVisited(unsigned long long linkHash) {
return false;
}
WebKit::WebMessagePortChannel*
TestWebKitPlatformSupport::createMessagePortChannel() {
return new TestWebMessagePortChannel();
}
void TestWebKitPlatformSupport::prefetchHostName(const WebKit::WebString&) {
}
WebKit::WebURLLoader* TestWebKitPlatformSupport::createURLLoader() {
if (!unit_test_mode_)
return webkit_glue::WebKitPlatformSupportImpl::createURLLoader();
return url_loader_factory_.CreateURLLoader(
webkit_glue::WebKitPlatformSupportImpl::createURLLoader());
}
WebKit::WebData TestWebKitPlatformSupport::loadResource(const char* name) {
if (!strcmp(name, "deleteButton")) {
// Create a red 30x30 square.
const char red_square[] =
"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52"
"\x00\x00\x00\x1e\x00\x00\x00\x1e\x04\x03\x00\x00\x00\xc9\x1e\xb3"
"\x91\x00\x00\x00\x30\x50\x4c\x54\x45\x00\x00\x00\x80\x00\x00\x00"
"\x80\x00\x80\x80\x00\x00\x00\x80\x80\x00\x80\x00\x80\x80\x80\x80"
"\x80\xc0\xc0\xc0\xff\x00\x00\x00\xff\x00\xff\xff\x00\x00\x00\xff"
"\xff\x00\xff\x00\xff\xff\xff\xff\xff\x7b\x1f\xb1\xc4\x00\x00\x00"
"\x09\x70\x48\x59\x73\x00\x00\x0b\x13\x00\x00\x0b\x13\x01\x00\x9a"
"\x9c\x18\x00\x00\x00\x17\x49\x44\x41\x54\x78\x01\x63\x98\x89\x0a"
"\x18\x50\xb9\x33\x47\xf9\xa8\x01\x32\xd4\xc2\x03\x00\x33\x84\x0d"
"\x02\x3a\x91\xeb\xa5\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60"
"\x82";
return WebKit::WebData(red_square, arraysize(red_square));
}
return webkit_glue::WebKitPlatformSupportImpl::loadResource(name);
}
WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString(
WebKit::WebLocalizedString::Name name) {
// Returns messages same as WebKit's in DRT.
// We use different strings for form validation messages and page popup UI
// strings.
switch (name) {
case WebKit::WebLocalizedString::ValidationValueMissing:
case WebKit::WebLocalizedString::ValidationValueMissingForCheckbox:
case WebKit::WebLocalizedString::ValidationValueMissingForFile:
case WebKit::WebLocalizedString::ValidationValueMissingForMultipleFile:
case WebKit::WebLocalizedString::ValidationValueMissingForRadio:
case WebKit::WebLocalizedString::ValidationValueMissingForSelect:
return ASCIIToUTF16("value missing");
case WebKit::WebLocalizedString::ValidationTypeMismatch:
case WebKit::WebLocalizedString::ValidationTypeMismatchForEmail:
case WebKit::WebLocalizedString::ValidationTypeMismatchForMultipleEmail:
case WebKit::WebLocalizedString::ValidationTypeMismatchForURL:
return ASCIIToUTF16("type mismatch");
case WebKit::WebLocalizedString::ValidationPatternMismatch:
return ASCIIToUTF16("pattern mismatch");
case WebKit::WebLocalizedString::ValidationTooLong:
return ASCIIToUTF16("too long");
case WebKit::WebLocalizedString::ValidationRangeUnderflow:
return ASCIIToUTF16("range underflow");
case WebKit::WebLocalizedString::ValidationRangeOverflow:
return ASCIIToUTF16("range overflow");
case WebKit::WebLocalizedString::ValidationStepMismatch:
return ASCIIToUTF16("step mismatch");
case WebKit::WebLocalizedString::OtherDateLabel:
return ASCIIToUTF16("<<OtherDateLabel>>");
case WebKit::WebLocalizedString::OtherMonthLabel:
return ASCIIToUTF16("<<OtherMonthLabel>>");
case WebKit::WebLocalizedString::OtherTimeLabel:
return ASCIIToUTF16("<<OtherTimeLabel>>");
case WebKit::WebLocalizedString::OtherWeekLabel:
return ASCIIToUTF16("<<OtherWeekLabel>>");
case WebKit::WebLocalizedString::CalendarClear:
return ASCIIToUTF16("<<CalendarClear>>");
case WebKit::WebLocalizedString::CalendarToday:
return ASCIIToUTF16("<<CalendarToday>>");
case WebKit::WebLocalizedString::ThisMonthButtonLabel:
return ASCIIToUTF16("<<ThisMonthLabel>>");
case WebKit::WebLocalizedString::ThisWeekButtonLabel:
return ASCIIToUTF16("<<ThisWeekLabel>>");
default:
return WebKitPlatformSupportImpl::queryLocalizedString(name);
}
}
WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString(
WebKit::WebLocalizedString::Name name, const WebKit::WebString& value) {
if (name == WebKit::WebLocalizedString::ValidationRangeUnderflow)
return ASCIIToUTF16("range underflow");
if (name == WebKit::WebLocalizedString::ValidationRangeOverflow)
return ASCIIToUTF16("range overflow");
return WebKitPlatformSupportImpl::queryLocalizedString(name, value);
}
WebKit::WebString TestWebKitPlatformSupport::queryLocalizedString(
WebKit::WebLocalizedString::Name name,
const WebKit::WebString& value1,
const WebKit::WebString& value2) {
if (name == WebKit::WebLocalizedString::ValidationTooLong)
return ASCIIToUTF16("too long");
if (name == WebKit::WebLocalizedString::ValidationStepMismatch)
return ASCIIToUTF16("step mismatch");
return WebKitPlatformSupportImpl::queryLocalizedString(name, value1, value2);
}
WebKit::WebString TestWebKitPlatformSupport::defaultLocale() {
return ASCIIToUTF16("en-US");
}
WebKit::WebStorageNamespace*
TestWebKitPlatformSupport::createLocalStorageNamespace(
const WebKit::WebString& path, unsigned quota) {
return dom_storage_system_.CreateLocalStorageNamespace();
}
// Wrap a WebKit::WebIDBFactory to rewrite the data directory to
// a scoped temp directory. In multiprocess Chromium this is rewritten
// to a real profile directory during IPC.
class TestWebIDBFactory : public WebKit::WebIDBFactory {
public:
TestWebIDBFactory()
: factory_(WebKit::WebIDBFactory::create()) {
// Create a new temp directory for Indexed DB storage, specific to this
// factory. If this fails, WebKit uses in-memory storage.
if (!indexed_db_dir_.CreateUniqueTempDir()) {
LOG(WARNING) << "Failed to create a temp dir for Indexed DB, "
"using in-memory storage.";
DCHECK(indexed_db_dir_.path().empty());
}
data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path(
indexed_db_dir_.path().AsUTF8Unsafe());
}
virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks,
const WebKit::WebSecurityOrigin& origin,
WebKit::WebFrame* frame,
const WebString& dataDir) {
factory_->getDatabaseNames(callbacks, origin, frame,
dataDir.isEmpty() ? data_dir_ : dataDir);
}
virtual void open(const WebString& name,
long long version,
WebKit::WebIDBCallbacks* callbacks,
WebKit::WebIDBDatabaseCallbacks* databaseCallbacks,
const WebKit::WebSecurityOrigin& origin,
WebKit::WebFrame* frame,
const WebString& dataDir) {
factory_->open(name, version, callbacks, databaseCallbacks, origin, frame,
dataDir.isEmpty() ? data_dir_ : dataDir);
}
virtual void open(const WebString& name,
long long version,
long long transaction_id,
WebKit::WebIDBCallbacks* callbacks,
WebKit::WebIDBDatabaseCallbacks* databaseCallbacks,
const WebKit::WebSecurityOrigin& origin,
WebKit::WebFrame* frame,
const WebString& dataDir) {
factory_->open(name, version, transaction_id, callbacks,
databaseCallbacks, origin, frame,
dataDir.isEmpty() ? data_dir_ : dataDir);
}
virtual void deleteDatabase(const WebString& name,
WebKit::WebIDBCallbacks* callbacks,
const WebKit::WebSecurityOrigin& origin,
WebKit::WebFrame* frame,
const WebString& dataDir) {
factory_->deleteDatabase(name, callbacks, origin, frame,
dataDir.isEmpty() ? data_dir_ : dataDir);
}
private:
scoped_ptr<WebIDBFactory> factory_;
base::ScopedTempDir indexed_db_dir_;
WebString data_dir_;
};
WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() {
return new TestWebIDBFactory();
}
#if defined(OS_WIN) || defined(OS_MACOSX)
void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) {
active_theme_engine_ = engine ?
engine : WebKitPlatformSupportImpl::themeEngine();
}
WebKit::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() {
return active_theme_engine_;
}
#endif
WebKit::WebGraphicsContext3D*
TestWebKitPlatformSupport::createOffscreenGraphicsContext3D(
const WebKit::WebGraphicsContext3D::Attributes& attributes) {
switch (webkit_support::GetGraphicsContext3DImplementation()) {
case webkit_support::IN_PROCESS:
return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
attributes, false);
case webkit_support::IN_PROCESS_COMMAND_BUFFER: {
scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl>
context(new
webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl());
if (!context->Initialize(attributes, NULL))
return NULL;
return context.release();
}
}
NOTREACHED();
return NULL;
}
bool TestWebKitPlatformSupport::canAccelerate2dCanvas() {
// We supply an OS-MESA based context for accelarated 2d
// canvas, which should always work.
return true;
}
double TestWebKitPlatformSupport::audioHardwareSampleRate() {
return 44100.0;
}
size_t TestWebKitPlatformSupport::audioHardwareBufferSize() {
return 128;
}
WebKit::WebAudioDevice* TestWebKitPlatformSupport::createAudioDevice(
size_t bufferSize, unsigned numberOfChannels, double sampleRate,
WebKit::WebAudioDevice::RenderCallback*) {
return new WebAudioDeviceMock(sampleRate);
}
void TestWebKitPlatformSupport::sampleGamepads(WebKit::WebGamepads& data) {
data = gamepad_data_;
}
void TestWebKitPlatformSupport::setGamepadData(
const WebKit::WebGamepads& data) {
gamepad_data_ = data;
}
void TestWebKitPlatformSupport::GetPlugins(
bool refresh, std::vector<webkit::WebPluginInfo>* plugins) {
if (refresh)
webkit::npapi::PluginList::Singleton()->RefreshPlugins();
webkit::npapi::PluginList::Singleton()->GetPlugins(plugins);
// Don't load the forked npapi_layout_test_plugin in DRT, we only want to
// use the upstream version TestNetscapePlugIn.
const FilePath::StringType kPluginBlackList[] = {
FILE_PATH_LITERAL("npapi_layout_test_plugin.dll"),
FILE_PATH_LITERAL("WebKitTestNetscapePlugIn.plugin"),
FILE_PATH_LITERAL("libnpapi_layout_test_plugin.so"),
};
for (int i = plugins->size() - 1; i >= 0; --i) {
webkit::WebPluginInfo plugin_info = plugins->at(i);
for (size_t j = 0; j < arraysize(kPluginBlackList); ++j) {
if (plugin_info.path.BaseName() == FilePath(kPluginBlackList[j])) {
plugins->erase(plugins->begin() + i);
}
}
}
}
webkit_glue::ResourceLoaderBridge*
TestWebKitPlatformSupport::CreateResourceLoader(
const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
return SimpleResourceLoaderBridge::Create(request_info);
}
webkit_glue::WebSocketStreamHandleBridge*
TestWebKitPlatformSupport::CreateWebSocketBridge(
WebKit::WebSocketStreamHandle* handle,
webkit_glue::WebSocketStreamHandleDelegate* delegate) {
return SimpleSocketStreamBridge::Create(handle, delegate);
}
WebKit::WebMediaStreamCenter*
TestWebKitPlatformSupport::createMediaStreamCenter(
WebKit::WebMediaStreamCenterClient* client) {
if (shadow_platform_delegate_)
return shadow_platform_delegate_->createMediaStreamCenter(client);
return webkit_glue::WebKitPlatformSupportImpl::createMediaStreamCenter(
client);
}
WebKit::WebRTCPeerConnectionHandler*
TestWebKitPlatformSupport::createRTCPeerConnectionHandler(
WebKit::WebRTCPeerConnectionHandlerClient* client) {
if (shadow_platform_delegate_)
return shadow_platform_delegate_->createRTCPeerConnectionHandler(client);
return webkit_glue::WebKitPlatformSupportImpl::createRTCPeerConnectionHandler(
client);
}
bool TestWebKitPlatformSupport::canHyphenate(const WebKit::WebString& locale) {
return locale.isEmpty() || locale.equals("en") || locale.equals("en_US") ||
locale.equals("en_GB");
}
size_t TestWebKitPlatformSupport::computeLastHyphenLocation(
const char16* characters,
size_t length,
size_t before_index,
const WebKit::WebString& locale) {
DCHECK(locale.isEmpty() || locale.equals("en") || locale.equals("en_US") ||
locale.equals("en_GB"));
if (!hyphen_dictionary_) {
// Initialize the hyphen library with a sample dictionary. To avoid test
// flakiness, this code synchronously loads the dictionary.
FilePath path;
if (!PathService::Get(base::DIR_SOURCE_ROOT, &path))
return 0;
path = path.AppendASCII("third_party");
path = path.AppendASCII("hyphen");
path = path.AppendASCII("hyph_en_US.dic");
std::string dictionary;
if (!file_util::ReadFileToString(path, &dictionary))
return 0;
hyphen_dictionary_ = hnj_hyphen_load(
reinterpret_cast<const unsigned char*>(dictionary.data()),
dictionary.length());
if (!hyphen_dictionary_)
return 0;
}
// Retrieve the positions where we can insert hyphens. This function assumes
// the input word is an English word so it can use the position returned by
// the hyphen library without conversion.
string16 word_utf16(characters, length);
if (!IsStringASCII(word_utf16))
return 0;
std::string word = StringToLowerASCII(UTF16ToASCII(word_utf16));
scoped_array<char> hyphens(new char[word.length() + 5]);
char** rep = NULL;
int* pos = NULL;
int* cut = NULL;
int error = hnj_hyphen_hyphenate2(hyphen_dictionary_,
word.data(),
static_cast<int>(word.length()),
hyphens.get(),
NULL,
&rep,
&pos,
&cut);
if (error)
return 0;
// Release all resources allocated by the hyphen library now because they are
// not used when hyphenating English words.
if (rep) {
for (size_t i = 0; i < word.length(); ++i) {
if (rep[i])
free(rep[i]);
}
free(rep);
}
if (pos)
free(pos);
if (cut)
free(cut);
// Retrieve the last position where we can insert a hyphen before the given
// index.
if (before_index >= 2) {
for (size_t index = before_index - 2; index > 0; --index) {
if (hyphens[index] & 1)
return index + 1;
}
}
return 0;
}
WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve(
int device_source,
const WebKit::WebFloatPoint& velocity,
const WebKit::WebSize& cumulative_scroll) {
// Caller will retain and release.
return new WebGestureCurveMock(velocity, cumulative_scroll);
}
|