OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/blink_platform_impl.h" | 5 #include "webkit/child/webkitplatformsupport_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/allocator/allocator_extension.h" | 11 #include "base/allocator/allocator_extension.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
19 #include "base/metrics/stats_counters.h" | 19 #include "base/metrics/stats_counters.h" |
20 #include "base/platform_file.h" | 20 #include "base/platform_file.h" |
21 #include "base/process/process_metrics.h" | 21 #include "base/process/process_metrics.h" |
22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
26 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
27 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
29 #include "content/child/web_socket_stream_handle_impl.h" | |
30 #include "content/child/web_url_loader_impl.h" | |
31 #include "grit/blink_resources.h" | 29 #include "grit/blink_resources.h" |
32 #include "grit/webkit_resources.h" | 30 #include "grit/webkit_resources.h" |
33 #include "grit/webkit_strings.h" | 31 #include "grit/webkit_strings.h" |
34 #include "net/base/data_url.h" | 32 #include "net/base/data_url.h" |
35 #include "net/base/mime_util.h" | 33 #include "net/base/mime_util.h" |
36 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
37 #include "third_party/WebKit/public/platform/WebData.h" | 35 #include "third_party/WebKit/public/platform/WebData.h" |
38 #include "third_party/WebKit/public/platform/WebString.h" | 36 #include "third_party/WebKit/public/platform/WebString.h" |
39 #include "ui/base/layout.h" | 37 #include "ui/base/layout.h" |
40 #include "webkit/child/webkit_child_helpers.h" | 38 #include "webkit/child/webkit_child_helpers.h" |
| 39 #include "webkit/child/websocketstreamhandle_impl.h" |
| 40 #include "webkit/child/weburlloader_impl.h" |
41 #include "webkit/common/user_agent/user_agent.h" | 41 #include "webkit/common/user_agent/user_agent.h" |
42 | 42 |
43 #if defined(OS_ANDROID) | 43 #if defined(OS_ANDROID) |
44 #include "base/android/sys_utils.h" | 44 #include "base/android/sys_utils.h" |
45 #endif | 45 #endif |
46 | 46 |
47 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | 47 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) |
48 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | 48 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
49 #endif | 49 #endif |
50 | 50 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 // How long the cached value should remain valid. | 100 // How long the cached value should remain valid. |
101 base::TimeDelta cache_valid_time_; | 101 base::TimeDelta cache_valid_time_; |
102 | 102 |
103 // The last time the cached value was updated. | 103 // The last time the cached value was updated. |
104 base::Time last_updated_time_; | 104 base::Time last_updated_time_; |
105 | 105 |
106 base::Lock lock_; | 106 base::Lock lock_; |
107 }; | 107 }; |
108 | 108 |
109 } // namespace | 109 } // anonymous namespace |
110 | 110 |
111 namespace content { | 111 namespace webkit_glue { |
112 | 112 |
113 static int ToMessageID(WebLocalizedString::Name name) { | 113 static int ToMessageID(WebLocalizedString::Name name) { |
114 switch (name) { | 114 switch (name) { |
115 case WebLocalizedString::AXAMPMFieldText: | 115 case WebLocalizedString::AXAMPMFieldText: |
116 return IDS_AX_AM_PM_FIELD_TEXT; | 116 return IDS_AX_AM_PM_FIELD_TEXT; |
117 case WebLocalizedString::AXButtonActionVerb: | 117 case WebLocalizedString::AXButtonActionVerb: |
118 return IDS_AX_BUTTON_ACTION_VERB; | 118 return IDS_AX_BUTTON_ACTION_VERB; |
119 case WebLocalizedString::AXCheckedCheckBoxActionVerb: | 119 case WebLocalizedString::AXCheckedCheckBoxActionVerb: |
120 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB; | 120 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB; |
121 case WebLocalizedString::AXDateTimeFieldEmptyValueText: | 121 case WebLocalizedString::AXDateTimeFieldEmptyValueText: |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // This "default:" line exists to avoid compile warnings about enum | 337 // This "default:" line exists to avoid compile warnings about enum |
338 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. | 338 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. |
339 // After a planned WebKit patch is landed, we need to add a case statement | 339 // After a planned WebKit patch is landed, we need to add a case statement |
340 // for the added symbol here. | 340 // for the added symbol here. |
341 default: | 341 default: |
342 break; | 342 break; |
343 } | 343 } |
344 return -1; | 344 return -1; |
345 } | 345 } |
346 | 346 |
347 BlinkPlatformImpl::BlinkPlatformImpl() | 347 WebKitPlatformSupportImpl::WebKitPlatformSupportImpl() |
348 : main_loop_(base::MessageLoop::current()), | 348 : main_loop_(base::MessageLoop::current()), |
349 shared_timer_func_(NULL), | 349 shared_timer_func_(NULL), |
350 shared_timer_fire_time_(0.0), | 350 shared_timer_fire_time_(0.0), |
351 shared_timer_fire_time_was_set_while_suspended_(false), | 351 shared_timer_fire_time_was_set_while_suspended_(false), |
352 shared_timer_suspended_(0) {} | 352 shared_timer_suspended_(0) {} |
353 | 353 |
354 BlinkPlatformImpl::~BlinkPlatformImpl() { | 354 WebKitPlatformSupportImpl::~WebKitPlatformSupportImpl() { |
355 } | 355 } |
356 | 356 |
357 WebURLLoader* BlinkPlatformImpl::createURLLoader() { | 357 WebURLLoader* WebKitPlatformSupportImpl::createURLLoader() { |
358 return new WebURLLoaderImpl(this); | 358 return new WebURLLoaderImpl(this); |
359 } | 359 } |
360 | 360 |
361 WebSocketStreamHandle* BlinkPlatformImpl::createSocketStreamHandle() { | 361 WebSocketStreamHandle* WebKitPlatformSupportImpl::createSocketStreamHandle() { |
362 return new WebSocketStreamHandleImpl(this); | 362 return new WebSocketStreamHandleImpl(this); |
363 } | 363 } |
364 | 364 |
365 WebString BlinkPlatformImpl::userAgent(const WebURL& url) { | 365 WebString WebKitPlatformSupportImpl::userAgent(const WebURL& url) { |
366 return WebString::fromUTF8(webkit_glue::GetUserAgent(url)); | 366 return WebString::fromUTF8(webkit_glue::GetUserAgent(url)); |
367 } | 367 } |
368 | 368 |
369 WebData BlinkPlatformImpl::parseDataURL( | 369 WebData WebKitPlatformSupportImpl::parseDataURL( |
370 const WebURL& url, | 370 const WebURL& url, |
371 WebString& mimetype_out, | 371 WebString& mimetype_out, |
372 WebString& charset_out) { | 372 WebString& charset_out) { |
373 std::string mime_type, char_set, data; | 373 std::string mime_type, char_set, data; |
374 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) | 374 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) |
375 && net::IsSupportedMimeType(mime_type)) { | 375 && net::IsSupportedMimeType(mime_type)) { |
376 mimetype_out = WebString::fromUTF8(mime_type); | 376 mimetype_out = WebString::fromUTF8(mime_type); |
377 charset_out = WebString::fromUTF8(char_set); | 377 charset_out = WebString::fromUTF8(char_set); |
378 return data; | 378 return data; |
379 } | 379 } |
380 return WebData(); | 380 return WebData(); |
381 } | 381 } |
382 | 382 |
383 WebURLError BlinkPlatformImpl::cancelledError( | 383 WebURLError WebKitPlatformSupportImpl::cancelledError( |
384 const WebURL& unreachableURL) const { | 384 const WebURL& unreachableURL) const { |
385 return WebURLLoaderImpl::CreateError(unreachableURL, false, net::ERR_ABORTED); | 385 return WebURLLoaderImpl::CreateError(unreachableURL, false, net::ERR_ABORTED); |
386 } | 386 } |
387 | 387 |
388 void BlinkPlatformImpl::decrementStatsCounter(const char* name) { | 388 void WebKitPlatformSupportImpl::decrementStatsCounter(const char* name) { |
389 base::StatsCounter(name).Decrement(); | 389 base::StatsCounter(name).Decrement(); |
390 } | 390 } |
391 | 391 |
392 void BlinkPlatformImpl::incrementStatsCounter(const char* name) { | 392 void WebKitPlatformSupportImpl::incrementStatsCounter(const char* name) { |
393 base::StatsCounter(name).Increment(); | 393 base::StatsCounter(name).Increment(); |
394 } | 394 } |
395 | 395 |
396 void BlinkPlatformImpl::histogramCustomCounts( | 396 void WebKitPlatformSupportImpl::histogramCustomCounts( |
397 const char* name, int sample, int min, int max, int bucket_count) { | 397 const char* name, int sample, int min, int max, int bucket_count) { |
398 // Copied from histogram macro, but without the static variable caching | 398 // Copied from histogram macro, but without the static variable caching |
399 // the histogram because name is dynamic. | 399 // the histogram because name is dynamic. |
400 base::HistogramBase* counter = | 400 base::HistogramBase* counter = |
401 base::Histogram::FactoryGet(name, min, max, bucket_count, | 401 base::Histogram::FactoryGet(name, min, max, bucket_count, |
402 base::HistogramBase::kUmaTargetedHistogramFlag); | 402 base::HistogramBase::kUmaTargetedHistogramFlag); |
403 DCHECK_EQ(name, counter->histogram_name()); | 403 DCHECK_EQ(name, counter->histogram_name()); |
404 counter->Add(sample); | 404 counter->Add(sample); |
405 } | 405 } |
406 | 406 |
407 void BlinkPlatformImpl::histogramEnumeration( | 407 void WebKitPlatformSupportImpl::histogramEnumeration( |
408 const char* name, int sample, int boundary_value) { | 408 const char* name, int sample, int boundary_value) { |
409 // Copied from histogram macro, but without the static variable caching | 409 // Copied from histogram macro, but without the static variable caching |
410 // the histogram because name is dynamic. | 410 // the histogram because name is dynamic. |
411 base::HistogramBase* counter = | 411 base::HistogramBase* counter = |
412 base::LinearHistogram::FactoryGet(name, 1, boundary_value, | 412 base::LinearHistogram::FactoryGet(name, 1, boundary_value, |
413 boundary_value + 1, base::HistogramBase::kUmaTargetedHistogramFlag); | 413 boundary_value + 1, base::HistogramBase::kUmaTargetedHistogramFlag); |
414 DCHECK_EQ(name, counter->histogram_name()); | 414 DCHECK_EQ(name, counter->histogram_name()); |
415 counter->Add(sample); | 415 counter->Add(sample); |
416 } | 416 } |
417 | 417 |
418 void BlinkPlatformImpl::histogramSparse(const char* name, int sample) { | 418 void WebKitPlatformSupportImpl::histogramSparse(const char* name, int sample) { |
419 // For sparse histograms, we can use the macro, as it does not incorporate a | 419 // For sparse histograms, we can use the macro, as it does not incorporate a |
420 // static. | 420 // static. |
421 UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample); | 421 UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample); |
422 } | 422 } |
423 | 423 |
424 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag( | 424 const unsigned char* WebKitPlatformSupportImpl::getTraceCategoryEnabledFlag( |
425 const char* category_group) { | 425 const char* category_group) { |
426 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); | 426 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); |
427 } | 427 } |
428 | 428 |
429 long* BlinkPlatformImpl::getTraceSamplingState( | 429 long* WebKitPlatformSupportImpl::getTraceSamplingState( |
430 const unsigned thread_bucket) { | 430 const unsigned thread_bucket) { |
431 switch (thread_bucket) { | 431 switch (thread_bucket) { |
432 case 0: | 432 case 0: |
433 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); | 433 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); |
434 case 1: | 434 case 1: |
435 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(1)); | 435 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(1)); |
436 case 2: | 436 case 2: |
437 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(2)); | 437 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(2)); |
438 default: | 438 default: |
439 NOTREACHED() << "Unknown thread bucket type."; | 439 NOTREACHED() << "Unknown thread bucket type."; |
440 } | 440 } |
441 return NULL; | 441 return NULL; |
442 } | 442 } |
443 | 443 |
444 COMPILE_ASSERT( | 444 COMPILE_ASSERT( |
445 sizeof(blink::Platform::TraceEventHandle) == | 445 sizeof(blink::Platform::TraceEventHandle) == |
446 sizeof(base::debug::TraceEventHandle), | 446 sizeof(base::debug::TraceEventHandle), |
447 TraceEventHandle_types_must_be_same_size); | 447 TraceEventHandle_types_must_be_same_size); |
448 | 448 |
449 blink::Platform::TraceEventHandle BlinkPlatformImpl::addTraceEvent( | 449 blink::Platform::TraceEventHandle WebKitPlatformSupportImpl::addTraceEvent( |
450 char phase, | 450 char phase, |
451 const unsigned char* category_group_enabled, | 451 const unsigned char* category_group_enabled, |
452 const char* name, | 452 const char* name, |
453 unsigned long long id, | 453 unsigned long long id, |
454 int num_args, | 454 int num_args, |
455 const char** arg_names, | 455 const char** arg_names, |
456 const unsigned char* arg_types, | 456 const unsigned char* arg_types, |
457 const unsigned long long* arg_values, | 457 const unsigned long long* arg_values, |
458 unsigned char flags) { | 458 unsigned char flags) { |
459 base::debug::TraceEventHandle handle = TRACE_EVENT_API_ADD_TRACE_EVENT( | 459 base::debug::TraceEventHandle handle = TRACE_EVENT_API_ADD_TRACE_EVENT( |
460 phase, category_group_enabled, name, id, | 460 phase, category_group_enabled, name, id, |
461 num_args, arg_names, arg_types, arg_values, NULL, flags); | 461 num_args, arg_names, arg_types, arg_values, NULL, flags); |
462 blink::Platform::TraceEventHandle result; | 462 blink::Platform::TraceEventHandle result; |
463 memcpy(&result, &handle, sizeof(result)); | 463 memcpy(&result, &handle, sizeof(result)); |
464 return result; | 464 return result; |
465 } | 465 } |
466 | 466 |
467 void BlinkPlatformImpl::updateTraceEventDuration( | 467 void WebKitPlatformSupportImpl::updateTraceEventDuration( |
468 const unsigned char* category_group_enabled, | 468 const unsigned char* category_group_enabled, |
469 const char* name, | 469 const char* name, |
470 TraceEventHandle handle) { | 470 TraceEventHandle handle) { |
471 base::debug::TraceEventHandle traceEventHandle; | 471 base::debug::TraceEventHandle traceEventHandle; |
472 memcpy(&traceEventHandle, &handle, sizeof(handle)); | 472 memcpy(&traceEventHandle, &handle, sizeof(handle)); |
473 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 473 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
474 category_group_enabled, name, traceEventHandle); | 474 category_group_enabled, name, traceEventHandle); |
475 } | 475 } |
476 | 476 |
477 namespace { | 477 namespace { |
478 | 478 |
479 WebData loadAudioSpatializationResource(BlinkPlatformImpl* platform, | 479 WebData loadAudioSpatializationResource(WebKitPlatformSupportImpl* platform, |
480 const char* name) { | 480 const char* name) { |
481 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE | 481 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE |
482 if (!strcmp(name, "Composite")) { | 482 if (!strcmp(name, "Composite")) { |
483 base::StringPiece resource = | 483 base::StringPiece resource = |
484 platform->GetDataResource(IDR_AUDIO_SPATIALIZATION_COMPOSITE, | 484 platform->GetDataResource(IDR_AUDIO_SPATIALIZATION_COMPOSITE, |
485 ui::SCALE_FACTOR_NONE); | 485 ui::SCALE_FACTOR_NONE); |
486 return WebData(resource.data(), resource.size()); | 486 return WebData(resource.data(), resource.size()); |
487 } | 487 } |
488 #endif | 488 #endif |
489 | 489 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 { "visaCC", IDR_AUTOFILL_CC_VISA, ui::SCALE_FACTOR_100P }, | 641 { "visaCC", IDR_AUTOFILL_CC_VISA, ui::SCALE_FACTOR_100P }, |
642 { "generatePassword", IDR_PASSWORD_GENERATION_ICON, ui::SCALE_FACTOR_100P }, | 642 { "generatePassword", IDR_PASSWORD_GENERATION_ICON, ui::SCALE_FACTOR_100P }, |
643 { "generatePasswordHover", | 643 { "generatePasswordHover", |
644 IDR_PASSWORD_GENERATION_ICON_HOVER, ui::SCALE_FACTOR_100P }, | 644 IDR_PASSWORD_GENERATION_ICON_HOVER, ui::SCALE_FACTOR_100P }, |
645 { "syntheticTouchCursor", | 645 { "syntheticTouchCursor", |
646 IDR_SYNTHETIC_TOUCH_CURSOR, ui::SCALE_FACTOR_100P }, | 646 IDR_SYNTHETIC_TOUCH_CURSOR, ui::SCALE_FACTOR_100P }, |
647 }; | 647 }; |
648 | 648 |
649 } // namespace | 649 } // namespace |
650 | 650 |
651 WebData BlinkPlatformImpl::loadResource(const char* name) { | 651 WebData WebKitPlatformSupportImpl::loadResource(const char* name) { |
652 // Some clients will call into this method with an empty |name| when they have | 652 // Some clients will call into this method with an empty |name| when they have |
653 // optional resources. For example, the PopupMenuChromium code can have icons | 653 // optional resources. For example, the PopupMenuChromium code can have icons |
654 // for some Autofill items but not for others. | 654 // for some Autofill items but not for others. |
655 if (!strlen(name)) | 655 if (!strlen(name)) |
656 return WebData(); | 656 return WebData(); |
657 | 657 |
658 // Check the name prefix to see if it's an audio resource. | 658 // Check the name prefix to see if it's an audio resource. |
659 if (StartsWithASCII(name, "IRC_Composite", true) || | 659 if (StartsWithASCII(name, "IRC_Composite", true) || |
660 StartsWithASCII(name, "Composite", true)) | 660 StartsWithASCII(name, "Composite", true)) |
661 return loadAudioSpatializationResource(this, name); | 661 return loadAudioSpatializationResource(this, name); |
662 | 662 |
663 // TODO(flackr): We should use a better than linear search here, a trie would | 663 // TODO(flackr): We should use a better than linear search here, a trie would |
664 // be ideal. | 664 // be ideal. |
665 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | 665 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
666 if (!strcmp(name, kDataResources[i].name)) { | 666 if (!strcmp(name, kDataResources[i].name)) { |
667 base::StringPiece resource = | 667 base::StringPiece resource = |
668 GetDataResource(kDataResources[i].id, | 668 GetDataResource(kDataResources[i].id, |
669 kDataResources[i].scale_factor); | 669 kDataResources[i].scale_factor); |
670 return WebData(resource.data(), resource.size()); | 670 return WebData(resource.data(), resource.size()); |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 NOTREACHED() << "Unknown image resource " << name; | 674 NOTREACHED() << "Unknown image resource " << name; |
675 return WebData(); | 675 return WebData(); |
676 } | 676 } |
677 | 677 |
678 WebString BlinkPlatformImpl::queryLocalizedString( | 678 WebString WebKitPlatformSupportImpl::queryLocalizedString( |
679 WebLocalizedString::Name name) { | 679 WebLocalizedString::Name name) { |
680 int message_id = ToMessageID(name); | 680 int message_id = ToMessageID(name); |
681 if (message_id < 0) | 681 if (message_id < 0) |
682 return WebString(); | 682 return WebString(); |
683 return GetLocalizedString(message_id); | 683 return GetLocalizedString(message_id); |
684 } | 684 } |
685 | 685 |
686 WebString BlinkPlatformImpl::queryLocalizedString( | 686 WebString WebKitPlatformSupportImpl::queryLocalizedString( |
687 WebLocalizedString::Name name, int numeric_value) { | 687 WebLocalizedString::Name name, int numeric_value) { |
688 return queryLocalizedString(name, base::IntToString16(numeric_value)); | 688 return queryLocalizedString(name, base::IntToString16(numeric_value)); |
689 } | 689 } |
690 | 690 |
691 WebString BlinkPlatformImpl::queryLocalizedString( | 691 WebString WebKitPlatformSupportImpl::queryLocalizedString( |
692 WebLocalizedString::Name name, const WebString& value) { | 692 WebLocalizedString::Name name, const WebString& value) { |
693 int message_id = ToMessageID(name); | 693 int message_id = ToMessageID(name); |
694 if (message_id < 0) | 694 if (message_id < 0) |
695 return WebString(); | 695 return WebString(); |
696 return ReplaceStringPlaceholders(GetLocalizedString(message_id), value, NULL); | 696 return ReplaceStringPlaceholders(GetLocalizedString(message_id), value, NULL); |
697 } | 697 } |
698 | 698 |
699 WebString BlinkPlatformImpl::queryLocalizedString( | 699 WebString WebKitPlatformSupportImpl::queryLocalizedString( |
700 WebLocalizedString::Name name, | 700 WebLocalizedString::Name name, |
701 const WebString& value1, | 701 const WebString& value1, |
702 const WebString& value2) { | 702 const WebString& value2) { |
703 int message_id = ToMessageID(name); | 703 int message_id = ToMessageID(name); |
704 if (message_id < 0) | 704 if (message_id < 0) |
705 return WebString(); | 705 return WebString(); |
706 std::vector<base::string16> values; | 706 std::vector<base::string16> values; |
707 values.reserve(2); | 707 values.reserve(2); |
708 values.push_back(value1); | 708 values.push_back(value1); |
709 values.push_back(value2); | 709 values.push_back(value2); |
710 return ReplaceStringPlaceholders( | 710 return ReplaceStringPlaceholders( |
711 GetLocalizedString(message_id), values, NULL); | 711 GetLocalizedString(message_id), values, NULL); |
712 } | 712 } |
713 | 713 |
714 double BlinkPlatformImpl::currentTime() { | 714 double WebKitPlatformSupportImpl::currentTime() { |
715 return base::Time::Now().ToDoubleT(); | 715 return base::Time::Now().ToDoubleT(); |
716 } | 716 } |
717 | 717 |
718 double BlinkPlatformImpl::monotonicallyIncreasingTime() { | 718 double WebKitPlatformSupportImpl::monotonicallyIncreasingTime() { |
719 return base::TimeTicks::Now().ToInternalValue() / | 719 return base::TimeTicks::Now().ToInternalValue() / |
720 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 720 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
721 } | 721 } |
722 | 722 |
723 void BlinkPlatformImpl::cryptographicallyRandomValues( | 723 void WebKitPlatformSupportImpl::cryptographicallyRandomValues( |
724 unsigned char* buffer, size_t length) { | 724 unsigned char* buffer, size_t length) { |
725 base::RandBytes(buffer, length); | 725 base::RandBytes(buffer, length); |
726 } | 726 } |
727 | 727 |
728 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func)()) { | 728 void WebKitPlatformSupportImpl::setSharedTimerFiredFunction(void (*func)()) { |
729 shared_timer_func_ = func; | 729 shared_timer_func_ = func; |
730 } | 730 } |
731 | 731 |
732 void BlinkPlatformImpl::setSharedTimerFireInterval( | 732 void WebKitPlatformSupportImpl::setSharedTimerFireInterval( |
733 double interval_seconds) { | 733 double interval_seconds) { |
734 shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime(); | 734 shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime(); |
735 if (shared_timer_suspended_) { | 735 if (shared_timer_suspended_) { |
736 shared_timer_fire_time_was_set_while_suspended_ = true; | 736 shared_timer_fire_time_was_set_while_suspended_ = true; |
737 return; | 737 return; |
738 } | 738 } |
739 | 739 |
740 // By converting between double and int64 representation, we run the risk | 740 // By converting between double and int64 representation, we run the risk |
741 // of losing precision due to rounding errors. Performing computations in | 741 // of losing precision due to rounding errors. Performing computations in |
742 // microseconds reduces this risk somewhat. But there still is the potential | 742 // microseconds reduces this risk somewhat. But there still is the potential |
743 // of us computing a fire time for the timer that is shorter than what we | 743 // of us computing a fire time for the timer that is shorter than what we |
744 // need. | 744 // need. |
745 // As the event loop will check event deadlines prior to actually firing | 745 // As the event loop will check event deadlines prior to actually firing |
746 // them, there is a risk of needlessly rescheduling events and of | 746 // them, there is a risk of needlessly rescheduling events and of |
747 // needlessly looping if sleep times are too short even by small amounts. | 747 // needlessly looping if sleep times are too short even by small amounts. |
748 // This results in measurable performance degradation unless we use ceil() to | 748 // This results in measurable performance degradation unless we use ceil() to |
749 // always round up the sleep times. | 749 // always round up the sleep times. |
750 int64 interval = static_cast<int64>( | 750 int64 interval = static_cast<int64>( |
751 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) | 751 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) |
752 * base::Time::kMicrosecondsPerMillisecond); | 752 * base::Time::kMicrosecondsPerMillisecond); |
753 | 753 |
754 if (interval < 0) | 754 if (interval < 0) |
755 interval = 0; | 755 interval = 0; |
756 | 756 |
757 shared_timer_.Stop(); | 757 shared_timer_.Stop(); |
758 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), | 758 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), |
759 this, &BlinkPlatformImpl::DoTimeout); | 759 this, &WebKitPlatformSupportImpl::DoTimeout); |
760 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); | 760 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); |
761 } | 761 } |
762 | 762 |
763 void BlinkPlatformImpl::stopSharedTimer() { | 763 void WebKitPlatformSupportImpl::stopSharedTimer() { |
764 shared_timer_.Stop(); | 764 shared_timer_.Stop(); |
765 } | 765 } |
766 | 766 |
767 void BlinkPlatformImpl::callOnMainThread( | 767 void WebKitPlatformSupportImpl::callOnMainThread( |
768 void (*func)(void*), void* context) { | 768 void (*func)(void*), void* context) { |
769 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); | 769 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); |
770 } | 770 } |
771 | 771 |
772 base::PlatformFile BlinkPlatformImpl::databaseOpenFile( | 772 base::PlatformFile WebKitPlatformSupportImpl::databaseOpenFile( |
773 const blink::WebString& vfs_file_name, int desired_flags) { | 773 const blink::WebString& vfs_file_name, int desired_flags) { |
774 return base::kInvalidPlatformFileValue; | 774 return base::kInvalidPlatformFileValue; |
775 } | 775 } |
776 | 776 |
777 int BlinkPlatformImpl::databaseDeleteFile( | 777 int WebKitPlatformSupportImpl::databaseDeleteFile( |
778 const blink::WebString& vfs_file_name, bool sync_dir) { | 778 const blink::WebString& vfs_file_name, bool sync_dir) { |
779 return -1; | 779 return -1; |
780 } | 780 } |
781 | 781 |
782 long BlinkPlatformImpl::databaseGetFileAttributes( | 782 long WebKitPlatformSupportImpl::databaseGetFileAttributes( |
783 const blink::WebString& vfs_file_name) { | 783 const blink::WebString& vfs_file_name) { |
784 return 0; | 784 return 0; |
785 } | 785 } |
786 | 786 |
787 long long BlinkPlatformImpl::databaseGetFileSize( | 787 long long WebKitPlatformSupportImpl::databaseGetFileSize( |
788 const blink::WebString& vfs_file_name) { | 788 const blink::WebString& vfs_file_name) { |
789 return 0; | 789 return 0; |
790 } | 790 } |
791 | 791 |
792 long long BlinkPlatformImpl::databaseGetSpaceAvailableForOrigin( | 792 long long WebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin( |
793 const blink::WebString& origin_identifier) { | 793 const blink::WebString& origin_identifier) { |
794 return 0; | 794 return 0; |
795 } | 795 } |
796 | 796 |
797 blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString( | 797 blink::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( |
798 unsigned key_size_index, | 798 unsigned key_size_index, |
799 const blink::WebString& challenge, | 799 const blink::WebString& challenge, |
800 const blink::WebURL& url) { | 800 const blink::WebURL& url) { |
801 return blink::WebString(""); | 801 return blink::WebString(""); |
802 } | 802 } |
803 | 803 |
804 static scoped_ptr<base::ProcessMetrics> CurrentProcessMetrics() { | 804 static scoped_ptr<base::ProcessMetrics> CurrentProcessMetrics() { |
805 using base::ProcessMetrics; | 805 using base::ProcessMetrics; |
806 #if defined(OS_MACOSX) | 806 #if defined(OS_MACOSX) |
807 return scoped_ptr<ProcessMetrics>( | 807 return scoped_ptr<ProcessMetrics>( |
808 // The default port provider is sufficient to get data for the current | 808 // The default port provider is sufficient to get data for the current |
809 // process. | 809 // process. |
810 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), | 810 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), |
811 NULL)); | 811 NULL)); |
812 #else | 812 #else |
813 return scoped_ptr<ProcessMetrics>( | 813 return scoped_ptr<ProcessMetrics>( |
814 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle())); | 814 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle())); |
815 #endif | 815 #endif |
816 } | 816 } |
817 | 817 |
818 static size_t getMemoryUsageMB(bool bypass_cache) { | 818 static size_t getMemoryUsageMB(bool bypass_cache) { |
819 size_t current_mem_usage = 0; | 819 size_t current_mem_usage = 0; |
820 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); | 820 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); |
821 if (!bypass_cache && | 821 if (!bypass_cache && |
822 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) | 822 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) |
823 return current_mem_usage; | 823 return current_mem_usage; |
824 | 824 |
825 current_mem_usage = webkit_glue::MemoryUsageKB() >> 10; | 825 current_mem_usage = MemoryUsageKB() >> 10; |
826 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage); | 826 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage); |
827 return current_mem_usage; | 827 return current_mem_usage; |
828 } | 828 } |
829 | 829 |
830 size_t BlinkPlatformImpl::memoryUsageMB() { | 830 size_t WebKitPlatformSupportImpl::memoryUsageMB() { |
831 return getMemoryUsageMB(false); | 831 return getMemoryUsageMB(false); |
832 } | 832 } |
833 | 833 |
834 size_t BlinkPlatformImpl::actualMemoryUsageMB() { | 834 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() { |
835 return getMemoryUsageMB(true); | 835 return getMemoryUsageMB(true); |
836 } | 836 } |
837 | 837 |
838 size_t BlinkPlatformImpl::physicalMemoryMB() { | 838 size_t WebKitPlatformSupportImpl::physicalMemoryMB() { |
839 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB()); | 839 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB()); |
840 } | 840 } |
841 | 841 |
842 size_t BlinkPlatformImpl::numberOfProcessors() { | 842 size_t WebKitPlatformSupportImpl::numberOfProcessors() { |
843 return static_cast<size_t>(base::SysInfo::NumberOfProcessors()); | 843 return static_cast<size_t>(base::SysInfo::NumberOfProcessors()); |
844 } | 844 } |
845 | 845 |
846 void BlinkPlatformImpl::startHeapProfiling( | 846 void WebKitPlatformSupportImpl::startHeapProfiling( |
847 const blink::WebString& prefix) { | 847 const blink::WebString& prefix) { |
848 // FIXME(morrita): Make this built on windows. | 848 // FIXME(morrita): Make this built on windows. |
849 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | 849 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) |
850 HeapProfilerStart(prefix.utf8().data()); | 850 HeapProfilerStart(prefix.utf8().data()); |
851 #endif | 851 #endif |
852 } | 852 } |
853 | 853 |
854 void BlinkPlatformImpl::stopHeapProfiling() { | 854 void WebKitPlatformSupportImpl::stopHeapProfiling() { |
855 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | 855 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) |
856 HeapProfilerStop(); | 856 HeapProfilerStop(); |
857 #endif | 857 #endif |
858 } | 858 } |
859 | 859 |
860 void BlinkPlatformImpl::dumpHeapProfiling( | 860 void WebKitPlatformSupportImpl::dumpHeapProfiling( |
861 const blink::WebString& reason) { | 861 const blink::WebString& reason) { |
862 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | 862 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) |
863 HeapProfilerDump(reason.utf8().data()); | 863 HeapProfilerDump(reason.utf8().data()); |
864 #endif | 864 #endif |
865 } | 865 } |
866 | 866 |
867 WebString BlinkPlatformImpl::getHeapProfile() { | 867 WebString WebKitPlatformSupportImpl::getHeapProfile() { |
868 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | 868 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) |
869 char* data = GetHeapProfile(); | 869 char* data = GetHeapProfile(); |
870 WebString result = WebString::fromUTF8(std::string(data)); | 870 WebString result = WebString::fromUTF8(std::string(data)); |
871 free(data); | 871 free(data); |
872 return result; | 872 return result; |
873 #else | 873 #else |
874 return WebString(); | 874 return WebString(); |
875 #endif | 875 #endif |
876 } | 876 } |
877 | 877 |
878 bool BlinkPlatformImpl::processMemorySizesInBytes( | 878 bool WebKitPlatformSupportImpl::processMemorySizesInBytes( |
879 size_t* private_bytes, | 879 size_t* private_bytes, |
880 size_t* shared_bytes) { | 880 size_t* shared_bytes) { |
881 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes, shared_bytes); | 881 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes, shared_bytes); |
882 } | 882 } |
883 | 883 |
884 bool BlinkPlatformImpl::memoryAllocatorWasteInBytes(size_t* size) { | 884 bool WebKitPlatformSupportImpl::memoryAllocatorWasteInBytes(size_t* size) { |
885 return base::allocator::GetAllocatorWasteSize(size); | 885 return base::allocator::GetAllocatorWasteSize(size); |
886 } | 886 } |
887 | 887 |
888 size_t BlinkPlatformImpl::maxDecodedImageBytes() { | 888 size_t WebKitPlatformSupportImpl::maxDecodedImageBytes() { |
889 #if defined(OS_ANDROID) | 889 #if defined(OS_ANDROID) |
890 if (base::android::SysUtils::IsLowEndDevice()) { | 890 if (base::android::SysUtils::IsLowEndDevice()) { |
891 // Limit image decoded size to 3M pixels on low end devices. | 891 // Limit image decoded size to 3M pixels on low end devices. |
892 // 4 is maximum number of bytes per pixel. | 892 // 4 is maximum number of bytes per pixel. |
893 return 3 * 1024 * 1024 * 4; | 893 return 3 * 1024 * 1024 * 4; |
894 } | 894 } |
895 // For other devices, limit decoded image size based on the amount of physical | 895 // For other devices, limit decoded image size based on the amount of physical |
896 // memory. For a device with 2GB physical memory the limit is 16M pixels. | 896 // memory. For a device with 2GB physical memory the limit is 16M pixels. |
897 return base::SysInfo::AmountOfPhysicalMemory() / 32; | 897 return base::SysInfo::AmountOfPhysicalMemory() / 32; |
898 #else | 898 #else |
899 return noDecodedImageByteLimit; | 899 return noDecodedImageByteLimit; |
900 #endif | 900 #endif |
901 } | 901 } |
902 | 902 |
903 void BlinkPlatformImpl::SuspendSharedTimer() { | 903 void WebKitPlatformSupportImpl::SuspendSharedTimer() { |
904 ++shared_timer_suspended_; | 904 ++shared_timer_suspended_; |
905 } | 905 } |
906 | 906 |
907 void BlinkPlatformImpl::ResumeSharedTimer() { | 907 void WebKitPlatformSupportImpl::ResumeSharedTimer() { |
908 // The shared timer may have fired or been adjusted while we were suspended. | 908 // The shared timer may have fired or been adjusted while we were suspended. |
909 if (--shared_timer_suspended_ == 0 && | 909 if (--shared_timer_suspended_ == 0 && |
910 (!shared_timer_.IsRunning() || | 910 (!shared_timer_.IsRunning() || |
911 shared_timer_fire_time_was_set_while_suspended_)) { | 911 shared_timer_fire_time_was_set_while_suspended_)) { |
912 shared_timer_fire_time_was_set_while_suspended_ = false; | 912 shared_timer_fire_time_was_set_while_suspended_ = false; |
913 setSharedTimerFireInterval( | 913 setSharedTimerFireInterval( |
914 shared_timer_fire_time_ - monotonicallyIncreasingTime()); | 914 shared_timer_fire_time_ - monotonicallyIncreasingTime()); |
915 } | 915 } |
916 } | 916 } |
917 | 917 |
918 } // namespace content | 918 } // namespace webkit_glue |
OLD | NEW |