Commit 1afbeed8 authored by Curt Clemens's avatar Curt Clemens Committed by Commit Bot

[Nearby] Allow chrome://nearby to accept parameters for testing files

A previous CL added support for creating text attachments using query
parameters to chrome://nearby. This CL expands that support to allow
passing file paths to be shared, e.g.
chrome://nearby/share?file=/path/to/file1.png|/path/to/file2.jpg

Bug: 1145684
Change-Id: Ie8fb9aa6ec82404393045a7ee1d52597572f5f25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530261Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Curt Clemens <cclem@google.com>
Cr-Commit-Position: refs/heads/master@{#826005}
parent f64bca25
......@@ -6,12 +6,15 @@
#include <string>
#include "base/strings/string_split.h"
#include "chrome/browser/nearby_sharing/contacts/nearby_share_contact_manager.h"
#include "chrome/browser/nearby_sharing/file_attachment.h"
#include "chrome/browser/nearby_sharing/nearby_per_session_discovery_manager.h"
#include "chrome/browser/nearby_sharing/nearby_share_settings.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service_factory.h"
#include "chrome/browser/nearby_sharing/nearby_sharing_service_impl.h"
#include "chrome/browser/nearby_sharing/text_attachment.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/nearby_share/shared_resources.h"
#include "chrome/browser/ui/webui/webui_util.h"
......@@ -66,7 +69,7 @@ NearbyShareDialogUI::NearbyShareDialogUI(content::WebUI* web_ui)
content::WebUIDataSource::Add(profile, html_source);
const GURL& url = web_ui->GetWebContents()->GetVisibleURL();
SetTextAttachmentFromQueryParameter(url);
SetAttachmentFromQueryParameter(url);
}
NearbyShareDialogUI::~NearbyShareDialogUI() = default;
......@@ -115,7 +118,8 @@ void NearbyShareDialogUI::HandleClose(const base::ListValue* args) {
}
}
void NearbyShareDialogUI::SetTextAttachmentFromQueryParameter(const GURL& url) {
void NearbyShareDialogUI::SetAttachmentFromQueryParameter(const GURL& url) {
std::vector<std::unique_ptr<Attachment>> attachments;
std::string value;
for (auto& text_type :
std::vector<std::pair<std::string, TextAttachment::Type>>{
......@@ -124,13 +128,21 @@ void NearbyShareDialogUI::SetTextAttachmentFromQueryParameter(const GURL& url) {
{"phone", TextAttachment::Type::kPhoneNumber},
{"text", TextAttachment::Type::kText}}) {
if (net::GetValueForKeyInQuery(url, text_type.first, &value)) {
std::vector<std::unique_ptr<Attachment>> attachments;
attachments.push_back(
std::make_unique<TextAttachment>(text_type.second, value));
SetAttachments(std::move(attachments));
break;
return;
}
}
if (net::GetValueForKeyInQuery(url, "file", &value)) {
for (std::string& path : base::SplitString(
value, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
attachments.push_back(
std::make_unique<FileAttachment>(base::FilePath(path)));
}
SetAttachments(std::move(attachments));
}
}
WEB_UI_CONTROLLER_TYPE_IMPL(NearbyShareDialogUI)
......
......@@ -51,9 +51,12 @@ class NearbyShareDialogUI : public ui::MojoWebUIController {
private:
void HandleClose(const base::ListValue* args);
// Search for a query parameter such as text, address, phone, or url, then use
// it to populate a text attachment.if found; otherwise, do nothing.
void SetTextAttachmentFromQueryParameter(const GURL& url);
// Search for a query parameter such as file, text, address, phone, or url,
// then use it to populate an attachment, if found; otherwise, do nothing.
// For text attachments, the parameter value is used as the text body. For
// file attachments, the parameter value is used as a pipe-delimited list
// of file paths.
void SetAttachmentFromQueryParameter(const GURL& url);
std::vector<std::unique_ptr<Attachment>> attachments_;
base::ObserverList<Observer> observers_;
......
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