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