Commit 9c051c3b authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[IntentHandling] Fetch intent filter action and mime type from ARC.

Pass the actions and mime types for Android apps from ARC to Chrome.

BUG=1092784
Test: Manually print out the intent filter getting from ARC and look
at the action and mime type entries.

Change-Id: I7ac3c6762a63817cb55cb06f6da0bb566755a11c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228591
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarDavid Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#777222}
parent f864bd6d
...@@ -225,9 +225,12 @@ apps::mojom::IntentFilterPtr ConvertArcIntentFilter( ...@@ -225,9 +225,12 @@ apps::mojom::IntentFilterPtr ConvertArcIntentFilter(
arc::IntentFilter CreateArcIntentFilter( arc::IntentFilter CreateArcIntentFilter(
const std::string& package_name, const std::string& package_name,
const apps::mojom::IntentFilterPtr& intent_filter) { const apps::mojom::IntentFilterPtr& intent_filter) {
std::vector<std::string> actions;
std::vector<std::string> schemes; std::vector<std::string> schemes;
std::vector<arc::IntentFilter::AuthorityEntry> authorities; std::vector<arc::IntentFilter::AuthorityEntry> authorities;
std::vector<arc::IntentFilter::PatternMatcher> paths; std::vector<arc::IntentFilter::PatternMatcher> paths;
std::vector<std::string> mime_types;
// TODO(crbug.com/853604): Add conversion for actions and mime types.
for (auto& condition : intent_filter->conditions) { for (auto& condition : intent_filter->conditions) {
switch (condition->condition_type) { switch (condition->condition_type) {
case apps::mojom::ConditionType::kScheme: case apps::mojom::ConditionType::kScheme:
...@@ -265,8 +268,9 @@ arc::IntentFilter CreateArcIntentFilter( ...@@ -265,8 +268,9 @@ arc::IntentFilter CreateArcIntentFilter(
} }
} }
// TODO(crbug.com/853604): Add support for other action and category types. // TODO(crbug.com/853604): Add support for other action and category types.
return arc::IntentFilter(package_name, std::move(authorities), return arc::IntentFilter(package_name, std::move(actions),
std::move(paths), std::move(schemes)); std::move(authorities), std::move(paths),
std::move(schemes), std::move(mime_types));
} }
// Check if this intent filter only contains HTTP and HTTPS schemes. // Check if this intent filter only contains HTTP and HTTPS schemes.
......
...@@ -24,9 +24,11 @@ IntentFilter GetIntentFilter(const std::string& host, ...@@ -24,9 +24,11 @@ IntentFilter GetIntentFilter(const std::string& host,
const std::string& pkg_name) { const std::string& pkg_name) {
std::vector<IntentFilter::AuthorityEntry> authorities; std::vector<IntentFilter::AuthorityEntry> authorities;
authorities.emplace_back(host, /*port=*/-1); authorities.emplace_back(host, /*port=*/-1);
return IntentFilter(pkg_name, std::move(authorities), return IntentFilter(pkg_name, /*actions=*/std::vector<std::string>(),
std::move(authorities),
std::vector<IntentFilter::PatternMatcher>(), std::vector<IntentFilter::PatternMatcher>(),
std::vector<std::string>()); /*schemes=*/std::vector<std::string>(),
/*mime_types=*/std::vector<std::string>());
} }
} // namespace } // namespace
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
#include "components/arc/intent_helper/intent_filter.h" #include "components/arc/intent_helper/intent_filter.h"
#include <algorithm>
#include <utility> #include <utility>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "components/arc/intent_helper/intent_constants.h"
#include "components/arc/mojom/intent_helper.mojom.h" #include "components/arc/mojom/intent_helper.mojom.h"
#include "components/services/app_service/public/cpp/arc_intent_util.h" #include "components/services/app_service/public/cpp/arc_intent_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -19,12 +21,16 @@ IntentFilter::IntentFilter(IntentFilter&& other) = default; ...@@ -19,12 +21,16 @@ IntentFilter::IntentFilter(IntentFilter&& other) = default;
IntentFilter::IntentFilter( IntentFilter::IntentFilter(
const std::string& package_name, const std::string& package_name,
std::vector<std::string> actions,
std::vector<IntentFilter::AuthorityEntry> authorities, std::vector<IntentFilter::AuthorityEntry> authorities,
std::vector<IntentFilter::PatternMatcher> paths, std::vector<IntentFilter::PatternMatcher> paths,
std::vector<std::string> schemes) std::vector<std::string> schemes,
std::vector<std::string> mime_types)
: package_name_(package_name), : package_name_(package_name),
actions_(std::move(actions)),
authorities_(std::move(authorities)), authorities_(std::move(authorities)),
schemes_(std::move(schemes)) { schemes_(std::move(schemes)),
mime_types_(std::move(mime_types)) {
// In order to register a path we need to have at least one authority. // In order to register a path we need to have at least one authority.
if (!authorities_.empty()) if (!authorities_.empty())
paths_ = std::move(paths); paths_ = std::move(paths);
...@@ -45,6 +51,15 @@ bool IntentFilter::Match(const GURL& url) const { ...@@ -45,6 +51,15 @@ bool IntentFilter::Match(const GURL& url) const {
return false; return false;
} }
// Don't return match for filters for sharing.
if (std::any_of(actions_.begin(), actions_.end(),
[](const std::string action) {
return action == kIntentActionSend ||
action == kIntentActionSendMultiple;
})) {
return false;
}
// Match the authority and the path. If there are no authorities for this // Match the authority and the path. If there are no authorities for this
// filter, we can treat this as a match, since we already know this filter // filter, we can treat this as a match, since we already know this filter
// has a http(s) scheme and it doesn't corresponds to a MIME type. // has a http(s) scheme and it doesn't corresponds to a MIME type.
......
...@@ -70,9 +70,11 @@ class IntentFilter { ...@@ -70,9 +70,11 @@ class IntentFilter {
IntentFilter(); IntentFilter();
IntentFilter(IntentFilter&& other); IntentFilter(IntentFilter&& other);
IntentFilter(const std::string& package_name, IntentFilter(const std::string& package_name,
std::vector<std::string> actions,
std::vector<AuthorityEntry> authorities, std::vector<AuthorityEntry> authorities,
std::vector<PatternMatcher> paths, std::vector<PatternMatcher> paths,
std::vector<std::string> schemes); std::vector<std::string> schemes,
std::vector<std::string> mime_types);
~IntentFilter(); ~IntentFilter();
IntentFilter& operator=(IntentFilter&& other); IntentFilter& operator=(IntentFilter&& other);
...@@ -80,20 +82,24 @@ class IntentFilter { ...@@ -80,20 +82,24 @@ class IntentFilter {
bool Match(const GURL& url) const; bool Match(const GURL& url) const;
const std::string& package_name() const { return package_name_; } const std::string& package_name() const { return package_name_; }
const std::vector<std::string>& actions() const { return actions_; }
const std::vector<AuthorityEntry>& authorities() const { const std::vector<AuthorityEntry>& authorities() const {
return authorities_; return authorities_;
} }
const std::vector<PatternMatcher>& paths() const { return paths_; } const std::vector<PatternMatcher>& paths() const { return paths_; }
const std::vector<std::string>& schemes() const { return schemes_; } const std::vector<std::string>& schemes() const { return schemes_; }
const std::vector<std::string>& mime_types() const { return mime_types_; }
private: private:
bool MatchDataAuthority(const GURL& url) const; bool MatchDataAuthority(const GURL& url) const;
bool HasDataPath(const GURL& url) const; bool HasDataPath(const GURL& url) const;
std::string package_name_; std::string package_name_;
std::vector<std::string> actions_;
std::vector<AuthorityEntry> authorities_; std::vector<AuthorityEntry> authorities_;
std::vector<PatternMatcher> paths_; std::vector<PatternMatcher> paths_;
std::vector<std::string> schemes_; std::vector<std::string> schemes_;
std::vector<std::string> mime_types_;
DISALLOW_COPY_AND_ASSIGN(IntentFilter); DISALLOW_COPY_AND_ASSIGN(IntentFilter);
}; };
......
...@@ -31,8 +31,17 @@ bool StructTraits<arc::mojom::IntentFilterDataView, arc::IntentFilter>::Read( ...@@ -31,8 +31,17 @@ bool StructTraits<arc::mojom::IntentFilterDataView, arc::IntentFilter>::Read(
if (!data.ReadDataSchemes(&schemes)) if (!data.ReadDataSchemes(&schemes))
return false; return false;
*out = arc::IntentFilter(package_name, std::move(authorities), std::vector<std::string> actions;
std::move(paths), std::move(schemes)); if (!data.ReadActions(&actions))
return false;
std::vector<std::string> mime_types;
if (!data.ReadMimeTypes(&mime_types))
return false;
*out = arc::IntentFilter(package_name, std::move(actions),
std::move(authorities), std::move(paths),
std::move(schemes), std::move(mime_types));
return true; return true;
} }
......
...@@ -16,9 +16,8 @@ namespace mojo { ...@@ -16,9 +16,8 @@ namespace mojo {
template <> template <>
struct StructTraits<arc::mojom::IntentFilterDataView, arc::IntentFilter> { struct StructTraits<arc::mojom::IntentFilterDataView, arc::IntentFilter> {
static const base::span<std::string> actions(const arc::IntentFilter& r) { static const std::vector<std::string>& actions(const arc::IntentFilter& r) {
// Returns an empty array. return r.actions();
return base::span<std::string>();
} }
static const base::span<std::string> categories(const arc::IntentFilter& r) { static const base::span<std::string> categories(const arc::IntentFilter& r) {
// Returns an empty array. // Returns an empty array.
...@@ -46,6 +45,11 @@ struct StructTraits<arc::mojom::IntentFilterDataView, arc::IntentFilter> { ...@@ -46,6 +45,11 @@ struct StructTraits<arc::mojom::IntentFilterDataView, arc::IntentFilter> {
return r.package_name(); return r.package_name();
} }
static const std::vector<std::string>& mime_types(
const arc::IntentFilter& r) {
return r.mime_types();
}
static bool Read(arc::mojom::IntentFilterDataView data, static bool Read(arc::mojom::IntentFilterDataView data,
arc::IntentFilter* out); arc::IntentFilter* out);
}; };
......
...@@ -40,8 +40,11 @@ class IntentFilterBuilder { ...@@ -40,8 +40,11 @@ class IntentFilterBuilder {
} }
operator IntentFilter() { operator IntentFilter() {
return IntentFilter(kPackageName, std::move(authorities_), return IntentFilter(kPackageName,
std::move(paths_), std::vector<std::string>()); /*actions=*/std::vector<std::string>(),
std::move(authorities_), std::move(paths_),
/*schemes=*/std::vector<std::string>(),
/*mime_types=*/std::vector<std::string>());
} }
private: private:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// Next MinVersion: 38 // Next MinVersion: 39
module arc.mojom; module arc.mojom;
...@@ -82,6 +82,7 @@ struct IntentFilter { ...@@ -82,6 +82,7 @@ struct IntentFilter {
[MinVersion=10] array<PatternMatcher>? data_paths; [MinVersion=10] array<PatternMatcher>? data_paths;
[MinVersion=10] array<PatternMatcher>? deprecated_data_scheme_specific_parts; [MinVersion=10] array<PatternMatcher>? deprecated_data_scheme_specific_parts;
[MinVersion=21] string? package_name; // Package which registered the filter. [MinVersion=21] string? package_name; // Package which registered the filter.
[MinVersion=38] array<string>? mime_types; // Intent filer mime types.
}; };
// Describes a package that can handle an intent. // Describes a package that can handle an intent.
......
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