diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-11-14 17:23:00 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-11-23 11:18:08 +0000 |
commit | 56a9594649872f4076b6891f917138d2b1e8d028 (patch) | |
tree | 2d14083e97fae7de29162e6002d6a7f2da08ffd3 /extensions/source | |
parent | 91cbbb7797f048834b51690e9fab60aa778b1e44 (diff) |
Update-check, expand to allow reporting of H/W and OS versions.
Off by default.
Expand config options to show the user agent used.
Re-use this to show more useful info in Help->About too.
Change-Id: I1044116ef9beeb341a537c0f4451dca54e198f67
Reviewed-on: https://gerrit.libreoffice.org/20098
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'extensions/source')
-rw-r--r-- | extensions/source/update/check/org/openoffice/Office/Jobs.xcu | 3 | ||||
-rw-r--r-- | extensions/source/update/feed/updatefeed.cxx | 111 |
2 files changed, 87 insertions, 27 deletions
diff --git a/extensions/source/update/check/org/openoffice/Office/Jobs.xcu b/extensions/source/update/check/org/openoffice/Office/Jobs.xcu index f11c14e9f74e..58db4048099e 100644 --- a/extensions/source/update/check/org/openoffice/Office/Jobs.xcu +++ b/extensions/source/update/check/org/openoffice/Office/Jobs.xcu @@ -49,6 +49,9 @@ <prop oor:name="DownloadPaused" oor:type="xs:boolean" oor:op="replace"> <value>false</value> </prop> + <prop oor:name="ExtendedUserAgent" oor:type="xs:boolean" oor:op="replace"> + <value>false</value> + </prop> </node> </node> </node> diff --git a/extensions/source/update/feed/updatefeed.cxx b/extensions/source/update/feed/updatefeed.cxx index 8bb92778e288..12ee3a824249 100644 --- a/extensions/source/update/feed/updatefeed.cxx +++ b/extensions/source/update/feed/updatefeed.cxx @@ -46,6 +46,8 @@ #include <com/sun/star/task/PasswordContainerInteractionHandler.hpp> #include <com/sun/star/xml/dom/DocumentBuilder.hpp> #include <com/sun/star/xml/xpath/XPathAPI.hpp> +#include <com/sun/star/awt/Toolkit.hpp> +#include <com/sun/star/awt/XToolkitExperimental.hpp> #include <rtl/ref.hxx> #include <rtl/bootstrap.hxx> @@ -136,6 +138,8 @@ class UpdateInformationProvider : ucb::XWebDAVCommandEnvironment, lang::XServiceInfo > { + OUString getUserAgent(bool bExtended); + bool isUserAgentExtended(); public: static uno::Reference< uno::XInterface > createInstance(const uno::Reference<uno::XComponentContext>& xContext); @@ -176,7 +180,7 @@ public: // XWebDAVCommandEnvironment virtual uno::Sequence< beans::StringPair > SAL_CALL getUserRequestHeaders( const OUString&, ucb::WebDAVHTTPMethod ) - throw ( uno::RuntimeException, std::exception ) override { return m_aRequestHeaderList; }; + throw ( uno::RuntimeException, std::exception ) override; // XServiceInfo virtual OUString SAL_CALL getImplementationName() @@ -190,6 +194,7 @@ protected: virtual ~UpdateInformationProvider(); static OUString getConfigurationItem(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, OUString const & node, OUString const & item); + static uno::Any getConfigurationItemAny(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, OUString const & node, OUString const & item); private: uno::Reference< io::XInputStream > load(const OUString& rURL); @@ -312,9 +317,6 @@ private: deployment::UpdateInformationEntry m_aEntry; }; - - - UpdateInformationProvider::UpdateInformationProvider( const uno::Reference<uno::XComponentContext>& xContext, const uno::Reference< ucb::XUniversalContentBroker >& xUniversalContentBroker, @@ -324,11 +326,35 @@ UpdateInformationProvider::UpdateInformationProvider( , m_xUniversalContentBroker(xUniversalContentBroker) , m_xDocumentBuilder(xDocumentBuilder) , m_xXPathAPI(xXPathAPI) - , m_aRequestHeaderList(1) + , m_aRequestHeaderList(2) , m_nCommandId(0) { uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider( - css::configuration::theDefaultProvider::get(xContext)); + css::configuration::theDefaultProvider::get(m_xContext)); + + m_aRequestHeaderList[0].First = "Accept-Language"; + m_aRequestHeaderList[0].Second = getConfigurationItem( xConfigurationProvider, "org.openoffice.Setup/L10N", "ooLocale" ); +} + +bool +UpdateInformationProvider::isUserAgentExtended() +{ + uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider( + css::configuration::theDefaultProvider::get(m_xContext)); + + uno::Any aExtended = getConfigurationItemAny( + xConfigurationProvider, + "org.openoffice.Office.Jobs/Jobs/UpdateCheck/Arguments", + "ExtendedUserAgent"); + bool bExtendedUserAgent = false; + aExtended >>= bExtendedUserAgent; + return bExtendedUserAgent; +} + +OUString UpdateInformationProvider::getUserAgent(bool bExtended) +{ + uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider( + css::configuration::theDefaultProvider::get(m_xContext)); OUStringBuffer buf; buf.append( @@ -342,30 +368,63 @@ UpdateInformationProvider::UpdateInformationProvider( xConfigurationProvider, "org.openoffice.Setup/Product", "ooSetupVersion")); + OUString extension( getConfigurationItem( xConfigurationProvider, "org.openoffice.Setup/Product", "ooSetupExtension")); - if (!extension.isEmpty()) { + if (!extension.isEmpty()) buf.append(extension); - } + OUString product(buf.makeStringAndClear()); OUString aUserAgent( "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("version") ":UpdateUserAgent}" ); + OUString aExtended; + if( bExtended ) + { + try { + uno::Reference< css::awt::XToolkitExperimental > xToolkit( + css::awt::Toolkit::create( m_xContext ), uno::UNO_QUERY_THROW ); + if ( xToolkit.is() ) + aExtended = xToolkit->getHWOSConfInfo(); + } catch (const uno::Exception &) { + SAL_WARN( "extensions.update", "Failed to find version info from toolkit" ); + } + } rtl::Bootstrap::expandMacros( aUserAgent ); aUserAgent = aUserAgent.replaceAll("<PRODUCT>", product); + aUserAgent = aUserAgent.replaceAll("<OPTIONAL_OS_HW_DATA>", aExtended); SAL_INFO("extensions.update", "UpdateUserAgent: " << aUserAgent); - m_aRequestHeaderList[0].First = "Accept-Language"; - m_aRequestHeaderList[0].Second = getConfigurationItem( xConfigurationProvider, "org.openoffice.Setup/L10N", "ooLocale" ); - if( !aUserAgent.isEmpty() ) + return aUserAgent; +} + +uno::Sequence< beans::StringPair > SAL_CALL UpdateInformationProvider::getUserRequestHeaders( + const OUString &aURL, ucb::WebDAVHTTPMethod ) + throw ( uno::RuntimeException, std::exception ) +{ + bool bExtendedUserAgent; + uno::Sequence< beans::StringPair > aPair = m_aRequestHeaderList; + + // Internal use from cui/ some magic URLs + if( aURL.startsWith( "useragent:" ) ) + bExtendedUserAgent = (aURL == "useragent:extended"); + else + bExtendedUserAgent = isUserAgentExtended(); + + OUString aUserAgent = getUserAgent(bExtendedUserAgent); + + if( aUserAgent.isEmpty() ) + aPair.realloc(1); + else { - m_aRequestHeaderList.realloc(2); - m_aRequestHeaderList[1].First = "User-Agent"; - m_aRequestHeaderList[1].Second = aUserAgent; + aPair[1].First = "User-Agent"; + aPair[1].Second = aUserAgent; } -} + + return aPair; +}; uno::Reference< uno::XInterface > UpdateInformationProvider::createInstance(const uno::Reference<uno::XComponentContext>& xContext) @@ -383,18 +442,13 @@ UpdateInformationProvider::createInstance(const uno::Reference<uno::XComponentCo return *new UpdateInformationProvider(xContext, xUniversalContentBroker, xDocumentBuilder, xXPath); } - - UpdateInformationProvider::~UpdateInformationProvider() { } - - -OUString -UpdateInformationProvider::getConfigurationItem(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, OUString const & node, OUString const & item) +uno::Any +UpdateInformationProvider::getConfigurationItemAny(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, OUString const & node, OUString const & item) { - rtl::OUString sRet; beans::PropertyValue aProperty; aProperty.Name = "nodepath"; aProperty.Value = uno::makeAny(node); @@ -408,11 +462,16 @@ UpdateInformationProvider::getConfigurationItem(uno::Reference<lang::XMultiServi aArgumentList ), uno::UNO_QUERY_THROW); - xNameAccess->getByName(item) >>= sRet; - return sRet; + return xNameAccess->getByName(item); } - +OUString +UpdateInformationProvider::getConfigurationItem(uno::Reference<lang::XMultiServiceFactory> const & configurationProvider, OUString const & node, OUString const & item) +{ + OUString sRet; + getConfigurationItemAny(configurationProvider, node, item) >>= sRet; + return sRet; +} void UpdateInformationProvider::storeCommandInfo( @@ -425,8 +484,6 @@ UpdateInformationProvider::storeCommandInfo( m_xCommandProcessor = rxCommandProcessor; } - - uno::Reference< io::XInputStream > UpdateInformationProvider::load(const OUString& rURL) { |