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/metrics/histogram.h"
17 #include "base/metrics/sparse_histogram.h"
18 #include "base/process/process_metrics.h"
19 #include "base/rand_util.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "base/synchronization/lock.h"
24 #include "base/synchronization/waitable_event.h"
25 #include "base/sys_info.h"
26 #include "base/threading/platform_thread.h"
27 #include "base/time/time.h"
28 #include "blink/public/resources/grit/blink_image_resources.h"
29 #include "blink/public/resources/grit/blink_resources.h"
30 #include "content/app/resources/grit/content_resources.h"
31 #include "content/app/strings/grit/content_strings.h"
32 #include "content/child/bluetooth/web_bluetooth_impl.h"
33 #include "content/child/child_thread_impl.h"
34 #include "content/child/content_child_helpers.h"
35 #include "content/child/geofencing/web_geofencing_provider_impl.h"
36 #include "content/child/navigator_connect/navigator_connect_provider.h"
37 #include "content/child/notifications/notification_dispatcher.h"
38 #include "content/child/notifications/notification_manager.h"
39 #include "content/child/permissions/permission_dispatcher.h"
40 #include "content/child/permissions/permission_dispatcher_thread_proxy.h"
41 #include "content/child/push_messaging/push_dispatcher.h"
42 #include "content/child/push_messaging/push_provider.h"
43 #include "content/child/thread_safe_sender.h"
44 #include "content/child/web_discardable_memory_impl.h"
45 #include "content/child/web_url_loader_impl.h"
46 #include "content/child/websocket_bridge.h"
47 #include "content/child/webthread_impl.h"
48 #include "content/child/worker_task_runner.h"
49 #include "content/public/common/content_client.h"
50 #include "net/base/data_url.h"
51 #include "net/base/mime_util.h"
52 #include "net/base/net_errors.h"
53 #include "net/base/net_util.h"
54 #include "third_party/WebKit/public/platform/WebConvertableToTraceFormat.h"
55 #include "third_party/WebKit/public/platform/WebData.h"
56 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
57 #include "third_party/WebKit/public/platform/WebString.h"
58 #include "third_party/WebKit/public/platform/WebURL.h"
59 #include "third_party/WebKit/public/platform/WebWaitableEvent.h"
60 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
61 #include "ui/base/layout.h"
62 #include "ui/events/gestures/blink/web_gesture_curve_impl.h"
63 #include "ui/events/keycodes/dom4/keycode_converter.h"
66 using blink::WebFallbackThemeEngine
;
67 using blink::WebLocalizedString
;
68 using blink::WebString
;
69 using blink::WebThemeEngine
;
71 using blink::WebURLError
;
72 using blink::WebURLLoader
;
78 class WebWaitableEventImpl
: public blink::WebWaitableEvent
{
80 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {}
81 virtual ~WebWaitableEventImpl() {}
83 virtual void wait() { impl_
->Wait(); }
84 virtual void signal() { impl_
->Signal(); }
86 base::WaitableEvent
* impl() {
91 scoped_ptr
<base::WaitableEvent
> impl_
;
92 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl
);
95 // A simple class to cache the memory usage for a given amount of time.
96 class MemoryUsageCache
{
98 // Retrieves the Singleton.
99 static MemoryUsageCache
* GetInstance() {
100 return Singleton
<MemoryUsageCache
>::get();
103 MemoryUsageCache() : memory_value_(0) { Init(); }
104 ~MemoryUsageCache() {}
107 const unsigned int kCacheSeconds
= 1;
108 cache_valid_time_
= base::TimeDelta::FromSeconds(kCacheSeconds
);
111 // Returns true if the cached value is fresh.
112 // Returns false if the cached value is stale, or if |cached_value| is NULL.
113 bool IsCachedValueValid(size_t* cached_value
) {
114 base::AutoLock
scoped_lock(lock_
);
117 if (base::Time::Now() - last_updated_time_
> cache_valid_time_
)
119 *cached_value
= memory_value_
;
123 // Setter for |memory_value_|, refreshes |last_updated_time_|.
124 void SetMemoryValue(const size_t value
) {
125 base::AutoLock
scoped_lock(lock_
);
126 memory_value_
= value
;
127 last_updated_time_
= base::Time::Now();
131 // The cached memory value.
132 size_t memory_value_
;
134 // How long the cached value should remain valid.
135 base::TimeDelta cache_valid_time_
;
137 // The last time the cached value was updated.
138 base::Time last_updated_time_
;
143 class ConvertableToTraceFormatWrapper
144 : public base::trace_event::ConvertableToTraceFormat
{
146 explicit ConvertableToTraceFormatWrapper(
147 const blink::WebConvertableToTraceFormat
& convertable
)
148 : convertable_(convertable
) {}
149 void AppendAsTraceFormat(std::string
* out
) const override
{
150 *out
+= convertable_
.asTraceFormat().utf8();
154 ~ConvertableToTraceFormatWrapper() override
{}
156 blink::WebConvertableToTraceFormat convertable_
;
161 static int ToMessageID(WebLocalizedString::Name name
) {
163 case WebLocalizedString::AXAMPMFieldText
:
164 return IDS_AX_AM_PM_FIELD_TEXT
;
165 case WebLocalizedString::AXButtonActionVerb
:
166 return IDS_AX_BUTTON_ACTION_VERB
;
167 case WebLocalizedString::AXCalendarShowMonthSelector
:
168 return IDS_AX_CALENDAR_SHOW_MONTH_SELECTOR
;
169 case WebLocalizedString::AXCalendarShowNextMonth
:
170 return IDS_AX_CALENDAR_SHOW_NEXT_MONTH
;
171 case WebLocalizedString::AXCalendarShowPreviousMonth
:
172 return IDS_AX_CALENDAR_SHOW_PREVIOUS_MONTH
;
173 case WebLocalizedString::AXCalendarWeekDescription
:
174 return IDS_AX_CALENDAR_WEEK_DESCRIPTION
;
175 case WebLocalizedString::AXCheckedCheckBoxActionVerb
:
176 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB
;
177 case WebLocalizedString::AXDateTimeFieldEmptyValueText
:
178 return IDS_AX_DATE_TIME_FIELD_EMPTY_VALUE_TEXT
;
179 case WebLocalizedString::AXDayOfMonthFieldText
:
180 return IDS_AX_DAY_OF_MONTH_FIELD_TEXT
;
181 case WebLocalizedString::AXHeadingText
:
182 return IDS_AX_ROLE_HEADING
;
183 case WebLocalizedString::AXHourFieldText
:
184 return IDS_AX_HOUR_FIELD_TEXT
;
185 case WebLocalizedString::AXImageMapText
:
186 return IDS_AX_ROLE_IMAGE_MAP
;
187 case WebLocalizedString::AXLinkActionVerb
:
188 return IDS_AX_LINK_ACTION_VERB
;
189 case WebLocalizedString::AXLinkText
:
190 return IDS_AX_ROLE_LINK
;
191 case WebLocalizedString::AXListMarkerText
:
192 return IDS_AX_ROLE_LIST_MARKER
;
193 case WebLocalizedString::AXMediaDefault
:
194 return IDS_AX_MEDIA_DEFAULT
;
195 case WebLocalizedString::AXMediaAudioElement
:
196 return IDS_AX_MEDIA_AUDIO_ELEMENT
;
197 case WebLocalizedString::AXMediaVideoElement
:
198 return IDS_AX_MEDIA_VIDEO_ELEMENT
;
199 case WebLocalizedString::AXMediaMuteButton
:
200 return IDS_AX_MEDIA_MUTE_BUTTON
;
201 case WebLocalizedString::AXMediaUnMuteButton
:
202 return IDS_AX_MEDIA_UNMUTE_BUTTON
;
203 case WebLocalizedString::AXMediaPlayButton
:
204 return IDS_AX_MEDIA_PLAY_BUTTON
;
205 case WebLocalizedString::AXMediaPauseButton
:
206 return IDS_AX_MEDIA_PAUSE_BUTTON
;
207 case WebLocalizedString::AXMediaSlider
:
208 return IDS_AX_MEDIA_SLIDER
;
209 case WebLocalizedString::AXMediaSliderThumb
:
210 return IDS_AX_MEDIA_SLIDER_THUMB
;
211 case WebLocalizedString::AXMediaCurrentTimeDisplay
:
212 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY
;
213 case WebLocalizedString::AXMediaTimeRemainingDisplay
:
214 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY
;
215 case WebLocalizedString::AXMediaStatusDisplay
:
216 return IDS_AX_MEDIA_STATUS_DISPLAY
;
217 case WebLocalizedString::AXMediaEnterFullscreenButton
:
218 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON
;
219 case WebLocalizedString::AXMediaExitFullscreenButton
:
220 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON
;
221 case WebLocalizedString::AXMediaShowClosedCaptionsButton
:
222 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON
;
223 case WebLocalizedString::AXMediaHideClosedCaptionsButton
:
224 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON
;
225 case WebLocalizedString::AxMediaCastOffButton
:
226 return IDS_AX_MEDIA_CAST_OFF_BUTTON
;
227 case WebLocalizedString::AxMediaCastOnButton
:
228 return IDS_AX_MEDIA_CAST_ON_BUTTON
;
229 case WebLocalizedString::AXMediaAudioElementHelp
:
230 return IDS_AX_MEDIA_AUDIO_ELEMENT_HELP
;
231 case WebLocalizedString::AXMediaVideoElementHelp
:
232 return IDS_AX_MEDIA_VIDEO_ELEMENT_HELP
;
233 case WebLocalizedString::AXMediaMuteButtonHelp
:
234 return IDS_AX_MEDIA_MUTE_BUTTON_HELP
;
235 case WebLocalizedString::AXMediaUnMuteButtonHelp
:
236 return IDS_AX_MEDIA_UNMUTE_BUTTON_HELP
;
237 case WebLocalizedString::AXMediaPlayButtonHelp
:
238 return IDS_AX_MEDIA_PLAY_BUTTON_HELP
;
239 case WebLocalizedString::AXMediaPauseButtonHelp
:
240 return IDS_AX_MEDIA_PAUSE_BUTTON_HELP
;
241 case WebLocalizedString::AXMediaAudioSliderHelp
:
242 return IDS_AX_MEDIA_AUDIO_SLIDER_HELP
;
243 case WebLocalizedString::AXMediaVideoSliderHelp
:
244 return IDS_AX_MEDIA_VIDEO_SLIDER_HELP
;
245 case WebLocalizedString::AXMediaSliderThumbHelp
:
246 return IDS_AX_MEDIA_SLIDER_THUMB_HELP
;
247 case WebLocalizedString::AXMediaCurrentTimeDisplayHelp
:
248 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY_HELP
;
249 case WebLocalizedString::AXMediaTimeRemainingDisplayHelp
:
250 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY_HELP
;
251 case WebLocalizedString::AXMediaStatusDisplayHelp
:
252 return IDS_AX_MEDIA_STATUS_DISPLAY_HELP
;
253 case WebLocalizedString::AXMediaEnterFullscreenButtonHelp
:
254 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON_HELP
;
255 case WebLocalizedString::AXMediaExitFullscreenButtonHelp
:
256 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON_HELP
;
257 case WebLocalizedString::AXMediaShowClosedCaptionsButtonHelp
:
258 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON_HELP
;
259 case WebLocalizedString::AXMediaHideClosedCaptionsButtonHelp
:
260 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON_HELP
;
261 case WebLocalizedString::AxMediaCastOffButtonHelp
:
262 return IDS_AX_MEDIA_CAST_OFF_BUTTON_HELP
;
263 case WebLocalizedString::AxMediaCastOnButtonHelp
:
264 return IDS_AX_MEDIA_CAST_ON_BUTTON_HELP
;
265 case WebLocalizedString::AXMillisecondFieldText
:
266 return IDS_AX_MILLISECOND_FIELD_TEXT
;
267 case WebLocalizedString::AXMinuteFieldText
:
268 return IDS_AX_MINUTE_FIELD_TEXT
;
269 case WebLocalizedString::AXMonthFieldText
:
270 return IDS_AX_MONTH_FIELD_TEXT
;
271 case WebLocalizedString::AXRadioButtonActionVerb
:
272 return IDS_AX_RADIO_BUTTON_ACTION_VERB
;
273 case WebLocalizedString::AXSecondFieldText
:
274 return IDS_AX_SECOND_FIELD_TEXT
;
275 case WebLocalizedString::AXTextFieldActionVerb
:
276 return IDS_AX_TEXT_FIELD_ACTION_VERB
;
277 case WebLocalizedString::AXUncheckedCheckBoxActionVerb
:
278 return IDS_AX_UNCHECKED_CHECK_BOX_ACTION_VERB
;
279 case WebLocalizedString::AXWebAreaText
:
280 return IDS_AX_ROLE_WEB_AREA
;
281 case WebLocalizedString::AXWeekOfYearFieldText
:
282 return IDS_AX_WEEK_OF_YEAR_FIELD_TEXT
;
283 case WebLocalizedString::AXYearFieldText
:
284 return IDS_AX_YEAR_FIELD_TEXT
;
285 case WebLocalizedString::CalendarClear
:
286 return IDS_FORM_CALENDAR_CLEAR
;
287 case WebLocalizedString::CalendarToday
:
288 return IDS_FORM_CALENDAR_TODAY
;
289 case WebLocalizedString::DateFormatDayInMonthLabel
:
290 return IDS_FORM_DATE_FORMAT_DAY_IN_MONTH
;
291 case WebLocalizedString::DateFormatMonthLabel
:
292 return IDS_FORM_DATE_FORMAT_MONTH
;
293 case WebLocalizedString::DateFormatYearLabel
:
294 return IDS_FORM_DATE_FORMAT_YEAR
;
295 case WebLocalizedString::DetailsLabel
:
296 return IDS_DETAILS_WITHOUT_SUMMARY_LABEL
;
297 case WebLocalizedString::FileButtonChooseFileLabel
:
298 return IDS_FORM_FILE_BUTTON_LABEL
;
299 case WebLocalizedString::FileButtonChooseMultipleFilesLabel
:
300 return IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL
;
301 case WebLocalizedString::FileButtonNoFileSelectedLabel
:
302 return IDS_FORM_FILE_NO_FILE_LABEL
;
303 case WebLocalizedString::InputElementAltText
:
304 return IDS_FORM_INPUT_ALT
;
305 case WebLocalizedString::KeygenMenuHighGradeKeySize
:
306 return IDS_KEYGEN_HIGH_GRADE_KEY
;
307 case WebLocalizedString::KeygenMenuMediumGradeKeySize
:
308 return IDS_KEYGEN_MED_GRADE_KEY
;
309 case WebLocalizedString::MissingPluginText
:
310 return IDS_PLUGIN_INITIALIZATION_ERROR
;
311 case WebLocalizedString::MultipleFileUploadText
:
312 return IDS_FORM_FILE_MULTIPLE_UPLOAD
;
313 case WebLocalizedString::OtherColorLabel
:
314 return IDS_FORM_OTHER_COLOR_LABEL
;
315 case WebLocalizedString::OtherDateLabel
:
316 return IDS_FORM_OTHER_DATE_LABEL
;
317 case WebLocalizedString::OtherMonthLabel
:
318 return IDS_FORM_OTHER_MONTH_LABEL
;
319 case WebLocalizedString::OtherTimeLabel
:
320 return IDS_FORM_OTHER_TIME_LABEL
;
321 case WebLocalizedString::OtherWeekLabel
:
322 return IDS_FORM_OTHER_WEEK_LABEL
;
323 case WebLocalizedString::PlaceholderForDayOfMonthField
:
324 return IDS_FORM_PLACEHOLDER_FOR_DAY_OF_MONTH_FIELD
;
325 case WebLocalizedString::PlaceholderForMonthField
:
326 return IDS_FORM_PLACEHOLDER_FOR_MONTH_FIELD
;
327 case WebLocalizedString::PlaceholderForYearField
:
328 return IDS_FORM_PLACEHOLDER_FOR_YEAR_FIELD
;
329 case WebLocalizedString::ResetButtonDefaultLabel
:
330 return IDS_FORM_RESET_LABEL
;
331 case WebLocalizedString::SearchableIndexIntroduction
:
332 return IDS_SEARCHABLE_INDEX_INTRO
;
333 case WebLocalizedString::SearchMenuClearRecentSearchesText
:
334 return IDS_RECENT_SEARCHES_CLEAR
;
335 case WebLocalizedString::SearchMenuNoRecentSearchesText
:
336 return IDS_RECENT_SEARCHES_NONE
;
337 case WebLocalizedString::SearchMenuRecentSearchesText
:
338 return IDS_RECENT_SEARCHES
;
339 case WebLocalizedString::SelectMenuListText
:
340 return IDS_FORM_SELECT_MENU_LIST_TEXT
;
341 case WebLocalizedString::SubmitButtonDefaultLabel
:
342 return IDS_FORM_SUBMIT_LABEL
;
343 case WebLocalizedString::ThisMonthButtonLabel
:
344 return IDS_FORM_THIS_MONTH_LABEL
;
345 case WebLocalizedString::ThisWeekButtonLabel
:
346 return IDS_FORM_THIS_WEEK_LABEL
;
347 case WebLocalizedString::ValidationBadInputForDateTime
:
348 return IDS_FORM_VALIDATION_BAD_INPUT_DATETIME
;
349 case WebLocalizedString::ValidationBadInputForNumber
:
350 return IDS_FORM_VALIDATION_BAD_INPUT_NUMBER
;
351 case WebLocalizedString::ValidationPatternMismatch
:
352 return IDS_FORM_VALIDATION_PATTERN_MISMATCH
;
353 case WebLocalizedString::ValidationRangeOverflow
:
354 return IDS_FORM_VALIDATION_RANGE_OVERFLOW
;
355 case WebLocalizedString::ValidationRangeOverflowDateTime
:
356 return IDS_FORM_VALIDATION_RANGE_OVERFLOW_DATETIME
;
357 case WebLocalizedString::ValidationRangeUnderflow
:
358 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW
;
359 case WebLocalizedString::ValidationRangeUnderflowDateTime
:
360 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW_DATETIME
;
361 case WebLocalizedString::ValidationStepMismatch
:
362 return IDS_FORM_VALIDATION_STEP_MISMATCH
;
363 case WebLocalizedString::ValidationStepMismatchCloseToLimit
:
364 return IDS_FORM_VALIDATION_STEP_MISMATCH_CLOSE_TO_LIMIT
;
365 case WebLocalizedString::ValidationTooLong
:
366 return IDS_FORM_VALIDATION_TOO_LONG
;
367 case WebLocalizedString::ValidationTooShort
:
368 return IDS_FORM_VALIDATION_TOO_SHORT
;
369 case WebLocalizedString::ValidationTypeMismatch
:
370 return IDS_FORM_VALIDATION_TYPE_MISMATCH
;
371 case WebLocalizedString::ValidationTypeMismatchForEmail
:
372 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL
;
373 case WebLocalizedString::ValidationTypeMismatchForEmailEmpty
:
374 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY
;
375 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyDomain
:
376 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_DOMAIN
;
377 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyLocal
:
378 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_LOCAL
;
379 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDomain
:
380 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOMAIN
;
381 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDots
:
382 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOTS
;
383 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidLocal
:
384 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_LOCAL
;
385 case WebLocalizedString::ValidationTypeMismatchForEmailNoAtSign
:
386 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_NO_AT_SIGN
;
387 case WebLocalizedString::ValidationTypeMismatchForMultipleEmail
:
388 return IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL
;
389 case WebLocalizedString::ValidationTypeMismatchForURL
:
390 return IDS_FORM_VALIDATION_TYPE_MISMATCH_URL
;
391 case WebLocalizedString::ValidationValueMissing
:
392 return IDS_FORM_VALIDATION_VALUE_MISSING
;
393 case WebLocalizedString::ValidationValueMissingForCheckbox
:
394 return IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX
;
395 case WebLocalizedString::ValidationValueMissingForFile
:
396 return IDS_FORM_VALIDATION_VALUE_MISSING_FILE
;
397 case WebLocalizedString::ValidationValueMissingForMultipleFile
:
398 return IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE
;
399 case WebLocalizedString::ValidationValueMissingForRadio
:
400 return IDS_FORM_VALIDATION_VALUE_MISSING_RADIO
;
401 case WebLocalizedString::ValidationValueMissingForSelect
:
402 return IDS_FORM_VALIDATION_VALUE_MISSING_SELECT
;
403 case WebLocalizedString::WeekFormatTemplate
:
404 return IDS_FORM_INPUT_WEEK_TEMPLATE
;
405 case WebLocalizedString::WeekNumberLabel
:
406 return IDS_FORM_WEEK_NUMBER_LABEL
;
407 // This "default:" line exists to avoid compile warnings about enum
408 // coverage when we add a new symbol to WebLocalizedString.h in WebKit.
409 // After a planned WebKit patch is landed, we need to add a case statement
410 // for the added symbol here.
417 BlinkPlatformImpl::BlinkPlatformImpl()
418 : main_thread_task_runner_(base::MessageLoopProxy::current()),
419 shared_timer_func_(NULL
),
420 shared_timer_fire_time_(0.0),
421 shared_timer_fire_time_was_set_while_suspended_(false),
422 shared_timer_suspended_(0) {
426 BlinkPlatformImpl::BlinkPlatformImpl(
427 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
)
428 : main_thread_task_runner_(main_thread_task_runner
),
429 shared_timer_func_(NULL
),
430 shared_timer_fire_time_(0.0),
431 shared_timer_fire_time_was_set_while_suspended_(false),
432 shared_timer_suspended_(0) {
433 // TODO(alexclarke): Use c++11 delegated constructors when allowed.
437 void BlinkPlatformImpl::InternalInit() {
438 // ChildThread may not exist in some tests.
439 if (ChildThreadImpl::current()) {
440 geofencing_provider_
.reset(new WebGeofencingProviderImpl(
441 ChildThreadImpl::current()->thread_safe_sender()));
443 new WebBluetoothImpl(ChildThreadImpl::current()->thread_safe_sender()));
444 thread_safe_sender_
= ChildThreadImpl::current()->thread_safe_sender();
445 notification_dispatcher_
=
446 ChildThreadImpl::current()->notification_dispatcher();
447 push_dispatcher_
= ChildThreadImpl::current()->push_dispatcher();
448 permission_client_
.reset(new PermissionDispatcher(
449 ChildThreadImpl::current()->service_registry()));
452 if (main_thread_task_runner_
.get()) {
453 shared_timer_
.SetTaskRunner(main_thread_task_runner_
);
457 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread
* thread
) {
458 DCHECK(!current_thread_slot_
.Get());
459 current_thread_slot_
.Set(thread
);
462 BlinkPlatformImpl::~BlinkPlatformImpl() {
465 WebURLLoader
* BlinkPlatformImpl::createURLLoader() {
466 ChildThreadImpl
* child_thread
= ChildThreadImpl::current();
467 // There may be no child thread in RenderViewTests. These tests can still use
468 // data URLs to bypass the ResourceDispatcher.
469 return new WebURLLoaderImpl(
470 child_thread
? child_thread
->resource_dispatcher() : NULL
,
471 MainTaskRunnerForCurrentThread());
474 blink::WebSocketHandle
* BlinkPlatformImpl::createWebSocketHandle() {
475 return new WebSocketBridge
;
478 WebString
BlinkPlatformImpl::userAgent() {
479 return WebString::fromUTF8(GetContentClient()->GetUserAgent());
482 WebData
BlinkPlatformImpl::parseDataURL(const WebURL
& url
,
483 WebString
& mimetype_out
,
484 WebString
& charset_out
) {
485 std::string mime_type
, char_set
, data
;
486 if (net::DataURL::Parse(url
, &mime_type
, &char_set
, &data
)
487 && net::IsSupportedMimeType(mime_type
)) {
488 mimetype_out
= WebString::fromUTF8(mime_type
);
489 charset_out
= WebString::fromUTF8(char_set
);
495 WebURLError
BlinkPlatformImpl::cancelledError(
496 const WebURL
& unreachableURL
) const {
497 return WebURLLoaderImpl::CreateError(unreachableURL
, false, net::ERR_ABORTED
);
500 bool BlinkPlatformImpl::isReservedIPAddress(
501 const blink::WebString
& host
) const {
502 net::IPAddressNumber address
;
503 if (!net::ParseURLHostnameToNumber(host
.utf8(), &address
))
505 return net::IsIPAddressReserved(address
);
508 blink::WebThread
* BlinkPlatformImpl::createThread(const char* name
) {
509 WebThreadImpl
* thread
= new WebThreadImpl(name
);
510 thread
->TaskRunner()->PostTask(
511 FROM_HERE
, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS
,
512 base::Unretained(this), thread
));
516 blink::WebThread
* BlinkPlatformImpl::currentThread() {
517 return static_cast<blink::WebThread
*>(current_thread_slot_
.Get());
520 void BlinkPlatformImpl::yieldCurrentThread() {
521 base::PlatformThread::YieldCurrentThread();
524 blink::WebWaitableEvent
* BlinkPlatformImpl::createWaitableEvent() {
525 return new WebWaitableEventImpl();
528 blink::WebWaitableEvent
* BlinkPlatformImpl::waitMultipleEvents(
529 const blink::WebVector
<blink::WebWaitableEvent
*>& web_events
) {
530 std::vector
<base::WaitableEvent
*> events
;
531 for (size_t i
= 0; i
< web_events
.size(); ++i
)
532 events
.push_back(static_cast<WebWaitableEventImpl
*>(web_events
[i
])->impl());
533 size_t idx
= base::WaitableEvent::WaitMany(
534 vector_as_array(&events
), events
.size());
535 DCHECK_LT(idx
, web_events
.size());
536 return web_events
[idx
];
539 void BlinkPlatformImpl::decrementStatsCounter(const char* name
) {
542 void BlinkPlatformImpl::incrementStatsCounter(const char* name
) {
545 void BlinkPlatformImpl::histogramCustomCounts(
546 const char* name
, int sample
, int min
, int max
, int bucket_count
) {
547 // Copied from histogram macro, but without the static variable caching
548 // the histogram because name is dynamic.
549 base::HistogramBase
* counter
=
550 base::Histogram::FactoryGet(name
, min
, max
, bucket_count
,
551 base::HistogramBase::kUmaTargetedHistogramFlag
);
552 DCHECK_EQ(name
, counter
->histogram_name());
553 counter
->Add(sample
);
556 void BlinkPlatformImpl::histogramEnumeration(
557 const char* name
, int sample
, int boundary_value
) {
558 // Copied from histogram macro, but without the static variable caching
559 // the histogram because name is dynamic.
560 base::HistogramBase
* counter
=
561 base::LinearHistogram::FactoryGet(name
, 1, boundary_value
,
562 boundary_value
+ 1, base::HistogramBase::kUmaTargetedHistogramFlag
);
563 DCHECK_EQ(name
, counter
->histogram_name());
564 counter
->Add(sample
);
567 void BlinkPlatformImpl::histogramSparse(const char* name
, int sample
) {
568 // For sparse histograms, we can use the macro, as it does not incorporate a
570 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);
573 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag(
574 const char* category_group
) {
575 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
578 long* BlinkPlatformImpl::getTraceSamplingState(
579 const unsigned thread_bucket
) {
580 switch (thread_bucket
) {
582 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0));
584 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(1));
586 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(2));
588 NOTREACHED() << "Unknown thread bucket type.";
594 sizeof(blink::Platform::TraceEventHandle
) ==
595 sizeof(base::trace_event::TraceEventHandle
),
596 "TraceEventHandle types must be same size");
598 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
600 const unsigned char* category_group_enabled
,
602 unsigned long long id
,
605 const char** arg_names
,
606 const unsigned char* arg_types
,
607 const unsigned long long* arg_values
,
608 unsigned char flags
) {
609 base::TimeTicks timestamp_tt
= base::TimeTicks::FromInternalValue(
610 static_cast<int64
>(timestamp
* base::Time::kMicrosecondsPerSecond
));
611 base::trace_event::TraceEventHandle handle
=
612 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
613 phase
, category_group_enabled
, name
, id
,
614 base::PlatformThread::CurrentId(),
616 num_args
, arg_names
, arg_types
, arg_values
, NULL
, flags
);
617 blink::Platform::TraceEventHandle result
;
618 memcpy(&result
, &handle
, sizeof(result
));
622 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
624 const unsigned char* category_group_enabled
,
626 unsigned long long id
,
629 const char** arg_names
,
630 const unsigned char* arg_types
,
631 const unsigned long long* arg_values
,
632 const blink::WebConvertableToTraceFormat
* convertable_values
,
633 unsigned char flags
) {
634 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
635 convertable_wrappers
[2];
636 if (convertable_values
) {
637 size_t size
= std::min(static_cast<size_t>(num_args
),
638 arraysize(convertable_wrappers
));
639 for (size_t i
= 0; i
< size
; ++i
) {
640 if (arg_types
[i
] == TRACE_VALUE_TYPE_CONVERTABLE
) {
641 convertable_wrappers
[i
] =
642 new ConvertableToTraceFormatWrapper(convertable_values
[i
]);
646 base::TimeTicks timestamp_tt
= base::TimeTicks::FromInternalValue(
647 static_cast<int64
>(timestamp
* base::Time::kMicrosecondsPerSecond
));
648 base::trace_event::TraceEventHandle handle
=
649 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(phase
,
650 category_group_enabled
,
653 base::PlatformThread::CurrentId(),
659 convertable_wrappers
,
661 blink::Platform::TraceEventHandle result
;
662 memcpy(&result
, &handle
, sizeof(result
));
666 void BlinkPlatformImpl::updateTraceEventDuration(
667 const unsigned char* category_group_enabled
,
669 TraceEventHandle handle
) {
670 base::trace_event::TraceEventHandle traceEventHandle
;
671 memcpy(&traceEventHandle
, &handle
, sizeof(handle
));
672 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
673 category_group_enabled
, name
, traceEventHandle
);
678 WebData
loadAudioSpatializationResource(const char* name
) {
679 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE
680 if (!strcmp(name
, "Composite")) {
681 base::StringPiece resource
= GetContentClient()->GetDataResource(
682 IDR_AUDIO_SPATIALIZATION_COMPOSITE
, ui::SCALE_FACTOR_NONE
);
683 return WebData(resource
.data(), resource
.size());
687 #ifdef IDR_AUDIO_SPATIALIZATION_T000_P000
688 const size_t kExpectedSpatializationNameLength
= 31;
689 if (strlen(name
) != kExpectedSpatializationNameLength
) {
693 // Extract the azimuth and elevation from the resource name.
697 sscanf(name
, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth
, &elevation
);
698 if (values_parsed
!= 2) {
702 // The resource index values go through the elevations first, then azimuths.
703 const int kAngleSpacing
= 15;
705 // 0 <= elevation <= 90 (or 315 <= elevation <= 345)
706 // in increments of 15 degrees.
707 int elevation_index
=
708 elevation
<= 90 ? elevation
/ kAngleSpacing
:
709 7 + (elevation
- 315) / kAngleSpacing
;
710 bool is_elevation_index_good
= 0 <= elevation_index
&& elevation_index
< 10;
712 // 0 <= azimuth < 360 in increments of 15 degrees.
713 int azimuth_index
= azimuth
/ kAngleSpacing
;
714 bool is_azimuth_index_good
= 0 <= azimuth_index
&& azimuth_index
< 24;
716 const int kNumberOfElevations
= 10;
717 const int kNumberOfAudioResources
= 240;
718 int resource_index
= kNumberOfElevations
* azimuth_index
+ elevation_index
;
719 bool is_resource_index_good
= 0 <= resource_index
&&
720 resource_index
< kNumberOfAudioResources
;
722 if (is_azimuth_index_good
&& is_elevation_index_good
&&
723 is_resource_index_good
) {
724 const int kFirstAudioResourceIndex
= IDR_AUDIO_SPATIALIZATION_T000_P000
;
725 base::StringPiece resource
= GetContentClient()->GetDataResource(
726 kFirstAudioResourceIndex
+ resource_index
, ui::SCALE_FACTOR_NONE
);
727 return WebData(resource
.data(), resource
.size());
729 #endif // IDR_AUDIO_SPATIALIZATION_T000_P000
735 struct DataResource
{
738 ui::ScaleFactor scale_factor
;
741 const DataResource kDataResources
[] = {
742 {"missingImage", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_100P
},
743 {"missingImage@2x", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_200P
},
744 {"mediaplayerPause", IDR_MEDIAPLAYER_PAUSE_BUTTON
, ui::SCALE_FACTOR_100P
},
745 {"mediaplayerPauseHover",
746 IDR_MEDIAPLAYER_PAUSE_BUTTON_HOVER
,
747 ui::SCALE_FACTOR_100P
},
748 {"mediaplayerPauseDown",
749 IDR_MEDIAPLAYER_PAUSE_BUTTON_DOWN
,
750 ui::SCALE_FACTOR_100P
},
751 {"mediaplayerPlay", IDR_MEDIAPLAYER_PLAY_BUTTON
, ui::SCALE_FACTOR_100P
},
752 {"mediaplayerPlayHover",
753 IDR_MEDIAPLAYER_PLAY_BUTTON_HOVER
,
754 ui::SCALE_FACTOR_100P
},
755 {"mediaplayerPlayDown",
756 IDR_MEDIAPLAYER_PLAY_BUTTON_DOWN
,
757 ui::SCALE_FACTOR_100P
},
758 {"mediaplayerPlayDisabled",
759 IDR_MEDIAPLAYER_PLAY_BUTTON_DISABLED
,
760 ui::SCALE_FACTOR_100P
},
761 {"mediaplayerSoundLevel3",
762 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON
,
763 ui::SCALE_FACTOR_100P
},
764 {"mediaplayerSoundLevel3Hover",
765 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_HOVER
,
766 ui::SCALE_FACTOR_100P
},
767 {"mediaplayerSoundLevel3Down",
768 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_DOWN
,
769 ui::SCALE_FACTOR_100P
},
770 {"mediaplayerSoundLevel2",
771 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON
,
772 ui::SCALE_FACTOR_100P
},
773 {"mediaplayerSoundLevel2Hover",
774 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_HOVER
,
775 ui::SCALE_FACTOR_100P
},
776 {"mediaplayerSoundLevel2Down",
777 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_DOWN
,
778 ui::SCALE_FACTOR_100P
},
779 {"mediaplayerSoundLevel1",
780 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON
,
781 ui::SCALE_FACTOR_100P
},
782 {"mediaplayerSoundLevel1Hover",
783 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_HOVER
,
784 ui::SCALE_FACTOR_100P
},
785 {"mediaplayerSoundLevel1Down",
786 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_DOWN
,
787 ui::SCALE_FACTOR_100P
},
788 {"mediaplayerSoundLevel0",
789 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON
,
790 ui::SCALE_FACTOR_100P
},
791 {"mediaplayerSoundLevel0Hover",
792 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_HOVER
,
793 ui::SCALE_FACTOR_100P
},
794 {"mediaplayerSoundLevel0Down",
795 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_DOWN
,
796 ui::SCALE_FACTOR_100P
},
797 {"mediaplayerSoundDisabled",
798 IDR_MEDIAPLAYER_SOUND_DISABLED
,
799 ui::SCALE_FACTOR_100P
},
800 {"mediaplayerSliderThumb",
801 IDR_MEDIAPLAYER_SLIDER_THUMB
,
802 ui::SCALE_FACTOR_100P
},
803 {"mediaplayerSliderThumbHover",
804 IDR_MEDIAPLAYER_SLIDER_THUMB_HOVER
,
805 ui::SCALE_FACTOR_100P
},
806 {"mediaplayerSliderThumbDown",
807 IDR_MEDIAPLAYER_SLIDER_THUMB_DOWN
,
808 ui::SCALE_FACTOR_100P
},
809 {"mediaplayerVolumeSliderThumb",
810 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB
,
811 ui::SCALE_FACTOR_100P
},
812 {"mediaplayerVolumeSliderThumbHover",
813 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_HOVER
,
814 ui::SCALE_FACTOR_100P
},
815 {"mediaplayerVolumeSliderThumbDown",
816 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DOWN
,
817 ui::SCALE_FACTOR_100P
},
818 {"mediaplayerVolumeSliderThumbDisabled",
819 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DISABLED
,
820 ui::SCALE_FACTOR_100P
},
821 {"mediaplayerClosedCaption",
822 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON
,
823 ui::SCALE_FACTOR_100P
},
824 {"mediaplayerClosedCaptionHover",
825 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_HOVER
,
826 ui::SCALE_FACTOR_100P
},
827 {"mediaplayerClosedCaptionDown",
828 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DOWN
,
829 ui::SCALE_FACTOR_100P
},
830 {"mediaplayerClosedCaptionDisabled",
831 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DISABLED
,
832 ui::SCALE_FACTOR_100P
},
833 {"mediaplayerFullscreen",
834 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON
,
835 ui::SCALE_FACTOR_100P
},
836 {"mediaplayerFullscreenHover",
837 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_HOVER
,
838 ui::SCALE_FACTOR_100P
},
839 {"mediaplayerFullscreenDown",
840 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DOWN
,
841 ui::SCALE_FACTOR_100P
},
842 {"mediaplayerCastOff",
843 IDR_MEDIAPLAYER_CAST_BUTTON_OFF
,
844 ui::SCALE_FACTOR_100P
},
845 {"mediaplayerCastOn",
846 IDR_MEDIAPLAYER_CAST_BUTTON_ON
,
847 ui::SCALE_FACTOR_100P
},
848 {"mediaplayerFullscreenDisabled",
849 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DISABLED
,
850 ui::SCALE_FACTOR_100P
},
851 {"mediaplayerOverlayCastOff",
852 IDR_MEDIAPLAYER_OVERLAY_CAST_BUTTON_OFF
,
853 ui::SCALE_FACTOR_100P
},
854 {"mediaplayerOverlayPlay",
855 IDR_MEDIAPLAYER_OVERLAY_PLAY_BUTTON
,
856 ui::SCALE_FACTOR_100P
},
857 {"panIcon", IDR_PAN_SCROLL_ICON
, ui::SCALE_FACTOR_100P
},
858 {"searchCancel", IDR_SEARCH_CANCEL
, ui::SCALE_FACTOR_100P
},
859 {"searchCancelPressed", IDR_SEARCH_CANCEL_PRESSED
, ui::SCALE_FACTOR_100P
},
860 {"searchMagnifier", IDR_SEARCH_MAGNIFIER
, ui::SCALE_FACTOR_100P
},
861 {"searchMagnifierResults",
862 IDR_SEARCH_MAGNIFIER_RESULTS
,
863 ui::SCALE_FACTOR_100P
},
864 {"textAreaResizeCorner", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_100P
},
865 {"textAreaResizeCorner@2x", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_200P
},
866 {"generatePassword", IDR_PASSWORD_GENERATION_ICON
, ui::SCALE_FACTOR_100P
},
867 {"generatePasswordHover",
868 IDR_PASSWORD_GENERATION_ICON_HOVER
,
869 ui::SCALE_FACTOR_100P
},
870 {"html.css", IDR_UASTYLE_HTML_CSS
, ui::SCALE_FACTOR_NONE
},
871 {"quirks.css", IDR_UASTYLE_QUIRKS_CSS
, ui::SCALE_FACTOR_NONE
},
872 {"view-source.css", IDR_UASTYLE_VIEW_SOURCE_CSS
, ui::SCALE_FACTOR_NONE
},
873 {"themeChromium.css",
874 IDR_UASTYLE_THEME_CHROMIUM_CSS
,
875 ui::SCALE_FACTOR_NONE
},
876 #if defined(OS_ANDROID)
877 {"themeChromiumAndroid.css",
878 IDR_UASTYLE_THEME_CHROMIUM_ANDROID_CSS
,
879 ui::SCALE_FACTOR_NONE
},
880 {"mediaControlsAndroid.css",
881 IDR_UASTYLE_MEDIA_CONTROLS_ANDROID_CSS
,
882 ui::SCALE_FACTOR_NONE
},
885 {"themeChromiumLinux.css",
886 IDR_UASTYLE_THEME_CHROMIUM_LINUX_CSS
,
887 ui::SCALE_FACTOR_NONE
},
889 {"themeChromiumSkia.css",
890 IDR_UASTYLE_THEME_CHROMIUM_SKIA_CSS
,
891 ui::SCALE_FACTOR_NONE
},
892 {"themeInputMultipleFields.css",
893 IDR_UASTYLE_THEME_INPUT_MULTIPLE_FIELDS_CSS
,
894 ui::SCALE_FACTOR_NONE
},
895 #if defined(OS_MACOSX)
896 {"themeMac.css", IDR_UASTYLE_THEME_MAC_CSS
, ui::SCALE_FACTOR_NONE
},
898 {"themeWin.css", IDR_UASTYLE_THEME_WIN_CSS
, ui::SCALE_FACTOR_NONE
},
899 {"themeWinQuirks.css",
900 IDR_UASTYLE_THEME_WIN_QUIRKS_CSS
,
901 ui::SCALE_FACTOR_NONE
},
902 {"svg.css", IDR_UASTYLE_SVG_CSS
, ui::SCALE_FACTOR_NONE
},
903 {"navigationTransitions.css",
904 IDR_UASTYLE_NAVIGATION_TRANSITIONS_CSS
,
905 ui::SCALE_FACTOR_NONE
},
906 {"mathml.css", IDR_UASTYLE_MATHML_CSS
, ui::SCALE_FACTOR_NONE
},
907 {"mediaControls.css",
908 IDR_UASTYLE_MEDIA_CONTROLS_CSS
,
909 ui::SCALE_FACTOR_NONE
},
910 {"fullscreen.css", IDR_UASTYLE_FULLSCREEN_CSS
, ui::SCALE_FACTOR_NONE
},
911 {"xhtmlmp.css", IDR_UASTYLE_XHTMLMP_CSS
, ui::SCALE_FACTOR_NONE
},
912 {"viewportAndroid.css",
913 IDR_UASTYLE_VIEWPORT_ANDROID_CSS
,
914 ui::SCALE_FACTOR_NONE
},
915 {"InspectorOverlayPage.html",
916 IDR_INSPECTOR_OVERLAY_PAGE_HTML
,
917 ui::SCALE_FACTOR_NONE
},
918 {"InjectedScriptCanvasModuleSource.js",
919 IDR_INSPECTOR_INJECTED_SCRIPT_CANVAS_MODULE_SOURCE_JS
,
920 ui::SCALE_FACTOR_NONE
},
921 {"InjectedScriptSource.js",
922 IDR_INSPECTOR_INJECTED_SCRIPT_SOURCE_JS
,
923 ui::SCALE_FACTOR_NONE
},
924 {"DebuggerScriptSource.js",
925 IDR_INSPECTOR_DEBUGGER_SCRIPT_SOURCE_JS
,
926 ui::SCALE_FACTOR_NONE
},
927 {"DocumentExecCommand.js",
928 IDR_PRIVATE_SCRIPT_DOCUMENTEXECCOMMAND_JS
,
929 ui::SCALE_FACTOR_NONE
},
930 {"DocumentXMLTreeViewer.css",
931 IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_CSS
,
932 ui::SCALE_FACTOR_NONE
},
933 {"DocumentXMLTreeViewer.js",
934 IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_JS
,
935 ui::SCALE_FACTOR_NONE
},
936 {"HTMLMarqueeElement.js",
937 IDR_PRIVATE_SCRIPT_HTMLMARQUEEELEMENT_JS
,
938 ui::SCALE_FACTOR_NONE
},
939 {"PluginPlaceholderElement.js",
940 IDR_PRIVATE_SCRIPT_PLUGINPLACEHOLDERELEMENT_JS
,
941 ui::SCALE_FACTOR_NONE
},
942 {"PrivateScriptRunner.js",
943 IDR_PRIVATE_SCRIPT_PRIVATESCRIPTRUNNER_JS
,
944 ui::SCALE_FACTOR_NONE
},
945 #ifdef IDR_PICKER_COMMON_JS
946 {"pickerCommon.js", IDR_PICKER_COMMON_JS
, ui::SCALE_FACTOR_NONE
},
947 {"pickerCommon.css", IDR_PICKER_COMMON_CSS
, ui::SCALE_FACTOR_NONE
},
948 {"calendarPicker.js", IDR_CALENDAR_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
949 {"calendarPicker.css", IDR_CALENDAR_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
950 {"listPicker.js", IDR_LIST_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
951 {"listPicker.css", IDR_LIST_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
952 {"pickerButton.css", IDR_PICKER_BUTTON_CSS
, ui::SCALE_FACTOR_NONE
},
953 {"suggestionPicker.js", IDR_SUGGESTION_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
954 {"suggestionPicker.css", IDR_SUGGESTION_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
955 {"colorSuggestionPicker.js",
956 IDR_COLOR_SUGGESTION_PICKER_JS
,
957 ui::SCALE_FACTOR_NONE
},
958 {"colorSuggestionPicker.css",
959 IDR_COLOR_SUGGESTION_PICKER_CSS
,
960 ui::SCALE_FACTOR_NONE
},
966 WebData
BlinkPlatformImpl::loadResource(const char* name
) {
967 // Some clients will call into this method with an empty |name| when they have
968 // optional resources. For example, the PopupMenuChromium code can have icons
969 // for some Autofill items but not for others.
973 // Check the name prefix to see if it's an audio resource.
974 if (StartsWithASCII(name
, "IRC_Composite", true) ||
975 StartsWithASCII(name
, "Composite", true))
976 return loadAudioSpatializationResource(name
);
978 // TODO(flackr): We should use a better than linear search here, a trie would
980 for (size_t i
= 0; i
< arraysize(kDataResources
); ++i
) {
981 if (!strcmp(name
, kDataResources
[i
].name
)) {
982 base::StringPiece resource
= GetContentClient()->GetDataResource(
983 kDataResources
[i
].id
, kDataResources
[i
].scale_factor
);
984 return WebData(resource
.data(), resource
.size());
988 NOTREACHED() << "Unknown image resource " << name
;
992 WebString
BlinkPlatformImpl::queryLocalizedString(
993 WebLocalizedString::Name name
) {
994 int message_id
= ToMessageID(name
);
997 return GetContentClient()->GetLocalizedString(message_id
);
1000 WebString
BlinkPlatformImpl::queryLocalizedString(
1001 WebLocalizedString::Name name
, int numeric_value
) {
1002 return queryLocalizedString(name
, base::IntToString16(numeric_value
));
1005 WebString
BlinkPlatformImpl::queryLocalizedString(
1006 WebLocalizedString::Name name
, const WebString
& value
) {
1007 int message_id
= ToMessageID(name
);
1010 return ReplaceStringPlaceholders(GetContentClient()->GetLocalizedString(
1011 message_id
), value
, NULL
);
1014 WebString
BlinkPlatformImpl::queryLocalizedString(
1015 WebLocalizedString::Name name
,
1016 const WebString
& value1
,
1017 const WebString
& value2
) {
1018 int message_id
= ToMessageID(name
);
1021 std::vector
<base::string16
> values
;
1023 values
.push_back(value1
);
1024 values
.push_back(value2
);
1025 return ReplaceStringPlaceholders(
1026 GetContentClient()->GetLocalizedString(message_id
), values
, NULL
);
1029 double BlinkPlatformImpl::currentTime() {
1030 return base::Time::Now().ToDoubleT();
1033 double BlinkPlatformImpl::monotonicallyIncreasingTime() {
1034 return base::TimeTicks::Now().ToInternalValue() /
1035 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
1038 void BlinkPlatformImpl::cryptographicallyRandomValues(
1039 unsigned char* buffer
, size_t length
) {
1040 base::RandBytes(buffer
, length
);
1043 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func
)()) {
1044 shared_timer_func_
= func
;
1047 void BlinkPlatformImpl::setSharedTimerFireInterval(
1048 double interval_seconds
) {
1049 shared_timer_fire_time_
= interval_seconds
+ monotonicallyIncreasingTime();
1050 if (shared_timer_suspended_
) {
1051 shared_timer_fire_time_was_set_while_suspended_
= true;
1055 // By converting between double and int64 representation, we run the risk
1056 // of losing precision due to rounding errors. Performing computations in
1057 // microseconds reduces this risk somewhat. But there still is the potential
1058 // of us computing a fire time for the timer that is shorter than what we
1060 // As the event loop will check event deadlines prior to actually firing
1061 // them, there is a risk of needlessly rescheduling events and of
1062 // needlessly looping if sleep times are too short even by small amounts.
1063 // This results in measurable performance degradation unless we use ceil() to
1064 // always round up the sleep times.
1065 int64 interval
= static_cast<int64
>(
1066 ceil(interval_seconds
* base::Time::kMillisecondsPerSecond
)
1067 * base::Time::kMicrosecondsPerMillisecond
);
1072 shared_timer_
.Stop();
1073 shared_timer_
.Start(FROM_HERE
, base::TimeDelta::FromMicroseconds(interval
),
1074 this, &BlinkPlatformImpl::DoTimeout
);
1075 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval
));
1078 void BlinkPlatformImpl::stopSharedTimer() {
1079 shared_timer_
.Stop();
1082 void BlinkPlatformImpl::callOnMainThread(
1083 void (*func
)(void*), void* context
) {
1084 main_thread_task_runner_
->PostTask(FROM_HERE
, base::Bind(func
, context
));
1087 blink::WebGestureCurve
* BlinkPlatformImpl::createFlingAnimationCurve(
1088 blink::WebGestureDevice device_source
,
1089 const blink::WebFloatPoint
& velocity
,
1090 const blink::WebSize
& cumulative_scroll
) {
1091 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
1092 gfx::Vector2dF(velocity
.x
, velocity
.y
),
1093 gfx::Vector2dF(cumulative_scroll
.width
, cumulative_scroll
.height
),
1094 IsMainThread()).release();
1097 void BlinkPlatformImpl::didStartWorkerRunLoop() {
1098 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
1099 worker_task_runner
->OnWorkerRunLoopStarted();
1102 void BlinkPlatformImpl::didStopWorkerRunLoop() {
1103 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
1104 worker_task_runner
->OnWorkerRunLoopStopped();
1107 blink::WebCrypto
* BlinkPlatformImpl::crypto() {
1108 return &web_crypto_
;
1111 blink::WebGeofencingProvider
* BlinkPlatformImpl::geofencingProvider() {
1112 return geofencing_provider_
.get();
1115 blink::WebBluetooth
* BlinkPlatformImpl::bluetooth() {
1116 return bluetooth_
.get();
1119 blink::WebNotificationManager
*
1120 BlinkPlatformImpl::notificationManager() {
1121 if (!thread_safe_sender_
.get() || !notification_dispatcher_
.get())
1124 return NotificationManager::ThreadSpecificInstance(
1125 thread_safe_sender_
.get(),
1126 main_thread_task_runner_
.get(),
1127 notification_dispatcher_
.get());
1130 blink::WebPushProvider
* BlinkPlatformImpl::pushProvider() {
1131 if (!thread_safe_sender_
.get() || !push_dispatcher_
.get())
1134 return PushProvider::ThreadSpecificInstance(thread_safe_sender_
.get(),
1135 push_dispatcher_
.get());
1138 blink::WebNavigatorConnectProvider
*
1139 BlinkPlatformImpl::navigatorConnectProvider() {
1140 if (!thread_safe_sender_
.get())
1143 return NavigatorConnectProvider::ThreadSpecificInstance(
1144 thread_safe_sender_
.get(), main_thread_task_runner_
);
1147 blink::WebPermissionClient
* BlinkPlatformImpl::permissionClient() {
1148 if (!permission_client_
.get())
1152 return permission_client_
.get();
1154 return PermissionDispatcherThreadProxy::GetThreadInstance(
1155 main_thread_task_runner_
.get(), permission_client_
.get());
1158 WebThemeEngine
* BlinkPlatformImpl::themeEngine() {
1159 return &native_theme_engine_
;
1162 WebFallbackThemeEngine
* BlinkPlatformImpl::fallbackThemeEngine() {
1163 return &fallback_theme_engine_
;
1166 blink::Platform::FileHandle
BlinkPlatformImpl::databaseOpenFile(
1167 const blink::WebString
& vfs_file_name
, int desired_flags
) {
1169 return INVALID_HANDLE_VALUE
;
1170 #elif defined(OS_POSIX)
1175 int BlinkPlatformImpl::databaseDeleteFile(
1176 const blink::WebString
& vfs_file_name
, bool sync_dir
) {
1180 long BlinkPlatformImpl::databaseGetFileAttributes(
1181 const blink::WebString
& vfs_file_name
) {
1185 long long BlinkPlatformImpl::databaseGetFileSize(
1186 const blink::WebString
& vfs_file_name
) {
1190 long long BlinkPlatformImpl::databaseGetSpaceAvailableForOrigin(
1191 const blink::WebString
& origin_identifier
) {
1195 bool BlinkPlatformImpl::databaseSetFileSize(
1196 const blink::WebString
& vfs_file_name
, long long size
) {
1200 blink::WebString
BlinkPlatformImpl::signedPublicKeyAndChallengeString(
1201 unsigned key_size_index
,
1202 const blink::WebString
& challenge
,
1203 const blink::WebURL
& url
) {
1204 return blink::WebString("");
1207 static scoped_ptr
<base::ProcessMetrics
> CurrentProcessMetrics() {
1208 using base::ProcessMetrics
;
1209 #if defined(OS_MACOSX)
1210 return scoped_ptr
<ProcessMetrics
>(
1211 // The default port provider is sufficient to get data for the current
1213 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
1216 return scoped_ptr
<ProcessMetrics
>(
1217 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()));
1221 static size_t getMemoryUsageMB(bool bypass_cache
) {
1222 size_t current_mem_usage
= 0;
1223 MemoryUsageCache
* mem_usage_cache_singleton
= MemoryUsageCache::GetInstance();
1224 if (!bypass_cache
&&
1225 mem_usage_cache_singleton
->IsCachedValueValid(¤t_mem_usage
))
1226 return current_mem_usage
;
1228 current_mem_usage
= GetMemoryUsageKB() >> 10;
1229 mem_usage_cache_singleton
->SetMemoryValue(current_mem_usage
);
1230 return current_mem_usage
;
1233 size_t BlinkPlatformImpl::memoryUsageMB() {
1234 return getMemoryUsageMB(false);
1237 size_t BlinkPlatformImpl::actualMemoryUsageMB() {
1238 return getMemoryUsageMB(true);
1241 size_t BlinkPlatformImpl::physicalMemoryMB() {
1242 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
1245 size_t BlinkPlatformImpl::virtualMemoryLimitMB() {
1246 return static_cast<size_t>(base::SysInfo::AmountOfVirtualMemoryMB());
1249 size_t BlinkPlatformImpl::numberOfProcessors() {
1250 return static_cast<size_t>(base::SysInfo::NumberOfProcessors());
1253 bool BlinkPlatformImpl::processMemorySizesInBytes(
1254 size_t* private_bytes
,
1255 size_t* shared_bytes
) {
1256 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes
, shared_bytes
);
1259 bool BlinkPlatformImpl::memoryAllocatorWasteInBytes(size_t* size
) {
1260 return base::allocator::GetAllocatorWasteSize(size
);
1263 blink::WebDiscardableMemory
*
1264 BlinkPlatformImpl::allocateAndLockDiscardableMemory(size_t bytes
) {
1265 return content::WebDiscardableMemoryImpl::CreateLockedMemory(bytes
).release();
1268 size_t BlinkPlatformImpl::maxDecodedImageBytes() {
1269 #if defined(OS_ANDROID)
1270 if (base::SysInfo::IsLowEndDevice()) {
1271 // Limit image decoded size to 3M pixels on low end devices.
1272 // 4 is maximum number of bytes per pixel.
1273 return 3 * 1024 * 1024 * 4;
1275 // For other devices, limit decoded image size based on the amount of physical
1277 // In some cases all physical memory is not accessible by Chromium, as it can
1278 // be reserved for direct use by certain hardware. Thus, we set the limit so
1279 // that 1.6GB of reported physical memory on a 2GB device is enough to set the
1280 // limit at 16M pixels, which is a desirable value since 4K*4K is a relatively
1281 // common texture size.
1282 return base::SysInfo::AmountOfPhysicalMemory() / 25;
1284 return noDecodedImageByteLimit
;
1288 void BlinkPlatformImpl::SuspendSharedTimer() {
1289 ++shared_timer_suspended_
;
1292 void BlinkPlatformImpl::ResumeSharedTimer() {
1293 DCHECK_GT(shared_timer_suspended_
, 0);
1295 // The shared timer may have fired or been adjusted while we were suspended.
1296 if (--shared_timer_suspended_
== 0 &&
1297 (!shared_timer_
.IsRunning() ||
1298 shared_timer_fire_time_was_set_while_suspended_
)) {
1299 shared_timer_fire_time_was_set_while_suspended_
= false;
1300 setSharedTimerFireInterval(
1301 shared_timer_fire_time_
- monotonicallyIncreasingTime());
1305 scoped_refptr
<base::SingleThreadTaskRunner
>
1306 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() {
1307 if (main_thread_task_runner_
.get() &&
1308 main_thread_task_runner_
->BelongsToCurrentThread()) {
1309 return main_thread_task_runner_
;
1311 return base::MessageLoopProxy::current();
1315 bool BlinkPlatformImpl::IsMainThread() const {
1316 return main_thread_task_runner_
.get() &&
1317 main_thread_task_runner_
->BelongsToCurrentThread();
1320 WebString
BlinkPlatformImpl::domCodeStringFromEnum(int dom_code
) {
1321 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString(
1322 static_cast<ui::DomCode
>(dom_code
)));
1325 int BlinkPlatformImpl::domEnumFromCodeString(const WebString
& code
) {
1326 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode(
1327 code
.utf8().data()));
1330 } // namespace content