| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "webkit/glue/webkitplatformsupport_impl.h" | |
| 6 | |
| 7 #include <math.h> | |
| 8 | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/allocator/allocator_extension.h" | |
| 12 #include "base/bind.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/singleton.h" | |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/metrics/histogram.h" | |
| 18 #include "base/metrics/sparse_histogram.h" | |
| 19 #include "base/metrics/stats_counters.h" | |
| 20 #include "base/platform_file.h" | |
| 21 #include "base/process_util.h" | |
| 22 #include "base/rand_util.h" | |
| 23 #include "base/strings/string_number_conversions.h" | |
| 24 #include "base/strings/string_util.h" | |
| 25 #include "base/strings/utf_string_conversions.h" | |
| 26 #include "base/synchronization/lock.h" | |
| 27 #include "base/sys_info.h" | |
| 28 #include "base/time/time.h" | |
| 29 #include "grit/webkit_chromium_resources.h" | |
| 30 #include "grit/webkit_resources.h" | |
| 31 #include "grit/webkit_strings.h" | |
| 32 #include "net/base/data_url.h" | |
| 33 #include "net/base/mime_util.h" | |
| 34 #include "net/base/net_errors.h" | |
| 35 #include "third_party/WebKit/public/platform/WebCookie.h" | |
| 36 #include "third_party/WebKit/public/platform/WebData.h" | |
| 37 #include "third_party/WebKit/public/platform/WebDiscardableMemory.h" | |
| 38 #include "third_party/WebKit/public/platform/WebGestureCurve.h" | |
| 39 #include "third_party/WebKit/public/platform/WebString.h" | |
| 40 #include "third_party/WebKit/public/platform/WebURL.h" | |
| 41 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 42 #include "third_party/WebKit/public/web/WebFrameClient.h" | |
| 43 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 44 #include "third_party/WebKit/public/web/WebScreenInfo.h" | |
| 45 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" | |
| 46 #include "ui/base/layout.h" | |
| 47 #include "webkit/common/user_agent/user_agent.h" | |
| 48 #include "webkit/glue/webkit_glue.h" | |
| 49 #include "webkit/glue/websocketstreamhandle_impl.h" | |
| 50 #include "webkit/glue/weburlloader_impl.h" | |
| 51 | |
| 52 using WebKit::WebAudioBus; | |
| 53 using WebKit::WebCookie; | |
| 54 using WebKit::WebData; | |
| 55 using WebKit::WebLocalizedString; | |
| 56 using WebKit::WebPluginListBuilder; | |
| 57 using WebKit::WebString; | |
| 58 using WebKit::WebSocketStreamHandle; | |
| 59 using WebKit::WebURL; | |
| 60 using WebKit::WebURLError; | |
| 61 using WebKit::WebURLLoader; | |
| 62 using WebKit::WebVector; | |
| 63 | |
| 64 namespace { | |
| 65 | |
| 66 // A simple class to cache the memory usage for a given amount of time. | |
| 67 class MemoryUsageCache { | |
| 68 public: | |
| 69 // Retrieves the Singleton. | |
| 70 static MemoryUsageCache* GetInstance() { | |
| 71 return Singleton<MemoryUsageCache>::get(); | |
| 72 } | |
| 73 | |
| 74 MemoryUsageCache() : memory_value_(0) { Init(); } | |
| 75 ~MemoryUsageCache() {} | |
| 76 | |
| 77 void Init() { | |
| 78 const unsigned int kCacheSeconds = 1; | |
| 79 cache_valid_time_ = base::TimeDelta::FromSeconds(kCacheSeconds); | |
| 80 } | |
| 81 | |
| 82 // Returns true if the cached value is fresh. | |
| 83 // Returns false if the cached value is stale, or if |cached_value| is NULL. | |
| 84 bool IsCachedValueValid(size_t* cached_value) { | |
| 85 base::AutoLock scoped_lock(lock_); | |
| 86 if (!cached_value) | |
| 87 return false; | |
| 88 if (base::Time::Now() - last_updated_time_ > cache_valid_time_) | |
| 89 return false; | |
| 90 *cached_value = memory_value_; | |
| 91 return true; | |
| 92 }; | |
| 93 | |
| 94 // Setter for |memory_value_|, refreshes |last_updated_time_|. | |
| 95 void SetMemoryValue(const size_t value) { | |
| 96 base::AutoLock scoped_lock(lock_); | |
| 97 memory_value_ = value; | |
| 98 last_updated_time_ = base::Time::Now(); | |
| 99 } | |
| 100 | |
| 101 private: | |
| 102 // The cached memory value. | |
| 103 size_t memory_value_; | |
| 104 | |
| 105 // How long the cached value should remain valid. | |
| 106 base::TimeDelta cache_valid_time_; | |
| 107 | |
| 108 // The last time the cached value was updated. | |
| 109 base::Time last_updated_time_; | |
| 110 | |
| 111 base::Lock lock_; | |
| 112 }; | |
| 113 | |
| 114 } // anonymous namespace | |
| 115 | |
| 116 namespace webkit_glue { | |
| 117 | |
| 118 static int ToMessageID(WebLocalizedString::Name name) { | |
| 119 switch (name) { | |
| 120 case WebLocalizedString::AXAMPMFieldText: | |
| 121 return IDS_AX_AM_PM_FIELD_TEXT; | |
| 122 case WebLocalizedString::AXButtonActionVerb: | |
| 123 return IDS_AX_BUTTON_ACTION_VERB; | |
| 124 case WebLocalizedString::AXCheckedCheckBoxActionVerb: | |
| 125 return IDS_AX_CHECKED_CHECK_BOX_ACTION_VERB; | |
| 126 case WebLocalizedString::AXDateTimeFieldEmptyValueText: | |
| 127 return IDS_AX_DATE_TIME_FIELD_EMPTY_VALUE_TEXT; | |
| 128 case WebLocalizedString::AXDayOfMonthFieldText: | |
| 129 return IDS_AX_DAY_OF_MONTH_FIELD_TEXT; | |
| 130 case WebLocalizedString::AXHeadingText: | |
| 131 return IDS_AX_ROLE_HEADING; | |
| 132 case WebLocalizedString::AXHourFieldText: | |
| 133 return IDS_AX_HOUR_FIELD_TEXT; | |
| 134 case WebLocalizedString::AXImageMapText: | |
| 135 return IDS_AX_ROLE_IMAGE_MAP; | |
| 136 case WebLocalizedString::AXLinkActionVerb: | |
| 137 return IDS_AX_LINK_ACTION_VERB; | |
| 138 case WebLocalizedString::AXLinkText: | |
| 139 return IDS_AX_ROLE_LINK; | |
| 140 case WebLocalizedString::AXListMarkerText: | |
| 141 return IDS_AX_ROLE_LIST_MARKER; | |
| 142 case WebLocalizedString::AXMediaDefault: | |
| 143 return IDS_AX_MEDIA_DEFAULT; | |
| 144 case WebLocalizedString::AXMediaAudioElement: | |
| 145 return IDS_AX_MEDIA_AUDIO_ELEMENT; | |
| 146 case WebLocalizedString::AXMediaVideoElement: | |
| 147 return IDS_AX_MEDIA_VIDEO_ELEMENT; | |
| 148 case WebLocalizedString::AXMediaMuteButton: | |
| 149 return IDS_AX_MEDIA_MUTE_BUTTON; | |
| 150 case WebLocalizedString::AXMediaUnMuteButton: | |
| 151 return IDS_AX_MEDIA_UNMUTE_BUTTON; | |
| 152 case WebLocalizedString::AXMediaPlayButton: | |
| 153 return IDS_AX_MEDIA_PLAY_BUTTON; | |
| 154 case WebLocalizedString::AXMediaPauseButton: | |
| 155 return IDS_AX_MEDIA_PAUSE_BUTTON; | |
| 156 case WebLocalizedString::AXMediaSlider: | |
| 157 return IDS_AX_MEDIA_SLIDER; | |
| 158 case WebLocalizedString::AXMediaSliderThumb: | |
| 159 return IDS_AX_MEDIA_SLIDER_THUMB; | |
| 160 case WebLocalizedString::AXMediaRewindButton: | |
| 161 return IDS_AX_MEDIA_REWIND_BUTTON; | |
| 162 case WebLocalizedString::AXMediaReturnToRealTime: | |
| 163 return IDS_AX_MEDIA_RETURN_TO_REALTIME_BUTTON; | |
| 164 case WebLocalizedString::AXMediaCurrentTimeDisplay: | |
| 165 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY; | |
| 166 case WebLocalizedString::AXMediaTimeRemainingDisplay: | |
| 167 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY; | |
| 168 case WebLocalizedString::AXMediaStatusDisplay: | |
| 169 return IDS_AX_MEDIA_STATUS_DISPLAY; | |
| 170 case WebLocalizedString::AXMediaEnterFullscreenButton: | |
| 171 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON; | |
| 172 case WebLocalizedString::AXMediaExitFullscreenButton: | |
| 173 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON; | |
| 174 case WebLocalizedString::AXMediaSeekForwardButton: | |
| 175 return IDS_AX_MEDIA_SEEK_FORWARD_BUTTON; | |
| 176 case WebLocalizedString::AXMediaSeekBackButton: | |
| 177 return IDS_AX_MEDIA_SEEK_BACK_BUTTON; | |
| 178 case WebLocalizedString::AXMediaShowClosedCaptionsButton: | |
| 179 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON; | |
| 180 case WebLocalizedString::AXMediaHideClosedCaptionsButton: | |
| 181 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON; | |
| 182 case WebLocalizedString::AXMediaAudioElementHelp: | |
| 183 return IDS_AX_MEDIA_AUDIO_ELEMENT_HELP; | |
| 184 case WebLocalizedString::AXMediaVideoElementHelp: | |
| 185 return IDS_AX_MEDIA_VIDEO_ELEMENT_HELP; | |
| 186 case WebLocalizedString::AXMediaMuteButtonHelp: | |
| 187 return IDS_AX_MEDIA_MUTE_BUTTON_HELP; | |
| 188 case WebLocalizedString::AXMediaUnMuteButtonHelp: | |
| 189 return IDS_AX_MEDIA_UNMUTE_BUTTON_HELP; | |
| 190 case WebLocalizedString::AXMediaPlayButtonHelp: | |
| 191 return IDS_AX_MEDIA_PLAY_BUTTON_HELP; | |
| 192 case WebLocalizedString::AXMediaPauseButtonHelp: | |
| 193 return IDS_AX_MEDIA_PAUSE_BUTTON_HELP; | |
| 194 case WebLocalizedString::AXMediaSliderHelp: | |
| 195 return IDS_AX_MEDIA_SLIDER_HELP; | |
| 196 case WebLocalizedString::AXMediaSliderThumbHelp: | |
| 197 return IDS_AX_MEDIA_SLIDER_THUMB_HELP; | |
| 198 case WebLocalizedString::AXMediaRewindButtonHelp: | |
| 199 return IDS_AX_MEDIA_REWIND_BUTTON_HELP; | |
| 200 case WebLocalizedString::AXMediaReturnToRealTimeHelp: | |
| 201 return IDS_AX_MEDIA_RETURN_TO_REALTIME_BUTTON_HELP; | |
| 202 case WebLocalizedString::AXMediaCurrentTimeDisplayHelp: | |
| 203 return IDS_AX_MEDIA_CURRENT_TIME_DISPLAY_HELP; | |
| 204 case WebLocalizedString::AXMediaTimeRemainingDisplayHelp: | |
| 205 return IDS_AX_MEDIA_TIME_REMAINING_DISPLAY_HELP; | |
| 206 case WebLocalizedString::AXMediaStatusDisplayHelp: | |
| 207 return IDS_AX_MEDIA_STATUS_DISPLAY_HELP; | |
| 208 case WebLocalizedString::AXMediaEnterFullscreenButtonHelp: | |
| 209 return IDS_AX_MEDIA_ENTER_FULL_SCREEN_BUTTON_HELP; | |
| 210 case WebLocalizedString::AXMediaExitFullscreenButtonHelp: | |
| 211 return IDS_AX_MEDIA_EXIT_FULL_SCREEN_BUTTON_HELP; | |
| 212 case WebLocalizedString::AXMediaSeekForwardButtonHelp: | |
| 213 return IDS_AX_MEDIA_SEEK_FORWARD_BUTTON_HELP; | |
| 214 case WebLocalizedString::AXMediaSeekBackButtonHelp: | |
| 215 return IDS_AX_MEDIA_SEEK_BACK_BUTTON_HELP; | |
| 216 case WebLocalizedString::AXMediaShowClosedCaptionsButtonHelp: | |
| 217 return IDS_AX_MEDIA_SHOW_CLOSED_CAPTIONS_BUTTON_HELP; | |
| 218 case WebLocalizedString::AXMediaHideClosedCaptionsButtonHelp: | |
| 219 return IDS_AX_MEDIA_HIDE_CLOSED_CAPTIONS_BUTTON_HELP; | |
| 220 case WebLocalizedString::AXMillisecondFieldText: | |
| 221 return IDS_AX_MILLISECOND_FIELD_TEXT; | |
| 222 case WebLocalizedString::AXMinuteFieldText: | |
| 223 return IDS_AX_MINUTE_FIELD_TEXT; | |
| 224 case WebLocalizedString::AXMonthFieldText: | |
| 225 return IDS_AX_MONTH_FIELD_TEXT; | |
| 226 case WebLocalizedString::AXRadioButtonActionVerb: | |
| 227 return IDS_AX_RADIO_BUTTON_ACTION_VERB; | |
| 228 case WebLocalizedString::AXSecondFieldText: | |
| 229 return IDS_AX_SECOND_FIELD_TEXT; | |
| 230 case WebLocalizedString::AXTextFieldActionVerb: | |
| 231 return IDS_AX_TEXT_FIELD_ACTION_VERB; | |
| 232 case WebLocalizedString::AXUncheckedCheckBoxActionVerb: | |
| 233 return IDS_AX_UNCHECKED_CHECK_BOX_ACTION_VERB; | |
| 234 case WebLocalizedString::AXWebAreaText: | |
| 235 return IDS_AX_ROLE_WEB_AREA; | |
| 236 case WebLocalizedString::AXWeekOfYearFieldText: | |
| 237 return IDS_AX_WEEK_OF_YEAR_FIELD_TEXT; | |
| 238 case WebLocalizedString::AXYearFieldText: | |
| 239 return IDS_AX_YEAR_FIELD_TEXT; | |
| 240 case WebLocalizedString::CalendarClear: | |
| 241 return IDS_FORM_CALENDAR_CLEAR; | |
| 242 case WebLocalizedString::CalendarToday: | |
| 243 return IDS_FORM_CALENDAR_TODAY; | |
| 244 case WebLocalizedString::DateFormatDayInMonthLabel: | |
| 245 return IDS_FORM_DATE_FORMAT_DAY_IN_MONTH; | |
| 246 case WebLocalizedString::DateFormatMonthLabel: | |
| 247 return IDS_FORM_DATE_FORMAT_MONTH; | |
| 248 case WebLocalizedString::DateFormatYearLabel: | |
| 249 return IDS_FORM_DATE_FORMAT_YEAR; | |
| 250 case WebLocalizedString::DetailsLabel: | |
| 251 return IDS_DETAILS_WITHOUT_SUMMARY_LABEL; | |
| 252 case WebLocalizedString::FileButtonChooseFileLabel: | |
| 253 return IDS_FORM_FILE_BUTTON_LABEL; | |
| 254 case WebLocalizedString::FileButtonChooseMultipleFilesLabel: | |
| 255 return IDS_FORM_MULTIPLE_FILES_BUTTON_LABEL; | |
| 256 case WebLocalizedString::FileButtonNoFileSelectedLabel: | |
| 257 return IDS_FORM_FILE_NO_FILE_LABEL; | |
| 258 case WebLocalizedString::InputElementAltText: | |
| 259 return IDS_FORM_INPUT_ALT; | |
| 260 case WebLocalizedString::KeygenMenuHighGradeKeySize: | |
| 261 return IDS_KEYGEN_HIGH_GRADE_KEY; | |
| 262 case WebLocalizedString::KeygenMenuMediumGradeKeySize: | |
| 263 return IDS_KEYGEN_MED_GRADE_KEY; | |
| 264 case WebLocalizedString::MissingPluginText: | |
| 265 return IDS_PLUGIN_INITIALIZATION_ERROR; | |
| 266 case WebLocalizedString::MultipleFileUploadText: | |
| 267 return IDS_FORM_FILE_MULTIPLE_UPLOAD; | |
| 268 case WebLocalizedString::OtherColorLabel: | |
| 269 return IDS_FORM_OTHER_COLOR_LABEL; | |
| 270 case WebLocalizedString::OtherDateLabel: | |
| 271 return IDS_FORM_OTHER_DATE_LABEL; | |
| 272 case WebLocalizedString::OtherMonthLabel: | |
| 273 return IDS_FORM_OTHER_MONTH_LABEL; | |
| 274 case WebLocalizedString::OtherTimeLabel: | |
| 275 return IDS_FORM_OTHER_TIME_LABEL; | |
| 276 case WebLocalizedString::OtherWeekLabel: | |
| 277 return IDS_FORM_OTHER_WEEK_LABEL; | |
| 278 case WebLocalizedString::PlaceholderForDayOfMonthField: | |
| 279 return IDS_FORM_PLACEHOLDER_FOR_DAY_OF_MONTH_FIELD; | |
| 280 case WebLocalizedString::PlaceholderForMonthField: | |
| 281 return IDS_FORM_PLACEHOLDER_FOR_MONTH_FIELD; | |
| 282 case WebLocalizedString::PlaceholderForYearField: | |
| 283 return IDS_FORM_PLACEHOLDER_FOR_YEAR_FIELD; | |
| 284 case WebLocalizedString::ResetButtonDefaultLabel: | |
| 285 return IDS_FORM_RESET_LABEL; | |
| 286 case WebLocalizedString::SearchableIndexIntroduction: | |
| 287 return IDS_SEARCHABLE_INDEX_INTRO; | |
| 288 case WebLocalizedString::SearchMenuClearRecentSearchesText: | |
| 289 return IDS_RECENT_SEARCHES_CLEAR; | |
| 290 case WebLocalizedString::SearchMenuNoRecentSearchesText: | |
| 291 return IDS_RECENT_SEARCHES_NONE; | |
| 292 case WebLocalizedString::SearchMenuRecentSearchesText: | |
| 293 return IDS_RECENT_SEARCHES; | |
| 294 case WebLocalizedString::SubmitButtonDefaultLabel: | |
| 295 return IDS_FORM_SUBMIT_LABEL; | |
| 296 case WebLocalizedString::ThisMonthButtonLabel: | |
| 297 return IDS_FORM_THIS_MONTH_LABEL; | |
| 298 case WebLocalizedString::ThisWeekButtonLabel: | |
| 299 return IDS_FORM_THIS_WEEK_LABEL; | |
| 300 case WebLocalizedString::ValidationBadInputForDateTime: | |
| 301 return IDS_FORM_VALIDATION_BAD_INPUT_DATETIME; | |
| 302 case WebLocalizedString::ValidationBadInputForNumber: | |
| 303 return IDS_FORM_VALIDATION_BAD_INPUT_NUMBER; | |
| 304 case WebLocalizedString::ValidationPatternMismatch: | |
| 305 return IDS_FORM_VALIDATION_PATTERN_MISMATCH; | |
| 306 case WebLocalizedString::ValidationRangeOverflow: | |
| 307 return IDS_FORM_VALIDATION_RANGE_OVERFLOW; | |
| 308 case WebLocalizedString::ValidationRangeUnderflow: | |
| 309 return IDS_FORM_VALIDATION_RANGE_UNDERFLOW; | |
| 310 case WebLocalizedString::ValidationStepMismatch: | |
| 311 return IDS_FORM_VALIDATION_STEP_MISMATCH; | |
| 312 case WebLocalizedString::ValidationTooLong: | |
| 313 return IDS_FORM_VALIDATION_TOO_LONG; | |
| 314 case WebLocalizedString::ValidationTypeMismatch: | |
| 315 return IDS_FORM_VALIDATION_TYPE_MISMATCH; | |
| 316 case WebLocalizedString::ValidationTypeMismatchForEmail: | |
| 317 return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL; | |
| 318 case WebLocalizedString::ValidationTypeMismatchForMultipleEmail: | |
| 319 return IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL; | |
| 320 case WebLocalizedString::ValidationTypeMismatchForURL: | |
| 321 return IDS_FORM_VALIDATION_TYPE_MISMATCH_URL; | |
| 322 case WebLocalizedString::ValidationValueMissing: | |
| 323 return IDS_FORM_VALIDATION_VALUE_MISSING; | |
| 324 case WebLocalizedString::ValidationValueMissingForCheckbox: | |
| 325 return IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX; | |
| 326 case WebLocalizedString::ValidationValueMissingForFile: | |
| 327 return IDS_FORM_VALIDATION_VALUE_MISSING_FILE; | |
| 328 case WebLocalizedString::ValidationValueMissingForMultipleFile: | |
| 329 return IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE; | |
| 330 case WebLocalizedString::ValidationValueMissingForRadio: | |
| 331 return IDS_FORM_VALIDATION_VALUE_MISSING_RADIO; | |
| 332 case WebLocalizedString::ValidationValueMissingForSelect: | |
| 333 return IDS_FORM_VALIDATION_VALUE_MISSING_SELECT; | |
| 334 case WebLocalizedString::WeekFormatTemplate: | |
| 335 return IDS_FORM_INPUT_WEEK_TEMPLATE; | |
| 336 case WebLocalizedString::WeekNumberLabel: | |
| 337 return IDS_FORM_WEEK_NUMBER_LABEL; | |
| 338 // This "default:" line exists to avoid compile warnings about enum | |
| 339 // coverage when we add a new symbol to WebLocalizedString.h in WebKit. | |
| 340 // After a planned WebKit patch is landed, we need to add a case statement | |
| 341 // for the added symbol here. | |
| 342 default: | |
| 343 break; | |
| 344 } | |
| 345 return -1; | |
| 346 } | |
| 347 | |
| 348 WebKitPlatformSupportImpl::WebKitPlatformSupportImpl() | |
| 349 : main_loop_(base::MessageLoop::current()), | |
| 350 shared_timer_func_(NULL), | |
| 351 shared_timer_fire_time_(0.0), | |
| 352 shared_timer_fire_time_was_set_while_suspended_(false), | |
| 353 shared_timer_suspended_(0) {} | |
| 354 | |
| 355 WebKitPlatformSupportImpl::~WebKitPlatformSupportImpl() { | |
| 356 } | |
| 357 | |
| 358 WebURLLoader* WebKitPlatformSupportImpl::createURLLoader() { | |
| 359 return new WebURLLoaderImpl(this); | |
| 360 } | |
| 361 | |
| 362 WebSocketStreamHandle* WebKitPlatformSupportImpl::createSocketStreamHandle() { | |
| 363 return new WebSocketStreamHandleImpl(this); | |
| 364 } | |
| 365 | |
| 366 WebString WebKitPlatformSupportImpl::userAgent(const WebURL& url) { | |
| 367 return WebString::fromUTF8(webkit_glue::GetUserAgent(url)); | |
| 368 } | |
| 369 | |
| 370 WebData WebKitPlatformSupportImpl::parseDataURL( | |
| 371 const WebURL& url, | |
| 372 WebString& mimetype_out, | |
| 373 WebString& charset_out) { | |
| 374 std::string mime_type, char_set, data; | |
| 375 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) | |
| 376 && net::IsSupportedMimeType(mime_type)) { | |
| 377 mimetype_out = WebString::fromUTF8(mime_type); | |
| 378 charset_out = WebString::fromUTF8(char_set); | |
| 379 return data; | |
| 380 } | |
| 381 return WebData(); | |
| 382 } | |
| 383 | |
| 384 WebURLError WebKitPlatformSupportImpl::cancelledError( | |
| 385 const WebURL& unreachableURL) const { | |
| 386 return WebURLLoaderImpl::CreateError(unreachableURL, net::ERR_ABORTED); | |
| 387 } | |
| 388 | |
| 389 void WebKitPlatformSupportImpl::decrementStatsCounter(const char* name) { | |
| 390 base::StatsCounter(name).Decrement(); | |
| 391 } | |
| 392 | |
| 393 void WebKitPlatformSupportImpl::incrementStatsCounter(const char* name) { | |
| 394 base::StatsCounter(name).Increment(); | |
| 395 } | |
| 396 | |
| 397 void WebKitPlatformSupportImpl::histogramCustomCounts( | |
| 398 const char* name, int sample, int min, int max, int bucket_count) { | |
| 399 // Copied from histogram macro, but without the static variable caching | |
| 400 // the histogram because name is dynamic. | |
| 401 base::HistogramBase* counter = | |
| 402 base::Histogram::FactoryGet(name, min, max, bucket_count, | |
| 403 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 404 DCHECK_EQ(name, counter->histogram_name()); | |
| 405 counter->Add(sample); | |
| 406 } | |
| 407 | |
| 408 void WebKitPlatformSupportImpl::histogramEnumeration( | |
| 409 const char* name, int sample, int boundary_value) { | |
| 410 // Copied from histogram macro, but without the static variable caching | |
| 411 // the histogram because name is dynamic. | |
| 412 base::HistogramBase* counter = | |
| 413 base::LinearHistogram::FactoryGet(name, 1, boundary_value, | |
| 414 boundary_value + 1, base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 415 DCHECK_EQ(name, counter->histogram_name()); | |
| 416 counter->Add(sample); | |
| 417 } | |
| 418 | |
| 419 void WebKitPlatformSupportImpl::histogramSparse(const char* name, int sample) { | |
| 420 // For sparse histograms, we can use the macro, as it does not incorporate a | |
| 421 // static. | |
| 422 UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample); | |
| 423 } | |
| 424 | |
| 425 const unsigned char* WebKitPlatformSupportImpl::getTraceCategoryEnabledFlag( | |
| 426 const char* category_group) { | |
| 427 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); | |
| 428 } | |
| 429 | |
| 430 long* WebKitPlatformSupportImpl::getTraceSamplingState( | |
| 431 const unsigned thread_bucket) { | |
| 432 switch (thread_bucket) { | |
| 433 case 0: | |
| 434 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(0)); | |
| 435 case 1: | |
| 436 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(1)); | |
| 437 case 2: | |
| 438 return reinterpret_cast<long*>(&TRACE_EVENT_API_THREAD_BUCKET(2)); | |
| 439 default: | |
| 440 NOTREACHED() << "Unknown thread bucket type."; | |
| 441 } | |
| 442 return NULL; | |
| 443 } | |
| 444 | |
| 445 void WebKitPlatformSupportImpl::addTraceEvent( | |
| 446 char phase, | |
| 447 const unsigned char* category_group_enabled, | |
| 448 const char* name, | |
| 449 unsigned long long id, | |
| 450 int num_args, | |
| 451 const char** arg_names, | |
| 452 const unsigned char* arg_types, | |
| 453 const unsigned long long* arg_values, | |
| 454 unsigned char flags) { | |
| 455 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id, | |
| 456 num_args, arg_names, arg_types, | |
| 457 arg_values, NULL, flags); | |
| 458 } | |
| 459 | |
| 460 | |
| 461 namespace { | |
| 462 | |
| 463 WebData loadAudioSpatializationResource(WebKitPlatformSupportImpl* platform, | |
| 464 const char* name) { | |
| 465 #ifdef IDR_AUDIO_SPATIALIZATION_COMPOSITE | |
| 466 if (!strcmp(name, "Composite")) { | |
| 467 base::StringPiece resource = | |
| 468 platform->GetDataResource(IDR_AUDIO_SPATIALIZATION_COMPOSITE, | |
| 469 ui::SCALE_FACTOR_NONE); | |
| 470 return WebData(resource.data(), resource.size()); | |
| 471 } | |
| 472 #endif | |
| 473 | |
| 474 #ifdef IDR_AUDIO_SPATIALIZATION_T000_P000 | |
| 475 const size_t kExpectedSpatializationNameLength = 31; | |
| 476 if (strlen(name) != kExpectedSpatializationNameLength) { | |
| 477 return WebData(); | |
| 478 } | |
| 479 | |
| 480 // Extract the azimuth and elevation from the resource name. | |
| 481 int azimuth = 0; | |
| 482 int elevation = 0; | |
| 483 int values_parsed = | |
| 484 sscanf(name, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth, &elevation); | |
| 485 if (values_parsed != 2) { | |
| 486 return WebData(); | |
| 487 } | |
| 488 | |
| 489 // The resource index values go through the elevations first, then azimuths. | |
| 490 const int kAngleSpacing = 15; | |
| 491 | |
| 492 // 0 <= elevation <= 90 (or 315 <= elevation <= 345) | |
| 493 // in increments of 15 degrees. | |
| 494 int elevation_index = | |
| 495 elevation <= 90 ? elevation / kAngleSpacing : | |
| 496 7 + (elevation - 315) / kAngleSpacing; | |
| 497 bool is_elevation_index_good = 0 <= elevation_index && elevation_index < 10; | |
| 498 | |
| 499 // 0 <= azimuth < 360 in increments of 15 degrees. | |
| 500 int azimuth_index = azimuth / kAngleSpacing; | |
| 501 bool is_azimuth_index_good = 0 <= azimuth_index && azimuth_index < 24; | |
| 502 | |
| 503 const int kNumberOfElevations = 10; | |
| 504 const int kNumberOfAudioResources = 240; | |
| 505 int resource_index = kNumberOfElevations * azimuth_index + elevation_index; | |
| 506 bool is_resource_index_good = 0 <= resource_index && | |
| 507 resource_index < kNumberOfAudioResources; | |
| 508 | |
| 509 if (is_azimuth_index_good && is_elevation_index_good && | |
| 510 is_resource_index_good) { | |
| 511 const int kFirstAudioResourceIndex = IDR_AUDIO_SPATIALIZATION_T000_P000; | |
| 512 base::StringPiece resource = | |
| 513 platform->GetDataResource(kFirstAudioResourceIndex + resource_index, | |
| 514 ui::SCALE_FACTOR_NONE); | |
| 515 return WebData(resource.data(), resource.size()); | |
| 516 } | |
| 517 #endif // IDR_AUDIO_SPATIALIZATION_T000_P000 | |
| 518 | |
| 519 NOTREACHED(); | |
| 520 return WebData(); | |
| 521 } | |
| 522 | |
| 523 struct DataResource { | |
| 524 const char* name; | |
| 525 int id; | |
| 526 ui::ScaleFactor scale_factor; | |
| 527 }; | |
| 528 | |
| 529 const DataResource kDataResources[] = { | |
| 530 { "missingImage", IDR_BROKENIMAGE, ui::SCALE_FACTOR_100P }, | |
| 531 { "missingImage@2x", IDR_BROKENIMAGE, ui::SCALE_FACTOR_200P }, | |
| 532 { "mediaplayerPause", IDR_MEDIAPLAYER_PAUSE_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 533 { "mediaplayerPauseHover", | |
| 534 IDR_MEDIAPLAYER_PAUSE_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 535 { "mediaplayerPauseDown", | |
| 536 IDR_MEDIAPLAYER_PAUSE_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 537 { "mediaplayerPlay", IDR_MEDIAPLAYER_PLAY_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 538 { "mediaplayerPlayHover", | |
| 539 IDR_MEDIAPLAYER_PLAY_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 540 { "mediaplayerPlayDown", | |
| 541 IDR_MEDIAPLAYER_PLAY_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 542 { "mediaplayerPlayDisabled", | |
| 543 IDR_MEDIAPLAYER_PLAY_BUTTON_DISABLED, ui::SCALE_FACTOR_100P }, | |
| 544 { "mediaplayerSoundLevel3", | |
| 545 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 546 { "mediaplayerSoundLevel3Hover", | |
| 547 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 548 { "mediaplayerSoundLevel3Down", | |
| 549 IDR_MEDIAPLAYER_SOUND_LEVEL3_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 550 { "mediaplayerSoundLevel2", | |
| 551 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 552 { "mediaplayerSoundLevel2Hover", | |
| 553 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 554 { "mediaplayerSoundLevel2Down", | |
| 555 IDR_MEDIAPLAYER_SOUND_LEVEL2_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 556 { "mediaplayerSoundLevel1", | |
| 557 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 558 { "mediaplayerSoundLevel1Hover", | |
| 559 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 560 { "mediaplayerSoundLevel1Down", | |
| 561 IDR_MEDIAPLAYER_SOUND_LEVEL1_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 562 { "mediaplayerSoundLevel0", | |
| 563 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 564 { "mediaplayerSoundLevel0Hover", | |
| 565 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 566 { "mediaplayerSoundLevel0Down", | |
| 567 IDR_MEDIAPLAYER_SOUND_LEVEL0_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 568 { "mediaplayerSoundDisabled", | |
| 569 IDR_MEDIAPLAYER_SOUND_DISABLED, ui::SCALE_FACTOR_100P }, | |
| 570 { "mediaplayerSliderThumb", | |
| 571 IDR_MEDIAPLAYER_SLIDER_THUMB, ui::SCALE_FACTOR_100P }, | |
| 572 { "mediaplayerSliderThumbHover", | |
| 573 IDR_MEDIAPLAYER_SLIDER_THUMB_HOVER, ui::SCALE_FACTOR_100P }, | |
| 574 { "mediaplayerSliderThumbDown", | |
| 575 IDR_MEDIAPLAYER_SLIDER_THUMB_DOWN, ui::SCALE_FACTOR_100P }, | |
| 576 { "mediaplayerVolumeSliderThumb", | |
| 577 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB, ui::SCALE_FACTOR_100P }, | |
| 578 { "mediaplayerVolumeSliderThumbHover", | |
| 579 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_HOVER, ui::SCALE_FACTOR_100P }, | |
| 580 { "mediaplayerVolumeSliderThumbDown", | |
| 581 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DOWN, ui::SCALE_FACTOR_100P }, | |
| 582 { "mediaplayerVolumeSliderThumbDisabled", | |
| 583 IDR_MEDIAPLAYER_VOLUME_SLIDER_THUMB_DISABLED, ui::SCALE_FACTOR_100P }, | |
| 584 { "mediaplayerClosedCaption", | |
| 585 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 586 { "mediaplayerClosedCaptionHover", | |
| 587 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 588 { "mediaplayerClosedCaptionDown", | |
| 589 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 590 { "mediaplayerClosedCaptionDisabled", | |
| 591 IDR_MEDIAPLAYER_CLOSEDCAPTION_BUTTON_DISABLED, ui::SCALE_FACTOR_100P }, | |
| 592 { "mediaplayerFullscreen", | |
| 593 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 594 { "mediaplayerFullscreenHover", | |
| 595 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 596 { "mediaplayerFullscreenDown", | |
| 597 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DOWN, ui::SCALE_FACTOR_100P }, | |
| 598 { "mediaplayerFullscreenDisabled", | |
| 599 IDR_MEDIAPLAYER_FULLSCREEN_BUTTON_DISABLED, ui::SCALE_FACTOR_100P }, | |
| 600 #if defined(OS_ANDROID) | |
| 601 { "mediaplayerOverlayPlay", | |
| 602 IDR_MEDIAPLAYER_OVERLAY_PLAY_BUTTON, ui::SCALE_FACTOR_100P }, | |
| 603 #endif | |
| 604 #if defined(OS_MACOSX) | |
| 605 { "overhangPattern", IDR_OVERHANG_PATTERN, ui::SCALE_FACTOR_100P }, | |
| 606 #endif | |
| 607 { "panIcon", IDR_PAN_SCROLL_ICON, ui::SCALE_FACTOR_100P }, | |
| 608 { "searchCancel", IDR_SEARCH_CANCEL, ui::SCALE_FACTOR_100P }, | |
| 609 { "searchCancelPressed", IDR_SEARCH_CANCEL_PRESSED, ui::SCALE_FACTOR_100P }, | |
| 610 { "searchMagnifier", IDR_SEARCH_MAGNIFIER, ui::SCALE_FACTOR_100P }, | |
| 611 { "searchMagnifierResults", | |
| 612 IDR_SEARCH_MAGNIFIER_RESULTS, ui::SCALE_FACTOR_100P }, | |
| 613 { "textAreaResizeCorner", IDR_TEXTAREA_RESIZER, ui::SCALE_FACTOR_100P }, | |
| 614 { "textAreaResizeCorner@2x", IDR_TEXTAREA_RESIZER, ui::SCALE_FACTOR_200P }, | |
| 615 { "inputSpeech", IDR_INPUT_SPEECH, ui::SCALE_FACTOR_100P }, | |
| 616 { "inputSpeechRecording", IDR_INPUT_SPEECH_RECORDING, ui::SCALE_FACTOR_100P }, | |
| 617 { "inputSpeechWaiting", IDR_INPUT_SPEECH_WAITING, ui::SCALE_FACTOR_100P }, | |
| 618 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX, ui::SCALE_FACTOR_100P }, | |
| 619 { "dinersCC", IDR_AUTOFILL_CC_DINERS, ui::SCALE_FACTOR_100P }, | |
| 620 { "discoverCC", IDR_AUTOFILL_CC_DISCOVER, ui::SCALE_FACTOR_100P }, | |
| 621 { "genericCC", IDR_AUTOFILL_CC_GENERIC, ui::SCALE_FACTOR_100P }, | |
| 622 { "jcbCC", IDR_AUTOFILL_CC_JCB, ui::SCALE_FACTOR_100P }, | |
| 623 { "masterCardCC", IDR_AUTOFILL_CC_MASTERCARD, ui::SCALE_FACTOR_100P }, | |
| 624 { "visaCC", IDR_AUTOFILL_CC_VISA, ui::SCALE_FACTOR_100P }, | |
| 625 { "generatePassword", IDR_PASSWORD_GENERATION_ICON, ui::SCALE_FACTOR_100P }, | |
| 626 { "generatePasswordHover", | |
| 627 IDR_PASSWORD_GENERATION_ICON_HOVER, ui::SCALE_FACTOR_100P }, | |
| 628 { "syntheticTouchCursor", | |
| 629 IDR_SYNTHETIC_TOUCH_CURSOR, ui::SCALE_FACTOR_100P }, | |
| 630 }; | |
| 631 | |
| 632 } // namespace | |
| 633 | |
| 634 WebData WebKitPlatformSupportImpl::loadResource(const char* name) { | |
| 635 // Some clients will call into this method with an empty |name| when they have | |
| 636 // optional resources. For example, the PopupMenuChromium code can have icons | |
| 637 // for some Autofill items but not for others. | |
| 638 if (!strlen(name)) | |
| 639 return WebData(); | |
| 640 | |
| 641 // Check the name prefix to see if it's an audio resource. | |
| 642 if (StartsWithASCII(name, "IRC_Composite", true) || | |
| 643 StartsWithASCII(name, "Composite", true)) | |
| 644 return loadAudioSpatializationResource(this, name); | |
| 645 | |
| 646 // TODO(flackr): We should use a better than linear search here, a trie would | |
| 647 // be ideal. | |
| 648 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | |
| 649 if (!strcmp(name, kDataResources[i].name)) { | |
| 650 base::StringPiece resource = | |
| 651 GetDataResource(kDataResources[i].id, | |
| 652 kDataResources[i].scale_factor); | |
| 653 return WebData(resource.data(), resource.size()); | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 NOTREACHED() << "Unknown image resource " << name; | |
| 658 return WebData(); | |
| 659 } | |
| 660 | |
| 661 WebString WebKitPlatformSupportImpl::queryLocalizedString( | |
| 662 WebLocalizedString::Name name) { | |
| 663 int message_id = ToMessageID(name); | |
| 664 if (message_id < 0) | |
| 665 return WebString(); | |
| 666 return GetLocalizedString(message_id); | |
| 667 } | |
| 668 | |
| 669 WebString WebKitPlatformSupportImpl::queryLocalizedString( | |
| 670 WebLocalizedString::Name name, int numeric_value) { | |
| 671 return queryLocalizedString(name, base::IntToString16(numeric_value)); | |
| 672 } | |
| 673 | |
| 674 WebString WebKitPlatformSupportImpl::queryLocalizedString( | |
| 675 WebLocalizedString::Name name, const WebString& value) { | |
| 676 int message_id = ToMessageID(name); | |
| 677 if (message_id < 0) | |
| 678 return WebString(); | |
| 679 return ReplaceStringPlaceholders(GetLocalizedString(message_id), value, NULL); | |
| 680 } | |
| 681 | |
| 682 WebString WebKitPlatformSupportImpl::queryLocalizedString( | |
| 683 WebLocalizedString::Name name, | |
| 684 const WebString& value1, | |
| 685 const WebString& value2) { | |
| 686 int message_id = ToMessageID(name); | |
| 687 if (message_id < 0) | |
| 688 return WebString(); | |
| 689 std::vector<base::string16> values; | |
| 690 values.reserve(2); | |
| 691 values.push_back(value1); | |
| 692 values.push_back(value2); | |
| 693 return ReplaceStringPlaceholders( | |
| 694 GetLocalizedString(message_id), values, NULL); | |
| 695 } | |
| 696 | |
| 697 double WebKitPlatformSupportImpl::currentTime() { | |
| 698 return base::Time::Now().ToDoubleT(); | |
| 699 } | |
| 700 | |
| 701 double WebKitPlatformSupportImpl::monotonicallyIncreasingTime() { | |
| 702 return base::TimeTicks::Now().ToInternalValue() / | |
| 703 static_cast<double>(base::Time::kMicrosecondsPerSecond); | |
| 704 } | |
| 705 | |
| 706 void WebKitPlatformSupportImpl::cryptographicallyRandomValues( | |
| 707 unsigned char* buffer, size_t length) { | |
| 708 base::RandBytes(buffer, length); | |
| 709 } | |
| 710 | |
| 711 void WebKitPlatformSupportImpl::setSharedTimerFiredFunction(void (*func)()) { | |
| 712 shared_timer_func_ = func; | |
| 713 } | |
| 714 | |
| 715 void WebKitPlatformSupportImpl::setSharedTimerFireInterval( | |
| 716 double interval_seconds) { | |
| 717 shared_timer_fire_time_ = interval_seconds + monotonicallyIncreasingTime(); | |
| 718 if (shared_timer_suspended_) { | |
| 719 shared_timer_fire_time_was_set_while_suspended_ = true; | |
| 720 return; | |
| 721 } | |
| 722 | |
| 723 // By converting between double and int64 representation, we run the risk | |
| 724 // of losing precision due to rounding errors. Performing computations in | |
| 725 // microseconds reduces this risk somewhat. But there still is the potential | |
| 726 // of us computing a fire time for the timer that is shorter than what we | |
| 727 // need. | |
| 728 // As the event loop will check event deadlines prior to actually firing | |
| 729 // them, there is a risk of needlessly rescheduling events and of | |
| 730 // needlessly looping if sleep times are too short even by small amounts. | |
| 731 // This results in measurable performance degradation unless we use ceil() to | |
| 732 // always round up the sleep times. | |
| 733 int64 interval = static_cast<int64>( | |
| 734 ceil(interval_seconds * base::Time::kMillisecondsPerSecond) | |
| 735 * base::Time::kMicrosecondsPerMillisecond); | |
| 736 | |
| 737 if (interval < 0) | |
| 738 interval = 0; | |
| 739 | |
| 740 shared_timer_.Stop(); | |
| 741 shared_timer_.Start(FROM_HERE, base::TimeDelta::FromMicroseconds(interval), | |
| 742 this, &WebKitPlatformSupportImpl::DoTimeout); | |
| 743 OnStartSharedTimer(base::TimeDelta::FromMicroseconds(interval)); | |
| 744 } | |
| 745 | |
| 746 void WebKitPlatformSupportImpl::stopSharedTimer() { | |
| 747 shared_timer_.Stop(); | |
| 748 } | |
| 749 | |
| 750 void WebKitPlatformSupportImpl::callOnMainThread( | |
| 751 void (*func)(void*), void* context) { | |
| 752 main_loop_->PostTask(FROM_HERE, base::Bind(func, context)); | |
| 753 } | |
| 754 | |
| 755 base::PlatformFile WebKitPlatformSupportImpl::databaseOpenFile( | |
| 756 const WebKit::WebString& vfs_file_name, int desired_flags) { | |
| 757 return base::kInvalidPlatformFileValue; | |
| 758 } | |
| 759 | |
| 760 int WebKitPlatformSupportImpl::databaseDeleteFile( | |
| 761 const WebKit::WebString& vfs_file_name, bool sync_dir) { | |
| 762 return -1; | |
| 763 } | |
| 764 | |
| 765 long WebKitPlatformSupportImpl::databaseGetFileAttributes( | |
| 766 const WebKit::WebString& vfs_file_name) { | |
| 767 return 0; | |
| 768 } | |
| 769 | |
| 770 long long WebKitPlatformSupportImpl::databaseGetFileSize( | |
| 771 const WebKit::WebString& vfs_file_name) { | |
| 772 return 0; | |
| 773 } | |
| 774 | |
| 775 long long WebKitPlatformSupportImpl::databaseGetSpaceAvailableForOrigin( | |
| 776 const WebKit::WebString& origin_identifier) { | |
| 777 return 0; | |
| 778 } | |
| 779 | |
| 780 WebKit::WebString WebKitPlatformSupportImpl::signedPublicKeyAndChallengeString( | |
| 781 unsigned key_size_index, | |
| 782 const WebKit::WebString& challenge, | |
| 783 const WebKit::WebURL& url) { | |
| 784 return WebKit::WebString(""); | |
| 785 } | |
| 786 | |
| 787 static scoped_ptr<base::ProcessMetrics> CurrentProcessMetrics() { | |
| 788 using base::ProcessMetrics; | |
| 789 #if defined(OS_MACOSX) | |
| 790 return scoped_ptr<ProcessMetrics>( | |
| 791 // The default port provider is sufficient to get data for the current | |
| 792 // process. | |
| 793 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), | |
| 794 NULL)); | |
| 795 #else | |
| 796 return scoped_ptr<ProcessMetrics>( | |
| 797 ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle())); | |
| 798 #endif | |
| 799 } | |
| 800 | |
| 801 static size_t getMemoryUsageMB(bool bypass_cache) { | |
| 802 size_t current_mem_usage = 0; | |
| 803 MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance(); | |
| 804 if (!bypass_cache && | |
| 805 mem_usage_cache_singleton->IsCachedValueValid(¤t_mem_usage)) | |
| 806 return current_mem_usage; | |
| 807 | |
| 808 current_mem_usage = MemoryUsageKB() >> 10; | |
| 809 mem_usage_cache_singleton->SetMemoryValue(current_mem_usage); | |
| 810 return current_mem_usage; | |
| 811 } | |
| 812 | |
| 813 size_t WebKitPlatformSupportImpl::memoryUsageMB() { | |
| 814 return getMemoryUsageMB(false); | |
| 815 } | |
| 816 | |
| 817 size_t WebKitPlatformSupportImpl::actualMemoryUsageMB() { | |
| 818 return getMemoryUsageMB(true); | |
| 819 } | |
| 820 | |
| 821 #if defined(OS_ANDROID) | |
| 822 size_t WebKitPlatformSupportImpl::lowMemoryUsageMB() { | |
| 823 // If memory usage is below this threshold, do not bother forcing GC. | |
| 824 // Allow us to use up to our memory class value before V8's GC kicks in. | |
| 825 // These values have been determined by experimentation. | |
| 826 return base::SysInfo::DalvikHeapSizeMB() / 2; | |
| 827 } | |
| 828 | |
| 829 size_t WebKitPlatformSupportImpl::highMemoryUsageMB() { | |
| 830 // If memory usage is above this threshold, force GC more aggressively. | |
| 831 return base::SysInfo::DalvikHeapSizeMB() * 3 / 4; | |
| 832 } | |
| 833 | |
| 834 size_t WebKitPlatformSupportImpl::highUsageDeltaMB() { | |
| 835 // If memory usage is above highMemoryUsageMB() and memory usage increased by | |
| 836 // more than highUsageDeltaMB() since the last GC, then force GC. | |
| 837 // Note that this limit should be greater than the amount of memory for V8 | |
| 838 // internal data structures that are released on GC and reallocated during JS | |
| 839 // execution (about 8MB). Otherwise, it will cause too aggressive GCs. | |
| 840 return base::SysInfo::DalvikHeapSizeMB() / 8; | |
| 841 } | |
| 842 #endif | |
| 843 | |
| 844 void WebKitPlatformSupportImpl::startHeapProfiling( | |
| 845 const WebKit::WebString& prefix) { | |
| 846 // FIXME(morrita): Make this built on windows. | |
| 847 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | |
| 848 HeapProfilerStart(prefix.utf8().data()); | |
| 849 #endif | |
| 850 } | |
| 851 | |
| 852 void WebKitPlatformSupportImpl::stopHeapProfiling() { | |
| 853 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | |
| 854 HeapProfilerStop(); | |
| 855 #endif | |
| 856 } | |
| 857 | |
| 858 void WebKitPlatformSupportImpl::dumpHeapProfiling( | |
| 859 const WebKit::WebString& reason) { | |
| 860 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | |
| 861 HeapProfilerDump(reason.utf8().data()); | |
| 862 #endif | |
| 863 } | |
| 864 | |
| 865 WebString WebKitPlatformSupportImpl::getHeapProfile() { | |
| 866 #if !defined(NO_TCMALLOC) && defined(USE_TCMALLOC) && !defined(OS_WIN) | |
| 867 char* data = GetHeapProfile(); | |
| 868 WebString result = WebString::fromUTF8(std::string(data)); | |
| 869 free(data); | |
| 870 return result; | |
| 871 #else | |
| 872 return WebString(); | |
| 873 #endif | |
| 874 } | |
| 875 | |
| 876 bool WebKitPlatformSupportImpl::processMemorySizesInBytes( | |
| 877 size_t* private_bytes, | |
| 878 size_t* shared_bytes) { | |
| 879 return CurrentProcessMetrics()->GetMemoryBytes(private_bytes, shared_bytes); | |
| 880 } | |
| 881 | |
| 882 bool WebKitPlatformSupportImpl::memoryAllocatorWasteInBytes(size_t* size) { | |
| 883 return base::allocator::GetAllocatorWasteSize(size); | |
| 884 } | |
| 885 | |
| 886 void WebKitPlatformSupportImpl::SuspendSharedTimer() { | |
| 887 ++shared_timer_suspended_; | |
| 888 } | |
| 889 | |
| 890 void WebKitPlatformSupportImpl::ResumeSharedTimer() { | |
| 891 // The shared timer may have fired or been adjusted while we were suspended. | |
| 892 if (--shared_timer_suspended_ == 0 && | |
| 893 (!shared_timer_.IsRunning() || | |
| 894 shared_timer_fire_time_was_set_while_suspended_)) { | |
| 895 shared_timer_fire_time_was_set_while_suspended_ = false; | |
| 896 setSharedTimerFireInterval( | |
| 897 shared_timer_fire_time_ - monotonicallyIncreasingTime()); | |
| 898 } | |
| 899 } | |
| 900 | |
| 901 } // namespace webkit_glue | |
| OLD | NEW |