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

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

Issue 2927503002: [Presentation API / Media Router] Relax PresentationRequest URL check. (Closed)
Patch Set: Really add #include 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..6734938b9f9e98798edaaa8b0772ed9b5deb8671 100644
--- a/chrome/common/media_router/media_source_helper.cc
+++ b/chrome/common/media_router/media_source_helper.cc
@@ -6,6 +6,9 @@
#include <stdio.h>
+#include <algorithm>
+#include <array>
+
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/common/media_router/media_source.h"
@@ -28,6 +31,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{
+ {"cast", "dial", "remote-playback", "test"}};
+
+bool IsSchemeAllowed(const GURL& url) {
+ return url.SchemeIsHTTPOrHTTPS() ||
+ std::any_of(
+ kAllowedSchemes.begin(), kAllowedSchemes.end(),
+ [&url](const char* const scheme) { return url.SchemeIs(scheme); });
+}
+
} // namespace
MediaSource MediaSourceForTab(int tab_id) {
@@ -87,7 +101,7 @@ bool IsValidMediaSource(const MediaSource& source) {
}
bool IsValidPresentationUrl(const GURL& url) {
- return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
+ return url.is_valid() && IsSchemeAllowed(url);
}
bool IsAutoJoinPresentationId(const std::string& presentation_id) {

Powered by Google App Engine
This is Rietveld 408576698