Hi all,
I would like to bump this discussion a little bit. What Alive proposing is
still a draft but I would like to know if this is the right direction. I
have not go through with Alive on the specifics yet though.
Ideally, everything should be dynamic in a Firefox OS System app so people
can plug/unplug features at well. Besides, it could cut the HTML parsing
time significantly, and we could in turn cut the load time by lazily loads
the script.
Tim
On Wed, Jan 16, 2013 at 6:05 PM, alive <
al...@mozilla.com> wrote:
> Hi all,
>
> Bug 824677 was landed for a while. It's a nontrivial patch to resolve some
> pain in showing error page and,
> what's more important, the first step to refactor our System app/Window
> Manager.
>
> ## Module pattern of Window Manager is unmanageable now. ##
> Hey, We are stacking workarounds one bug by one bug.
> Every time we have a new bug, we add some lines into Window Manager and
> Yay!
>
> Now time to stop workarounds and cleanup!
> I saw many workarounds in system app is landed because we have a tight
> schedule.
> Yes, workaround is adoptable. But also many regressions upcoming because
> workarounds were affecting each other workarounds..
> Now, it's nearly time to stop workarounds. And it's also time to stop make
> code size of window manager grow unlimitedly.
> As you know Window Manager is the core the system app.
> Now it is about 2000 lines.
> Nearly TL;DR…..
> anyone who is working on it may think this is really hard to trace(and
> lazy to trace…and regression coming!)
>
> ## Static DOM? Why not dynamic? ##
> I feel there's one thing that we should do but never did:
> Make every mozBrowser iframe or iframe which is provided by platform
> having specific tasks live in its own DOM element container, something like
> a <div>. Currently they are grouped together somewhere. This design is
> problematic.
>
> The targets include:
> A) A normal mozbrowser iframe [frameType="window"]
> B) Inline-actvity iframe [frameType="inline"]
> C) Popup dialog[frameType="popup"] (by window.open)
> D) Attention dialog[frameType="attention"] (by window.open with
> 'attention' specified)
> E) Wrapper[frameType='wrapper"…but now it's identified as dataset.wrapper]
> (a bookmark when you choose to bookmark to home screen in browser app)
>
> ## We should know that some dialogs are app-specific and some dialogs are
> system-specific ##
> ### App specific dialogs ###
> 1) Modal Dialog(Alert, confirm, prompt, custom_dialog)
> 2) Error Dialog/Overlay(Tells you that we have network error when loading
> the app page)
> 3) Popup!(By window.open)
> 3.1) Note that an iframe in Popup could also have modal dialogs or error
> overlays.
> 4) Inline Activity!(By design, an inline activity is tightened to the
> caller app. Any inline activities should be canceled/closed if we leave the
> caller app. I had a patch to enable multiple inline activities on single
> app already.
> 4.1) Note that an inline activity frame should have the ability to open
> popup also modal dialogs and error overlays.
> 5) Attention screen(!)
> IMO This is just a special version of popup. It's belong to an app.
> What's different is it's beyond any opened app.
> In the case of dialer, it tries to have the call screen of attention
> screen has its own slide transition.
> I would say this is app specific. The transition of app attention
> screen could be used to replace the app open transition.
> 5.1) As you know attention screen has an active status bar. I would say
> this should be moved to status bar. But still under design.
> 6) Trusted UI(Payment or Persona login)
> 7) Custom Dialog
>
> ### Maybe System-wide ###
> * Permission Screen - Josh tells me this is still under consideration.
> Currently the implementation of permission dialog in platform doesn't
> tell which iframe it's currently happening -- I begin to believe this is
> intentional if we confirm that any permission dialog should be system wide.
>
> ### System-wide dialog ###
> * SIM-PIN Dialog
> * Crash Report
> * System update prompt
>
> We are now make everything `singleton`ed in system/index.html
> And use 'appopen' or 'appwillopen' event fired by window manager to deal
> with app switching case to determine show them or not.
> * It's bad on UX because when the app is transitioning, the app-specific
> dialog should be transitioned as well as it could.
>
> We could just resize the app Window who contains any dialog in its
> container regardless to what's being displayed.
> As you know, resize related events are restrict to two factors
> 1) Global factor:
> 1.1) orientation change
> 1.2) status bar height
> 1.3) Fullscreen status
> 2) App factor:
> 2.1) Keyboard height - it's belong to app I believe.
> We could avoid resize every time appopen event fired. The dialog in a
> certain app would be resized natively if the app container is resized.
>
> ## Gather mozBrowser API ##
> We have much function work relying on mozbrowser API and mozbrowser frames.
> * mozbrowsererror
> * mozbrowsershowmodalprompt
> * mozbrowserloadstart
> * mozbrowserloadend
> * mozbrowsercontextmenu
> * mozbrowseropenwindow
> * mozbrowserclose
> * mozbrowserusernameandpasswordrequired
>
> These events handler are everywhere in system app in many modules.
> Do we have a chance to gather it together to avoid rewrite event handler
> everywhere? Yes I think.
>
> ## Visibility change ##
> We know that setVisible is also part of Browser API. Now window manager is
> in charge of change the visibility of every mozbrowser iframe by some
> complex code paths. And there are also some cases/bugs are not being found
> now.
> For example, if we are having two activities at the same time, currently
> we don't setVisible(false) to the activity frame under the most top one.
> This is undefined because some app(Communications - Contact) is using
> mozvisibilitychange to close itself :O I don't think this is needed to be
> avoided. We still need to investigate this.
>
> ## Home button events and hold home events ##
> Now this is not severe -- many effort had be done to keep 'home button'
> really returns the user to home screen now.
> However, if one day we could make hardware events deliver to app itself -
> that would be reasonable to deliver it in window manager to appWindow.
>
> ## Transition relevant to app/inline activity/.…
> Tim does a good job in implemanting app transition.
> But IMO the transition is belong to appWindow and could be controlled by
> Window Manager by class addition/remove.
> With this, we could 'replace' the openTransition of specific app if
> necessary.
> For example:
> 1) SIM PIN dialog: Replace the zoom-in transition of an appWindow touches
> SIM function with SIM PIN Dialog transitions(like window.open transition)
> 2) Trusted UI dialog: Replace the zoom-in transition of its appWindow
> 3) Call screen: Replace the zoom-in transition of its appWindow by
> slide-down transition
>
> ## Hierarchy manager(dynamic z-index assign) ##
> * If we are creating DOM elements dynamically, it's reasonable to have a
> "z-index assigner" when a new overlay is created.
> For example, if we have the attention screen belong to the app itself, the
> only way to have it displayed upon other app is to assign the attention
> screen
>
> ## So what we could do? What's the plan? What's the next? ##
> * Make (all) mozbrowser iframe be contained in its own container instead
> of '#windows'.
> * Make everything as being an object pattern if possible.
> * Make every `AppWindow` be in charge of dispatching events like
> 'appopen', 'appwillopen', 'appclose'
> * Make Window Manager be in charge of managing cross-app events, gathering
> the events firing by an AppWindow instance and then to determine what's
> going to be done if some events are meeting each other. Yes, a Finite State
> Machine!
> * Move FTU logic out of Window Manager. It's not reasonable to have FTU
> occupied in Window Manager.
> * Move TrustedUI logic out of Window Manager
> * Make Wrapper relevant DOM elements live in appWindow container
> * Move createFrame/open transition/close transition into appWindow objects.
>
> ### The patterns of Window Manager ###
> 1. Global Event Listener to all the elements under '#windows'
> 2. App Switch Manager - bring app to foreground by calling app.open() or
> app.close(). Determine who is 'displayedApp'.
> 3. App Launcher - Launch an app if needed.(include FTU, Homescreen,
> Wrapper, normal app…)
> 4. Resize Manager
> 5. Hierarchy Manager
> 6. Manage system-wide dialogs(fire events)
> 7. Expose reasonable properties.
>
> ### The responsibility of appWindow and appDialog ###
> 1. Create iframe, set suitable attributes
> 2. Create DOM elements/objects if needed. e.g.
> wrapper-header/wrapper-footer, error dialog, modal dialog…
> 3. Event listener to mozbrowser* events
> 4. Event listener to the elements under this container, e.g., click event
> handler.
> 5. resize
> 6. setHeight
> 7. setVisibility
> 8. Fire app* events if the event is belong to the container.
> IMO, in the long run we don't need these events -- at least could be
> limited to a very small amount.
>
> ### Final Structures for example ###
> - Window Manager
> - new AppWindow();
> - new AppWindow(frameType=wrapper) or new Wrapper();
> - new AppWindow();
> - new ModalDialog();
> - new AppError();
> - new ContextMenu();
> - new TrustedUI();
> - new Modal Dialog();
> - new AppError();
> - new InlineActivity();
> - new Popup();
> - new InlineActivity(); // Multiple inline activity I mean
> - new ModalDialog();
> - new AppError();
> - new Popup();
> - new ModalDialog();
> - new AppError();
>
>
>
> Some of these ideas are still draft.
> I think I should make a slide about this plan for others to understand
> easily, but I rather throws these ideas by pure text first.
>
> - Alive
>
>
>
--
Tim Guan-tin Chien, Senior Front-end Dev., Mozilla Corp. (Taiwan)