Closed Bug 821633 Opened 12 years ago Closed 12 years ago

Alarm API - .getAll() need to wrap the objects respecting to the content window.

Categories

(Core :: DOM: Device Interfaces, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla20
blocking-basecamp +
Tracking Status
firefox19 --- fixed
firefox20 --- fixed
b2g18 --- fixed

People

(Reporter: airpingu, Assigned: airpingu)

References

Details

Attachments

(2 files, 2 obsolete files)

No description provided.
Please see [1]. Currently, .getAll() returns [{},{},{}] (3 alarms are set for example). We need to re-wrap the returned objects subjecting to the content window so that they can be exposed to the web contents. [1] https://bugzilla.mozilla.org/show_bug.cgi?id=821138#c6
Attached patch Part 1, ObjectWrapper.jsm (obsolete) — Splinter Review
Hi Fabrice, When I tried to use .wrap(), I found the Date object cannot be properly exposed to web contents. For example, when the alarm fires, the alarm system message carries a Date object. The system message handler on the web content side would see: {"id":6,"date":{},"respectTimezone":"ignoreTimezone","data":{"id":6}} With this patch, it will correctly see: {"id":6,"date":"2012-12-14T12:03:00.000Z","respectTimezone":"ignoreTimezone","data":{"id":6}} What do you think?
Attachment #692269 - Flags: review?(fabrice)
Hi Vivien, 1. We need to expose the objects returned by .getAll(). It's backward-compatible to do this, because the apps only use .length to know whether any alarm has been added. 2. Also, I think we don't need to expose too many internal attributes to contents in the system message. This is also backward-compatible because all the apps only use |data| so far. 3. Both #1 and #2 now return: "id" "date" "respectTimezone" "data" which are exactly the parameters and returned ID of .add() as below: DOMRequest add(in jsval date, in DOMString respectTimezone, [optional] in jsval data); Could you please take this review? Thanks a lot!
Attachment #692271 - Flags: review?(21)
blocking-basecamp: --- → ?
(In reply to Gene Lian [:gene] from comment #2) > Created attachment 692269 [details] [diff] [review] > Part 1, ObjectWrapper.jsm Hi Fabrice, Please let me know if you prefer using .getMonth() at [1]. [1] http://stackoverflow.com/questions/643782/how-to-know-if-an-object-is-a-date-or-not-with-javascript
Hi David, If you have a chance, could you please take a look at comment #2 about why we need to treat the Date object as "primitive" instead of "object" when wrapping it? Thanks!
Comment on attachment 692269 [details] [diff] [review] Part 1, ObjectWrapper.jsm Review of attachment 692269 [details] [diff] [review]: ----------------------------------------------------------------- Hmm... wait.. we need to do |new aCtxt.Date(aObject)|. In other words, you should return "date" here and add a new branch to the wrap function.
Attachment #692269 - Flags: review+ → review-
And while you are here. Can you change return new aCtxt.Blob([aObject]); to return new aCtxt.Blob([aObject], { type: aObject.type });
(In reply to Gene Lian [:gene] from comment #5) > Hi David, > > If you have a chance, could you please take a look at comment #2 about why > we need to treat the Date object as "primitive" instead of "object" when > wrapping it? Thanks! I think Jonas answered this question. I'd prefer to not pass the date object to the Date constructor (because I don't understand why it works), so I'd modify Jonas' suggestion to this: new aCtxt.Date(aObject.getTime())
Also, while we're fixing up ObjectWrapper.jsm, shouldn't we do something sensible with functions? Right now they're treated as primitives and passed through unmodified. Is that even possible? Is it desireable or is it a security hole? I propose that functions just don't get wrapped. If you pass a function to wrap() it returns null. And if you pass an object with methods to wrap(), then those function-valued properties are just omitted from the wrapped object. I'm assuming that wrapped functions don't work in the receiver so there can't be any code relying on the current behavior, but I suppose that might not be right.
We never meant to wrap functions so I'm ok with them being nullified currently. Of course we can revisit that if we have valid use cases.
Fabrice: are they being nullified? I thought they were being treated as primitives and so passed through unmodified.
(In reply to Jonas Sicking (:sicking) from comment #6) > Comment on attachment 692269 [details] [diff] [review] > Part 1, ObjectWrapper.jsm > > Review of attachment 692269 [details] [diff] [review]: > ----------------------------------------------------------------- > > Hmm... wait.. we need to do |new aCtxt.Date(aObject)|. After some experiments, that's not lucky we can do this like new |new aCtxt.Blob(...)| or |new aCtxt.File(...)|. The log returns me: "aCtxt.Date is not a constructor" The |aCtxt| is passed by the |aWindow| of |nsIDOMGlobalPropertyInitializer.init(aWindow)| in the AlarmsManager.js [1]. Using |this._window| inherited from |DOMRequestIpcHelper| doesn't work either (which seems the same window). May I have your suggestions or workarounds regarding this issue please? [1] http://mxr.mozilla.org/mozilla-central/source/dom/alarm/AlarmsManager.js#137
Flags: needinfo?(jonas)
Flags: needinfo?(fabrice)
(In reply to David Flanagan [:djf] from comment #8) > I think Jonas answered this question. I'd prefer to not pass the date object > to the Date constructor (because I don't understand why it works), so I'd > modify Jonas' suggestion to this: > > new aCtxt.Date(aObject.getTime()) |new Date(new Date())| seems working in my JS console although Date() doesn't accept a Date object as parameter. I guess the Date object is implicitly converted to a string value, though. Anyway, I still got another problem at comment #12 that we cannot use the |aCtxt| to construct a Date object subjecting to that context. Any inputs are highly appreciated.
(In reply to Jonas Sicking (:sicking) from comment #7) > And while you are here. Can you change > > return new aCtxt.Blob([aObject]); > > to > > return new aCtxt.Blob([aObject], { type: aObject.type }); If you don't mind, I'd prefer addressing another bug to do this, which is a separate issue and can help others tracing the blame. Fire bug 821977.
(In reply to Gene Lian [:gene] from comment #12) > After some experiments, that's not lucky we can do this like new |new > aCtxt.Blob(...)| or |new aCtxt.File(...)|. The log returns me: > > "aCtxt.Date is not a constructor" > > The |aCtxt| is passed by the |aWindow| of > |nsIDOMGlobalPropertyInitializer.init(aWindow)| in the AlarmsManager.js [1]. > Using |this._window| inherited from |DOMRequestIpcHelper| doesn't work > either (which seems the same window). May I have your suggestions or > workarounds regarding this issue please? Responds to myself: following [1] to implement a Cu.createDateIn() might be an option but I'm not sure if there exists any other better ways? [1] http://mxr.mozilla.org/mozilla-central/source/js/xpconnect/idl/xpccomponents.idl#301
Try doing x = new aCtxt.wrappedJSObject.Date(Date.getTime()); The downside with doing that is that the page can override the "Date" property and can return an arbitrary thing, or run arbitrary JS when the above is called. But that's very unlikely that as far as I can see it can't cause any harm by doing so. But we should file a followup on adding a Cu.createDateIn function.
Flags: needinfo?(jonas)
Thanks Jonas! Good to learn the trick! I think I can directly add a Cu.createDateIn(), which seems a simple work. ;)
Flags: needinfo?(fabrice)
Attachment #692269 - Attachment is obsolete: true
Attachment #692819 - Flags: review?(jonas)
Comment on attachment 692819 [details] [diff] [review] Part 1, ObjectWrapper.jsm and Cu.createDateIn(), V2 Review of attachment 692819 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/xpconnect/idl/xpccomponents.idl @@ +306,5 @@ > + * Returns a date given timestamp |msec| created in |vobj|'s compartment. > + */ > + [implicit_jscontext] > + jsval createDateIn(in jsval vobj, in long long msec); > + Nit: update the UUID of the interface.
Updated the UUID. Thanks Fabrice for the reminder!
Attachment #692819 - Attachment is obsolete: true
Attachment #692819 - Flags: review?(jonas)
Attachment #692840 - Flags: review?(jonas)
Comment on attachment 692840 [details] [diff] [review] Part 1, ObjectWrapper.jsm and Cu.createDateIn(), V2.1 Review of attachment 692840 [details] [diff] [review]: ----------------------------------------------------------------- Holy moly this is awesome! Thanks for doing the extra work here!
Attachment #692840 - Flags: review?(jonas) → review+
(In reply to Gene Lian [:gene] from comment #19) > Try: https://tbpl.mozilla.org/?tree=Try&rev=6b441d762f52 All green!
Keywords: checkin-needed
Whiteboard: Needs to be checked in *after* bug 821977 to avoid conflicts.
blocking-basecamp: ? → +
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla20
Is there any chance of this uplifting to mozilla-beta?
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: