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

Unified Diff: chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/display_ad.js

Issue 12463015: Enable <adview> tag for packaged apps. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Rebasing Created 7 years, 9 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/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);

Powered by Google App Engine
This is Rietveld 408576698