Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: chrome/browser/webshare/share_service_impl.cc

Issue 2667803002: Picker takes a vector of pairs, and passes back the user chosen target. (Closed)
Patch Set: Pass vector of string16 and gurl, and return optional string Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/webshare/share_service_impl.h" 5 #include "chrome/browser/webshare/share_service_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return false; 107 return false;
108 } 108 }
109 split_template.push_back(url_template.substr( 109 split_template.push_back(url_template.substr(
110 start_index_to_copy, url_template.size() - start_index_to_copy)); 110 start_index_to_copy, url_template.size() - start_index_to_copy));
111 111
112 *url_template_filled = JoinString(split_template); 112 *url_template_filled = JoinString(split_template);
113 return true; 113 return true;
114 } 114 }
115 115
116 void ShareServiceImpl::ShowPickerDialog( 116 void ShareServiceImpl::ShowPickerDialog(
117 const std::vector<base::string16>& targets, 117 const std::vector<std::pair<base::string16, GURL>>& targets,
118 const base::Callback<void(SharePickerResult)>& callback) { 118 const base::Callback<void(base::Optional<std::string>)>& callback) {
119 // TODO(mgiuca): Get the browser window as |parent_window|. 119 // TODO(mgiuca): Get the browser window as |parent_window|.
120 #if defined(OS_LINUX) || defined(OS_WIN) 120 #if defined(OS_LINUX) || defined(OS_WIN)
121 chrome::ShowWebShareTargetPickerDialog(nullptr /* parent_window */, targets, 121 chrome::ShowWebShareTargetPickerDialog(nullptr /* parent_window */, targets,
122 callback); 122 callback);
123 #else 123 #else
124 callback.Run(SharePickerResult::CANCEL); 124 callback.Run(base::nullopt);
125 #endif 125 #endif
126 } 126 }
127 127
128 void ShareServiceImpl::OpenTargetURL(const GURL& target_url) { 128 void ShareServiceImpl::OpenTargetURL(const GURL& target_url) {
129 // TODO(constantina): Prevent this code from being run/compiled in android. 129 // TODO(constantina): Prevent this code from being run/compiled in android.
130 #if defined(OS_LINUX) || defined(OS_WIN) 130 #if defined(OS_LINUX) || defined(OS_WIN)
131 Browser* browser = BrowserList::GetInstance()->GetLastActive(); 131 Browser* browser = BrowserList::GetInstance()->GetLastActive();
132 chrome::AddTabAt(browser, target_url, 132 chrome::AddTabAt(browser, target_url,
133 browser->tab_strip_model()->active_index() + 1, true); 133 browser->tab_strip_model()->active_index() + 1, true);
134 #endif 134 #endif
135 } 135 }
136 136
137 void ShareServiceImpl::Share(const std::string& title, 137 void ShareServiceImpl::Share(const std::string& title,
138 const std::string& text, 138 const std::string& text,
139 const GURL& share_url, 139 const GURL& share_url,
140 const ShareCallback& callback) { 140 const ShareCallback& callback) {
141 // TODO(constantina): Replace hard-coded name with the registered target list. 141 // TODO(constantina): Replace hard-coded manifest URL with the list of
Matt Giuca 2017/02/03 01:44:45 name and manifest URL
constantina 2017/02/03 04:32:39 Done.
142 constexpr char kTargetName[] = "Web Share Target Test App"; 142 // registered targets' manifest URLs.
143 std::vector<base::string16> targets{base::ASCIIToUTF16(kTargetName)}; 143 constexpr char kTargetName[] = "Web Share Target Demo App";
Matt Giuca 2017/02/03 01:44:45 s/Demo/Test (no point changing this line from what
constantina 2017/02/03 04:32:39 Done.
144 constexpr char kManifestURL[] =
145 "https://wicg.github.io/web-share-target/demos/manifest.json";
146 // TODO(constantina): Pass vector of pairs of target names and manifest URLs
147 // to picker.
148 std::vector<std::pair<base::string16, GURL>> targets{make_pair(
149 base::ASCIIToUTF16(kTargetName), GURL(kManifestURL))};
144 150
145 ShowPickerDialog(targets, base::Bind(&ShareServiceImpl::OnPickerClosed, 151 ShowPickerDialog(targets, base::Bind(&ShareServiceImpl::OnPickerClosed,
146 base::Unretained(this), title, text, 152 base::Unretained(this), title, text,
147 share_url, callback)); 153 share_url, callback));
148 } 154 }
149 155
150 void ShareServiceImpl::OnPickerClosed(const std::string& title, 156 void ShareServiceImpl::OnPickerClosed(const std::string& title,
151 const std::string& text, 157 const std::string& text,
152 const GURL& share_url, 158 const GURL& share_url,
153 const ShareCallback& callback, 159 const ShareCallback& callback,
154 SharePickerResult result) { 160 base::Optional<std::string> result) {
155 if (result == SharePickerResult::CANCEL) { 161 if (!result.has_value()) {
156 callback.Run(base::Optional<std::string>("Share was cancelled")); 162 callback.Run(base::Optional<std::string>("Share was cancelled"));
157 return; 163 return;
158 } 164 }
159 165
160 // TODO(constantina): replace hard-coded URL with one from user-chosen site. 166 // TODO(constantina): use manifest URL in result to look up corresponding URL
161 constexpr char kUrlBase[] = "https://wicg.github.io/web-share-target/"; 167 // template.
162 constexpr char kUrlTemplate[] = 168 constexpr char kUrlTemplate[] =
163 "demos/sharetarget.html?title={title}&text={text}&url={url}"; 169 "https://wicg.github.io/web-share-target/demos/"
170 "sharetarget.html?title={title}&text={text}&url={url}";
164 171
165 std::string url_template_filled; 172 std::string url_template_filled;
166 if (!ReplacePlaceholders(kUrlTemplate, title, text, share_url, 173 if (!ReplacePlaceholders(kUrlTemplate, title, text, share_url,
167 &url_template_filled)) { 174 &url_template_filled)) {
168 callback.Run(base::Optional<std::string>( 175 callback.Run(base::Optional<std::string>(
169 "Error: unable to replace placeholders in url template")); 176 "Error: unable to replace placeholders in url template"));
170 return; 177 return;
171 } 178 }
172 179
173 GURL target_url(kUrlBase + url_template_filled); 180 GURL target_url(url_template_filled);
174 if (!target_url.is_valid()) { 181 if (!target_url.is_valid()) {
175 callback.Run(base::Optional<std::string>( 182 callback.Run(base::Optional<std::string>(
176 "Error: url of share target is not a valid url.")); 183 "Error: url of share target is not a valid url."));
177 return; 184 return;
178 } 185 }
179 OpenTargetURL(target_url); 186 OpenTargetURL(target_url);
180 187
181 callback.Run(base::nullopt); 188 callback.Run(base::nullopt);
182 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698