VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp@ 101824

Last change on this file since 101824 was 101824, checked in by vboxsync, 15 months ago

libs/xpcom: Get rid of unused nsRecyclingAllocator.{cpp,h}, bugref:10545

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.7 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#include "nsXPCOM.h"
39#include "nsXPCOMPrivate.h"
40#include "nscore.h"
41#include "prlink.h"
42#include "nsCOMPtr.h"
43#include "nsObserverList.h"
44#include "nsObserverService.h"
45#include "nsProperties.h"
46#include "nsIProperties.h"
47#include "nsPersistentProperties.h"
48#include "nsScriptableInputStream.h"
49#include "nsBinaryStream.h"
50#include "nsStorageStream.h"
51
52#include "nsMemoryImpl.h"
53#include "nsDebugImpl.h"
54#include "nsTraceRefcntImpl.h"
55#include "nsErrorService.h"
56#include "nsByteBuffer.h"
57
58#include "nsSupportsArray.h"
59#include "nsArray.h"
60#include "nsSupportsPrimitives.h"
61#include "nsConsoleService.h"
62#include "nsExceptionService.h"
63
64#include "nsComponentManager.h"
65#include "nsCategoryManagerUtils.h"
66#include "nsIServiceManager.h"
67#include "nsGenericFactory.h"
68
69#include "nsEventQueueService.h"
70#include "nsEventQueue.h"
71#ifdef VBOX
72# include "nsEventQueueUtils.h"
73# include "nsProxyRelease.h"
74#endif /* VBOX */
75
76#include "nsIProxyObjectManager.h"
77#include "nsProxyEventPrivate.h" // access to the impl of nsProxyObjectManager for the generic factory registration.
78
79#include "xptinfo.h"
80#include "nsIInterfaceInfoManager.h"
81
82#include "nsTimerImpl.h"
83#include "TimerThread.h"
84
85#include "nsThread.h"
86#include "nsProcess.h"
87#include "nsEnvironment.h"
88
89#include "nsEmptyEnumerator.h"
90
91#include "nsILocalFile.h"
92#include "nsLocalFile.h"
93#if defined(XP_UNIX) || defined(XP_OS2)
94#include "nsNativeCharsetUtils.h"
95#endif
96#include "nsDirectoryService.h"
97#include "nsDirectoryServiceDefs.h"
98#include "nsCategoryManager.h"
99#include "nsICategoryManager.h"
100#include "nsStringStream.h"
101#include "nsMultiplexInputStream.h"
102
103#include "nsAtomService.h"
104#include "nsAtomTable.h"
105#include "nsTraceRefcnt.h"
106
107#include "nsVariant.h"
108
109#include "SpecialSystemDirectory.h"
110
111#include "ipcdclient.h"
112#include "ipcService.h"
113#include "ipcConfig.h"
114#include "ipcCID.h"
115#include "ipcLockService.h"
116#include "ipcLockCID.h"
117#include "tmTransactionService.h"
118#include "ipcDConnectService.h"
119
120#include <locale.h>
121
122// Registry Factory creation function defined in nsRegistry.cpp
123// We hook into this function locally to create and register the registry
124// Since noone outside xpcom needs to know about this and nsRegistry.cpp
125// does not have a local include file, we are putting this definition
126// here rather than in nsIRegistry.h
127extern nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
128extern nsresult NS_CategoryManagerGetFactory( nsIFactory** );
129
130#ifdef DEBUG
131extern void _FreeAutoLockStatics();
132#endif
133
134static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
135static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
136static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
137
138NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess)
139NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsEventQueueServiceImpl, Init)
140
141#define NS_ENVIRONMENT_CLASSNAME "Environment Service"
142
143#include "nsXPCOM.h"
144// ds/nsISupportsPrimitives
145#define NS_SUPPORTS_ID_CLASSNAME "Supports ID"
146#define NS_SUPPORTS_CSTRING_CLASSNAME "Supports String"
147#define NS_SUPPORTS_STRING_CLASSNAME "Supports WString"
148#define NS_SUPPORTS_PRBOOL_CLASSNAME "Supports PRBool"
149#define NS_SUPPORTS_PRUINT8_CLASSNAME "Supports PRUint8"
150#define NS_SUPPORTS_PRUINT16_CLASSNAME "Supports PRUint16"
151#define NS_SUPPORTS_PRUINT32_CLASSNAME "Supports PRUint32"
152#define NS_SUPPORTS_PRUINT64_CLASSNAME "Supports PRUint64"
153#define NS_SUPPORTS_PRTIME_CLASSNAME "Supports PRTime"
154#define NS_SUPPORTS_CHAR_CLASSNAME "Supports Char"
155#define NS_SUPPORTS_PRINT16_CLASSNAME "Supports PRInt16"
156#define NS_SUPPORTS_PRINT32_CLASSNAME "Supports PRInt32"
157#define NS_SUPPORTS_PRINT64_CLASSNAME "Supports PRInt64"
158#define NS_SUPPORTS_FLOAT_CLASSNAME "Supports float"
159#define NS_SUPPORTS_DOUBLE_CLASSNAME "Supports double"
160#define NS_SUPPORTS_VOID_CLASSNAME "Supports void"
161#define NS_SUPPORTS_INTERFACE_POINTER_CLASSNAME "Supports interface pointer"
162
163NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsIDImpl)
164NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsStringImpl)
165NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCStringImpl)
166NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRBoolImpl)
167NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint8Impl)
168NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint16Impl)
169NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint32Impl)
170NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint64Impl)
171NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRTimeImpl)
172NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCharImpl)
173NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt16Impl)
174NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
175NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
176NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
177NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
178NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
179NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
180
181NS_GENERIC_FACTORY_CONSTRUCTOR(nsArray)
182NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleService)
183NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService)
184NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService)
185NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl)
186NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerManager)
187NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryOutputStream)
188NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryInputStream)
189NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageStream)
190
191NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant)
192
193static NS_METHOD
194nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer,
195 const nsIID& aIID,
196 void* *aInstancePtr)
197{
198 NS_ENSURE_ARG_POINTER(aInstancePtr);
199 NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
200
201 nsCOMPtr<nsIInterfaceInfoManager> iim(dont_AddRef(XPTI_GetInterfaceInfoManager()));
202 if (!iim) {
203 return NS_ERROR_FAILURE;
204 }
205
206 return iim->QueryInterface(aIID, aInstancePtr);
207}
208
209
210PR_STATIC_CALLBACK(nsresult)
211RegisterGenericFactory(nsIComponentRegistrar* registrar,
212 const nsModuleComponentInfo *info)
213{
214 nsresult rv;
215 nsIGenericFactory* fact;
216 rv = NS_NewGenericFactory(&fact, info);
217 if (NS_FAILED(rv)) return rv;
218
219 rv = registrar->RegisterFactory(info->mCID,
220 info->mDescription,
221 info->mContractID,
222 fact);
223 NS_RELEASE(fact);
224 return rv;
225}
226
227// In order to support the installer, we need
228// to be told out of band if we should cause
229// an autoregister. If the file ".autoreg" exists in the binary
230// directory, we check its timestamp against the timestamp of the
231// compreg.dat file. If the .autoreg file is newer, we autoregister.
232static PRBool CheckUpdateFile()
233{
234 nsresult rv;
235 nsCOMPtr<nsIProperties> directoryService;
236 nsDirectoryService::Create(nsnull,
237 NS_GET_IID(nsIProperties),
238 getter_AddRefs(directoryService));
239
240 if (!directoryService)
241 return PR_FALSE;
242
243 nsCOMPtr<nsIFile> file;
244 rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
245 NS_GET_IID(nsIFile),
246 getter_AddRefs(file));
247
248 if (NS_FAILED(rv)) {
249 NS_WARNING("Getting NS_XPCOM_CURRENT_PROCESS_DIR failed");
250 return PR_FALSE;
251 }
252
253 file->AppendNative(nsDependentCString(".autoreg"));
254
255 PRBool exists;
256 file->Exists(&exists);
257 if (!exists)
258 return PR_FALSE;
259
260 nsCOMPtr<nsIFile> compregFile;
261 rv = directoryService->Get(NS_XPCOM_COMPONENT_REGISTRY_FILE,
262 NS_GET_IID(nsIFile),
263 getter_AddRefs(compregFile));
264
265
266 if (NS_FAILED(rv)) {
267 NS_WARNING("Getting NS_XPCOM_COMPONENT_REGISTRY_FILE failed");
268 return PR_FALSE;
269 }
270
271 // Don't need to check whether compreg exists; if it doesn't
272 // we won't even be here.
273
274 PRInt64 compregModTime, autoregModTime;
275 compregFile->GetLastModifiedTime(&compregModTime);
276 file->GetLastModifiedTime(&autoregModTime);
277
278 return LL_CMP(autoregModTime, >, compregModTime);
279}
280
281#if 0 /// @todo later
282NS_GENERIC_FACTORY_CONSTRUCTOR(ipcService)
283NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ipcLockService, Init)
284NS_GENERIC_FACTORY_CONSTRUCTOR(tmTransactionService)
285NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ipcDConnectService, Init)
286
287// enable this code to make the IPC DCONNECT service auto-start.
288NS_METHOD
289ipcDConnectServiceRegisterProc(nsIComponentManager *aCompMgr,
290 nsIFile *aPath,
291 const char *registryLocation,
292 const char *componentType,
293 const nsModuleComponentInfo *info)
294{
295 //
296 // add ipcService to the XPCOM startup category
297 //
298 nsCOMPtr<nsICategoryManager> catman(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
299 if (catman) {
300 nsXPIDLCString prevEntry;
301 catman->AddCategoryEntry(NS_XPCOM_STARTUP_OBSERVER_ID, "ipcDConnectService",
302 IPC_DCONNECTSERVICE_CONTRACTID, PR_TRUE, PR_TRUE,
303 getter_Copies(prevEntry));
304 }
305 return NS_OK;
306}
307
308NS_METHOD
309ipcDConnectServiceUnregisterProc(nsIComponentManager *aCompMgr,
310 nsIFile *aPath,
311 const char *registryLocation,
312 const nsModuleComponentInfo *info)
313{
314 nsCOMPtr<nsICategoryManager> catman(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
315 if (catman)
316 catman->DeleteCategoryEntry(NS_XPCOM_STARTUP_OBSERVER_ID,
317 IPC_DCONNECTSERVICE_CONTRACTID, PR_TRUE);
318 return NS_OK;
319}
320#endif
321
322nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
323nsIProperties *gDirectoryService = NULL;
324PRBool gXPCOMShuttingDown = PR_FALSE;
325
326// For each class that wishes to support nsIClassInfo, add a line like this
327// NS_DECL_CLASSINFO(nsMyClass)
328
329#define COMPONENT(NAME, Ctor) \
330 { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor }
331
332#define COMPONENT_CI(NAME, Ctor, Class) \
333 { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor, \
334 NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(Class), NULL, \
335 &NS_CLASSINFO_NAME(Class) }
336
337static const nsModuleComponentInfo components[] = {
338 COMPONENT(MEMORY, nsMemoryImpl::Create),
339 COMPONENT(DEBUG, nsDebugImpl::Create),
340#define NS_ERRORSERVICE_CLASSNAME NS_ERRORSERVICE_NAME
341 COMPONENT(ERRORSERVICE, nsErrorService::Create),
342
343 COMPONENT(BYTEBUFFER, ByteBufferImpl::Create),
344 COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create),
345 COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor),
346 COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor),
347 COMPONENT(STORAGESTREAM, nsStorageStreamConstructor),
348
349#define NS_PROPERTIES_CLASSNAME "Properties"
350 COMPONENT(PROPERTIES, nsProperties::Create),
351
352#define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
353 COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create),
354
355 COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create),
356 COMPONENT(ARRAY, nsArrayConstructor),
357 COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor),
358 COMPONENT(EXCEPTIONSERVICE, nsExceptionServiceConstructor),
359 COMPONENT(ATOMSERVICE, nsAtomServiceConstructor),
360 COMPONENT(OBSERVERSERVICE, nsObserverService::Create),
361 COMPONENT(GENERICFACTORY, nsGenericFactory::Create),
362 COMPONENT(EVENTQUEUESERVICE, nsEventQueueServiceImplConstructor),
363 COMPONENT(EVENTQUEUE, nsEventQueueImpl::Create),
364 COMPONENT(THREAD, nsThread::Create),
365
366#define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
367 COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create),
368
369 COMPONENT(TIMER, nsTimerImplConstructor),
370 COMPONENT(TIMERMANAGER, nsTimerManagerConstructor),
371
372#define COMPONENT_SUPPORTS(TYPE, Type) \
373 COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)
374
375 COMPONENT_SUPPORTS(ID, ID),
376 COMPONENT_SUPPORTS(STRING, String),
377 COMPONENT_SUPPORTS(CSTRING, CString),
378 COMPONENT_SUPPORTS(PRBOOL, PRBool),
379 COMPONENT_SUPPORTS(PRUINT8, PRUint8),
380 COMPONENT_SUPPORTS(PRUINT16, PRUint16),
381 COMPONENT_SUPPORTS(PRUINT32, PRUint32),
382 COMPONENT_SUPPORTS(PRUINT64, PRUint64),
383 COMPONENT_SUPPORTS(PRTIME, PRTime),
384 COMPONENT_SUPPORTS(CHAR, Char),
385 COMPONENT_SUPPORTS(PRINT16, PRInt16),
386 COMPONENT_SUPPORTS(PRINT32, PRInt32),
387 COMPONENT_SUPPORTS(PRINT64, PRInt64),
388 COMPONENT_SUPPORTS(FLOAT, Float),
389 COMPONENT_SUPPORTS(DOUBLE, Double),
390 COMPONENT_SUPPORTS(VOID, Void),
391 COMPONENT_SUPPORTS(INTERFACE_POINTER, InterfacePointer),
392
393#undef COMPONENT_SUPPORTS
394#define NS_LOCAL_FILE_CLASSNAME "Local File Specification"
395 COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor),
396#define NS_DIRECTORY_SERVICE_CLASSNAME "nsIFile Directory Service"
397 COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create),
398 COMPONENT(PROCESS, nsProcessConstructor),
399 COMPONENT(ENVIRONMENT, nsEnvironment::Create),
400
401 COMPONENT(STRINGINPUTSTREAM, nsStringInputStreamConstructor),
402 COMPONENT(MULTIPLEXINPUTSTREAM, nsMultiplexInputStreamConstructor),
403
404 COMPONENT(VARIANT, nsVariantConstructor),
405 COMPONENT(INTERFACEINFOMANAGER_SERVICE, nsXPTIInterfaceInfoManagerGetSingleton),
406
407#if 0 /// @todo later
408 { IPC_SERVICE_CLASSNAME,
409 IPC_SERVICE_CID,
410 IPC_SERVICE_CONTRACTID,
411 ipcServiceConstructor },
412 /*
413 ipcServiceRegisterProc,
414 ipcServiceUnregisterProc },
415 */
416 //
417 // extensions go here:
418 //
419 { IPC_LOCKSERVICE_CLASSNAME,
420 IPC_LOCKSERVICE_CID,
421 IPC_LOCKSERVICE_CONTRACTID,
422 ipcLockServiceConstructor },
423 { IPC_TRANSACTIONSERVICE_CLASSNAME,
424 IPC_TRANSACTIONSERVICE_CID,
425 IPC_TRANSACTIONSERVICE_CONTRACTID,
426 tmTransactionServiceConstructor },
427
428#ifdef BUILD_DCONNECT
429 { IPC_DCONNECTSERVICE_CLASSNAME,
430 IPC_DCONNECTSERVICE_CID,
431 IPC_DCONNECTSERVICE_CONTRACTID,
432 ipcDConnectServiceConstructor,
433 ipcDConnectServiceRegisterProc,
434 ipcDConnectServiceUnregisterProc },
435#endif
436#endif
437};
438
439#undef COMPONENT
440
441const int components_length = sizeof(components) / sizeof(components[0]);
442
443// gMemory will be freed during shutdown.
444static nsIMemory* gMemory = nsnull;
445nsresult NS_COM NS_GetMemoryManager(nsIMemory* *result)
446{
447 nsresult rv = NS_OK;
448 if (!gMemory)
449 {
450 rv = nsMemoryImpl::Create(nsnull,
451 NS_GET_IID(nsIMemory),
452 (void**)&gMemory);
453 }
454 NS_IF_ADDREF(*result = gMemory);
455 return rv;
456}
457
458// gDebug will be freed during shutdown.
459static nsIDebug* gDebug = nsnull;
460nsresult NS_COM NS_GetDebug(nsIDebug** result)
461{
462 nsresult rv = NS_OK;
463 if (!gDebug)
464 {
465 rv = nsDebugImpl::Create(nsnull,
466 NS_GET_IID(nsIDebug),
467 (void**)&gDebug);
468 }
469 NS_IF_ADDREF(*result = gDebug);
470 return rv;
471}
472
473#ifdef NS_BUILD_REFCNT_LOGGING
474// gTraceRefcnt will be freed during shutdown.
475static nsITraceRefcnt* gTraceRefcnt = nsnull;
476#endif
477
478nsresult NS_COM NS_GetTraceRefcnt(nsITraceRefcnt** result)
479{
480#ifdef NS_BUILD_REFCNT_LOGGING
481 nsresult rv = NS_OK;
482 if (!gTraceRefcnt)
483 {
484 rv = nsTraceRefcntImpl::Create(nsnull,
485 NS_GET_IID(nsITraceRefcnt),
486 (void**)&gTraceRefcnt);
487 }
488 NS_IF_ADDREF(*result = gTraceRefcnt);
489 return rv;
490#else
491 return NS_ERROR_NOT_INITIALIZED;
492#endif
493}
494
495nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
496 nsIFile* binDirectory)
497{
498 return NS_InitXPCOM2(result, binDirectory, nsnull);
499}
500
501nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
502 nsIFile* binDirectory,
503 nsIDirectoryServiceProvider* appFileLocationProvider)
504{
505 nsresult rv = NS_OK;
506
507 // We are not shutting down
508 gXPCOMShuttingDown = PR_FALSE;
509
510#ifdef NS_BUILD_REFCNT_LOGGING
511 nsTraceRefcntImpl::Startup();
512#endif
513
514 // Establish the main thread here.
515 rv = nsIThread::SetMainThread();
516 if (NS_FAILED(rv)) return rv;
517
518 // Set up the timer globals/timer thread
519 rv = nsTimerImpl::Startup();
520 NS_ENSURE_SUCCESS(rv, rv);
521
522 // Startup the memory manager
523 rv = nsMemoryImpl::Startup();
524 if (NS_FAILED(rv)) return rv;
525
526 // If the locale hasn't already been setup by our embedder,
527 // get us out of the "C" locale and into the system
528 if (strcmp(setlocale(LC_ALL, NULL), "C") == 0)
529 setlocale(LC_ALL, "");
530
531#if defined(XP_UNIX) || defined(XP_OS2)
532 NS_StartupNativeCharsetUtils();
533#endif
534 NS_StartupLocalFile();
535
536 StartupSpecialSystemDirectory();
537
538 // Start the directory service so that the component manager init can use it.
539 rv = nsDirectoryService::Create(nsnull,
540 NS_GET_IID(nsIProperties),
541 (void**)&gDirectoryService);
542 if (NS_FAILED(rv))
543 return rv;
544
545 nsCOMPtr<nsIDirectoryService> dirService = do_QueryInterface(gDirectoryService, &rv);
546 if (NS_FAILED(rv))
547 return rv;
548 rv = dirService->Init();
549 if (NS_FAILED(rv))
550 return rv;
551
552 // Create the Component/Service Manager
553 nsComponentManagerImpl *compMgr = NULL;
554
555 if (nsComponentManagerImpl::gComponentManager == NULL)
556 {
557 compMgr = new nsComponentManagerImpl();
558 if (compMgr == NULL)
559 return NS_ERROR_OUT_OF_MEMORY;
560 NS_ADDREF(compMgr);
561
562 nsCOMPtr<nsIFile> xpcomLib;
563
564 PRBool value;
565 if (binDirectory)
566 {
567 rv = binDirectory->IsDirectory(&value);
568
569 if (NS_SUCCEEDED(rv) && value) {
570 gDirectoryService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory);
571 binDirectory->Clone(getter_AddRefs(xpcomLib));
572 }
573 }
574 else {
575 gDirectoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
576 NS_GET_IID(nsIFile),
577 getter_AddRefs(xpcomLib));
578 }
579
580 if (xpcomLib) {
581 xpcomLib->AppendNative(nsDependentCString(XPCOM_DLL));
582 gDirectoryService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
583 }
584
585 if (appFileLocationProvider) {
586 rv = dirService->RegisterProvider(appFileLocationProvider);
587 if (NS_FAILED(rv)) return rv;
588 }
589
590 rv = compMgr->Init();
591 if (NS_FAILED(rv))
592 {
593 NS_RELEASE(compMgr);
594 return rv;
595 }
596
597 nsComponentManagerImpl::gComponentManager = compMgr;
598
599 if (result) {
600 nsIServiceManager *serviceManager =
601 NS_STATIC_CAST(nsIServiceManager*, compMgr);
602
603 NS_ADDREF(*result = serviceManager);
604 }
605 }
606
607 nsCOMPtr<nsIMemory> memory;
608 NS_GetMemoryManager(getter_AddRefs(memory));
609 // dougt - these calls will be moved into a new interface when nsIComponentManager is frozen.
610 rv = compMgr->RegisterService(kMemoryCID, memory);
611 if (NS_FAILED(rv)) return rv;
612
613 rv = compMgr->RegisterService(kComponentManagerCID, NS_STATIC_CAST(nsIComponentManager*, compMgr));
614 if (NS_FAILED(rv)) return rv;
615
616 // 2. Register the global services with the component manager so that
617 // clients can create new objects.
618
619 // Category Manager
620 {
621 nsCOMPtr<nsIFactory> categoryManagerFactory;
622 if ( NS_FAILED(rv = NS_CategoryManagerGetFactory(getter_AddRefs(categoryManagerFactory))) )
623 return rv;
624
625 NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
626
627 rv = compMgr->RegisterFactory(kCategoryManagerCID,
628 NS_CATEGORYMANAGER_CLASSNAME,
629 NS_CATEGORYMANAGER_CONTRACTID,
630 categoryManagerFactory,
631 PR_TRUE);
632 if ( NS_FAILED(rv) ) return rv;
633 }
634
635 // what I want to do here is QI for a Component Registration Manager. Since this
636 // has not been invented yet, QI to the obsolete manager. Kids, don't do this at home.
637 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(
638 NS_STATIC_CAST(nsIComponentManager*,compMgr), &rv);
639 if (registrar) {
640 for (int i = 0; i < components_length; i++)
641 RegisterGenericFactory(registrar, &components[i]);
642 }
643 rv = nsComponentManagerImpl::gComponentManager->ReadPersistentRegistry();
644#ifdef DEBUG
645 if (NS_FAILED(rv)) {
646 printf("No Persistent Registry Found.\n");
647 }
648#endif
649
650#if 0 /// @todo later
651 rv = IPC_Init();
652 if (NS_FAILED(rv))
653 return rv;
654#endif
655
656 if ( NS_FAILED(rv) || CheckUpdateFile()) {
657 // if we find no persistent registry, we will try to autoregister
658 // the default components directory.
659 nsComponentManagerImpl::gComponentManager->AutoRegister(nsnull);
660
661 // If the application is using a GRE, then,
662 // auto register components in the GRE directory as well.
663 //
664 // The application indicates that it's using an GRE by
665 // returning a valid nsIFile when queried (via appFileLocProvider)
666 // for the NS_GRE_DIR atom as shown below
667 //
668
669 if ( appFileLocationProvider ) {
670 nsCOMPtr<nsIFile> greDir;
671 PRBool persistent = PR_TRUE;
672
673 appFileLocationProvider->GetFile(NS_GRE_DIR, &persistent, getter_AddRefs(greDir));
674
675 if (greDir) {
676#ifdef DEBUG_dougt
677 printf("start - Registering GRE components\n");
678#endif
679 rv = gDirectoryService->Get(NS_GRE_COMPONENT_DIR,
680 NS_GET_IID(nsIFile),
681 getter_AddRefs(greDir));
682 if (NS_FAILED(rv)) {
683 NS_ERROR("Could not get GRE components directory!");
684 return rv;
685 }
686
687 // If the GRE contains any loaders, we want to know about it so that we can cause another
688 // autoregistration of the applications component directory.
689 int loaderCount = nsComponentManagerImpl::gComponentManager->GetLoaderCount();
690 rv = nsComponentManagerImpl::gComponentManager->AutoRegister(greDir);
691
692 if (loaderCount != nsComponentManagerImpl::gComponentManager->GetLoaderCount())
693 nsComponentManagerImpl::gComponentManager->AutoRegisterNonNativeComponents(nsnull);
694
695#ifdef DEBUG_dougt
696 printf("end - Registering GRE components\n");
697#endif
698 if (NS_FAILED(rv)) {
699 NS_ERROR("Could not AutoRegister GRE components");
700 return rv;
701 }
702 }
703 }
704
705 //
706 // If additional component directories have been specified, then
707 // register them as well.
708 //
709
710 nsCOMPtr<nsISimpleEnumerator> dirList;
711 gDirectoryService->Get(NS_XPCOM_COMPONENT_DIR_LIST,
712 NS_GET_IID(nsISimpleEnumerator),
713 getter_AddRefs(dirList));
714 if (dirList) {
715 PRBool hasMore;
716 while (NS_SUCCEEDED(dirList->HasMoreElements(&hasMore)) && hasMore) {
717 nsCOMPtr<nsISupports> elem;
718 dirList->GetNext(getter_AddRefs(elem));
719 if (elem) {
720 nsCOMPtr<nsIFile> dir = do_QueryInterface(elem);
721 if (dir)
722 nsComponentManagerImpl::gComponentManager->AutoRegister(dir);
723
724 // XXX should we worry about new component loaders being
725 // XXX defined by this process?
726 }
727 }
728 }
729
730
731 // Make sure the compreg file's mod time is current.
732 nsCOMPtr<nsIFile> compregFile;
733 rv = gDirectoryService->Get(NS_XPCOM_COMPONENT_REGISTRY_FILE,
734 NS_GET_IID(nsIFile),
735 getter_AddRefs(compregFile));
736 compregFile->SetLastModifiedTime(PR_Now() / 1000);
737 }
738
739 // Pay the cost at startup time of starting this singleton.
740 nsIInterfaceInfoManager* iim = XPTI_GetInterfaceInfoManager();
741 NS_IF_RELEASE(iim);
742#ifdef VBOX
743 // Must initialize the EventQueueService singleton before anyone is
744 // using it. The notification below creates a thread which races creating
745 // the EventQueueService creation otherwise, no matter what.
746 nsCOMPtr<nsIEventQueue> eventQ;
747 rv = NS_GetMainEventQ(getter_AddRefs(eventQ));
748 if (NS_FAILED(rv)) {
749 NS_ERROR("Could not create event queue for main thread");
750 /* this is just a build-time hack, to reference NS_ProxyRelease */
751 if (rv == 666)
752 NS_ProxyRelease(nsnull, nsnull);
753 return rv;
754 }
755#endif /* VBOX */
756
757 // Notify observers of xpcom autoregistration start
758 NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_OBSERVER_ID,
759 nsnull,
760 NS_XPCOM_STARTUP_OBSERVER_ID);
761
762 return NS_OK;
763}
764
765
766static nsVoidArray* gExitRoutines;
767
768static void CallExitRoutines()
769{
770 if (!gExitRoutines)
771 return;
772
773 PRInt32 count = gExitRoutines->Count();
774 for (PRInt32 i = 0; i < count; i++) {
775 XPCOMExitRoutine func = (XPCOMExitRoutine) gExitRoutines->ElementAt(i);
776 func();
777 }
778 gExitRoutines->Clear();
779 delete gExitRoutines;
780 gExitRoutines = nsnull;
781}
782
783nsresult NS_COM
784NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
785{
786 // priority are not used right now. It will need to be implemented as more
787 // classes are moved into the glue library --dougt
788 if (!gExitRoutines) {
789 gExitRoutines = new nsVoidArray();
790 if (!gExitRoutines) {
791 NS_WARNING("Failed to allocate gExitRoutines");
792 return NS_ERROR_FAILURE;
793 }
794 }
795
796 PRBool okay = gExitRoutines->AppendElement((void*)exitRoutine);
797 return okay ? NS_OK : NS_ERROR_FAILURE;
798}
799
800nsresult NS_COM
801NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
802{
803 if (!gExitRoutines)
804 return NS_ERROR_FAILURE;
805
806 PRBool okay = gExitRoutines->RemoveElement((void*)exitRoutine);
807 return okay ? NS_OK : NS_ERROR_FAILURE;
808}
809
810
811//
812// NS_ShutdownXPCOM()
813//
814// The shutdown sequence for xpcom would be
815//
816// - Release the Global Service Manager
817// - Release all service instances held by the global service manager
818// - Release the Global Service Manager itself
819// - Release the Component Manager
820// - Release all factories cached by the Component Manager
821// - Unload Libraries
822// - Release Contractid Cache held by Component Manager
823// - Release dll abstraction held by Component Manager
824// - Release the Registry held by Component Manager
825// - Finally, release the component manager itself
826//
827nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr)
828{
829
830 // Notify observers of xpcom shutting down
831 nsresult rv = NS_OK;
832 {
833 // Block it so that the COMPtr will get deleted before we hit
834 // servicemanager shutdown
835 nsCOMPtr<nsIObserverService> observerService =
836 do_GetService("@mozilla.org/observer-service;1", &rv);
837 if (NS_SUCCEEDED(rv))
838 {
839 nsCOMPtr<nsIServiceManager> mgr;
840 rv = NS_GetServiceManager(getter_AddRefs(mgr));
841 if (NS_SUCCEEDED(rv))
842 {
843 (void) observerService->NotifyObservers(mgr,
844 NS_XPCOM_SHUTDOWN_OBSERVER_ID,
845 nsnull);
846 }
847 }
848 }
849
850 // grab the event queue so that we can process events one last time before exiting
851 nsCOMPtr <nsIEventQueue> currentQ;
852 {
853 nsCOMPtr<nsIEventQueueService> eventQService =
854 do_GetService(kEventQueueServiceCID, &rv);
855
856 if (eventQService) {
857 eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(currentQ));
858 }
859 }
860 // XPCOM is officially in shutdown mode NOW
861 // Set this only after the observers have been notified as this
862 // will cause servicemanager to become inaccessible.
863 gXPCOMShuttingDown = PR_TRUE;
864
865#ifdef DEBUG_dougt
866 fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
867#endif
868
869#if 0 /// @todo later
870 IPC_Shutdown();
871#endif
872
873 // We may have AddRef'd for the caller of NS_InitXPCOM, so release it
874 // here again:
875 NS_IF_RELEASE(servMgr);
876
877 // Shutdown global servicemanager
878 if (nsComponentManagerImpl::gComponentManager) {
879 nsComponentManagerImpl::gComponentManager->FreeServices();
880 }
881 nsServiceManager::ShutdownGlobalServiceManager(nsnull);
882
883 if (currentQ) {
884 currentQ->ProcessPendingEvents();
885 currentQ = 0;
886 }
887
888 nsProxyObjectManager::Shutdown();
889
890 // Release the directory service
891 NS_IF_RELEASE(gDirectoryService);
892
893 // Shutdown nsLocalFile string conversion
894 NS_ShutdownLocalFile();
895#ifdef XP_UNIX
896 NS_ShutdownNativeCharsetUtils();
897#endif
898
899 // Shutdown the timer thread and all timers that might still be alive before
900 // shutting down the component manager
901 nsTimerImpl::Shutdown();
902
903 CallExitRoutines();
904
905 // Shutdown xpcom. This will release all loaders and cause others holding
906 // a refcount to the component manager to release it.
907 if (nsComponentManagerImpl::gComponentManager) {
908 rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
909 NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
910 } else
911 NS_WARNING("Component Manager was never created ...");
912
913 // Release our own singletons
914 // Do this _after_ shutting down the component manager, because the
915 // JS component loader will use XPConnect to call nsIModule::canUnload,
916 // and that will spin up the InterfaceInfoManager again -- bad mojo
917 XPTI_FreeInterfaceInfoManager();
918
919 // Finally, release the component manager last because it unloads the
920 // libraries:
921 if (nsComponentManagerImpl::gComponentManager) {
922 nsrefcnt cnt;
923 NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
924 NS_WARN_IF_FALSE(cnt == 0, "Component Manager being held past XPCOM shutdown.");
925 }
926 nsComponentManagerImpl::gComponentManager = nsnull;
927
928#ifdef DEBUG
929 _FreeAutoLockStatics();
930#endif
931
932 ShutdownSpecialSystemDirectory();
933
934 EmptyEnumeratorImpl::Shutdown();
935 nsMemoryImpl::Shutdown();
936 NS_IF_RELEASE(gMemory);
937
938 nsThread::Shutdown();
939 NS_PurgeAtomTable();
940
941 NS_IF_RELEASE(gDebug);
942
943#ifdef NS_BUILD_REFCNT_LOGGING
944 nsTraceRefcntImpl::DumpStatistics();
945 nsTraceRefcntImpl::ResetStatistics();
946 nsTraceRefcntImpl::Shutdown();
947#endif
948
949 return NS_OK;
950}
951
952#define GET_FUNC(_tag, _decl, _name) \
953 functions->_tag = (_decl) PR_FindSymbol(xpcomLib, _name); \
954 if (!functions->_tag) goto end
955
956nsresult NS_COM PR_CALLBACK
957NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* libraryPath)
958{
959 if (!functions)
960 return NS_ERROR_OUT_OF_MEMORY;
961
962 if (functions->version != XPCOM_GLUE_VERSION)
963 return NS_ERROR_FAILURE;
964
965 PRLibrary *xpcomLib = PR_LoadLibrary(libraryPath);
966 if (!xpcomLib)
967 return NS_ERROR_FAILURE;
968
969 nsresult rv = NS_ERROR_FAILURE;
970
971#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
972 GET_FUNC(init, InitFunc, "VBoxNsxpNS_InitXPCOM2");
973 GET_FUNC(shutdown, ShutdownFunc, "VBoxNsxpNS_ShutdownXPCOM");
974 GET_FUNC(getServiceManager, GetServiceManagerFunc, "VBoxNsxpNS_GetServiceManager");
975 GET_FUNC(getComponentManager, GetComponentManagerFunc, "VBoxNsxpNS_GetComponentManager");
976 GET_FUNC(getComponentRegistrar, GetComponentRegistrarFunc, "VBoxNsxpNS_GetComponentRegistrar");
977 GET_FUNC(getMemoryManager, GetMemoryManagerFunc, "VBoxNsxpNS_GetMemoryManager");
978 GET_FUNC(newLocalFile, NewLocalFileFunc, "VBoxNsxpNS_NewLocalFile");
979 GET_FUNC(newNativeLocalFile, NewNativeLocalFileFunc, "VBoxNsxpNS_NewNativeLocalFile");
980 GET_FUNC(registerExitRoutine, RegisterXPCOMExitRoutineFunc, "VBoxNsxpNS_RegisterXPCOMExitRoutine");
981 GET_FUNC(unregisterExitRoutine, UnregisterXPCOMExitRoutineFunc, "VBoxNsxpNS_UnregisterXPCOMExitRoutine");
982#else /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
983 GET_FUNC(init, InitFunc, "NS_InitXPCOM2");
984 GET_FUNC(shutdown, ShutdownFunc, "NS_ShutdownXPCOM");
985 GET_FUNC(getServiceManager, GetServiceManagerFunc, "NS_GetServiceManager");
986 GET_FUNC(getComponentManager, GetComponentManagerFunc, "NS_GetComponentManager");
987 GET_FUNC(getComponentRegistrar, GetComponentRegistrarFunc, "NS_GetComponentRegistrar");
988 GET_FUNC(getMemoryManager, GetMemoryManagerFunc, "NS_GetMemoryManager");
989 GET_FUNC(newLocalFile, NewLocalFileFunc, "NS_NewLocalFile");
990 GET_FUNC(newNativeLocalFile, NewNativeLocalFileFunc, "NS_NewNativeLocalFile");
991 GET_FUNC(registerExitRoutine, RegisterXPCOMExitRoutineFunc, "NS_RegisterXPCOMExitRoutine");
992 GET_FUNC(unregisterExitRoutine, UnregisterXPCOMExitRoutineFunc, "NS_UnregisterXPCOMExitRoutine");
993#endif /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
994
995 // these functions were added post 1.4 (need to check size of |functions|)
996 if (functions->size > offsetof(XPCOMFunctions, getTraceRefcnt)) {
997#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
998 GET_FUNC(getDebug, GetDebugFunc, "VBoxNsxpNS_GetDebug");
999 GET_FUNC(getTraceRefcnt, GetTraceRefcntFunc, "VBoxNsxpNS_GetTraceRefcnt");
1000#else /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
1001 GET_FUNC(getDebug, GetDebugFunc, "NS_GetDebug");
1002 GET_FUNC(getTraceRefcnt, GetTraceRefcntFunc, "NS_GetTraceRefcnt");
1003#endif /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
1004 }
1005
1006 // these functions were added post 1.6 (need to check size of |functions|)
1007 if (functions->size > offsetof(XPCOMFunctions, cstringCloneData)) {
1008#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
1009 GET_FUNC(stringContainerInit, StringContainerInitFunc, "VBoxNsxpNS_StringContainerInit");
1010 GET_FUNC(stringContainerFinish, StringContainerFinishFunc, "VBoxNsxpNS_StringContainerFinish");
1011 GET_FUNC(stringGetData, StringGetDataFunc, "VBoxNsxpNS_StringGetData");
1012 GET_FUNC(stringSetData, StringSetDataFunc, "VBoxNsxpNS_StringSetData");
1013 GET_FUNC(stringSetDataRange, StringSetDataRangeFunc, "VBoxNsxpNS_StringSetDataRange");
1014 GET_FUNC(stringCopy, StringCopyFunc, "VBoxNsxpNS_StringCopy");
1015 GET_FUNC(cstringContainerInit, CStringContainerInitFunc, "VBoxNsxpNS_CStringContainerInit");
1016 GET_FUNC(cstringContainerFinish, CStringContainerFinishFunc, "VBoxNsxpNS_CStringContainerFinish");
1017 GET_FUNC(cstringGetData, CStringGetDataFunc, "VBoxNsxpNS_CStringGetData");
1018 GET_FUNC(cstringSetData, CStringSetDataFunc, "VBoxNsxpNS_CStringSetData");
1019 GET_FUNC(cstringSetDataRange, CStringSetDataRangeFunc, "VBoxNsxpNS_CStringSetDataRange");
1020 GET_FUNC(cstringCopy, CStringCopyFunc, "VBoxNsxpNS_CStringCopy");
1021 GET_FUNC(cstringToUTF16, CStringToUTF16, "VBoxNsxpNS_CStringToUTF16");
1022 GET_FUNC(utf16ToCString, UTF16ToCString, "VBoxNsxpNS_UTF16ToCString");
1023 GET_FUNC(stringCloneData, StringCloneDataFunc, "VBoxNsxpNS_StringCloneData");
1024 GET_FUNC(cstringCloneData, CStringCloneDataFunc, "VBoxNsxpNS_CStringCloneData");
1025#else /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
1026 GET_FUNC(stringContainerInit, StringContainerInitFunc, "NS_StringContainerInit");
1027 GET_FUNC(stringContainerFinish, StringContainerFinishFunc, "NS_StringContainerFinish");
1028 GET_FUNC(stringGetData, StringGetDataFunc, "NS_StringGetData");
1029 GET_FUNC(stringSetData, StringSetDataFunc, "NS_StringSetData");
1030 GET_FUNC(stringSetDataRange, StringSetDataRangeFunc, "NS_StringSetDataRange");
1031 GET_FUNC(stringCopy, StringCopyFunc, "NS_StringCopy");
1032 GET_FUNC(cstringContainerInit, CStringContainerInitFunc, "NS_CStringContainerInit");
1033 GET_FUNC(cstringContainerFinish, CStringContainerFinishFunc, "NS_CStringContainerFinish");
1034 GET_FUNC(cstringGetData, CStringGetDataFunc, "NS_CStringGetData");
1035 GET_FUNC(cstringSetData, CStringSetDataFunc, "NS_CStringSetData");
1036 GET_FUNC(cstringSetDataRange, CStringSetDataRangeFunc, "NS_CStringSetDataRange");
1037 GET_FUNC(cstringCopy, CStringCopyFunc, "NS_CStringCopy");
1038 GET_FUNC(cstringToUTF16, CStringToUTF16, "NS_CStringToUTF16");
1039 GET_FUNC(utf16ToCString, UTF16ToCString, "NS_UTF16ToCString");
1040 GET_FUNC(stringCloneData, StringCloneDataFunc, "NS_StringCloneData");
1041 GET_FUNC(cstringCloneData, CStringCloneDataFunc, "NS_CStringCloneData");
1042#endif /* !VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
1043 }
1044
1045 rv = NS_OK;
1046end:
1047 PR_UnloadLibrary(xpcomLib); // the library is refcnt'ed above by the caller.
1048 return rv;
1049}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette