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

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

Issue 2708023002: Web Share (desktop): DCHECK instead of user error for invalid URLs. (Closed)
Patch Set: DCHECK instead of failing. 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
« no previous file with comments | « no previous file | chrome/browser/webshare/share_service_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 "Error: unable to replace placeholders in url template")); 230 "Error: unable to replace placeholders in url template"));
231 return; 231 return;
232 } 232 }
233 233
234 // The template is relative to the manifest URL (minus the filename). 234 // The template is relative to the manifest URL (minus the filename).
235 // Concatenate to make an absolute URL. 235 // Concatenate to make an absolute URL.
236 base::StringPiece url_base( 236 base::StringPiece url_base(
237 chosen_target.data(), 237 chosen_target.data(),
238 chosen_target.size() - GURL(chosen_target).ExtractFileName().size()); 238 chosen_target.size() - GURL(chosen_target).ExtractFileName().size());
239 const GURL target(url_base.as_string() + url_template_filled); 239 const GURL target(url_base.as_string() + url_template_filled);
240 if (!target.is_valid()) { 240 // User should not be able to cause an invalid target URL. Possibilities are:
241 callback.Run(base::Optional<std::string>( 241 // - The base URL: can't be invalid since it's derived from the manifest URL.
242 "Error: url of share target is not a valid url.")); 242 // - The template: can only be invalid if it contains a NUL character or
243 return; 243 // invalid UTF-8 sequence (which it can't have).
244 } 244 // - The replaced pieces: these are escaped.
245 // If somehow we slip through this DCHECK, it will just open about:blank.
246 DCHECK(target.is_valid());
245 OpenTargetURL(target); 247 OpenTargetURL(target);
246 248
247 callback.Run(base::nullopt); 249 callback.Run(base::nullopt);
248 } 250 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/webshare/share_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698