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
3 // found in the LICENSE file.
5 #include "content/child/blink_platform_impl.h"
11 #include "base/allocator/allocator_extension.h"
12 #include "base/bind.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/metrics/histogram.h"
18 #include "base/metrics/sparse_histogram.h"
19 #include "base/metrics/stats_counters.h"
20 #include "base/process/process_metrics.h"
21 #include "base/rand_util.h"
22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h"
24 #include "base/strings/utf_string_conversions.h"
25 #include "base/synchronization/lock.h"
26 #include "base/synchronization/waitable_event.h"
27 #include "base/sys_info.h"
28 #include "base/threading/platform_thread.h"
29 #include "base/time/time.h"
30 #include "blink/public/resources/grit/blink_resources.h"
31 #include "content/app/resources/grit/content_resources.h"
32 #include "content/app/strings/grit/content_strings.h"
33 #include "content/child/child_thread.h"
34 #include "content/child/content_child_helpers.h"
35 #include "content/child/geofencing/web_geofencing_provider_impl.h"
36 #include "content/child/notifications/notification_dispatcher.h"
37 #include "content/child/notifications/notification_manager.h"
38 #include "content/child/thread_safe_sender.h"
39 #include "content/child/web_discardable_memory_impl.h"
40 #include "content/child/web_gesture_curve_impl.h"
41 #include "content/child/web_url_loader_impl.h"
42 #include "content/child/websocket_bridge.h"
43 #include "content/child/webthread_impl.h"
44 #include "content/child/worker_task_runner.h"
45 #include "content/public/common/content_client.h"
46 #include "net/base/data_url.h"
47 #include "net/base/mime_util.h"
48 #include "net/base/net_errors.h"
49 #include "net/base/net_util.h"
50 #include "third_party/WebKit/public/platform/WebConvertableToTraceFormat.h"
51 #include "third_party/WebKit/public/platform/WebData.h"
52 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
53 #include "third_party/WebKit/public/platform/WebString.h"
54 #include "third_party/WebKit/public/platform/WebURL.h"
55 #include "third_party/WebKit/public/platform/WebWaitableEvent.h"
56 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
57 #include "ui/base/layout.h"
59 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
60 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
64 using blink::WebFallbackThemeEngine
;
65 using blink::WebLocalizedString
;
66 using blink::WebString
;
67 using blink::WebThemeEngine
;
69 using blink::WebURLError
;
70 using blink::WebURLLoader
;
76 class WebWaitableEventImpl
: public blink::WebWaitableEvent
{
78 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {}
79 virtual ~WebWaitableEventImpl() {}
81 virtual void wait() { impl_
->Wait(); }
82 virtual void signal() { impl_
->Signal(); }
84 base::WaitableEvent
* impl() {
89 scoped_ptr
<base::WaitableEvent
> impl_
;
90 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl
);
93 // A simple class to cache the memory usage for a given amount of time.
94 class MemoryUsageCache
{
96 // Retrieves the Singleton.
97 static MemoryUsageCache
* GetInstance() {
98 return Singleton
<MemoryUsageCache
>::get();
101 MemoryUsageCache() : memory_value_(0) { Init(); }
102 ~MemoryUsageCache() {}
105 const unsigned int kCacheSeconds
= 1;
106 cache_valid_time_
= base::TimeDelta::FromSeconds(kCacheSeconds
);
109 // Returns true if the cached value is fresh.
110 // Returns false if the cached value is stale, or if |cached_value| is NULL.
111 bool IsCachedValueValid(size_t* cached_value
) {
112 base::AutoLock
scoped_lock(lock_
);
115 if (base::Time::Now() - last_updated_time_
> cache_valid_time_
)
117 *cached_value
= memory_value_
;
121 // Setter for |memory_value_|, refreshes |last_updated_time_|.
122 void SetMemoryValue(const size_t value
) {
123 base::AutoLock
scoped_lock(lock_
);
124 memory_value_
= value
;
125 last_updated_time_
= base::Time::Now();
129 // The cached memory value.
130 size_t memory_value_
;
132 // How long the cached value should remain valid.
133 base::TimeDelta cache_valid_time_
;
135 // The last time the cached value was updated.
136 base::Time last_updated_time_
;
141 class ConvertableToTraceFormatWrapper
142 : public base::debug::ConvertableToTraceFormat
{
144 explicit ConvertableToTraceFormatWrapper(
145 const blink::WebConvertableToTraceFormat
& convertable
)
146 : convertable_(convertable
) {}
147 void AppendAsTraceFormat(std::string
* out
) const override
{
148 *out
+= convertable_
.asTraceFormat().utf8();
152 ~ConvertableToTraceFormatWrapper() override
{}
154 blink::WebConvertableToTraceFormat convertable_
;
157 bool isHostnameReservedIPAddress(const std::string
& host
) {
158 net::IPAddressNumber address
;
159 if (!net::ParseURLHostnameToNumber(host
, &address
))
161 return net::IsIPAddressReserved(address
);
166 static int ToMessageID(WebLocalizedString::Name name
) {
168 case WebLocalizedString::AXAMPMFieldText
:
169 return IDS_AX_AM_PM_FIELD_TEXT
;
170 case WebLocalizedString::AXButtonActionVerb
:
171 return IDS_AX_BUTTON_ACTION_VERB
;
172 case WebLocalizedString::AXCalendarShowMonthSelector
:
173 return IDS_AX_CALENDAR_SHOW_MONTH_SELECTOR
;
174 case WebLocalizedString::AXCalendarShowNextMonth
:
175 return IDS_AX_CALENDAR_SHOW_NEXT_MONTH
;
176 case WebLocalizedString::AXCalendarShowPreviousMonth
:
177 return IDS_AX_CALENDAR_SHOW_PREVIOUS_MONTH
;
178 case WebLocalizedString::AXCalendarWeekDescription
:
179 return IDS_AX_CALENDAR_WEEK_DESCRIPTION
;
180 case WebLocalizedString::AXCheckedCheckBoxActionVerb
:
181 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB
;
182 case WebLocalizedString::AXDateTimeFieldEmptyValueText
:
183 return IDS_AX_DATE_TIME_FIELD_EMPTY_VALUE_TEXT
;
184 case WebLocalizedString::AXDayOfMonthFieldText
:
185 return IDS_AX_DAY_OF_MONTH_FIELD_TEXT
;
186 case WebLocalizedString::AXHeadingText
:
187 return IDS_AX_ROLE_HEADING
;
188 case WebLocalizedString::AXHourFieldText
:
189 return IDS_AX_HOUR_FIELD_TEXT
;
190 case WebLocalizedString::AXImageMapText
:
191 return IDS_AX_ROLE_IMAGE_MAP
;
192 case WebLocalizedString::AXLinkActionVerb
:
193 return IDS_AX_LINK_ACTION_VERB
;
194 case WebLocalizedString::AXLinkText
:
195 return IDS_AX_ROLE_LINK
;
196 case WebLocalizedString::AXListMarkerText
:
197 return IDS_AX_ROLE_LIST_MARKER
;
198 case WebLocalizedString::AXMediaDefault
:
199 return IDS_AX_MEDIA_DEFAULT
;
200 case WebLocalizedString::AXMediaAudioElement
:
201 return IDS_AX_MEDIA_AUDIO_ELEMENT
;
202 case WebLocalizedString::AXMediaVideoElement
:
203 return IDS_AX_MEDIA_VIDEO_ELEMENT
;
204 case WebLocalizedString::AXMediaMuteButton
:
205 return IDS_AX_MEDIA_MUTE_BUTTON
;
206 case WebLocalizedString::AXMediaUnMuteButton
:
207 return IDS_AX_MEDIA_UNMUTE_BUTTON
;
208 case WebLocalizedString::AXMediaPlayButton
:
209 return IDS_AX_MEDIA_PLAY_BUTTON
;
210 case WebLocalizedString::AXMediaPauseButton
:
211 return IDS_AX_MEDIA_PAUSE_BUTTON
;
212 case WebLocalizedString::AXMediaSlider
:
213 return IDS_AX_MEDIA_SLIDER
;
214 case WebLocalizedString::AXMediaSliderThumb
:
215 return IDS_AX_MEDIA_SLIDER_THUMB
;
216 case WebLocalizedString::AXMediaCurrentTimeDisplay
:
217 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY
;
218 case WebLocalizedString::AXMediaTimeRemainingDisplay
:
219 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY
;
220 case WebLocalizedString::AXMediaStatusDisplay
:
221 return IDS_AX_MEDIA_STATUS_DISPLAY
;
222 case WebLocalizedString::AXMediaEnterFullscreenButton
:
223 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON
;
224 case WebLocalizedString::AXMediaExitFullscreenButton
:
225 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON
;
226 case WebLocalizedString::AXMediaShowClosedCaptionsButton
:
227 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON
;
228 case WebLocalizedString::AXMediaHideClosedCaptionsButton
:
229 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON
;
230 case WebLocalizedString::AxMediaCastOffButton
:
231 return IDS_AX_MEDIA_CAST_OFF_BUTTON
;
232 case WebLocalizedString::AxMediaCastOnButton
:
233 return IDS_AX_MEDIA_CAST_ON_BUTTON
;
234 case WebLocalizedString::AXMediaAudioElementHelp
:
235 return IDS_AX_MEDIA_AUDIO_ELEMENT_HELP
;
236 case WebLocalizedString::AXMediaVideoElementHelp
:
237 return IDS_AX_MEDIA_VIDEO_ELEMENT_HELP
;
238 case WebLocalizedString::AXMediaMuteButtonHelp
:
239 return IDS_AX_MEDIA_MUTE_BUTTON_HELP
;
240 case WebLocalizedString::AXMediaUnMuteButtonHelp
:
241 return IDS_AX_MEDIA_UNMUTE_BUTTON_HELP
;
242 case WebLocalizedString::AXMediaPlayButtonHelp
:
243 return IDS_AX_MEDIA_PLAY_BUTTON_HELP
;
244 case WebLocalizedString::AXMediaPauseButtonHelp
:
245 return IDS_AX_MEDIA_PAUSE_BUTTON_HELP
;
246 case WebLocalizedString::AXMediaSliderHelp
:
247 return IDS_AX_MEDIA_SLIDER_HELP
;
248 case WebLocalizedString::AXMediaSliderThumbHelp
:
249 return IDS_AX_MEDIA_SLIDER_THUMB_HELP
;
250 case WebLocalizedString::AXMediaCurrentTimeDisplayHelp
:
251 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY_HELP
;
252 case WebLocalizedString::AXMediaTimeRemainingDisplayHelp
:
253 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY_HELP
;
254 case WebLocalizedString::AXMediaStatusDisplayHelp
:
255 return IDS_AX_MEDIA_STATUS_DISPLAY_HELP
;
256 case WebLocalizedString::AXMediaEnterFullscreenButtonHelp
:
257 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON_HELP
;
258 case WebLocalizedString::AXMediaExitFullscreenButtonHelp
:
259 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON_HELP
;
260 case WebLocalizedString::AXMediaShowClosedCaptionsButtonHelp
:
261 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON_HELP
;
262 case WebLocalizedString::AXMediaHideClosedCaptionsButtonHelp
:
263 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON_HELP
;
264 case WebLocalizedString::AxMediaCastOffButtonHelp
:
265 return IDS_AX_MEDIA_CAST_OFF_BUTTON_HELP
;
266 case WebLocalizedString::AxMediaCastOnButtonHelp
:
267 return IDS_AX_MEDIA_CAST_ON_BUTTON_HELP
;
268 case WebLocalizedString::AXMillisecondFieldText
:
269 return IDS_AX_MILLISECOND_FIELD_TEXT
;
270 case WebLocalizedString::AXMinuteFieldText
:
271 return IDS_AX_MINUTE_FIELD_TEXT
;
272 case WebLocalizedString::AXMonthFieldText
:
273 return IDS_AX_MONTH_FIELD_TEXT
;
274 case WebLocalizedString::AXRadioButtonActionVerb
:
275 return IDS_AX_RADIO_BUTTON_ACTION_VERB
;
276 case WebLocalizedString::AXSecondFieldText
:
277 return IDS_AX_SECOND_FIELD_TEXT
;
278 case WebLocalizedString::AXTextFieldActionVerb
:
279 return IDS_AX_TEXT_FIELD_ACTION_VERB
;
280 case WebLocalizedString::AXUncheckedCheckBoxActionVerb
:
281 return IDS_AX_UNCHECKED_CHECK_BOX_ACTION_VERB
;
282 case WebLocalizedString::AXWebAreaText
:
283 return IDS_AX_ROLE_WEB_AREA
;
284 case WebLocalizedString::AXWeekOfYearFieldText
:
285 return IDS_AX_WEEK_OF_YEAR_FIELD_TEXT
;
286 case WebLocalizedString::AXYearFieldText
:
287 return IDS_AX_YEAR_FIELD_TEXT
;
288 case WebLocalizedString::CalendarClear
:
289 return IDS_FORM_CALENDAR_CLEAR
;
290 case WebLocalizedString::CalendarToday
:
291 return IDS_FORM_CALENDAR_TODAY
;
292 case WebLocalizedString::DateFormatDayInMonthLabel
:
293 return IDS_FORM_DATE_FORMAT_DAY_IN_MONTH
;
294 case WebLocalizedString::DateFormatMonthLabel
:
295 return IDS_FORM_DATE_FORMAT_MONTH
;
296 case WebLocalizedString::DateFormatYearLabel
:
297 return IDS_FORM_DATE_FORMAT_YEAR
;
298 case WebLocalizedString::DetailsLabel
:
299 return IDS_DETAILS_WITHOUT_SUMMARY_LABEL
;
300 case WebLocalizedString::FileButtonChooseFileLabel
:
301 return IDS_FORM_FILE_BUTTON_LABEL
;
302 case WebLocalizedString::FileButtonChooseMultipleFilesLabel
:
303 return IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL
;
304 case WebLocalizedString::FileButtonNoFileSelectedLabel
:
305 return IDS_FORM_FILE_NO_FILE_LABEL
;
306 case WebLocalizedString::InputElementAltText
:
307 return IDS_FORM_INPUT_ALT
;
308 case WebLocalizedString::KeygenMenuHighGradeKeySize
:
309 return IDS_KEYGEN_HIGH_GRADE_KEY
;
310 case WebLocalizedString::KeygenMenuMediumGradeKeySize
:
311 return IDS_KEYGEN_MED_GRADE_KEY
;
312 case WebLocalizedString::MissingPluginText
:
313 return IDS_PLUGIN_INITIALIZATION_ERROR
;
314 case WebLocalizedString::MultipleFileUploadText
:
315 return IDS_FORM_FILE_MULTIPLE_UPLOAD
;
316 case WebLocalizedString::OtherColorLabel
:
317 return IDS_FORM_OTHER_COLOR_LABEL
;
318 case WebLocalizedString::OtherDateLabel
:
319 return IDS_FORM_OTHER_DATE_LABEL
;
320 case WebLocalizedString::OtherMonthLabel
:
321 return IDS_FORM_OTHER_MONTH_LABEL
;
322 case WebLocalizedString::OtherTimeLabel
:
323 return IDS_FORM_OTHER_TIME_LABEL
;
324 case WebLocalizedString::OtherWeekLabel
:
325 return IDS_FORM_OTHER_WEEK_LABEL
;
326 case WebLocalizedString::PlaceholderForDayOfMonthField
:
327 return IDS_FORM_PLACEHOLDER_FOR_DAY_OF_MONTH_FIELD
;
328 case WebLocalizedString::PlaceholderForMonthField
:
329 return IDS_FORM_PLACEHOLDER_FOR_MONTH_FIELD
;
330 case WebLocalizedString::PlaceholderForYearField
:
331 return IDS_FORM_PLACEHOLDER_FOR_YEAR_FIELD
;
332 case WebLocalizedString::ResetButtonDefaultLabel
:
333 return IDS_FORM_RESET_LABEL
;
334 case WebLocalizedString::SearchableIndexIntroduction
:
335 return IDS_SEARCHABLE_INDEX_INTRO
;
336 case WebLocalizedString::SearchMenuClearRecentSearchesText
:
337 return IDS_RECENT_SEARCHES_CLEAR
;
338 case WebLocalizedString::SearchMenuNoRecentSearchesText
:
339 return IDS_RECENT_SEARCHES_NONE
;
340 case WebLocalizedString::SearchMenuRecentSearchesText
:
341 return IDS_RECENT_SEARCHES
;
342 case WebLocalizedString::SelectMenuListText
:
343 return IDS_FORM_SELECT_MENU_LIST_TEXT
;
344 case WebLocalizedString::SubmitButtonDefaultLabel
:
345 return IDS_FORM_SUBMIT_LABEL
;
346 case WebLocalizedString::ThisMonthButtonLabel
:
347 return IDS_FORM_THIS_MONTH_LABEL
;
348 case WebLocalizedString::ThisWeekButtonLabel
:
349 return IDS_FORM_THIS_WEEK_LABEL
;
350 case WebLocalizedString::ValidationBadInputForDateTime
:
351 return IDS_FORM_VALIDATION_BAD_INPUT_DATETIME
;
352 case WebLocalizedString::ValidationBadInputForNumber
:
353 return IDS_FORM_VALIDATION_BAD_INPUT_NUMBER
;
354 case WebLocalizedString::ValidationPatternMismatch
:
355 return IDS_FORM_VALIDATION_PATTERN_MISMATCH
;
356 case WebLocalizedString::ValidationRangeOverflow
:
357 return IDS_FORM_VALIDATION_RANGE_OVERFLOW
;
358 case WebLocalizedString::ValidationRangeOverflowDateTime
:
359 return IDS_FORM_VALIDATION_RANGE_OVERFLOW_DATETIME
;
360 case WebLocalizedString::ValidationRangeUnderflow
:
361 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW
;
362 case WebLocalizedString::ValidationRangeUnderflowDateTime
:
363 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW_DATETIME
;
364 case WebLocalizedString::ValidationStepMismatch
:
365 return IDS_FORM_VALIDATION_STEP_MISMATCH
;
366 case WebLocalizedString::ValidationStepMismatchCloseToLimit
:
367 return IDS_FORM_VALIDATION_STEP_MISMATCH_CLOSE_TO_LIMIT
;
368 case WebLocalizedString::ValidationTooLong
:
369 return IDS_FORM_VALIDATION_TOO_LONG
;
370 case WebLocalizedString::ValidationTooShort
:
371 return IDS_FORM_VALIDATION_TOO_SHORT
;
372 case WebLocalizedString::ValidationTypeMismatch
:
373 return IDS_FORM_VALIDATION_TYPE_MISMATCH
;
374 case WebLocalizedString::ValidationTypeMismatchForEmail
:
375 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL
;
376 case WebLocalizedString::ValidationTypeMismatchForEmailEmpty
:
377 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY
;
378 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyDomain
:
379 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_DOMAIN
;
380 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyLocal
:
381 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_LOCAL
;
382 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDomain
:
383 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOMAIN
;
384 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDots
:
385 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOTS
;
386 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidLocal
:
387 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_LOCAL
;
388 case WebLocalizedString::ValidationTypeMismatchForEmailNoAtSign
:
389 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_NO_AT_SIGN
;
390 case WebLocalizedString::ValidationTypeMismatchForMultipleEmail
:
391 return IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL
;
392 case WebLocalizedString::ValidationTypeMismatchForURL
:
393 return IDS_FORM_VALIDATION_TYPE_MISMATCH_URL
;
394 case WebLocalizedString::ValidationValueMissing
:
395 return IDS_FORM_VALIDATION_VALUE_MISSING
;
396 case WebLocalizedString::ValidationValueMissingForCheckbox
:
397 return IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX
;
398 case WebLocalizedString::ValidationValueMissingForFile
:
399 return IDS_FORM_VALIDATION_VALUE_MISSING_FILE
;
400 case WebLocalizedString::ValidationValueMissingForMultipleFile
:
401 return IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE
;
402 case WebLocalizedString::ValidationValueMissingForRadio
:
403 return IDS_FORM_VALIDATION_VALUE_MISSING_RADIO
;
404 case WebLocalizedString::ValidationValueMissingForSelect
:
405 return IDS_FORM_VALIDATION_VALUE_MISSING_SELECT
;
406 case WebLocalizedString::WeekFormatTemplate
:
407 return IDS_FORM_INPUT_WEEK_TEMPLATE
;
408 case WebLocalizedString::WeekNumberLabel
:
409 return IDS_FORM_WEEK_NUMBER_LABEL
;
410 // This "default:" line exists to avoid compile warnings about enum
411 // coverage when we add a new symbol to WebLocalizedString.h in WebKit.
412 // After a planned WebKit patch is landed, we need to add a case statement
413 // for the added symbol here.
420 BlinkPlatformImpl::BlinkPlatformImpl()
421 : main_loop_(base::MessageLoop::current()),
422 shared_timer_func_(NULL
),
423 shared_timer_fire_time_(0.0),
424 shared_timer_fire_time_was_set_while_suspended_(false),
425 shared_timer_suspended_(0),
426 current_thread_slot_(&DestroyCurrentThread
) {
427 // ChildThread may not exist in some tests.
428 if (ChildThread::current()) {
429 geofencing_provider_
.reset(new WebGeofencingProviderImpl(
430 ChildThread::current()->thread_safe_sender()));
431 thread_safe_sender_
= ChildThread::current()->thread_safe_sender();
432 notification_dispatcher_
=
433 ChildThread::current()->notification_dispatcher();
437 BlinkPlatformImpl::~BlinkPlatformImpl() {
440 WebURLLoader
* BlinkPlatformImpl::createURLLoader() {
441 ChildThread
* child_thread
= ChildThread::current();
442 // There may be no child thread in RenderViewTests. These tests can still use
443 // data URLs to bypass the ResourceDispatcher.
444 return new WebURLLoaderImpl(
445 child_thread
? child_thread
->resource_dispatcher() : NULL
);
448 blink::WebSocketHandle
* BlinkPlatformImpl::createWebSocketHandle() {
449 return new WebSocketBridge
;
452 WebString
BlinkPlatformImpl::userAgent() {
453 return WebString::fromUTF8(GetContentClient()->GetUserAgent());
456 WebData
BlinkPlatformImpl::parseDataURL(const WebURL
& url
,
457 WebString
& mimetype_out
,
458 WebString
& charset_out
) {
459 std::string mime_type
, char_set
, data
;
460 if (net::DataURL::Parse(url
, &mime_type
, &char_set
, &data
)
461 && net::IsSupportedMimeType(mime_type
)) {
462 mimetype_out
= WebString::fromUTF8(mime_type
);
463 charset_out
= WebString::fromUTF8(char_set
);
469 WebURLError
BlinkPlatformImpl::cancelledError(
470 const WebURL
& unreachableURL
) const {
471 return WebURLLoaderImpl::CreateError(unreachableURL
, false, net::ERR_ABORTED
);
474 bool BlinkPlatformImpl::isReservedIPAddress(
475 const blink::WebSecurityOrigin
& securityOrigin
) const {
476 return isHostnameReservedIPAddress(securityOrigin
.host().utf8());
479 bool BlinkPlatformImpl::isReservedIPAddress(const blink::WebURL
& url
) const {
480 return isHostnameReservedIPAddress(GURL(url
).host());
483 blink::WebThread
* BlinkPlatformImpl::createThread(const char* name
) {
484 return new WebThreadImpl(name
);
487 blink::WebThread
* BlinkPlatformImpl::currentThread() {
488 WebThreadImplForMessageLoop
* thread
=
489 static_cast<WebThreadImplForMessageLoop
*>(current_thread_slot_
.Get());
493 scoped_refptr
<base::MessageLoopProxy
> message_loop
=
494 base::MessageLoopProxy::current();
495 if (!message_loop
.get())
498 thread
= new WebThreadImplForMessageLoop(message_loop
.get());
499 current_thread_slot_
.Set(thread
);
503 void BlinkPlatformImpl::yieldCurrentThread() {
504 base::PlatformThread::YieldCurrentThread();
507 blink::WebWaitableEvent
* BlinkPlatformImpl::createWaitableEvent() {
508 return new WebWaitableEventImpl();
511 blink::WebWaitableEvent
* BlinkPlatformImpl::waitMultipleEvents(
512 const blink::WebVector
<blink::WebWaitableEvent
*>& web_events
) {
513 std::vector
<base::WaitableEvent
*> events
;
514 for (size_t i
= 0; i
< web_events
.size(); ++i
)
515 events
.push_back(static_cast<WebWaitableEventImpl
*>(web_events
[i
])->impl());
516 size_t idx
= base::WaitableEvent::WaitMany(
517 vector_as_array(&events
), events
.size());
518 DCHECK_LT(idx
, web_events
.size());
519 return web_events
[idx
];
522 void BlinkPlatformImpl::decrementStatsCounter(const char* name
) {
523 base::StatsCounter(name
).Decrement();
526 void BlinkPlatformImpl::incrementStatsCounter(const char* name
) {
527 base::StatsCounter(name
).Increment();
530 void BlinkPlatformImpl::histogramCustomCounts(
531 const char* name
, int sample
, int min
, int max
, int bucket_count
) {
532 // Copied from histogram macro, but without the static variable caching
533 // the histogram because name is dynamic.
534 base::HistogramBase
* counter
=
535 base::Histogram::FactoryGet(name
, min
, max
, bucket_count
,
536 base::HistogramBase::kUmaTargetedHistogramFlag
);
537 DCHECK_EQ(name
, counter
->histogram_name());
538 counter
->Add(sample
);
541 void BlinkPlatformImpl::histogramEnumeration(
542 const char* name
, int sample
, int boundary_value
) {
543 // Copied from histogram macro, but without the static variable caching
544 // the histogram because name is dynamic.
545 base::HistogramBase
* counter
=
546 base::LinearHistogram::FactoryGet(name
, 1, boundary_value
,
547 boundary_value
+ 1, base::HistogramBase::kUmaTargetedHistogramFlag
);
548 DCHECK_EQ(name
, counter
->histogram_name());
549 counter
->Add(sample
);
552 void BlinkPlatformImpl::histogramSparse(const char* name
, int sample
) {
553 // For sparse histograms, we can use the macro, as it does not incorporate a
555 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);
558 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag(
559 const char* category_group
) {
560 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
563 long* BlinkPlatformImpl::getTraceSamplingState(
564 const unsigned thread_bucket
) {
565 switch (thread_bucket
) {
567 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0));
569 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(1));
571 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(2));
573 NOTREACHED() << "Unknown thread bucket type.";
579 sizeof(blink::Platform::TraceEventHandle
) ==
580 sizeof(base::debug::TraceEventHandle
),
581 TraceEventHandle_types_must_be_same_size
);
583 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
585 const unsigned char* category_group_enabled
,
587 unsigned long long id
,
589 const char** arg_names
,
590 const unsigned char* arg_types
,
591 const unsigned long long* arg_values
,
592 unsigned char flags
) {
593 base::debug::TraceEventHandle handle
= TRACE_EVENT_API_ADD_TRACE_EVENT(
594 phase
, category_group_enabled
, name
, id
,
595 num_args
, arg_names
, arg_types
, arg_values
, NULL
, flags
);
596 blink::Platform::TraceEventHandle result
;
597 memcpy(&result
, &handle
, sizeof(result
));
601 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
603 const unsigned char* category_group_enabled
,
605 unsigned long long id
,
607 const char** arg_names
,
608 const unsigned char* arg_types
,
609 const unsigned long long* arg_values
,
610 const blink::WebConvertableToTraceFormat
* convertable_values
,
611 unsigned char flags
) {
612 scoped_refptr
<base::debug::ConvertableToTraceFormat
> convertable_wrappers
[2];
613 if (convertable_values
) {
614 size_t size
= std::min(static_cast<size_t>(num_args
),
615 arraysize(convertable_wrappers
));
616 for (size_t i
= 0; i
< size
; ++i
) {
617 if (arg_types
[i
] == TRACE_VALUE_TYPE_CONVERTABLE
) {
618 convertable_wrappers
[i
] =
619 new ConvertableToTraceFormatWrapper(convertable_values
[i
]);
623 base::debug::TraceEventHandle handle
=
624 TRACE_EVENT_API_ADD_TRACE_EVENT(phase
,
625 category_group_enabled
,
632 convertable_wrappers
,
634 blink::Platform::TraceEventHandle result
;
635 memcpy(&result
, &handle
, sizeof(result
));
639 void BlinkPlatformImpl::updateTraceEventDuration(
640 const unsigned char* category_group_enabled
,
642 TraceEventHandle handle
) {
643 base::debug::TraceEventHandle traceEventHandle
;
644 memcpy(&traceEventHandle
, &handle
, sizeof(handle
));
645 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
646 category_group_enabled
, name
, traceEventHandle
);
651 WebData
loadAudioSpatializationResource(const char* name
) {
652 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE
653 if (!strcmp(name
, "Composite")) {
654 base::StringPiece resource
= GetContentClient()->GetDataResource(
655 IDR_AUDIO_SPATIALIZATION_COMPOSITE
, ui::SCALE_FACTOR_NONE
);
656 return WebData(resource
.data(), resource
.size());
660 #ifdef IDR_AUDIO_SPATIALIZATION_T000_P000
661 const size_t kExpectedSpatializationNameLength
= 31;
662 if (strlen(name
) != kExpectedSpatializationNameLength
) {
666 // Extract the azimuth and elevation from the resource name.
670 sscanf(name
, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth
, &elevation
);
671 if (values_parsed
!= 2) {
675 // The resource index values go through the elevations first, then azimuths.
676 const int kAngleSpacing
= 15;
678 // 0 <= elevation <= 90 (or 315 <= elevation <= 345)
679 // in increments of 15 degrees.
680 int elevation_index
=
681 elevation
<= 90 ? elevation
/ kAngleSpacing
:
682 7 + (elevation
- 315) / kAngleSpacing
;
683 bool is_elevation_index_good
= 0 <= elevation_index
&& elevation_index
< 10;
685 // 0 <= azimuth < 360 in increments of 15 degrees.
686 int azimuth_index
= azimuth
/ kAngleSpacing
;
687 bool is_azimuth_index_good
= 0 <= azimuth_index
&& azimuth_index
< 24;
689 const int kNumberOfElevations
= 10;
690 const int kNumberOfAudioResources
= 240;
691 int resource_index
= kNumberOfElevations
* azimuth_index
+ elevation_index
;
692 bool is_resource_index_good
= 0 <= resource_index
&&
693 resource_index
< kNumberOfAudioResources
;
695 if (is_azimuth_index_good
&& is_elevation_index_good
&&
696 is_resource_index_good
) {
697 const int kFirstAudioResourceIndex
= IDR_AUDIO_SPATIALIZATION_T000_P000
;
698 base::StringPiece resource
= GetContentClient()->GetDataResource(
699 kFirstAudioResourceIndex
+ resource_index
, ui::SCALE_FACTOR_NONE
);
700 return WebData(resource
.data(), resource
.size());
702 #endif // IDR_AUDIO_SPATIALIZATION_T000_P000
708 struct DataResource
{
711 ui::ScaleFactor scale_factor
;
714 const DataResource kDataResources
[] = {
715 { "missingImage", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_100P
},
716 { "missingImage@2x", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_200P
},
717 { "mediaplayerPause", IDR_MEDIAPLAYER_PAUSE_BUTTON
, ui::SCALE_FACTOR_100P
},
718 { "mediaplayerPauseHover",
719 IDR_MEDIAPLAYER_PAUSE_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
720 { "mediaplayerPauseDown",
721 IDR_MEDIAPLAYER_PAUSE_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
722 { "mediaplayerPlay", IDR_MEDIAPLAYER_PLAY_BUTTON
, ui::SCALE_FACTOR_100P
},
723 { "mediaplayerPlayHover",
724 IDR_MEDIAPLAYER_PLAY_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
725 { "mediaplayerPlayDown",
726 IDR_MEDIAPLAYER_PLAY_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
727 { "mediaplayerPlayDisabled",
728 IDR_MEDIAPLAYER_PLAY_BUTTON_DISABLED
, ui::SCALE_FACTOR_100P
},
729 { "mediaplayerSoundLevel3",
730 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON
, ui::SCALE_FACTOR_100P
},
731 { "mediaplayerSoundLevel3Hover",
732 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
733 { "mediaplayerSoundLevel3Down",
734 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
735 { "mediaplayerSoundLevel2",
736 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON
, ui::SCALE_FACTOR_100P
},
737 { "mediaplayerSoundLevel2Hover",
738 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
739 { "mediaplayerSoundLevel2Down",
740 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
741 { "mediaplayerSoundLevel1",
742 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON
, ui::SCALE_FACTOR_100P
},
743 { "mediaplayerSoundLevel1Hover",
744 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
745 { "mediaplayerSoundLevel1Down",
746 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
747 { "mediaplayerSoundLevel0",
748 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON
, ui::SCALE_FACTOR_100P
},
749 { "mediaplayerSoundLevel0Hover",
750 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
751 { "mediaplayerSoundLevel0Down",
752 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
753 { "mediaplayerSoundDisabled",
754 IDR_MEDIAPLAYER_SOUND_DISABLED
, ui::SCALE_FACTOR_100P
},
755 { "mediaplayerSliderThumb",
756 IDR_MEDIAPLAYER_SLIDER_THUMB
, ui::SCALE_FACTOR_100P
},
757 { "mediaplayerSliderThumbHover",
758 IDR_MEDIAPLAYER_SLIDER_THUMB_HOVER
, ui::SCALE_FACTOR_100P
},
759 { "mediaplayerSliderThumbDown",
760 IDR_MEDIAPLAYER_SLIDER_THUMB_DOWN
, ui::SCALE_FACTOR_100P
},
761 { "mediaplayerVolumeSliderThumb",
762 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB
, ui::SCALE_FACTOR_100P
},
763 { "mediaplayerVolumeSliderThumbHover",
764 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_HOVER
, ui::SCALE_FACTOR_100P
},
765 { "mediaplayerVolumeSliderThumbDown",
766 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DOWN
, ui::SCALE_FACTOR_100P
},
767 { "mediaplayerVolumeSliderThumbDisabled",
768 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DISABLED
, ui::SCALE_FACTOR_100P
},
769 { "mediaplayerClosedCaption",
770 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON
, ui::SCALE_FACTOR_100P
},
771 { "mediaplayerClosedCaptionHover",
772 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
773 { "mediaplayerClosedCaptionDown",
774 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
775 { "mediaplayerClosedCaptionDisabled",
776 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DISABLED
, ui::SCALE_FACTOR_100P
},
777 { "mediaplayerFullscreen",
778 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON
, ui::SCALE_FACTOR_100P
},
779 { "mediaplayerFullscreenHover",
780 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_HOVER
, ui::SCALE_FACTOR_100P
},
781 { "mediaplayerFullscreenDown",
782 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DOWN
, ui::SCALE_FACTOR_100P
},
783 { "mediaplayerCastOff",
784 IDR_MEDIAPLAYER_CAST_BUTTON_OFF
, ui::SCALE_FACTOR_100P
},
785 { "mediaplayerCastOn",
786 IDR_MEDIAPLAYER_CAST_BUTTON_ON
, ui::SCALE_FACTOR_100P
},
787 { "mediaplayerFullscreenDisabled",
788 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DISABLED
, ui::SCALE_FACTOR_100P
},
789 { "mediaplayerOverlayPlay",
790 IDR_MEDIAPLAYER_OVERLAY_PLAY_BUTTON
, ui::SCALE_FACTOR_100P
},
791 #if defined(OS_MACOSX)
792 { "overhangPattern", IDR_OVERHANG_PATTERN
, ui::SCALE_FACTOR_100P
},
793 { "overhangShadow", IDR_OVERHANG_SHADOW
, ui::SCALE_FACTOR_100P
},
795 { "panIcon", IDR_PAN_SCROLL_ICON
, ui::SCALE_FACTOR_100P
},
796 { "searchCancel", IDR_SEARCH_CANCEL
, ui::SCALE_FACTOR_100P
},
797 { "searchCancelPressed", IDR_SEARCH_CANCEL_PRESSED
, ui::SCALE_FACTOR_100P
},
798 { "searchMagnifier", IDR_SEARCH_MAGNIFIER
, ui::SCALE_FACTOR_100P
},
799 { "searchMagnifierResults",
800 IDR_SEARCH_MAGNIFIER_RESULTS
, ui::SCALE_FACTOR_100P
},
801 { "textAreaResizeCorner", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_100P
},
802 { "textAreaResizeCorner@2x", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_200P
},
803 { "generatePassword", IDR_PASSWORD_GENERATION_ICON
, ui::SCALE_FACTOR_100P
},
804 { "generatePasswordHover",
805 IDR_PASSWORD_GENERATION_ICON_HOVER
, ui::SCALE_FACTOR_100P
},
806 { "html.css", IDR_UASTYLE_HTML_CSS
, ui::SCALE_FACTOR_NONE
},
807 { "quirks.css", IDR_UASTYLE_QUIRKS_CSS
, ui::SCALE_FACTOR_NONE
},
808 { "view-source.css", IDR_UASTYLE_VIEW_SOURCE_CSS
, ui::SCALE_FACTOR_NONE
},
809 { "themeChromium.css", IDR_UASTYLE_THEME_CHROMIUM_CSS
,
810 ui::SCALE_FACTOR_NONE
},
811 #if defined(OS_ANDROID)
812 { "themeChromiumAndroid.css", IDR_UASTYLE_THEME_CHROMIUM_ANDROID_CSS
,
813 ui::SCALE_FACTOR_NONE
},
814 { "mediaControlsAndroid.css", IDR_UASTYLE_MEDIA_CONTROLS_ANDROID_CSS
,
815 ui::SCALE_FACTOR_NONE
},
818 { "themeChromiumLinux.css", IDR_UASTYLE_THEME_CHROMIUM_LINUX_CSS
,
819 ui::SCALE_FACTOR_NONE
},
821 { "themeChromiumSkia.css", IDR_UASTYLE_THEME_CHROMIUM_SKIA_CSS
,
822 ui::SCALE_FACTOR_NONE
},
823 { "themeInputMultipleFields.css",
824 IDR_UASTYLE_THEME_INPUT_MULTIPLE_FIELDS_CSS
, ui::SCALE_FACTOR_NONE
},
825 #if defined(OS_MACOSX)
826 { "themeMac.css", IDR_UASTYLE_THEME_MAC_CSS
, ui::SCALE_FACTOR_NONE
},
828 { "themeWin.css", IDR_UASTYLE_THEME_WIN_CSS
, ui::SCALE_FACTOR_NONE
},
829 { "themeWinQuirks.css", IDR_UASTYLE_THEME_WIN_QUIRKS_CSS
,
830 ui::SCALE_FACTOR_NONE
},
831 { "svg.css", IDR_UASTYLE_SVG_CSS
, ui::SCALE_FACTOR_NONE
},
832 { "navigationTransitions.css", IDR_UASTYLE_NAVIGATION_TRANSITIONS_CSS
,
833 ui::SCALE_FACTOR_NONE
},
834 { "mathml.css", IDR_UASTYLE_MATHML_CSS
, ui::SCALE_FACTOR_NONE
},
835 { "mediaControls.css", IDR_UASTYLE_MEDIA_CONTROLS_CSS
,
836 ui::SCALE_FACTOR_NONE
},
837 { "fullscreen.css", IDR_UASTYLE_FULLSCREEN_CSS
, ui::SCALE_FACTOR_NONE
},
838 { "xhtmlmp.css", IDR_UASTYLE_XHTMLMP_CSS
, ui::SCALE_FACTOR_NONE
},
839 { "viewportAndroid.css", IDR_UASTYLE_VIEWPORT_ANDROID_CSS
,
840 ui::SCALE_FACTOR_NONE
},
841 { "InspectorOverlayPage.html", IDR_INSPECTOR_OVERLAY_PAGE_HTML
,
842 ui::SCALE_FACTOR_NONE
},
843 { "InjectedScriptCanvasModuleSource.js",
844 IDR_INSPECTOR_INJECTED_SCRIPT_CANVAS_MODULE_SOURCE_JS
,
845 ui::SCALE_FACTOR_NONE
},
846 { "InjectedScriptSource.js", IDR_INSPECTOR_INJECTED_SCRIPT_SOURCE_JS
,
847 ui::SCALE_FACTOR_NONE
},
848 { "DebuggerScriptSource.js", IDR_INSPECTOR_DEBUGGER_SCRIPT_SOURCE_JS
,
849 ui::SCALE_FACTOR_NONE
},
850 { "DocumentExecCommand.js", IDR_PRIVATE_SCRIPT_DOCUMENTEXECCOMMAND_JS
,
851 ui::SCALE_FACTOR_NONE
},
852 { "DocumentXMLTreeViewer.js", IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_JS
,
853 ui::SCALE_FACTOR_NONE
},
854 { "HTMLMarqueeElement.js", IDR_PRIVATE_SCRIPT_HTMLMARQUEEELEMENT_JS
,
855 ui::SCALE_FACTOR_NONE
},
856 { "PluginPlaceholderElement.js",
857 IDR_PRIVATE_SCRIPT_PLUGINPLACEHOLDERELEMENT_JS
, ui::SCALE_FACTOR_NONE
},
858 { "PrivateScriptRunner.js", IDR_PRIVATE_SCRIPT_PRIVATESCRIPTRUNNER_JS
,
859 ui::SCALE_FACTOR_NONE
},
860 #ifdef IDR_PICKER_COMMON_JS
861 { "pickerCommon.js", IDR_PICKER_COMMON_JS
, ui::SCALE_FACTOR_NONE
},
862 { "pickerCommon.css", IDR_PICKER_COMMON_CSS
, ui::SCALE_FACTOR_NONE
},
863 { "calendarPicker.js", IDR_CALENDAR_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
864 { "calendarPicker.css", IDR_CALENDAR_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
865 { "pickerButton.css", IDR_PICKER_BUTTON_CSS
, ui::SCALE_FACTOR_NONE
},
866 { "suggestionPicker.js", IDR_SUGGESTION_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
867 { "suggestionPicker.css", IDR_SUGGESTION_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
868 { "colorSuggestionPicker.js",
869 IDR_COLOR_SUGGESTION_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
870 { "colorSuggestionPicker.css",
871 IDR_COLOR_SUGGESTION_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
877 WebData
BlinkPlatformImpl::loadResource(const char* name
) {
878 // Some clients will call into this method with an empty |name| when they have
879 // optional resources. For example, the PopupMenuChromium code can have icons
880 // for some Autofill items but not for others.
884 // Check the name prefix to see if it's an audio resource.
885 if (StartsWithASCII(name
, "IRC_Composite", true) ||
886 StartsWithASCII(name
, "Composite", true))
887 return loadAudioSpatializationResource(name
);
889 // TODO(flackr): We should use a better than linear search here, a trie would
891 for (size_t i
= 0; i
< arraysize(kDataResources
); ++i
) {
892 if (!strcmp(name
, kDataResources
[i
].name
)) {
893 base::StringPiece resource
= GetContentClient()->GetDataResource(
894 kDataResources
[i
].id
, kDataResources
[i
].scale_factor
);
895 return WebData(resource
.data(), resource
.size());
899 NOTREACHED() << "Unknown image resource " << name
;
903 WebString
BlinkPlatformImpl::queryLocalizedString(
904 WebLocalizedString::Name name
) {
905 int message_id
= ToMessageID(name
);
908 return GetContentClient()->GetLocalizedString(message_id
);
911 WebString
BlinkPlatformImpl::queryLocalizedString(
912 WebLocalizedString::Name name
, int numeric_value
) {
913 return queryLocalizedString(name
, base::IntToString16(numeric_value
));
916 WebString
BlinkPlatformImpl::queryLocalizedString(
917 WebLocalizedString::Name name
, const WebString
& value
) {
918 int message_id
= ToMessageID(name
);
921 return ReplaceStringPlaceholders(GetContentClient()->GetLocalizedString(
922 message_id
), value
, NULL
);
925 WebString
BlinkPlatformImpl::queryLocalizedString(
926 WebLocalizedString::Name name
,
927 const WebString
& value1
,
928 const WebString
& value2
) {
929 int message_id
= ToMessageID(name
);
932 std::vector
<base::string16
> values
;
934 values
.push_back(value1
);
935 values
.push_back(value2
);
936 return ReplaceStringPlaceholders(
937 GetContentClient()->GetLocalizedString(message_id
), values
, NULL
);
940 double BlinkPlatformImpl::currentTime() {
941 return base::Time::Now().ToDoubleT();
944 double BlinkPlatformImpl::monotonicallyIncreasingTime() {
945 return base::TimeTicks::Now().ToInternalValue() /
946 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
949 void BlinkPlatformImpl::cryptographicallyRandomValues(
950 unsigned char* buffer
, size_t length
) {
951 base::RandBytes(buffer
, length
);
954 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func
)()) {
955 shared_timer_func_
= func
;
958 void BlinkPlatformImpl::setSharedTimerFireInterval(
959 double interval_seconds
) {
960 shared_timer_fire_time_
= interval_seconds
+ monotonicallyIncreasingTime();
961 if (shared_timer_suspended_
) {
962 shared_timer_fire_time_was_set_while_suspended_
= true;
966 // By converting between double and int64 representation, we run the risk
967 // of losing precision due to rounding errors. Performing computations in
968 // microseconds reduces this risk somewhat. But there still is the potential
969 // of us computing a fire time for the timer that is shorter than what we
971 // As the event loop will check event deadlines prior to actually firing
972 // them, there is a risk of needlessly rescheduling events and of
973 // needlessly looping if sleep times are too short even by small amounts.
974 // This results in measurable performance degradation unless we use ceil() to
975 // always round up the sleep times.
976 int64 interval
= static_cast<int64
>(
977 ceil(interval_seconds
* base::Time::kMillisecondsPerSecond
)
978 * base::Time::kMicrosecondsPerMillisecond
);
983 shared_timer_
.Stop();
984 shared_timer_
.Start(FROM_HERE
, base::TimeDelta::FromMicroseconds(interval
),
985 this, &BlinkPlatformImpl::DoTimeout
);
986 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval
));
989 void BlinkPlatformImpl::stopSharedTimer() {
990 shared_timer_
.Stop();
993 void BlinkPlatformImpl::callOnMainThread(
994 void (*func
)(void*), void* context
) {
995 main_loop_
->PostTask(FROM_HERE
, base::Bind(func
, context
));
998 blink::WebGestureCurve
* BlinkPlatformImpl::createFlingAnimationCurve(
999 blink::WebGestureDevice device_source
,
1000 const blink::WebFloatPoint
& velocity
,
1001 const blink::WebSize
& cumulative_scroll
) {
1002 auto curve
= WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
1003 gfx::Vector2dF(velocity
.x
, velocity
.y
),
1004 gfx::Vector2dF(cumulative_scroll
.width
, cumulative_scroll
.height
));
1005 return curve
.release();
1008 void BlinkPlatformImpl::didStartWorkerRunLoop(
1009 const blink::WebWorkerRunLoop
& runLoop
) {
1010 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
1011 worker_task_runner
->OnWorkerRunLoopStarted(runLoop
);
1014 void BlinkPlatformImpl::didStopWorkerRunLoop(
1015 const blink::WebWorkerRunLoop
& runLoop
) {
1016 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
1017 worker_task_runner
->OnWorkerRunLoopStopped(runLoop
);
1020 blink::WebCrypto
* BlinkPlatformImpl::crypto() {
1021 return &web_crypto_
;
1024 blink::WebGeofencingProvider
* BlinkPlatformImpl::geofencingProvider() {
1025 return geofencing_provider_
.get();
1028 blink::WebNotificationManager
*
1029 BlinkPlatformImpl::notificationManager() {
1030 if (!thread_safe_sender_
.get() || !notification_dispatcher_
.get())
1033 return NotificationManager::ThreadSpecificInstance(
1034 thread_safe_sender_
.get(),
1035 notification_dispatcher_
.get());
1038 WebThemeEngine
* BlinkPlatformImpl::themeEngine() {
1039 return &native_theme_engine_
;
1042 WebFallbackThemeEngine
* BlinkPlatformImpl::fallbackThemeEngine() {
1043 return &fallback_theme_engine_
;
1046 blink::Platform::FileHandle
BlinkPlatformImpl::databaseOpenFile(
1047 const blink::WebString
& vfs_file_name
, int desired_flags
) {
1049 return INVALID_HANDLE_VALUE
;
1050 #elif defined(OS_POSIX)
1055 int BlinkPlatformImpl::databaseDeleteFile(
1056 const blink::WebString
& vfs_file_name
, bool sync_dir
) {
1060 long BlinkPlatformImpl::databaseGetFileAttributes(
1061 const blink::WebString
& vfs_file_name
) {
1065 long long BlinkPlatformImpl::databaseGetFileSize(
1066 const blink::WebString
& vfs_file_name
) {
1070 long long BlinkPlatformImpl::databaseGetSpaceAvailableForOrigin(
1071 const blink::WebString
& origin_identifier
) {
1075 blink::WebString
BlinkPlatformImpl::signedPublicKeyAndChallengeString(
1076 unsigned key_size_index
,
1077 const blink::WebString
& challenge
,
1078 const blink::WebURL
& url
) {
1079 return blink::WebString("");
1082 static scoped_ptr
<base::ProcessMetrics
> CurrentProcessMetrics() {
1083 using base::ProcessMetrics
;
1084 #if defined(OS_MACOSX)
1085 return scoped_ptr
<ProcessMetrics
>(
1086 // The default port provider is sufficient to get data for the current
1088 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
1091 return scoped_ptr
<ProcessMetrics
>(
1092 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()));
1096 static size_t getMemoryUsageMB(bool bypass_cache
) {
1097 size_t current_mem_usage
= 0;
1098 MemoryUsageCache
* mem_usage_cache_singleton
= MemoryUsageCache::GetInstance();
1099 if (!bypass_cache
&&
1100 mem_usage_cache_singleton
->IsCachedValueValid(¤t_mem_usage
))
1101 return current_mem_usage
;
1103 current_mem_usage
= GetMemoryUsageKB() >> 10;
1104 mem_usage_cache_singleton
->SetMemoryValue(current_mem_usage
);
1105 return current_mem_usage
;
1108 size_t BlinkPlatformImpl::memoryUsageMB() {
1109 return getMemoryUsageMB(false);
1112 size_t BlinkPlatformImpl::actualMemoryUsageMB() {
1113 return getMemoryUsageMB(true);
1116 size_t BlinkPlatformImpl::physicalMemoryMB() {
1117 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
1120 size_t BlinkPlatformImpl::virtualMemoryLimitMB() {
1121 return static_cast<size_t>(base::SysInfo::AmountOfVirtualMemoryMB());
1124 size_t BlinkPlatformImpl::numberOfProcessors() {
1125 return static_cast<size_t>(base::SysInfo::NumberOfProcessors());
1128 void BlinkPlatformImpl::startHeapProfiling(
1129 const blink::WebString
& prefix
) {
1130 // FIXME(morrita): Make this built on windows.
1131 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1132 HeapProfilerStart(prefix
.utf8().data());
1136 void BlinkPlatformImpl::stopHeapProfiling() {
1137 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1142 void BlinkPlatformImpl::dumpHeapProfiling(
1143 const blink::WebString
& reason
) {
1144 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1145 HeapProfilerDump(reason
.utf8().data());
1149 WebString
BlinkPlatformImpl::getHeapProfile() {
1150 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN)
1151 char* data
= GetHeapProfile();
1152 WebString result
= WebString::fromUTF8(std::string(data
));
1160 bool BlinkPlatformImpl::processMemorySizesInBytes(
1161 size_t* private_bytes
,
1162 size_t* shared_bytes
) {
1163 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes
, shared_bytes
);
1166 bool BlinkPlatformImpl::memoryAllocatorWasteInBytes(size_t* size
) {
1167 return base::allocator::GetAllocatorWasteSize(size
);
1170 blink::WebDiscardableMemory
*
1171 BlinkPlatformImpl::allocateAndLockDiscardableMemory(size_t bytes
) {
1172 base::DiscardableMemoryType type
=
1173 base::DiscardableMemory::GetPreferredType();
1174 if (type
== base::DISCARDABLE_MEMORY_TYPE_EMULATED
)
1176 return content::WebDiscardableMemoryImpl::CreateLockedMemory(bytes
).release();
1179 size_t BlinkPlatformImpl::maxDecodedImageBytes() {
1180 #if defined(OS_ANDROID)
1181 if (base::SysInfo::IsLowEndDevice()) {
1182 // Limit image decoded size to 3M pixels on low end devices.
1183 // 4 is maximum number of bytes per pixel.
1184 return 3 * 1024 * 1024 * 4;
1186 // For other devices, limit decoded image size based on the amount of physical
1188 // In some cases all physical memory is not accessible by Chromium, as it can
1189 // be reserved for direct use by certain hardware. Thus, we set the limit so
1190 // that 1.6GB of reported physical memory on a 2GB device is enough to set the
1191 // limit at 16M pixels, which is a desirable value since 4K*4K is a relatively
1192 // common texture size.
1193 return base::SysInfo::AmountOfPhysicalMemory() / 25;
1195 return noDecodedImageByteLimit
;
1199 void BlinkPlatformImpl::SuspendSharedTimer() {
1200 ++shared_timer_suspended_
;
1203 void BlinkPlatformImpl::ResumeSharedTimer() {
1204 DCHECK_GT(shared_timer_suspended_
, 0);
1206 // The shared timer may have fired or been adjusted while we were suspended.
1207 if (--shared_timer_suspended_
== 0 &&
1208 (!shared_timer_
.IsRunning() ||
1209 shared_timer_fire_time_was_set_while_suspended_
)) {
1210 shared_timer_fire_time_was_set_while_suspended_
= false;
1211 setSharedTimerFireInterval(
1212 shared_timer_fire_time_
- monotonicallyIncreasingTime());
1217 void BlinkPlatformImpl::DestroyCurrentThread(void* thread
) {
1218 WebThreadImplForMessageLoop
* impl
=
1219 static_cast<WebThreadImplForMessageLoop
*>(thread
);
1223 } // namespace content