WebSMS: Expose SmsRequestManager as a scriptable XPCOM service

RESOLVED FIXED in mozilla13

Status

()

Core
DOM: Device Interfaces
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: philikon, Assigned: philikon)

Tracking

Trunk
mozilla13
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(4 attachments, 4 obsolete attachments)

This is needed for the JS-based implementation of nsISmsDatabaseService (bug 712809).
(Assignee)

Updated

5 years ago
Blocks: 720643
Created attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

I'm taking a shot at this since it blocks some important SMS fixes. Here's the IDL, I'm working through the implementation right now.
Assignee: nobody → philipp
Attachment #592179 - Flags: review?(mounir)
(Assignee)

Updated

5 years ago
OS: Linux → All
Hardware: x86_64 → All
Version: unspecified → Trunk
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

I would prefer to look at the entire patch at the same time if you don't mind.

This said, I can really do that this week (I was in the DOM Binding work week last week so I hadn't much time).
Do you still want to work on this?
Attachment #592179 - Flags: review?(mounir)
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #2)
> I would prefer to look at the entire patch at the same time if you don't
> mind.

Fair enough. Let me see how far I can get it on Monday. If I get stuck somewhere, you're welcome to take it over. :)
(In reply to Philipp von Weitershausen [:philikon] from comment #3)
> Fair enough. Let me see how far I can get it on Monday. If I get stuck
> somewhere, you're welcome to take it over. :)

I'm putting this on hold until we decide whether WebSMS will adopt DOMRequest (bug 722626) or not. If so, this bug becomes obsolete. If not, then we can pick it up again.
Target Milestone: --- → mozilla12
Created attachment 593170 [details] [diff] [review]
Part 2 (WIP 1): XPCOMtaminate SmsRequestManager

Posting this here for posterity's sake. Grossly incomplete.
Created attachment 596215 [details] [diff] [review]
Part 2 (v1): XPCOMtaminate SmsRequestManager

I ended up finishing this real quick, seeing that DOMRequest might take a bit longer.
Attachment #593170 - Attachment is obsolete: true
Attachment #596215 - Flags: review?(mounir)
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

Re-requesting review now that part 2 is up :)
Attachment #592179 - Flags: review?(mounir)
Created attachment 596233 [details] [diff] [review]
Part 3 (v1): XPCOM turds

XPCOM registration bits.
Attachment #596233 - Flags: review?(mounir)
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

mounir is swamped and this is blocking the compmletion of WebSMS on Gonk, so over to cjones!
Attachment #592179 - Flags: review?(mounir) → review?(jones.chris.g)
(Assignee)

Updated

5 years ago
Attachment #596215 - Flags: review?(mounir) → review?(jones.chris.g)
(Assignee)

Updated

5 years ago
Attachment #596233 - Flags: review?(mounir) → review?(jones.chris.g)
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

>diff --git a/dom/sms/interfaces/nsISmsRequestManager.idl b/dom/sms/interfaces/nsISmsRequestManager.idl

>+[scriptable, uuid(1638b963-3a45-4937-b6a9-280c1bfb166c)]
>+interface nsISmsRequestManager : nsISupports
>+{
>+
>+  const unsigned short eNoError       = 0;
>+  const unsigned short eNoSignalError = 1;
>+  const unsigned short eNotFoundError = 2;
>+  const unsigned short eUnknownError  = 3;
>+  const unsigned short eInternalError = 4;

I've mostly seen NO_ERROR for enum-alikes in IDL.  Deferring this call
to someone who knows IDL style.

>+  long createRequest(in nsPIDOMWindow aWindow,
>+                     in nsIScriptContext aScriptContext,

I don't know what this is for.  Need to defer this part of the review.

>+  /**
>+   * Track an already existing request object.
>+   *
>+   * @return the request ID.
>+   */
>+  long addRequest(in nsIDOMMozSmsRequest aRequest);
>+

Why are there separate createRequest/addRequest methods?  How can a
request be created outside the purview of SmsRequestManager?

--> gal for IDL style and nsIScriptContext
Attachment #592179 - Flags: review?(gal)
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

>diff --git a/dom/sms/interfaces/nsISmsRequestManager.idl b/dom/sms/interfaces/nsISmsRequestManager.idl

>+  const unsigned short eNoError       = 0;
>+  const unsigned short eNoSignalError = 1;
>+  const unsigned short eNotFoundError = 2;
>+  const unsigned short eUnknownError  = 3;
>+  const unsigned short eInternalError = 4;
>+

Also, we need to keep this comment here

  /**
   * All SMS related errors that could apply to SmsRequest objects.
   * Make sure to keep this list in sync with the list in:
   * embedding/android/GeckoSmsManager.java
   */
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

I understand addRequest now.  I don't like it, but it's not your design.

r=me with comment update above
Attachment #592179 - Flags: review?(jones.chris.g) → review+

Updated

5 years ago
Attachment #592179 - Flags: review?(gal) → review+

Comment 13

5 years ago
Comment on attachment 596215 [details] [diff] [review]
Part 2 (v1): XPCOMtaminate SmsRequestManager

Should the request id be long? (for sanity).

There is some commented out dead code in SmsRequestManager.h
Comment on attachment 592179 [details] [diff] [review]
Part 1 (v1): IDL

>+  void notifySmsSendFailed(in long aRequestId,
>+                           in unsigned short aError);
>+

One more issue here: all these |unsigned short| params should be |long|.
Comment on attachment 596215 [details] [diff] [review]
Part 2 (v1): XPCOMtaminate SmsRequestManager

Shame on you ;).

>diff --git a/dom/sms/src/SmsManager.cpp b/dom/sms/src/SmsManager.cpp

>+  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
>+  int requestId;

IDL |long| is |PRInt32|.

> NS_IMETHODIMP
> SmsManager::GetMessageMoz(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)

>+  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
>+  int requestId;

And here.

>+  nsresult rv = requestManager->CreateRequest(mOwner, mScriptContext, aRequest,
>+                                              &requestId);
>+  if (NS_FAILED(rv)) {
>+    NS_ERROR("Failed to create the request!");
>+    return rv;
>+  }
> 

If I had reviewed this originally, I would have requested that all
this gunk be factored out into a helper method.  But I won't make you
do that for a mechanical rewrite.

> nsresult
> SmsManager::Delete(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)

>-  NS_ASSERTION(*aRequest, "The request object must have been created!");
>+  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
>+  int requestId;

And here.

>+  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
>+  int requestId;

And here.

>diff --git a/dom/sms/src/SmsRequestManager.cpp b/dom/sms/src/SmsRequestManager.cpp

>+NS_IMETHODIMP
>+SmsRequestManager::AddRequest(nsIDOMMozSmsRequest* aRequest,
>+                              PRInt32* aRequestId)
> {
>   // TODO: merge with CreateRequest
>   PRInt32 size = mRequests.Count();
> 
>   // Look for empty slots.
>   for (PRInt32 i=0; i<size; ++i) {
>     if (mRequests[i]) {
>       continue;
>     }
> 
>     mRequests.ReplaceObjectAt(aRequest, i);
>     return i;

Bzzzrt.

>+NS_IMETHODIMP
> SmsRequestManager::CreateRequest(nsPIDOMWindow* aWindow,
>                                  nsIScriptContext* aScriptContext,
>-                                 nsIDOMMozSmsRequest** aRequest)
>+                                 nsIDOMMozSmsRequest** aRequest,
>+                                 PRInt32* aRequestId)
> {
>   nsCOMPtr<nsIDOMMozSmsRequest> request =
>     new SmsRequest(aWindow, aScriptContext);
> 
>   PRInt32 size = mRequests.Count();
> 
>   // Look for empty slots.
>   for (PRInt32 i=0; i<size; ++i) {
>@@ -114,17 +95,18 @@ SmsRequestManager::CreateRequest(nsPIDOM
> 
>     mRequests.ReplaceObjectAt(request, i);
>     NS_ADDREF(*aRequest = request);
>     return i;

And here.

>+NS_IMETHODIMP
>+SmsRequestManager::NotifySmsSendFailed(PRInt32 aRequestId, PRUint16 aError)

PRInt32 aError and everywhere below.

>diff --git a/dom/sms/src/SmsRequestManager.h b/dom/sms/src/SmsRequestManager.h

>+/*
> class nsIDOMMozSmsRequest;
> class nsPIDOMWindow;
> class nsIScriptContext;
> class nsIDOMMozSmsMessage;
>+*/
> 

Kill this.

r=me with those fixes
Attachment #596215 - Flags: review?(jones.chris.g) → review+
Attachment #596233 - Flags: review?(jones.chris.g) → review+
Comment on attachment 596215 [details] [diff] [review]
Part 2 (v1): XPCOMtaminate SmsRequestManager

Review of attachment 596215 [details] [diff] [review]:
-----------------------------------------------------------------

Removing the ErrorType enum makes me sad :(

Seems good to go though.

::: dom/sms/src/SmsCursor.cpp
@@ +115,5 @@
>    mMessage = nsnull;
>    static_cast<SmsRequest*>(mRequest.get())->Reset();
>  
> +  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> +  PRInt32 requestId;

nit: leave a blank line between those two lines

::: dom/sms/src/SmsManager.cpp
@@ +146,5 @@
>  
>    nsCOMPtr<nsIDOMMozSmsRequest> request;
>  
> +  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> +  int requestId;

nit: blank line between those two lines

@@ +222,5 @@
>  NS_IMETHODIMP
>  SmsManager::GetMessageMoz(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)
>  {
> +  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> +  int requestId;

nit: ditto

@@ +243,5 @@
>  nsresult
>  SmsManager::Delete(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)
>  {
> +  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> +  int requestId;

nit: ditto

@@ +293,5 @@
>      filter = new SmsFilter();
>    }
>  
> +  nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> +  int requestId;

nit: ditto

::: dom/sms/src/SmsRequest.cpp
@@ +264,2 @@
>        aError.AssignLiteral("InternalError");
>        break;

Please add a |default| statement with a MOZ_ASSERT.

::: dom/sms/src/SmsRequestManager.h
@@ +47,5 @@
>  class nsIDOMMozSmsRequest;
>  class nsPIDOMWindow;
>  class nsIScriptContext;
>  class nsIDOMMozSmsMessage;
> +*/

Please, remove this block if not needed. Don't keep it commented.

::: embedding/android/GeckoSmsManager.java
@@ +328,5 @@
>  
>    /*
> +   * Make sure that the following error codes are in sync with the ones
> +   * defined in dom/sms/interfaces/nsISmsRequestManager.idl. They are owned
> +   * owned by the DOM.

s/DOM/interface/
(Assignee)

Updated

5 years ago
Blocks: 727319
Created attachment 597275 [details] [diff] [review]
Part 1 (v2): IDL

Addressed review comments.
Attachment #592179 - Attachment is obsolete: true
Created attachment 597276 [details] [diff] [review]
Part 2 (v2): XPCOMtaminate SmsRequestManager

Addressed review comments.
Attachment #596215 - Attachment is obsolete: true
https://hg.mozilla.org/integration/mozilla-inbound/rev/3bb24b12b0d6
https://hg.mozilla.org/integration/mozilla-inbound/rev/ac771e54d7ca
https://hg.mozilla.org/integration/mozilla-inbound/rev/5cf0a12c1cf0
Push backed out for build failures on Android:
https://tbpl.mozilla.org/?tree=Mozilla-Inbound&rev=6c1ded13556d

https://hg.mozilla.org/integration/mozilla-inbound/rev/d2e1b248f40d
Target Milestone: mozilla12 → ---
> Push backed out for build failures on Android:

Also later failed on Windows.
Created attachment 598450 [details] [diff] [review]
Part 4 (v1): Android bits

Yeah, so, I kinda forgot to change Android's usage of SmsRequestManager. Pretty mechanical, just like the rest. In the old fashion r?cjones with potential fallback to mounir.
Attachment #598450 - Flags: review?(jones.chris.g)
Created attachment 598458 [details] [diff] [review]
Part 2 (v3): XPCOMtaminate SmsRequestManager

I had to change the NO_ERROR constant to SUCCESS_NO_ERROR to avoid breakage on Windows (where apparently there's a #define NO_ERROR that breaks things in unexpected ways.) Stoopid Windoze.
Attachment #597276 - Attachment is obsolete: true
Attachment #598450 - Flags: review?(jones.chris.g) → review+
Comment on attachment 598450 [details] [diff] [review]
Part 4 (v1): Android bits

Review of attachment 598450 [details] [diff] [review]:
-----------------------------------------------------------------

::: widget/android/AndroidJNI.cpp
@@ +344,5 @@
>          obs->NotifyObservers(message, kSmsSentObserverTopic, nsnull);
>  
>          if (mProcessId == 0) { // Parent process.
> +          nsCOMPtr<nsISmsRequestManager> requestManager;
> +            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);

You probably want:
nsCOMPtr<nsISmsRequestManager> requestManager =
  do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);

I assume you do.

In addition, |do_GetService| can return |nsnull| so you should check the result.

You are doing this mistake in a lot of places after. I will not point all of them.

Comment 25

5 years ago
Try run for eb9207c37e3a is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=eb9207c37e3a
Results (out of 14 total builds):
    success: 11
    failure: 3
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/pweitershausen@mozilla.com-eb9207c37e3a
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #24)
> Comment on attachment 598450 [details] [diff] [review]
> Part 4 (v1): Android bits
> 
> Review of attachment 598450 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: widget/android/AndroidJNI.cpp
> @@ +344,5 @@
> >          obs->NotifyObservers(message, kSmsSentObserverTopic, nsnull);
> >  
> >          if (mProcessId == 0) { // Parent process.
> > +          nsCOMPtr<nsISmsRequestManager> requestManager;
> > +            = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> 
> You probably want:
> nsCOMPtr<nsISmsRequestManager> requestManager =
>   do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
> 
> I assume you do.

*cough* yes. Thanks for noticing... It was late. :)

> In addition, |do_GetService| can return |nsnull| so you should check the
> result.

Good point. I will do that.

Comment 27

5 years ago
Try run for 02a950d519e7 is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=02a950d519e7
Results (out of 14 total builds):
    success: 11
    failure: 3
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/pweitershausen@mozilla.com-02a950d519e7

Comment 28

5 years ago
Try run for f8c7bb9ad347 is complete.
Detailed breakdown of the results available here:
    https://tbpl.mozilla.org/?tree=Try&rev=f8c7bb9ad347
Results (out of 3 total builds):
    success: 3
Builds (or logs if builds failed) available at:
http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/pweitershausen@mozilla.com-f8c7bb9ad347
Relanded, now with build fixes for Android and Windows, and with Mounir's comments addressed:

https://hg.mozilla.org/integration/mozilla-inbound/rev/c49a23c7084a
https://hg.mozilla.org/integration/mozilla-inbound/rev/82202374e8f0
https://hg.mozilla.org/integration/mozilla-inbound/rev/b6344097919d
https://hg.mozilla.org/integration/mozilla-inbound/rev/7b757f2d70c4
https://hg.mozilla.org/mozilla-central/rev/c49a23c7084a
https://hg.mozilla.org/mozilla-central/rev/82202374e8f0
https://hg.mozilla.org/mozilla-central/rev/b6344097919d
https://hg.mozilla.org/mozilla-central/rev/7b757f2d70c4
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla13
You need to log in before you can comment on or make changes to this bug.