no intersection more awesome
Header

Associating Firefox Profiles with KDE Activities

August 16th, 2012 | Posted by Jason "moofang" in KDE | Linux | Mozilla

As a heavy user of the Activities feature, I’ve always had two major itches. One was addressed when KDE 4.9 finally brought the ability to set activity window rules. The other was how only some applications had the necessary (XSMP) compliance to work properly with activities and its session restoring – in particular, a lack of compliant web browsers.

In fact, to date, the only apparently fully XSMP compliant web browser I know of is Konqueror, full stop. And while Konqueror is a pretty decent browser, its lack of a Firebug-esque DOM inspector made it increasingly inadequate for my purposes now that I do a lot of web development for my day job.

Being reduced to keeping one giant unmanageable lump of tabs in one central Firefox instance gave me plenty of incentive to think hard about the problem. Since it doesn’t look like Firefox or any other browser was gonna go compliant on its own anytime soon, the thought occurred to me if compliance might be hacked in by proxy: if I could manage the browser instance via an external program, I could deal with the session manager from my program and proxy the desired behavior onto the browser instance. So I spent some free time looking up how I might be able to externally control Firefox or Chrome or whatnot. Not surprisingly, the browsers aren’t very open to external controlling, but Firefox’s profiles feature provided just enough command line controls to be exploitable for my purposes. You could run different profiles simultaneously, with each profile being it’s own single process and conveniently remembering it’s own state/session information. So all I needed to do was write an XSMP-compliant program that keeps a Firefox profile name as state information, launches the Firefox instance so it knows its PID, killing the correct Firefox process when the activity closes and the session manager tells it to save state, and reading the profile name and relaunching the Firefox instance for it when the session restores.

So I went ahead and wrote that program, and dubbed it ‘activityfox’. It works quite well :) The proxy program needed to be a GUI application because it seems like the session manager doesn’t save and restore console ones, but with a little Kwin window-rule magic we could completely hide away the proxy program’s GUI window. Here’s a short screencast showing it in action:


OGG here

The way it works is you launch activityfox in an activity, which by proxy launches a Firefox instance with your chosen profile. activityfox will be automatically associated with the current activity, and when you stop the activity, activityfox will be asked to save state and close, and it’ll save the profile name and close it’s child Firefox process too. When you relaunch the activity, the session mechanism automatically calls up activityfox again, which reads the profile name from its saved state information, and uses that to restore the right Firefox profile instance. Since every Firefox profile instance is its own process, you can have as many Firefox profiles running in as many activities as you want, and they’ll all behave. Stopping an activity only closes it’s associated Firefox profile instance, leaving the rest alone, and restoring it restores the instance.

Source code, with build and usage instructions, can be downloaded here (Edit: it’s now on my github here). I’m afraid it’s a C++ program you need to compile: I tried to make it a python script, but for some reason it always crashes after KMainWindow::saveProperties is called, whereas the equivalent C++ program worked fine.

  • Facebook
  • Twitter
  • Identi.ca
  • Delicious
  • Digg
  • Google Buzz
  • StumbleUpon
  • Add to favorites
  • RSS
1239
Rate this post
Thanks!
An error occurred!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

19 Responses

  • Ivan says:

    Cool idea.

    I was (am) planning to make a firefox addon that will integrate firefox with activities on two levels:
    – report the open documents to the activity manager (1st step)
    – link tab groups and activities – so the same instance of firefox would be able to handle multiple activities properly.

    This is going to take a lot of time since I don’t really know how to write firefox addons, but I hope it will be done eventually :)

    • Jason "moofang" says:

      I actually have no idea how to do that: talk to the activitymanager and such. This is a little of a hacky solution, but it works well enough for me until you can get a more complete solution up :)

      Actually now that I’m using this I kinda like how every activity’s Firefox instance can have its own settings and addons.

  • It doesn’t seem like this will handle opening links from Kmail or Kopete. Have you found a solution to that? Take a look at the -no-remote flag.

    • Jason "moofang" says:

      I am using that flag, that’s how you get a different process/window for different firefox profiles. In my setup right now I’m using chromium as my default browser with firefoxes opening when I open activities, so all my links open in chromium. If your default browser is firefox I think all links would open in firefox’s default profile? If you want it to open in the current activity’s profile it’ll be tricky. Potentially another proxy program can communicate with activityfox to figure out which firefox profile is associated with the current activity and open links using that profile, then that proxy program can be supplied to KCM as “default browser”. Will take some thought and experimenting.

  • Oliver Henshaw says:

    Whayt do you mean when you say that firefox isn’t fully XSMP compliant? Do you see problems with basic login/logout session restores or is there some special XSMP feature that activities require that the normal session restores don’t.

    If the former, this sounds like https://bugzilla.redhat.com/show_bug.cgi?id=831347#c7 – firefox was XSMP aware but needs libgnome for it to work right. The problem is that this isn’t installed anymore or pulled in by firefox, since it would bring in long-deprecated gnome tech (which in turn pulls in long-deprecated freedesktop tech like HAL). There’s some prototype libSM integration in https://bugzilla.mozilla.org/show_bug.cgi?id=694570 but nothing has happened with that in the last few months.

    So firefox may be closer to being xsmp compliant than you think. Even though it isn’t as close as we might like.

    • Jason "moofang" says:

      Interesting, so does that mean if I pull in libgnome I get full XSMP compliance? I need to try that when I’m free.

      The way I understand it, in order to work well with activities, an application needs to not only be able to save state and restore its state, but do it in an instance-specific fashion, so that you can have multiple sleeping activities and restoring any one will restore that specific instance of the app. Moreover with something like firefox it’ll _still_ be tricky even with such full XSMP compliance because, be default, the entirety of firefox is one single process, ie one single instance, so in order to for it to behave like konqueror does – have a window attached to each activity – you’ll still need to either open a different profile in each activity (but you won’t need a proxy program), or do something like what Ivan said above.

  • Andrew Potter says:

    I’d like to have something like this for Libre-Office.

    • Jason "moofang" says:

      It’ll be pretty hard :( I took a quick look and libreoffice doesn’t really have a comparable invokable profile feature. The darned thing is libreoffice has enough XSMP support to support one session per user, so it restores fine if you log out/log in for example, but not if you have many activities. I guess only in the case of activities do you have many sessions used by one user. If I understand this right though this is nonetheless incomplete compliance with XSMP on libreoffice’s part and so could probably be filed as a bug to libreoffice.

      A possible incomplete hack could be to launch a proxy program with the file you want to open, so the proxy program remembers the file and restores it. However this means that if you file > open another file in libreoffice the proxy program has no way of knowing. Also, you can’t handle the new file case.

      • Jason "moofang" says:

        Hmmm, actually, I just had an idea that might work to help make non-compliant apps like libreoffice work better with activities. Would not be a complete solution of course, but might be better than the current state of simply doesn’t work. Let me think and try it out, I’ll make a blog post if anything ever comes of it.

  • Bugsbane says:

    By the way, Blip.tv don’t allow you to link straight to the source video (ogv in this case) any more. If anyone tries to look at it, they get redirected to a short video telling them they need to view it in the embedded player or on Blip.tv.

    As far as I know, the only major video host that lets people view the original version is Vimeoh, but they only let people download it if they’re logged in to Vimeoh.

    *sigh*

    • Jason "moofang" says:

      Thanks for the heads up, but did you try my link? As far as I can tell it seems to work somehow – I got my friends to try it and such. Or could it be a geographical thing where certain places aren’t allowed to view/dl the source ogv (which sounds completely senseless)?

  • Chani says:

    OMG. you are awesome. :) :)

    I was beginning to think I’d have to do this myself ;) and I haven’t had *any* time for non-work code any more :(

  • Satsuki says:

    404 – That Blip has sailed.
    I cant download .ogg too :(

    • Jason "moofang" says:

      Yep Blip has since changed the way it operates and has snipped me off in the process :( I’m afraid the screencast is lost now, but it doesn’t contain any critical info not described in the post. Feel free to ask here if something is unclear all the same.

  • Excellent post. I used to be checking continuously this weblog and I’m impressed!
    Very helpful info specially the remaining part :) I maintain such
    info much. I used to be looking for this certain info
    for a long time. Thank you and good luck.

  • melia says:

    After going over a few of the blog articles on your blog,
    I truly appreciate your technique of writing a blog. I book-marked it to my bookmark site list and will be checking back in the near future.
    Take a look at my web site as well and tell me how you
    feel.

  • Trena says:

    Unquestionably imagine that that you stated. Your favourite justification seemed to be
    on the web the easiest thing to remember of. I say to you,
    I definitely get annoyed at the same time
    as other people consider issues that they just don’t
    realize about. You controlled to hit the nail upon the highest
    and also defined out the entire thing with no
    need side-effects , people can take a signal. Will probably be back to get more.

    Thanks



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>