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/location.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/singleton.h"
17 #include "base/metrics/histogram.h"
18 #include "base/metrics/sparse_histogram.h"
19 #include "base/process/process_metrics.h"
20 #include "base/rand_util.h"
21 #include "base/single_thread_task_runner.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/thread_task_runner_handle.h"
29 #include "base/threading/platform_thread.h"
30 #include "base/time/time.h"
31 #include "base/trace_event/memory_dump_manager.h"
32 #include "blink/public/resources/grit/blink_image_resources.h"
33 #include "blink/public/resources/grit/blink_resources.h"
34 #include "components/mime_util/mime_util.h"
35 #include "components/scheduler/child/webthread_impl_for_worker_scheduler.h"
36 #include "content/app/resources/grit/content_resources.h"
37 #include "content/app/strings/grit/content_strings.h"
38 #include "content/child/background_sync/background_sync_provider.h"
39 #include "content/child/background_sync/background_sync_provider_thread_proxy.h"
40 #include "content/child/bluetooth/web_bluetooth_impl.h"
41 #include "content/child/child_thread_impl.h"
42 #include "content/child/content_child_helpers.h"
43 #include "content/child/geofencing/web_geofencing_provider_impl.h"
44 #include "content/child/navigator_connect/navigator_connect_provider.h"
45 #include "content/child/notifications/notification_dispatcher.h"
46 #include "content/child/notifications/notification_manager.h"
47 #include "content/child/permissions/permission_dispatcher.h"
48 #include "content/child/permissions/permission_dispatcher_thread_proxy.h"
49 #include "content/child/push_messaging/push_dispatcher.h"
50 #include "content/child/push_messaging/push_provider.h"
51 #include "content/child/thread_safe_sender.h"
52 #include "content/child/web_discardable_memory_impl.h"
53 #include "content/child/web_memory_dump_provider_adapter.h"
54 #include "content/child/web_process_memory_dump_impl.h"
55 #include "content/child/web_url_loader_impl.h"
56 #include "content/child/web_url_request_util.h"
57 #include "content/child/websocket_bridge.h"
58 #include "content/child/worker_task_runner.h"
59 #include "content/public/common/content_client.h"
60 #include "net/base/data_url.h"
61 #include "net/base/net_errors.h"
62 #include "net/base/net_util.h"
63 #include "third_party/WebKit/public/platform/WebConvertableToTraceFormat.h"
64 #include "third_party/WebKit/public/platform/WebData.h"
65 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
66 #include "third_party/WebKit/public/platform/WebMemoryDumpProvider.h"
67 #include "third_party/WebKit/public/platform/WebString.h"
68 #include "third_party/WebKit/public/platform/WebURL.h"
69 #include "third_party/WebKit/public/platform/WebWaitableEvent.h"
70 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
71 #include "ui/base/layout.h"
72 #include "ui/events/gestures/blink/web_gesture_curve_impl.h"
73 #include "ui/events/keycodes/dom/keycode_converter.h"
76 using blink::WebFallbackThemeEngine
;
77 using blink::WebLocalizedString
;
78 using blink::WebString
;
79 using blink::WebThemeEngine
;
81 using blink::WebURLError
;
82 using blink::WebURLLoader
;
88 class WebWaitableEventImpl
: public blink::WebWaitableEvent
{
90 WebWaitableEventImpl() : impl_(new base::WaitableEvent(false, false)) {}
91 virtual ~WebWaitableEventImpl() {}
93 virtual void wait() { impl_
->Wait(); }
94 virtual void signal() { impl_
->Signal(); }
96 base::WaitableEvent
* impl() {
101 scoped_ptr
<base::WaitableEvent
> impl_
;
102 DISALLOW_COPY_AND_ASSIGN(WebWaitableEventImpl
);
105 // A simple class to cache the memory usage for a given amount of time.
106 class MemoryUsageCache
{
108 // Retrieves the Singleton.
109 static MemoryUsageCache
* GetInstance() {
110 return Singleton
<MemoryUsageCache
>::get();
113 MemoryUsageCache() : memory_value_(0) { Init(); }
114 ~MemoryUsageCache() {}
117 const unsigned int kCacheSeconds
= 1;
118 cache_valid_time_
= base::TimeDelta::FromSeconds(kCacheSeconds
);
121 // Returns true if the cached value is fresh.
122 // Returns false if the cached value is stale, or if |cached_value| is NULL.
123 bool IsCachedValueValid(size_t* cached_value
) {
124 base::AutoLock
scoped_lock(lock_
);
127 if (base::Time::Now() - last_updated_time_
> cache_valid_time_
)
129 *cached_value
= memory_value_
;
133 // Setter for |memory_value_|, refreshes |last_updated_time_|.
134 void SetMemoryValue(const size_t value
) {
135 base::AutoLock
scoped_lock(lock_
);
136 memory_value_
= value
;
137 last_updated_time_
= base::Time::Now();
141 // The cached memory value.
142 size_t memory_value_
;
144 // How long the cached value should remain valid.
145 base::TimeDelta cache_valid_time_
;
147 // The last time the cached value was updated.
148 base::Time last_updated_time_
;
153 class ConvertableToTraceFormatWrapper
154 : public base::trace_event::ConvertableToTraceFormat
{
156 // We move a reference pointer from |convertable| to |convertable_|,
157 // rather than copying, for thread safety. https://crbug.com/478149
158 explicit ConvertableToTraceFormatWrapper(
159 blink::WebConvertableToTraceFormat
& convertable
) {
160 convertable_
.moveFrom(convertable
);
162 void AppendAsTraceFormat(std::string
* out
) const override
{
163 *out
+= convertable_
.asTraceFormat().utf8();
167 ~ConvertableToTraceFormatWrapper() override
{}
169 blink::WebConvertableToTraceFormat convertable_
;
174 static int ToMessageID(WebLocalizedString::Name name
) {
176 case WebLocalizedString::AXAMPMFieldText
:
177 return IDS_AX_AM_PM_FIELD_TEXT
;
178 case WebLocalizedString::AXButtonActionVerb
:
179 return IDS_AX_BUTTON_ACTION_VERB
;
180 case WebLocalizedString::AXCalendarShowMonthSelector
:
181 return IDS_AX_CALENDAR_SHOW_MONTH_SELECTOR
;
182 case WebLocalizedString::AXCalendarShowNextMonth
:
183 return IDS_AX_CALENDAR_SHOW_NEXT_MONTH
;
184 case WebLocalizedString::AXCalendarShowPreviousMonth
:
185 return IDS_AX_CALENDAR_SHOW_PREVIOUS_MONTH
;
186 case WebLocalizedString::AXCalendarWeekDescription
:
187 return IDS_AX_CALENDAR_WEEK_DESCRIPTION
;
188 case WebLocalizedString::AXCheckedCheckBoxActionVerb
:
189 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB
;
190 case WebLocalizedString::AXDateTimeFieldEmptyValueText
:
191 return IDS_AX_DATE_TIME_FIELD_EMPTY_VALUE_TEXT
;
192 case WebLocalizedString::AXDayOfMonthFieldText
:
193 return IDS_AX_DAY_OF_MONTH_FIELD_TEXT
;
194 case WebLocalizedString::AXHeadingText
:
195 return IDS_AX_ROLE_HEADING
;
196 case WebLocalizedString::AXHourFieldText
:
197 return IDS_AX_HOUR_FIELD_TEXT
;
198 case WebLocalizedString::AXImageMapText
:
199 return IDS_AX_ROLE_IMAGE_MAP
;
200 case WebLocalizedString::AXLinkActionVerb
:
201 return IDS_AX_LINK_ACTION_VERB
;
202 case WebLocalizedString::AXLinkText
:
203 return IDS_AX_ROLE_LINK
;
204 case WebLocalizedString::AXListMarkerText
:
205 return IDS_AX_ROLE_LIST_MARKER
;
206 case WebLocalizedString::AXMediaDefault
:
207 return IDS_AX_MEDIA_DEFAULT
;
208 case WebLocalizedString::AXMediaAudioElement
:
209 return IDS_AX_MEDIA_AUDIO_ELEMENT
;
210 case WebLocalizedString::AXMediaVideoElement
:
211 return IDS_AX_MEDIA_VIDEO_ELEMENT
;
212 case WebLocalizedString::AXMediaMuteButton
:
213 return IDS_AX_MEDIA_MUTE_BUTTON
;
214 case WebLocalizedString::AXMediaUnMuteButton
:
215 return IDS_AX_MEDIA_UNMUTE_BUTTON
;
216 case WebLocalizedString::AXMediaPlayButton
:
217 return IDS_AX_MEDIA_PLAY_BUTTON
;
218 case WebLocalizedString::AXMediaPauseButton
:
219 return IDS_AX_MEDIA_PAUSE_BUTTON
;
220 case WebLocalizedString::AXMediaSlider
:
221 return IDS_AX_MEDIA_SLIDER
;
222 case WebLocalizedString::AXMediaSliderThumb
:
223 return IDS_AX_MEDIA_SLIDER_THUMB
;
224 case WebLocalizedString::AXMediaCurrentTimeDisplay
:
225 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY
;
226 case WebLocalizedString::AXMediaTimeRemainingDisplay
:
227 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY
;
228 case WebLocalizedString::AXMediaStatusDisplay
:
229 return IDS_AX_MEDIA_STATUS_DISPLAY
;
230 case WebLocalizedString::AXMediaEnterFullscreenButton
:
231 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON
;
232 case WebLocalizedString::AXMediaExitFullscreenButton
:
233 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON
;
234 case WebLocalizedString::AXMediaShowClosedCaptionsButton
:
235 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON
;
236 case WebLocalizedString::AXMediaHideClosedCaptionsButton
:
237 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON
;
238 case WebLocalizedString::AxMediaCastOffButton
:
239 return IDS_AX_MEDIA_CAST_OFF_BUTTON
;
240 case WebLocalizedString::AxMediaCastOnButton
:
241 return IDS_AX_MEDIA_CAST_ON_BUTTON
;
242 case WebLocalizedString::AXMediaAudioElementHelp
:
243 return IDS_AX_MEDIA_AUDIO_ELEMENT_HELP
;
244 case WebLocalizedString::AXMediaVideoElementHelp
:
245 return IDS_AX_MEDIA_VIDEO_ELEMENT_HELP
;
246 case WebLocalizedString::AXMediaMuteButtonHelp
:
247 return IDS_AX_MEDIA_MUTE_BUTTON_HELP
;
248 case WebLocalizedString::AXMediaUnMuteButtonHelp
:
249 return IDS_AX_MEDIA_UNMUTE_BUTTON_HELP
;
250 case WebLocalizedString::AXMediaPlayButtonHelp
:
251 return IDS_AX_MEDIA_PLAY_BUTTON_HELP
;
252 case WebLocalizedString::AXMediaPauseButtonHelp
:
253 return IDS_AX_MEDIA_PAUSE_BUTTON_HELP
;
254 case WebLocalizedString::AXMediaAudioSliderHelp
:
255 return IDS_AX_MEDIA_AUDIO_SLIDER_HELP
;
256 case WebLocalizedString::AXMediaVideoSliderHelp
:
257 return IDS_AX_MEDIA_VIDEO_SLIDER_HELP
;
258 case WebLocalizedString::AXMediaSliderThumbHelp
:
259 return IDS_AX_MEDIA_SLIDER_THUMB_HELP
;
260 case WebLocalizedString::AXMediaCurrentTimeDisplayHelp
:
261 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY_HELP
;
262 case WebLocalizedString::AXMediaTimeRemainingDisplayHelp
:
263 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY_HELP
;
264 case WebLocalizedString::AXMediaStatusDisplayHelp
:
265 return IDS_AX_MEDIA_STATUS_DISPLAY_HELP
;
266 case WebLocalizedString::AXMediaEnterFullscreenButtonHelp
:
267 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON_HELP
;
268 case WebLocalizedString::AXMediaExitFullscreenButtonHelp
:
269 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON_HELP
;
270 case WebLocalizedString::AXMediaShowClosedCaptionsButtonHelp
:
271 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON_HELP
;
272 case WebLocalizedString::AXMediaHideClosedCaptionsButtonHelp
:
273 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON_HELP
;
274 case WebLocalizedString::AxMediaCastOffButtonHelp
:
275 return IDS_AX_MEDIA_CAST_OFF_BUTTON_HELP
;
276 case WebLocalizedString::AxMediaCastOnButtonHelp
:
277 return IDS_AX_MEDIA_CAST_ON_BUTTON_HELP
;
278 case WebLocalizedString::AXMillisecondFieldText
:
279 return IDS_AX_MILLISECOND_FIELD_TEXT
;
280 case WebLocalizedString::AXMinuteFieldText
:
281 return IDS_AX_MINUTE_FIELD_TEXT
;
282 case WebLocalizedString::AXMonthFieldText
:
283 return IDS_AX_MONTH_FIELD_TEXT
;
284 case WebLocalizedString::AXRadioButtonActionVerb
:
285 return IDS_AX_RADIO_BUTTON_ACTION_VERB
;
286 case WebLocalizedString::AXSecondFieldText
:
287 return IDS_AX_SECOND_FIELD_TEXT
;
288 case WebLocalizedString::AXTextFieldActionVerb
:
289 return IDS_AX_TEXT_FIELD_ACTION_VERB
;
290 case WebLocalizedString::AXUncheckedCheckBoxActionVerb
:
291 return IDS_AX_UNCHECKED_CHECK_BOX_ACTION_VERB
;
292 case WebLocalizedString::AXWebAreaText
:
293 return IDS_AX_ROLE_WEB_AREA
;
294 case WebLocalizedString::AXWeekOfYearFieldText
:
295 return IDS_AX_WEEK_OF_YEAR_FIELD_TEXT
;
296 case WebLocalizedString::AXYearFieldText
:
297 return IDS_AX_YEAR_FIELD_TEXT
;
298 case WebLocalizedString::CalendarClear
:
299 return IDS_FORM_CALENDAR_CLEAR
;
300 case WebLocalizedString::CalendarToday
:
301 return IDS_FORM_CALENDAR_TODAY
;
302 case WebLocalizedString::DateFormatDayInMonthLabel
:
303 return IDS_FORM_DATE_FORMAT_DAY_IN_MONTH
;
304 case WebLocalizedString::DateFormatMonthLabel
:
305 return IDS_FORM_DATE_FORMAT_MONTH
;
306 case WebLocalizedString::DateFormatYearLabel
:
307 return IDS_FORM_DATE_FORMAT_YEAR
;
308 case WebLocalizedString::DetailsLabel
:
309 return IDS_DETAILS_WITHOUT_SUMMARY_LABEL
;
310 case WebLocalizedString::FileButtonChooseFileLabel
:
311 return IDS_FORM_FILE_BUTTON_LABEL
;
312 case WebLocalizedString::FileButtonChooseMultipleFilesLabel
:
313 return IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL
;
314 case WebLocalizedString::FileButtonNoFileSelectedLabel
:
315 return IDS_FORM_FILE_NO_FILE_LABEL
;
316 case WebLocalizedString::InputElementAltText
:
317 return IDS_FORM_INPUT_ALT
;
318 case WebLocalizedString::KeygenMenuHighGradeKeySize
:
319 return IDS_KEYGEN_HIGH_GRADE_KEY
;
320 case WebLocalizedString::KeygenMenuMediumGradeKeySize
:
321 return IDS_KEYGEN_MED_GRADE_KEY
;
322 case WebLocalizedString::MissingPluginText
:
323 return IDS_PLUGIN_INITIALIZATION_ERROR
;
324 case WebLocalizedString::MultipleFileUploadText
:
325 return IDS_FORM_FILE_MULTIPLE_UPLOAD
;
326 case WebLocalizedString::OtherColorLabel
:
327 return IDS_FORM_OTHER_COLOR_LABEL
;
328 case WebLocalizedString::OtherDateLabel
:
329 return IDS_FORM_OTHER_DATE_LABEL
;
330 case WebLocalizedString::OtherMonthLabel
:
331 return IDS_FORM_OTHER_MONTH_LABEL
;
332 case WebLocalizedString::OtherTimeLabel
:
333 return IDS_FORM_OTHER_TIME_LABEL
;
334 case WebLocalizedString::OtherWeekLabel
:
335 return IDS_FORM_OTHER_WEEK_LABEL
;
336 case WebLocalizedString::PlaceholderForDayOfMonthField
:
337 return IDS_FORM_PLACEHOLDER_FOR_DAY_OF_MONTH_FIELD
;
338 case WebLocalizedString::PlaceholderForMonthField
:
339 return IDS_FORM_PLACEHOLDER_FOR_MONTH_FIELD
;
340 case WebLocalizedString::PlaceholderForYearField
:
341 return IDS_FORM_PLACEHOLDER_FOR_YEAR_FIELD
;
342 case WebLocalizedString::ResetButtonDefaultLabel
:
343 return IDS_FORM_RESET_LABEL
;
344 case WebLocalizedString::SearchableIndexIntroduction
:
345 return IDS_SEARCHABLE_INDEX_INTRO
;
346 case WebLocalizedString::SearchMenuClearRecentSearchesText
:
347 return IDS_RECENT_SEARCHES_CLEAR
;
348 case WebLocalizedString::SearchMenuNoRecentSearchesText
:
349 return IDS_RECENT_SEARCHES_NONE
;
350 case WebLocalizedString::SearchMenuRecentSearchesText
:
351 return IDS_RECENT_SEARCHES
;
352 case WebLocalizedString::SelectMenuListText
:
353 return IDS_FORM_SELECT_MENU_LIST_TEXT
;
354 case WebLocalizedString::SubmitButtonDefaultLabel
:
355 return IDS_FORM_SUBMIT_LABEL
;
356 case WebLocalizedString::ThisMonthButtonLabel
:
357 return IDS_FORM_THIS_MONTH_LABEL
;
358 case WebLocalizedString::ThisWeekButtonLabel
:
359 return IDS_FORM_THIS_WEEK_LABEL
;
360 case WebLocalizedString::ValidationBadInputForDateTime
:
361 return IDS_FORM_VALIDATION_BAD_INPUT_DATETIME
;
362 case WebLocalizedString::ValidationBadInputForNumber
:
363 return IDS_FORM_VALIDATION_BAD_INPUT_NUMBER
;
364 case WebLocalizedString::ValidationPatternMismatch
:
365 return IDS_FORM_VALIDATION_PATTERN_MISMATCH
;
366 case WebLocalizedString::ValidationRangeOverflow
:
367 return IDS_FORM_VALIDATION_RANGE_OVERFLOW
;
368 case WebLocalizedString::ValidationRangeOverflowDateTime
:
369 return IDS_FORM_VALIDATION_RANGE_OVERFLOW_DATETIME
;
370 case WebLocalizedString::ValidationRangeUnderflow
:
371 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW
;
372 case WebLocalizedString::ValidationRangeUnderflowDateTime
:
373 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW_DATETIME
;
374 case WebLocalizedString::ValidationStepMismatch
:
375 return IDS_FORM_VALIDATION_STEP_MISMATCH
;
376 case WebLocalizedString::ValidationStepMismatchCloseToLimit
:
377 return IDS_FORM_VALIDATION_STEP_MISMATCH_CLOSE_TO_LIMIT
;
378 case WebLocalizedString::ValidationTooLong
:
379 return IDS_FORM_VALIDATION_TOO_LONG
;
380 case WebLocalizedString::ValidationTooShort
:
381 return IDS_FORM_VALIDATION_TOO_SHORT
;
382 case WebLocalizedString::ValidationTypeMismatch
:
383 return IDS_FORM_VALIDATION_TYPE_MISMATCH
;
384 case WebLocalizedString::ValidationTypeMismatchForEmail
:
385 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL
;
386 case WebLocalizedString::ValidationTypeMismatchForEmailEmpty
:
387 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY
;
388 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyDomain
:
389 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_DOMAIN
;
390 case WebLocalizedString::ValidationTypeMismatchForEmailEmptyLocal
:
391 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_EMPTY_LOCAL
;
392 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDomain
:
393 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOMAIN
;
394 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidDots
:
395 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_DOTS
;
396 case WebLocalizedString::ValidationTypeMismatchForEmailInvalidLocal
:
397 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_INVALID_LOCAL
;
398 case WebLocalizedString::ValidationTypeMismatchForEmailNoAtSign
:
399 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL_NO_AT_SIGN
;
400 case WebLocalizedString::ValidationTypeMismatchForMultipleEmail
:
401 return IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL
;
402 case WebLocalizedString::ValidationTypeMismatchForURL
:
403 return IDS_FORM_VALIDATION_TYPE_MISMATCH_URL
;
404 case WebLocalizedString::ValidationValueMissing
:
405 return IDS_FORM_VALIDATION_VALUE_MISSING
;
406 case WebLocalizedString::ValidationValueMissingForCheckbox
:
407 return IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX
;
408 case WebLocalizedString::ValidationValueMissingForFile
:
409 return IDS_FORM_VALIDATION_VALUE_MISSING_FILE
;
410 case WebLocalizedString::ValidationValueMissingForMultipleFile
:
411 return IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE
;
412 case WebLocalizedString::ValidationValueMissingForRadio
:
413 return IDS_FORM_VALIDATION_VALUE_MISSING_RADIO
;
414 case WebLocalizedString::ValidationValueMissingForSelect
:
415 return IDS_FORM_VALIDATION_VALUE_MISSING_SELECT
;
416 case WebLocalizedString::WeekFormatTemplate
:
417 return IDS_FORM_INPUT_WEEK_TEMPLATE
;
418 case WebLocalizedString::WeekNumberLabel
:
419 return IDS_FORM_WEEK_NUMBER_LABEL
;
420 // This "default:" line exists to avoid compile warnings about enum
421 // coverage when we add a new symbol to WebLocalizedString.h in WebKit.
422 // After a planned WebKit patch is landed, we need to add a case statement
423 // for the added symbol here.
430 // TODO(skyostil): Ensure that we always have an active task runner when
431 // constructing the platform.
432 BlinkPlatformImpl::BlinkPlatformImpl()
433 : main_thread_task_runner_(base::ThreadTaskRunnerHandle::IsSet()
434 ? base::ThreadTaskRunnerHandle::Get()
436 shared_timer_func_(NULL
),
437 shared_timer_fire_time_(0.0),
438 shared_timer_fire_time_was_set_while_suspended_(false),
439 shared_timer_suspended_(0) {
443 BlinkPlatformImpl::BlinkPlatformImpl(
444 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
)
445 : main_thread_task_runner_(main_thread_task_runner
),
446 shared_timer_func_(NULL
),
447 shared_timer_fire_time_(0.0),
448 shared_timer_fire_time_was_set_while_suspended_(false),
449 shared_timer_suspended_(0) {
450 // TODO(alexclarke): Use c++11 delegated constructors when allowed.
454 void BlinkPlatformImpl::InternalInit() {
455 // ChildThread may not exist in some tests.
456 if (ChildThreadImpl::current()) {
457 geofencing_provider_
.reset(new WebGeofencingProviderImpl(
458 ChildThreadImpl::current()->thread_safe_sender()));
460 new WebBluetoothImpl(ChildThreadImpl::current()->thread_safe_sender()));
461 thread_safe_sender_
= ChildThreadImpl::current()->thread_safe_sender();
462 notification_dispatcher_
=
463 ChildThreadImpl::current()->notification_dispatcher();
464 push_dispatcher_
= ChildThreadImpl::current()->push_dispatcher();
465 permission_client_
.reset(new PermissionDispatcher(
466 ChildThreadImpl::current()->service_registry()));
467 sync_provider_
.reset(new BackgroundSyncProvider(
468 ChildThreadImpl::current()->service_registry()));
471 if (main_thread_task_runner_
.get()) {
472 shared_timer_
.SetTaskRunner(main_thread_task_runner_
);
476 void BlinkPlatformImpl::UpdateWebThreadTLS(blink::WebThread
* thread
) {
477 DCHECK(!current_thread_slot_
.Get());
478 current_thread_slot_
.Set(thread
);
481 BlinkPlatformImpl::~BlinkPlatformImpl() {
484 WebURLLoader
* BlinkPlatformImpl::createURLLoader() {
485 ChildThreadImpl
* child_thread
= ChildThreadImpl::current();
486 // There may be no child thread in RenderViewTests. These tests can still use
487 // data URLs to bypass the ResourceDispatcher.
488 return new WebURLLoaderImpl(
489 child_thread
? child_thread
->resource_dispatcher() : NULL
,
490 MainTaskRunnerForCurrentThread());
493 blink::WebSocketHandle
* BlinkPlatformImpl::createWebSocketHandle() {
494 return new WebSocketBridge
;
497 WebString
BlinkPlatformImpl::userAgent() {
498 return WebString::fromUTF8(GetContentClient()->GetUserAgent());
501 WebData
BlinkPlatformImpl::parseDataURL(const WebURL
& url
,
502 WebString
& mimetype_out
,
503 WebString
& charset_out
) {
504 std::string mime_type
, char_set
, data
;
505 if (net::DataURL::Parse(url
, &mime_type
, &char_set
, &data
) &&
506 mime_util::IsSupportedMimeType(mime_type
)) {
507 mimetype_out
= WebString::fromUTF8(mime_type
);
508 charset_out
= WebString::fromUTF8(char_set
);
514 WebURLError
BlinkPlatformImpl::cancelledError(
515 const WebURL
& unreachableURL
) const {
516 return CreateWebURLError(unreachableURL
, false, net::ERR_ABORTED
);
519 bool BlinkPlatformImpl::isReservedIPAddress(
520 const blink::WebString
& host
) const {
521 net::IPAddressNumber address
;
522 if (!net::ParseURLHostnameToNumber(host
.utf8(), &address
))
524 return net::IsIPAddressReserved(address
);
527 bool BlinkPlatformImpl::portAllowed(const blink::WebURL
& url
) const {
528 GURL gurl
= GURL(url
);
529 if (!gurl
.has_port())
531 int port
= gurl
.IntPort();
532 if (net::IsPortAllowedByOverride(port
))
534 if (gurl
.SchemeIs("ftp"))
535 return net::IsPortAllowedByFtp(port
);
536 return net::IsPortAllowedByDefault(port
);
539 blink::WebThread
* BlinkPlatformImpl::createThread(const char* name
) {
540 scheduler::WebThreadImplForWorkerScheduler
* thread
=
541 new scheduler::WebThreadImplForWorkerScheduler(name
);
542 thread
->TaskRunner()->PostTask(
543 FROM_HERE
, base::Bind(&BlinkPlatformImpl::UpdateWebThreadTLS
,
544 base::Unretained(this), thread
));
548 blink::WebThread
* BlinkPlatformImpl::currentThread() {
549 return static_cast<blink::WebThread
*>(current_thread_slot_
.Get());
552 void BlinkPlatformImpl::yieldCurrentThread() {
553 base::PlatformThread::YieldCurrentThread();
556 blink::WebWaitableEvent
* BlinkPlatformImpl::createWaitableEvent() {
557 return new WebWaitableEventImpl();
560 blink::WebWaitableEvent
* BlinkPlatformImpl::waitMultipleEvents(
561 const blink::WebVector
<blink::WebWaitableEvent
*>& web_events
) {
562 std::vector
<base::WaitableEvent
*> events
;
563 for (size_t i
= 0; i
< web_events
.size(); ++i
)
564 events
.push_back(static_cast<WebWaitableEventImpl
*>(web_events
[i
])->impl());
565 size_t idx
= base::WaitableEvent::WaitMany(
566 vector_as_array(&events
), events
.size());
567 DCHECK_LT(idx
, web_events
.size());
568 return web_events
[idx
];
571 void BlinkPlatformImpl::decrementStatsCounter(const char* name
) {
574 void BlinkPlatformImpl::incrementStatsCounter(const char* name
) {
577 void BlinkPlatformImpl::histogramCustomCounts(
578 const char* name
, int sample
, int min
, int max
, int bucket_count
) {
579 // Copied from histogram macro, but without the static variable caching
580 // the histogram because name is dynamic.
581 base::HistogramBase
* counter
=
582 base::Histogram::FactoryGet(name
, min
, max
, bucket_count
,
583 base::HistogramBase::kUmaTargetedHistogramFlag
);
584 DCHECK_EQ(name
, counter
->histogram_name());
585 counter
->Add(sample
);
588 void BlinkPlatformImpl::histogramEnumeration(
589 const char* name
, int sample
, int boundary_value
) {
590 // Copied from histogram macro, but without the static variable caching
591 // the histogram because name is dynamic.
592 base::HistogramBase
* counter
=
593 base::LinearHistogram::FactoryGet(name
, 1, boundary_value
,
594 boundary_value
+ 1, base::HistogramBase::kUmaTargetedHistogramFlag
);
595 DCHECK_EQ(name
, counter
->histogram_name());
596 counter
->Add(sample
);
599 void BlinkPlatformImpl::histogramSparse(const char* name
, int sample
) {
600 // For sparse histograms, we can use the macro, as it does not incorporate a
602 UMA_HISTOGRAM_SPARSE_SLOWLY(name
, sample
);
605 const unsigned char* BlinkPlatformImpl::getTraceCategoryEnabledFlag(
606 const char* category_group
) {
607 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group
);
610 blink::Platform::TraceEventAPIAtomicWord
*
611 BlinkPlatformImpl::getTraceSamplingState(const unsigned thread_bucket
) {
612 switch (thread_bucket
) {
614 return reinterpret_cast<blink::Platform::TraceEventAPIAtomicWord
*>(
615 &TRACE_EVENT_API_THREAD_BUCKET(0));
617 return reinterpret_cast<blink::Platform::TraceEventAPIAtomicWord
*>(
618 &TRACE_EVENT_API_THREAD_BUCKET(1));
620 return reinterpret_cast<blink::Platform::TraceEventAPIAtomicWord
*>(
621 &TRACE_EVENT_API_THREAD_BUCKET(2));
623 NOTREACHED() << "Unknown thread bucket type.";
629 sizeof(blink::Platform::TraceEventHandle
) ==
630 sizeof(base::trace_event::TraceEventHandle
),
631 "TraceEventHandle types must be same size");
633 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
635 const unsigned char* category_group_enabled
,
637 unsigned long long id
,
640 const char** arg_names
,
641 const unsigned char* arg_types
,
642 const unsigned long long* arg_values
,
643 unsigned char flags
) {
644 base::TimeTicks timestamp_tt
= base::TimeTicks::FromInternalValue(
645 static_cast<int64
>(timestamp
* base::Time::kMicrosecondsPerSecond
));
646 base::trace_event::TraceEventHandle handle
=
647 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
648 phase
, category_group_enabled
, name
, id
,
649 base::PlatformThread::CurrentId(),
651 num_args
, arg_names
, arg_types
, arg_values
, NULL
, flags
);
652 blink::Platform::TraceEventHandle result
;
653 memcpy(&result
, &handle
, sizeof(result
));
657 blink::Platform::TraceEventHandle
BlinkPlatformImpl::addTraceEvent(
659 const unsigned char* category_group_enabled
,
661 unsigned long long id
,
664 const char** arg_names
,
665 const unsigned char* arg_types
,
666 const unsigned long long* arg_values
,
667 blink::WebConvertableToTraceFormat
* convertable_values
,
668 unsigned char flags
) {
669 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
670 convertable_wrappers
[2];
671 if (convertable_values
) {
672 size_t size
= std::min(static_cast<size_t>(num_args
),
673 arraysize(convertable_wrappers
));
674 for (size_t i
= 0; i
< size
; ++i
) {
675 if (arg_types
[i
] == TRACE_VALUE_TYPE_CONVERTABLE
) {
676 convertable_wrappers
[i
] =
677 new ConvertableToTraceFormatWrapper(convertable_values
[i
]);
681 base::TimeTicks timestamp_tt
= base::TimeTicks::FromInternalValue(
682 static_cast<int64
>(timestamp
* base::Time::kMicrosecondsPerSecond
));
683 base::trace_event::TraceEventHandle handle
=
684 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(phase
,
685 category_group_enabled
,
688 base::PlatformThread::CurrentId(),
694 convertable_wrappers
,
696 blink::Platform::TraceEventHandle result
;
697 memcpy(&result
, &handle
, sizeof(result
));
701 void BlinkPlatformImpl::updateTraceEventDuration(
702 const unsigned char* category_group_enabled
,
704 TraceEventHandle handle
) {
705 base::trace_event::TraceEventHandle traceEventHandle
;
706 memcpy(&traceEventHandle
, &handle
, sizeof(handle
));
707 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
708 category_group_enabled
, name
, traceEventHandle
);
711 void BlinkPlatformImpl::registerMemoryDumpProvider(
712 blink::WebMemoryDumpProvider
* wmdp
) {
713 WebMemoryDumpProviderAdapter
* wmdp_adapter
=
714 new WebMemoryDumpProviderAdapter(wmdp
);
716 memory_dump_providers_
.add(wmdp
, make_scoped_ptr(wmdp_adapter
)).second
;
719 wmdp_adapter
->set_is_registered(true);
720 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
721 wmdp_adapter
, base::ThreadTaskRunnerHandle::Get());
724 void BlinkPlatformImpl::unregisterMemoryDumpProvider(
725 blink::WebMemoryDumpProvider
* wmdp
) {
726 scoped_ptr
<WebMemoryDumpProviderAdapter
> wmdp_adapter
=
727 memory_dump_providers_
.take_and_erase(wmdp
);
730 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
732 wmdp_adapter
->set_is_registered(false);
735 blink::WebProcessMemoryDump
* BlinkPlatformImpl::createProcessMemoryDump() {
736 return new WebProcessMemoryDumpImpl();
741 WebData
loadAudioSpatializationResource(const char* name
) {
742 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE
743 if (!strcmp(name
, "Composite")) {
744 base::StringPiece resource
= GetContentClient()->GetDataResource(
745 IDR_AUDIO_SPATIALIZATION_COMPOSITE
, ui::SCALE_FACTOR_NONE
);
746 return WebData(resource
.data(), resource
.size());
750 #ifdef IDR_AUDIO_SPATIALIZATION_T000_P000
751 const size_t kExpectedSpatializationNameLength
= 31;
752 if (strlen(name
) != kExpectedSpatializationNameLength
) {
756 // Extract the azimuth and elevation from the resource name.
760 sscanf(name
, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth
, &elevation
);
761 if (values_parsed
!= 2) {
765 // The resource index values go through the elevations first, then azimuths.
766 const int kAngleSpacing
= 15;
768 // 0 <= elevation <= 90 (or 315 <= elevation <= 345)
769 // in increments of 15 degrees.
770 int elevation_index
=
771 elevation
<= 90 ? elevation
/ kAngleSpacing
:
772 7 + (elevation
- 315) / kAngleSpacing
;
773 bool is_elevation_index_good
= 0 <= elevation_index
&& elevation_index
< 10;
775 // 0 <= azimuth < 360 in increments of 15 degrees.
776 int azimuth_index
= azimuth
/ kAngleSpacing
;
777 bool is_azimuth_index_good
= 0 <= azimuth_index
&& azimuth_index
< 24;
779 const int kNumberOfElevations
= 10;
780 const int kNumberOfAudioResources
= 240;
781 int resource_index
= kNumberOfElevations
* azimuth_index
+ elevation_index
;
782 bool is_resource_index_good
= 0 <= resource_index
&&
783 resource_index
< kNumberOfAudioResources
;
785 if (is_azimuth_index_good
&& is_elevation_index_good
&&
786 is_resource_index_good
) {
787 const int kFirstAudioResourceIndex
= IDR_AUDIO_SPATIALIZATION_T000_P000
;
788 base::StringPiece resource
= GetContentClient()->GetDataResource(
789 kFirstAudioResourceIndex
+ resource_index
, ui::SCALE_FACTOR_NONE
);
790 return WebData(resource
.data(), resource
.size());
792 #endif // IDR_AUDIO_SPATIALIZATION_T000_P000
798 struct DataResource
{
801 ui::ScaleFactor scale_factor
;
804 const DataResource kDataResources
[] = {
805 {"missingImage", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_100P
},
806 {"missingImage@2x", IDR_BROKENIMAGE
, ui::SCALE_FACTOR_200P
},
807 {"mediaplayerPause", IDR_MEDIAPLAYER_PAUSE_BUTTON
, ui::SCALE_FACTOR_100P
},
808 {"mediaplayerPauseHover",
809 IDR_MEDIAPLAYER_PAUSE_BUTTON_HOVER
,
810 ui::SCALE_FACTOR_100P
},
811 {"mediaplayerPauseDown",
812 IDR_MEDIAPLAYER_PAUSE_BUTTON_DOWN
,
813 ui::SCALE_FACTOR_100P
},
814 {"mediaplayerPlay", IDR_MEDIAPLAYER_PLAY_BUTTON
, ui::SCALE_FACTOR_100P
},
815 {"mediaplayerPlayHover",
816 IDR_MEDIAPLAYER_PLAY_BUTTON_HOVER
,
817 ui::SCALE_FACTOR_100P
},
818 {"mediaplayerPlayDown",
819 IDR_MEDIAPLAYER_PLAY_BUTTON_DOWN
,
820 ui::SCALE_FACTOR_100P
},
821 {"mediaplayerPlayDisabled",
822 IDR_MEDIAPLAYER_PLAY_BUTTON_DISABLED
,
823 ui::SCALE_FACTOR_100P
},
824 {"mediaplayerSoundLevel3",
825 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON
,
826 ui::SCALE_FACTOR_100P
},
827 {"mediaplayerSoundLevel3Hover",
828 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_HOVER
,
829 ui::SCALE_FACTOR_100P
},
830 {"mediaplayerSoundLevel3Down",
831 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_DOWN
,
832 ui::SCALE_FACTOR_100P
},
833 {"mediaplayerSoundLevel2",
834 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON
,
835 ui::SCALE_FACTOR_100P
},
836 {"mediaplayerSoundLevel2Hover",
837 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_HOVER
,
838 ui::SCALE_FACTOR_100P
},
839 {"mediaplayerSoundLevel2Down",
840 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_DOWN
,
841 ui::SCALE_FACTOR_100P
},
842 {"mediaplayerSoundLevel1",
843 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON
,
844 ui::SCALE_FACTOR_100P
},
845 {"mediaplayerSoundLevel1Hover",
846 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_HOVER
,
847 ui::SCALE_FACTOR_100P
},
848 {"mediaplayerSoundLevel1Down",
849 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_DOWN
,
850 ui::SCALE_FACTOR_100P
},
851 {"mediaplayerSoundLevel0",
852 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON
,
853 ui::SCALE_FACTOR_100P
},
854 {"mediaplayerSoundLevel0Hover",
855 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_HOVER
,
856 ui::SCALE_FACTOR_100P
},
857 {"mediaplayerSoundLevel0Down",
858 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_DOWN
,
859 ui::SCALE_FACTOR_100P
},
860 {"mediaplayerSoundDisabled",
861 IDR_MEDIAPLAYER_SOUND_DISABLED
,
862 ui::SCALE_FACTOR_100P
},
863 {"mediaplayerSliderThumb",
864 IDR_MEDIAPLAYER_SLIDER_THUMB
,
865 ui::SCALE_FACTOR_100P
},
866 {"mediaplayerSliderThumbHover",
867 IDR_MEDIAPLAYER_SLIDER_THUMB_HOVER
,
868 ui::SCALE_FACTOR_100P
},
869 {"mediaplayerSliderThumbDown",
870 IDR_MEDIAPLAYER_SLIDER_THUMB_DOWN
,
871 ui::SCALE_FACTOR_100P
},
872 {"mediaplayerVolumeSliderThumb",
873 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB
,
874 ui::SCALE_FACTOR_100P
},
875 {"mediaplayerVolumeSliderThumbHover",
876 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_HOVER
,
877 ui::SCALE_FACTOR_100P
},
878 {"mediaplayerVolumeSliderThumbDown",
879 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DOWN
,
880 ui::SCALE_FACTOR_100P
},
881 {"mediaplayerVolumeSliderThumbDisabled",
882 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DISABLED
,
883 ui::SCALE_FACTOR_100P
},
884 {"mediaplayerClosedCaption",
885 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON
,
886 ui::SCALE_FACTOR_100P
},
887 {"mediaplayerClosedCaptionHover",
888 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_HOVER
,
889 ui::SCALE_FACTOR_100P
},
890 {"mediaplayerClosedCaptionDown",
891 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DOWN
,
892 ui::SCALE_FACTOR_100P
},
893 {"mediaplayerClosedCaptionDisabled",
894 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DISABLED
,
895 ui::SCALE_FACTOR_100P
},
896 {"mediaplayerFullscreen",
897 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON
,
898 ui::SCALE_FACTOR_100P
},
899 {"mediaplayerFullscreenHover",
900 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_HOVER
,
901 ui::SCALE_FACTOR_100P
},
902 {"mediaplayerFullscreenDown",
903 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DOWN
,
904 ui::SCALE_FACTOR_100P
},
905 {"mediaplayerCastOff",
906 IDR_MEDIAPLAYER_CAST_BUTTON_OFF
,
907 ui::SCALE_FACTOR_100P
},
908 {"mediaplayerCastOn",
909 IDR_MEDIAPLAYER_CAST_BUTTON_ON
,
910 ui::SCALE_FACTOR_100P
},
911 {"mediaplayerFullscreenDisabled",
912 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DISABLED
,
913 ui::SCALE_FACTOR_100P
},
914 {"mediaplayerOverlayCastOff",
915 IDR_MEDIAPLAYER_OVERLAY_CAST_BUTTON_OFF
,
916 ui::SCALE_FACTOR_100P
},
917 {"mediaplayerOverlayPlay",
918 IDR_MEDIAPLAYER_OVERLAY_PLAY_BUTTON
,
919 ui::SCALE_FACTOR_100P
},
920 {"panIcon", IDR_PAN_SCROLL_ICON
, ui::SCALE_FACTOR_100P
},
921 {"searchCancel", IDR_SEARCH_CANCEL
, ui::SCALE_FACTOR_100P
},
922 {"searchCancelPressed", IDR_SEARCH_CANCEL_PRESSED
, ui::SCALE_FACTOR_100P
},
923 {"searchMagnifier", IDR_SEARCH_MAGNIFIER
, ui::SCALE_FACTOR_100P
},
924 {"searchMagnifierResults",
925 IDR_SEARCH_MAGNIFIER_RESULTS
,
926 ui::SCALE_FACTOR_100P
},
927 {"textAreaResizeCorner", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_100P
},
928 {"textAreaResizeCorner@2x", IDR_TEXTAREA_RESIZER
, ui::SCALE_FACTOR_200P
},
929 {"generatePassword", IDR_PASSWORD_GENERATION_ICON
, ui::SCALE_FACTOR_100P
},
930 {"generatePasswordHover",
931 IDR_PASSWORD_GENERATION_ICON_HOVER
,
932 ui::SCALE_FACTOR_100P
},
933 {"html.css", IDR_UASTYLE_HTML_CSS
, ui::SCALE_FACTOR_NONE
},
934 {"quirks.css", IDR_UASTYLE_QUIRKS_CSS
, ui::SCALE_FACTOR_NONE
},
935 {"view-source.css", IDR_UASTYLE_VIEW_SOURCE_CSS
, ui::SCALE_FACTOR_NONE
},
936 {"themeChromium.css",
937 IDR_UASTYLE_THEME_CHROMIUM_CSS
,
938 ui::SCALE_FACTOR_NONE
},
939 #if defined(OS_ANDROID)
940 {"themeChromiumAndroid.css",
941 IDR_UASTYLE_THEME_CHROMIUM_ANDROID_CSS
,
942 ui::SCALE_FACTOR_NONE
},
943 {"mediaControlsAndroid.css",
944 IDR_UASTYLE_MEDIA_CONTROLS_ANDROID_CSS
,
945 ui::SCALE_FACTOR_NONE
},
948 {"themeChromiumLinux.css",
949 IDR_UASTYLE_THEME_CHROMIUM_LINUX_CSS
,
950 ui::SCALE_FACTOR_NONE
},
952 {"themeChromiumSkia.css",
953 IDR_UASTYLE_THEME_CHROMIUM_SKIA_CSS
,
954 ui::SCALE_FACTOR_NONE
},
955 {"themeInputMultipleFields.css",
956 IDR_UASTYLE_THEME_INPUT_MULTIPLE_FIELDS_CSS
,
957 ui::SCALE_FACTOR_NONE
},
958 #if defined(OS_MACOSX)
959 {"themeMac.css", IDR_UASTYLE_THEME_MAC_CSS
, ui::SCALE_FACTOR_NONE
},
961 {"themeWin.css", IDR_UASTYLE_THEME_WIN_CSS
, ui::SCALE_FACTOR_NONE
},
962 {"themeWinQuirks.css",
963 IDR_UASTYLE_THEME_WIN_QUIRKS_CSS
,
964 ui::SCALE_FACTOR_NONE
},
965 {"svg.css", IDR_UASTYLE_SVG_CSS
, ui::SCALE_FACTOR_NONE
},
966 {"mathml.css", IDR_UASTYLE_MATHML_CSS
, ui::SCALE_FACTOR_NONE
},
967 {"mediaControls.css",
968 IDR_UASTYLE_MEDIA_CONTROLS_CSS
,
969 ui::SCALE_FACTOR_NONE
},
970 {"fullscreen.css", IDR_UASTYLE_FULLSCREEN_CSS
, ui::SCALE_FACTOR_NONE
},
971 {"xhtmlmp.css", IDR_UASTYLE_XHTMLMP_CSS
, ui::SCALE_FACTOR_NONE
},
972 {"viewportAndroid.css",
973 IDR_UASTYLE_VIEWPORT_ANDROID_CSS
,
974 ui::SCALE_FACTOR_NONE
},
975 {"InspectorOverlayPage.html",
976 IDR_INSPECTOR_OVERLAY_PAGE_HTML
,
977 ui::SCALE_FACTOR_NONE
},
978 {"InjectedScriptSource.js",
979 IDR_INSPECTOR_INJECTED_SCRIPT_SOURCE_JS
,
980 ui::SCALE_FACTOR_NONE
},
981 {"DebuggerScriptSource.js",
982 IDR_INSPECTOR_DEBUGGER_SCRIPT_SOURCE_JS
,
983 ui::SCALE_FACTOR_NONE
},
984 {"DocumentExecCommand.js",
985 IDR_PRIVATE_SCRIPT_DOCUMENTEXECCOMMAND_JS
,
986 ui::SCALE_FACTOR_NONE
},
987 {"DocumentXMLTreeViewer.css",
988 IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_CSS
,
989 ui::SCALE_FACTOR_NONE
},
990 {"DocumentXMLTreeViewer.js",
991 IDR_PRIVATE_SCRIPT_DOCUMENTXMLTREEVIEWER_JS
,
992 ui::SCALE_FACTOR_NONE
},
993 {"HTMLMarqueeElement.js",
994 IDR_PRIVATE_SCRIPT_HTMLMARQUEEELEMENT_JS
,
995 ui::SCALE_FACTOR_NONE
},
996 {"PluginPlaceholderElement.js",
997 IDR_PRIVATE_SCRIPT_PLUGINPLACEHOLDERELEMENT_JS
,
998 ui::SCALE_FACTOR_NONE
},
999 {"PrivateScriptRunner.js",
1000 IDR_PRIVATE_SCRIPT_PRIVATESCRIPTRUNNER_JS
,
1001 ui::SCALE_FACTOR_NONE
},
1002 #ifdef IDR_PICKER_COMMON_JS
1003 {"pickerCommon.js", IDR_PICKER_COMMON_JS
, ui::SCALE_FACTOR_NONE
},
1004 {"pickerCommon.css", IDR_PICKER_COMMON_CSS
, ui::SCALE_FACTOR_NONE
},
1005 {"calendarPicker.js", IDR_CALENDAR_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
1006 {"calendarPicker.css", IDR_CALENDAR_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
1007 {"listPicker.js", IDR_LIST_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
1008 {"listPicker.css", IDR_LIST_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
1009 {"pickerButton.css", IDR_PICKER_BUTTON_CSS
, ui::SCALE_FACTOR_NONE
},
1010 {"suggestionPicker.js", IDR_SUGGESTION_PICKER_JS
, ui::SCALE_FACTOR_NONE
},
1011 {"suggestionPicker.css", IDR_SUGGESTION_PICKER_CSS
, ui::SCALE_FACTOR_NONE
},
1012 {"colorSuggestionPicker.js",
1013 IDR_COLOR_SUGGESTION_PICKER_JS
,
1014 ui::SCALE_FACTOR_NONE
},
1015 {"colorSuggestionPicker.css",
1016 IDR_COLOR_SUGGESTION_PICKER_CSS
,
1017 ui::SCALE_FACTOR_NONE
},
1023 WebData
BlinkPlatformImpl::loadResource(const char* name
) {
1024 // Some clients will call into this method with an empty |name| when they have
1025 // optional resources. For example, the PopupMenuChromium code can have icons
1026 // for some Autofill items but not for others.
1030 // Check the name prefix to see if it's an audio resource.
1031 if (StartsWithASCII(name
, "IRC_Composite", true) ||
1032 StartsWithASCII(name
, "Composite", true))
1033 return loadAudioSpatializationResource(name
);
1035 // TODO(flackr): We should use a better than linear search here, a trie would
1037 for (size_t i
= 0; i
< arraysize(kDataResources
); ++i
) {
1038 if (!strcmp(name
, kDataResources
[i
].name
)) {
1039 base::StringPiece resource
= GetContentClient()->GetDataResource(
1040 kDataResources
[i
].id
, kDataResources
[i
].scale_factor
);
1041 return WebData(resource
.data(), resource
.size());
1045 NOTREACHED() << "Unknown image resource " << name
;
1049 WebString
BlinkPlatformImpl::queryLocalizedString(
1050 WebLocalizedString::Name name
) {
1051 int message_id
= ToMessageID(name
);
1054 return GetContentClient()->GetLocalizedString(message_id
);
1057 WebString
BlinkPlatformImpl::queryLocalizedString(
1058 WebLocalizedString::Name name
, int numeric_value
) {
1059 return queryLocalizedString(name
, base::IntToString16(numeric_value
));
1062 WebString
BlinkPlatformImpl::queryLocalizedString(
1063 WebLocalizedString::Name name
, const WebString
& value
) {
1064 int message_id
= ToMessageID(name
);
1067 return ReplaceStringPlaceholders(GetContentClient()->GetLocalizedString(
1068 message_id
), value
, NULL
);
1071 WebString
BlinkPlatformImpl::queryLocalizedString(
1072 WebLocalizedString::Name name
,
1073 const WebString
& value1
,
1074 const WebString
& value2
) {
1075 int message_id
= ToMessageID(name
);
1078 std::vector
<base::string16
> values
;
1080 values
.push_back(value1
);
1081 values
.push_back(value2
);
1082 return ReplaceStringPlaceholders(
1083 GetContentClient()->GetLocalizedString(message_id
), values
, NULL
);
1086 double BlinkPlatformImpl::currentTime() {
1087 return base::Time::Now().ToDoubleT();
1090 double BlinkPlatformImpl::monotonicallyIncreasingTime() {
1091 return base::TimeTicks::Now().ToInternalValue() /
1092 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
1095 double BlinkPlatformImpl::systemTraceTime() {
1096 return base::TimeTicks::NowFromSystemTraceTime().ToInternalValue() /
1097 static_cast<double>(base::Time::kMicrosecondsPerSecond
);
1100 void BlinkPlatformImpl::cryptographicallyRandomValues(
1101 unsigned char* buffer
, size_t length
) {
1102 base::RandBytes(buffer
, length
);
1105 void BlinkPlatformImpl::setSharedTimerFiredFunction(void (*func
)()) {
1106 shared_timer_func_
= func
;
1109 void BlinkPlatformImpl::setSharedTimerFireInterval(
1110 double interval_seconds
) {
1111 shared_timer_fire_time_
= interval_seconds
+ monotonicallyIncreasingTime();
1112 if (shared_timer_suspended_
) {
1113 shared_timer_fire_time_was_set_while_suspended_
= true;
1117 // By converting between double and int64 representation, we run the risk
1118 // of losing precision due to rounding errors. Performing computations in
1119 // microseconds reduces this risk somewhat. But there still is the potential
1120 // of us computing a fire time for the timer that is shorter than what we
1122 // As the event loop will check event deadlines prior to actually firing
1123 // them, there is a risk of needlessly rescheduling events and of
1124 // needlessly looping if sleep times are too short even by small amounts.
1125 // This results in measurable performance degradation unless we use ceil() to
1126 // always round up the sleep times.
1127 int64 interval
= static_cast<int64
>(
1128 ceil(interval_seconds
* base::Time::kMillisecondsPerSecond
)
1129 * base::Time::kMicrosecondsPerMillisecond
);
1134 shared_timer_
.Stop();
1135 shared_timer_
.Start(FROM_HERE
, base::TimeDelta::FromMicroseconds(interval
),
1136 this, &BlinkPlatformImpl::DoTimeout
);
1137 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval
));
1140 void BlinkPlatformImpl::stopSharedTimer() {
1141 shared_timer_
.Stop();
1144 blink::WebGestureCurve
* BlinkPlatformImpl::createFlingAnimationCurve(
1145 blink::WebGestureDevice device_source
,
1146 const blink::WebFloatPoint
& velocity
,
1147 const blink::WebSize
& cumulative_scroll
) {
1148 return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
1149 gfx::Vector2dF(velocity
.x
, velocity
.y
),
1150 gfx::Vector2dF(cumulative_scroll
.width
, cumulative_scroll
.height
),
1151 IsMainThread()).release();
1154 void BlinkPlatformImpl::didStartWorkerRunLoop() {
1155 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
1156 worker_task_runner
->OnWorkerRunLoopStarted();
1159 void BlinkPlatformImpl::didStopWorkerRunLoop() {
1160 WorkerTaskRunner
* worker_task_runner
= WorkerTaskRunner::Instance();
1161 worker_task_runner
->OnWorkerRunLoopStopped();
1164 blink::WebCrypto
* BlinkPlatformImpl::crypto() {
1165 return &web_crypto_
;
1168 blink::WebGeofencingProvider
* BlinkPlatformImpl::geofencingProvider() {
1169 return geofencing_provider_
.get();
1172 blink::WebBluetooth
* BlinkPlatformImpl::bluetooth() {
1173 return bluetooth_
.get();
1176 blink::WebNotificationManager
*
1177 BlinkPlatformImpl::notificationManager() {
1178 if (!thread_safe_sender_
.get() || !notification_dispatcher_
.get())
1181 return NotificationManager::ThreadSpecificInstance(
1182 thread_safe_sender_
.get(),
1183 main_thread_task_runner_
.get(),
1184 notification_dispatcher_
.get());
1187 blink::WebPushProvider
* BlinkPlatformImpl::pushProvider() {
1188 if (!thread_safe_sender_
.get() || !push_dispatcher_
.get())
1191 return PushProvider::ThreadSpecificInstance(thread_safe_sender_
.get(),
1192 push_dispatcher_
.get());
1195 blink::WebNavigatorConnectProvider
*
1196 BlinkPlatformImpl::navigatorConnectProvider() {
1197 if (!thread_safe_sender_
.get())
1200 return NavigatorConnectProvider::ThreadSpecificInstance(
1201 thread_safe_sender_
.get(), main_thread_task_runner_
);
1204 blink::WebPermissionClient
* BlinkPlatformImpl::permissionClient() {
1205 if (!permission_client_
.get())
1209 return permission_client_
.get();
1211 return PermissionDispatcherThreadProxy::GetThreadInstance(
1212 main_thread_task_runner_
.get(), permission_client_
.get());
1215 blink::WebSyncProvider
* BlinkPlatformImpl::backgroundSyncProvider() {
1216 if (!sync_provider_
.get())
1220 return sync_provider_
.get();
1222 return BackgroundSyncProviderThreadProxy::GetThreadInstance(
1223 main_thread_task_runner_
.get(), sync_provider_
.get());
1226 WebThemeEngine
* BlinkPlatformImpl::themeEngine() {
1227 return &native_theme_engine_
;
1230 WebFallbackThemeEngine
* BlinkPlatformImpl::fallbackThemeEngine() {
1231 return &fallback_theme_engine_
;
1234 blink::Platform::FileHandle
BlinkPlatformImpl::databaseOpenFile(
1235 const blink::WebString
& vfs_file_name
, int desired_flags
) {
1237 return INVALID_HANDLE_VALUE
;
1238 #elif defined(OS_POSIX)
1243 int BlinkPlatformImpl::databaseDeleteFile(
1244 const blink::WebString
& vfs_file_name
, bool sync_dir
) {
1248 long BlinkPlatformImpl::databaseGetFileAttributes(
1249 const blink::WebString
& vfs_file_name
) {
1253 long long BlinkPlatformImpl::databaseGetFileSize(
1254 const blink::WebString
& vfs_file_name
) {
1258 long long BlinkPlatformImpl::databaseGetSpaceAvailableForOrigin(
1259 const blink::WebString
& origin_identifier
) {
1263 bool BlinkPlatformImpl::databaseSetFileSize(
1264 const blink::WebString
& vfs_file_name
, long long size
) {
1268 blink::WebString
BlinkPlatformImpl::signedPublicKeyAndChallengeString(
1269 unsigned key_size_index
,
1270 const blink::WebString
& challenge
,
1271 const blink::WebURL
& url
) {
1272 return blink::WebString("");
1275 static scoped_ptr
<base::ProcessMetrics
> CurrentProcessMetrics() {
1276 using base::ProcessMetrics
;
1277 #if defined(OS_MACOSX)
1278 return scoped_ptr
<ProcessMetrics
>(
1279 // The default port provider is sufficient to get data for the current
1281 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
1284 return scoped_ptr
<ProcessMetrics
>(
1285 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()));
1289 static size_t getMemoryUsageMB(bool bypass_cache
) {
1290 size_t current_mem_usage
= 0;
1291 MemoryUsageCache
* mem_usage_cache_singleton
= MemoryUsageCache::GetInstance();
1292 if (!bypass_cache
&&
1293 mem_usage_cache_singleton
->IsCachedValueValid(¤t_mem_usage
))
1294 return current_mem_usage
;
1296 current_mem_usage
= GetMemoryUsageKB() >> 10;
1297 mem_usage_cache_singleton
->SetMemoryValue(current_mem_usage
);
1298 return current_mem_usage
;
1301 size_t BlinkPlatformImpl::memoryUsageMB() {
1302 return getMemoryUsageMB(false);
1305 size_t BlinkPlatformImpl::actualMemoryUsageMB() {
1306 return getMemoryUsageMB(true);
1309 size_t BlinkPlatformImpl::physicalMemoryMB() {
1310 return static_cast<size_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
1313 size_t BlinkPlatformImpl::virtualMemoryLimitMB() {
1314 return static_cast<size_t>(base::SysInfo::AmountOfVirtualMemoryMB());
1317 size_t BlinkPlatformImpl::numberOfProcessors() {
1318 return static_cast<size_t>(base::SysInfo::NumberOfProcessors());
1321 bool BlinkPlatformImpl::processMemorySizesInBytes(
1322 size_t* private_bytes
,
1323 size_t* shared_bytes
) {
1324 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes
, shared_bytes
);
1327 bool BlinkPlatformImpl::memoryAllocatorWasteInBytes(size_t* size
) {
1328 return base::allocator::GetAllocatorWasteSize(size
);
1331 blink::WebDiscardableMemory
*
1332 BlinkPlatformImpl::allocateAndLockDiscardableMemory(size_t bytes
) {
1333 return content::WebDiscardableMemoryImpl::CreateLockedMemory(bytes
).release();
1336 size_t BlinkPlatformImpl::maxDecodedImageBytes() {
1337 #if defined(OS_ANDROID)
1338 if (base::SysInfo::IsLowEndDevice()) {
1339 // Limit image decoded size to 3M pixels on low end devices.
1340 // 4 is maximum number of bytes per pixel.
1341 return 3 * 1024 * 1024 * 4;
1343 // For other devices, limit decoded image size based on the amount of physical
1345 // In some cases all physical memory is not accessible by Chromium, as it can
1346 // be reserved for direct use by certain hardware. Thus, we set the limit so
1347 // that 1.6GB of reported physical memory on a 2GB device is enough to set the
1348 // limit at 16M pixels, which is a desirable value since 4K*4K is a relatively
1349 // common texture size.
1350 return base::SysInfo::AmountOfPhysicalMemory() / 25;
1352 return noDecodedImageByteLimit
;
1356 void BlinkPlatformImpl::SuspendSharedTimer() {
1357 ++shared_timer_suspended_
;
1360 void BlinkPlatformImpl::ResumeSharedTimer() {
1361 DCHECK_GT(shared_timer_suspended_
, 0);
1363 // The shared timer may have fired or been adjusted while we were suspended.
1364 if (--shared_timer_suspended_
== 0 &&
1365 (!shared_timer_
.IsRunning() ||
1366 shared_timer_fire_time_was_set_while_suspended_
)) {
1367 shared_timer_fire_time_was_set_while_suspended_
= false;
1368 setSharedTimerFireInterval(
1369 shared_timer_fire_time_
- monotonicallyIncreasingTime());
1373 scoped_refptr
<base::SingleThreadTaskRunner
>
1374 BlinkPlatformImpl::MainTaskRunnerForCurrentThread() {
1375 if (main_thread_task_runner_
.get() &&
1376 main_thread_task_runner_
->BelongsToCurrentThread()) {
1377 return main_thread_task_runner_
;
1379 return base::ThreadTaskRunnerHandle::Get();
1383 bool BlinkPlatformImpl::IsMainThread() const {
1384 return main_thread_task_runner_
.get() &&
1385 main_thread_task_runner_
->BelongsToCurrentThread();
1388 WebString
BlinkPlatformImpl::domCodeStringFromEnum(int dom_code
) {
1389 return WebString::fromUTF8(ui::KeycodeConverter::DomCodeToCodeString(
1390 static_cast<ui::DomCode
>(dom_code
)));
1393 int BlinkPlatformImpl::domEnumFromCodeString(const WebString
& code
) {
1394 return static_cast<int>(ui::KeycodeConverter::CodeStringToDomCode(
1395 code
.utf8().data()));
1398 } // namespace content