Commit d5d75e70 authored by mdjones's avatar mdjones Committed by Commit bot

Iframe placeholders, security and resizing

This change adds javascript to fill in the YouTube placeholders
created by the distiller. the content security policy now allows
for iframes from all sources (distiller closely controls which
iframes are allowed). Some css has also been added to appropriately
resize these iframes when the page is resized.

This change will not work correctly by itself, it depends on the
following CL to work correctly:

https://codereview.chromium.org/1015463004

BUG=468862

Review URL: https://codereview.chromium.org/880983007

Cr-Commit-Position: refs/heads/master@{#323934}
parent 7faf645e
...@@ -375,4 +375,8 @@ std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc() ...@@ -375,4 +375,8 @@ std::string DomDistillerViewerSource::GetContentSecurityPolicyObjectSrc()
return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;"; return "object-src 'none'; style-src 'self' https://fonts.googleapis.com;";
} }
std::string DomDistillerViewerSource::GetContentSecurityPolicyFrameSrc() const {
return "frame-src *;";
}
} // namespace dom_distiller } // namespace dom_distiller
...@@ -39,6 +39,7 @@ class DomDistillerViewerSource : public content::URLDataSource { ...@@ -39,6 +39,7 @@ class DomDistillerViewerSource : public content::URLDataSource {
void WillServiceRequest(const net::URLRequest* request, void WillServiceRequest(const net::URLRequest* request,
std::string* path) const override; std::string* path) const override;
std::string GetContentSecurityPolicyObjectSrc() const override; std::string GetContentSecurityPolicyObjectSrc() const override;
std::string GetContentSecurityPolicyFrameSrc() const override;
private: private:
friend class DomDistillerViewerSourceTest; friend class DomDistillerViewerSourceTest;
......
...@@ -345,6 +345,23 @@ pre { ...@@ -345,6 +345,23 @@ pre {
} }
} }
/* Iframe sizing. */
.youtubeContainer {
height: 0px;
/* This is the perecnt height of a standard HD video. */
padding-bottom: 56.25%;
position: relative;
width: 100%;
}
.youtubeIframe {
height: 100%;
left: 0px;
position: absolute;
top: 0px;
width: 100%;
}
/* Loading Indicator. */ /* Loading Indicator. */
#loader { #loader {
height: 22px; height: 22px;
......
...@@ -6,6 +6,32 @@ function addToPage(html) { ...@@ -6,6 +6,32 @@ function addToPage(html) {
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = html; div.innerHTML = html;
document.getElementById('content').appendChild(div); document.getElementById('content').appendChild(div);
fillYouTubePlaceholders();
}
function fillYouTubePlaceholders() {
var placeholders = document.getElementsByClassName('embed-placeholder');
for (var i = 0; i < placeholders.length; i++) {
if (!placeholders[i].hasAttribute('data-type') ||
placeholders[i].getAttribute('data-type') != 'youtube' ||
!placeholders[i].hasAttribute('data-id')) {
continue;
}
var embed = document.createElement('iframe');
var url = 'http://www.youtube.com/embed/' +
placeholders[i].getAttribute('data-id');
embed.setAttribute('class', 'youtubeIframe');
embed.setAttribute('src', url);
embed.setAttribute('type', 'text/html');
embed.setAttribute('frameborder', '0');
var parent = placeholders[i].parentElement;
var container = document.createElement('div');
container.setAttribute('class', 'youtubeContainer');
container.appendChild(embed);
parent.replaceChild(container, placeholders[i]);
}
} }
function showLoadingIndicator(isLastPage) { function showLoadingIndicator(isLastPage) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment