| OLD | NEW |
| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 | 210 |
| 211 void ShareServiceImpl::OnPickerClosed( | 211 void ShareServiceImpl::OnPickerClosed( |
| 212 std::unique_ptr<base::DictionaryValue> share_targets, | 212 std::unique_ptr<base::DictionaryValue> share_targets, |
| 213 const std::string& title, | 213 const std::string& title, |
| 214 const std::string& text, | 214 const std::string& text, |
| 215 const GURL& share_url, | 215 const GURL& share_url, |
| 216 const ShareCallback& callback, | 216 const ShareCallback& callback, |
| 217 base::Optional<std::string> result) { | 217 base::Optional<std::string> result) { |
| 218 if (!result.has_value()) { | 218 if (!result.has_value()) { |
| 219 callback.Run(base::Optional<std::string>("Share was cancelled")); | 219 callback.Run(blink::mojom::ShareError::CANCELED); |
| 220 return; | 220 return; |
| 221 } | 221 } |
| 222 | 222 |
| 223 std::string chosen_target = result.value(); | 223 std::string chosen_target = result.value(); |
| 224 | 224 |
| 225 std::string url_template = GetTargetTemplate(chosen_target, *share_targets); | 225 std::string url_template = GetTargetTemplate(chosen_target, *share_targets); |
| 226 std::string url_template_filled; | 226 std::string url_template_filled; |
| 227 if (!ReplacePlaceholders(url_template, title, text, share_url, | 227 if (!ReplacePlaceholders(url_template, title, text, share_url, |
| 228 &url_template_filled)) { | 228 &url_template_filled)) { |
| 229 callback.Run(base::Optional<std::string>( | 229 callback.Run(blink::mojom::ShareError::INVALID_TEMPLATE); |
| 230 "Error: unable to replace placeholders in url template")); | |
| 231 return; | 230 return; |
| 232 } | 231 } |
| 233 | 232 |
| 234 // The template is relative to the manifest URL (minus the filename). | 233 // The template is relative to the manifest URL (minus the filename). |
| 235 // Concatenate to make an absolute URL. | 234 // Concatenate to make an absolute URL. |
| 236 base::StringPiece url_base( | 235 base::StringPiece url_base( |
| 237 chosen_target.data(), | 236 chosen_target.data(), |
| 238 chosen_target.size() - GURL(chosen_target).ExtractFileName().size()); | 237 chosen_target.size() - GURL(chosen_target).ExtractFileName().size()); |
| 239 const GURL target(url_base.as_string() + url_template_filled); | 238 const GURL target(url_base.as_string() + url_template_filled); |
| 240 // User should not be able to cause an invalid target URL. Possibilities are: | 239 // User should not be able to cause an invalid target URL. Possibilities are: |
| 241 // - The base URL: can't be invalid since it's derived from the manifest URL. | 240 // - The base URL: can't be invalid since it's derived from the manifest URL. |
| 242 // - The template: can only be invalid if it contains a NUL character or | 241 // - The template: can only be invalid if it contains a NUL character or |
| 243 // invalid UTF-8 sequence (which it can't have). | 242 // invalid UTF-8 sequence (which it can't have). |
| 244 // - The replaced pieces: these are escaped. | 243 // - The replaced pieces: these are escaped. |
| 245 // If somehow we slip through this DCHECK, it will just open about:blank. | 244 // If somehow we slip through this DCHECK, it will just open about:blank. |
| 246 DCHECK(target.is_valid()); | 245 DCHECK(target.is_valid()); |
| 247 OpenTargetURL(target); | 246 OpenTargetURL(target); |
| 248 | 247 |
| 249 callback.Run(base::nullopt); | 248 callback.Run(blink::mojom::ShareError::OK); |
| 250 } | 249 } |
| OLD | NEW |