Closed Bug 783408 Opened 12 years ago Closed 12 years ago

Delete cookiejar when we remove a B2G app

Categories

(Core :: Networking: Cookies, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla18
blocking-basecamp +

People

(Reporter: jduell.mcbugs, Assigned: mounir)

References

Details

(Keywords: feature, Whiteboard: [LOE:S][WebAPI:P3][qa-])

Attachments

(4 files, 4 obsolete files)

I assume we have a nsIObserver notification when an app is uninstalled. We should remove its cookies from the parent nsCookieService hash and the sqlite DB at that time.
blocking-basecamp: --- → ?
Marking as blocking and can you fill out the LOE in the whiteboard? Thanks.
Assignee: nobody → jduell.mcbugs
blocking-basecamp: ? → +
jlebar, cjones, sicking: If someone can point me at how we provide notification for 'app-uninstall' I can make quick work of this.
Whiteboard: [LOE:S]
(In reply to Jason Duell (:jduell) from comment #2) > jlebar, cjones, sicking: If someone can point me at how we provide > notification for 'app-uninstall' I can make quick work of this. Fabrice or Mounir might know better.
We fire an observer notification: Services.obs.notifyObservers(this, "webapps-sync-uninstall", app); |app| has a localId property which is the appId we probably need.
Blocks: 786293
Whiteboard: [LOE:S] → [LOE:S][WebAPI:P3]
Keywords: feature
Jason, did you begin working on that? I had a look and I have a clear idea about how to implement this feature. Do you want me to go ahead or do you have anything ready?
OS: Linux → All
Hardware: x86_64 → All
Version: unspecified → Trunk
Taking this bug given that I just finished writing the patches.
Assignee: jduell.mcbugs → mounir
Status: NEW → ASSIGNED
Attached patch Part 1 - GetCookiesForApp (obsolete) — — Splinter Review
Add a method returning all cookies for a given app. If InBrowserElement is true, it will only returned cookies for browser elements inside the app.
Attachment #663414 - Flags: review?(jduell.mcbugs)
Attached patch Part 2 - RemoveCookiesForApp (obsolete) — — Splinter Review
Attachment #663415 - Flags: review?(jduell.mcbugs)
Attached patch Part 3 - Hook to webapps-uninstall (obsolete) — — Splinter Review
Attachment #663416 - Flags: review?(justin.lebar+bug)
Attached patch Part 4 - Tests (obsolete) — — Splinter Review
Attachment #663417 - Flags: review?(jduell.mcbugs)
With these patches included, you can easily remove cookies for a given app or for browsers of a given app. However, there are only hooks for app uninstall. Hooks for browser private data removal will have to happen in another bug but that should be pretty trivial.
Comment on attachment 663416 [details] [diff] [review] Part 3 - Hook to webapps-uninstall > +} // anonymous namespace > + > +NS_IMPL_ISUPPORTS1(AppUninstallObserver, nsIObserver) I guess it doesn't matter, but can you move the NS_IMPL_ISUPPORTS1 into the anonymous namespace? > + * Initialize the "webapp-uninstall" observing. > + * Will create a nsCookieService instance if needed. > + * That way, we can prevent have nsCookieService created at startup just > + * to be able to clear data when an application is uninstalled. I think I understand what you're saying, but it's kind of confusing. How about something like: Start watching the observer service for messages indicating that an app has been uninstalled. When an app is uninstalled, we get the cookie service (thus instantiating it, if necessary) and clear all the cookies for that app. Looks great aside from those nits!
Attachment #663416 - Flags: review?(justin.lebar+bug) → review+
Attached patch Part 1 - GetCookiesForApp — — Splinter Review
New version with minor changes.
Attachment #663414 - Attachment is obsolete: true
Attachment #663414 - Flags: review?(jduell.mcbugs)
Attachment #663674 - Flags: review?(jduell.mcbugs)
Attached patch Part 2 - RemoveCookiesForApp — — Splinter Review
Attachment #663415 - Attachment is obsolete: true
Attachment #663415 - Flags: review?(jduell.mcbugs)
Attachment #663675 - Flags: review?(jduell.mcbugs)
With jlebar's comments applied.
Attachment #663416 - Attachment is obsolete: true
Attached patch Part 4 - Tests — — Splinter Review
Adding a test to make sure that we don't actually delete non-app cookies when uninstalling an app.
Attachment #663417 - Attachment is obsolete: true
Attachment #663417 - Flags: review?(jduell.mcbugs)
Attachment #663677 - Flags: review?(jduell.mcbugs)
Comment on attachment 663675 [details] [diff] [review] Part 2 - RemoveCookiesForApp Review of attachment 663675 [details] [diff] [review]: ----------------------------------------------------------------- Thanks for jumping into this Mounir. The approach here is both more complicated and inefficient than it needs to be :) We don't need the enumerator functions in the IDL (getCookiesForApp). Just have the removeCookiesForApp, and have it 1) remove the entry in the nsCookieService::hostTable hashtable, and 2) issue a SQL statement that deletes the cookies from the database. That will be faster, easier, and you won't have to infer appId/inBrowser from nsCookies. I'm happy to look at the next rev of this, but for final review we'll need a cookie peer (or permission for me to review from one). mconnor is probably the best choice.
Attachment #663675 - Flags: review?(jduell.mcbugs) → feedback-
* If onlyBrowserElement is set to true, the method will only remove the * cookies marked as part of a browser element inside the app. * * Special app id values are not allowed (NO_APP_ID or UNKNOWN_APP_ID for example). Oh, also: B2G firefox appears to be using a nonzero appId for the app, but zero (aka NO_APP_ID) for the mozbrowser process's appID (I consider this to be an insane design decision, FWIW). So we'll need to either change that, or accept NO_APP_ID. Given that allowing NO_APP_ID would mean that we'd probably allow the firefox process to delete the OS's cookies (if it can pass NO_APP_ID and somehow also set inBrowser=false), we should probably change it. Do you know who made this decision? Fabrice didn't when I last asked him.
Comment on attachment 663674 [details] [diff] [review] Part 1 - GetCookiesForApp Review of attachment 663674 [details] [diff] [review]: ----------------------------------------------------------------- As mentioned I don't think we need the enum approach here. This code might come in handy at some future point when we want to expose a way for apps to enumerate through their own cookies. ::: netwerk/cookie/nsCookieService.cpp @@ +3767,5 @@ > + return NS_ERROR_NOT_AVAILABLE; > + } > + > + NS_ENSURE_TRUE(aAppId != NECKO_NO_APP_ID && aAppId != NECKO_UNKNOWN_APP_ID, > + NS_ERROR_INVALID_ARG); IIRC the mozbrowser process for B2G firefox is using NECKO_NO_APP (aka appID=0) for some reason (which really seems a bad idea to me), so we'd better either change that or accept it. ::: netwerk/cookie/nsICookieManager2.idl @@ +110,5 @@ > + > + /** > + * Returns an enumerator of all cookies that are related to a specific app. > + * > + * If the onlyBrowserELement parameter is set to true, only cookies part of onlyBrowserELement--lowercase the "L". Also "only cookies *that are* part of ..." @@ +112,5 @@ > + * Returns an enumerator of all cookies that are related to a specific app. > + * > + * If the onlyBrowserELement parameter is set to true, only cookies part of > + * a browser element inside the app will be returned. If set to false, all > + * cookies will be returned, regardless of their browserElement flag. I'm not sure the semantic here is optimal--there's no way to enumerate through just the app's cookies, you have to get its inBrowser ones mixed in.
Attachment #663674 - Flags: review?(jduell.mcbugs) → feedback-
(In reply to Jason Duell (:jduell) from comment #20) > Oh, also: B2G firefox appears to be using a nonzero appId for the app, but > zero (aka NO_APP_ID) for the mozbrowser process's appID (I consider this to > be an insane design decision, FWIW). This wasn't a design decision, it's just a bug.
Sorry, some earlier review comments got left in that last comment--ignore since I don't think we need the patch at all.
Comment on attachment 663675 [details] [diff] [review] Part 2 - RemoveCookiesForApp Hmm, it does look like the enumerate function might be useful just for the test--I'll look over that tomorrow. I still think the actual deletion shouldn't use enumerate.
Attachment #663675 - Flags: feedback- → feedback?(jduell.mcbugs)
(In reply to Jason Duell (:jduell) from comment #24) > Comment on attachment 663675 [details] [diff] [review] > Part 2 - RemoveCookiesForApp > > Hmm, it does look like the enumerate function might be useful just for the > test--I'll look over that tomorrow. I still think the actual deletion > shouldn't use enumerate. Indeed, that's exactly why I used that function: it helps testing and isn't really bad for performances. My plan was to have a follow-up to have the delete method not using this method (as said in a comment).
Attachment #663674 - Flags: review?(mconnor)
Attachment #663675 - Flags: review?(mconnor)
Attachment #663677 - Flags: review?(mconnor)
Depends on: 794023
> Oh, also: B2G firefox appears to be using a nonzero appId for the app, but zero (aka NO_APP_ID) for > the mozbrowser process's appID (I consider this to be an insane design decision, FWIW). So we'll > need to either change that, or accept NO_APP_ID. Given that allowing NO_APP_ID would mean that > we'd probably allow the firefox process to delete the OS's cookies (if it can pass NO_APP_ID and > somehow also set inBrowser=false), we should probably change it. Do you know who made this > decision? cjones said elsewhere and I agree that it's a bug. Let's change it. It looks like the dom/ipc/AppProcessPermissions.cpp is already written correctly, so hopefully this won't even break anything.
Whiteboard: [LOE:S][WebAPI:P3] → [LOE:S][WebAPI:P3][needs review]
Comment on attachment 663676 [details] [diff] [review] Part 3 - Hook to webapps-uninstall (r=jlebar) Review of attachment 663676 [details] [diff] [review]: ----------------------------------------------------------------- This also touches some cookie stuff--mostly uncontroversial IMO. ::: netwerk/cookie/nsCookieService.cpp @@ +566,5 @@ > + MOZ_ASSERT(appId != NECKO_NO_APP_ID); > + > + nsCOMPtr<nsICookieManager2> cookieManager = do_GetService(NS_COOKIEMANAGER_CONTRACTID); > + return cookieManager->RemoveCookiesForApp(appId, false); > + } IIUC if this happens to actually initialize the cookie manager for the first time, none of the cookies will be loaded yet, so when RemoveCookiesForApp enums there will be no cookies yet and nothing will get deleted. It seems quite unlikely that a user could actually navigate to app uninstall before the DB is loaded, however (the cookieService is loaded when the first HTTP channel is opened, including appcache and cache hits). So it's probably fine, for now at least.
Attachment #663676 - Flags: review?(mconnor)
Mconnor/Jduell - what's the ETA on reviewing this?
Soon(tm), hopefully today.
Comment on attachment 663674 [details] [diff] [review] Part 1 - GetCookiesForApp Review of attachment 663674 [details] [diff] [review]: ----------------------------------------------------------------- good enough for now, would like to see a followup on the get API at least to allow retrieving just the app cookies. ::: netwerk/cookie/nsCookieService.cpp @@ +3739,5 @@ > + > +} // anonymous namespace > + > +/* static */ PLDHashOperator > +nsCookieService::GetCookiesForApp(nsCookieEntry* entry, void* arg) using "arg" as an argument name bugs me a little, on general principle. @@ +3767,5 @@ > + return NS_ERROR_NOT_AVAILABLE; > + } > + > + NS_ENSURE_TRUE(aAppId != NECKO_NO_APP_ID && aAppId != NECKO_UNKNOWN_APP_ID, > + NS_ERROR_INVALID_ARG); Is there a bug on the NECKO_NO_APP thing discused in comments? ::: netwerk/cookie/nsICookieManager2.idl @@ +112,5 @@ > + * Returns an enumerator of all cookies that are related to a specific app. > + * > + * If the onlyBrowserELement parameter is set to true, only cookies part of > + * a browser element inside the app will be returned. If set to false, all > + * cookies will be returned, regardless of their browserElement flag. I agree strongly here, but not enough to block forward progress. I know this is just reflecting the delete options, but if you're sticking a get API in the IDL... let's just do it right.
Attachment #663674 - Flags: review?(mconnor) → review+
Comment on attachment 663675 [details] [diff] [review] Part 2 - RemoveCookiesForApp Review of attachment 663675 [details] [diff] [review]: ----------------------------------------------------------------- I think this is ok. I'm not sure why you inserted new arguments in the middle of existing ones, rather than just appending, but it doesn't really matter with only two consumers.
Attachment #663675 - Flags: review?(mconnor) → review+
Comment on attachment 663676 [details] [diff] [review] Part 3 - Hook to webapps-uninstall (r=jlebar) Review of attachment 663676 [details] [diff] [review]: ----------------------------------------------------------------- ::: netwerk/cookie/nsCookieService.cpp @@ +566,5 @@ > + MOZ_ASSERT(appId != NECKO_NO_APP_ID); > + > + nsCOMPtr<nsICookieManager2> cookieManager = do_GetService(NS_COOKIEMANAGER_CONTRACTID); > + return cookieManager->RemoveCookiesForApp(appId, false); > + } As pointed out on IRC, if the device starts in airplane mode... we may have a problem. I'm fine with treating that as a followup, it's a corner case at best, but we should file and triage appropriately.
Attachment #663676 - Flags: review?(mconnor) → review+
(In reply to Mike Connor [:mconnor] from comment #31) > @@ +3767,5 @@ > > + return NS_ERROR_NOT_AVAILABLE; > > + } > > + > > + NS_ENSURE_TRUE(aAppId != NECKO_NO_APP_ID && aAppId != NECKO_UNKNOWN_APP_ID, > > + NS_ERROR_INVALID_ARG); > > Is there a bug on the NECKO_NO_APP thing discused in comments? Do you mean bug 794023 about NECKO_UNKNOWN_APP_ID?
(In reply to Mike Connor [:mconnor] from comment #31) > ::: netwerk/cookie/nsCookieService.cpp > @@ +3739,5 @@ > > + > > +} // anonymous namespace > > + > > +/* static */ PLDHashOperator > > +nsCookieService::GetCookiesForApp(nsCookieEntry* entry, void* arg) > > using "arg" as an argument name bugs me a little, on general principle. I agree with that principle but in that case we have a void* that means nothing. We have to static_cast it to something. IMO, |arg| or |aData| would be the best names but both are vague names.
(In reply to Mike Connor [:mconnor] from comment #32) > Comment on attachment 663675 [details] [diff] [review] > Part 2 - RemoveCookiesForApp > > Review of attachment 663675 [details] [diff] [review]: > ----------------------------------------------------------------- > > I think this is ok. I'm not sure why you inserted new arguments in the > middle of existing ones, rather than just appending, but it doesn't really > matter with only two consumers. Because { host, appId, browserElementFlag } is the tuple that identifies a cookie. I think it's better if they are one after each other in the argument list.
Depends on: 794971
Depends on: 794978
Comment on attachment 663677 [details] [diff] [review] Part 4 - Tests Review of attachment 663677 [details] [diff] [review]: ----------------------------------------------------------------- Subject to biesi's request to not have mochitest in /netwerk, this looks good to me. r/sr=me (and really, that can apply to every patch on this bug, if jduell wants to mark r+ on these).
Attachment #663677 - Flags: review?(mconnor) → review+
Comment on attachment 663677 [details] [diff] [review] Part 4 - Tests No need for two reviews for tests.
Attachment #663677 - Flags: review?(jduell.mcbugs)
Attachment #663674 - Flags: superreview?(jonas)
Attachment #663675 - Flags: superreview?(jonas)
Comment on attachment 663674 [details] [diff] [review] Part 1 - GetCookiesForApp Review of attachment 663674 [details] [diff] [review]: ----------------------------------------------------------------- so this is now +r/sr between mconnor and I.
Attachment #663674 - Flags: superreview?(jonas) → superreview+
Comment on attachment 663675 [details] [diff] [review] Part 2 - RemoveCookiesForApp Review of attachment 663675 [details] [diff] [review]: ----------------------------------------------------------------- ditto. So all we need is the mochitest to move from /netwerk for this to land. We can clean up the code in followups.
Attachment #663675 - Flags: superreview?(jonas)
Attachment #663675 - Flags: superreview+
Attachment #663675 - Flags: feedback?(jduell.mcbugs)
Attachment #663675 - Flags: feedback?
Attachment #663674 - Flags: feedback-
Attachment #663675 - Flags: feedback?
Please be sure to file the followups before closing this bug, thanks!
> As pointed out on IRC, if the device starts in airplane mode... we may have a problem. What's the problem with airplane mode? nsHttpChannel addsCookies to channels even when offline during asyncOpen (observers need to see them), so cookie svc should still be present just as early: http://mxr.mozilla.org/mozilla-central/source/netwerk/protocol/http/nsHttpChannel.cpp#4392
(In reply to Mike Connor [:mconnor] from comment #42) > Please be sure to file the followups before closing this bug, thanks! I think all the follow-ups are already filed.
Whiteboard: [LOE:S][WebAPI:P3] → [LOE:S][WebAPI:P3][qa-]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: