зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1258053 - Convert YouTube Flash embed URLs that contain params in the path components. r=kmachulis
--HG-- rename : dom/base/test/test_bug1240471.html => dom/base/test/test_youtube_flash_embed.html
This commit is contained in:
Родитель
bdcdded91f
Коммит
a396185694
|
@ -1531,25 +1531,19 @@ nsObjectLoadingContent::MaybeRewriteYoutubeEmbed(nsIURI* aURI, nsIURI* aBaseURI,
|
|||
return;
|
||||
}
|
||||
|
||||
// Some youtube urls have invalid query strings attached, e.g.
|
||||
// Some YouTube urls have parameters in path components, e.g.
|
||||
// http://youtube.com/embed/7LcUOEP7Brc&start=35. These URLs work with flash,
|
||||
// but break iframe/object embedding. If this situation occurs with rewritten
|
||||
// URLs, and the user has flash installed, just use flash. If the user does
|
||||
// not have flash installed or activated, chop off the query in order to make
|
||||
// the video load correctly as an iframe. In either case, warn about it in the
|
||||
// URLs, convert the parameters to query in order to make the video load
|
||||
// correctly as an iframe. In either case, warn about it in the
|
||||
// developer console.
|
||||
int32_t ampIndex = uri.FindChar('&', 0);
|
||||
bool trimQuery = false;
|
||||
bool replaceQuery = false;
|
||||
if (ampIndex != -1) {
|
||||
int32_t qmIndex = uri.FindChar('?', 0);
|
||||
if (qmIndex == -1 ||
|
||||
qmIndex > ampIndex) {
|
||||
if (!nsContentUtils::IsSWFPlayerEnabled()) {
|
||||
trimQuery = true;
|
||||
} else {
|
||||
// Flash is enabled, just use it in this case.
|
||||
return;
|
||||
}
|
||||
replaceQuery = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1563,10 +1557,13 @@ nsObjectLoadingContent::MaybeRewriteYoutubeEmbed(nsIURI* aURI, nsIURI* aBaseURI,
|
|||
}
|
||||
|
||||
nsAutoString utf16OldURI = NS_ConvertUTF8toUTF16(uri);
|
||||
// If we need to trim the query off the URL, it means it's malformed, and an
|
||||
// ampersand comes first. Use the index we found earlier.
|
||||
if (trimQuery) {
|
||||
uri.Truncate(ampIndex);
|
||||
// If we need to convert the URL, it means an ampersand comes first.
|
||||
// Use the index we found earlier.
|
||||
if (replaceQuery) {
|
||||
// Replace question marks with ampersands.
|
||||
uri.ReplaceChar('?', '&');
|
||||
// Replace the first ampersand with a question mark.
|
||||
uri.SetCharAt('?', ampIndex);
|
||||
}
|
||||
// Switch out video access url formats, which should possibly allow HTML5
|
||||
// video loading.
|
||||
|
@ -1584,7 +1581,7 @@ nsObjectLoadingContent::MaybeRewriteYoutubeEmbed(nsIURI* aURI, nsIURI* aBaseURI,
|
|||
const char* msgName;
|
||||
// If there's no query to rewrite, just notify in the developer console
|
||||
// that we're changing the embed.
|
||||
if (!trimQuery) {
|
||||
if (!replaceQuery) {
|
||||
msgName = "RewriteYoutubeEmbed";
|
||||
} else {
|
||||
msgName = "RewriteYoutubeEmbedInvalidQuery";
|
||||
|
|
|
@ -661,7 +661,6 @@ skip-if = buildapp == 'b2g'
|
|||
[test_bug1187157.html]
|
||||
[test_bug1198095.html]
|
||||
[test_bug1238440.html]
|
||||
[test_bug1240471.html]
|
||||
[test_bug1250148.html]
|
||||
[test_bug1259588.html]
|
||||
[test_bug1263696.html]
|
||||
|
@ -830,6 +829,7 @@ skip-if = toolkit == 'android'
|
|||
[test_textnode_split_in_selection.html]
|
||||
[test_title.html]
|
||||
[test_treewalker_nextsibling.xml]
|
||||
[test_unknown_url_origin.html]
|
||||
[test_url.html]
|
||||
[test_url_data.html]
|
||||
[test_url_empty_port.html]
|
||||
|
@ -906,4 +906,5 @@ support-files = test_XHR_timeout.js
|
|||
[test_XHRDocURI.html]
|
||||
[test_XHRResponseURL.html]
|
||||
[test_XHRSendData.html]
|
||||
[test_unknown_url_origin.html]
|
||||
[test_youtube_flash_embed.html]
|
||||
# Please keep alphabetical order.
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
SimpleTest.waitForExplicitFinish();
|
||||
"use strict";
|
||||
function onLoad () {
|
||||
let youtube_changed_url_noquery = "https://mochitest.youtube.com/embed/Xm5i5kbIXzc";
|
||||
let youtube_changed_url_query = "https://mochitest.youtube.com/embed/Xm5i5kbIXzc?start=10&end=20";
|
||||
|
||||
function testEmbed(embed, expected_url) {
|
||||
|
@ -22,8 +21,8 @@
|
|||
}
|
||||
info("Running youtube rewrite query test");
|
||||
testEmbed(document.getElementById("testembed-correct"), youtube_changed_url_query);
|
||||
testEmbed(document.getElementById("testembed-wrong"), youtube_changed_url_noquery);
|
||||
testEmbed(document.getElementById("testembed-whywouldyouevendothat"), youtube_changed_url_noquery);
|
||||
testEmbed(document.getElementById("testembed-wrong"), youtube_changed_url_query);
|
||||
testEmbed(document.getElementById("testembed-whywouldyouevendothat"), youtube_changed_url_query);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
</script>
|
Загрузка…
Ссылка в новой задаче