27 #include <nsIChromeRegistry.h>
28 #include <nsIFileURL.h>
29 #include <nsIHttpChannel.h>
30 #include <nsIIOService.h>
31 #include <nsIScriptSecurityManager.h>
33 #include <nsArrayUtils.h>
34 #include <nsAutoLock.h>
35 #include <nsServiceManagerUtils.h>
36 #include <nsThreadUtils.h>
39 #include <sbIDevice.h>
40 #include <sbIDeviceEventTarget.h>
52 static PRLogModuleInfo* gBaseDeviceFirmwareHandlerLog = nsnull;
53 # define TRACE(args) PR_LOG(gBaseDeviceFirmwareHandlerLog, PR_LOG_DEBUG, args)
54 # define LOG(args) PR_LOG(gBaseDeviceFirmwareHandlerLog, PR_LOG_WARN, args)
56 # define __FUNCTION__ __PRETTY_FUNCTION__
75 , mHandlerState(HANDLER_IDLE)
77 , mDefaultFirmwareVersion(0)
78 , mNeedsRecoveryMode(PR_FALSE)
79 , mRecoveryMode(PR_FALSE)
82 if(!gBaseDeviceFirmwareHandlerLog) {
83 gBaseDeviceFirmwareHandlerLog =
84 PR_NewLogModule(
"sbBaseDeviceFirmwareHandler");
92 nsAutoMonitor::DestroyMonitor(
mMonitor);
102 TRACE((
"[%s]", __FUNCTION__));
103 mMonitor = nsAutoMonitor::NewMonitor(
"sbBaseDeviceFirmwareHandler::mMonitor");
104 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_OUT_OF_MEMORY);
106 nsresult rv = NS_ERROR_UNEXPECTED;
107 mXMLHttpRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
108 NS_ENSURE_SUCCESS(rv, rv);
110 nsCOMPtr<nsIScriptSecurityManager> ssm =
111 do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
112 NS_ENSURE_SUCCESS(rv, rv);
114 nsCOMPtr<nsIPrincipal> principal;
115 rv = ssm->GetSystemPrincipal(getter_AddRefs(principal));
116 NS_ENSURE_SUCCESS(rv, rv);
119 NS_ENSURE_SUCCESS(rv, rv);
122 NS_ENSURE_SUCCESS(rv, rv);
125 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
126 NS_ENSURE_SUCCESS(rv, rv);
131 NS_ENSURE_SUCCESS(rv, rv);
138 const nsAString &aDeviceFriendlyName,
139 const PRUint32 aDeviceVendorID,
140 const PRUint32 aDeviceProductID)
142 nsresult rv = NS_ERROR_UNEXPECTED;
143 nsCOMPtr<sbIDeviceFirmwareSupport> deviceSupport =
145 NS_ENSURE_SUCCESS(rv, rv);
147 rv = deviceSupport->SimpleInit(aDeviceFriendlyName,
150 NS_ENSURE_SUCCESS(rv, rv);
153 NS_ENSURE_SUCCESS(rv, rv);
160 const nsAString &aDeviceFriendlyName,
161 const PRUint32 aDeviceProductID)
165 NS_ENSURE_SUCCESS(rv, rv);
168 NS_ENSURE_SUCCESS(rv, rv);
170 for(PRUint32 current = 0; current < length; current++) {
171 nsCOMPtr<sbIDeviceFirmwareSupport> deviceSupport =
172 do_QueryElementAt(array, current, &rv);
173 NS_ENSURE_SUCCESS(rv, rv);
175 nsAutoString friendlyName;
176 rv = deviceSupport->GetDeviceFriendlyName(friendlyName);
177 NS_ENSURE_SUCCESS(rv, rv);
179 if(friendlyName.Equals(aDeviceFriendlyName)) {
180 rv = deviceSupport->AppendProductID(aDeviceProductID);
181 NS_ENSURE_SUCCESS(rv, rv);
194 TRACE((
"[%s]", __FUNCTION__));
195 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
196 NS_ENSURE_ARG_POINTER(aURI);
198 nsresult rv = NS_ERROR_UNEXPECTED;
201 if(NS_IsMainThread()) {
202 ioService = do_GetService(
"@mozilla.org/network/io-service;1", &rv);
203 NS_ENSURE_SUCCESS(rv, rv);
207 NS_ENSURE_SUCCESS(rv, rv);
212 nsCOMPtr<nsIURI>
uri;
213 rv = ioService->NewURI(aURISpec,
216 getter_AddRefs(uri));
217 NS_ENSURE_SUCCESS(rv, rv);
219 nsCOMPtr<nsIThread> mainThread;
220 rv = NS_GetMainThread(getter_AddRefs(mainThread));
221 NS_ENSURE_SUCCESS(rv, rv);
226 NS_PROXY_ALWAYS | NS_PROXY_SYNC,
228 NS_ENSURE_SUCCESS(rv, rv);
235 const nsACString &aUrl,
236 const nsAString &aUsername ,
237 const nsAString &aPassword ,
238 const nsACString &aContentType ,
239 nsIVariant *aRequestBody )
241 TRACE((
"[%s]", __FUNCTION__));
242 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
245 NS_ENSURE_TRUE(!aMethod.IsEmpty(), NS_ERROR_INVALID_ARG);
246 NS_ENSURE_TRUE(!aUrl.IsEmpty(), NS_ERROR_INVALID_ARG);
250 NS_ENSURE_SUCCESS(rv, rv);
255 TRACE((
"[%s] - can't do parallel requests (in state %08x)", __FUNCTION__, state));
259 TRACE((
"[%s] - sending %s request to %s", __FUNCTION__,
260 nsCString(aMethod).
get(), nsCString(aUrl).
get()));
263 aUsername, aPassword);
264 NS_ENSURE_SUCCESS(rv, rv);
266 if (!aContentType.IsEmpty()) {
267 rv =
mXMLHttpRequest->SetRequestHeader(NS_LITERAL_CSTRING(
"Content-Type"),
269 NS_ENSURE_SUCCESS(rv, rv);
274 NS_ENSURE_SUCCESS(rv, rv);
279 NS_ENSURE_SUCCESS(rv, rv);
281 nsCOMPtr<nsITimerCallback>
callback =
283 NS_ASSERTION(NS_SUCCEEDED(rv),
284 "sbBaseDeviceFirmwareHandler doesn't implement nsITimerCallback!");
287 nsITimer::TYPE_REPEATING_SLACK);
288 NS_ENSURE_SUCCESS(rv, rv);
296 TRACE((
"[%s]", __FUNCTION__));
297 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
302 NS_ENSURE_SUCCESS(rv, rv);
307 NS_ENSURE_SUCCESS(rv, rv);
312 NS_ENSURE_SUCCESS(rv, rv);
323 TRACE((
"[%s]", __FUNCTION__));
324 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
326 NS_ENSURE_ARG_POINTER(aEvent);
330 nsCOMPtr<sbIDevice> device =
mDevice;
333 nsresult rv = NS_ERROR_UNEXPECTED;
335 nsCOMPtr<sbIDeviceManager2> deviceManager =
336 do_GetService(
"@songbirdnest.com/Songbird/DeviceManager;2", &rv);
337 NS_ENSURE_SUCCESS(rv, rv);
339 rv = deviceManager->CreateEvent(aType,
345 NS_ENSURE_SUCCESS(rv, rv);
354 TRACE((
"[%s]", __FUNCTION__));
355 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
356 NS_ENSURE_ARG_POINTER(aEvent);
358 nsresult rv = NS_ERROR_UNEXPECTED;
364 if(!NS_IsMainThread() && listener) {
368 nsCOMPtr<nsIThread> mainThread;
369 rv = NS_GetMainThread(getter_AddRefs(mainThread));
370 NS_ENSURE_SUCCESS(rv, rv);
372 nsCOMPtr<sbIDeviceEventListener> proxiedListener;
376 NS_PROXY_ALWAYS | NS_PROXY_ASYNC,
377 getter_AddRefs(proxiedListener));
378 NS_ENSURE_SUCCESS(rv, rv);
388 nsCOMPtr<sbIDeviceEventTarget>
target = do_QueryInterface(
mDevice, &rv);
389 NS_ENSURE_SUCCESS(rv, rv);
393 PRBool dispatched = PR_FALSE;
394 rv = target->DispatchEvent(aEvent, aAsync, &dispatched);
395 NS_ENSURE_SUCCESS(rv, rv);
397 NS_WARN_IF_FALSE(dispatched,
"Event not dispatched");
400 rv = listener->OnDeviceEvent(aEvent);
401 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Error while calling listener.");
412 TRACE((
"[%s]", __FUNCTION__));
413 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
415 nsCOMPtr<sbIDeviceEvent> deviceEvent;
417 NS_ENSURE_SUCCESS(rv, rv);
420 NS_ENSURE_SUCCESS(rv, rv);
428 TRACE((
"[%s]", __FUNCTION__));
436 TRACE((
"[%s]", __FUNCTION__));
450 TRACE((
"[%s]", __FUNCTION__));
451 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
453 if(NS_FAILED(aResult)) {
455 NS_ENSURE_SUCCESS(rv, rv);
468 TRACE((
"[%s]", __FUNCTION__));
490 return NS_ERROR_NOT_IMPLEMENTED;
500 return NS_ERROR_NOT_IMPLEMENTED;
511 return NS_ERROR_NOT_IMPLEMENTED;
521 return NS_ERROR_NOT_IMPLEMENTED;
527 TRACE((
"[%s]", __FUNCTION__));
536 aModelNumber.SetIsVoid(PR_TRUE);
544 TRACE((
"[%s]", __FUNCTION__));
553 aModelVersion.SetIsVoid(PR_TRUE);
562 TRACE((
"[%s]", __FUNCTION__));
571 aDeviceVendor.SetIsVoid(PR_TRUE);
589 PRUint32 aDeviceVendorID,
590 PRUint32 aDeviceProductID,
593 TRACE((
"[%s]", __FUNCTION__));
601 return NS_ERROR_NOT_IMPLEMENTED;
606 PRUint32 aDeviceVendorID,
607 PRUint32 aDeviceProductID)
609 TRACE((
"[%s]", __FUNCTION__));
623 TRACE((
"[%s]", __FUNCTION__));
651 return NS_ERROR_NOT_IMPLEMENTED;
657 TRACE((
"[%s]", __FUNCTION__));
663 return NS_ERROR_NOT_IMPLEMENTED;
669 TRACE((
"[%s]", __FUNCTION__));
689 return NS_ERROR_NOT_IMPLEMENTED;
695 TRACE((
"[%s]", __FUNCTION__));
714 return NS_ERROR_NOT_IMPLEMENTED;
720 TRACE((
"[%s]", __FUNCTION__));
747 return NS_ERROR_NOT_IMPLEMENTED;
753 TRACE((
"[%s]", __FUNCTION__));
772 return NS_ERROR_NOT_IMPLEMENTED;
778 TRACE((
"[%s]", __FUNCTION__));
797 return NS_ERROR_NOT_IMPLEMENTED;
803 TRACE((
"[%s]", __FUNCTION__));
804 return NS_ERROR_NOT_IMPLEMENTED;
812 sbBaseDeviceFirmwareHandler::GetBoundDevice(
sbIDevice **aDevice)
814 TRACE((
"[%s]", __FUNCTION__));
815 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
816 NS_ENSURE_ARG_POINTER(aDevice);
820 NS_IF_ADDREF(*aDevice =
mDevice);
825 sbBaseDeviceFirmwareHandler::GetContractId(nsAString & aContractId)
827 TRACE((
"[%s]", __FUNCTION__));
828 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
837 sbBaseDeviceFirmwareHandler::GetLatestFirmwareLocation(nsIURI * *aLatestFirmwareLocation)
839 TRACE((
"[%s]", __FUNCTION__));
840 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
841 NS_ENSURE_ARG_POINTER(aLatestFirmwareLocation);
843 *aLatestFirmwareLocation = nsnull;
848 return NS_ERROR_NOT_AVAILABLE;
852 NS_ENSURE_SUCCESS(rv, rv);
858 sbBaseDeviceFirmwareHandler::GetLatestFirmwareVersion(PRUint32 *aLatestFirmwareVersion)
860 TRACE((
"[%s]", __FUNCTION__));
861 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
862 NS_ENSURE_ARG_POINTER(aLatestFirmwareVersion);
871 sbBaseDeviceFirmwareHandler::GetLatestFirmwareReadableVersion(nsAString & aLatestFirmwareReadableVersion)
873 TRACE((
"[%s]", __FUNCTION__));
874 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
883 sbBaseDeviceFirmwareHandler::GetCurrentFirmwareVersion(PRUint32 *aCurrentFirmwareVersion)
885 TRACE((
"[%s]", __FUNCTION__));
886 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
887 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
888 NS_ENSURE_ARG_POINTER(aCurrentFirmwareVersion);
893 NS_ENSURE_SUCCESS(rv, rv);
899 sbBaseDeviceFirmwareHandler::GetCurrentFirmwareReadableVersion(nsAString &aCurrentFirmwareReadableVersion)
901 TRACE((
"[%s]", __FUNCTION__));
902 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
903 NS_ENSURE_TRUE(
mDevice, NS_ERROR_NOT_INITIALIZED);
909 NS_ENSURE_SUCCESS(rv, rv);
915 sbBaseDeviceFirmwareHandler::GetReleaseNotesLocation(nsIURI * *aReleaseNotesLocation)
917 TRACE((
"[%s]", __FUNCTION__));
918 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
919 NS_ENSURE_ARG_POINTER(aReleaseNotesLocation);
921 *aReleaseNotesLocation = nsnull;
926 return NS_ERROR_NOT_AVAILABLE;
930 NS_ENSURE_SUCCESS(rv, rv);
936 sbBaseDeviceFirmwareHandler::GetResetInstructionsLocation(nsIURI * *aResetInstructionsLocation)
938 TRACE((
"[%s]", __FUNCTION__));
939 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
940 NS_ENSURE_ARG_POINTER(aResetInstructionsLocation);
942 *aResetInstructionsLocation = nsnull;
947 return NS_ERROR_NOT_AVAILABLE;
951 NS_ENSURE_SUCCESS(rv, rv);
957 sbBaseDeviceFirmwareHandler::GetRecoveryModeKeyCombination(
958 nsAString &aRecoveryModeKeyCombination)
960 TRACE((
"[%s]", __FUNCTION__));
961 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
963 aRecoveryModeKeyCombination.Truncate();
972 sbBaseDeviceFirmwareHandler::GetCustomerSupportLocation(nsIURI * *aSupportLocation)
974 TRACE((
"[%s]", __FUNCTION__));
975 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
976 NS_ENSURE_ARG_POINTER(aSupportLocation);
978 *aSupportLocation = nsnull;
987 NS_ENSURE_SUCCESS(rv, rv);
993 sbBaseDeviceFirmwareHandler::GetRegisterLocation(nsIURI * *aRegisterLocation)
995 TRACE((
"[%s]", __FUNCTION__));
996 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
997 NS_ENSURE_ARG_POINTER(aRegisterLocation);
999 *aRegisterLocation = nsnull;
1008 NS_ENSURE_SUCCESS(rv, rv);
1014 sbBaseDeviceFirmwareHandler::GetNeedsRecoveryMode(PRBool *aNeedsRecoveryMode)
1016 TRACE((
"[%s]", __FUNCTION__));
1017 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1018 NS_ENSURE_ARG_POINTER(aNeedsRecoveryMode);
1027 sbBaseDeviceFirmwareHandler::GetRecoveryMode(PRBool *aRecoveryMode)
1029 TRACE((
"[%s]", __FUNCTION__));
1030 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1031 NS_ENSURE_ARG_POINTER(aRecoveryMode);
1036 NS_ENSURE_SUCCESS(rv, rv);
1044 TRACE((
"[%s]", __FUNCTION__));
1045 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1046 NS_ENSURE_ARG_POINTER(aFirmwareUpdate);
1048 *aFirmwareUpdate = nsnull;
1055 PRBool schemeIsChrome = PR_FALSE;
1058 NS_ENSURE_SUCCESS(rv, rv);
1060 PRBool schemeIsFile = PR_FALSE;
1063 NS_ENSURE_SUCCESS(rv, rv);
1065 nsCOMPtr<nsIFile>
file;
1066 if(schemeIsChrome) {
1067 nsCOMPtr<nsIChromeRegistry> chromeRegistry =
1068 do_GetService(
"@mozilla.org/chrome/chrome-registry;1", &rv);
1069 NS_ENSURE_SUCCESS(rv, rv);
1071 nsCOMPtr<nsIURI> fileURI;
1073 getter_AddRefs(fileURI));
1074 NS_ENSURE_SUCCESS(rv, rv);
1076 nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI, &rv);
1077 NS_ENSURE_SUCCESS(rv, rv);
1079 rv = fileURL->GetFile(getter_AddRefs(file));
1080 NS_ENSURE_SUCCESS(rv, rv);
1082 else if(schemeIsFile) {
1083 nsCOMPtr<nsIFileURL> fileURL =
1085 NS_ENSURE_SUCCESS(rv, rv);
1087 rv = fileURL->GetFile(getter_AddRefs(file));
1088 NS_ENSURE_SUCCESS(rv, rv);
1092 return NS_ERROR_INVALID_ARG;
1095 nsCOMPtr<sbIDeviceFirmwareUpdate> firmwareUpdate =
1097 NS_ENSURE_SUCCESS(rv, rv);
1099 rv = firmwareUpdate->Init(file,
1102 NS_ENSURE_SUCCESS(rv, rv);
1104 firmwareUpdate.forget(aFirmwareUpdate);
1110 sbBaseDeviceFirmwareHandler::GetDeviceModelNumber(nsAString &aModelNumber)
1112 TRACE((
"[%s]", __FUNCTION__));
1113 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1118 NS_ENSURE_SUCCESS(rv, rv);
1124 sbBaseDeviceFirmwareHandler::GetDeviceModelVersion(nsAString &aModelVersion)
1126 TRACE((
"[%s]", __FUNCTION__));
1127 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1132 NS_ENSURE_SUCCESS(rv, rv);
1138 sbBaseDeviceFirmwareHandler::GetDeviceVendor(nsAString &aDeviceVendor)
1140 TRACE((
"[%s]", __FUNCTION__));
1141 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1146 NS_ENSURE_SUCCESS(rv, rv);
1152 sbBaseDeviceFirmwareHandler::GetSupportedDevices(
1157 *aSupportedDevices = nsnull;
1160 NS_ENSURE_SUCCESS(rv, rv);
1166 sbBaseDeviceFirmwareHandler::CanUpdate(
sbIDevice *aDevice,
1167 PRUint32 aDeviceVendorID,
1168 PRUint32 aDeviceProductID,
1171 TRACE((
"[%s]", __FUNCTION__));
1172 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1173 NS_ENSURE_ARG_POINTER(_retval);
1181 NS_ENSURE_SUCCESS(rv, rv);
1187 sbBaseDeviceFirmwareHandler::InitiateRecoveryModeSwitch(
1188 PRUint32 aDeviceVendorID,
1189 PRUint32 aDeviceProductID)
1191 TRACE((
"[%s]", __FUNCTION__));
1192 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1200 NS_ENSURE_SUCCESS(rv, rv);
1206 sbBaseDeviceFirmwareHandler::Bind(
sbIDevice *aDevice,
1209 TRACE((
"[%s]", __FUNCTION__));
1210 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1211 NS_ENSURE_ARG_POINTER(aDevice);
1215 NS_ENSURE_FALSE(
mDevice, NS_ERROR_ALREADY_INITIALIZED);
1216 NS_ENSURE_FALSE(
mListener, NS_ERROR_ALREADY_INITIALIZED);
1222 NS_ENSURE_SUCCESS(rv, rv);
1228 sbBaseDeviceFirmwareHandler::Rebind(
sbIDevice *aDevice,
1232 TRACE((
"[%s]", __FUNCTION__));
1233 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1234 NS_ENSURE_ARG_POINTER(aDevice);
1235 NS_ENSURE_ARG_POINTER(_retval);
1237 *_retval = PR_FALSE;
1241 nsresult rv =
OnRebind(aDevice, aListener, _retval);
1242 NS_ENSURE_SUCCESS(rv, rv);
1248 sbBaseDeviceFirmwareHandler::Unbind()
1250 TRACE((
"[%s]", __FUNCTION__));
1251 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1262 sbBaseDeviceFirmwareHandler::Cancel()
1264 TRACE((
"[%s]", __FUNCTION__));
1265 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1268 NS_ENSURE_SUCCESS(rv, rv);
1274 sbBaseDeviceFirmwareHandler::RefreshInfo()
1276 TRACE((
"[%s]", __FUNCTION__));
1277 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1280 NS_ENSURE_SUCCESS(rv, rv);
1288 TRACE((
"[%s]", __FUNCTION__));
1289 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1290 NS_ENSURE_ARG_POINTER(aFirmwareUpdate);
1292 nsresult rv =
OnUpdate(aFirmwareUpdate);
1293 NS_ENSURE_SUCCESS(rv, rv);
1301 TRACE((
"[%s]", __FUNCTION__));
1302 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1304 nsresult rv =
OnRecover(aFirmwareUpdate);
1305 NS_ENSURE_SUCCESS(rv, rv);
1311 sbBaseDeviceFirmwareHandler::VerifyDevice()
1313 TRACE((
"[%s]", __FUNCTION__));
1314 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1317 NS_ENSURE_SUCCESS(rv, rv);
1325 TRACE((
"[%s]", __FUNCTION__));
1326 NS_ENSURE_TRUE(
mMonitor, NS_ERROR_NOT_INITIALIZED);
1329 NS_ENSURE_SUCCESS(rv, rv);
1339 sbBaseDeviceFirmwareHandler::Notify(nsITimer *aTimer)
1341 TRACE((
"[%s]", __FUNCTION__));
1342 NS_ENSURE_ARG_POINTER(aTimer);
1343 nsresult rv = NS_ERROR_UNEXPECTED;
1350 NS_ENSURE_SUCCESS(rv, rv);
1354 NS_ENSURE_SUCCESS(rv, rv);
1357 nsCOMPtr<nsIChannel> channel;
1359 NS_ENSURE_SUCCESS(rv, rv);
1361 nsCOMPtr<nsIHttpChannel> httpChannel =
1362 do_QueryInterface(channel, &rv);
1364 if(NS_SUCCEEDED(rv) && httpChannel) {
1365 PRUint32 status = 0;
1366 rv = httpChannel->GetResponseStatus(&status);
1367 NS_ENSURE_SUCCESS(rv, rv);
1369 LOG((
"HTTP Request Status Code: %i", status));
1371 nsCString statusText;
1372 rv = httpChannel->GetResponseStatusText(statusText);
1373 NS_ENSURE_SUCCESS(rv, rv);
1375 LOG((
"HTTP Request Status Text: %s", statusText.BeginReading()));
1378 LOG((
"No HTTP Channel available!"));
1383 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"OnHttpRequestCompleted failed");
static const PRInt32 HTTP_STATE_UNINITIALIZED
virtual nsresult OnCancel()
NS_IMPL_THREADSAFE_ISUPPORTS2(sbBaseDeviceFirmwareHandler, sbIDeviceFirmwareHandler, nsITimerCallback) sbBaseDeviceFirmwareHandler
virtual nsresult OnCanUpdate(sbIDevice *aDevice, PRUint32 aDeviceVendorID, PRUint32 aDeviceProductID, PRBool *_retval)
virtual nsresult OnRefreshInfo()
virtual nsresult OnBeginRecoveryModeSwitch(PRUint32 aDeviceVendorID, PRUint32 aDeviceProductID)
PRUint32 mDefaultFirmwareVersion
virtual nsresult OnEndRecoveryModeSwitch()
nsCOMPtr< nsIURI > mSupportLocation
nsresult AppendSupportedDeviceProductID(const nsAString &aDeviceFriendlyName, const PRUint32 aDeviceProductID)
#define SB_DEVICEFIRMWAREUPDATE_CONTRACTID
nsCOMPtr< nsIURI > mDefaultFirmwareLocation
nsCOMPtr< sbIDevice > mDevice
nsCOMPtr< sbIDeviceEventListener > mProxiedListener
virtual nsresult OnInit()
nsCOMPtr< nsIURI > mFirmwareLocation
nsresult do_GetProxyForObject(nsIEventTarget *aTarget, REFNSIID aIID, nsISupports *aObj, PRInt32 aProxyType, void **aProxyObject)
nsresult SetState(handlerstate_t aState)
Get internal state.
virtual nsresult OnRebind(sbIDevice *aDevice, sbIDeviceEventListener *aListener, PRBool *_retval)
nsresult CheckForError(const nsresult &aResult, PRUint32 aEventType, nsIVariant *aData=nsnull)
Check nsresult value, send error event if nsresult value is an error.
PRPackedBool mNeedsRecoveryMode
nsCOMPtr< nsITimer > mXMLHttpRequestTimer
virtual nsresult OnGetCurrentFirmwareVersion(PRUint32 *aCurrentFirmwareVersion)
nsCOMPtr< nsIURI > mResetInstructionsLocation
virtual nsresult OnGetRecoveryMode(PRBool *aRecoveryMode)
PRUint32 mFirmwareVersion
static const PRInt32 HTTP_STATE_LOADED
handlerstate_t GetState()
Set internal state.
nsresult AbortHttpRequest()
Abort an HTTP request.
nsresult SendDeviceEvent(sbIDeviceEvent *aEvent, PRBool aAsync=PR_TRUE)
Send a device event.
const sbCreateProxiedComponent do_ProxiedGetService(const nsCID &aCID, nsresult *error=0)
virtual nsresult OnGetDeviceVendor(nsAString &aDeviceVendor)
static const PRInt32 HTTP_STATE_COMPLETED
handlerstate_t mHandlerState
nsresult AppendSupportedDevice(const nsAString &aDeviceFriendlyName, const PRUint32 aDeviceVendorID, const PRUint32 aDeviceProductID)
Append an entry to the list of supported devices.
static const PRInt32 HTTP_STATE_LOADING
const unsigned long STATE_IDLE
nsCOMPtr< nsIXMLHttpRequest > mXMLHttpRequest
nsString mRecoveryModeKeyCombination
nsString mDefaultReadableFirmwareVersion
#define SB_DEVICEFIRMWARESUPPORT_CONTRACTID
virtual nsresult OnGetDeviceModelVersion(nsAString &aModelVersion)
virtual nsresult OnVerifyUpdate(sbIDeviceFirmwareUpdate *aFirmwareUpdate)
virtual nsresult OnVerifyDevice()
nsCOMPtr< nsIURI > mRegisterLocation
nsCOMPtr< nsIMutableArray > mSupportedDevices
virtual nsresult OnGetSupportedDevices(nsISimpleEnumerator **aSupportedDevices)
virtual nsresult OnRecover(sbIDeviceFirmwareUpdate *aFirmwareUpdate)
nsresult CreateDeviceEvent(PRUint32 aType, nsIVariant *aData, sbIDeviceEvent **aEvent)
Create a device event.
virtual ~sbBaseDeviceFirmwareHandler()
static const PRInt32 HTTP_STATE_INTERACTIVE
nsresult CreateProxiedURI(const nsACString &aURISpec, nsIURI **aURI)
Create an nsIURI from a spec string (e.g. http://some.url.com/path) in a thread-safe manner...
virtual nsresult OnGetCurrentFirmwareReadableVersion(nsAString &aCurrentFirmwareReadableVersion)
nsCOMPtr< sbIDeviceEventListener > mListener
virtual nsresult OnGetDeviceModelNumber(nsAString &aModelNumber)
nsCOMPtr< nsIURI > mReleaseNotesLocation
virtual nsresult OnUpdate(sbIDeviceFirmwareUpdate *aFirmwareUpdate)
virtual nsresult OnHttpRequestCompleted()
nsString mReadableFirmwareVersion
nsresult SendHttpRequest(const nsACString &aMethod, const nsACString &aUrl, const nsAString &aUsername=EmptyString(), const nsAString &aPassword=EmptyString(), const nsACString &aContentType=EmptyCString(), nsIVariant *aRequestBody=nsnull)
Send an HTTP request.
_updateTextAndScrollDataForFrame aData