Commit 55f65ce4 authored by Yue Li's avatar Yue Li Committed by Commit Bot

Update check rules for Android intent

The check rules does not work for playing media intent. Update the rule
to also check the ref part.

Bug: b/142075916
Test: Manual Test
Change-Id: I67d4e75efb038bb024560799d6466b7220751c54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1838977
Commit-Queue: Yue Li <updowndota@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703902}
parent 2e3365f7
......@@ -32,13 +32,6 @@
namespace ash {
namespace {
// Scheme of the Android intent url.
constexpr char kAndroidIntentScheme[] = "intent";
} // namespace
AssistantController::AssistantController() {
assistant_state_controller_.AddObserver(this);
chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
......@@ -234,7 +227,7 @@ void AssistantController::OpenUrl(const GURL& url,
}
auto* android_helper = AndroidIntentHelper::GetInstance();
if (url.SchemeIs(kAndroidIntentScheme) && !android_helper) {
if (IsAndroidIntent(url) && !android_helper) {
NOTREACHED();
return;
}
......@@ -243,7 +236,7 @@ void AssistantController::OpenUrl(const GURL& url,
// open the specified |url| in a new browser tab.
NotifyOpeningUrl(url, in_background, from_server);
if (url.SchemeIs(kAndroidIntentScheme)) {
if (IsAndroidIntent(url)) {
android_helper->LaunchAndroidIntent(url.spec());
} else {
// The new tab should be opened with a user activation since the user
......
......@@ -308,6 +308,7 @@ source_set("manifest_for_tests") {
source_set("unit_tests") {
testonly = true
sources = [
"android_intent_helper_unittest.cc",
"app_list/app_list_config_provider_unittest.cc",
"default_scale_factor_retriever_unittest.cc",
"pagination/pagination_model_unittest.cc",
......
......@@ -7,8 +7,16 @@
namespace ash {
namespace {
AndroidIntentHelper* g_android_intent_helper = nullptr;
}
// Scheme of the Android intent url.
constexpr char kAndroidIntentScheme[] = "intent";
// Prefix of the Android intent ref fragment.
constexpr char kAndroidIntentPrefix[] = "Intent;";
} // namespace
// static
AndroidIntentHelper* AndroidIntentHelper::GetInstance() {
......@@ -25,4 +33,10 @@ AndroidIntentHelper::~AndroidIntentHelper() {
g_android_intent_helper = nullptr;
}
bool IsAndroidIntent(const GURL& url) {
return url.SchemeIs(kAndroidIntentScheme) ||
base::StartsWith(url.ref(), kAndroidIntentPrefix,
base::CompareCase::SENSITIVE);
}
} // namespace ash
......@@ -34,6 +34,8 @@ class ASH_PUBLIC_EXPORT AndroidIntentHelper {
DISALLOW_COPY_AND_ASSIGN(AndroidIntentHelper);
};
ASH_PUBLIC_EXPORT bool IsAndroidIntent(const GURL& url);
} // namespace ash
#endif // ASH_PUBLIC_CPP_ANDROID_INTENT_HELPER_H_
// Copyright 2019 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 "ash/public/cpp/android_intent_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash {
using AndroidIntentHelperTest = testing::Test;
TEST_F(AndroidIntentHelperTest, AndroidIntentURL) {
const std::string intent_url_type_1 = "intent://abc";
EXPECT_TRUE(IsAndroidIntent(GURL(intent_url_type_1)));
const std::string intent_url_type_2 =
"http://www.youtube.com/watch?v=abc;"
"#Intent;action=android.intent.action.VIEW;"
"package=com.google.android.youtube;end";
EXPECT_TRUE(IsAndroidIntent(GURL(intent_url_type_2)));
const std::string normal_url = "http://www.google.com";
EXPECT_FALSE(IsAndroidIntent(GURL(normal_url)));
}
} // namespace ash
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