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