Bug 586836 - Support Meego Network Managment. r=doug.turner a=blocking-fennec

--HG--
extra : rebase_source : 1f8de52621ce8c6dc680e81a3b82bc8f5e3df57e
This commit is contained in:
jeremias bosch 2010-08-30 23:23:35 -07:00
Родитель febde24fc8
Коммит 2ffe49d1e9
16 изменённых файлов: 647 добавлений и 12 удалений

Просмотреть файл

@ -530,6 +530,7 @@ MOZ_GTK2_LIBS = @MOZ_GTK2_LIBS@
MOZ_QT_CFLAGS = @MOZ_QT_CFLAGS@
MOZ_QT_LIBS = @MOZ_QT_LIBS@
MOZ_ENABLE_QTNETWORK = @MOZ_ENABLE_QTNETWORK@
MOZ_ENABLE_MEEGOTOUCH = @MOZ_ENABLE_MEEGOTOUCH@
MOZ_DBUS_CFLAGS = @MOZ_DBUS_CFLAGS@

Просмотреть файл

@ -5319,6 +5319,16 @@ then
incorrect])
fi
MOC=$HOST_MOC
MOZ_ENABLE_QTNETWORK=
PKG_CHECK_MODULES(_QTNETWORK, QtNetwork >= 4.7,
MOZ_ENABLE_QTNETWORK=1,
MOZ_ENABLE_QTNETWORK=)
if test "$MOZ_ENABLE_QTNETWORK"; then
MOZ_ENABLE_QTNETWORK=1
AC_DEFINE(MOZ_ENABLE_QTNETWORK)
fi
fi
AC_SUBST(GTK_CONFIG)
@ -5328,6 +5338,7 @@ AC_SUBST(TK_LIBS)
AC_SUBST(MOZ_ENABLE_GTK2)
AC_SUBST(MOZ_ENABLE_PHOTON)
AC_SUBST(MOZ_ENABLE_QT)
AC_SUBST(MOZ_ENABLE_QTNETWORK)
AC_SUBST(MOZ_ENABLE_XREMOTE)
AC_SUBST(MOZ_GTK2_CFLAGS)
AC_SUBST(MOZ_GTK2_LIBS)
@ -6799,9 +6810,17 @@ MOZ_ARG_DISABLE_BOOL(zipwriter,
AC_SUBST(MOZ_ZIPWRITER)
dnl ========================================================
dnl = Disable libconic
dnl = libconic
dnl ========================================================
dnl superseded by QtNetwork starting from 4.7
MOZ_ENABLE_LIBCONIC=1
if test -n "$MOZ_ENABLE_QT"; then
if test "$MOZ_ENABLE_QTNETWORK"; then
MOZ_ENABLE_LIBCONIC=
fi
fi
MOZ_ARG_DISABLE_BOOL(libconic,
[ --disable-libconic Disable libconic],
MOZ_ENABLE_LIBCONIC=,

Просмотреть файл

@ -97,11 +97,6 @@ CPPSRCS = \
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
CPPSRCS += nsURLHelperOS2.cpp
else
ifdef MOZ_ENABLE_LIBCONIC
CPPSRCS += nsAutodialMaemo.cpp
CPPSRCS += nsNativeConnectionHelper.cpp
LOCAL_INCLUDES += -I$(srcdir)/../../system/maemo
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
CPPSRCS += nsURLHelperWin.cpp
CPPSRCS += nsNativeConnectionHelper.cpp
@ -119,6 +114,18 @@ endif
endif
endif
ifdef MOZ_PLATFORM_MAEMO
CPPSRCS += nsNativeConnectionHelper.cpp
ifdef MOZ_ENABLE_LIBCONIC
CPPSRCS += nsAutodialMaemo.cpp
LOCAL_INCLUDES += -I$(srcdir)/../../system/maemo
endif
ifdef MOZ_ENABLE_QTNETWORK
CPPSRCS += nsAutodialQt.cpp
LOCAL_INCLUDES += -I$(srcdir)/../../system/qt
endif
endif
EXTRA_COMPONENTS = \
$(srcdir)/nsProxyAutoConfig.js \
$(srcdir)/nsProxyAutoConfig.manifest \

Просмотреть файл

@ -0,0 +1,77 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Nokia Corporation Code.
*
* The Initial Developer of the Original Code is
* Nokia Corporation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jeremias Bosch <jeremias.bosch@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsAutodialQt.h"
#include "nsNetCID.h"
#include "nsCOMPtr.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
#include "nsQtNetworkManager.h"
nsAutodial::nsAutodial()
{
}
nsAutodial::~nsAutodial()
{
}
nsresult
nsAutodial::Init()
{
return NS_OK;
}
nsresult
nsAutodial::DialDefault(const PRUnichar* hostName)
{
if (nsQtNetworkManager::OpenConnectionSync())
return NS_OK;
return NS_ERROR_FAILURE;
}
PRBool
nsAutodial::ShouldDialOnNetworkError()
{
if (nsQtNetworkManager::IsConnected())
return PR_FALSE;
return PR_TRUE;
}

Просмотреть файл

@ -0,0 +1,59 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Nokia Corporation Code.
*
* The Initial Developer of the Original Code is
* Nokia Corporation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jeremias Bosch <jeremias.bosch@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSAUTODIALQT
#define NSAUTODIALQT
#include "nspr.h"
#include "nscore.h"
class nsAutodial
{
public:
nsAutodial();
~nsAutodial();
nsresult Init();
// Dial the default RAS dialup connection.
nsresult DialDefault(const PRUnichar* hostName);
// Should we try to dial on network error?
PRBool ShouldDialOnNetworkError();
};
#endif /* NSAUTODIALQT */

Просмотреть файл

@ -78,7 +78,7 @@
#include "mozilla/FunctionTimer.h"
#if defined(XP_WIN) || defined(MOZ_ENABLE_LIBCONIC)
#if defined(XP_WIN) || defined(MOZ_PLATFORM_MAEMO)
#include "nsNativeConnectionHelper.h"
#endif
@ -1077,7 +1077,7 @@ nsIOService::TrackNetworkLinkStatusForOffline()
// option is set to always autodial. If so, then we are
// always up for the purposes of offline management.
if (autodialEnabled) {
#if defined(XP_WIN) || defined(MOZ_ENABLE_LIBCONIC)
#if defined(XP_WIN) || defined(MOZ_PLATFORM_MAEMO)
// On Windows and Maemo (libconic) we should first check with the OS
// to see if autodial is enabled. If it is enabled then we are
// allowed to manage the offline state.

Просмотреть файл

@ -38,7 +38,7 @@
#include "nsNativeConnectionHelper.h"
#if defined(MOZ_ENABLE_LIBCONIC)
#if defined(MOZ_PLATFORM_MAEMO)
#include "nsAutodialMaemo.h"
#elif defined(WINCE)
#include "nsAutodialWinCE.h"
@ -59,7 +59,7 @@ nsNativeConnectionHelper::OnConnectionFailed(const PRUnichar* hostName)
// should ask the dialer directly. This allows the dialer to update
// link status more forcefully rather than passively watching link
// status changes.
#if !defined(MOZ_ENABLE_LIBCONIC) && !defined(WINCE_WINDOWS_MOBILE)
#if !defined(MOZ_PLATFORM_MAEMO) && !defined(WINCE_WINDOWS_MOBILE)
if (gIOService->IsLinkUp())
return PR_FALSE;
#endif

Просмотреть файл

@ -71,7 +71,7 @@
#include "nsIProgrammingLanguage.h"
#include "nsIClassInfoImpl.h"
#if defined(XP_WIN) || defined(MOZ_ENABLE_LIBCONIC)
#if defined(XP_WIN) || defined(MOZ_PLATFORM_MAEMO)
#include "nsNativeConnectionHelper.h"
#endif
@ -1272,7 +1272,7 @@ nsSocketTransport::RecoverFromError()
}
}
#if defined(XP_WIN) || defined(MOZ_ENABLE_LIBCONIC)
#if defined(XP_WIN) || defined(MOZ_PLATFORM_MAEMO)
// If not trying next address, try to make a connection using dialup.
// Retry if that connection is made.
if (!tryAgain) {

Просмотреть файл

@ -90,6 +90,11 @@ ifdef MOZ_ENABLE_LIBCONIC
../system/maemo/$(LIB_PREFIX)neckosystem_s.$(LIB_SUFFIX)
endif
ifdef MOZ_ENABLE_QTNETWORK
SHARED_LIBRARY_LIBS += \
../system/qt/$(LIB_PREFIX)neckosystem_s.$(LIB_SUFFIX)
endif
LOCAL_INCLUDES = \
-I$(srcdir)/../base/src \
-I$(srcdir)/../dns \
@ -119,6 +124,10 @@ ifdef MOZ_ENABLE_LIBCONIC
LOCAL_INCLUDES += -I$(srcdir)/../system/maemo
endif
ifdef MOZ_ENABLE_QTNETWORK
LOCAL_INCLUDES += -I$(srcdir)/../system/qt
endif
ifdef NECKO_COOKIES
SHARED_LIBRARY_LIBS += \
../cookie/$(LIB_PREFIX)neckocookie_s.$(LIB_SUFFIX) \

Просмотреть файл

@ -303,6 +303,9 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNetworkLinkService, Init)
#elif defined(MOZ_ENABLE_LIBCONIC)
#include "nsMaemoNetworkLinkService.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMaemoNetworkLinkService, Init)
#elif defined(MOZ_ENABLE_QTNETWORK)
#include "nsQtNetworkLinkService.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsQtNetworkLinkService, Init)
#endif
///////////////////////////////////////////////////////////////////////////////
@ -723,6 +726,8 @@ NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
#elif defined(MOZ_ENABLE_LIBCONIC)
NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
#elif defined(MOZ_ENABLE_QTNETWORK)
NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
#endif
static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
@ -841,6 +846,8 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_NETWORK_LINK_SERVICE_CID, false, NULL, nsNetworkLinkServiceConstructor },
#elif defined(MOZ_ENABLE_LIBCONIC)
{ &kNS_NETWORK_LINK_SERVICE_CID, false, NULL, nsMaemoNetworkLinkServiceConstructor },
#elif defined(MOZ_ENABLE_QTNETWORK)
{ &kNS_NETWORK_LINK_SERVICE_CID, false, NULL, nsQtNetworkLinkServiceConstructor },
#endif
{ NULL }
};
@ -966,6 +973,8 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_NETWORK_LINK_SERVICE_CONTRACTID, &kNS_NETWORK_LINK_SERVICE_CID },
#elif defined(MOZ_ENABLE_LIBCONIC)
{ NS_NETWORK_LINK_SERVICE_CONTRACTID, &kNS_NETWORK_LINK_SERVICE_CID },
#elif defined(MOZ_ENABLE_QTNETWORK)
{ NS_NETWORK_LINK_SERVICE_CONTRACTID, &kNS_NETWORK_LINK_SERVICE_CID },
#endif
{ NULL }
};

Просмотреть файл

@ -60,4 +60,8 @@ ifdef MOZ_ENABLE_LIBCONIC
DIRS += maemo
endif
ifdef MOZ_ENABLE_QTNETWORK
DIRS += qt
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,62 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Nokia Corporation Code.
#
# The Initial Developer of the Original Code is
# Nokia Corporation.
# Portions created by the Initial Developer are Copyright (C) 2010
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Jeremias Bosch <jeremias.bosch@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = necko
LIBRARY_NAME = neckosystem_s
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
CPPSRCS += \
nsQtNetworkLinkService.cpp \
nsQtNetworkManager.cpp \
$(NULL)
include $(topsrcdir)/config/rules.mk
DEFINES += -DIMPL_NS_NET
OS_INCLUDES += $(GLIB_CFLAGS) $(MOZ_QT_CFLAGS)
LOCAL_INCLUDES += -I$(srcdir)/../../base/src

Просмотреть файл

@ -0,0 +1,106 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Nokia Corporation Code.
*
* The Initial Developer of the Original Code is
* Nokia Corporation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jeremias Bosch <jeremias.bosch@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsQtNetworkLinkService.h"
#include "nsCOMPtr.h"
#include "nsIObserverService.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
#include "nsQtNetworkManager.h"
#include "mozilla/Services.h"
NS_IMPL_ISUPPORTS2(nsQtNetworkLinkService,
nsINetworkLinkService,
nsIObserver)
nsQtNetworkLinkService::nsQtNetworkLinkService()
{
}
nsQtNetworkLinkService::~nsQtNetworkLinkService()
{
}
NS_IMETHODIMP
nsQtNetworkLinkService::GetIsLinkUp(PRBool *aIsUp)
{
*aIsUp = nsQtNetworkManager::IsConnected();
return NS_OK;
}
NS_IMETHODIMP
nsQtNetworkLinkService::GetLinkStatusKnown(PRBool *aIsKnown)
{
*aIsKnown = nsQtNetworkManager::GetLinkStatusKnown();
return NS_OK;
}
NS_IMETHODIMP
nsQtNetworkLinkService::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
if (!strcmp(aTopic, "xpcom-shutdown"))
Shutdown();
return NS_OK;
}
nsresult
nsQtNetworkLinkService::Init(void)
{
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (!observerService)
return NS_ERROR_FAILURE;
nsresult rv = observerService->AddObserver(this, "xpcom-shutdown", PR_FALSE);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
if (!nsQtNetworkManager::Startup())
return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
nsQtNetworkLinkService::Shutdown()
{
nsQtNetworkManager::Shutdown();
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,61 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Nokia Corporation Code.
*
* The Initial Developer of the Original Code is
* Nokia Corporation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jeremias Bosch <jeremias.bosch@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSQTNETWORKLINKSERVICE_H_
#define NSQTNETWORKLINKSERVICE_H_
#include "nsINetworkLinkService.h"
#include "nsIObserver.h"
class nsQtNetworkLinkService: public nsINetworkLinkService,
public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSINETWORKLINKSERVICE
NS_DECL_NSIOBSERVER
nsQtNetworkLinkService();
virtual ~nsQtNetworkLinkService();
nsresult Init();
nsresult Shutdown();
};
#endif /* NSQTNETWORKLINKSERVICE_H_ */

Просмотреть файл

@ -0,0 +1,163 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Nokia Corporation Code.
*
* The Initial Developer of the Original Code is
* Nokia Corporation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jeremias Bosch <jeremias.bosch@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//order is important - mozilla redefine qt macros
#include <QNetworkConfigurationManager>
#include <QNetworkConfiguration>
#include <QNetworkSession>
#include "nsQtNetworkManager.h"
#include "nsCOMPtr.h"
#include "nsThreadUtils.h"
#include "nsINetworkLinkService.h"
#include "nsIWindowMediator.h"
#include "nsISimpleEnumerator.h"
#include "nsIOService.h"
#include "nsIObserverService.h"
#include "nsIOService.h"
#include "nsINetworkLinkService.h"
static QNetworkConfigurationManager* sNetworkConfig = 0;
PRBool
nsQtNetworkManager::OpenConnectionSync()
{
if (!sNetworkConfig)
return PR_FALSE;
//do not request when we are online...
if (sNetworkConfig->isOnline())
return PR_FALSE;
//Check that there is atleast one XUL window. If there isn't just return
//without establishing connectivity
nsresult rv;
nsCOMPtr <nsIWindowMediator> windowMediator =
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS (rv,PR_FALSE);
nsCOMPtr <nsISimpleEnumerator> windowEnumerator;
rv = windowMediator->GetXULWindowEnumerator(nsnull,
getter_AddRefs(windowEnumerator));
NS_ENSURE_SUCCESS (rv,PR_FALSE);
PRBool moreElements = PR_FALSE;
windowEnumerator->HasMoreElements(&moreElements);
if (!moreElements) {
return PR_FALSE;
}
//Window found -> we can continue
if (!(sNetworkConfig->capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces))
return PR_FALSE;
// Is there default access point, use it
QNetworkConfiguration default_cfg = sNetworkConfig->defaultConfiguration();
if (!default_cfg.isValid())
{
NS_WARNING("default configuration is not valid. Looking for any other:");
foreach (QNetworkConfiguration cfg, sNetworkConfig->allConfigurations())
{
if (cfg.isValid())
default_cfg = cfg;
}
if (!default_cfg.isValid())
{
NS_WARNING("No valid configuration found. Giving up.");
return PR_FALSE;
}
}
//do use pointer here, it will be deleted after connected!
//Creation on stack cause appearing issues and segfaults of the connectivity dialog
QNetworkSession* session = new QNetworkSession(default_cfg);
QObject::connect(session, SIGNAL(opened()),
session, SLOT(deleteLater()));
QObject::connect(session, SIGNAL(error(QNetworkSession::SessionError)),
session, SLOT(deleteLater()));
session->open();
return session->waitForOpened(-1);
}
void
nsQtNetworkManager::CloseConnection()
{
NS_WARNING("nsQtNetworkManager::CloseConnection() Not implemented by QtNetwork.");
}
PRBool
nsQtNetworkManager::IsConnected()
{
NS_ASSERTION(sNetworkConfig, "Network not initialized");
return sNetworkConfig->isOnline();
}
PRBool
nsQtNetworkManager::GetLinkStatusKnown()
{
return IsConnected();
}
PRBool
nsQtNetworkManager::Startup()
{
//Dont do it if already there
if (sNetworkConfig)
return PR_FALSE;
sNetworkConfig = new QNetworkConfigurationManager();
return PR_TRUE;
}
void
nsQtNetworkManager::Shutdown()
{
delete sNetworkConfig;
sNetworkConfig = nsnull;
}

Просмотреть файл

@ -0,0 +1,58 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Nokia Corporation Code.
*
* The Initial Developer of the Original Code is
* Nokia Corporation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jeremias Bosch <jeremias.bosch@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSQTNETWORKMANAGER_H_
#define NSQTNETWORKMANAGER_H_
#include "nscore.h"
class nsQtNetworkManager
{
public:
// Can be called from any thread, most likely the socket transport thread
static PRBool OpenConnectionSync();
static void CloseConnection();
static PRBool IsConnected();
static PRBool GetLinkStatusKnown();
// Called from the nsQtNetworkLinkService (main thread only)
static PRBool Startup();
static void Shutdown();
};
#endif /* NSQTNETWORKMANAGER_H_ */