bug 486063 - AutoDialer support on Windows Mobile doesn't work just quite right r=blassey sr=stuart

This commit is contained in:
Doug Tuner 2009-04-13 22:49:06 -04:00
parent 059019827b
commit d7f6d3ca7b
3 changed files with 96 additions and 77 deletions

View File

@ -48,7 +48,6 @@
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
// pulled from the header so that we do not get multiple define errors during link
static const GUID ras_DestNetInternet =
{ 0x436ef144, 0xb4fb, 0x4863, { 0xa0, 0x41, 0x8f, 0x90, 0x5a, 0x62, 0xc5, 0x72 } };
@ -85,23 +84,11 @@ nsresult nsRASAutodial::DialDefault(const PRUnichar* /* hostName */)
DWORD status;
HRESULT result = ConnMgrEstablishConnectionSync(&conn_info,
&connectionHandle,
60000,
&status);
if (result != S_OK)
return NS_ERROR_FAILURE;
&connectionHandle,
60000,
&status);
PRInt32 defaultCacheTime = 1; // 1 second according to msdn
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 t;
if (NS_SUCCEEDED(prefs->GetIntPref("network.autodial.cacheTime", &t)))
defaultCacheTime = t;
}
ConnMgrReleaseConnection(connectionHandle, defaultCacheTime);
if (status != CONNMGR_STATUS_CONNECTED)
if (result != S_OK || status != CONNMGR_STATUS_CONNECTED)
return NS_ERROR_FAILURE;
return NS_OK;

View File

@ -1,3 +1,39 @@
/* ***** 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 Windows CE Link Monitoring.
*
* The Initial Developer of the Original Code is Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@meer.net> (Original Author)
*
* 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 "nsNotifyAddrListener.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
@ -13,19 +49,11 @@ static const GUID nal_DestNetInternet =
{ 0x436ef144, 0xb4fb, 0x4863, { 0xa0, 0x41, 0x8f, 0x90, 0x5a, 0x62, 0xc5, 0x72 } };
NS_IMPL_THREADSAFE_ISUPPORTS2(nsNotifyAddrListener,
nsINetworkLinkService,
nsITimerCallback)
NS_IMPL_THREADSAFE_ISUPPORTS1(nsNotifyAddrListener,
nsINetworkLinkService)
nsNotifyAddrListener::nsNotifyAddrListener()
#ifdef wINCE_WINDOWS_MOBILE
: mLinkUp(PR_FALSE) // assume false by default
, mStatusKnown(PR_FALSE)
#else
: mLinkUp(PR_TRUE) // assume true by default on non-WinMo
, mStatusKnown(PR_TRUE)
#endif
, mConnectionHandle(NULL)
: mConnectionHandle(NULL)
{
}
@ -34,9 +62,6 @@ nsNotifyAddrListener::~nsNotifyAddrListener()
#ifdef WINCE_WINDOWS_MOBILE
if (mConnectionHandle)
ConnMgrReleaseConnection(mConnectionHandle, 0);
if (mTimer)
mTimer->Cancel();
#endif
}
@ -57,11 +82,6 @@ nsNotifyAddrListener::Init(void)
ConnMgrEstablishConnection(&conn_info,
&mConnectionHandle);
mTimer = do_CreateInstance("@mozilla.org/timer;1");
if (mTimer)
mTimer->InitWithCallback(this,
15*1000, // every 15 seconds
nsITimer::TYPE_REPEATING_SLACK);
#endif
return NS_OK;
}
@ -69,50 +89,33 @@ nsNotifyAddrListener::Init(void)
NS_IMETHODIMP
nsNotifyAddrListener::GetIsLinkUp(PRBool *aIsUp)
{
*aIsUp = mLinkUp;
#ifdef WINCE_WINDOWS_MOBILE
DWORD status;
HRESULT result = ConnMgrConnectionStatus(mConnectionHandle, &status);
if (FAILED(result)) {
*aIsUp = PR_FALSE;
return NS_ERROR_FAILURE;
}
*aIsUp = status == CONNMGR_STATUS_CONNECTED;
#else
*aIsUp = PR_TRUE;
#endif
return NS_OK;
}
NS_IMETHODIMP
nsNotifyAddrListener::GetLinkStatusKnown(PRBool *aIsUp)
{
*aIsUp = mStatusKnown;
return NS_OK;
}
NS_IMETHODIMP
nsNotifyAddrListener::Notify(nsITimer* aTimer)
nsNotifyAddrListener::GetLinkStatusKnown(PRBool *aIsKnown)
{
#ifdef WINCE_WINDOWS_MOBILE
DWORD status;
HRESULT result = ConnMgrConnectionStatus(mConnectionHandle, &status);
if (FAILED(result)) {
mLinkUp = PR_FALSE;
mStatusKnown = PR_FALSE;
*aIsKnown = PR_FALSE;
return NS_ERROR_FAILURE;
}
else
{
mLinkUp = (status==CONNMGR_STATUS_CONNECTED);
mStatusKnown = PR_TRUE;
}
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (!observerService)
return NS_ERROR_FAILURE;
const char *event;
if (!mStatusKnown)
event = NS_NETWORK_LINK_DATA_UNKNOWN;
else
event = mLinkUp ? NS_NETWORK_LINK_DATA_UP
: NS_NETWORK_LINK_DATA_DOWN;
observerService->NotifyObservers(static_cast<nsINetworkLinkService*>(this),
NS_NETWORK_LINK_TOPIC,
NS_ConvertASCIItoUTF16(event).get());
*aIsKnown = status != CONNMGR_STATUS_UNKNOWN;
#else
*aIsKnown = PR_TRUE;
#endif
return NS_OK;
}

View File

@ -1,20 +1,53 @@
/* ***** 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 Windows CE Link Monitoring.
*
* The Initial Developer of the Original Code is Mozilla Corporation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@meer.net> (Original Author)
*
* 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 NSNOTIFYADDRLISTENER_H_
#define NSNOTIFYADDRLISTENER_H_
#include <windows.h>
#include "nsITimer.h"
#include "nsINetworkLinkService.h"
#include "nsCOMPtr.h"
class nsNotifyAddrListener : public nsINetworkLinkService, nsITimerCallback
class nsNotifyAddrListener : public nsINetworkLinkService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSINETWORKLINKSERVICE
NS_DECL_NSITIMERCALLBACK
nsNotifyAddrListener();
virtual ~nsNotifyAddrListener();
@ -22,10 +55,6 @@ public:
nsresult Init(void);
protected:
nsCOMPtr<nsITimer> mTimer;
PRPackedBool mLinkUp;
PRPackedBool mStatusKnown;
HANDLE mConnectionHandle;
};