Bug 733320 - [WebSMS][B2G SMS] Add 'read' attribute to nsIDOMMozSmsMessage. Part 2 - WebSMS; r=mounir

This commit is contained in:
Fernando Jiménez 2012-05-17 12:42:38 -07:00
Родитель 7516bbad17
Коммит 47f41e7b22
6 изменённых файлов: 116 добавлений и 215 удалений

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

@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SmsFilter.h"
#include "nsIDOMClassInfo.h"
@ -66,6 +34,7 @@ SmsFilter::SmsFilter()
mData.startDate() = 0;
mData.endDate() = 0;
mData.delivery() = eDeliveryState_Unknown;
mData.read() = eReadState_Unknown;
}
SmsFilter::SmsFilter(const SmsFilterData& aData)
@ -259,6 +228,35 @@ SmsFilter::SetDelivery(const nsAString& aDelivery)
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
SmsFilter::GetRead(JSContext* aCx, jsval* aRead)
{
if (mData.read() == eReadState_Unknown) {
*aRead = JSVAL_VOID;
return NS_OK;
}
aRead->setBoolean(mData.read());
return NS_OK;
}
NS_IMETHODIMP
SmsFilter::SetRead(JSContext* aCx, const jsval& aRead)
{
if (aRead == JSVAL_VOID) {
mData.read() = eReadState_Unknown;
return NS_OK;
}
if (!aRead.isBoolean()) {
return NS_ERROR_INVALID_ARG;
}
mData.read() = aRead.toBoolean() ? eReadState_Read : eReadState_Unread;
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SmsFilter.h"
#include "SmsManager.h"
@ -316,6 +284,29 @@ SmsManager::GetMessages(nsIDOMMozSmsFilter* aFilter, bool aReverse,
return NS_OK;
}
NS_IMETHODIMP
SmsManager::MarkMessageRead(PRInt32 aId, bool aValue,
nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsISmsRequestManager> requestManager =
do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
PRInt32 requestId;
nsresult rv = requestManager->CreateRequest(this, aRequest, &requestId);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create the request!");
return rv;
}
nsCOMPtr<nsISmsDatabaseService> smsDBService =
do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE);
smsDBService->MarkMessageRead(aId, aValue, requestId, 0);
return NS_OK;
}
NS_IMPL_EVENT_HANDLER(SmsManager, received)
NS_IMPL_EVENT_HANDLER(SmsManager, sent)
NS_IMPL_EVENT_HANDLER(SmsManager, delivered)

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

@ -1,40 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
* Philipp von Weitershausen <philipp@weitershausen.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SmsMessage.h"
#include "nsIDOMClassInfo.h"
@ -59,8 +26,8 @@ NS_IMPL_RELEASE(SmsMessage)
SmsMessage::SmsMessage(PRInt32 aId, DeliveryState aDelivery,
const nsString& aSender, const nsString& aReceiver,
const nsString& aBody, PRUint64 aTimestamp)
: mData(aId, aDelivery, aSender, aReceiver, aBody, aTimestamp)
const nsString& aBody, PRUint64 aTimestamp, bool aRead)
: mData(aId, aDelivery, aSender, aReceiver, aBody, aTimestamp, aRead)
{
}
@ -76,6 +43,7 @@ SmsMessage::Create(PRInt32 aId,
const nsAString& aReceiver,
const nsAString& aBody,
const jsval& aTimestamp,
const bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage)
{
@ -88,6 +56,7 @@ SmsMessage::Create(PRInt32 aId,
data.sender() = nsString(aSender);
data.receiver() = nsString(aReceiver);
data.body() = nsString(aBody);
data.read() = aRead;
if (aDelivery.Equals(DELIVERY_RECEIVED)) {
data.delivery() = eDeliveryState_Received;
@ -181,6 +150,13 @@ SmsMessage::GetTimestamp(JSContext* cx, jsval* aDate)
return NS_OK;
}
NS_IMETHODIMP
SmsMessage::GetRead(bool* aRead)
{
*aRead = mData.read();
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_sms_SmsMessage_h
#define mozilla_dom_sms_SmsMessage_h
@ -56,7 +24,7 @@ public:
SmsMessage(PRInt32 aId, DeliveryState aDelivery, const nsString& aSender,
const nsString& aReceiver, const nsString& aBody,
PRUint64 aTimestamp);
PRUint64 aTimestamp, bool aRead);
SmsMessage(const SmsMessageData& aData);
static nsresult Create(PRInt32 aId,
@ -65,6 +33,7 @@ public:
const nsAString& aReceiver,
const nsAString& aBody,
const JS::Value& aTimestamp,
const bool aRead,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage);
const SmsMessageData& GetData() const;

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

@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SmsRequestManager.h"
#include "nsIDOMSmsMessage.h"
@ -245,6 +213,18 @@ SmsRequestManager::NotifyReadMessageListFailed(PRInt32 aRequestId, PRInt32 aErro
return NotifyError(aRequestId, aError);
}
NS_IMETHODIMP
SmsRequestManager::NotifyMarkedMessageRead(PRInt32 aRequestId, bool aRead)
{
return NotifySuccess<bool>(aRequestId, aRead);
}
NS_IMETHODIMP
SmsRequestManager::NotifyMarkMessageReadFailed(PRInt32 aRequestId, PRInt32 aError)
{
return NotifyError(aRequestId, aError);
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -1,39 +1,7 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_sms_Types_h
#define mozilla_dom_sms_Types_h
@ -44,7 +12,7 @@ namespace mozilla {
namespace dom {
namespace sms {
// For SmsMessageDate.delivery.
// For SmsMessageData.delivery.
// Please keep the following files in sync with enum below:
// embedding/android/GeckoSmsManager.java
enum DeliveryState {
@ -55,6 +23,15 @@ enum DeliveryState {
eDeliveryState_EndGuard
};
// For SmsFilterData.read
enum ReadState {
eReadState_Unknown = -1,
eReadState_Unread,
eReadState_Read,
// This state should stay at the end.
eReadState_EndGuard
};
} // namespace sms
} // namespace dom
} // namespace mozilla
@ -71,6 +48,16 @@ struct ParamTraits<mozilla::dom::sms::DeliveryState>
mozilla::dom::sms::eDeliveryState_EndGuard>
{};
/**
* Read state serializer.
*/
template <>
struct ParamTraits<mozilla::dom::sms::ReadState>
: public EnumSerializer<mozilla::dom::sms::ReadState,
mozilla::dom::sms::eReadState_Unknown,
mozilla::dom::sms::eReadState_EndGuard>
{};
} // namespace IPC
#endif // mozilla_dom_sms_Types_h