aw_media_url_interceptor.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2014 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. #include <string>
  5. #include "android_webview/browser/aw_media_url_interceptor.h"
  6. #include "android_webview/common/url_constants.h"
  7. #include "base/android/apk_assets.h"
  8. #include "base/strings/string_util.h"
  9. #include "content/public/common/url_constants.h"
  10. namespace android_webview {
  11. bool AwMediaUrlInterceptor::Intercept(const std::string& url,
  12. int* fd,
  13. int64_t* offset,
  14. int64_t* size) const {
  15. std::string asset_file_prefix(url::kFileScheme);
  16. asset_file_prefix.append(url::kStandardSchemeSeparator);
  17. asset_file_prefix.append(android_webview::kAndroidAssetPath);
  18. if (base::StartsWith(url, asset_file_prefix, base::CompareCase::SENSITIVE)) {
  19. std::string filename(url);
  20. base::ReplaceFirstSubstringAfterOffset(&filename, 0, asset_file_prefix,
  21. "assets/");
  22. base::MemoryMappedFile::Region region =
  23. base::MemoryMappedFile::Region::kWholeFile;
  24. *fd = base::android::OpenApkAsset(filename, &region);
  25. *offset = region.offset;
  26. *size = region.size;
  27. return *fd != -1;
  28. }
  29. return false;
  30. }
  31. } // namespace android_webview