bool RegisterProtocol(const wxString &scheme, wxProtocolHandler *handler) {
    nsresult res;
    ns_smartptr<nsIComponentRegistrar> comp_reg;
    ns_smartptr<nsIServiceManager> service_mgr;
    ns_smartptr<nsIFactory> protocol_handler_factory;

    res = NS_GetComponentRegistrar(&comp_reg.p);
    if (NS_FAILED(res))
        return false;

    // XXX: Memory leak?
    wxString *contractID = new wxString(wxT(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX) + scheme);
    wxString *className = new wxString(wxT("WebConnect Protocol - ") + scheme);
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return false;
    
    ns_smartptr<nsIUUIDGenerator> uuid_generator(nsCreateInstance("@mozilla.org/uuid-generator;1"));
    // Generate a new UUID.
    nsCID *protocol_cid;
    res = uuid_generator->GenerateUUID(&protocol_cid);
    if (NS_FAILED(res))
        return false;

    // Create a factory.
    CreateProtocolHandlerFactory(scheme, handler, &protocol_handler_factory.p);
    res = comp_reg->RegisterFactory(*protocol_cid,
                                    className->ToAscii(),
                                    contractID->ToAscii(),
                                    protocol_handler_factory);

    return true;
}
예제 #2
0
NS_IMETHODIMP
nsPluginArray::Refresh(PRBool aReloadDocuments)
{
  nsresult res = NS_OK;
  if (!AllowPlugins())
    return NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;

  // refresh the component registry first, see bug 87913
  nsCOMPtr<nsIServiceManager> servManager;
  NS_GetServiceManager(getter_AddRefs(servManager));
  nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servManager);
  if (registrar)
    registrar->AutoRegister(nsnull);

  if (!mPluginHost) {
    mPluginHost = do_GetService(kPluginManagerCID, &res);
  }

  if(NS_FAILED(res)) {
    return res;
  }

  nsCOMPtr<nsIPluginManager> pm(do_QueryInterface(mPluginHost));

  // NS_ERROR_PLUGINS_PLUGINSNOTCHANGED on reloading plugins indicates
  // that plugins did not change and was not reloaded
  PRBool pluginsNotChanged = PR_FALSE;
  if(pm)
    pluginsNotChanged = (NS_ERROR_PLUGINS_PLUGINSNOTCHANGED == pm->ReloadPlugins(aReloadDocuments));

  // no need to reload the page if plugins have not been changed
  // in fact, if we do reload we can hit recursive load problem, see bug 93351
  if(pluginsNotChanged)
    return res;

  nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mDocShell);

  if (mPluginArray != nsnull) {
    for (PRUint32 i = 0; i < mPluginCount; i++) 
      NS_IF_RELEASE(mPluginArray[i]);

    delete[] mPluginArray;
  }

  mPluginCount = 0;
  mPluginArray = nsnull;

  if (mNavigator)
    mNavigator->RefreshMIMEArray();
  
  if (aReloadDocuments && webNav)
    webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);

  return res;
}
/* attribute nsIFile defaultLocalPath; */
NS_IMETHODIMP MailEwsMsgProtocolInfo::GetDefaultLocalPath(nsIFile * *aDefaultLocalPath)
{
  //TODO: load the root folder from preference
  nsCOMPtr<nsIServiceManager> servMan;
  nsresult rv = NS_GetServiceManager(getter_AddRefs(servMan));
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIProperties> properties;
  rv = servMan->GetServiceByContractID("@mozilla.org/file/directory_service;1",
                                       NS_GET_IID(nsIProperties),
                                       getter_AddRefs(properties));

  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIFile> file;

  rv = properties->Get("ProfD", NS_GET_IID(nsIFile), getter_AddRefs(file));

  if (NS_FAILED(rv))
    return rv;

  nsEmbedString data;
  data.AppendASCII("MailEws");

  rv = file->Append(data);

  if (NS_FAILED(rv))
    return rv;

  bool exists = false;

  rv = file->Exists(&exists);

  if (NS_FAILED(rv))
    return rv;

  if (!exists) {
    rv = file->Create(nsIFile::DIRECTORY_TYPE, 0775);
    
    if (NS_FAILED(rv))
      return rv;
  }

  *aDefaultLocalPath = file.get();

  NS_IF_ADDREF(*aDefaultLocalPath);
  return rv;
}
예제 #4
0
/* nsISupports getService (); */
NS_IMETHODIMP
nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
                    PRUint8 optionalArgc, JS::Value* retval)
{
    if (!mDetails.IsValid())
        return NS_ERROR_XPC_BAD_CID;

    JSObject* obj = GetWrapperObject();
    if (!obj) {
        return NS_ERROR_UNEXPECTED;
    }

    // Do the security check if necessary
    XPCContext* xpcc = XPCContext::GetXPCContext(cx);

    nsIXPCSecurityManager* sm;
    sm = xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_GET_SERVICE);
    if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID()))) {
        NS_ASSERTION(JS_IsExceptionPending(cx),
                     "security manager vetoed GetService without setting exception");
        return NS_OK;
    }

    // If an IID was passed in then use it
    const nsID* iid = GetIIDArg(optionalArgc, iidval, cx);
    if (!iid)
        return NS_ERROR_XPC_BAD_IID;

    nsCOMPtr<nsIServiceManager> svcMgr;
    nsresult rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsISupports> srvc;
    rv = svcMgr->GetService(mDetails.ID(), *iid, getter_AddRefs(srvc));
    NS_ASSERTION(NS_FAILED(rv) || srvc, "service manager returned success, but service is null!");
    if (NS_FAILED(rv) || !srvc)
        return NS_ERROR_XPC_GS_RETURNED_FAILURE;

    JSObject* instJSObj;
    nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
    rv = nsXPConnect::GetXPConnect()->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
    if (NS_FAILED(rv) || !holder || NS_FAILED(holder->GetJSObject(&instJSObj)))
        return NS_ERROR_XPC_CANT_CREATE_WN;

    *retval = OBJECT_TO_JSVAL(instJSObj);
    return NS_OK;
}
예제 #5
0
파일: nsimpl.cpp 프로젝트: BBkBlade/e
ns_smartptr<nsISupports> nsGetService(const char* contract_id)
{
    ns_smartptr<nsISupports> result;
    ns_smartptr<nsIServiceManager> service_mgr;
    nsresult res;
    
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return result;
    
    nsIID iid = NS_ISUPPORTS_IID;
    service_mgr->GetServiceByContractID(contract_id,
                                        iid,
                                        (void**)&result.p);
    
    return result;
}
예제 #6
0
파일: nsimpl.cpp 프로젝트: BBkBlade/e
ns_smartptr<nsIIOService> nsGetIOService()
{
    ns_smartptr<nsIIOService> result;
    ns_smartptr<nsIServiceManager> service_mgr;
    nsresult res;
    
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return result;
    
    nsIID iid = NS_IIOSERVICE_IID;
    service_mgr->GetServiceByContractID("@mozilla.org/network/io-service;1",
                                        iid,
                                        (void**)&result.p);
    
    return result;
}
예제 #7
0
파일: nsimpl.cpp 프로젝트: BBkBlade/e
ns_smartptr<nsIProperties> nsGetDirectoryService()
{
    ns_smartptr<nsIProperties> result;
    ns_smartptr<nsIServiceManager> service_mgr;
    nsresult res;
    
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return result;
    
    nsIID iid = NS_IPROPERTIES_IID;
    service_mgr->GetServiceByContractID("@mozilla.org/file/directory_service;1",
                                        iid,
                                        (void**)&result.p);
    
    return result;
}
예제 #8
0
파일: nsimpl.cpp 프로젝트: BBkBlade/e
ns_smartptr<nsIPref> nsGetPrefService()
{
    ns_smartptr<nsIServiceManager> service_mgr;
    ns_smartptr<nsIPref> result;
    nsresult res;
    
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return result;
    
    nsIID iid = NS_IPREF_IID;
    service_mgr->GetServiceByContractID("@mozilla.org/preferences;1",
                                        iid,
                                        (void**)&result.p);
    
    return result;
}
예제 #9
0
파일: nsimpl.cpp 프로젝트: BBkBlade/e
ns_smartptr<nsIWindowWatcher> nsGetWindowWatcherService()
{
    ns_smartptr<nsIServiceManager> service_mgr;
    ns_smartptr<nsIWindowWatcher> result;
    nsresult res;
    
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return result;
    
    nsIID iid = NS_IWINDOWWATCHER_IID;
    service_mgr->GetServiceByContractID("@mozilla.org/embedcomp/window-watcher;1",
                                        iid,
                                        (void**)&result.p);
    
    return result;
}
NS_IMETHODIMP GnomeKeyring::Init()
#endif
{
  nsresult ret;
  nsCOMPtr<nsIServiceManager> servMan;
  nsCOMPtr<nsIPrefService> prefService;
  nsCOMPtr<nsIPrefBranch> pref;
#ifdef PR_LOGGING
  gGnomeKeyringLog = PR_NewLogModule("GnomeKeyringLog");
#endif
  keyringName.AssignLiteral(kDefaultKeyring);
  ret = NS_GetServiceManager(getter_AddRefs(servMan));
  if (ret != NS_OK) { return ret; }

  ret = servMan->GetServiceByContractID("@mozilla.org/preferences-service;1",
                                        NS_GET_IID(nsIPrefService),
                                        getter_AddRefs(prefService));
  if (ret != NS_OK) { return ret; }

  ret = prefService->ReadUserPrefs(nullptr);
  if (ret != NS_OK) { return ret; }

  ret = prefService->GetBranch(kPrefsBranch, getter_AddRefs(pref));
  if (ret != NS_OK) { return ret; }

  PRInt32 prefType;
  ret = pref->GetPrefType(kPrefsKeyring, &prefType);
  if (ret != NS_OK) { return ret; }

  if (prefType == 32) {
    char* tempKeyringName;
    pref->GetCharPref(kPrefsKeyring, &tempKeyringName);
    keyringName = tempKeyringName;
    if ( keyringName.IsVoid() || keyringName.IsEmpty() ) keyringName.AssignLiteral(kDefaultKeyring);
  }

  /* Create the password keyring, it doesn't hurt if it already exists */
  GnomeKeyringResult result = gnome_keyring_create_sync(keyringName.get(), NULL);
  if ((result != GNOME_KEYRING_RESULT_OK) &&
      (result != GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS)) {
    NS_ERROR("Can't open or create password keyring!");
    return NS_ERROR_FAILURE;
  }
  return ret;
}
예제 #11
0
extern "C" NS_EXPORT jobject JNICALL
XPCOM_NATIVE(getServiceManager) (JNIEnv *env, jobject)
{
  // Call XPCOM method
  nsCOMPtr<nsIServiceManager> sm;
  nsresult rv = NS_GetServiceManager(getter_AddRefs(sm));

  if (NS_SUCCEEDED(rv)) {
    jobject javaProxy;
    rv = NativeInterfaceToJavaObject(env, sm, NS_GET_IID(nsIServiceManager),
                                     nullptr, &javaProxy);
    if (NS_SUCCEEDED(rv))
      return javaProxy;
  }

  ThrowException(env, rv, "Failure in getServiceManager");
  return nullptr;
}
nsresult
nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
    nsresult status = NS_ERROR_FAILURE;
    if ( mServiceManager ) {
        status = mServiceManager->GetService(mCID, aIID, (void**)aInstancePtr);
    } else {
        nsCOMPtr<nsIServiceManager> mgr;
        NS_GetServiceManager(getter_AddRefs(mgr));
        if (mgr)
            status = mgr->GetService(mCID, aIID, (void**)aInstancePtr);
    }
    if ( NS_FAILED(status) )
        *aInstancePtr = 0;

    if ( mErrorPtr )
        *mErrorPtr = status;
    return status;
}
NS_IMETHODIMP nsProtocolHandlerImpl::NewChannel(nsIURI *aURI, nsIChannel **_retval)
{
    ns_smartptr<nsIServiceManager> service_mgr;
    nsresult res;
    res = NS_GetServiceManager(&service_mgr.p);
    if (NS_FAILED(res))
        return res;
    
    ns_smartptr<nsIInputStreamChannel> input_stream_channel(nsCreateInstance("@mozilla.org/network/input-stream-channel;1"));
    ns_smartptr<nsIChannel> channel(input_stream_channel);

    nsCString nsspec;
    res = aURI->GetSpec(nsspec);
    if (NS_FAILED(res))
        return res;

    wxString wxSpec = ns2wx(nsspec);

    nsCString nsContentType;
    nsString nsContent;

    wxString contentType = m_handler->GetContentType(wxSpec);
    wxString content = m_handler->GetContent(wxSpec);
    wx2ns(contentType, nsContentType);
    wx2ns(content, nsContent);

    channel->SetContentType(nsContentType);
    /* XXX: Is UTF-8 the best encoding all the time? */
    channel->SetContentCharset(NS_LITERAL_CSTRING("utf-8"));
    input_stream_channel->SetURI(aURI);
    
    ns_smartptr<nsIScriptableUnicodeConverter> unicode_converter(nsCreateInstance("@mozilla.org/intl/scriptableunicodeconverter"));
    unicode_converter->SetCharset("UTF-8");
    nsIInputStream* input_stream;
    res = unicode_converter->ConvertToInputStream(nsContent, &input_stream);
    if (NS_FAILED(res))
        return res;
    input_stream_channel->SetContentStream(input_stream);
    
    *_retval = channel;
	NS_ADDREF(*_retval);
    return NS_OK;
}
예제 #14
0
nsBrowserListener::nsBrowserListener()
     :mBro(nsnull),
      running(NOT_RUN),
      brwStop(false),
      WinStop(true),
      docStop(true),
      NetStop(true),
      browError(true),
      interTime(0.3),
      timeCount(0),
      isScrolled(false),
      scroolWait(-1),
      evenWait(false),
      LastDoc(nsnull),
      isred(false),
      cid(0),
      MaxAccCount(20)
{
     
     nsresult rv = NS_GetServiceManager(getter_AddRefs(servMan));
     if (NS_FAILED(rv))
     {
          std::cout<<"Get manager Error:"<<rv<<std::endl;
     }
     rv=servMan->GetServiceByContractID("@mozilla.org/network/io-service;1", NS_GET_IID(nsIIOService), getter_AddRefs(iio));
     
     if (NS_FAILED(rv))
     {
	  std::cout<<"Get ioservice  Error:"<<std::hex<<rv<<std::endl;
     }
     
     timeOut=do_CreateInstance("@mozilla.org/timer;1", &rv);
     if (NS_FAILED(rv)) 
     {
	  std::cout<<"Get Timmer Error:"<<rv<<std::endl;
     }
     rv=servMan->GetServiceByContractID("@mozilla.org/cookieService;1",  NS_GET_IID(nsICookieService),getter_AddRefs(cookServ));
     if (NS_FAILED(rv)) 
     {
	  std::cout<<"Get nsicookieservice Error:"<<rv<<std::endl;
     }
}
예제 #15
0
NS_EXPORT
nsresult
iPlugletEngine::GetInstance(void ** result)
{
    nsIServiceManager *servman = nsnull;
    NS_GetServiceManager(&servman);
    nsresult rv;
    rv = servman->GetServiceByContractID(PLUGLETENGINE_ContractID,
                                         NS_GET_IID(iPlugletEngine),
                                         (void **) &result);

    if (NS_FAILED(rv)) {
        PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
               ("Pluglet::PlugletFactory: Cannot access iPlugletEngine service\n"));
        return rv;
    }


    return NS_OK;
}
nsresult
ShutdownXPCOM(nsIServiceManager* servMgr)
{
    // Make sure the hang monitor is enabled for shutdown.
    HangMonitor::NotifyActivity();

    NS_ENSURE_STATE(NS_IsMainThread());

    nsresult rv;
    nsCOMPtr<nsISimpleEnumerator> moduleLoaders;

    // Notify observers of xpcom shutting down
    {
        // Block it so that the COMPtr will get deleted before we hit
        // servicemanager shutdown

        nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
        NS_ENSURE_STATE(thread);

        nsRefPtr<nsObserverService> observerService;
        CallGetService("@mozilla.org/observer-service;1",
                       (nsObserverService**) getter_AddRefs(observerService));

        if (observerService)
        {
            (void) observerService->
                NotifyObservers(nullptr, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID,
                                nullptr);

            nsCOMPtr<nsIServiceManager> mgr;
            rv = NS_GetServiceManager(getter_AddRefs(mgr));
            if (NS_SUCCEEDED(rv))
            {
                (void) observerService->
                    NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                                    nullptr);
            }
        }

        NS_ProcessPendingEvents(thread);
        mozilla::scache::StartupCache::DeleteSingleton();
        if (observerService)
            (void) observerService->
                NotifyObservers(nullptr, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID,
                                nullptr);

        nsCycleCollector_shutdownThreads();

        NS_ProcessPendingEvents(thread);

        // Shutdown the timer thread and all timers that might still be alive before
        // shutting down the component manager
        nsTimerImpl::Shutdown();

        NS_ProcessPendingEvents(thread);

        // Shutdown all remaining threads.  This method does not return until
        // all threads created using the thread manager (with the exception of
        // the main thread) have exited.
        nsThreadManager::get()->Shutdown();

        NS_ProcessPendingEvents(thread);

        HangMonitor::NotifyActivity();

        // We save the "xpcom-shutdown-loaders" observers to notify after
        // the observerservice is gone.
        if (observerService) {
            observerService->
                EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
                                   getter_AddRefs(moduleLoaders));

            observerService->Shutdown();
        }
    }

    // Free ClearOnShutdown()'ed smart pointers.  This needs to happen *after*
    // we've finished notifying observers of XPCOM shutdown, because shutdown
    // observers themselves might call ClearOnShutdown().
    mozilla::KillClearOnShutdown();

    // XPCOM is officially in shutdown mode NOW
    // Set this only after the observers have been notified as this
    // will cause servicemanager to become inaccessible.
    mozilla::services::Shutdown();

#ifdef DEBUG_dougt
    fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
#endif
    // We may have AddRef'd for the caller of NS_InitXPCOM, so release it
    // here again:
    NS_IF_RELEASE(servMgr);

    // Shutdown global servicemanager
    if (nsComponentManagerImpl::gComponentManager) {
        nsComponentManagerImpl::gComponentManager->FreeServices();
    }

    // Release the directory service
    NS_IF_RELEASE(nsDirectoryService::gService);

    SAMPLE_MARKER("Shutdown xpcom");
    mozilla::PoisonWrite();

    nsCycleCollector_shutdown();

    if (moduleLoaders) {
        bool more;
        nsCOMPtr<nsISupports> el;
        while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) &&
               more) {
            moduleLoaders->GetNext(getter_AddRefs(el));

            // Don't worry about weak-reference observers here: there is
            // no reason for weak-ref observers to register for
            // xpcom-shutdown-loaders

            nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
            if (obs)
                (void) obs->Observe(nullptr,
                                    NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
                                    nullptr);
        }

        moduleLoaders = nullptr;
    }

    // Shutdown nsLocalFile string conversion
    NS_ShutdownLocalFile();
#ifdef XP_UNIX
    NS_ShutdownNativeCharsetUtils();
#endif

    // Shutdown xpcom. This will release all loaders and cause others holding
    // a refcount to the component manager to release it.
    if (nsComponentManagerImpl::gComponentManager) {
        rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
        NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
    } else
        NS_WARNING("Component Manager was never created ...");

    // Release our own singletons
    // Do this _after_ shutting down the component manager, because the
    // JS component loader will use XPConnect to call nsIModule::canUnload,
    // and that will spin up the InterfaceInfoManager again -- bad mojo
    xptiInterfaceInfoManager::FreeInterfaceInfoManager();

    // Finally, release the component manager last because it unloads the
    // libraries:
    if (nsComponentManagerImpl::gComponentManager) {
      nsrefcnt cnt;
      NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
      NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
    }
    nsComponentManagerImpl::gComponentManager = nullptr;
    nsCategoryManager::Destroy();

    NS_PurgeAtomTable();

    NS_IF_RELEASE(gDebug);

    if (sIOThread) {
        delete sIOThread;
        sIOThread = nullptr;
    }
    if (sMessageLoop) {
        delete sMessageLoop;
        sMessageLoop = nullptr;
    }
    if (sCommandLineWasInitialized) {
        CommandLine::Terminate();
        sCommandLineWasInitialized = false;
    }
    if (sExitManager) {
        delete sExitManager;
        sExitManager = nullptr;
    }

    Omnijar::CleanUp();

    HangMonitor::Shutdown();

    eventtracer::Shutdown();

    NS_LogTerm();

    return NS_OK;
}
예제 #17
0
/* nsISupports getService (); */
NS_IMETHODIMP
nsJSCID::GetService(nsISupports **_retval)
{
    if(!mDetails.IsValid())
        return NS_ERROR_XPC_BAD_CID;

    nsXPConnect* xpc = nsXPConnect::GetXPConnect();
    if(!xpc)
        return NS_ERROR_UNEXPECTED;

    nsAXPCNativeCallContext *ccxp = nsnull;
    xpc->GetCurrentNativeCallContext(&ccxp);
    if(!ccxp)
        return NS_ERROR_UNEXPECTED;

    PRUint32 argc;
    jsval * argv;
    jsval * vp;
    JSContext* cx;
    JSObject* obj;

    ccxp->GetJSContext(&cx);
    ccxp->GetArgc(&argc);
    ccxp->GetArgvPtr(&argv);
    ccxp->GetRetValPtr(&vp);

    nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
    ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
    wrapper->GetJSObject(&obj);

    // Do the security check if necessary

    XPCContext* xpcc = XPCContext::GetXPCContext(cx);

    nsIXPCSecurityManager* sm;
    sm = xpcc->GetAppropriateSecurityManager(
                        nsIXPCSecurityManager::HOOK_GET_SERVICE);
    if(sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID())))
    {
        NS_ASSERTION(JS_IsExceptionPending(cx),
                     "security manager vetoed GetService without setting exception");
        return NS_OK;
    }

    // If an IID was passed in then use it
    const nsID* iid = GetIIDArg(argc, argv, cx);
    if (!iid)
        return NS_ERROR_XPC_BAD_IID;

    nsCOMPtr<nsIServiceManager> svcMgr;
    nsresult rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsISupports> srvc;
    rv = svcMgr->GetService(mDetails.ID(), *iid, getter_AddRefs(srvc));
    NS_ASSERTION(NS_FAILED(rv) || srvc, "service manager returned success, but service is null!");
    if(NS_FAILED(rv) || !srvc)
        return NS_ERROR_XPC_GS_RETURNED_FAILURE;

    JSObject* instJSObj;
    nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
    rv = xpc->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
    if(NS_FAILED(rv) || !holder || NS_FAILED(holder->GetJSObject(&instJSObj)))
        return NS_ERROR_XPC_CANT_CREATE_WN;

    *vp = OBJECT_TO_JSVAL(instJSObj);
    ccxp->SetReturnValueWasSet(JS_TRUE);
    return NS_OK;
}
예제 #18
0
nsresult
ShutdownXPCOM(nsIServiceManager* aServMgr)
{
  // Make sure the hang monitor is enabled for shutdown.
  HangMonitor::NotifyActivity();

  if (!NS_IsMainThread()) {
    NS_RUNTIMEABORT("Shutdown on wrong thread");
  }

  nsresult rv;
  nsCOMPtr<nsISimpleEnumerator> moduleLoaders;

  // Notify observers of xpcom shutting down
  {
    // Block it so that the COMPtr will get deleted before we hit
    // servicemanager shutdown

    nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
    if (NS_WARN_IF(!thread)) {
      return NS_ERROR_UNEXPECTED;
    }

    RefPtr<nsObserverService> observerService;
    CallGetService("@mozilla.org/observer-service;1",
                   (nsObserverService**)getter_AddRefs(observerService));

    if (observerService) {
      observerService->NotifyObservers(nullptr,
                                       NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID,
                                       nullptr);

      nsCOMPtr<nsIServiceManager> mgr;
      rv = NS_GetServiceManager(getter_AddRefs(mgr));
      if (NS_SUCCEEDED(rv)) {
        observerService->NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
                                         nullptr);
      }
    }

    // This must happen after the shutdown of media and widgets, which
    // are triggered by the NS_XPCOM_SHUTDOWN_OBSERVER_ID notification.
    NS_ProcessPendingEvents(thread);
    gfxPlatform::ShutdownLayersIPC();

    mozilla::scache::StartupCache::DeleteSingleton();
    if (observerService)
      observerService->NotifyObservers(nullptr,
                                       NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID,
                                       nullptr);

    gXPCOMThreadsShutDown = true;
    NS_ProcessPendingEvents(thread);

    // Shutdown the timer thread and all timers that might still be alive before
    // shutting down the component manager
    nsTimerImpl::Shutdown();

    NS_ProcessPendingEvents(thread);

    // Shutdown all remaining threads.  This method does not return until
    // all threads created using the thread manager (with the exception of
    // the main thread) have exited.
    nsThreadManager::get()->Shutdown();

    NS_ProcessPendingEvents(thread);

    HangMonitor::NotifyActivity();

    // Late-write checks needs to find the profile directory, so it has to
    // be initialized before mozilla::services::Shutdown or (because of
    // xpcshell tests replacing the service) modules being unloaded.
    mozilla::InitLateWriteChecks();

    // We save the "xpcom-shutdown-loaders" observers to notify after
    // the observerservice is gone.
    if (observerService) {
      observerService->EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
                                          getter_AddRefs(moduleLoaders));

      observerService->Shutdown();
    }
  }

  // Free ClearOnShutdown()'ed smart pointers.  This needs to happen *after*
  // we've finished notifying observers of XPCOM shutdown, because shutdown
  // observers themselves might call ClearOnShutdown().
  mozilla::KillClearOnShutdown();

  // XPCOM is officially in shutdown mode NOW
  // Set this only after the observers have been notified as this
  // will cause servicemanager to become inaccessible.
  mozilla::services::Shutdown();

#ifdef DEBUG_dougt
  fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
#endif
  // We may have AddRef'd for the caller of NS_InitXPCOM, so release it
  // here again:
  NS_IF_RELEASE(aServMgr);

  // Shutdown global servicemanager
  if (nsComponentManagerImpl::gComponentManager) {
    nsComponentManagerImpl::gComponentManager->FreeServices();
  }

  // Release the directory service
  NS_IF_RELEASE(nsDirectoryService::gService);

  free(gGREBinPath);
  gGREBinPath = nullptr;

  if (moduleLoaders) {
    bool more;
    nsCOMPtr<nsISupports> el;
    while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) && more) {
      moduleLoaders->GetNext(getter_AddRefs(el));

      // Don't worry about weak-reference observers here: there is
      // no reason for weak-ref observers to register for
      // xpcom-shutdown-loaders

      // FIXME: This can cause harmless writes from sqlite committing
      // log files. We have to ignore them before we can move
      // the mozilla::PoisonWrite call before this point. See bug
      // 834945 for the details.
      nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
      if (obs) {
        obs->Observe(nullptr, NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID, nullptr);
      }
    }

    moduleLoaders = nullptr;
  }

  nsCycleCollector_shutdown();

  layers::AsyncTransactionTrackersHolder::Finalize();

  PROFILER_MARKER("Shutdown xpcom");
  // If we are doing any shutdown checks, poison writes.
  if (gShutdownChecks != SCM_NOTHING) {
#ifdef XP_MACOSX
    mozilla::OnlyReportDirtyWrites();
#endif /* XP_MACOSX */
    mozilla::BeginLateWriteChecks();
  }

  // Shutdown nsLocalFile string conversion
  NS_ShutdownLocalFile();
#ifdef XP_UNIX
  NS_ShutdownNativeCharsetUtils();
#endif

#if defined(XP_WIN)
  // This exit(0) call is intended to be temporary, to get shutdown leak
  // checking working on Linux.
  // On Windows XP debug, there are intermittent failures in
  // dom/media/tests/mochitest/test_peerConnection_basicH264Video.html
  // if we don't exit early in a child process. See bug 1073310.
  if (XRE_IsContentProcess() && !IsVistaOrLater()) {
      NS_WARNING("Exiting child process early!");
      exit(0);
  }
#endif

  // Shutdown xpcom. This will release all loaders and cause others holding
  // a refcount to the component manager to release it.
  if (nsComponentManagerImpl::gComponentManager) {
    rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
    NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
  } else {
    NS_WARNING("Component Manager was never created ...");
  }

#ifdef MOZ_ENABLE_PROFILER_SPS
  // In optimized builds we don't do shutdown collections by default, so
  // uncollected (garbage) objects may keep the nsXPConnect singleton alive,
  // and its XPCJSRuntime along with it. However, we still destroy various
  // bits of state in JS_ShutDown(), so we need to make sure the profiler
  // can't access them when it shuts down. This call nulls out the
  // JS pseudo-stack's internal reference to the main thread JSRuntime,
  // duplicating the call in XPCJSRuntime::~XPCJSRuntime() in case that
  // never fired.
  if (PseudoStack* stack = mozilla_get_pseudo_stack()) {
    stack->sampleRuntime(nullptr);
  }
#endif

  // Shut down the JS engine.
  JS_ShutDown();

  // Release our own singletons
  // Do this _after_ shutting down the component manager, because the
  // JS component loader will use XPConnect to call nsIModule::canUnload,
  // and that will spin up the InterfaceInfoManager again -- bad mojo
  XPTInterfaceInfoManager::FreeInterfaceInfoManager();

  // Finally, release the component manager last because it unloads the
  // libraries:
  if (nsComponentManagerImpl::gComponentManager) {
    nsrefcnt cnt;
    NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
    NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
  }
  nsComponentManagerImpl::gComponentManager = nullptr;
  nsCategoryManager::Destroy();

  NS_PurgeAtomTable();

  NS_IF_RELEASE(gDebug);

  delete sIOThread;
  sIOThread = nullptr;

  delete sMessageLoop;
  sMessageLoop = nullptr;

  if (sCommandLineWasInitialized) {
    CommandLine::Terminate();
    sCommandLineWasInitialized = false;
  }

  delete sExitManager;
  sExitManager = nullptr;

  Omnijar::CleanUp();

  HangMonitor::Shutdown();

  delete sMainHangMonitor;
  sMainHangMonitor = nullptr;

  BackgroundHangMonitor::Shutdown();

  profiler_shutdown();

  NS_LogTerm();

#if defined(MOZ_WIDGET_GONK)
  // This exit(0) call is intended to be temporary, to get shutdown leak
  // checking working on Linux.
  // On debug B2G, the child process crashes very late.  Instead, just
  // give up so at least we exit cleanly. See bug 1071866.
  if (XRE_IsContentProcess()) {
      NS_WARNING("Exiting child process early!");
      exit(0);
  }
#endif

  return NS_OK;
}
예제 #19
0
gluezilla_getServiceManager()
{
	nsCOMPtr<nsIServiceManager> servMan;
	NS_GetServiceManager (getter_AddRefs (servMan));
	return servMan;
}
예제 #20
0
int main(int argc, char** argv) {
     GtkWidget *window=NULL;
     GtkWidget *vbox=NULL;
     nsCOMPtr<nsIServiceManager> servMan;
    
     nsCOMPtr<nsILocalFile> libxul;
     nsIWebNavigation *webNavigation;
     int cid=0;
     std::string lstStr("");
     int mozSet=0;
     std::string xulPath(XUL_PATH);
     std::string xulrunPath(XUL_BIN);
     std::string soapServer;
     int maxDoc=20;
     if(argc<2)
     {
	  usage();
	  return 0;
     }
     bool isCraw=true;
     int opt;
     while((opt = getopt(argc, argv, "n:i:c:l:r:t:s:b:S:CG")) != -1) {
	  switch(opt) {
	  case 'C':
	       isCraw=true;
	       break;
	  case 'G':
	       isCraw=false;
	       break;
	  case 'c':
	       cid=atoi(optarg);
	       break;
	  case 'n':
	       maxDoc=atoi(optarg);
	       break;
	  case 'l':
	       
	       lstStr=std::string(optarg);
	       break;
	  case 'r':
	       mozSet=atoi(optarg);
	       break;
	  case 's':
	       xulPath=std::string(optarg);
	       break;
	  case 'S':
	       soapServer=std::string(optarg);
	       break;
	  case 'b':
	       xulrunPath=std::string(optarg);
	       break;
	  default:
	       usage();
	  }
     }
     if(lstStr.length()==0||lstStr.length()==0)
     {
	  usage();
     }
     nsDynamicFunctionLoad nsFuncs[] = {
	  {"XRE_InitEmbedding", (NSFuncPtr*)&XRE_InitEmbedding},
	  {"XRE_TermEmbedding", (NSFuncPtr*)
	   &XRE_TermEmbedding},
	  {0, 0}
     };
     nsresult rv;
     //create native window
     gtk_init (&argc, &argv);
     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     GTKEmbedGlueStartup();
     GTKEmbedGlueStartupInternal();

     gtk_widget_set_usize(window, 1280,1024);
     vbox = gtk_vbox_new(TRUE, 0);
     gtk_container_add(GTK_CONTAINER(window), vbox);
     gtk_widget_show(window);
     gtk_widget_show(vbox);
     //init standalone env
     rv = XPCOMGlueStartup(xulPath.c_str());
     if (NS_FAILED(rv)) {
	  printf("XPCOMGlueStartup\n");
     }
     rv = XPCOMGlueLoadXULFunctions(nsFuncs);
     if (NS_FAILED(rv)) {
	  printf("XPCOMGlueLoadXULFunctions\n");
     }
     rv = NS_NewNativeLocalFile(nsEmbedCString(xulrunPath.c_str()),
				PR_FALSE, getter_AddRefs(libxul));
     if (NS_FAILED(rv)) {
	  printf("NS_NewNativeLocalFile\n");
     }
     rv = XRE_InitEmbedding(libxul, 0, 0, 0, 0);
     if (NS_FAILED(rv)) {
	  printf("XRE_InitEmbedding\n");
     }

     rv = NS_GetServiceManager(getter_AddRefs(servMan)); 
     if (NS_FAILED(rv)) 
     {
	  std::cout<<"Get manager Error:"<<rv<<std::endl;
     }
     nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
     rv=registrar->AutoRegister(nsnull); 
     if (NS_FAILED(rv)) 
     {
	  std::cout<<"Get manager Error:"<<rv<<std::endl;
     }
     mozilla_prefs_set_string (servMan,"general.useragent.override", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.8) Gecko/2009032600 SUSE/3.0.8-1.1 Firefox/3.0.8");
     nsCOMPtr<nsIStatManager> sm=do_CreateInstance(lstStr.c_str(),&rv);
     if (NS_FAILED(rv))
     {
	  std::cout<<"Get stat manager Error:"<<std::hex<<rv<<std::endl;
	  return 0;    
     }
     nsCOMPtr<nsISoapInter> inter=do_CreateInstance("@nyapc.com/XPCOM/nsSoapInter;1",&rv);
     if (NS_FAILED(rv)) 
     {
	  std::cout<<"Init Soap Inter error\n";
	  return 0;    
     }
     if(soapServer.length()>0)
	  inter->SetAddress(nsCString(soapServer.c_str()));
     nsCOMPtr<nsISoapTask> task;
     if(isCraw)
	  inter->GetTask(cid,maxDoc,getter_AddRefs(task));
     else
	  inter->GetWrapTask(cid,maxDoc,getter_AddRefs(task));
     sm->SetInter(inter);
     std::list<gtkBrowser> bList;
     if(task!=nsnull)
     {
 	  sm->SetTask(task);
 	  PRInt32 len;
 	  task->GetUrlCount(&len);
 	  for(PRInt32 index=0;index<len;index++)
 	  {
 	       int Uid;
 	       nsCString aurl;
 	       task->GetUrlByIndex(index,&Uid,aurl);
	       gtkBrowser gb(vbox,Uid);

	       gb.SetListener(sm);
	       gb.SetRunlevel(mozSet);
	       gb.SetUrl(aurl);
 	       bList.push_back(gb);
 	  }
     
 	  for(std::list<gtkBrowser>::iterator it=bList.begin();it!=bList.end();++it)
 	       it->Start();
     }else
     {
	  sleep(60);
	  exit(0);
     }
     gtk_widget_hide(vbox);
     gtk_widget_hide(window);
     /**********set listener***********/

     
     std::cout<<"Crawler ID:"<<cid<<std::endl;
     
     
     
     
     
     gtk_main();
     
     XRE_TermEmbedding();
     XPCOMGlueShutdown();
     return 0;

}