Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=2:tabstop=8: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | #include <QWindow> |
michael@0 | 8 | #include "nsQtRemoteService.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/ModuleUtils.h" |
michael@0 | 11 | #include "mozilla/X11Util.h" |
michael@0 | 12 | #include "nsIServiceManager.h" |
michael@0 | 13 | #include "nsIAppShellService.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "nsCOMPtr.h" |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | Helper class which is used to receive notification about property changes |
michael@0 | 19 | */ |
michael@0 | 20 | class MozQRemoteEventHandlerWidget: public QWindow { |
michael@0 | 21 | public: |
michael@0 | 22 | /** |
michael@0 | 23 | Constructor |
michael@0 | 24 | @param aRemoteService remote service, which is notified about atom change |
michael@0 | 25 | */ |
michael@0 | 26 | MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService); |
michael@0 | 27 | virtual ~MozQRemoteEventHandlerWidget() {} |
michael@0 | 28 | |
michael@0 | 29 | protected: |
michael@0 | 30 | /** |
michael@0 | 31 | Event filter, which receives all XEvents |
michael@0 | 32 | @return false which continues event handling |
michael@0 | 33 | */ |
michael@0 | 34 | bool x11Event(XEvent *); |
michael@0 | 35 | |
michael@0 | 36 | private: |
michael@0 | 37 | /** |
michael@0 | 38 | Service which is notified about property change |
michael@0 | 39 | */ |
michael@0 | 40 | nsQtRemoteService &mRemoteService; |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | MozQRemoteEventHandlerWidget::MozQRemoteEventHandlerWidget(nsQtRemoteService &aRemoteService) |
michael@0 | 44 | :mRemoteService(aRemoteService) |
michael@0 | 45 | { |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | bool |
michael@0 | 49 | MozQRemoteEventHandlerWidget::x11Event(XEvent *aEvt) |
michael@0 | 50 | { |
michael@0 | 51 | if (aEvt->type == PropertyNotify && aEvt->xproperty.state == PropertyNewValue) |
michael@0 | 52 | mRemoteService.PropertyNotifyEvent(aEvt); |
michael@0 | 53 | |
michael@0 | 54 | return false; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | NS_IMPL_ISUPPORTS(nsQtRemoteService, |
michael@0 | 58 | nsIRemoteService, |
michael@0 | 59 | nsIObserver) |
michael@0 | 60 | |
michael@0 | 61 | nsQtRemoteService::nsQtRemoteService(): |
michael@0 | 62 | mServerWindow(0) |
michael@0 | 63 | { |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | NS_IMETHODIMP |
michael@0 | 67 | nsQtRemoteService::Startup(const char* aAppName, const char* aProfileName) |
michael@0 | 68 | { |
michael@0 | 69 | if (mServerWindow) return NS_ERROR_ALREADY_INITIALIZED; |
michael@0 | 70 | NS_ASSERTION(aAppName, "Don't pass a null appname!"); |
michael@0 | 71 | |
michael@0 | 72 | XRemoteBaseStartup(aAppName,aProfileName); |
michael@0 | 73 | |
michael@0 | 74 | //Create window, which is not shown. |
michael@0 | 75 | mServerWindow = new MozQRemoteEventHandlerWidget(*this); |
michael@0 | 76 | |
michael@0 | 77 | HandleCommandsFor(mServerWindow->winId()); |
michael@0 | 78 | return NS_OK; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | NS_IMETHODIMP |
michael@0 | 82 | nsQtRemoteService::RegisterWindow(nsIDOMWindow* aWindow) |
michael@0 | 83 | { |
michael@0 | 84 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | NS_IMETHODIMP |
michael@0 | 88 | nsQtRemoteService::Shutdown() |
michael@0 | 89 | { |
michael@0 | 90 | if (!mServerWindow) |
michael@0 | 91 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 92 | |
michael@0 | 93 | delete mServerWindow; |
michael@0 | 94 | mServerWindow = nullptr; |
michael@0 | 95 | |
michael@0 | 96 | return NS_OK; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | void |
michael@0 | 100 | nsQtRemoteService::PropertyNotifyEvent(XEvent *aEvt) |
michael@0 | 101 | { |
michael@0 | 102 | HandleNewProperty(aEvt->xproperty.window, |
michael@0 | 103 | mozilla::DefaultXDisplay(), |
michael@0 | 104 | aEvt->xproperty.time, |
michael@0 | 105 | aEvt->xproperty.atom, |
michael@0 | 106 | 0); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | void |
michael@0 | 110 | nsQtRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID, |
michael@0 | 111 | uint32_t aTimestamp) |
michael@0 | 112 | { |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | // {C0773E90-5799-4eff-AD03-3EBCD85624AC} |
michael@0 | 116 | #define NS_REMOTESERVICE_CID \ |
michael@0 | 117 | { 0xc0773e90, 0x5799, 0x4eff, { 0xad, 0x3, 0x3e, 0xbc, 0xd8, 0x56, 0x24, 0xac } } |
michael@0 | 118 | |
michael@0 | 119 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsQtRemoteService) |
michael@0 | 120 | NS_DEFINE_NAMED_CID(NS_REMOTESERVICE_CID); |
michael@0 | 121 | |
michael@0 | 122 | static const mozilla::Module::CIDEntry kRemoteCIDs[] = { |
michael@0 | 123 | { &kNS_REMOTESERVICE_CID, false, nullptr, nsQtRemoteServiceConstructor }, |
michael@0 | 124 | { nullptr } |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | static const mozilla::Module::ContractIDEntry kRemoteContracts[] = { |
michael@0 | 128 | { "@mozilla.org/toolkit/remote-service;1", &kNS_REMOTESERVICE_CID }, |
michael@0 | 129 | { nullptr } |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | static const mozilla::Module kRemoteModule = { |
michael@0 | 133 | mozilla::Module::kVersion, |
michael@0 | 134 | kRemoteCIDs, |
michael@0 | 135 | kRemoteContracts |
michael@0 | 136 | }; |
michael@0 | 137 | |
michael@0 | 138 | NSMODULE_DEFN(RemoteServiceModule) = &kRemoteModule; |