From 750a9a7af2f609518427bad227d043349df2eb90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?=
 <morten.sorvig@theqtcompany.com>
Date: Fri, 12 Feb 2016 23:56:33 +0100
Subject: [PATCH] qtlaoder.js: Support adding Init() arguments.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is useful for sending arguments to the application
at startup. QtLoader users can now add key/value
pairs to config.environment. QtLoader will forward
these as attributes on the embed element. Finally
the key/value pairs will end up as arguments to
pp::Instance::Init()

Change-Id: Ic7ca434e9c097cd624b25692c250daa46a257c2f
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
---
 src/tools/nacldeployqt/template_qtloader.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/tools/nacldeployqt/template_qtloader.cpp b/src/tools/nacldeployqt/template_qtloader.cpp
index fe4bd98aa57..58a5e4fe77b 100644
--- a/src/tools/nacldeployqt/template_qtloader.cpp
+++ b/src/tools/nacldeployqt/template_qtloader.cpp
@@ -38,16 +38,22 @@ const char *templateQtLoader = R"STRING_DELIMITER(
 //  element.postMessage(message) // ends up in pp::Instance::HandleMessage
 //  element.addEventListener('message', function(message){ ... })
 //
-// Additional supported Qt constructor config keys
-//   query           : Query string. Qt will parse this for environment variables.
+// Additional supported Qt constructor config keys:
+//   query           : Query string. Qt will parse this for pp:Instance::Init() arguments
+//   environment     : JavaScript object with pp::Instance::Init() arguments
 //   isChromeApp     : enable Chrome Application package mode
 //   loadText        : Loading placeholder text
 //
+// The pp:Instance::Init arguments are available in two ways:
+//     1) As argn, argv key/value pairs to Init() of a QPepperInstance subclass.
+//     2) As environment variables: toUpper(key)=value.
+
 function QtLoader(config) {
     var self = this;
     self.config = config;
     self.loadText = config.loadText !== undefined ? config.loadText : "Loading Qt:"
     self.type = config.type !== undefined ? config.type : "%APPTYPE%"
+    self.environment = config.environment;
     self.loadTextElement = undefined;
     self.embed = undefined;
     self.listener = undefined;
@@ -240,6 +246,12 @@ function loadNaCl()
             embed.setAttribute(key, queryHash[key])
     }
 
+    // Propagate extra environment variables from QtLoader config.
+    for (var key in self.environment) {
+        if (key !== undefined)
+            embed.setAttribute(key, self.environment[key])
+    }
+
     self.listener.appendChild(embed);
     self.listener.embed = embed;
 }
-- 
GitLab