Commit 8481860c authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[IntentHandling] Support text content sharing.

This CL adds the support for text content sharing in the intent handling
system.

BUG=1092784

Change-Id: I360a3e9e36fdc11ea5bc26c560aff46d0b9aac2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409396Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806853}
parent 0169e5bc
......@@ -213,7 +213,7 @@ base::Optional<arc::UserInteractionType> GetUserInterationType(
arc::mojom::IntentInfoPtr CreateArcIntent(apps::mojom::IntentPtr intent) {
arc::mojom::IntentInfoPtr arc_intent;
if (!intent->url.has_value()) {
if (!intent->url.has_value() && !intent->share_text.has_value()) {
return arc_intent;
}
arc_intent = arc::mojom::IntentInfo::New();
......@@ -230,7 +230,14 @@ arc::mojom::IntentInfoPtr CreateArcIntent(apps::mojom::IntentPtr intent) {
} else {
arc_intent->action = arc::kIntentActionView;
}
arc_intent->data = intent->url->spec();
if (intent->url.has_value()) {
arc_intent->data = intent->url->spec();
}
if (intent->share_text.has_value()) {
arc_intent->extras = base::flat_map<std::string, std::string>();
arc_intent->extras.value().insert(std::make_pair(
"android.intent.extra.TEXT", intent->share_text.value()));
}
return arc_intent;
}
......@@ -761,14 +768,8 @@ void ArcApps::LaunchAppWithIntent(const std::string& app_id,
!intent->activity_name.value().empty()) {
activity->activity_name = intent->activity_name.value();
}
// At the moment, the only case we have mime_type field set is to share
// files, in this case, convert the file urls to content urls and use
// arc file system instance to launch the app with files.
if (intent->mime_type.has_value()) {
if (!intent->file_urls.has_value()) {
LOG(ERROR) << "Share files failed, share intent is not valid";
return;
}
if (intent->mime_type.has_value() && intent->file_urls.has_value()) {
file_manager::util::ConvertToContentUrls(
apps::GetFileSystemURL(profile_, intent->file_urls.value()),
base::BindOnce(&OnContentUrlResolved, std::move(intent),
......
......@@ -167,6 +167,15 @@ apps::mojom::IntentPtr CreateShareIntentFromDriveFile(
return intent;
}
apps::mojom::IntentPtr CreateShareIntentFromText(
const std::string& share_text) {
auto intent = apps::mojom::Intent::New();
intent->action = kIntentActionSend;
intent->mime_type = "text/plain";
intent->share_text = share_text;
return intent;
}
bool ConditionValueMatches(
const std::string& value,
const apps::mojom::ConditionValuePtr& condition_value) {
......
......@@ -35,6 +35,9 @@ apps::mojom::IntentPtr CreateShareIntentFromDriveFile(
const std::string& mime_type,
const GURL& drive_share_url);
// Create an intent struct from URL.
apps::mojom::IntentPtr CreateShareIntentFromText(const std::string& share_text);
// Return true if |value| matches with the |condition_value|, based on the
// pattern match type in the |condition_value|.
bool ConditionValueMatches(
......
......@@ -329,6 +329,7 @@ struct Intent {
// The Drive share URL, this is only filled if the intent contains a file
// from Google Drive.
url.mojom.Url? drive_share_url;
string? share_text; // Text to share. e.g. Share link to other app.
};
// Represents a group of |app_ids| that is no longer preferred app of their
......
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