Commit 2cecae61 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

Update App Service intent filter condition value to an array.

This CL updates the App Service intent filter condition value to an
array and create a intent_filter_util file to handle the creation of the
condition values.

Bug: 853604
Change-Id: Ib43f1efd4cde468379f25d6aaf9dd3ae54a6a142
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1816000
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699194}
parent e5964e84
...@@ -3576,6 +3576,7 @@ jumbo_split_static_library("browser") { ...@@ -3576,6 +3576,7 @@ jumbo_split_static_library("browser") {
"//chrome/services/app_service:lib", "//chrome/services/app_service:lib",
"//chrome/services/app_service/public/cpp:app_update", "//chrome/services/app_service/public/cpp:app_update",
"//chrome/services/app_service/public/cpp:icon_loader", "//chrome/services/app_service/public/cpp:icon_loader",
"//chrome/services/app_service/public/cpp:intent_filter_util",
"//components/feedback", "//components/feedback",
"//components/image_fetcher/core", "//components/image_fetcher/core",
"//components/keep_alive_registry", "//components/keep_alive_registry",
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/browser/web_applications/web_app_registrar.h" #include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/extensions/extension_metrics.h" #include "chrome/common/extensions/extension_metrics.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/services/app_service/public/cpp/intent_filter_util.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h" #include "chrome/services/app_service/public/mojom/types.mojom.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h" #include "components/content_settings/core/common/content_settings.h"
...@@ -99,19 +100,6 @@ ash::ShelfLaunchSource ConvertLaunchSource( ...@@ -99,19 +100,6 @@ ash::ShelfLaunchSource ConvertLaunchSource(
return ash::LAUNCH_FROM_SHELF; return ash::LAUNCH_FROM_SHELF;
} }
} }
apps::mojom::ConditionPtr MakeCondition(
apps::mojom::ConditionType condition_type,
const std::string& value,
apps::mojom::PatternMatchType pattern_match_type) {
auto condition = apps::mojom::Condition::New();
condition->condition_type = condition_type;
condition->value = value;
condition->match_type = pattern_match_type;
return condition;
}
} // namespace } // namespace
namespace apps { namespace apps {
...@@ -695,15 +683,29 @@ void ExtensionApps::PopulateIntentFilters( ...@@ -695,15 +683,29 @@ void ExtensionApps::PopulateIntentFilters(
std::vector<mojom::IntentFilterPtr>* target) { std::vector<mojom::IntentFilterPtr>* target) {
if (app_scope) { if (app_scope) {
auto intent_filter = apps::mojom::IntentFilter::New(); auto intent_filter = apps::mojom::IntentFilter::New();
intent_filter->conditions.push_back(
MakeCondition(apps::mojom::ConditionType::kScheme, app_scope->scheme(), std::vector<apps::mojom::ConditionValuePtr> scheme_condition_values;
apps::mojom::PatternMatchType::kNone)); scheme_condition_values.push_back(apps_util::MakeConditionValue(
intent_filter->conditions.push_back( app_scope->scheme(), apps::mojom::PatternMatchType::kNone));
MakeCondition(apps::mojom::ConditionType::kHost, app_scope->host(), auto scheme_condition =
apps::mojom::PatternMatchType::kNone)); apps_util::MakeCondition(apps::mojom::ConditionType::kScheme,
intent_filter->conditions.push_back( std::move(scheme_condition_values));
MakeCondition(apps::mojom::ConditionType::kPattern, app_scope->path(), intent_filter->conditions.push_back(std::move(scheme_condition));
apps::mojom::PatternMatchType::kPrefix));
std::vector<apps::mojom::ConditionValuePtr> host_condition_values;
host_condition_values.push_back(apps_util::MakeConditionValue(
app_scope->host(), apps::mojom::PatternMatchType::kNone));
auto host_condition = apps_util::MakeCondition(
apps::mojom::ConditionType::kHost, std::move(host_condition_values));
intent_filter->conditions.push_back(std::move(host_condition));
std::vector<apps::mojom::ConditionValuePtr> path_condition_values;
path_condition_values.push_back(apps_util::MakeConditionValue(
app_scope->path(), apps::mojom::PatternMatchType::kPrefix));
auto path_condition = apps_util::MakeCondition(
apps::mojom::ConditionType::kPattern, std::move(path_condition_values));
intent_filter->conditions.push_back(std::move(path_condition));
target->push_back(std::move(intent_filter)); target->push_back(std::move(intent_filter));
} }
} }
......
...@@ -55,6 +55,18 @@ source_set("manifest") { ...@@ -55,6 +55,18 @@ source_set("manifest") {
] ]
} }
source_set("intent_filter_util") {
sources = [
"intent_filter_util.cc",
"intent_filter_util.h",
]
deps = [
"//base",
"//chrome/services/app_service/public/mojom",
]
}
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/services/app_service/public/cpp/app_update.h" #include "chrome/services/app_service/public/cpp/app_update.h"
#include "chrome/services/app_service/public/cpp/intent_filter_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace { namespace {
...@@ -80,15 +81,6 @@ class AppUpdateTest : public testing::Test { ...@@ -80,15 +81,6 @@ class AppUpdateTest : public testing::Test {
return permission; return permission;
} }
apps::mojom::ConditionPtr MakeCondition(
apps::mojom::ConditionType condition_type,
std::string value) {
auto condition = apps::mojom::Condition::New();
condition->condition_type = condition_type;
condition->value = value;
return condition;
}
void ExpectNoChange() { void ExpectNoChange() {
expect_readiness_changed_ = false; expect_readiness_changed_ = false;
expect_name_changed_ = false; expect_name_changed_ = false;
...@@ -591,10 +583,21 @@ class AppUpdateTest : public testing::Test { ...@@ -591,10 +583,21 @@ class AppUpdateTest : public testing::Test {
if (state) { if (state) {
auto intent_filter = apps::mojom::IntentFilter::New(); auto intent_filter = apps::mojom::IntentFilter::New();
std::vector<apps::mojom::ConditionValuePtr> scheme_condition_values;
scheme_condition_values.push_back(apps_util::MakeConditionValue(
"https", apps::mojom::PatternMatchType::kNone));
auto scheme_condition = auto scheme_condition =
MakeCondition(apps::mojom::ConditionType::kScheme, "https"); apps_util::MakeCondition(apps::mojom::ConditionType::kScheme,
auto host_condition = std::move(scheme_condition_values));
MakeCondition(apps::mojom::ConditionType::kHost, "www.google.com"); intent_filter->conditions.push_back(std::move(scheme_condition));
std::vector<apps::mojom::ConditionValuePtr> host_condition_values;
host_condition_values.push_back(apps_util::MakeConditionValue(
"www.google.com", apps::mojom::PatternMatchType::kNone));
auto host_condition = apps_util::MakeCondition(
apps::mojom::ConditionType::kHost, std::move(host_condition_values));
intent_filter->conditions.push_back(std::move(host_condition));
intent_filter->conditions.push_back(scheme_condition.Clone()); intent_filter->conditions.push_back(scheme_condition.Clone());
intent_filter->conditions.push_back(host_condition.Clone()); intent_filter->conditions.push_back(host_condition.Clone());
...@@ -610,10 +613,20 @@ class AppUpdateTest : public testing::Test { ...@@ -610,10 +613,20 @@ class AppUpdateTest : public testing::Test {
auto intent_filter = apps::mojom::IntentFilter::New(); auto intent_filter = apps::mojom::IntentFilter::New();
std::vector<apps::mojom::ConditionValuePtr> scheme_condition_values;
scheme_condition_values.push_back(apps_util::MakeConditionValue(
"https", apps::mojom::PatternMatchType::kNone));
auto scheme_condition = auto scheme_condition =
MakeCondition(apps::mojom::ConditionType::kScheme, "https"); apps_util::MakeCondition(apps::mojom::ConditionType::kScheme,
auto host_condition = std::move(scheme_condition_values));
MakeCondition(apps::mojom::ConditionType::kHost, "www.abc.com"); intent_filter->conditions.push_back(std::move(scheme_condition));
std::vector<apps::mojom::ConditionValuePtr> host_condition_values;
host_condition_values.push_back(apps_util::MakeConditionValue(
"www.abc.com", apps::mojom::PatternMatchType::kNone));
auto host_condition = apps_util::MakeCondition(
apps::mojom::ConditionType::kHost, std::move(host_condition_values));
intent_filter->conditions.push_back(std::move(host_condition));
intent_filter->conditions.push_back(scheme_condition.Clone()); intent_filter->conditions.push_back(scheme_condition.Clone());
intent_filter->conditions.push_back(host_condition.Clone()); intent_filter->conditions.push_back(host_condition.Clone());
......
// Copyright (c) 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 "chrome/services/app_service/public/cpp/intent_filter_util.h"
namespace apps_util {
apps::mojom::ConditionValuePtr MakeConditionValue(
const std::string& value,
apps::mojom::PatternMatchType pattern_match_type) {
auto condition_value = apps::mojom::ConditionValue::New();
condition_value->value = value;
condition_value->match_type = pattern_match_type;
return condition_value;
}
apps::mojom::ConditionPtr MakeCondition(
apps::mojom::ConditionType condition_type,
std::vector<apps::mojom::ConditionValuePtr> condition_values) {
auto condition = apps::mojom::Condition::New();
condition->condition_type = condition_type;
condition->condition_values = std::move(condition_values);
return condition;
}
} // namespace apps_util
// Copyright (c) 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.
#ifndef CHROME_SERVICES_APP_SERVICE_PUBLIC_CPP_INTENT_FILTER_UTIL_H_
#define CHROME_SERVICES_APP_SERVICE_PUBLIC_CPP_INTENT_FILTER_UTIL_H_
// Utility functions for providing an App Service intent filter.
#include <string>
#include "base/macros.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h"
namespace apps_util {
apps::mojom::ConditionValuePtr MakeConditionValue(
const std::string& value,
apps::mojom::PatternMatchType pattern_match_type);
// Creates condition that makes up App Service intent filter.
apps::mojom::ConditionPtr MakeCondition(
apps::mojom::ConditionType condition_type,
std::vector<apps::mojom::ConditionValuePtr> condition_values);
} // namespace apps_util
#endif // CHROME_SERVICES_APP_SERVICE_PUBLIC_CPP_INTENT_FILTER_UTIL_H_
...@@ -190,12 +190,20 @@ enum PatternMatchType { ...@@ -190,12 +190,20 @@ enum PatternMatchType {
kGlob, kGlob,
}; };
// For pattern type of condition, the value match will be based on the pattern
// match type. If the match_type is kNone, then an exact match with the value
// will be required.
struct ConditionValue {
string value;
PatternMatchType match_type; // This will be None for non pattern conditions.
};
// The condition for an intent filter. It matches if the intent contains this // The condition for an intent filter. It matches if the intent contains this
// condition type and the corresponding value matches with the value. // condition type and the corresponding value matches with any of the
// condition_values.
struct Condition { struct Condition {
ConditionType condition_type; ConditionType condition_type;
string value; array<ConditionValue> condition_values;
PatternMatchType match_type; //This will be None for non pattern conditions.
}; };
// An intent filter is defined by an app, and contains a list of conditions that // An intent filter is defined by an app, and contains a list of conditions that
......
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