OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/glue/webkitclient_impl.h" | 5 #include "webkit/glue/webkitclient_impl.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <malloc.h> | 8 #include <malloc.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <math.h> | 11 #include <math.h> |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
16 #include "base/lock.h" | 16 #include "base/lock.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/metrics/stats_counters.h" | 18 #include "base/metrics/stats_counters.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
21 #include "base/platform_file.h" | 21 #include "base/platform_file.h" |
22 #include "base/singleton.h" | 22 #include "base/singleton.h" |
23 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
25 #include "base/time.h" | 25 #include "base/time.h" |
26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 27 #include "grit/webkit_chromium_resources.h" |
27 #include "grit/webkit_resources.h" | 28 #include "grit/webkit_resources.h" |
28 #include "grit/webkit_strings.h" | 29 #include "grit/webkit_strings.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCookie.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCookie.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder.
h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginListBuilder.
h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void WebKitClientImpl::traceEventBegin(const char* name, void* id, | 285 void WebKitClientImpl::traceEventBegin(const char* name, void* id, |
285 const char* extra) { | 286 const char* extra) { |
286 TRACE_EVENT_BEGIN(name, id, extra); | 287 TRACE_EVENT_BEGIN(name, id, extra); |
287 } | 288 } |
288 | 289 |
289 void WebKitClientImpl::traceEventEnd(const char* name, void* id, | 290 void WebKitClientImpl::traceEventEnd(const char* name, void* id, |
290 const char* extra) { | 291 const char* extra) { |
291 TRACE_EVENT_END(name, id, extra); | 292 TRACE_EVENT_END(name, id, extra); |
292 } | 293 } |
293 | 294 |
| 295 namespace { |
| 296 |
| 297 WebData loadAudioSpatializationResource(const char* name) { |
| 298 const size_t kExpectedSpatializationNameLength = 31; |
| 299 if (strlen(name) != kExpectedSpatializationNameLength) { |
| 300 return WebData(); |
| 301 } |
| 302 |
| 303 // Extract the azimuth and elevation from the resource name. |
| 304 int azimuth = 0; |
| 305 int elevation = 0; |
| 306 int values_parsed = |
| 307 sscanf(name, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth, &elevation); |
| 308 if (values_parsed != 2) { |
| 309 return WebData(); |
| 310 } |
| 311 |
| 312 // The resource index values go through the elevations first, then azimuths. |
| 313 const int kAngleSpacing = 15; |
| 314 |
| 315 // 0 <= elevation <= 90 (or 315 <= elevation <= 345) |
| 316 // in increments of 15 degrees. |
| 317 int elevation_index = |
| 318 elevation <= 90 ? elevation / kAngleSpacing : |
| 319 7 + (elevation - 315) / kAngleSpacing; |
| 320 bool is_elevation_index_good = 0 <= elevation_index && elevation_index < 10; |
| 321 |
| 322 // 0 <= azimuth < 360 in increments of 15 degrees. |
| 323 int azimuth_index = azimuth / kAngleSpacing; |
| 324 bool is_azimuth_index_good = 0 <= azimuth_index && azimuth_index < 24; |
| 325 |
| 326 const int kNumberOfElevations = 10; |
| 327 const int kNumberOfAudioResources = 240; |
| 328 int resource_index = kNumberOfElevations * azimuth_index + elevation_index; |
| 329 bool is_resource_index_good = 0 <= resource_index && |
| 330 resource_index < kNumberOfAudioResources; |
| 331 |
| 332 if (is_azimuth_index_good && is_elevation_index_good && |
| 333 is_resource_index_good) { |
| 334 const int kFirstAudioResourceIndex = IDR_AUDIO_SPATIALIZATION_T000_P000; |
| 335 base::StringPiece resource = |
| 336 GetDataResource(kFirstAudioResourceIndex + resource_index); |
| 337 return WebData(resource.data(), resource.size()); |
| 338 } |
| 339 |
| 340 NOTREACHED(); |
| 341 return WebData(); |
| 342 } |
| 343 |
| 344 } // namespace |
| 345 |
294 WebData WebKitClientImpl::loadResource(const char* name) { | 346 WebData WebKitClientImpl::loadResource(const char* name) { |
295 struct { | 347 struct { |
296 const char* name; | 348 const char* name; |
297 int id; | 349 int id; |
298 } resources[] = { | 350 } resources[] = { |
299 { "missingImage", IDR_BROKENIMAGE }, | 351 { "missingImage", IDR_BROKENIMAGE }, |
300 { "mediaPause", IDR_MEDIA_PAUSE_BUTTON }, | 352 { "mediaPause", IDR_MEDIA_PAUSE_BUTTON }, |
301 { "mediaPlay", IDR_MEDIA_PLAY_BUTTON }, | 353 { "mediaPlay", IDR_MEDIA_PLAY_BUTTON }, |
302 { "mediaPlayDisabled", IDR_MEDIA_PLAY_BUTTON_DISABLED }, | 354 { "mediaPlayDisabled", IDR_MEDIA_PLAY_BUTTON_DISABLED }, |
303 { "mediaSoundDisabled", IDR_MEDIA_SOUND_DISABLED }, | 355 { "mediaSoundDisabled", IDR_MEDIA_SOUND_DISABLED }, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 { "linuxRadioDisabledOff", IDR_LINUX_RADIO_DISABLED_OFF }, | 387 { "linuxRadioDisabledOff", IDR_LINUX_RADIO_DISABLED_OFF }, |
336 { "linuxRadioDisabledOn", IDR_LINUX_RADIO_DISABLED_ON }, | 388 { "linuxRadioDisabledOn", IDR_LINUX_RADIO_DISABLED_ON }, |
337 { "linuxRadioOff", IDR_LINUX_RADIO_OFF }, | 389 { "linuxRadioOff", IDR_LINUX_RADIO_OFF }, |
338 { "linuxRadioOn", IDR_LINUX_RADIO_ON }, | 390 { "linuxRadioOn", IDR_LINUX_RADIO_ON }, |
339 { "linuxProgressBar", IDR_PROGRESS_BAR }, | 391 { "linuxProgressBar", IDR_PROGRESS_BAR }, |
340 { "linuxProgressBorderLeft", IDR_PROGRESS_BORDER_LEFT }, | 392 { "linuxProgressBorderLeft", IDR_PROGRESS_BORDER_LEFT }, |
341 { "linuxProgressBorderRight", IDR_PROGRESS_BORDER_RIGHT }, | 393 { "linuxProgressBorderRight", IDR_PROGRESS_BORDER_RIGHT }, |
342 { "linuxProgressValue", IDR_PROGRESS_VALUE }, | 394 { "linuxProgressValue", IDR_PROGRESS_VALUE }, |
343 #endif | 395 #endif |
344 }; | 396 }; |
345 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { | 397 |
346 if (!strcmp(name, resources[i].name)) { | 398 // Check the name prefix to see if it's an audio resource. |
347 base::StringPiece resource = GetDataResource(resources[i].id); | 399 if (StartsWithASCII(name, "IRC_Composite", true)) { |
348 return WebData(resource.data(), resource.size()); | 400 return loadAudioSpatializationResource(name); |
| 401 } else { |
| 402 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
| 403 if (!strcmp(name, resources[i].name)) { |
| 404 base::StringPiece resource = GetDataResource(resources[i].id); |
| 405 return WebData(resource.data(), resource.size()); |
| 406 } |
349 } | 407 } |
350 } | 408 } |
351 // TODO(jhawkins): Restore this NOTREACHED once WK stops sending in empty | 409 // TODO(jhawkins): Restore this NOTREACHED once WK stops sending in empty |
352 // strings. http://crbug.com/50675. | 410 // strings. http://crbug.com/50675. |
353 //NOTREACHED() << "Unknown image resource " << name; | 411 //NOTREACHED() << "Unknown image resource " << name; |
354 return WebData(); | 412 return WebData(); |
355 } | 413 } |
356 | 414 |
357 bool WebKitClientImpl::loadAudioResource( | 415 bool WebKitClientImpl::loadAudioResource( |
358 WebKit::WebAudioBus* destination_bus, const char* audio_file_data, | 416 WebKit::WebAudioBus* destination_bus, const char* audio_file_data, |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 ++shared_timer_suspended_; | 597 ++shared_timer_suspended_; |
540 } | 598 } |
541 | 599 |
542 void WebKitClientImpl::ResumeSharedTimer() { | 600 void WebKitClientImpl::ResumeSharedTimer() { |
543 // The shared timer may have fired or been adjusted while we were suspended. | 601 // The shared timer may have fired or been adjusted while we were suspended. |
544 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) | 602 if (--shared_timer_suspended_ == 0 && !shared_timer_.IsRunning()) |
545 setSharedTimerFireTime(shared_timer_fire_time_); | 603 setSharedTimerFireTime(shared_timer_fire_time_); |
546 } | 604 } |
547 | 605 |
548 } // namespace webkit_glue | 606 } // namespace webkit_glue |
OLD | NEW |