Chromium Code Reviews| Index: webkit/glue/webkitclient_impl.cc |
| =================================================================== |
| --- webkit/glue/webkitclient_impl.cc (revision 71703) |
| +++ webkit/glue/webkitclient_impl.cc (working copy) |
| @@ -24,6 +24,7 @@ |
| #include "base/string_util.h" |
| #include "base/time.h" |
| #include "base/utf_string_conversions.h" |
| +#include "grit/webkit_chromium_audio_resources.h" |
| #include "grit/webkit_resources.h" |
| #include "grit/webkit_strings.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebCookie.h" |
| @@ -291,6 +292,52 @@ |
| TRACE_EVENT_END(name, id, extra); |
| } |
| +namespace { |
| + |
| +WebData loadAudioSpatializationResource(const char* name) { |
| + const size_t kExpectedSpatializationNameLength = 31; |
| + if (strlen(name) != kExpectedSpatializationNameLength) { |
| + return WebData(); |
| + } |
| + |
| + // Extract the azimuth and elevation from the resource name. |
| + int azimuth = 0; |
| + int elevation = 0; |
| + sscanf(name, "IRC_Composite_C_R0195_T%3d_P%3d", &azimuth, &elevation); |
|
tony
2011/01/19 17:46:10
Nit: Maybe you could also check the return value o
|
| + |
| + // The resource index values go through the elevations first, then azimuths. |
| + const int kAngleSpacing = 15; |
| + |
| + // 0 <= elevation <= 90 (or 315 <= elevation <= 345) |
| + // in increments of 15 degrees. |
| + int elevation_index = |
| + elevation <= 90 ? elevation / kAngleSpacing : |
| + 7 + (elevation - 315) / kAngleSpacing; |
| + bool is_elevation_index_good = 0 <= elevation_index < 10; |
|
tony
2011/01/19 17:46:10
I don't think this does what you think this does.
|
| + |
| + // 0 <= azimuth < 360 in increments of 15 degrees. |
| + int azimuth_index = azimuth / kAngleSpacing; |
| + bool is_azimuth_index_good = 0 <= azimuth_index < 24; |
|
tony
2011/01/19 17:46:10
Same as above, I think you need to split this out
|
| + |
| + const int kNumberOfElevations = 10; |
| + const int kNumberOfAudioResources = 240; |
| + int resource_index = kNumberOfElevations * azimuth_index + elevation_index; |
| + bool is_resource_index_good = 0 <= resource_index < kNumberOfAudioResources; |
|
tony
2011/01/19 17:46:10
Same error as above.
|
| + |
| + if (is_azimuth_index_good && is_elevation_index_good && |
| + is_resource_index_good) { |
| + const int kFirstAudioResourceIndex = IDR_AUDIO_SPATIALIZATION_T000_P000; |
| + base::StringPiece resource = |
| + GetDataResource(kFirstAudioResourceIndex + resource_index); |
| + return WebData(resource.data(), resource.size()); |
| + } |
| + |
| + NOTREACHED(); |
| + return WebData(); |
| +} |
| + |
| +} // namespace |
| + |
| WebData WebKitClientImpl::loadResource(const char* name) { |
| struct { |
| const char* name; |
| @@ -342,10 +389,16 @@ |
| { "linuxProgressValue", IDR_PROGRESS_VALUE }, |
| #endif |
| }; |
| - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
| - if (!strcmp(name, resources[i].name)) { |
| - base::StringPiece resource = GetDataResource(resources[i].id); |
| - return WebData(resource.data(), resource.size()); |
| + |
| + // Check the name prefix to see if it's an audio resource. |
| + if (!strncmp(name, "IRC_Composite", 13)) { |
|
tony
2011/01/19 17:46:10
There's a StartsWithASCII() function in base/strin
|
| + return loadAudioSpatializationResource(name); |
| + } else { |
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
| + if (!strcmp(name, resources[i].name)) { |
| + base::StringPiece resource = GetDataResource(resources[i].id); |
| + return WebData(resource.data(), resource.size()); |
| + } |
| } |
| } |
| // TODO(jhawkins): Restore this NOTREACHED once WK stops sending in empty |