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

Unified Diff: components/dom_distiller/core/javascript/dom_distiller_viewer.js

Issue 880983007: Iframe placeholders, security and resizing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fill youtube placehlders Created 5 years, 10 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
« no previous file with comments | « components/dom_distiller/content/dom_distiller_viewer_source.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/dom_distiller/core/javascript/dom_distiller_viewer.js
diff --git a/components/dom_distiller/core/javascript/dom_distiller_viewer.js b/components/dom_distiller/core/javascript/dom_distiller_viewer.js
index 55f53bbf3854feaebdf305bed92df2acce7a9ef2..548222f2913b11d523d991de33875ff8f1da7591 100644
--- a/components/dom_distiller/core/javascript/dom_distiller_viewer.js
+++ b/components/dom_distiller/core/javascript/dom_distiller_viewer.js
@@ -6,6 +6,41 @@ function addToPage(html) {
var div = document.createElement('div');
div.innerHTML = html;
document.getElementById('content').appendChild(div);
+ fillYouTubePlaceholders();
+}
+
+function resizeIframes() {
+ iframeList = document.getElementsByTagName('iframe');
+ for (var i = 0; i < iframeList.length; i++) {
+ var ratio = iframeList[i].clientHeight / iframeList[i].clientWidth;
+ iframeList[i].width = iframeList[i].parentElement.clientWidth;
+ iframeList[i].height = iframeList[i].parentElement.clientWidth * ratio;
+ }
+}
+
+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('src', url);
+ embed.setAttribute('type', 'text/html');
+ embed.setAttribute('frameborder', '0');
+
+ var parent = placeholders[i].parentElement;
+ var width = parent.clientWidth;
+ var hdMult = 1080.0 / 1920.0; // YouTube frame width/height is always HD.
+ embed.setAttribute('width', width);
+ embed.setAttribute('height', width * hdMult);
+
+ parent.replaceChild(embed, placeholders[i]);
+ }
}
function showLoadingIndicator(isLastPage) {
@@ -74,3 +109,16 @@ document.getElementById('showOriginal').addEventListener('click', function(e) {
document.body.appendChild(img);
}, true);
+window.addEventListener('orientationchange', function(e) {
+ // Wait for the page to have actually updated before resizing.
+ setTimeout(resizeIframes, 150);
+});
+
+window.addEventListener('resize', function(e) {
+ setTimeout(resizeIframes, 150);
cjhopman 2015/03/12 02:39:22 How about using an approach like http://flwebsites
mdjones 2015/03/14 02:04:44 Done.
+});
+
+window.addEventListener('load', function(e) {
+ fillYouTubePlaceholders();
+});
+
« no previous file with comments | « components/dom_distiller/content/dom_distiller_viewer_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698