Commit 750a9a7a authored by Morten Johan Sørvig's avatar Morten Johan Sørvig
Browse files

qtlaoder.js: Support adding Init() arguments.


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: default avatarMorten Johan Sørvig <morten.sorvig@theqtcompany.com>
No related merge requests found
Showing with 14 additions and 2 deletions
...@@ -38,16 +38,22 @@ const char *templateQtLoader = R"STRING_DELIMITER( ...@@ -38,16 +38,22 @@ const char *templateQtLoader = R"STRING_DELIMITER(
// element.postMessage(message) // ends up in pp::Instance::HandleMessage // element.postMessage(message) // ends up in pp::Instance::HandleMessage
// element.addEventListener('message', function(message){ ... }) // element.addEventListener('message', function(message){ ... })
// //
// Additional supported Qt constructor config keys // Additional supported Qt constructor config keys:
// query : Query string. Qt will parse this for environment variables. // 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 // isChromeApp : enable Chrome Application package mode
// loadText : Loading placeholder text // 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) { function QtLoader(config) {
var self = this; var self = this;
self.config = config; self.config = config;
self.loadText = config.loadText !== undefined ? config.loadText : "Loading Qt:" self.loadText = config.loadText !== undefined ? config.loadText : "Loading Qt:"
self.type = config.type !== undefined ? config.type : "%APPTYPE%" self.type = config.type !== undefined ? config.type : "%APPTYPE%"
self.environment = config.environment;
self.loadTextElement = undefined; self.loadTextElement = undefined;
self.embed = undefined; self.embed = undefined;
self.listener = undefined; self.listener = undefined;
...@@ -240,6 +246,12 @@ function loadNaCl() ...@@ -240,6 +246,12 @@ function loadNaCl()
embed.setAttribute(key, queryHash[key]) 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.appendChild(embed);
self.listener.embed = embed; self.listener.embed = embed;
} }
......
Supports Markdown
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