Commit bcc24571 authored by Ethan Xu's avatar Ethan Xu Committed by Commit Bot

Update WebApk proto file to include three new fields: method, enctype, and files.

This CL updates the WebApk proto file to support three additional fields for web share target.
Specifically:

- Method:  can be either GET or POST request.
- Enctype: only relevant for POST method, can be either application/x-www-form-urlencoded
           or multipart/form-data.
           (please note that in the proto file, APPLICATION corresponds with
           application/x-www-form-urlencoded, MULTIPART corresponds with multipart/form-data.)
- Files:   a sequence of share target files. Each share target file contains a name field as an
           identifier, and an accept field that includes a sequence of accepted mime types.

Change-Id: I70f84bf349a5c61519aafcec72a7b68e3f67ef83
Reviewed-on: https://chromium-review.googlesource.com/c/1294595
Commit-Queue: Ethan Xu <xuethan@google.com>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarGlenn Hartmann <hartmanng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610746}
parent 3c041bcd
...@@ -2,9 +2,28 @@ ...@@ -2,9 +2,28 @@
// 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.
#include "base/feature_list.h"
#include "chrome/browser/android/shortcut_info.h" #include "chrome/browser/android/shortcut_info.h"
#include "base/feature_list.h"
#include "base/strings/utf_string_conversions.h"
ShareTargetParamsFile::ShareTargetParamsFile() {}
ShareTargetParamsFile::ShareTargetParamsFile(
const ShareTargetParamsFile& other) = default;
ShareTargetParamsFile::~ShareTargetParamsFile() {}
ShareTargetParams::ShareTargetParams() {}
ShareTargetParams::ShareTargetParams(const ShareTargetParams& other) = default;
ShareTargetParams::~ShareTargetParams() {}
ShareTarget::ShareTarget() {}
ShareTarget::~ShareTarget() {}
ShortcutInfo::ShortcutInfo(const GURL& shortcut_url) ShortcutInfo::ShortcutInfo(const GURL& shortcut_url)
: url(shortcut_url), : url(shortcut_url),
display(blink::kWebDisplayModeBrowser), display(blink::kWebDisplayModeBrowser),
...@@ -74,12 +93,32 @@ void ShortcutInfo::UpdateFromManifest(const blink::Manifest& manifest) { ...@@ -74,12 +93,32 @@ void ShortcutInfo::UpdateFromManifest(const blink::Manifest& manifest) {
if (manifest.share_target) { if (manifest.share_target) {
share_target = ShareTarget(); share_target = ShareTarget();
share_target->action = manifest.share_target->action; share_target->action = manifest.share_target->action;
if (manifest.share_target->method ==
blink::Manifest::ShareTarget::Method::kPost) {
share_target->method = ShareTarget::Method::kPost;
} else {
share_target->method = ShareTarget::Method::kGet;
}
if (manifest.share_target->enctype ==
blink::Manifest::ShareTarget::Enctype::kMultipart) {
share_target->enctype = ShareTarget::Enctype::kMultipart;
} else {
share_target->enctype = ShareTarget::Enctype::kApplication;
}
if (!manifest.share_target->params.text.is_null()) if (!manifest.share_target->params.text.is_null())
share_target->params.text = manifest.share_target->params.text.string(); share_target->params.text = manifest.share_target->params.text.string();
if (!manifest.share_target->params.title.is_null()) if (!manifest.share_target->params.title.is_null())
share_target->params.title = manifest.share_target->params.title.string(); share_target->params.title = manifest.share_target->params.title.string();
if (!manifest.share_target->params.url.is_null()) if (!manifest.share_target->params.url.is_null())
share_target->params.url = manifest.share_target->params.url.string(); share_target->params.url = manifest.share_target->params.url.string();
for (blink::Manifest::ShareTargetFile manifest_share_target_file :
manifest.share_target->params.files) {
ShareTargetParamsFile share_target_params_file;
share_target_params_file.name = manifest_share_target_file.name;
share_target_params_file.accept = manifest_share_target_file.accept;
share_target->params.files.push_back(share_target_params_file);
}
} }
} }
......
...@@ -16,17 +16,43 @@ ...@@ -16,17 +16,43 @@
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "url/gurl.h" #include "url/gurl.h"
// https://pr-preview.s3.amazonaws.com/ewilligers/web-share-target/pull/53.html#sharetargetfiles-and-its-members
struct ShareTargetParamsFile {
base::string16 name;
std::vector<base::string16> accept;
ShareTargetParamsFile();
ShareTargetParamsFile(const ShareTargetParamsFile& other);
~ShareTargetParamsFile();
};
// https://wicg.github.io/web-share-target/#dom-sharetargetparams // https://wicg.github.io/web-share-target/#dom-sharetargetparams
struct ShareTargetParams { struct ShareTargetParams {
base::string16 title; base::string16 title;
base::string16 text; base::string16 text;
base::string16 url; base::string16 url;
std::vector<ShareTargetParamsFile> files;
ShareTargetParams();
ShareTargetParams(const ShareTargetParams& other);
~ShareTargetParams();
}; };
// https://wicg.github.io/web-share-target/#dom-sharetarget // https://wicg.github.io/web-share-target/#dom-sharetarget
struct ShareTarget { struct ShareTarget {
// This enum is used to indicate the HTTP method used by the share target.
// kGet stands for GET request, and kPost stands for POST request.
enum Method { kGet = 0, kPost = 1 };
// This enum is used to indicate the HTTP enctype used by the share target.
// kApplication stands for application/x-www-form-urlencoded enctype, and
// kMultipart stands for multipart/form-data enctype.
enum Enctype { kApplication = 0, kMultipart = 1 };
GURL action; GURL action;
Method method;
Enctype enctype;
ShareTargetParams params; ShareTargetParams params;
ShareTarget();
~ShareTarget();
}; };
// Information needed to create a shortcut via ShortcutHelper. // Information needed to create a shortcut via ShortcutHelper.
......
...@@ -118,6 +118,13 @@ message Image { ...@@ -118,6 +118,13 @@ message Image {
reserved 2, 3, 4, 7; reserved 2, 3, 4, 7;
} }
// A proto representing a ShareTargetParamsFile
// https://pr-preview.s3.amazonaws.com/ewilligers/web-share-target/pull/53.html#sharetargetfiles-and-its-members
message ShareTargetParamsFile {
optional string name = 1;
repeated string accept = 2;
}
// A proto representing ShareTargetParams // A proto representing ShareTargetParams
// https://wicg.github.io/web-share-target/#dom-sharetargetparams // https://wicg.github.io/web-share-target/#dom-sharetargetparams
// Each field corresponds to key in ShareData. These are the query parameter // Each field corresponds to key in ShareData. These are the query parameter
...@@ -127,6 +134,7 @@ message ShareTargetParams { ...@@ -127,6 +134,7 @@ message ShareTargetParams {
optional string title = 1; optional string title = 1;
optional string text = 2; optional string text = 2;
optional string url = 3; optional string url = 3;
repeated ShareTargetParamsFile files = 4;
} }
// A proto representing a ShareTarget. // A proto representing a ShareTarget.
...@@ -135,8 +143,7 @@ message ShareTarget { ...@@ -135,8 +143,7 @@ message ShareTarget {
// The URL to be resolved when sharing. // The URL to be resolved when sharing.
optional string action = 2; optional string action = 2;
optional ShareTargetParams params = 3; optional ShareTargetParams params = 3;
// TODO(ckitagawa): optional string method = 4;
// Add method and enctype for POST (GET by default). optional string enctype = 5;
reserved 1; reserved 1;
} }
...@@ -217,6 +217,17 @@ std::unique_ptr<std::string> BuildProtoInBackground( ...@@ -217,6 +217,17 @@ std::unique_ptr<std::string> BuildProtoInBackground(
if (shortcut_info.share_target) { if (shortcut_info.share_target) {
webapk::ShareTarget* share_target = web_app_manifest->add_share_targets(); webapk::ShareTarget* share_target = web_app_manifest->add_share_targets();
share_target->set_action(shortcut_info.share_target->action.spec()); share_target->set_action(shortcut_info.share_target->action.spec());
if (shortcut_info.share_target->method == ShareTarget::Method::kPost) {
share_target->set_method("POST");
} else {
share_target->set_method("GET");
}
if (shortcut_info.share_target->enctype ==
ShareTarget::Enctype::kMultipart) {
share_target->set_enctype("multipart/form-data");
} else {
share_target->set_enctype("application/x-www-form-urlencoded");
}
webapk::ShareTargetParams* share_target_params = webapk::ShareTargetParams* share_target_params =
share_target->mutable_params(); share_target->mutable_params();
share_target_params->set_title( share_target_params->set_title(
...@@ -225,6 +236,16 @@ std::unique_ptr<std::string> BuildProtoInBackground( ...@@ -225,6 +236,16 @@ std::unique_ptr<std::string> BuildProtoInBackground(
base::UTF16ToUTF8(shortcut_info.share_target->params.text)); base::UTF16ToUTF8(shortcut_info.share_target->params.text));
share_target_params->set_url( share_target_params->set_url(
base::UTF16ToUTF8(shortcut_info.share_target->params.url)); base::UTF16ToUTF8(shortcut_info.share_target->params.url));
for (const ShareTargetParamsFile& share_target_params_file :
shortcut_info.share_target->params.files) {
webapk::ShareTargetParamsFile* share_files =
share_target_params->add_files();
share_files->set_name(base::UTF16ToUTF8(share_target_params_file.name));
for (base::string16 mime_type : share_target_params_file.accept) {
share_files->add_accept(base::UTF16ToUTF8(mime_type));
}
}
} }
if (shortcut_info.best_primary_icon_url.is_empty()) { if (shortcut_info.best_primary_icon_url.is_empty()) {
......
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