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