1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/remote/nsQtRemoteService.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:expandtab:shiftwidth=2:tabstop=8: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 +#include <QWindow> 1.11 +#include "nsQtRemoteService.h" 1.12 + 1.13 +#include "mozilla/ModuleUtils.h" 1.14 +#include "mozilla/X11Util.h" 1.15 +#include "nsIServiceManager.h" 1.16 +#include "nsIAppShellService.h" 1.17 + 1.18 +#include "nsCOMPtr.h" 1.19 + 1.20 +/** 1.21 + Helper class which is used to receive notification about property changes 1.22 +*/ 1.23 +class MozQRemoteEventHandlerWidget: public QWindow { 1.24 +public: 1.25 + /** 1.26 + Constructor 1.27 + @param aRemoteService remote service, which is notified about atom change 1.28 + */ 1.29 + MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService); 1.30 + virtual ~MozQRemoteEventHandlerWidget() {} 1.31 + 1.32 +protected: 1.33 + /** 1.34 + Event filter, which receives all XEvents 1.35 + @return false which continues event handling 1.36 + */ 1.37 + bool x11Event(XEvent *); 1.38 + 1.39 +private: 1.40 + /** 1.41 + Service which is notified about property change 1.42 + */ 1.43 + nsQtRemoteService &mRemoteService; 1.44 +}; 1.45 + 1.46 +MozQRemoteEventHandlerWidget::MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService) 1.47 + :mRemoteService(aRemoteService) 1.48 +{ 1.49 +} 1.50 + 1.51 +bool 1.52 +MozQRemoteEventHandlerWidget::x11Event(XEvent *aEvt) 1.53 +{ 1.54 + if (aEvt->type == PropertyNotify && aEvt->xproperty.state == PropertyNewValue) 1.55 + mRemoteService.PropertyNotifyEvent(aEvt); 1.56 + 1.57 + return false; 1.58 +} 1.59 + 1.60 +NS_IMPL_ISUPPORTS(nsQtRemoteService, 1.61 + nsIRemoteService, 1.62 + nsIObserver) 1.63 + 1.64 +nsQtRemoteService::nsQtRemoteService(): 1.65 +mServerWindow(0) 1.66 +{ 1.67 +} 1.68 + 1.69 +NS_IMETHODIMP 1.70 +nsQtRemoteService::Startup(const char* aAppName, const char* aProfileName) 1.71 +{ 1.72 + if (mServerWindow) return NS_ERROR_ALREADY_INITIALIZED; 1.73 + NS_ASSERTION(aAppName, "Don't pass a null appname!"); 1.74 + 1.75 + XRemoteBaseStartup(aAppName,aProfileName); 1.76 + 1.77 + //Create window, which is not shown. 1.78 + mServerWindow = new MozQRemoteEventHandlerWidget(*this); 1.79 + 1.80 + HandleCommandsFor(mServerWindow->winId()); 1.81 + return NS_OK; 1.82 +} 1.83 + 1.84 +NS_IMETHODIMP 1.85 +nsQtRemoteService::RegisterWindow(nsIDOMWindow* aWindow) 1.86 +{ 1.87 + return NS_ERROR_NOT_IMPLEMENTED; 1.88 +} 1.89 + 1.90 +NS_IMETHODIMP 1.91 +nsQtRemoteService::Shutdown() 1.92 +{ 1.93 + if (!mServerWindow) 1.94 + return NS_ERROR_NOT_INITIALIZED; 1.95 + 1.96 + delete mServerWindow; 1.97 + mServerWindow = nullptr; 1.98 + 1.99 + return NS_OK; 1.100 +} 1.101 + 1.102 +void 1.103 +nsQtRemoteService::PropertyNotifyEvent(XEvent *aEvt) 1.104 +{ 1.105 + HandleNewProperty(aEvt->xproperty.window, 1.106 + mozilla::DefaultXDisplay(), 1.107 + aEvt->xproperty.time, 1.108 + aEvt->xproperty.atom, 1.109 + 0); 1.110 +} 1.111 + 1.112 +void 1.113 +nsQtRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID, 1.114 + uint32_t aTimestamp) 1.115 +{ 1.116 +} 1.117 + 1.118 +// {C0773E90-5799-4eff-AD03-3EBCD85624AC} 1.119 +#define NS_REMOTESERVICE_CID \ 1.120 + { 0xc0773e90, 0x5799, 0x4eff, { 0xad, 0x3, 0x3e, 0xbc, 0xd8, 0x56, 0x24, 0xac } } 1.121 + 1.122 +NS_GENERIC_FACTORY_CONSTRUCTOR(nsQtRemoteService) 1.123 +NS_DEFINE_NAMED_CID(NS_REMOTESERVICE_CID); 1.124 + 1.125 +static const mozilla::Module::CIDEntry kRemoteCIDs[] = { 1.126 + { &kNS_REMOTESERVICE_CID, false, nullptr, nsQtRemoteServiceConstructor }, 1.127 + { nullptr } 1.128 +}; 1.129 + 1.130 +static const mozilla::Module::ContractIDEntry kRemoteContracts[] = { 1.131 + { "@mozilla.org/toolkit/remote-service;1", &kNS_REMOTESERVICE_CID }, 1.132 + { nullptr } 1.133 +}; 1.134 + 1.135 +static const mozilla::Module kRemoteModule = { 1.136 + mozilla::Module::kVersion, 1.137 + kRemoteCIDs, 1.138 + kRemoteContracts 1.139 +}; 1.140 + 1.141 +NSMODULE_DEFN(RemoteServiceModule) = &kRemoteModule;