diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 8b41a85cf8..23f506a795 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -39,6 +39,7 @@ const char* WebEntityRenderer::URL_PROPERTY = "url"; const char* WebEntityRenderer::SCRIPT_URL_PROPERTY = "scriptURL"; const char* WebEntityRenderer::GLOBAL_POSITION_PROPERTY = "globalPosition"; const char* WebEntityRenderer::USE_BACKGROUND_PROPERTY = "useBackground"; +const char* WebEntityRenderer::USER_AGENT_PROPERTY = "userAgent"; std::function&, bool&)> WebEntityRenderer::_acquireWebSurfaceOperator = nullptr; std::function&, bool&, std::vector&)> WebEntityRenderer::_releaseWebSurfaceOperator = nullptr; @@ -194,6 +195,7 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene _webSurface->getRootItem()->setProperty(URL_PROPERTY, newSourceURL); _webSurface->getRootItem()->setProperty(SCRIPT_URL_PROPERTY, _scriptURL); _webSurface->getRootItem()->setProperty(USE_BACKGROUND_PROPERTY, _useBackground); + _webSurface->getRootItem()->setProperty(USER_AGENT_PROPERTY, _userAgent); _webSurface->getSurfaceContext()->setContextProperty(GLOBAL_POSITION_PROPERTY, vec3toVariant(_contextPosition)); _webSurface->setMaxFps((QUrl(newSourceURL).host().endsWith("youtube.com", Qt::CaseInsensitive)) ? YOUTUBE_MAX_FPS : _maxFPS); ::hifi::scripting::setLocalAccessSafeThread(false); @@ -231,6 +233,14 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene _useBackground = useBackground; } } + + { + auto userAgent = entity->getUserAgent(); + if (_userAgent != userAgent) { + _webSurface->getRootItem()->setProperty(USER_AGENT_PROPERTY, userAgent); + _userAgent = userAgent; + } + } { auto contextPosition = entity->getWorldPosition(); diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.h b/libraries/entities-renderer/src/RenderableWebEntityItem.h index 63ec722811..7288a380d3 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.h +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.h @@ -36,6 +36,7 @@ public: static const char* SCRIPT_URL_PROPERTY; static const char* GLOBAL_POSITION_PROPERTY; static const char* USE_BACKGROUND_PROPERTY; + static const char* USER_AGENT_PROPERTY; static void setAcquireWebSurfaceOperator(std::function&, bool&)> acquireWebSurfaceOperator) { _acquireWebSurfaceOperator = acquireWebSurfaceOperator; } static void acquireWebSurface(const QString& url, bool htmlContent, QSharedPointer& webSurface, bool& cachedWebSurface) { @@ -97,6 +98,7 @@ private: QString _scriptURL; uint8_t _maxFPS; bool _useBackground; + QString _userAgent; WebInputMode _inputMode; glm::vec3 _contextPosition; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index ff55137a03..969be6589e 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -603,6 +603,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_INPUT_MODE, inputMode); CHECK_PROPERTY_CHANGE(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, showKeyboardFocusHighlight); CHECK_PROPERTY_CHANGE(PROP_WEB_USE_BACKGROUND, useBackground); + CHECK_PROPERTY_CHANGE(PROP_USER_AGENT, userAgent); // Polyline CHECK_PROPERTY_CHANGE(PROP_LINE_POINTS, linePoints); @@ -1387,6 +1388,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @property {boolean} useBackground=true - true if the web entity should have a background, * false if the web entity's background should be transparent. The webpage must have CSS properties for transparency set * on the background-color for this property to have an effect. + * @property {string} userAgent="Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36" - The user agent for the web entity to use when visiting web pages. * @example Create a Web entity displaying at 1920 x 1080 resolution. * var METERS_TO_INCHES = 39.3701; * var entity = Entities.addEntity({ @@ -1825,6 +1827,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_INPUT_MODE, inputMode, getInputModeAsString()); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, showKeyboardFocusHighlight); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_WEB_USE_BACKGROUND, useBackground); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_USER_AGENT, userAgent); } // PolyVoxel only @@ -2207,6 +2210,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(inputMode, InputMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(showKeyboardFocusHighlight, bool, setShowKeyboardFocusHighlight); COPY_PROPERTY_FROM_QSCRIPTVALUE(useBackground, bool, setUseBackground); + COPY_PROPERTY_FROM_QSCRIPTVALUE(userAgent, QString, setUserAgent); // Polyline COPY_PROPERTY_FROM_QSCRIPTVALUE(linePoints, qVectorVec3, setLinePoints); @@ -2499,6 +2503,7 @@ void EntityItemProperties::merge(const EntityItemProperties& other) { COPY_PROPERTY_IF_CHANGED(inputMode); COPY_PROPERTY_IF_CHANGED(showKeyboardFocusHighlight); COPY_PROPERTY_IF_CHANGED(useBackground); + COPY_PROPERTY_IF_CHANGED(userAgent); // Polyline COPY_PROPERTY_IF_CHANGED(linePoints); @@ -2899,6 +2904,7 @@ bool EntityItemProperties::getPropertyInfo(const QString& propertyName, EntityPr ADD_PROPERTY_TO_MAP(PROP_INPUT_MODE, InputMode, inputMode, WebInputMode); ADD_PROPERTY_TO_MAP(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, ShowKeyboardFocusHighlight, showKeyboardFocusHighlight, bool); ADD_PROPERTY_TO_MAP(PROP_WEB_USE_BACKGROUND, useBackground, useBackground, bool); + ADD_PROPERTY_TO_MAP(PROP_USER_AGENT, UserAgent, userAgent, QString); // Polyline ADD_PROPERTY_TO_MAP(PROP_LINE_POINTS, LinePoints, linePoints, QVector); @@ -3330,6 +3336,7 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_INPUT_MODE, (uint32_t)properties.getInputMode()); APPEND_ENTITY_PROPERTY(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, properties.getShowKeyboardFocusHighlight()); APPEND_ENTITY_PROPERTY(PROP_WEB_USE_BACKGROUND, properties.getUseBackground()); + APPEND_ENTITY_PROPERTY(PROP_USER_AGENT, properties.getUserAgent()); } if (properties.getType() == EntityTypes::Line) { @@ -3806,6 +3813,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_INPUT_MODE, WebInputMode, setInputMode); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, bool, setShowKeyboardFocusHighlight); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_WEB_USE_BACKGROUND, bool, setUseBackground); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_USER_AGENT, QString, setUserAgent); } if (properties.getType() == EntityTypes::Line) { @@ -4194,6 +4202,7 @@ void EntityItemProperties::markAllChanged() { _inputModeChanged = true; _showKeyboardFocusHighlightChanged = true; _useBackgroundChanged = true; + _userAgentChanged = true; // Polyline _linePointsChanged = true; @@ -4887,6 +4896,9 @@ QList EntityItemProperties::listChangedProperties() { if (useBackgroundChanged()) { out += "useBackground"; } + if (userAgentChanged()) { + out += "userAgent"; + } // Shape if (shapeChanged()) { diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index f7fde73430..df163e2cd6 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -367,6 +367,7 @@ public: DEFINE_PROPERTY_REF_ENUM(PROP_INPUT_MODE, InputMode, inputMode, WebInputMode, WebInputMode::TOUCH); DEFINE_PROPERTY_REF(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, ShowKeyboardFocusHighlight, showKeyboardFocusHighlight, bool, true); DEFINE_PROPERTY_REF(PROP_WEB_USE_BACKGROUND, UseBackground, useBackground, bool, true); + DEFINE_PROPERTY_REF(PROP_USER_AGENT, UserAgent, userAgent, QString, WebEntityItem::DEFAULT_USER_AGENT); // Polyline DEFINE_PROPERTY_REF(PROP_LINE_POINTS, LinePoints, linePoints, QVector, ENTITY_ITEM_DEFAULT_EMPTY_VEC3_QVEC); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 93bb8a89a7..76585450b8 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -319,6 +319,7 @@ enum EntityPropertyList { PROP_INPUT_MODE = PROP_DERIVED_4, PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT = PROP_DERIVED_5, PROP_WEB_USE_BACKGROUND = PROP_DERIVED_6, + PROP_USER_AGENT = PROP_DERIVED_7, // Polyline PROP_LINE_POINTS = PROP_DERIVED_0, diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index 61a1ed18c5..1e3b932b6a 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -25,6 +25,7 @@ #include "EntityTreeElement.h" const QString WebEntityItem::DEFAULT_SOURCE_URL = NetworkingConstants::WEB_ENTITY_DEFAULT_SOURCE_URL; +const QString WebEntityItem::DEFAULT_USER_AGENT = NetworkingConstants::WEB_ENTITY_DEFAULT_USER_AGENT; const uint8_t WebEntityItem::DEFAULT_MAX_FPS = 10; EntityItemPointer WebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { @@ -63,6 +64,7 @@ EntityItemProperties WebEntityItem::getProperties(const EntityPropertyFlags& des COPY_ENTITY_PROPERTY_TO_PROPERTIES(inputMode, getInputMode); COPY_ENTITY_PROPERTY_TO_PROPERTIES(showKeyboardFocusHighlight, getShowKeyboardFocusHighlight); COPY_ENTITY_PROPERTY_TO_PROPERTIES(useBackground, getUseBackground); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(userAgent, getUserAgent); return properties; } @@ -85,6 +87,7 @@ bool WebEntityItem::setSubClassProperties(const EntityItemProperties& properties SET_ENTITY_PROPERTY_FROM_PROPERTIES(inputMode, setInputMode); SET_ENTITY_PROPERTY_FROM_PROPERTIES(showKeyboardFocusHighlight, setShowKeyboardFocusHighlight); SET_ENTITY_PROPERTY_FROM_PROPERTIES(useBackground, setUseBackground); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(userAgent, setUserAgent); return somethingChanged; } @@ -115,6 +118,7 @@ int WebEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, i READ_ENTITY_PROPERTY(PROP_INPUT_MODE, WebInputMode, setInputMode); READ_ENTITY_PROPERTY(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, bool, setShowKeyboardFocusHighlight); READ_ENTITY_PROPERTY(PROP_WEB_USE_BACKGROUND, bool, setUseBackground); + READ_ENTITY_PROPERTY(PROP_USER_AGENT, QString, setUserAgent); return bytesRead; } @@ -133,6 +137,7 @@ EntityPropertyFlags WebEntityItem::getEntityProperties(EncodeBitstreamParams& pa requestedProperties += PROP_INPUT_MODE; requestedProperties += PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT; requestedProperties += PROP_WEB_USE_BACKGROUND; + requestedProperties += PROP_USER_AGENT; return requestedProperties; } @@ -160,6 +165,7 @@ void WebEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst APPEND_ENTITY_PROPERTY(PROP_INPUT_MODE, (uint32_t)getInputMode()); APPEND_ENTITY_PROPERTY(PROP_SHOW_KEYBOARD_FOCUS_HIGHLIGHT, getShowKeyboardFocusHighlight()); APPEND_ENTITY_PROPERTY(PROP_WEB_USE_BACKGROUND, getUseBackground()); + APPEND_ENTITY_PROPERTY(PROP_USER_AGENT, getUserAgent()); } glm::vec3 WebEntityItem::getRaycastDimensions() const { @@ -365,6 +371,17 @@ bool WebEntityItem::getUseBackground() const { return resultWithReadLock([&] { return _useBackground; }); } +void WebEntityItem::setUserAgent(const QString& value) { + withWriteLock([&] { + _needsRenderUpdate |= _userAgent != value; + _userAgent = value; + }); +} + +QString WebEntityItem::getUserAgent() const { + return resultWithReadLock([&] { return _userAgent; }); +} + PulsePropertyGroup WebEntityItem::getPulseProperties() const { return resultWithReadLock([&] { return _pulseProperties; diff --git a/libraries/entities/src/WebEntityItem.h b/libraries/entities/src/WebEntityItem.h index 4b39261bfb..f5cbac43cc 100644 --- a/libraries/entities/src/WebEntityItem.h +++ b/libraries/entities/src/WebEntityItem.h @@ -89,6 +89,10 @@ public: bool getUseBackground() const; void setUseBackground(bool value); + + static const QString DEFAULT_USER_AGENT; + QString getUserAgent() const; + void setUserAgent(const QString& value); PulsePropertyGroup getPulseProperties() const; @@ -105,6 +109,7 @@ protected: WebInputMode _inputMode; bool _showKeyboardFocusHighlight; bool _useBackground; + QString _userAgent; bool _localSafeContext { false }; }; diff --git a/libraries/networking/src/NetworkingConstants.h b/libraries/networking/src/NetworkingConstants.h index b64a0845ac..a3818930dd 100644 --- a/libraries/networking/src/NetworkingConstants.h +++ b/libraries/networking/src/NetworkingConstants.h @@ -46,6 +46,7 @@ namespace NetworkingConstants { // WebEntity Defaults const QString WEB_ENTITY_DEFAULT_SOURCE_URL = "https://vircadia.com/"; + const QString WEB_ENTITY_DEFAULT_USER_AGENT = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"; const QString DEFAULT_AVATAR_COLLISION_SOUND_URL = "https://hifi-public.s3.amazonaws.com/sounds/Collisions-otherorganic/Body_Hits_Impact.wav"; diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index fc74f4459c..ced3d8756b 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -283,6 +283,7 @@ enum class EntityVersion : PacketVersion { ZoneOcclusion, ModelBlendshapes, TransparentWeb, + UserAgent, // Add new versions above here NUM_PACKET_TYPE, diff --git a/scripts/system/create/assets/data/createAppTooltips.json b/scripts/system/create/assets/data/createAppTooltips.json index 478793ab78..f898d594c6 100644 --- a/scripts/system/create/assets/data/createAppTooltips.json +++ b/scripts/system/create/assets/data/createAppTooltips.json @@ -616,6 +616,9 @@ "scriptURL": { "tooltip": "The URL of a script to inject into the web page." }, + "userAgent": { + "tooltip": "The user agent that the web entity will use when visiting web pages." + }, "alignToGrid": { "tooltip": "Used to align entities to the grid, or floor of the environment.", "skipJSProperty": true diff --git a/scripts/system/create/entityProperties/html/js/entityProperties.js b/scripts/system/create/entityProperties/html/js/entityProperties.js index f3f92a887e..6898bb1b5c 100644 --- a/scripts/system/create/entityProperties/html/js/entityProperties.js +++ b/scripts/system/create/entityProperties/html/js/entityProperties.js @@ -800,6 +800,12 @@ const GROUPS = [ type: "string", propertyID: "scriptURL", placeholder: "URL", + }, + { + label: "User Agent", + type: "string", + propertyID: "userAgent", + placeholder: "User Agent", } ] },