mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 05:29:34 +02:00
Add script injection to Web 3D overlay
This commit is contained in:
parent
b723f3d92e
commit
a8a04cfbba
5 changed files with 50 additions and 7 deletions
|
@ -6,6 +6,7 @@ import HFWebEngineProfile 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property alias url: root.url
|
property alias url: root.url
|
||||||
|
property alias scriptURL: root.userScriptUrl
|
||||||
property alias eventBridge: eventBridgeWrapper.eventBridge
|
property alias eventBridge: eventBridgeWrapper.eventBridge
|
||||||
property bool keyboardEnabled: true // FIXME - Keyboard HMD only: Default to false
|
property bool keyboardEnabled: true // FIXME - Keyboard HMD only: Default to false
|
||||||
property bool keyboardRaised: false
|
property bool keyboardRaised: false
|
||||||
|
@ -38,6 +39,8 @@ Item {
|
||||||
storageName: "qmlWebEngine"
|
storageName: "qmlWebEngine"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property string userScriptUrl: ""
|
||||||
|
|
||||||
// creates a global EventBridge object.
|
// creates a global EventBridge object.
|
||||||
WebEngineScript {
|
WebEngineScript {
|
||||||
id: createGlobalEventBridge
|
id: createGlobalEventBridge
|
||||||
|
@ -54,7 +57,15 @@ Item {
|
||||||
worldId: WebEngineScript.MainWorld
|
worldId: WebEngineScript.MainWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard ]
|
// User script.
|
||||||
|
WebEngineScript {
|
||||||
|
id: userScript
|
||||||
|
sourceUrl: root.userScriptUrl
|
||||||
|
injectionPoint: WebEngineScript.DocumentReady // DOM ready but page load may not be finished.
|
||||||
|
worldId: WebEngineScript.MainWorld
|
||||||
|
}
|
||||||
|
|
||||||
|
userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ]
|
||||||
|
|
||||||
property string newUrl: ""
|
property string newUrl: ""
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ Web3DOverlay::Web3DOverlay() : _dpi(DPI) {
|
||||||
Web3DOverlay::Web3DOverlay(const Web3DOverlay* Web3DOverlay) :
|
Web3DOverlay::Web3DOverlay(const Web3DOverlay* Web3DOverlay) :
|
||||||
Billboard3DOverlay(Web3DOverlay),
|
Billboard3DOverlay(Web3DOverlay),
|
||||||
_url(Web3DOverlay->_url),
|
_url(Web3DOverlay->_url),
|
||||||
|
_scriptURL(Web3DOverlay->_scriptURL),
|
||||||
_dpi(Web3DOverlay->_dpi),
|
_dpi(Web3DOverlay->_dpi),
|
||||||
_resolution(Web3DOverlay->_resolution)
|
_resolution(Web3DOverlay->_resolution)
|
||||||
{
|
{
|
||||||
|
@ -112,6 +113,7 @@ void Web3DOverlay::render(RenderArgs* args) {
|
||||||
_webSurface->load("WebView.qml");
|
_webSurface->load("WebView.qml");
|
||||||
_webSurface->resume();
|
_webSurface->resume();
|
||||||
_webSurface->getRootItem()->setProperty("url", _url);
|
_webSurface->getRootItem()->setProperty("url", _url);
|
||||||
|
_webSurface->getRootItem()->setProperty("scriptURL", _scriptURL);
|
||||||
_webSurface->resize(QSize(_resolution.x, _resolution.y));
|
_webSurface->resize(QSize(_resolution.x, _resolution.y));
|
||||||
currentContext->makeCurrent(currentSurface);
|
currentContext->makeCurrent(currentSurface);
|
||||||
|
|
||||||
|
@ -273,6 +275,14 @@ void Web3DOverlay::setProperties(const QVariantMap& properties) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto scriptURLValue = properties["scriptURL"];
|
||||||
|
if (scriptURLValue.isValid()) {
|
||||||
|
QString newScriptURL = scriptURLValue.toString();
|
||||||
|
if (newScriptURL != _scriptURL) {
|
||||||
|
setScriptURL(newScriptURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto resolution = properties["resolution"];
|
auto resolution = properties["resolution"];
|
||||||
if (resolution.isValid()) {
|
if (resolution.isValid()) {
|
||||||
bool valid;
|
bool valid;
|
||||||
|
@ -282,7 +292,6 @@ void Web3DOverlay::setProperties(const QVariantMap& properties) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto dpi = properties["dpi"];
|
auto dpi = properties["dpi"];
|
||||||
if (dpi.isValid()) {
|
if (dpi.isValid()) {
|
||||||
_dpi = dpi.toFloat();
|
_dpi = dpi.toFloat();
|
||||||
|
@ -293,6 +302,9 @@ QVariant Web3DOverlay::getProperty(const QString& property) {
|
||||||
if (property == "url") {
|
if (property == "url") {
|
||||||
return _url;
|
return _url;
|
||||||
}
|
}
|
||||||
|
if (property == "scriptURL") {
|
||||||
|
return _scriptURL;
|
||||||
|
}
|
||||||
if (property == "dpi") {
|
if (property == "dpi") {
|
||||||
return _dpi;
|
return _dpi;
|
||||||
}
|
}
|
||||||
|
@ -308,6 +320,15 @@ void Web3DOverlay::setURL(const QString& url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Web3DOverlay::setScriptURL(const QString& scriptURL) {
|
||||||
|
_scriptURL = scriptURL;
|
||||||
|
if (_webSurface) {
|
||||||
|
AbstractViewStateInterface::instance()->postLambdaEvent([this, scriptURL] {
|
||||||
|
_webSurface->getRootItem()->setProperty("scriptURL", scriptURL);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec2 Web3DOverlay::getSize() {
|
glm::vec2 Web3DOverlay::getSize() {
|
||||||
return _resolution / _dpi * INCHES_TO_METERS * getDimensions();
|
return _resolution / _dpi * INCHES_TO_METERS * getDimensions();
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
void setURL(const QString& url);
|
void setURL(const QString& url);
|
||||||
|
void setScriptURL(const QString& script);
|
||||||
|
|
||||||
void setProperties(const QVariantMap& properties) override;
|
void setProperties(const QVariantMap& properties) override;
|
||||||
QVariant getProperty(const QString& property) override;
|
QVariant getProperty(const QString& property) override;
|
||||||
|
@ -55,6 +56,7 @@ private:
|
||||||
QMetaObject::Connection _connection;
|
QMetaObject::Connection _connection;
|
||||||
gpu::TexturePointer _texture;
|
gpu::TexturePointer _texture;
|
||||||
QString _url;
|
QString _url;
|
||||||
|
QString _scriptURL;
|
||||||
float _dpi;
|
float _dpi;
|
||||||
vec2 _resolution{ 640, 480 };
|
vec2 _resolution{ 640, 480 };
|
||||||
int _geometryId { 0 };
|
int _geometryId { 0 };
|
||||||
|
|
|
@ -85,15 +85,19 @@ WebTablet = function (url, width, dpi, clientOnly) {
|
||||||
this.state = "idle";
|
this.state = "idle";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WebTablet.prototype.setScriptURL = function (scriptURL) {
|
||||||
|
Overlays.editOverlay(this.webOverlayID, { scriptURL: scriptURL });
|
||||||
|
};
|
||||||
|
|
||||||
WebTablet.prototype.destroy = function () {
|
WebTablet.prototype.destroy = function () {
|
||||||
Overlays.deleteOverlay(this.webOverlayID);
|
Overlays.deleteOverlay(this.webOverlayID);
|
||||||
Entities.deleteEntity(this.tabletEntityID);
|
Entities.deleteEntity(this.tabletEntityID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
WebTablet.prototype.pickle = function () {
|
WebTablet.prototype.pickle = function () {
|
||||||
return JSON.stringify({ webOverlayID: this.webOverlayID, tabletEntityID: this.tabletEntityID });
|
return JSON.stringify({ webOverlayID: this.webOverlayID, tabletEntityID: this.tabletEntityID });
|
||||||
};
|
};
|
||||||
|
|
||||||
WebTablet.unpickle = function (string) {
|
WebTablet.unpickle = function (string) {
|
||||||
if (!string) {
|
if (!string) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -16,6 +16,10 @@ Script.include("../libraries/WebTablet.js");
|
||||||
var toolIconUrl = Script.resolvePath("../assets/images/tools/");
|
var toolIconUrl = Script.resolvePath("../assets/images/tools/");
|
||||||
|
|
||||||
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
|
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
|
||||||
|
var MARKETPLACES_DIRECTORY_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesDirectory.js");
|
||||||
|
var MARKETPLACES_HFIF_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesHiFi.js");
|
||||||
|
var MARKETPLACES_CLARA_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesClara.js");
|
||||||
|
|
||||||
var marketplaceWindow = new OverlayWebWindow({
|
var marketplaceWindow = new OverlayWebWindow({
|
||||||
title: "Marketplace",
|
title: "Marketplace",
|
||||||
source: "about:blank",
|
source: "about:blank",
|
||||||
|
@ -23,17 +27,17 @@ var marketplaceWindow = new OverlayWebWindow({
|
||||||
height: 700,
|
height: 700,
|
||||||
visible: false
|
visible: false
|
||||||
});
|
});
|
||||||
marketplaceWindow.setScriptURL(Script.resolvePath("../html/js/marketplacesDirectory.js"));
|
marketplaceWindow.setScriptURL(MARKETPLACES_DIRECTORY_SCRIPT_URL);
|
||||||
|
|
||||||
marketplaceWindow.webEventReceived.connect(function (data) {
|
marketplaceWindow.webEventReceived.connect(function (data) {
|
||||||
if (data === "INJECT_CLARA") {
|
if (data === "INJECT_CLARA") {
|
||||||
marketplaceWindow.setScriptURL(Script.resolvePath("../html/js/marketplacesClara.js"));
|
marketplaceWindow.setScriptURL(MARKETPLACES_CLARA_SCRIPT_URL);
|
||||||
}
|
}
|
||||||
if (data === "INJECT_HIFI") {
|
if (data === "INJECT_HIFI") {
|
||||||
marketplaceWindow.setScriptURL(Script.resolvePath("../html/js/marketplacesHiFi.js"));
|
marketplaceWindow.setScriptURL(MARKETPLACES_HFIF_SCRIPT_URL);
|
||||||
}
|
}
|
||||||
if (data === "RELOAD_DIRECTORY") {
|
if (data === "RELOAD_DIRECTORY") {
|
||||||
marketplaceWindow.setScriptURL(Script.resolvePath("../html/js/marketplacesDirectory.js"));
|
marketplaceWindow.setScriptURL(MARKETPLACES_DIRECTORY_SCRIPT_URL);
|
||||||
marketplaceWindow.setURL(MARKETPLACES_URL);
|
marketplaceWindow.setURL(MARKETPLACES_URL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -60,6 +64,7 @@ function showMarketplace(marketplaceID) {
|
||||||
updateButtonState(true);
|
updateButtonState(true);
|
||||||
marketplaceWebTablet = new WebTablet(MARKETPLACES_URL, null, null, true);
|
marketplaceWebTablet = new WebTablet(MARKETPLACES_URL, null, null, true);
|
||||||
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
|
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
|
||||||
|
marketplaceWebTablet.setScriptURL(MARKETPLACES_DIRECTORY_SCRIPT_URL);
|
||||||
} else {
|
} else {
|
||||||
var url = MARKETPLACES_URL;
|
var url = MARKETPLACES_URL;
|
||||||
if (marketplaceID) {
|
if (marketplaceID) {
|
||||||
|
|
Loading…
Reference in a new issue