Chromium Code Reviews| Index: chrome/common/media_router/media_source_helper.cc |
| diff --git a/chrome/common/media_router/media_source_helper.cc b/chrome/common/media_router/media_source_helper.cc |
| index 944e0b76578312f4ddd66dea57303840831a2835..fd101f2fef0679446b08affcdb6fc712168b3bd4 100644 |
| --- a/chrome/common/media_router/media_source_helper.cc |
| +++ b/chrome/common/media_router/media_source_helper.cc |
| @@ -6,6 +6,8 @@ |
| #include <stdio.h> |
| +#include <algorithm> |
| + |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "chrome/common/media_router/media_source.h" |
| @@ -28,6 +30,17 @@ constexpr char kCastPresentationUrlPath[] = "/cast"; |
| // component extension. |
| constexpr char kAutoJoinPresentationId[] = "auto-join"; |
| +// List of non-http(s) schemes that are allowed in a Presentation URL. |
| +constexpr std::array<const char* const, 4> kAllowedSchemes{ |
|
mark a. foltz
2017/06/06 22:49:08
Is std::array a type alias to POD or does it have
imcheng
2017/06/07 00:53:43
Yep, this is a POD. https://stackoverflow.com/ques
|
| + {"cast", "dial", "remote-playback", "test"}}; |
| + |
| +bool IsUrlAllowed(const GURL& url) { |
|
mark a. foltz
2017/06/06 22:49:08
IsSchemeAllowed?
imcheng
2017/06/07 00:53:43
Done.
|
| + return url.SchemeIsHTTPOrHTTPS() || |
| + std::any_of( |
|
mark a. foltz
2017/06/06 22:49:08
I think a for loop over a kAllowedSchemes array wo
imcheng
2017/06/07 00:53:43
A decent compiler should be able to optimize this.
|
| + kAllowedSchemes.begin(), kAllowedSchemes.end(), |
| + [&url](const char* const scheme) { return url.SchemeIs(scheme); }); |
| +} |
| + |
| } // namespace |
| MediaSource MediaSourceForTab(int tab_id) { |
| @@ -87,7 +100,7 @@ bool IsValidMediaSource(const MediaSource& source) { |
| } |
| bool IsValidPresentationUrl(const GURL& url) { |
| - return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); |
| + return url.is_valid() && IsUrlAllowed(url); |
| } |
| bool IsAutoJoinPresentationId(const std::string& presentation_id) { |