Chromium Code Reviews| Index: chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/display_ad.js |
| diff --git a/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/display_ad.js b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/display_ad.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7800d98cd972e61728dbd62ea6cdd4a409a6fdcd |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/display_ad.js |
| @@ -0,0 +1,86 @@ |
| +(function( window ) { |
|
asargent_no_longer_on_chrome
2013/03/11 19:10:14
nit: Any reason you pass in window as a parameter
rpaquay
2013/03/12 19:56:48
Done.
|
| + "use strict"; |
| + |
| + var document = window.document; |
| + |
| + // Random data |
| + var publisher_data = { |
| + id: "rpaquay_ads", |
| + js: "afma-sdk-i-v6.2.0", |
| + extras: { |
| + color_text: "Red", |
| + color_bg: "Default" |
| + }, |
| + }; |
| + |
| + var timeout_sequence_id = 0; |
|
asargent_no_longer_on_chrome
2013/03/11 19:10:14
style nit: we use variableNamesLikeThis for JS cod
rpaquay
2013/03/12 19:56:48
Done.
|
| + function displayStatus(statusText) { |
| + timeout_sequence_id++; |
| + |
| + var div = document.getElementById("my-status"); |
| + div.textContent = statusText; |
| + |
| + var sequence_id = timeout_sequence_id; |
| + setTimeout(function() { |
| + if (sequence_id === timeout_sequence_id) { |
| + div.textContent = ""; |
| + } |
| + }, 15000); |
| + } |
| + |
| + function adDisplayed(source, appMessage) { |
| + var adview = document.getElementById("my-adview"); |
| + adview.style.height = appMessage.data.ad_size.height; |
| + |
| + displayStatus("Ad displayed( " + appMessage.sequence_number + "): " + |
| + "height=" + appMessage.data.ad_size.height); |
| + } |
| + |
| + function adClicked(source, appMessage) { |
| + displayStatus("Ad clicked(" + appMmessage.sequence_number + "): " + |
| + "publisher id=" + appMessage.publisher_data.id); |
| + } |
| + |
| + function processAppMessage(source, appMessage) { |
| + if (appMessage.message == "ad-displayed") { |
| + adDisplayed(source, appMessage); |
| + } |
| + if (appMessage.message == "ad-clicked") { |
| + adClicked(source, appMessage); |
| + } |
| + } |
| + |
| + // |
| + // Process 'message' event |
| + // |
| + function onPostMessage(event) { |
| + processAppMessage(event.source, event.data); |
| + } |
| + |
| + // |
| + // Process "DOMContentLoader" event. |
| + // |
| + function onDocumentReady() { |
| + var button = document.getElementById('display-ad'); |
| + var adview = document.getElementById("my-adview"); |
| + |
| + // Enable "Display Ad" button when the adview content is loaded |
| + adview.addEventListener('loadcommit', function() { |
| + button.disabled = false; |
| + button.value = "Display Ad"; |
| + button.addEventListener('click', function () { |
| + adview.contentWindow.postMessage({ |
| + 'message': "display-ad", |
| + 'publisher_data': publisher_data |
| + }, "*"); |
| + }, false); |
| + }); |
| + } |
| + |
| + // |
| + // Add global event listeners. |
| + // |
| + window.addEventListener("message", onPostMessage, false); |
| + document.addEventListener('DOMContentLoaded', onDocumentReady, false); |
| + |
| +})(window); |