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
5 : *
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/
10 : *
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.
15 : *
16 : * The Original Code is Mozilla Content App.
17 : *
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.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef mozilla_dom_ContentParent_h
40 : #define mozilla_dom_ContentParent_h
41 :
42 : #include "base/waitable_event_watcher.h"
43 :
44 : #include "mozilla/dom/PContentParent.h"
45 : #include "mozilla/dom/PMemoryReportRequestParent.h"
46 : #include "mozilla/ipc/GeckoChildProcessHost.h"
47 :
48 : #include "nsIObserver.h"
49 : #include "nsIThreadInternal.h"
50 : #include "nsNetUtil.h"
51 : #include "nsIPrefService.h"
52 : #include "nsIPermissionManager.h"
53 : #include "nsIDOMGeoPositionCallback.h"
54 : #include "nsIDeviceMotion.h"
55 : #include "nsIMemoryReporter.h"
56 : #include "nsCOMArray.h"
57 :
58 : class nsFrameMessageManager;
59 : namespace mozilla {
60 :
61 : namespace ipc {
62 : class TestShellParent;
63 : }
64 :
65 : namespace dom {
66 :
67 : class TabParent;
68 : class PStorageParent;
69 :
70 : class ContentParent : public PContentParent
71 : , public nsIObserver
72 : , public nsIThreadObserver
73 : , public nsIDOMGeoPositionCallback
74 : , public nsIDeviceMotionListener
75 : {
76 : private:
77 : typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
78 : typedef mozilla::ipc::TestShellParent TestShellParent;
79 :
80 : public:
81 : static ContentParent* GetNewOrUsed();
82 : static void GetAll(nsTArray<ContentParent*>& aArray);
83 :
84 : NS_DECL_ISUPPORTS
85 : NS_DECL_NSIOBSERVER
86 : NS_DECL_NSITHREADOBSERVER
87 : NS_DECL_NSIDOMGEOPOSITIONCALLBACK
88 : NS_DECL_NSIDEVICEMOTIONLISTENER
89 :
90 : TabParent* CreateTab(PRUint32 aChromeFlags);
91 :
92 : TestShellParent* CreateTestShell();
93 : bool DestroyTestShell(TestShellParent* aTestShell);
94 : TestShellParent* GetTestShellSingleton();
95 :
96 : void ReportChildAlreadyBlocked();
97 : bool RequestRunToCompletion();
98 :
99 : bool IsAlive();
100 :
101 : void SetChildMemoryReporters(const InfallibleTArray<MemoryReport>& report);
102 :
103 : GeckoChildProcessHost* Process() {
104 : return mSubprocess;
105 : }
106 :
107 0 : bool NeedsPermissionsUpdate() {
108 0 : return mSendPermissionUpdates;
109 : }
110 :
111 : protected:
112 : void OnChannelConnected(int32 pid);
113 : virtual void ActorDestroy(ActorDestroyReason why);
114 :
115 : private:
116 : static nsTArray<ContentParent*>* gContentParents;
117 :
118 : // Hide the raw constructor methods since we don't want client code
119 : // using them.
120 : using PContentParent::SendPBrowserConstructor;
121 : using PContentParent::SendPTestShellConstructor;
122 :
123 : ContentParent();
124 : virtual ~ContentParent();
125 :
126 : void Init();
127 :
128 : virtual PBrowserParent* AllocPBrowser(const PRUint32& aChromeFlags);
129 : virtual bool DeallocPBrowser(PBrowserParent* frame);
130 :
131 : virtual PCrashReporterParent* AllocPCrashReporter(const NativeThreadId& tid,
132 : const PRUint32& processType);
133 : virtual bool DeallocPCrashReporter(PCrashReporterParent* crashreporter);
134 : virtual bool RecvPCrashReporterConstructor(PCrashReporterParent* actor,
135 : const NativeThreadId& tid,
136 : const PRUint32& processType);
137 :
138 : NS_OVERRIDE virtual PHalParent* AllocPHal();
139 : NS_OVERRIDE virtual bool DeallocPHal(PHalParent*);
140 :
141 : virtual PMemoryReportRequestParent* AllocPMemoryReportRequest();
142 : virtual bool DeallocPMemoryReportRequest(PMemoryReportRequestParent* actor);
143 :
144 : virtual PTestShellParent* AllocPTestShell();
145 : virtual bool DeallocPTestShell(PTestShellParent* shell);
146 :
147 : virtual PAudioParent* AllocPAudio(const PRInt32&,
148 : const PRInt32&,
149 : const PRInt32&);
150 : virtual bool DeallocPAudio(PAudioParent*);
151 :
152 : virtual PNeckoParent* AllocPNecko();
153 : virtual bool DeallocPNecko(PNeckoParent* necko);
154 :
155 : virtual PExternalHelperAppParent* AllocPExternalHelperApp(
156 : const IPC::URI& uri,
157 : const nsCString& aMimeContentType,
158 : const nsCString& aContentDisposition,
159 : const bool& aForceSave,
160 : const PRInt64& aContentLength,
161 : const IPC::URI& aReferrer);
162 : virtual bool DeallocPExternalHelperApp(PExternalHelperAppParent* aService);
163 :
164 : virtual PSmsParent* AllocPSms();
165 : virtual bool DeallocPSms(PSmsParent*);
166 :
167 : virtual PStorageParent* AllocPStorage(const StorageConstructData& aData);
168 : virtual bool DeallocPStorage(PStorageParent* aActor);
169 :
170 : virtual bool RecvReadPrefsArray(InfallibleTArray<PrefTuple> *retValue);
171 : virtual bool RecvReadFontList(InfallibleTArray<FontListEntry>* retValue);
172 :
173 : void EnsurePrefService();
174 :
175 : virtual bool RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions);
176 :
177 : virtual bool RecvGetIndexedDBDirectory(nsString* aDirectory);
178 :
179 : virtual bool RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard);
180 : virtual bool RecvGetClipboardText(const PRInt32& whichClipboard, nsString* text);
181 : virtual bool RecvEmptyClipboard();
182 : virtual bool RecvClipboardHasText(bool* hasText);
183 :
184 : virtual bool RecvGetSystemColors(const PRUint32& colorsCount, InfallibleTArray<PRUint32>* colors);
185 : virtual bool RecvGetIconForExtension(const nsCString& aFileExt, const PRUint32& aIconSize, InfallibleTArray<PRUint8>* bits);
186 : virtual bool RecvGetShowPasswordSetting(bool* showPassword);
187 :
188 : virtual bool RecvStartVisitedQuery(const IPC::URI& uri);
189 :
190 : virtual bool RecvVisitURI(const IPC::URI& uri,
191 : const IPC::URI& referrer,
192 : const PRUint32& flags);
193 :
194 : virtual bool RecvSetURITitle(const IPC::URI& uri,
195 : const nsString& title);
196 :
197 : virtual bool RecvShowFilePicker(const PRInt16& mode,
198 : const PRInt16& selectedType,
199 : const bool& addToRecentDocs,
200 : const nsString& title,
201 : const nsString& defaultFile,
202 : const nsString& defaultExtension,
203 : const InfallibleTArray<nsString>& filters,
204 : const InfallibleTArray<nsString>& filterNames,
205 : InfallibleTArray<nsString>* files,
206 : PRInt16* retValue,
207 : nsresult* result);
208 :
209 : virtual bool RecvShowAlertNotification(const nsString& aImageUrl, const nsString& aTitle,
210 : const nsString& aText, const bool& aTextClickable,
211 : const nsString& aCookie, const nsString& aName);
212 :
213 : virtual bool RecvLoadURIExternal(const IPC::URI& uri);
214 :
215 : virtual bool RecvSyncMessage(const nsString& aMsg, const nsString& aJSON,
216 : InfallibleTArray<nsString>* aRetvals);
217 : virtual bool RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON);
218 :
219 : virtual bool RecvAddGeolocationListener();
220 : virtual bool RecvRemoveGeolocationListener();
221 : virtual bool RecvAddDeviceMotionListener();
222 : virtual bool RecvRemoveDeviceMotionListener();
223 :
224 : virtual bool RecvConsoleMessage(const nsString& aMessage);
225 : virtual bool RecvScriptError(const nsString& aMessage,
226 : const nsString& aSourceName,
227 : const nsString& aSourceLine,
228 : const PRUint32& aLineNumber,
229 : const PRUint32& aColNumber,
230 : const PRUint32& aFlags,
231 : const nsCString& aCategory);
232 :
233 : GeckoChildProcessHost* mSubprocess;
234 :
235 : PRInt32 mGeolocationWatchID;
236 : int mRunToCompletionDepth;
237 : bool mShouldCallUnblockChild;
238 :
239 : // This is a cache of all of the memory reporters
240 : // registered in the child process. To update this, one
241 : // can broadcast the topic "child-memory-reporter-request" using
242 : // the nsIObserverService.
243 : nsCOMArray<nsIMemoryReporter> mMemoryReporters;
244 :
245 : bool mIsAlive;
246 : nsCOMPtr<nsIPrefService> mPrefService;
247 :
248 : bool mSendPermissionUpdates;
249 :
250 : nsRefPtr<nsFrameMessageManager> mMessageManager;
251 :
252 : friend class CrashReporterParent;
253 : };
254 :
255 : } // namespace dom
256 : } // namespace mozilla
257 :
258 : #endif
|