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

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: Enable share button, only if target selected 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<base::string16>& targets,
118 const base::Callback<void(SharePickerResult)>& callback) { 118 const base::Callback<void(base::Optional<base::string16>)>& 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 name with the registered target list.
142 constexpr char kTargetName[] = "Web Share Target Test App"; 142 constexpr char kUrlBase[] = "https://wicg.github.io/web-share-target/demos/";
Matt Giuca 2017/02/01 07:04:33 This makes it ugly: you are no longer displaying t
constantina 2017/02/01 23:24:21 Done.
143 std::vector<base::string16> targets{base::ASCIIToUTF16(kTargetName)}; 143 std::vector<base::string16> targets{base::ASCIIToUTF16(kUrlBase)};
Matt Giuca 2017/02/01 07:04:33 Also I'm confused what the actual URL is that you'
Matt Giuca 2017/02/01 07:25:23 Had an offline chat: the summary is that this will
constantina 2017/02/01 23:24:21 Done.
144 144
145 ShowPickerDialog(targets, base::Bind(&ShareServiceImpl::OnPickerClosed, 145 ShowPickerDialog(targets, base::Bind(&ShareServiceImpl::OnPickerClosed,
146 base::Unretained(this), title, text, 146 base::Unretained(this), title, text,
147 share_url, callback)); 147 share_url, callback));
148 } 148 }
149 149
150 void ShareServiceImpl::OnPickerClosed(const std::string& title, 150 void ShareServiceImpl::OnPickerClosed(const std::string& title,
151 const std::string& text, 151 const std::string& text,
152 const GURL& share_url, 152 const GURL& share_url,
153 const ShareCallback& callback, 153 const ShareCallback& callback,
154 SharePickerResult result) { 154 base::Optional<base::string16> result) {
155 if (result == SharePickerResult::CANCEL) { 155 if (!result.has_value()) {
156 callback.Run(base::Optional<std::string>("Share was cancelled")); 156 callback.Run(base::Optional<std::string>("Share was cancelled"));
157 return; 157 return;
158 } 158 }
159 159
160 // TODO(constantina): replace hard-coded URL with one from user-chosen site.
161 constexpr char kUrlBase[] = "https://wicg.github.io/web-share-target/";
162 constexpr char kUrlTemplate[] = 160 constexpr char kUrlTemplate[] =
163 "demos/sharetarget.html?title={title}&text={text}&url={url}"; 161 "sharetarget.html?title={title}&text={text}&url={url}";
Matt Giuca 2017/02/01 07:04:33 This template part of the URL is still hard-coded
constantina 2017/02/01 23:24:21 Done as per your last comment.
164 162
165 std::string url_template_filled; 163 std::string url_template_filled;
166 if (!ReplacePlaceholders(kUrlTemplate, title, text, share_url, 164 if (!ReplacePlaceholders(kUrlTemplate, title, text, share_url,
167 &url_template_filled)) { 165 &url_template_filled)) {
168 callback.Run(base::Optional<std::string>( 166 callback.Run(base::Optional<std::string>(
169 "Error: unable to replace placeholders in url template")); 167 "Error: unable to replace placeholders in url template"));
170 return; 168 return;
171 } 169 }
172 170
173 GURL target_url(kUrlBase + url_template_filled); 171 std::string url_base = base::UTF16ToASCII(result.value());
Matt Giuca 2017/02/01 07:17:23 UTF16ToUTF8 Otherwise this will fail if it contai
constantina 2017/02/01 23:24:21 Done.
172 GURL target_url(url_base + url_template_filled);
174 if (!target_url.is_valid()) { 173 if (!target_url.is_valid()) {
175 callback.Run(base::Optional<std::string>( 174 callback.Run(base::Optional<std::string>(
176 "Error: url of share target is not a valid url.")); 175 "Error: url of share target is not a valid url."));
177 return; 176 return;
178 } 177 }
179 OpenTargetURL(target_url); 178 OpenTargetURL(target_url);
180 179
181 callback.Run(base::nullopt); 180 callback.Run(base::nullopt);
182 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698