Firefox 3 for Mac OS X: Under the Hood

Josh and his grandfather RolandFirefox 3 will be released soon (get the RC here). While the release contains a huge number of new features and performance improvements for all platforms, it is particularly significant for Mac OS X users. We rewrote most of the Mac OS X code that was behind Firefox 2 in order to benefit from modern Apple technologies and fix long-standing bugs. Once you try it I think you’ll agree that the results are astounding. I’d like to explain what exactly we did in this rewrite, how Firefox 3 for Mac OS X is different “under the hood.”

Before I start, I need to explain Gecko vs. Firefox for anyone who doesn’t already know. Gecko is the engine behind Firefox. It provides the capabilities that we use to build Firefox. Under the umbrella of Mozilla, Gecko is actually a much bigger project in technical terms than Firefox is. For example, there is much more Gecko code than there is code specific to Firefox, which is an application we built on top of Gecko. Firefox and Gecko have different version numbers – Firefox 2 uses Gecko 1.8.1 and Firefox 3 uses Gecko 1.9. This post is about changes we made in Gecko 1.9, the engine behind Firefox 3.

The biggest change is that Gecko 1.9 is based on Cocoa instead of Carbon on Mac OS X. There has always been a lot of confusion about what this means, particularly since Gecko 1.9 also happens to include Aqua form controls. It may seem strange to some, but Gecko’s new Cocoa underpinnings and its Aqua form controls are almost completely unrelated.

There are only 2 types of Cocoa objects at the heart of Gecko 1.9 on Mac OS X (let’s forget about the menu bar at the top of the screen for now). Cocoa’s NSWindow allows us to make and control a window on the screen and Cocoa’s NSView allows us to draw things into a window. Those two objects also allow us to get most of the events we need to know about from the operating system (such as key and mouse events). We do not use actual Cocoa buttons or any other Cocoa controls within any Gecko 1.9 windows. The context menus, dropdown menus, the toolbar, the search bar, the buttons and text fields within web pages – they are not actual Cocoa controls. For example, instead of using actual Cocoa buttons for “Submit” buttons we just draw the image of an Aqua “Submit” button into an NSView, one of the basic Cocoa objects we use. Gecko 1.9 has Aqua form controls because we now draw images of Aqua form controls when appropriate, not because we use actual Cocoa controls. The reason we don’t use actual Cocoa controls isn’t because we are lazy or we can’t figure out how to use them or because we are constrained by our cross-platform requirements – Apple’s WebKit doesn’t use actual Cocoa controls for things like “Submit” buttons or popup buttons in web pages either, at least not the last time I checked. IE for Windows is in the same boat. The reason Gecko 1.9 doesn’t use Cocoa controls is for the sake of flexibility – form control behavior and appearance can be changed significantly via HTML, CSS, and JavaScript. Actual Cocoa controls are simply not flexible enough to do all of the things that people want to be able to do with controls on the web.

So if we didn’t get Aqua form controls out of the deal why did we do the Cocoa rewrite? First of all, Apple has deprecated much of Carbon already1 and has made it clear that Cocoa is the future for Mac OS X applications. Apple is investing heavily in Cocoa, which benefits us if we use Cocoa. Cocoa also gives us access to great features that would be more difficult or impossible to take advantage of through Carbon. For example, with Cocoa we were able to relatively easily draw using CoreGraphics instead of the ancient Quickdraw API (more on this later). Secondly, the Cocoa way of doing things matches up with the Gecko way of doing things better than Carbon did. Our Cocoa code is easier to understand and maintain because of this2. This will result in faster development and fewer bugs in the long run. In fact, we actually added more capabilities to Firefox 3’s Gecko 1.9 (such as transparent windows, unified toolbar windows, and an alert service) than we have ever added in any release of Gecko since Firefox 1.0. This is in addition to doing a huge amount of work just to re-implement many of the features that Gecko 1.8.1 had already implemented in Carbon!

Another major under-the-hood change in Gecko 1.9 for Mac OS X is drawing via CoreGraphics and ATSUI instead of Quickdraw. Like much of Carbon, Quickdraw is deprecated and does not exist in 64-bit Mac OS X. Gecko 1.9 uses the Cairo library on all platforms, and Cairo draws with CoreGraphics and ATSUI on Mac OS X. The CoreGraphics drawing API is modern and hardware accelerated, a huge improvement over Quickdraw in terms of speed, capabilities, and code clarity. In addition to using CoreGraphics ourselves, we have made it possible for plugins to use CoreGraphics via NPAPI Drawing Models3. Flash is already prepared to take advantage of this new capability in Gecko 1.9! As for text, using ATSUI allowed us to improve our text kerning and ligature capabilities. It also gives us better glyph cluster positioning, which is good for Indic languages and languages that use exotic combining marks.

I hope this helps to shed some light on why Firefox 3 is a particularly significant upgrade for Mac OS X users. I’m really proud of what we accomplished with this release, it was ambitious and things worked out well. Kinks remain as with all major revisions, we’ll be addressing those quickly in minor updates to Firefox 3.

==

1 While the deprecated Carbon API is still available for 32-bit applications like Firefox 3, it simply won’t be available to 64-bit applications. Firefox 3 for Mac OS X will not be available in 64-bit but we’re preparing for 64-bit by removing code that won’t work in 64-bit.
2 It might be true that on the whole our Cocoa implementation is more complex than our Carbon implementation was, but that is because our Cocoa implementation does far more than our Carbon implementation ever did. The Cocoa code is still more readable and maintainable.
3 See the NPAPI Drawing Models spec. http://wiki.mozilla.org/Mac:NPAPI_Drawing_Models

About these ads

About Josh Aas

Josh Aas is a Gecko platform software engineer with Mozilla Corporation.
This entry was posted in Mozilla. Bookmark the permalink.

54 Responses to Firefox 3 for Mac OS X: Under the Hood

  1. pets says:

    But what about Core Text (http://en.wikipedia.org/wiki/Core_text) instead of ATSUI?

    I am asking because the same signal of deprecation applies equally to Carbon and to ATSUI and some other stuff as well. Read what John Siracusa said: “Core Text replaces the confusing alphabet soup of text APIs in Mac OS X Tiger and earlier, mostly inherited from classic Mac OS: ATSUI, MLTE, and QuickDraw text.”

    http://arstechnica.com/reviews/os/mac-os-x-10-5.ars/11

  2. David Emery says:

    Cool, thanks for the notes. My biggest concern with FF 2.x has been its performance if I leave it running for a long time. After a while, although VM growth isn’t recorded, the app basically becomes non-responsive. This is particularly noticeable when I click on a CNN.com link that takes me to one of their affiliated sites with the “15 best xyz”, and I try paging through those 15 links.

    dave

  3. Sean says:

    What’s keeping me on Safari instead of using Firefox is the fact that, in spite of all of this Cocoa goodness, Firefox still does not seem to be able to use the Services menu that is available to all other Mac apps (http://tinyurl.com/5ryn4o)

    Related, I suppose, is the fact that I can’t select text in Firefox and automatically send it to LaunchBar – this is the true showstopper for me.

    Are there plans in the works to address that?

  4. Zorin says:

    One issue I’ve noticed with Firefox 3 (all the way up to the current release candidate) on Mac is that after browsing for a few hours, the browser seems to “break”.

    Pages load incomplete, images don’t appear, and even Firefox -> Quit doesn’t exit the browser and I have to right-click the dock icon and select quit to exit it.

    I filed this as a bugzilla bug (424337) but nobody has commented on the bug, so I’m not sure it’s being seen by the appropriate people.

    I figured I would bring this to your attention, since you are one of the developers; this issue has occurred on both of my Macs so it doesn’t seem to be specific to one machine.

  5. Jon says:

    I get Zorin’s bug too on both my machines – PowerBook G4 (Tiger) and MacBook (Leopard).

  6. Chrigi says:

    Nice to hear, that you made more than just a new (and quite gross ;) ) UI for the Mac. I think it’s a good step to keep “cross platform” but integrate it better into the OS. I hope KeyChain integration will come next ;)
    One other little question: Does Gecko 1.9/FF3 use the Sandboxing features on Leopard as Safari does?

  7. Josh Aas says:

    “One other little question: Does Gecko 1.9/FF3 use the Sandboxing features on Leopard as Safari does?”

    At this time, no.

  8. Jubal says:

    Can I compile stock FF3 on Mac to be 64-bit?
    I think I need 64-bit to run Java 6 applets.

    Concise answer appreciated.

  9. Hey, Why no support for Mac OS 10.3 or earlier ???? This is not very fair !

    Windows 2000 is supported and old pentiums also.

    I cannot install 10.4 on my mac (no Firewire). I may not be the only one in this situation. Mac Users are not necessary rich guys or addicted geeks that always have a brand new Hardware.

    Please can you send this message to the Firefox team ?

    THNAK YOU !

  10. Ben C says:

    Just a quick thanks! Us Mac users really appreciate what you guys have done. I just wish I could use my Mac at work…stupid Windows XP.

  11. Cairo Gobs says:

    Great job ! I can notice the difference with ATSUI I guess on large arabic text display for instance. But since beta versions of fx3, I’ve experienced the same slowdown (and extensive fan activity) as Zorin with my PowerBook G4 (Tiger), with top command reaching 70% on very simple sessions (4 or 5 concurrent tabs ). A since I still use fx2 for heavy work….
    Thank you again

  12. Bob says:

    Are you working on fullscreen support for firefox on Mac OS X. This is a real limitation at this point. Lots of Mac applications have true fullscreen support so it should be possible.

  13. Josh Aas says:

    “Can I compile stock FF3 on Mac to be 64-bit? I think I need 64-bit to run Java 6 applets.”

    We cannot produce 64-bit builds of Firefox for Mac OS X at this time. There is a lot of work that needs to be done there and we’re on it, but it’ll still be a while. I don’t know about Java 6 and how it relates to the question of 64-bit.

    “Hey, Why no support for Mac OS 10.3 or earlier?”

    Apple evolves very quickly. Mac OS X 10.3 does not do many of the things we need it to do and we don’t have the resources to offer support that far back.

    “Are you working on fullscreen support for firefox on Mac OS X.”

    We are working on it though admittedly it is not a high priority task.

  14. Josh Aas says:

    “But what about Core Text (http://en.wikipedia.org/wiki/Core_text) instead of ATSUI?”

    CoreText is not available on Mac OS X 10.4, which Gecko 1.9.0 supports, so we couldn’t use it. We have plans to use CoreText in Gecko 2.0, which will only support Mac OS X 10.5 and higher.

  15. Dustin says:

    Hey, great work on ff3, it’s awesome!

    My bug report: dragging an image from a webpage onto Photoshop in the dock doesn’t work. Says it’s not the right type of document. I would love to have this work…

  16. sardisson says:

    Dustin, that’s possibly the same thing as bug 433093. Without being able to see the insides of the receiving app (or documentation on what flavors it wants), though, it’s really hard to know what the problem might be.

  17. vegangeek says:

    The main thing that keeps me on Safari, and likely will continue to, is the lack of text system integration. I use and rely on the ability to lookup words in the dictionary/thesaurus with a keystroke (FF3 doesn’t even let me select the word and then use context menu, as that’s custom too), and the inbuilt spell checking in text entry areas. I know gecko has its own spellcheck, but why have to maintain a separate custom dict, etc. if all my other apps use the one provided by the system?

  18. Machine says:

    When I drag and drop a photo from a website to the desktop in Tiger, it won’t drop where I’ve indicated and snaps to the desktop grid. If I drag/drop a photo into a folder… the folder is snapped to the grid most of the time… while at other times it is sent to the middle of the screen. Firefox appears to be the only browser that behaves this way and it’s quite annoying.

    Has anyone experienced this issue with Leopard?

  19. And some Mac bugs will go into the release today. See Bug #437456.

  20. Pete says:

    I have the latest build of 3 (still waiting for the final release today though) and am on Tiger 10.4.11. I am experiencing major problems: response often very slow – prevents me from moving the browser window around until the processor has slowed up again. Simple re-sizing of the Firefox window causes a huge spike in processor activity (fans whirr madly etc) – whilst this is going on Firefox is of course completely unresponsive.

    Something’s definately not right – all other browsers (safari 3/opera etc) and apps perform normally, so this is definately a firefox 3 specific problem.

    I hope things will work better with the public release version today!

  21. Chu Wei says:

    I really appreciate all the work that has gone into the Mac version. One thing that still bothers me and a lot of other Safari users though is the fact that Firefox can’t seem to scroll properly. Choppy with smooth scrolling turned off, laggy if on.

    I’ve been using Safari 3 as it’s noticeably faster than firefox 2. I was going to switch back to firefox 3 since the RCs but noticed the lag straightaway after getting used to safari’s silky smooth scrolling.

    However, once all extensions support ff3, I will probably switch back anyway. But it’d be nice if firefox can scroll as smoothly as safari.

  22. jason says:

    Pete. I had the same slowdown issue on my imac g5 at home. The browser would stall. Big problem. This was a straight copy over Firefox2. I decided to do the bookmark backup. Then delete EVERYTHING that was for Firefox/Mozilla on the machine. I then reinstalled. I’m now no longer having any slowdown issues. Of course this is bad for less technical users.

  23. Lola LB says:

    I agree about services. It shouldn’t be too difficult to add that in and Apple has plenty of documentation on how to do this. Services feature has been around for more than 4 or 5 years. What’s the holdup here???

  24. Joshua says:

    Major issues on my end with scrolling and CPU, especially on pages with any type of Flash. If a second or third window with even a small Flash ad is open, it dramatically slows down the scrolling, causes the CPU to spike, and heats my iBook G4 (1.33 GHz) (runs Leopard). This is NOT a bug I expected to be allowed into FF3, but I guess I shouldn’t be surprised. It’s absolutely disappointing.

  25. Matthew says:

    What is going on with the font rendering in FF3 on Mac OS X? Specifically, light text on top of a dark background looks bold, even when the font-weight property is set to normal. Firefox 2 did not have this problem. Firefox3 for the PC does not have this problem. Firefox3 for OS X seems to be the only browser rendering larger text bolder than it should be. This has made my company’s website look TERRIBLE. We have literally been searching for a solution for the past 18 hours and have not been able to find anything. Please give us some insight as to why this is happening. What would have changed from FF2 to FF3 on OS X that would cause font rendering to be so distorted and inaccurate?

  26. edgeoforever says:

    My IMac (OSX) rejects the FF3 – it just appears in the dock then goes away…So, I had to reinstall 2 ….sigh

  27. yonghweefoo says:

    I’m loving Firefox 3! Seems a lot more stable than 2.

  28. daftmonk says:

    I’m loving the new fox – but I do sincerely hope that true fullscreen becomes available, whether it’s part of the package or as an extension.

    Saft for Safari gives me true Full Screen, but Firefox would be perfect if it did the same.

  29. vincent says:

    I’m having problem with text encoding/font rendering on certain sites such as wikipedia. Instead of seeing letters from correct alphabet/legible font, I’m seeing unicode/cyrillic looking alphabets. It only happens on certain sites, and on these sites the words are completely illegibe. Another strange thing is that it mess up the safari’s capability to display letter correctly as well. Anyone has any clue?

  30. flo says:

    Services menu certainly works for me on FF3 in 10.5 … did you actually try it?
    To flash problems: I really wouldn’t blame that on FF3, I think it’s quite widely known that flash is an obnoxious resource hog and that the mac os x implementation is especially bad.

  31. racer of SEO says:

    We cannot produce 64-bit builds of Firefox for Mac OS X at this time. There is a lot of work that needs to be done there and we’re on it, but it’ll still be a while. I don’t know about Java 6 and how it relates to the question of 64-bit.

  32. Paul says:

    The services menu is not working for me either. You might get the menu, but all the options are grayed out. I need it to easily clip text to my notetaking application.

  33. Asad says:

    Vincent, i have the same problem. wikipedia and slashdot among others.
    looks like tiny numbers with lines over them or something.
    i hadnt even realized that it killed safari too.
    wtf do we do?

  34. Wayne says:

    Hi,

    OT question. I am new to Cocoa and want to get some advice from you. How do I program a text input that behaves like the address bar in FF3.
    1) auto complete from history
    2) Drop down list of history from the “down arrow” icon at the right.

    Thanks,
    Wayne

  35. Asad says:

    hey Vincent, disable all your fonts. i’m not sure what was messing it up, but that fixed my problem.

  36. MrLee says:

    Vincent, I too had the same font display issue(Craigslist was horrific). My solution was to change the default font from within Firefox (Firefox / Preference / Content / under Font & Colors), for instance from “Times” to “Times Roman”. Wish I knew the cause of the problem for something so simple–for is it my Mac, or a corrupt font, or a Firefox? But this is the work around.

  37. Hey Josh: FF3 doesn’t use ATSUI for it’s about box and chrome.
    For an example try using an indic localisation and you’ll see that the ZWJ/ZWNJ glyphs aren’t suppressed, and vowels aren’t rearranged. This problem does not occur on actual web pages in FF3.

  38. David says:

    Seems like I’m having the same problem as edgeoforever. I’ve installed firefox 3 on my mac and everytime I try to open it, it closes down. The small black upsidedown triangle underneath the FF icon (in the dock) signals to me that its opening for about a second then disapears. I have no idea why this is happening as i have followed the installation guide on their website (eg: copied FF to my apps folder etc). I’d be greatful for any infomation on how to fix this problem or if someone could shed some light on something I’m doing wrong. Thanks.

  39. space man says:

    Talking about Firefox and Safari, I think they both are kinda equal…And its true that now it seems impossible to produce 64-bit builds of Firefox for Mac OS X. We in Russia trying to make something out of this:)By the way, I dont have problem with Firefox scrolling,goes pretty smooth:)

  40. Sasha says:

    Hi, people,
    I ran into a problem: Firefox 3 for Mac diplays a drop content bug on our site: http://www.nti.org
    It is similar to the 3 px drop bug in IE6 for which I had to use a proprietary hack.
    The problem only shows in the Firefox 3 for Mac version. Firefox for Windows is fine. I would appreciate any of your insight into how I can combat this in Firefox 3 for Mac. Is there any kind of proprietary code I can use? thanks.
    Sasha
    nikitin@nti.org

  41. SwineFactory says:

    Fullscreen support for FF3 on OS X *should* be a priority – us designer types (you know, the ones who own macs? Ostensibly the people you’re developing FF3 on OS X for…) eat up fullscreen mode for the presentation enhancements that if gives when previewing work. A number of the designers that I’ve worked with load parallels on the machines of their art directors specifically so that they can demo live web work using fullscreen mode.

    Bringing it in would be a boon, and remove the whole pesky virtualization thing (for what I would consider to be a defining feature that’s conspicuously absent on a major platform).

    I’m sure there’s a good reason that it’s missing, but certainly, it’s not an insurmountable challenge to include it, is it?

    I, and many others, would love you long time (and further aim to promote the dominance of FF).

  42. SwineFactory says:

    Sorry – edit to the above. The somewhat confusing sentence about designers and parallels should have read:

    “A number of the designers that I’ve worked with load parallels on their machines specifically so that they can… etc.”

    My non-linear comment writing is catching up with me again, and annihilating what little coherence I manage to hang onto through all of the whiskey ;)

  43. Chris says:

    I’m using identical builds of the latest download of FF 3.0.5. on an Intel Mac on 10.5.6, and on an old white iBook G3 on 10.4.11.
    – Why won’t it load images from Wikipedia on the IntelMac? I am now forced to go back to using safari.

  44. EdmonCU says:

    I have consistently noticed on all editions of Firefox (w/o any 3rd party-installed add-ons) on all my machines (G4 / dualG4 / dualG5 / Intel Core2Duo Mac) is behaving the same way… (even on a Freshly installed OSX — used Tiger and Leopard and from v2 until the latest v3 Firefox)

    – Flash animations and actions are slow and choppy.
    – Java script (IRC) tend to have display problems. Images disappearing w/in the Java applet.

    What’s odd is that in Safari, none of these behaviors show.

  45. disgruntled says:

    FF3 for mac freezes and crashes after a couple hours of use. Especially on facebook and myspace. FF2 did this too. So dissapointed. Please fix. Plus it’s a resource hog. Losing faith.

  46. Robert says:

    “Apple evolves very quickly. Mac OS X 10.3 does not do many of the things we need it to do and we don’t have the resources to offer support that far back.”

    Well maybe WE ALL don’t have the resources to buy a million goddamn new computers. You’re forcing us to turn perfectly good 4-5 year old systems into toxic e-waste, coz a newer OS won’t run decently on it.

    “don’t have the resources” – then what was the 55 million dollars Mozilla got from Google Adwords? Couldn’t you, like *pay* someone to do the dreary scut work volunteers can’t be bothered to do? That’s what most volunteer organizations do…

    I mean, honestly. Who are you writing Firefox for? Regular folks, or you “replace your computer every year” digirati? Grrr…. I thought the whole POINT of the Mozilla foundation was internet democracy and access to all. Yes it’s true you look at your access logs and don’t see a lot of older OS’s… but this is self-fulfilling.

    What, “use firefox 2 then”? Two problems. #1, security is no longer being maintained, so that’s the road to getting hacked. #2, modern Web application writers think the same way you do, and demand/require more modern browsers.

    So who is in the best position to help with gap between web applications and consumer hardware/OS? Ding. The browser folks.

  47. Bob says:

    We’re starting to notice on the Mac OS that Firefox 3.x is not properly handling applet window updates. Our applet is sending the display.repaint() call; the OS is not returning applet.update().

    Jmol to OS: display.repaint(); // tell the OS to upate the page
    OS to Jmol: update(); // tell Jmol to construct a new screen buffer and display it in the window.

    Our crude test at http://chemapps.stolaf.edu/docs/examples-11/testmac.htm repeats endlessly until this quirk appears. The OS just doesn’t return Jmol’s call. No other problem with other operating systems that we know of.

  48. Gord says:

    I am loving firefox 3. much better than 2 on a mac thats for sure. Thanks for the post and the blog, it is a much apreciated resource.

  49. dineys says:

    In the end, the Mozilla community, organization and technology is all focused on a single goal: making the Internet better for everyone.

  50. I’ve only just moved over to firefox, I wasn’t that bothered before but really glad I did!

  51. Gary Arctic says:

    It still amazes me how powerful firefox is as an open source software. I love the fact that you can customize and build firefox into such a powerful application even moreso than a browser due to all the extensions you can add.

  52. FF I use for a long time. It is my favourite browser. But I would like, that at viewing of a code of page it would be more simple. It is dream only?

  53. Firefox 2 had huge problems, but it seems that most of them have been fixed in version 3. Glad to see more and more people switching over to Apple, I switched years ago and never looked back.

  54. I love the new Firefox 3. It’s a world better that the old Firefox 2 on a Mac. You’re performing a great service to your visitors by opening the comments area, it’s a terrific way to connect with them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s