Arena pool macros don't want to die.
[mozilla-central.git] / dom / ipc / ContentProcessChild.h
blob3d6c590fe9ce8310703972f524d8e491bf8d0a6b
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set sw=4 ts=8 et tw=80 : */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Content App.
18 * The Initial Developer of the Original Code is
19 * The Mozilla Foundation.
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Frederic Plourde <frederic.plourde@collabora.co.uk>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef mozilla_dom_ContentProcessChild_h
41 #define mozilla_dom_ContentProcessChild_h
43 #include "mozilla/dom/PContentProcessChild.h"
45 #include "nsIObserverService.h"
46 #include "nsTObserverArray.h"
47 #include "nsIObserver.h"
48 #include "nsIPrefService.h"
49 #include "nsIPrefBranch.h"
50 #include "nsServiceManagerUtils.h"
51 #include "nsTArray.h"
52 #include "nsAutoPtr.h"
53 #include "nsWeakReference.h"
55 struct ChromePackage;
56 struct ResourceMapping;
57 struct OverrideMapping;
59 namespace mozilla {
60 namespace dom {
62 class ContentProcessChild : public PContentProcessChild
64 public:
65 ContentProcessChild();
66 virtual ~ContentProcessChild();
68 class nsPrefObserverStorage {
69 public:
70 nsPrefObserverStorage(nsIObserver *aObserver, nsCString aDomain,
71 nsCString aPrefRoot, bool aHoldWeak) {
72 mDomain = aDomain;
73 mPrefRoot = aPrefRoot;
74 mObserver = aObserver;
75 if (aHoldWeak) {
76 nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
77 do_QueryInterface(aObserver);
78 if (weakRefFactory)
79 mWeakRef = do_GetWeakReference(aObserver);
80 } else {
81 mWeakRef = nsnull;
85 ~nsPrefObserverStorage() {
88 bool NotifyObserver() {
89 nsCOMPtr<nsIObserver> observer;
90 if (mWeakRef) {
91 observer = do_QueryReferent(mWeakRef);
92 if (!observer) {
93 // this weak referenced observer went away, tell
94 // the caller so he can remove the observer from the list
95 return false;
97 } else {
98 observer = mObserver;
101 nsCOMPtr<nsIPrefBranch> prefBranch;
102 nsCOMPtr<nsIPrefService> prefService =
103 do_GetService(NS_PREFSERVICE_CONTRACTID);
104 if (prefService) {
105 prefService->GetBranch(mPrefRoot.get(),
106 getter_AddRefs(prefBranch));
107 observer->Observe(prefBranch, "nsPref:changed",
108 NS_ConvertASCIItoUTF16(mDomain).get());
110 return true;
113 nsIObserver* GetObserver() { return mObserver; }
114 const nsCString& GetDomain() { return mDomain; }
115 const nsCString& GetPrefRoot() { return mPrefRoot; }
117 private:
118 nsCOMPtr<nsIObserver> mObserver;
119 nsWeakPtr mWeakRef;
120 nsCString mPrefRoot;
121 nsCString mDomain;
124 bool Init(MessageLoop* aIOLoop,
125 base::ProcessHandle aParentHandle,
126 IPC::Channel* aChannel);
128 static ContentProcessChild* GetSingleton() {
129 NS_ASSERTION(sSingleton, "not initialized");
130 return sSingleton;
133 /* if you remove this, please talk to cjones or dougt */
134 virtual bool RecvDummy(Shmem& foo) { return true; }
136 virtual PIFrameEmbeddingChild* AllocPIFrameEmbedding();
137 virtual bool DeallocPIFrameEmbedding(PIFrameEmbeddingChild*);
139 virtual PTestShellChild* AllocPTestShell();
140 virtual bool DeallocPTestShell(PTestShellChild*);
141 virtual bool RecvPTestShellConstructor(PTestShellChild*);
143 virtual PNeckoChild* AllocPNecko();
144 virtual bool DeallocPNecko(PNeckoChild*);
146 virtual bool RecvRegisterChrome(const nsTArray<ChromePackage>& packages,
147 const nsTArray<ResourceMapping>& resources,
148 const nsTArray<OverrideMapping>& overrides);
150 virtual bool RecvSetOffline(const PRBool& offline);
152 nsresult AddRemotePrefObserver(const nsCString &aDomain,
153 const nsCString &aPrefRoot,
154 nsIObserver *aObserver, PRBool aHoldWeak);
155 nsresult RemoveRemotePrefObserver(const nsCString &aDomain,
156 const nsCString &aPrefRoot,
157 nsIObserver *aObserver);
158 inline void ClearPrefObservers() {
159 mPrefObserverArray.Clear();
162 virtual bool RecvNotifyRemotePrefObserver(
163 const nsCString& aDomain);
167 private:
168 NS_OVERRIDE
169 virtual void ActorDestroy(ActorDestroyReason why);
171 static ContentProcessChild* sSingleton;
173 nsTArray< nsAutoPtr<nsPrefObserverStorage> > mPrefObserverArray;
175 DISALLOW_EVIL_CONSTRUCTORS(ContentProcessChild);
178 } // namespace dom
179 } // namespace mozilla
181 #endif