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

Unified Diff: chrome/common/media_router/media_source_helper.cc

Issue 2927503002: [Presentation API / Media Router] Relax PresentationRequest URL check. (Closed)
Patch Set: updated scheme check in mr + tests Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698