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

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

Issue 2703333002: Web Share: Refactor Mojo interface to now return an enum error. (Closed)
Patch Set: Fix assignment statement. #oops Created 3 years, 9 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 193
194 void ShareServiceImpl::OnPickerClosed( 194 void ShareServiceImpl::OnPickerClosed(
195 std::unique_ptr<base::DictionaryValue> share_targets, 195 std::unique_ptr<base::DictionaryValue> share_targets,
196 const std::string& title, 196 const std::string& title,
197 const std::string& text, 197 const std::string& text,
198 const GURL& share_url, 198 const GURL& share_url,
199 const ShareCallback& callback, 199 const ShareCallback& callback,
200 base::Optional<std::string> result) { 200 base::Optional<std::string> result) {
201 if (!result.has_value()) { 201 if (!result.has_value()) {
202 callback.Run(base::Optional<std::string>("Share was cancelled")); 202 callback.Run(blink::mojom::ShareError::CANCELED);
203 return; 203 return;
204 } 204 }
205 205
206 std::string chosen_target = result.value(); 206 std::string chosen_target = result.value();
207 207
208 std::string url_template = GetTargetTemplate(chosen_target, *share_targets); 208 std::string url_template = GetTargetTemplate(chosen_target, *share_targets);
209 std::string url_template_filled; 209 std::string url_template_filled;
210 if (!ReplacePlaceholders(url_template, title, text, share_url, 210 if (!ReplacePlaceholders(url_template, title, text, share_url,
211 &url_template_filled)) { 211 &url_template_filled)) {
212 callback.Run(base::Optional<std::string>( 212 // TODO(mgiuca): This error should not be possible at share time, because
213 "Error: unable to replace placeholders in url template")); 213 // targets with invalid templates should not be chooseable. Fix
214 // https://crbug.com/694380 and replace this with a DCHECK.
215 callback.Run(blink::mojom::ShareError::INTERNAL_ERROR);
214 return; 216 return;
215 } 217 }
216 218
217 // The template is relative to the manifest URL (minus the filename). 219 // The template is relative to the manifest URL (minus the filename).
218 // Concatenate to make an absolute URL. 220 // Concatenate to make an absolute URL.
219 base::StringPiece url_base( 221 base::StringPiece url_base(
220 chosen_target.data(), 222 chosen_target.data(),
221 chosen_target.size() - GURL(chosen_target).ExtractFileName().size()); 223 chosen_target.size() - GURL(chosen_target).ExtractFileName().size());
222 const GURL target(url_base.as_string() + url_template_filled); 224 const GURL target(url_base.as_string() + url_template_filled);
223 // User should not be able to cause an invalid target URL. Possibilities are: 225 // User should not be able to cause an invalid target URL. Possibilities are:
224 // - The base URL: can't be invalid since it's derived from the manifest URL. 226 // - The base URL: can't be invalid since it's derived from the manifest URL.
225 // - The template: can only be invalid if it contains a NUL character or 227 // - The template: can only be invalid if it contains a NUL character or
226 // invalid UTF-8 sequence (which it can't have). 228 // invalid UTF-8 sequence (which it can't have).
227 // - The replaced pieces: these are escaped. 229 // - The replaced pieces: these are escaped.
228 // If somehow we slip through this DCHECK, it will just open about:blank. 230 // If somehow we slip through this DCHECK, it will just open about:blank.
229 DCHECK(target.is_valid()); 231 DCHECK(target.is_valid());
230 OpenTargetURL(target); 232 OpenTargetURL(target);
231 233
232 callback.Run(base::nullopt); 234 callback.Run(blink::mojom::ShareError::OK);
233 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698