Commit 63ab5052 authored by igsolla@chromium.org's avatar igsolla@chromium.org

[Android WebView] AwMediaUrlInterceptor to handle media assets.

This change registers an AwMediaUrlInterceptor to enable apps
to play media assets.

This is a follow-up change to:
https://codereview.chromium.org/411353002/

BUG=387898

Review URL: https://codereview.chromium.org/415043006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287315 0039d316-1c4b-4281-b951-d872f2087c98
parent c1ec0fb1
# Please include joth@ and (joi@ or erikwright@) on the review for any changes
# Please include benm@ and (erikwright@) on the review for any changes
# to DEPS files under android_webview/
# Do not add any includes under chrome/ anywhere in android_webview.
......@@ -8,6 +8,7 @@ include_rules = [
"-android_webview/lib",
"+components/data_reduction_proxy",
"+content/browser/media/android",
"+content/public/common",
"+crypto",
"+gpu",
......
......@@ -109,6 +109,7 @@
'../components/components.gyp:visitedlink_renderer',
'../components/components.gyp:web_contents_delegate_android',
'../content/content.gyp:content_app_both',
'../content/content.gyp:content_browser',
'../gpu/gpu.gyp:command_buffer_service',
'../gpu/gpu.gyp:gles2_implementation',
'../gpu/gpu.gyp:gl_in_process_context',
......
......@@ -107,6 +107,7 @@
'browser/net/input_stream_reader_unittest.cc',
'lib/main/webview_tests.cc',
'native/aw_contents_client_bridge_unittest.cc',
'native/aw_media_url_interceptor_unittest.cc',
'native/input_stream_unittest.cc',
'native/permission/media_access_permission_request_unittest.cc',
'native/permission/permission_request_handler_unittest.cc',
......@@ -147,7 +148,18 @@
],
'variables': {
'test_suite_name': 'android_webview_unittests',
'additional_input_paths': [
'<(PRODUCT_DIR)/android_webview_unittests_apk/assets/asset_file.ogg',
],
},
'copies': [
{
'destination': '<(PRODUCT_DIR)/android_webview_unittests_apk/assets',
'files': [
'test/unittest/assets/asset_file.ogg',
],
},
],
'includes': [ '../build/apk_test.gypi' ],
},
],
......
......@@ -9,6 +9,7 @@
#include "android_webview/browser/gpu_memory_buffer_factory_impl.h"
#include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
#include "android_webview/lib/aw_browser_dependency_factory_impl.h"
#include "android_webview/native/aw_media_url_interceptor.h"
#include "android_webview/native/aw_quota_manager_bridge_impl.h"
#include "android_webview/native/aw_web_contents_view_delegate.h"
#include "android_webview/native/aw_web_preferences_populater_impl.h"
......@@ -20,6 +21,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_restrictions.h"
#include "content/browser/media/android/browser_media_player_manager.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
......@@ -59,6 +61,9 @@ bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
cl->AppendSwitch(switches::kDisableZeroCopy);
}
content::BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
new AwMediaUrlInterceptor());
BrowserViewRenderer::CalculateTileMemoryPolicy(use_zero_copy);
cl->AppendSwitch(switches::kEnableBeginFrameScheduling);
......
include_rules = [
"+content/public/browser",
"+content/public/test",
"+media/base/android",
"+ui/gfx",
"+ui/shell_dialogs",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "android_webview/common/url_constants.h"
#include "android_webview/native/aw_assets.h"
#include "android_webview/native/aw_media_url_interceptor.h"
#include "base/strings/string_util.h"
#include "content/public/common/url_constants.h"
namespace android_webview {
bool AwMediaUrlInterceptor::Intercept(const std::string& url,
int* fd, int64* offset, int64* size) const{
const std::string asset_file_prefix(
std::string(url::kFileScheme) +
std::string(url::kStandardSchemeSeparator) +
android_webview::kAndroidAssetPath);
if (StartsWithASCII(url, asset_file_prefix, true)) {
std::string filename(url);
ReplaceFirstSubstringAfterOffset(&filename, 0, asset_file_prefix, "");
return AwAssets::OpenAsset(filename, fd, offset, size);
}
return false;
}
} // namespace android_webview
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_NATIVE_AW_MEDIA_URL_INTERCEPTOR_H_
#define ANDROID_WEBVIEW_NATIVE_AW_MEDIA_URL_INTERCEPTOR_H_
#include <string>
#include "base/android/jni_android.h"
#include "media/base/android/media_url_interceptor.h"
namespace android_webview {
// Interceptor to handle urls for media assets in the apk.
class AwMediaUrlInterceptor : public media::MediaUrlInterceptor {
public:
virtual bool Intercept(const std::string& url,
int* fd,
int64* offset,
int64* size) const OVERRIDE;
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_NATIVE_AW_MEDIA_URL_INTERCEPTOR_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "android_webview/native/aw_media_url_interceptor.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::Test;
namespace android_webview {
namespace {
// Sentinel value to check whether the fields have been set.
const int UNSET_VALUE = -1;
class AwMediaUrlInterceptorTest : public Test {
public:
AwMediaUrlInterceptorTest()
: fd_(UNSET_VALUE), offset_(UNSET_VALUE), size_(UNSET_VALUE),
url_interceptor_(new AwMediaUrlInterceptor()){
}
protected:
int fd_;
int64 offset_;
int64 size_;
scoped_ptr<AwMediaUrlInterceptor> url_interceptor_;
};
} // namespace
TEST_F(AwMediaUrlInterceptorTest, TestInterceptValidAssetUrl) {
// This asset file exists in the android_webview_unittests-debug.apk.
// See gyp rule android_webview_unittests_apk.
const std::string valid_asset_url(
"file:///android_asset/asset_file.ogg");
ASSERT_TRUE(url_interceptor_->Intercept(
valid_asset_url, &fd_, &offset_, &size_));
EXPECT_NE(UNSET_VALUE, fd_);
EXPECT_NE(UNSET_VALUE, offset_);
EXPECT_NE(UNSET_VALUE, size_);
}
TEST_F(AwMediaUrlInterceptorTest, TestInterceptInvalidAssetUrl) {
// This asset file does not exist in the android_webview_unittests-debug.apk.
// See gyp rule android_webview_unittests_apk.
const std::string invalid_asset_url(
"file:///android_asset/file_does_not_exist.ogg");
ASSERT_FALSE(url_interceptor_->Intercept(
invalid_asset_url, &fd_, &offset_, &size_));
EXPECT_EQ(UNSET_VALUE, fd_);
EXPECT_EQ(UNSET_VALUE, offset_);
EXPECT_EQ(UNSET_VALUE, size_);
}
TEST_F(AwMediaUrlInterceptorTest, TestInterceptNonAssetUrl) {
// This url does not refer to an asset in the apk.
const std::string non_asset_url("file:///sdcard/file.txt");
ASSERT_FALSE(url_interceptor_->Intercept(
non_asset_url, &fd_, &offset_, &size_));
EXPECT_EQ(UNSET_VALUE, fd_);
EXPECT_EQ(UNSET_VALUE, offset_);
EXPECT_EQ(UNSET_VALUE, size_);
}
} // namespace android_webview
......@@ -16,6 +16,7 @@
'../../components/components.gyp:autofill_content_browser',
'../../components/components.gyp:web_contents_delegate_android',
'../../content/content.gyp:content_common',
'../../media/media.gyp:player_android',
'../../net/net.gyp:net',
'../../skia/skia.gyp:skia',
'../../ui/base/ui_base.gyp:ui_base',
......@@ -55,6 +56,8 @@
'aw_form_database.h',
'aw_http_auth_handler.cc',
'aw_http_auth_handler.h',
'aw_media_url_interceptor.cc',
'aw_media_url_interceptor.h',
'aw_pdf_exporter.cc',
'aw_pdf_exporter.h',
'aw_picture.cc',
......
This file is used by the WebView unittests for loading media asset files,
see android_webview_unittests_apk and AwMediaUrlInterceptorTest.
This is a text file, but we use the .ogg extension so that aapt will not
compress its contents. This is ok for the purpose of the unit tests since
they do not play the media, and they are only interested in the existance of
an uncompressed media file in the assets directory.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment