Closed Bug 756131 Opened 12 years ago Closed 12 years ago

API for creating default profiles for webapps

Categories

(Toolkit :: General, defect)

x86_64
All
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: smaug, Assigned: smaug)

References

Details

Attachments

(1 file, 7 obsolete files)

Attached patch patch (obsolete) — Splinter Review
To be able to pre-populate webapps appcache, we need to be able to create the profile during installation.
If the following is run in FF, FF's default profile ends up to $HOME/.mozilla/foobarapp/{salt}.default
If "Mozilla" is not use, it will be in $HOME/.foobarapp/{salt}.default

var currentDefaultProfile = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("profDef", Components.interfaces.nsIFile);
var ts = Components.classes["@mozilla.org/toolkit/profile-service;1"].getService(Components.interfaces.nsIToolkitProfileService);
ts.createDefaultProfileForApp("FooBarApp", "Mozilla", currentDefaultProfile);

I just realized I'm missing still profile.ini handling.
Attachment #624783 - Flags: feedback?(benjamin)
Attached patch +profile.ini creation (obsolete) — Splinter Review
Attachment #624783 - Attachment is obsolete: true
Attachment #624783 - Flags: feedback?(benjamin)
Attachment #624823 - Flags: feedback?(benjamin)
https://tbpl.mozilla.org/?tree=Try&rev=e8ba9b56835d
Hopefully it compiles on Windows so that I can try creating profile for a web app before launching it.
Ah, webapps do something a bit strange.
profiles.ini is in directory Foo, but profile in Foo/Profiles/salt.default
Er, my mistake.
Doesn't help that I can use only linux for development :)
Attached patch v3 (obsolete) — Splinter Review
Attachment #624823 - Attachment is obsolete: true
Attachment #624823 - Flags: feedback?(benjamin)
Attachment #624926 - Flags: feedback?(felipc)
Attached patch v4 (obsolete) — Splinter Review
Attachment #624926 - Attachment is obsolete: true
Attachment #624926 - Flags: feedback?(felipc)
Attachment #624946 - Flags: feedback?(felipc)
Comment on attachment 624946 [details] [diff] [review]
v4

I tested v4 of the patch using that try build. It created the Path=Profiles/asfda.default correctly in the .ini file, and created the folder at appname/Profiles/asfda.default as expected, however the folder it created is empty
Attachment #624946 - Flags: feedback?(felipc)
did you pass the 3rd parameter to the method?
(Since I thought the v3 did copy the default profile files even on Windows, and v4 shouldn't change
that, only profiles.ini handling.)
Ok, I get the same problem :(
How strange. If I change the #ifdef which creates Profiles directory, I still get the
right profile on Linux.
Attached patch v5 (obsolete) — Splinter Review
Somewhat random guess. Ensure that Profiles directory exists before copying
anything under it.

https://tbpl.mozilla.org/?tree=Try&rev=6c6d1e49f9b9
Attachment #624946 - Attachment is obsolete: true
Attachment #624946 - Attachment is obsolete: false
Comment on attachment 625115 [details] [diff] [review]
v5

this doesn't help. So v4 is still the best one. Need to figure out why
right files aren't copied.
Is rv = profileDefaultsDir->CopyTo(profileDirParent, profileDirName);
in nsToolkitProfileService not executed or does it fail
Attachment #625115 - Attachment is obsolete: true
Felipe, or anyone with Windows dev environment, I could need some help here.
Smaug: does this seem like a timing issue and the patch v3 when I tried just worked by luck?  or is there something that changed between v3 and v4 that could have caused it to fail?
I'll debug it soon
ooh wait I second, when I build the patch myself (v4) it works.. when I use the try build it didn't (I'll try it again)..  maybe this is a packaging issue
indeed, currentDefaultProfile.exists() is false on a packaged build
Bizarre. But ok, so Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("profDef", Components.interfaces.nsIFile); is wrong.
Does default profile handling work with packaged builds at all?
Need to test.
That is indeed true, at least on linux. Files don't get created when profile is created.
When using own build, the files are created when the profile is.
Comment on attachment 624946 [details] [diff] [review]
v4

I'm not going to fix that behavior in this bug.
This should give similar to current webapp profiles when the
2 latter parameters are omitted.
Attachment #624946 - Flags: review?(benjamin)
...and if webapps need a default profile, some new, non-packaged stuff can be added to Firefox installation.
Comment on attachment 624946 [details] [diff] [review]
v4

But I want to change the API :/
The method should give two nsIFiles out, the rootdir and localdir.
I believe appCache stores data in localDir
Attachment #624946 - Flags: review?(benjamin)
Attached patch v6, reuse nsIToolkitProfile (obsolete) — Splinter Review
This is pretty flexible. The appname and optional vendor name are passed to
nsXREDirProvider so that right kind of directory hierarchy can be created.
aProfileDefaultsDir lets one to define where the "template" for the profile is.

https://tbpl.mozilla.org/?tree=Try&rev=b0097709a637
Attachment #624946 - Attachment is obsolete: true
Attachment #625426 - Flags: review?(benjamin)
Comment on attachment 625426 [details] [diff] [review]
v6, reuse nsIToolkitProfile

Since webrt overrides the normal system in nsXREAppData: http://mxr.mozilla.org/mozilla-central/source/webapprt/win/webapprt.cpp#289

So in order to do this with the same logic as nsXREDirProvider::AppendProfilePath you really need appname, vendor, and "profile" from nsXREAppData, and vendor name really shouldn't be optional in the IDL. I think the rest of the patch is fine, but I'd like some comments in nsXREDirProvider.h explaining why we need to pass in directories to the methods like GetUserDataDirectory and such.
Attachment #625426 - Flags: review?(benjamin) → review-
(In reply to Benjamin Smedberg  [:bsmedberg] from comment #26)
> Comment on attachment 625426 [details] [diff] [review]
> v6, reuse nsIToolkitProfile
> 
> Since webrt overrides the normal system in nsXREAppData:
> http://mxr.mozilla.org/mozilla-central/source/webapprt/win/webapprt.cpp#289
> 
> So in order to do this with the same logic as
> nsXREDirProvider::AppendProfilePath you really need appname, vendor, and
> "profile" from nsXREAppData, and vendor name really shouldn't be optional in
> the IDL. 
Vendor is optional in the other cases. Why not here?
I think that the caller should specify it, whether it is null or a value.
Attached patch +comments (obsolete) — Splinter Review
https://tbpl.mozilla.org/?tree=Try&rev=2a0484aab586
Attachment #625426 - Attachment is obsolete: true
Attachment #626166 - Flags: review?(benjamin)
Maybe this even compiles on platforms I can't build on.

https://tbpl.mozilla.org/?tree=Try&rev=03b29673813f
Attachment #626166 - Attachment is obsolete: true
Attachment #626166 - Flags: review?(benjamin)
Attachment #626192 - Flags: review?(benjamin)
Comment on attachment 626192 [details] [diff] [review]
+compilation fixes

+  nsresult rv = GetUserDataDirectory((nsILocalFile**)(nsIFile**)
+                                      getter_AddRefs(file),

Darktrojan is fixing most of this in bug 749930, but if you can just change GetUserDataDirectory to nsIFile while you're here this will avoid the terrible terrible casting.
Attachment #626192 - Flags: review?(benjamin) → review+
IIRC I tried that but I would have had to change plenty of other code too.
https://hg.mozilla.org/mozilla-central/rev/4f66e59eaa77
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: