Merge from mozilla-central.
authorDavid Anderson <danderson@mozilla.com>
Tue, 22 May 2012 16:56:19 -0700
changeset 112529 8d8f6fbdf4d0f7086b889077d8016827868150fa
parent 112528 9602aebd7e43a27f1675ca8313b80045c383c7fb (current diff)
parent 98614 b038090f07c2dae64f83c6d557321d34c42e7060 (diff)
child 112530 afbfcebb1976458d567ad875cf8f0762770ddb94
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge from mozilla-central.
accessible/src/base/nsAccUtils.cpp
accessible/src/base/nsAccUtils.h
b2g/installer/package-manifest.in
browser/app/profile/extensions/uriloader@pdf.js/LICENSE
browser/app/profile/extensions/uriloader@pdf.js/Makefile.in
browser/app/profile/extensions/uriloader@pdf.js/README.mozilla
browser/app/profile/extensions/uriloader@pdf.js/bootstrap.js
browser/app/profile/extensions/uriloader@pdf.js/components/PdfStreamConverter.js
browser/app/profile/extensions/uriloader@pdf.js/content/web/debugger.js
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/bookmark.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/check.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/comment.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/document-print.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/download.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/go-down.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/go-up.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/loading-icon.gif
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/nav-outline.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/nav-thumbs.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/pin-down.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/pin-up.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/zoom-in.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/images/zoom-out.svg
browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer-snippet-firefox-extension.html
browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer.css
browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer.html
browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer.js
browser/app/profile/extensions/uriloader@pdf.js/extension-files
browser/app/profile/extensions/uriloader@pdf.js/icon.png
browser/app/profile/extensions/uriloader@pdf.js/icon64.png
browser/app/profile/extensions/uriloader@pdf.js/install.rdf.in
browser/app/profile/extensions/uriloader@pdf.js/test/Makefile.in
browser/app/profile/extensions/uriloader@pdf.js/test/browser_pdfjs_main.js
browser/app/profile/extensions/uriloader@pdf.js/test/file_pdfjs_test.pdf
browser/app/profile/firefox.js
browser/base/content/browser.js
browser/components/sessionstore/test/Makefile.in
browser/devtools/commandline/gcliblank.xhtml
browser/devtools/jar.mn
browser/devtools/webconsole/HUDService.jsm
browser/locales/en-US/chrome/browser/browser.dtd
browser/locales/en-US/chrome/browser/browser.properties
config/autoconf.mk.in
config/system-headers
configure.in
content/base/public/nsContentUtils.h
content/base/public/nsDOMFile.h
content/base/public/nsIDocument.h
content/base/src/nsContentSink.cpp
content/base/src/nsContentSink.h
content/base/src/nsContentUtils.cpp
content/base/src/nsDOMFile.cpp
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/events/src/nsEventStateManager.cpp
dom/Makefile.in
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/plugins/base/nsNPAPIPluginInstance.cpp
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxContext.h
gfx/thebes/gfxHarfBuzzShaper.cpp
gfx/thebes/gfxPattern.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
intl/uconv/src/nsUTF8ConverterService.cpp
js/src/config/system-headers
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/Parser.cpp
js/src/frontend/Parser.h
js/src/js.msg
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jscompartment.cpp
js/src/jscompartment.h
js/src/jsfun.cpp
js/src/jsfun.h
js/src/jsgc.cpp
js/src/jsinfer.cpp
js/src/jsinterp.cpp
js/src/jsopcode.cpp
js/src/jsopcode.tbl
js/src/vm/ArgumentsObject.cpp
js/src/vm/Stack-inl.h
js/src/vm/Stack.h
js/xpconnect/shell/xpcshell.cpp
layout/base/nsCaret.cpp
layout/base/nsDisplayList.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/base/nsPresContext.h
layout/base/nsPresShell.cpp
layout/build/Makefile.in
layout/forms/nsFieldSetFrame.cpp
layout/forms/nsFormControlFrame.cpp
layout/forms/nsListControlFrame.cpp
layout/forms/nsListControlFrame.h
layout/forms/nsProgressFrame.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/TextOverflow.cpp
layout/generic/crashtests/crashtests.list
layout/generic/nsBRFrame.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsBlockReflowState.cpp
layout/generic/nsBulletFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsGfxScrollFrame.cpp
layout/generic/nsGfxScrollFrame.h
layout/generic/nsHTMLReflowState.cpp
layout/generic/nsHTMLReflowState.h
layout/generic/nsImageFrame.cpp
layout/generic/nsInlineFrame.cpp
layout/generic/nsLineLayout.cpp
layout/generic/nsTextFrameThebes.cpp
layout/svg/base/src/nsSVGForeignObjectFrame.cpp
layout/tables/BasicTableLayoutStrategy.cpp
layout/tables/nsTableFrame.cpp
layout/tables/nsTableOuterFrame.cpp
layout/xul/base/src/nsBox.cpp
layout/xul/base/src/nsMenuBarFrame.cpp
mobile/xul/installer/package-manifest.in
modules/libpref/src/init/all.js
netwerk/mime/nsIMIMEHeaderParam.idl
netwerk/mime/nsMIMEHeaderParamImpl.cpp
netwerk/protocol/http/SpdySession.cpp
netwerk/protocol/http/SpdySession.h
netwerk/protocol/http/SpdyStream.cpp
netwerk/protocol/http/nsHttpConnectionMgr.cpp
other-licenses/virtualenv/docs/_build/_sources/index.txt
other-licenses/virtualenv/docs/_build/_sources/license.txt
other-licenses/virtualenv/docs/_build/_sources/news.txt
other-licenses/virtualenv/docs/license.txt
other-licenses/virtualenv/virtualenv_support/distribute-0.6.8.tar.gz
other-licenses/virtualenv/virtualenv_support/pip-0.7.1.tar.gz
testing/marionette/client/marionette/selenium_proxy.py
testing/marionette/client/marionette/test_selenium.py
toolkit/components/telemetry/TelemetryPing.js
toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
toolkit/mozapps/installer/packager.mk
toolkit/mozapps/update/nsUpdateService.js
toolkit/mozapps/update/test/unit/head_update.js.in
toolkit/mozapps/update/test/unit/test_0030_general.js
toolkit/themes/winstripe/global/toolbar/Lighten.png
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsAppRunner.h
toolkit/xre/nsUpdateDriver.cpp
toolkit/xre/nsWindowsRestart.cpp
toolkit/xre/nsXREDirProvider.cpp
toolkit/xre/nsXREDirProvider.h
xpcom/build/nsXULAppAPI.h
xpcom/io/nsLocalFileWin.cpp
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -456,34 +456,34 @@ nsAccUtils::TextLength(nsAccessible *aAc
   // XXX In the future, list bullets may have frame and anon content, so 
   // we should be able to remove this at that point
   nsAutoString text;
   aAccessible->AppendTextTo(text); // Get all the text
   return text.Length();
 }
 
 bool
-nsAccUtils::MustPrune(nsIAccessible *aAccessible)
+nsAccUtils::MustPrune(nsAccessible* aAccessible)
 { 
-  PRUint32 role = nsAccUtils::Role(aAccessible);
+  roles::Role role = aAccessible->Role();
 
   // We don't prune buttons any more however AT don't expect children inside of
   // button in general, we allow menu buttons to have children to make them
   // accessible.
-  return role == nsIAccessibleRole::ROLE_MENUITEM || 
-    role == nsIAccessibleRole::ROLE_COMBOBOX_OPTION ||
-    role == nsIAccessibleRole::ROLE_OPTION ||
-    role == nsIAccessibleRole::ROLE_ENTRY ||
-    role == nsIAccessibleRole::ROLE_FLAT_EQUATION ||
-    role == nsIAccessibleRole::ROLE_PASSWORD_TEXT ||
-    role == nsIAccessibleRole::ROLE_TOGGLE_BUTTON ||
-    role == nsIAccessibleRole::ROLE_GRAPHIC ||
-    role == nsIAccessibleRole::ROLE_SLIDER ||
-    role == nsIAccessibleRole::ROLE_PROGRESSBAR ||
-    role == nsIAccessibleRole::ROLE_SEPARATOR;
+  return role == roles::MENUITEM || 
+    role == roles::COMBOBOX_OPTION ||
+    role == roles::OPTION ||
+    role == roles::ENTRY ||
+    role == roles::FLAT_EQUATION ||
+    role == roles::PASSWORD_TEXT ||
+    role == roles::TOGGLE_BUTTON ||
+    role == roles::GRAPHIC ||
+    role == roles::SLIDER ||
+    role == roles::PROGRESSBAR ||
+    role == roles::SEPARATOR;
 }
 
 nsresult
 nsAccUtils::GetHeaderCellsFor(nsIAccessibleTable *aTable,
                               nsIAccessibleTableCell *aCell,
                               PRInt32 aRowOrColHeaderCells, nsIArray **aCells)
 {
   nsresult rv = NS_OK;
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -290,17 +290,17 @@ public:
     if (aState2)
       *aState2 = static_cast<PRUint32>(aState64 >> 31);
   }
 
   /**
    * Return true if the given accessible can't have children. Used when exposing
    * to platform accessibility APIs, should the children be pruned off?
    */
-  static bool MustPrune(nsIAccessible *aAccessible);
+  static bool MustPrune(nsAccessible* aAccessible);
 
   /**
    * Search hint enum constants. Used by GetHeaderCellsFor() method.
    */
   enum {
     // search for row header cells, left direction
     eRowHeaderCells,
     // search for column header cells, top direction
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -387,21 +387,27 @@ pref("layers.acceleration.force-enabled"
 // 1=current window/tab, 2=new window, 3=new tab in most recent window
 pref("browser.link.open_newwindow", 3);
 
 // 0: no restrictions - divert everything
 // 1: don't divert window.open at all
 // 2: don't divert window.open with features
 pref("browser.link.open_newwindow.restriction", 0);
 
-// Enable browser frames (including OOP), but make in-process browser frames
-// the default.
+// Enable browser frames (including OOP, except on Windows, where it doesn't
+// work), but make in-process browser frames the default.
 pref("dom.mozBrowserFramesEnabled", true);
 pref("dom.mozBrowserFramesWhitelist", "http://homescreen.gaiamobile.org,http://browser.gaiamobile.org");
+
+#ifdef XP_WIN
+pref("dom.ipc.tabs.disabled", true);
+#else
 pref("dom.ipc.tabs.disabled", false);
+#endif
+
 pref("dom.ipc.browser_frames.oop_by_default", false);
 
 // Temporary permission hack for WebSMS
 pref("dom.sms.enabled", true);
 pref("dom.sms.whitelist", "file://,http://homescreen.gaiamobile.org,http://sms.gaiamobile.org");
 
 // Temporary permission hack for WebMobileConnection
 pref("dom.mobileconnection.whitelist", "http://system.gaiamobile.org,http://homescreen.gaiamobile.org,http://dialer.gaiamobile.org");
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -174,17 +174,20 @@ var shell = {
       if (steps <= 0)
         steps = 1;
     } catch(e) {}
 
     let audioManager = Services.audioManager;
     if (!audioManager)
       return;
 
-    let volume = audioManager.masterVolume + delta / steps;
+    let currentVolume = audioManager.masterVolume;
+    let newStep = Math.round(steps * Math.sqrt(currentVolume)) + delta;
+    let volume = (newStep / steps) * (newStep / steps);
+
     if (volume > 1)
       volume = 1;
     if (volume < 0)
       volume = 0;
     audioManager.masterVolume = volume;
   },
 
   forwardKeyToHomescreen: function shell_forwardKeyToHomescreen(evt) {
--- a/browser/Makefile.in
+++ b/browser/Makefile.in
@@ -11,16 +11,17 @@ include $(topsrcdir)/config/config.mk
 
 PARALLEL_DIRS = \
   base \
   components \
   fuel \
   locales \
   modules \
   themes \
+  extensions \
   $(NULL)
 
 DIRS = \
   devtools \
   app \
   $(NULL)
 
 ifdef MAKENSISU
new file mode 120000
--- /dev/null
+++ b/browser/app/macbuild/Contents/CodeResources
@@ -0,0 +1,1 @@
+_CodeSignature/CodeResources
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/app/macbuild/Contents/_CodeSignature/CodeResources
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+    <dict>
+        <key>rules</key>
+        <dict>
+            <key>^Info.plist$</key>
+            <true/>
+            <key>^PkgInfo$</key>
+            <true/>
+            <key>^MacOS/</key>
+            <true/>
+            <key>^Resources/</key>
+            <true/>
+            <key>^MacOS/extensions/.*</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+            <key>^MacOS/distribution/.*</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+            <key>^MacOS/updates/.*</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+            <key>^MacOS/active-update.xml$</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+            <key>^MacOS/defaults/.*</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+            <key>^MacOS/mozilla.cfg$</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+            <key>^MacOS/updates.xml$</key><dict>
+                <key>omit</key>
+                <true/>
+            </dict>
+        </dict>
+    </dict>
+</plist>
--- a/browser/app/profile/extensions/Makefile.in
+++ b/browser/app/profile/extensions/Makefile.in
@@ -9,17 +9,16 @@ srcdir     = @srcdir@
 VPATH      = @srcdir@
 
 DISTROEXT = $(call core_abspath,$(DIST))/bin/distribution/extensions
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   {972ce4c6-7e08-4474-a285-3208198ce6fd} \
-  uriloader@pdf.js \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 ifneq (,$(filter aurora beta,$(MOZ_UPDATE_CHANNEL)))
 EXTENSIONS = \
   testpilot@labs.mozilla.com \
   $(NULL)
deleted file mode 100644
--- a/browser/app/profile/extensions/uriloader@pdf.js/Makefile.in
+++ /dev/null
@@ -1,30 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this file,
-# You can obtain one at http://mozilla.org/MPL/2.0/.
-
-DEPTH      = ../../../../..
-topsrcdir  = @top_srcdir@
-srcdir     = @srcdir@
-VPATH      = @srcdir@
-
-APPEXT = $(call core_abspath,$(DIST))/bin/extensions
-
-TEST_DIRS += test
-
-include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-
-# Using the extension-files as an extension files whitelist to avoid noise
-# in the xpi file such as MOZILLA.readme, install.pdf.in and this make file.
-FILES := $(shell cat $(srcdir)/extension-files)
-
-libs::
-	$(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py $(DEFINES) $(ACDEFINES) $(srcdir)/install.rdf.in > install.rdf
-	$(ZIP) -9X $(APPEXT)/uriloader@pdf.js.xpi install.rdf
-	cd $(call core_abspath,$(srcdir)) && \
-	$(ZIP) -9X $(APPEXT)/uriloader@pdf.js.xpi $(FILES)
-
-install::
-	$(SYSINSTALL) $(IFLAGS1) $(APPEXT)/uriloader@pdf.js.xpi $(DESTDIR)$(mozappdir)/extensions
-
-GARBAGE += install.rdf
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -54,19 +54,18 @@ pref("extensions.blocklist.detailsURL", 
 pref("extensions.blocklist.itemURL", "https://addons.mozilla.org/%LOCALE%/%APP%/blocked/%blockID%");
 
 pref("extensions.update.autoUpdateDefault", true);
 
 pref("extensions.hotfix.id", "firefox-hotfix@mozilla.org");
 pref("extensions.hotfix.cert.checkAttributes", true);
 pref("extensions.hotfix.certs.1.sha1Fingerprint", "F1:DB:F9:6A:7B:B8:04:FA:48:3C:16:95:C7:2F:17:C6:5B:C2:9F:45");
 
-// Disable add-ons installed into the shared user and shared system areas by
-// default. This does not include the application directory. See the SCOPE
-// constants in AddonManager.jsm for values to use here
+// Disable add-ons that are not installed by the user in all scopes by default.
+// See the SCOPE constants in AddonManager.jsm for values to use here.
 pref("extensions.autoDisableScopes", 15);
 
 // Dictionary download preference
 pref("browser.dictionaries.download.url", "https://addons.mozilla.org/%LOCALE%/firefox/dictionaries/");
 
 // The minimum delay in seconds for the timer to fire.
 // default=2 minutes
 pref("app.update.timerMinimumDelay", 120);
@@ -141,16 +140,20 @@ pref("app.update.auto", true);
 //
 // See chart in nsUpdateService.js source for more details
 //
 pref("app.update.mode", 1);
 
 // If set to true, the Update Service will present no UI for any event.
 pref("app.update.silent", false);
 
+// If set to true, the Update Service will apply updates in the background
+// when it finishes downloading them.
+pref("app.update.stage.enabled", true);
+
 // Update service URL:
 pref("app.update.url", "https://aus3.mozilla.org/update/3/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/update.xml");
 // app.update.url.manual is in branding section
 // app.update.url.details is in branding section
 
 // User-settable override to app.update.url for testing purposes.
 //pref("app.update.url.override", "");
 
@@ -1022,17 +1025,17 @@ pref("devtools.inspector.activeSidebar",
 pref("devtools.inspector.highlighterShowVeil", true);
 pref("devtools.inspector.highlighterShowInfobar", true);
 
 // Enable the Layout View
 pref("devtools.layoutview.enabled", false);
 pref("devtools.layoutview.open", false);
 
 // Enable the Debugger
-pref("devtools.debugger.enabled", false);
+pref("devtools.debugger.enabled", true);
 pref("devtools.debugger.remote-enabled", false);
 pref("devtools.debugger.remote-host", "localhost");
 pref("devtools.debugger.remote-port", 6000);
 pref("devtools.debugger.remote-autoconnect", false);
 pref("devtools.debugger.remote-connection-retries", 3);
 pref("devtools.debugger.remote-timeout", 3000);
 
 // The default Debugger UI height
--- a/browser/base/content/aboutDialog.js
+++ b/browser/base/content/aboutDialog.js
@@ -117,16 +117,22 @@ function appUpdater()
   }
 
   if (this.isPending) {
     this.setupUpdateButton("update.restart." +
                            (this.isMajor ? "upgradeButton" : "updateButton"));
     return;
   }
 
+  if (this.isApplied) {
+    this.setupUpdateButton("update.restart." +
+                           (this.isMajor ? "upgradeButton" : "restartButton"));
+    return;
+  }
+
   if (this.isDownloading) {
     this.startDownload();
     return;
   }
 
   if (this.updateEnabled && this.updateAuto) {
     this.selectPanel("checkingForUpdates");
     this.isChecking = true;
@@ -146,16 +152,26 @@ appUpdater.prototype =
       return this.update.state == "pending" || 
              this.update.state == "pending-service";
     }
     return this.um.activeUpdate &&
            (this.um.activeUpdate.state == "pending" ||
             this.um.activeUpdate.state == "pending-service");
   },
 
+  // true when there is an update already installed in the background.
+  get isApplied() {
+    if (this.update)
+      return this.update.state == "applied" ||
+             this.update.state == "applied-service";
+    return this.um.activeUpdate &&
+           (this.um.activeUpdate.state == "applied" ||
+            this.um.activeUpdate.state == "applied-service");
+  },
+
   // true when there is an update download in progress.
   get isDownloading() {
     if (this.update)
       return this.update.state == "downloading";
     return this.um.activeUpdate &&
            this.um.activeUpdate.state == "downloading";
   },
 
@@ -176,16 +192,22 @@ appUpdater.prototype =
   get updateEnabled() {
     try {
       return Services.prefs.getBoolPref("app.update.enabled");
     }
     catch (e) { }
     return true; // Firefox default is true
   },
 
+  // true when updating in background is enabled.
+  get backgroundUpdateEnabled() {
+    return this.updateEnabled &&
+           Services.prefs.getBoolPref("app.update.stage.enabled");
+  },
+
   // true when updating is automatic.
   get updateAuto() {
     try {
       return Services.prefs.getBoolPref("app.update.auto");
     }
     catch (e) { }
     return true; // Firefox default is true
   },
@@ -215,17 +237,17 @@ appUpdater.prototype =
         document.commandDispatcher.focusedElement == this.updateBtn)
       this.updateBtn.focus();
   },
 
   /**
    * Handles oncommand for the update button.
    */
   buttonOnCommand: function() {
-    if (this.isPending) {
+    if (this.isPending || this.isApplied) {
       // Notify all windows that an application quit has been requested.
       let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].
                        createInstance(Components.interfaces.nsISupportsPRBool);
       Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
       // Something aborted the quit process.
       if (cancelQuit.data)
         return;
@@ -500,19 +522,44 @@ appUpdater.prototype =
       // Verification failed for a partial patch, complete patch is now
       // downloading so return early and do NOT remove the download listener!
       break;
     case Components.results.NS_BINDING_ABORTED:
       // Do not remove UI listener since the user may resume downloading again.
       break;
     case Components.results.NS_OK:
       this.removeDownloadListener();
-      this.selectPanel("updateButtonBox");
-      this.setupUpdateButton("update.restart." +
-                             (this.isMajor ? "upgradeButton" : "updateButton"));
+      if (this.backgroundUpdateEnabled) {
+        this.selectPanel("applying");
+        let update = this.um.activeUpdate;
+        let self = this;
+        let timer = Components.classes["@mozilla.org/timer;1"]
+                              .createInstance(Components.interfaces.nsITimer);
+        timer.initWithCallback(function () {
+          // Update the UI when the background updater is finished
+          let status = update.state;
+          if (status == "applied" || status == "applied-service") {
+            self.selectPanel("updateButtonBox");
+            self.setupUpdateButton("update.restart." +
+                                   (self.isMajor ? "upgradeButton" : "restartButton"));
+            timer.cancel();
+            timer = null;
+          } else if (status == "failed") {
+            // Background update has failed, let's show the UI responsible for
+            // prompting the user to update manually.
+            self.selectPanel("downloadFailed");
+            timer.cancel();
+            timer = null;
+          }
+        }, 500, timer.TYPE_REPEATING_SLACK);
+      } else {
+        this.selectPanel("updateButtonBox");
+        this.setupUpdateButton("update.restart." +
+                               (this.isMajor ? "upgradeButton" : "updateButton"));
+      }
       break;
     default:
       this.removeDownloadListener();
       this.selectPanel("downloadFailed");
       break;
     }
 
   },
--- a/browser/base/content/aboutDialog.xul
+++ b/browser/base/content/aboutDialog.xul
@@ -59,16 +59,19 @@
                 <image class="update-throbber"/><label>&update.checkingForUpdates;</label>
               </hbox>
               <hbox id="checkingAddonCompat" align="center">
                 <image class="update-throbber"/><label>&update.checkingAddonCompat;</label>
               </hbox>
               <hbox id="downloading" align="center">
                 <image class="update-throbber"/><label>&update.downloading.start;</label><label id="downloadStatus"/><label>&update.downloading.end;</label>
               </hbox>
+              <hbox id="applying" align="center">
+                <image class="update-throbber"/><label>&update.applying;</label>
+              </hbox>
               <hbox id="downloadFailed" align="center">
                 <label>&update.failed.start;</label><label id="failedLink" class="text-link">&update.failed.linkText;</label><label>&update.failed.end;</label>
               </hbox>
               <hbox id="adminDisabled" align="center">
                 <label>&update.adminDisabled;</label>
               </hbox>
               <hbox id="noUpdatesFound" align="center">
                 <label>&update.noUpdatesFound;</label>
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4179,17 +4179,17 @@ var FullScreen = {
     clearTimeout(this._animationTimeout);
     this._isAnimating = false;
     this._shouldAnimate = false;
   },
 
   cancelWarning: function(event) {
     if (!this.warningBox)
       return;
-    this.fullscreenDocUri = null;
+    this.fullscreenDoc = null;
     this.warningBox.removeEventListener("transitionend", this);
     if (this.warningFadeOutTimeout) {
       clearTimeout(this.warningFadeOutTimeout);
       this.warningFadeOutTimeout = null;
     }
 
     // Ensure focus switches away from the (now hidden) warning box. If the user
     // clicked buttons in the fullscreen key authorization UI, it would have been
@@ -4199,86 +4199,120 @@ var FullScreen = {
 
     this.warningBox.setAttribute("hidden", true);
     this.warningBox.removeAttribute("fade-warning-out");
     this.warningBox.removeAttribute("obscure-browser");
     this.warningBox = null;
   },
 
   setFullscreenAllowed: function(isApproved) {
-    let remember = document.getElementById("full-screen-remember-decision").checked;
-    if (remember)
-      Services.perms.add(this.fullscreenDocUri,
-                         "fullscreen",
-                         isApproved ? Services.perms.ALLOW_ACTION : Services.perms.DENY_ACTION,
-                         Services.perms.EXPIRE_NEVER);
-    else if (isApproved) {
-      // The user has only temporarily approved fullscren for this domain.
-      // Add the permission (so Gecko knows fullscreen is approved) but add a
-      // listener to remove the permission when the chrome document exits fullscreen.
-      Services.perms.add(this.fullscreenDocUri,
-                         "fullscreen",
-                         Services.perms.ALLOW_ACTION,
-                         Services.perms.EXPIRE_SESSION);
-      let host = this.fullscreenDocUri.host;
-      function onFullscreenchange(event) {
-        if (event.target == document && document.mozFullScreenElement == null) {
-          // The chrome document has left fullscreen. Remove the temporary permission grant.
-          Services.perms.remove(host, "fullscreen");
-          document.removeEventListener("mozfullscreenchange", onFullscreenchange);
+    // The "remember decision" checkbox is hidden when showing for documents that
+    // the permission manager can't handle (documents with URIs without a host).
+    // We simply require those to be approved every time instead.
+    let rememberCheckbox = document.getElementById("full-screen-remember-decision");
+    let uri = this.fullscreenDoc.nodePrincipal.URI;
+    if (!rememberCheckbox.hidden) {
+      if (rememberCheckbox.checked)
+        Services.perms.add(uri,
+                           "fullscreen",
+                           isApproved ? Services.perms.ALLOW_ACTION : Services.perms.DENY_ACTION,
+                           Services.perms.EXPIRE_NEVER);
+      else if (isApproved) {
+        // The user has only temporarily approved fullscren for this fullscreen
+        // session only. Add the permission (so Gecko knows to approve any further
+        // fullscreen requests for this host in this fullscreen session) but add
+        // a listener to revoke the permission when the chrome document exits
+        // fullscreen.
+        Services.perms.add(uri,
+                           "fullscreen",
+                           Services.perms.ALLOW_ACTION,
+                           Services.perms.EXPIRE_SESSION);
+        let host = uri.host;
+        function onFullscreenchange(event) {
+          if (event.target == document && document.mozFullScreenElement == null) {
+            // The chrome document has left fullscreen. Remove the temporary permission grant.
+            Services.perms.remove(host, "fullscreen");
+            document.removeEventListener("mozfullscreenchange", onFullscreenchange);
+          }
         }
+        document.addEventListener("mozfullscreenchange", onFullscreenchange);
       }
-      document.addEventListener("mozfullscreenchange", onFullscreenchange);
     }
     if (this.warningBox)
       this.warningBox.setAttribute("fade-warning-out", "true");
-    if (!isApproved)
+    // If the document has been granted fullscreen, notify Gecko so it can resume
+    // any pending pointer lock requests, otherwise exit fullscreen; the user denied
+    // the fullscreen request.
+    if (isApproved)
+      Services.obs.notifyObservers(this.fullscreenDoc, "fullscreen-approved", "");
+    else
       document.mozCancelFullScreen();
   },
 
   warningBox: null,
   warningFadeOutTimeout: null,
-  fullscreenDocUri: null,
+  fullscreenDoc: null,
 
   // Shows the fullscreen approval UI, or if the domain has already been approved
   // for fullscreen, shows a warning that the site has entered fullscreen for a short
   // duration.
   showWarning: function(targetDoc) {
     if (!document.mozFullScreen ||
         !gPrefService.getBoolPref("full-screen-api.approval-required"))
       return;
 
     // Set the strings on the fullscreen approval UI.
-    this.fullscreenDocUri = targetDoc.nodePrincipal.URI;
-    let utils = {};
-    Cu.import("resource://gre/modules/DownloadUtils.jsm", utils);
-    let [displayHost, fullHost] = utils.DownloadUtils.getURIHost(this.fullscreenDocUri.spec);
-    let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
-    let domainText = bundle.formatStringFromName("fullscreen.entered", [displayHost], 1);
-    document.getElementById("full-screen-domain-text").textContent = domainText;
-    let rememberText = bundle.formatStringFromName("fullscreen.rememberDecision", [displayHost], 1);
-    document.getElementById("full-screen-remember-decision").label = rememberText;
+    this.fullscreenDoc = targetDoc;
+    let uri = this.fullscreenDoc.nodePrincipal.URI;
+    let host = null;
+    try {
+      host = uri.host;
+    } catch (e) { }
+    let hostLabel = document.getElementById("full-screen-domain-text");
+    let rememberCheckbox = document.getElementById("full-screen-remember-decision");
+    let isApproved = false;
+    if (host) {
+      // Document's principal's URI has a host. Display a warning including the hostname and
+      // show UI to enable the user to permanently grant this host permission to enter fullscreen.
+      let utils = {};
+      Cu.import("resource://gre/modules/DownloadUtils.jsm", utils);
+      let displayHost = utils.DownloadUtils.getURIHost(uri.spec)[0];
+      let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
+
+      hostLabel.textContent = bundle.formatStringFromName("fullscreen.entered", [displayHost], 1);
+      hostLabel.removeAttribute("hidden");
+
+      rememberCheckbox.label = bundle.formatStringFromName("fullscreen.rememberDecision", [displayHost], 1);
+      rememberCheckbox.checked = false;
+      rememberCheckbox.removeAttribute("hidden");
+
+      // Note we only allow documents whose principal's URI has a host to
+      // store permission grants.
+      isApproved = Services.perms.testPermission(uri, "fullscreen") == Services.perms.ALLOW_ACTION;
+    } else {
+      hostLabel.setAttribute("hidden", "true");
+      rememberCheckbox.setAttribute("hidden", "true");
+    }
 
     // Note: the warning box can be non-null if the warning box from the previous request
     // wasn't hidden before another request was made.
     if (!this.warningBox) {
       this.warningBox = document.getElementById("full-screen-warning-container");
       // Add a listener to clean up state after the warning is hidden.
       this.warningBox.addEventListener("transitionend", this);
       this.warningBox.removeAttribute("hidden");
     }
 
     // If fullscreen mode has not yet been approved for the fullscreen
     // document's domain, show the approval UI and don't auto fade out the
     // fullscreen warning box. Otherwise, we're just notifying of entry into
-    // fullscreen mode.
-    let isApproved =
-      Services.perms.testPermission(this.fullscreenDocUri, "fullscreen") == Services.perms.ALLOW_ACTION;
+    // fullscreen mode. Note if the resource's host is null, we must be
+    // showing a local file or a local data URI, and we require explicit
+    // approval every time.
     let authUI = document.getElementById("full-screen-approval-pane");
-    document.getElementById("full-screen-remember-decision").checked = false;
     if (isApproved)
       authUI.setAttribute("hidden", "true");
     else {
       // Partially obscure the <browser> element underneath the approval UI.
       this.warningBox.setAttribute("obscure-browser", "true");
       authUI.removeAttribute("hidden");
     }
 
@@ -4466,17 +4500,17 @@ var XULBrowserWindow = {
   status: "",
   defaultStatus: "",
   jsStatus: "",
   jsDefaultStatus: "",
   overLink: "",
   startTime: 0,
   statusText: "",
   isBusy: false,
-  inContentWhitelist: ["about:addons", "about:permissions", 
+  inContentWhitelist: ["about:addons", "about:permissions",
                        "about:sync-progress", "about:preferences"],
 
   QueryInterface: function (aIID) {
     if (aIID.equals(Ci.nsIWebProgressListener) ||
         aIID.equals(Ci.nsIWebProgressListener2) ||
         aIID.equals(Ci.nsISupportsWeakReference) ||
         aIID.equals(Ci.nsIXULBrowserWindow) ||
         aIID.equals(Ci.nsISupports))
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -775,18 +775,26 @@ function selectSaveFolder()
 function saveMedia()
 {
   var tree = document.getElementById("imagetree");
   var count = tree.view.selection.count;
   if (count == 1) {
     var item = getSelectedImage(tree);
     var url = gImageView.data[tree.currentIndex][COL_IMAGE_ADDRESS];
 
-    if (url)
-      saveURL(url, null, "SaveImageTitle", false, false, makeURI(item.baseURI));
+    if (url) {
+      var titleKey = "SaveImageTitle";
+
+      if (item instanceof HTMLVideoElement)
+        titleKey = "SaveVideoTitle";
+      else if (item instanceof HTMLAudioElement)
+        titleKey = "SaveAudioTitle";
+
+      saveURL(url, null, titleKey, false, false, makeURI(item.baseURI));
+    }
   }
   else {
     var odir  = selectSaveFolder();
     var start = { };
     var end   = { };
     var numRanges = tree.view.selection.getRangeCount();
 
     var rowArray = [ ];
--- a/browser/components/about/Makefile.in
+++ b/browser/components/about/Makefile.in
@@ -6,21 +6,19 @@ DEPTH     = ../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = browserabout
 LIBRARY_NAME = browserabout_s
+
 FORCE_STATIC_LIB = 1
-ifndef MOZ_MEMORY
 USE_STATIC_LIBS = 1
-endif
-
 
 EXPORTS_NAMESPACES = mozilla/browser
 
 EXPORTS_mozilla/browser = AboutRedirector.h
 
 CPPSRCS = AboutRedirector.cpp
 
 LOCAL_INCLUDES = -I$(srcdir)/../build
--- a/browser/components/build/Makefile.in
+++ b/browser/components/build/Makefile.in
@@ -11,21 +11,17 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE = browsercomps
 LIBRARY_NAME = browsercomps
 SHORT_LIBNAME = brwsrcmp
 IS_COMPONENT = 1
 MODULE_NAME = nsBrowserCompsModule
 FORCE_SHARED_LIB = 1
 
-# Statically link the CRT on Windows if building against
-# a XULRunner SDK.
-ifdef LIBXUL_SDK
 USE_STATIC_LIBS = 1
-endif
 
 EXPORTS = nsBrowserCompsCID.h
 
 CPPSRCS = nsModule.cpp \
           $(NULL)
 
 ifeq ($(OS_ARCH),WINNT)
 OS_LIBS	+= $(call EXPAND_LIBNAME,ole32 shell32 shlwapi)
@@ -51,17 +47,17 @@ SHARED_LIBRARY_LIBS = \
 	$(NULL)
 
 ifneq (,$(filter windows cocoa gtk2, $(MOZ_WIDGET_TOOLKIT)))
 SHARED_LIBRARY_LIBS += ../shell/src/$(LIB_PREFIX)shellservice_s.$(LIB_SUFFIX)
 endif
 
 EXTRA_DSO_LDOPTS += \
 	$(call EXPAND_LIBNAME_PATH,unicharutil_external_s,$(LIBXUL_DIST)/lib) \
-	$(XPCOM_GLUE_LDOPTS) \
+	$(XPCOM_STATICRUNTIME_GLUE_LDOPTS) \
 	$(MOZ_COMPONENT_LIBS) \
 	$(NULL)
 
 ifdef JS_SHARED_LIBRARY
 EXTRA_DSO_LDOPTS += $(MOZ_JS_LIBS)
 endif
 
 LOCAL_INCLUDES += -I$(srcdir)/../migration/src
--- a/browser/components/dirprovider/Makefile.in
+++ b/browser/components/dirprovider/Makefile.in
@@ -10,22 +10,17 @@ VPATH     = @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = browserdir
 LIBRARY_NAME = browserdir_s
 
 TEST_DIRS += tests
 
 FORCE_STATIC_LIB = 1
-
-# Because we are an application component, link against the CRT statically
-# (on Windows, but only if we're not building our own CRT for jemalloc)
-ifndef MOZ_MEMORY
-USE_STATIC_LIBS      = 1
-endif
+USE_STATIC_LIBS = 1
 
 EXPORTS_NAMESPACES = mozilla/browser
 EXPORTS_mozilla/browser = DirectoryProvider.h
 
 CPPSRCS = DirectoryProvider.cpp
 
 LOCAL_INCLUDES = -I$(srcdir)/../build
 
--- a/browser/components/feeds/src/Makefile.in
+++ b/browser/components/feeds/src/Makefile.in
@@ -6,20 +6,19 @@ DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = browser_feeds
 LIBRARY_NAME = browser_feeds_s
+
 FORCE_STATIC_LIB = 1
-ifndef MOZ_MEMORY
 USE_STATIC_LIBS = 1
-endif
 
 DEFINES += \
 	-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
 	-DMOZ_MACBUNDLE_NAME=$(MOZ_MACBUNDLE_NAME) \
 	$(NULL)
 
 EXTRA_COMPONENTS = \
   BrowserFeeds.manifest \
--- a/browser/components/migration/src/Makefile.in
+++ b/browser/components/migration/src/Makefile.in
@@ -6,20 +6,19 @@ DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= migration
 LIBRARY_NAME	= migration_s
+
 FORCE_STATIC_LIB = 1
-ifndef MOZ_MEMORY
 USE_STATIC_LIBS = 1
-endif
 
 EXTRA_PP_COMPONENTS = \
   ProfileMigrator.js \
   ChromeProfileMigrator.js \
   FirefoxProfileMigrator.js \
   $(NULL)
 
 ifeq ($(OS_ARCH)_$(GNU_CXX),WINNT_)
--- a/browser/components/privatebrowsing/src/Makefile.in
+++ b/browser/components/privatebrowsing/src/Makefile.in
@@ -6,21 +6,19 @@ DEPTH   = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH   = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = privatebrowsing
 LIBRARY_NAME = privatebrowsing_s
+
 FORCE_STATIC_LIB = 1
-ifndef MOZ_MEMORY
 USE_STATIC_LIBS = 1
-endif
-
 
 CPPSRCS = \
 	nsPrivateBrowsingServiceWrapper.cpp \
 	$(NULL)
 
 LOCAL_INCLUDES = -I$(srcdir)/../../build
 
 EXTRA_COMPONENTS = \
--- a/browser/components/sessionstore/src/DocumentUtils.jsm
+++ b/browser/components/sessionstore/src/DocumentUtils.jsm
@@ -68,26 +68,26 @@ let DocumentUtils = {
             value = node.value;
             hasDefaultValue = value == node.defaultValue;
             break;
         }
       } else if (!node.multiple) {
         // <select>s without the multiple attribute are hard to determine the
         // default value, so assume we don't have the default.
         hasDefaultValue = false;
-        value = node.selectedIndex;
+        value = { selectedIndex: node.selectedIndex, value: node.value };
       } else {
         // <select>s with the multiple attribute are easier to determine the
         // default value since each <option> has a defaultSelected
         let options = Array.map(node.options, function(aOpt, aIx) {
           let oSelected = aOpt.selected;
           hasDefaultValue = hasDefaultValue && (oSelected == aOpt.defaultSelected);
-          return oSelected ? aIx : -1;
+          return oSelected ? aOpt.value : -1;
         });
-        value = options.filter(function(aIx) aIx >= 0);
+        value = options.filter(function(aIx) aIx !== -1);
       }
 
       // In order to reduce XPath generation (which is slow), we only save data
       // for form fields that have been changed. (cf. bug 537289)
       if (!hasDefaultValue) {
         if (nId) {
           ret.id[nId] = value;
         } else {
@@ -172,33 +172,51 @@ let DocumentUtils = {
       // Don't dispatch a change event for no change.
       if (aNode.checked == aValue) {
         return;
       }
       
       aNode.checked = aValue;
       eventType = "change";
     } else if (typeof aValue == "number") {
+      // handle select backwards compatibility, example { "#id" : index }
       // We saved the value blindly since selects take more work to determine
       // default values. So now we should check to avoid unnecessary events.
       if (aNode.selectedIndex == aValue) {
         return;
       }
       
-      try {
+      if (aValue < aNode.options.length) {
         aNode.selectedIndex = aValue;
         eventType = "change";
-      } catch (ex) { /* throws for invalid indices */ }
+      } 
+    } else if (aValue && aValue.selectedIndex >= 0 && aValue.value) {
+      // handle select new format
+
+      // Don't dispatch a change event for no change
+      if (aNode.options[aNode.selectedIndex].value == aValue.value) {
+        return;
+      }
+
+      // find first option with matching aValue if possible
+      for (let i = 0; i < aNode.options.length; i++) {
+        if (aNode.options[i].value == aValue.value) {
+          aNode.selectedIndex = i;
+          break;
+        }
+      }
+      eventType = "change";
     } else if (aValue && aValue.fileList && aValue.type == "file" &&
       aNode.type == "file") {
       aNode.mozSetFileNameArray(aValue.fileList, aValue.fileList.length);
       eventType = "input";
     } else if (aValue && typeof aValue.indexOf == "function" && aNode.options) {
       Array.forEach(aNode.options, function(opt, index) {
-        opt.selected = aValue.indexOf(index) > -1;
+        // don't worry about malformed options with same values
+        opt.selected = aValue.indexOf(opt.value) > -1;
         
         // Only fire the event here if this wasn't selected by default
         if (!opt.defaultSelected) {
           eventType = "change";
         }
       });
     }
 
--- a/browser/components/sessionstore/test/Makefile.in
+++ b/browser/components/sessionstore/test/Makefile.in
@@ -116,16 +116,18 @@ include $(topsrcdir)/config/rules.mk
 	browser_624727.js \
 	browser_625257.js \
 	browser_628270.js \
 	browser_635418.js \
 	browser_636279.js \
 	browser_644409-scratchpads.js \
 	browser_645428.js \
 	browser_659591.js \
+	browser_662743.js \
+	browser_662743_sample.html \
 	browser_662812.js \
 	browser_665702-state_session.js \
 	browser_682507.js \
 	browser_687710.js \
 	browser_687710_2.js \
 	browser_694378.js \
 	browser_701377.js \
 	browser_705597.js \
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_662743.js
@@ -0,0 +1,128 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// This tests that session restore component does restore the right <select> option.
+// Session store should not rely only on previous user's selectedIndex, it should
+// check its value as well.
+
+function test() {
+  /** Tests selected options **/
+  waitForExplicitFinish();
+
+  let testTabCount = 0;
+  let formData = [
+  // default case
+    { },
+  // old format
+    { "#select_id" : 0 },
+    { "#select_id" : 2 },
+    // invalid index
+    { "#select_id" : 8 },
+    { "/xhtml:html/xhtml:body/xhtml:select" : 5},
+    { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : 6},
+
+  // new format
+    // index doesn't match value (testing an option in between (two))
+    { id:{ "select_id": {"selectedIndex":0,"value":"val2"} } },
+    // index doesn't match value (testing an invalid value)
+    { id:{ "select_id": {"selectedIndex":4,"value":"val8"} } },
+    // index doesn't match value (testing an invalid index)
+    { id:{ "select_id": {"selectedIndex":8,"value":"val5"} } },
+    // index and value match position zero
+    { id:{ "select_id": {"selectedIndex":0,"value":"val0"} }, xpath: {} },
+    // index doesn't match value (testing the last option (seven))
+    { id:{},"xpath":{ "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']": {"selectedIndex":1,"value":"val7"} } },
+    // index and value match the default option "selectedIndex":3,"value":"val3"
+    { xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":3,"value":"val3"} } },
+    // index matches default option however it doesn't match value
+    { id:{ "select_id": {"selectedIndex":3,"value":"val4"} } },
+
+  // combinations
+    { "#select_id" : 3, id:{ "select_id": {"selectedIndex":1,"value":"val1"} } },
+    { "#select_id" : 5, xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":4,"value":"val4"} } },
+    { "/xhtml:html/xhtml:body/xhtml:select" : 5, id:{ "select_id": {"selectedIndex":1,"value":"val1"} }},
+    { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : 2, xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":7,"value":"val7"} } }
+  ];
+
+  let expectedValues = [
+    [ "val3"], // default value
+    [ "val0"],
+    [ "val2"],
+    [ "val3"], // default value (invalid index)
+    [ "val5"],
+    [ "val6"],
+    [ "val2"],
+    [ "val3"], // default value (invalid value)
+    [ "val5"], // value is still valid (even it has an invalid index)
+    [ "val0"],
+    [ "val7"],
+    [ "val3"],
+    [ "val4"],
+    [ "val1"],
+    [ "val4"],
+    [ "val1"],
+    [ "val7"]
+  ];
+  let callback = function() {
+    testTabCount--;
+    if (testTabCount == 0) {
+      finish();
+    }
+  };
+
+  for (let i = 0; i < formData.length; i++) {
+    testTabCount++;
+    testTabRestoreData(formData[i], expectedValues[i], callback);
+  }
+}
+
+function testTabRestoreData(aFormData, aExpectedValues, aCallback) {
+  let testURL =
+    getRootDirectory(gTestPath) + "browser_662743_sample.html";
+  let tab = gBrowser.addTab(testURL);
+  let tabState = { entries: [{ url: testURL, formdata: aFormData}] };
+
+  tab.linkedBrowser.addEventListener("load", function(aEvent) {
+    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
+    ss.setTabState(tab, JSON.stringify(tabState));
+
+    tab.addEventListener("SSTabRestored", function(aEvent) {
+      tab.removeEventListener("SSTabRestored", arguments.callee);
+      let doc = tab.linkedBrowser.contentDocument;
+      let select = doc.getElementById("select_id");
+      let value = select.options[select.selectedIndex].value;
+
+      // test select options values
+      is(value, aExpectedValues[0],
+        "Select Option by selectedIndex &/or value has been restored correctly");
+
+      // clean up
+      gBrowser.removeTab(tab);
+      aCallback();
+    });
+
+    tab.addEventListener("TabClose", function(aEvent) {
+      tab.removeEventListener("TabClose", arguments.callee);
+      let restoredTabState = JSON.parse(ss.getTabState(tab));
+      let restoredFormData = restoredTabState.entries[0].formdata;
+      let selectIdFormData = restoredFormData.id.select_id;
+      let value = restoredFormData.id.select_id.value;
+
+      // test format
+      ok("id" in restoredFormData && "xpath" in restoredFormData,
+        "FormData format is valid");
+      // validate that there are no old keys
+      is(Object.keys(restoredFormData).length, 2,
+        "FormData key length is valid");
+      // test format
+      ok("selectedIndex" in selectIdFormData && "value" in selectIdFormData,
+        "select format is valid");
+      // validate that there are no old keys
+      is(Object.keys(selectIdFormData).length, 2,
+        "select_id length is valid");
+       // test set collection values
+      is(value, aExpectedValues[0],
+        "Collection has been saved correctly");
+    });
+  }, true);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_662743_sample.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<title>Test 662743</title>
+
+<!-- Select events -->
+<h3>Select options</h3>
+<select id="select_id" name="select_name">
+  <option value="val0">Zero</option>
+  <option value="val1">One</option>
+  <option value="val2">Two</option>
+  <option value="val3" selected="selected">Three</option>
+  <option value="val4">Four</option>
+  <option value="val5">Five</option>
+  <option value="val6">Six</option>
+  <option value="val7">Seven</option>
+</select>
\ No newline at end of file
--- a/browser/components/shell/src/Makefile.in
+++ b/browser/components/shell/src/Makefile.in
@@ -6,21 +6,19 @@
 DEPTH   = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH   = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = shellservice
+
 FORCE_STATIC_LIB = 1
-ifndef MOZ_MEMORY
 USE_STATIC_LIBS = 1
-endif
-
 
 ifeq ($(OS_ARCH),WINNT)
 CPPSRCS = nsWindowsShellService.cpp
 else
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 CPPSRCS = nsMacShellService.cpp
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT), gtk2)
--- a/browser/components/test/browser_bug538331.js
+++ b/browser/components/test/browser_bug538331.js
@@ -407,19 +407,20 @@ function reloadUpdateManagerData()
 function writeUpdatesToXMLFile(aText)
 {
   const PERMS_FILE = 0644;
 
   const MODE_WRONLY   = 0x02;
   const MODE_CREATE   = 0x08;
   const MODE_TRUNCATE = 0x20;
 
+  const kIsWin = (navigator.platform.indexOf("Win") == 0);
   let file = Cc["@mozilla.org/file/directory_service;1"].
              getService(Ci.nsIProperties).
-             get("XCurProcD", Ci.nsIFile);
+             get(kIsWin ? "UpdRootD" : "XCurProcD", Ci.nsIFile);
   file.append("updates.xml");
   let fos = Cc["@mozilla.org/network/file-output-stream;1"].
             createInstance(Ci.nsIFileOutputStream);
   if (!file.exists()) {
     file.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, PERMS_FILE);
   }
   fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE, 0);
   fos.write(aText, aText.length);
--- a/browser/devtools/commandline/gcli.jsm
+++ b/browser/devtools/commandline/gcli.jsm
@@ -6196,17 +6196,17 @@ var eagerHelperSettingSpec = {
   type: {
     name: 'selection',
     lookup: [
       { name: 'never', value: Eagerness.NEVER },
       { name: 'sometimes', value: Eagerness.SOMETIMES },
       { name: 'always', value: Eagerness.ALWAYS },
     ]
   },
-  defaultValue: 1,
+  defaultValue: Eagerness.SOMETIMES,
   description: l10n.lookup('eagerHelperDesc'),
   ignoreTypeDifference: true
 };
 var eagerHelper;
 
 /**
  * Register (and unregister) the hide-intro setting
  */
@@ -6341,17 +6341,18 @@ FocusManager.prototype.removeMonitoredEl
 };
 
 /**
  * Monitor for new command executions
  */
 FocusManager.prototype.updatePosition = function(dimensions) {
   var ev = {
     tooltipVisible: this.isTooltipVisible,
-    outputVisible: this.isOutputVisible
+    outputVisible: this.isOutputVisible,
+    dimensions: dimensions
   };
   this.onVisibilityChange(ev);
 };
 
 /**
  * Monitor for new command executions
  */
 FocusManager.prototype._outputted = function(ev) {
new file mode 100644
--- /dev/null
+++ b/browser/devtools/commandline/gclioutput.xhtml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
+  [
+    <!ENTITY % webConsoleDTD SYSTEM "chrome://browser/locale/devtools/webConsole.dtd">
+    %webConsoleDTD;
+  ]
+>
+
+<!-- ***** BEGIN LICENSE BLOCK *****
+   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
+   -
+   - The contents of this file are subject to the Mozilla Public License Version
+   - 1.1 (the "License"); you may not use this file except in compliance with
+   - the License. You may obtain a copy of the License at
+   - http://www.mozilla.org/MPL/
+   -
+   - Software distributed under the License is distributed on an "AS IS" basis,
+   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+   - for the specific language governing rights and limitations under the
+   - License.
+   -
+   - The Original Code is GCLI.
+   -
+   - The Initial Developer of the Original Code is
+   - Mozilla Foundation.
+   - Portions created by the Initial Developer are Copyright (C) 2012
+   - the Initial Developer. All Rights Reserved.
+   -
+   - Contributor(s):
+   -   Joe Walker <jwalker@mozilla.com>
+   -
+   - Alternatively, the contents of this file may be used under the terms of
+   - either the GNU General Public License Version 2 or later (the "GPL"), or
+   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+   - in which case the provisions of the GPL or the LGPL are applicable instead
+   - of those above. If you wish to allow use of your version of this file only
+   - under the terms of either the GPL or the LGPL, and not to allow others to
+   - use your version of this file under the terms of the MPL, indicate your
+   - decision by deleting the provisions above and replace them with the notice
+   - and other provisions required by the LGPL or the GPL. If you do not delete
+   - the provisions above, a recipient may use your version of this file under
+   - the terms of any one of the MPL, the GPL or the LGPL.
+   -
+   - ***** END LICENSE BLOCK ***** -->
+
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+  <link rel="stylesheet" href="chrome://global/skin/global.css" type="text/css"/>
+  <link rel="stylesheet" href="chrome://browser/content/devtools/gcli.css" type="text/css"/>
+  <link rel="stylesheet" href="chrome://browser/skin/devtools/gcli.css" type="text/css"/>
+</head>
+<body class="gcli-body">
+<div id="gcli-output-root"></div>
+</body>
+</html>
rename from browser/devtools/commandline/gcliblank.xhtml
rename to browser/devtools/commandline/gclitooltip.xhtml
--- a/browser/devtools/commandline/gcliblank.xhtml
+++ b/browser/devtools/commandline/gclitooltip.xhtml
@@ -14,13 +14,13 @@
 
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
   <link rel="stylesheet" href="chrome://global/skin/global.css" type="text/css"/>
   <link rel="stylesheet" href="chrome://browser/content/devtools/gcli.css" type="text/css"/>
   <link rel="stylesheet" href="chrome://browser/skin/devtools/gcli.css" type="text/css"/>
 </head>
-<body id="gclichrome-body">
-<div>
-</div>
+<body class="gcli-body">
+<div id="gcli-tooltip-root"></div>
+<div id="gcli-tooltip-connector"></div>
 </body>
 </html>
old mode 100755
new mode 100644
--- a/browser/devtools/debugger/debugger-controller.js
+++ b/browser/devtools/debugger/debugger-controller.js
@@ -528,53 +528,30 @@ StackFrames.prototype = {
       // Add nodes for every other variable in scope.
       variables = frame.environment.bindings.variables;
       for (let variable in variables) {
         let paramVar = localScope.addVar(variable);
         let paramVal = variables[variable].value;
         paramVar.setGrip(paramVal);
         this._addExpander(paramVar, paramVal);
       }
-
-      // If we already found 'arguments', we are done here.
-      if ("arguments" in frame.environment.bindings.variables) {
-        // Signal that variables have been fetched.
-        DebuggerController.dispatchEvent("Debugger:FetchedVariables");
-        return;
-      }
     }
 
-    // Sometimes in call frames with arguments we don't get 'arguments' in the
-    // environment (bug 746601) and we have to construct it manually. Note, that
-    // in this case arguments.callee will be absent, even in the cases where it
-    // shouldn't be.
-    if (frame.arguments && frame.arguments.length > 0) {
-      // Add "arguments".
-      let argsVar = localScope.addVar("arguments");
-      argsVar.setGrip({
-        type: "object",
-        class: "Arguments"
-      });
-      this._addExpander(argsVar, frame.arguments);
-
-      // Signal that variables have been fetched.
-      DebuggerController.dispatchEvent("Debugger:FetchedVariables");
-    }
-
+    // Signal that variables have been fetched.
+    DebuggerController.dispatchEvent("Debugger:FetchedVariables");
   },
 
   /**
    * Adds an 'onexpand' callback for a variable, lazily handling the addition of
    * new properties.
    */
   _addExpander: function SF__addExpander(aVar, aObject) {
-    // No need for expansion for null and undefined values, but we do need them
-    // for frame.arguments which is a regular array.
+    // No need for expansion for null and undefined values.
     if (!aVar || !aObject || typeof aObject !== "object" ||
-        (aObject.type !== "object" && !Array.isArray(aObject))) {
+        aObject.type !== "object") {
       return;
     }
 
     // Force the twisty to show up.
     aVar.forceShowArrow();
     aVar.onexpand = this._addVarProperties.bind(this, aVar, aObject);
   },
 
@@ -583,33 +560,16 @@ StackFrames.prototype = {
    * expanded.
    */
   _addVarProperties: function SF__addVarProperties(aVar, aObject) {
     // Retrieve the properties only once.
     if (aVar.fetched) {
       return;
     }
 
-    // For arrays we have to construct a grip-like object.
-    if (Array.isArray(aObject)) {
-      let properties = { length: { value: aObject.length } };
-      for (let i = 0, l = aObject.length; i < l; i++) {
-        properties[i] = { value: aObject[i] };
-      }
-      aVar.addProperties(properties);
-
-      // Expansion handlers must be set after the properties are added.
-      for (let i = 0, l = aObject.length; i < l; i++) {
-        this._addExpander(aVar[i], aObject[i]);
-      }
-
-      aVar.fetched = true;
-      return;
-    }
-
     let objClient = this.activeThread.pauseGrip(aObject);
     objClient.getPrototypeAndProperties(function SF_onProtoAndProps(aResponse) {
       // Add __proto__.
       if (aResponse.prototype.type !== "null") {
         let properties = { "__proto__ ": { value: aResponse.prototype } };
         aVar.addProperties(properties);
 
         // Expansion handlers must be set after the properties are added.
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-07.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-07.js
@@ -71,28 +71,27 @@ function testFrameParameters()
         "Should have the right property value for 'dArg'.");
 
       is(localNodes[5].querySelector(".info").textContent, "null",
         "Should have the right property value for 'eArg'.");
 
       is(localNodes[6].querySelector(".info").textContent, "undefined",
         "Should have the right property value for 'fArg'.");
 
-      // FIXME bug TODO: reenable
-      //is(localNodes[7].querySelector(".info").textContent, "1",
-      //  "Should have the right property value for 'a'.");
+      is(localNodes[7].querySelector(".info").textContent, "1",
+       "Should have the right property value for 'a'.");
+
+      is(localNodes[8].querySelector(".info").textContent, "[object Object]",
+       "Should have the right property value for 'b'.");
 
-      //is(localNodes[8].querySelector(".info").textContent, "[object Object]",
-      //  "Should have the right property value for 'b'.");
+      is(localNodes[9].querySelector(".info").textContent, "[object Object]",
+       "Should have the right property value for 'c'.");
 
-      //is(localNodes[9].querySelector(".info").textContent, "[object Object]",
-      //  "Should have the right property value for 'c'.");
-
-      //is(localNodes[10].querySelector(".info").textContent, "[object Arguments]",
-      //  "Should have the right property value for 'arguments'.");
+      is(localNodes[10].querySelector(".info").textContent, "[object Arguments]",
+        "Should have the right property value for 'arguments'.");
 
       resumeAndFinish();
     }}, 0);
   }, false);
 
   EventUtils.sendMouseEvent({ type: "click" },
     content.document.querySelector("button"),
     content.window);
--- a/browser/devtools/debugger/test/browser_dbg_propertyview-08.js
+++ b/browser/devtools/debugger/test/browser_dbg_propertyview-08.js
@@ -51,27 +51,28 @@ function testFrameParameters()
         "Should have three frames.");
 
       is(localNodes.length, 11,
         "The localScope should contain all the created variable elements.");
 
       is(localNodes[0].querySelector(".info").textContent, "[object Proxy]",
         "Should have the right property value for 'this'.");
 
-      // Expand the '__proto__', 'arguments' and 'a' tree nodes. This causes
+      // Expand the 'this', 'arguments' and 'c' tree nodes. This causes
       // their properties to be retrieved and displayed.
       localNodes[0].expand();
       localNodes[9].expand();
       localNodes[10].expand();
 
       // Poll every few milliseconds until the properties are retrieved.
       // It's important to set the timer in the chrome window, because the
       // content window timers are disabled while the debuggee is paused.
       let count = 0;
       let intervalID = window.setInterval(function(){
+        dump("count: "+count+" ");
         if (++count > 50) {
           ok(false, "Timed out while polling for the properties.");
           resumeAndFinish();
         }
         if (!localNodes[0].fetched ||
             !localNodes[9].fetched ||
             !localNodes[10].fetched) {
           return;
@@ -91,27 +92,27 @@ function testFrameParameters()
         is(localNodes[9].querySelectorAll(".property > .title > .key")[1]
                         .textContent, "a",
           "Should have the right property name for 'a'.");
 
         is(localNodes[9].querySelectorAll(".property > .title > .value")[1]
                         .textContent, 1,
           "Should have the right value for 'c.a'.");
 
-        //is(localNodes[10].querySelector(".info").textContent,
-        //  "[object Arguments]",
-        //  "Should have the right property value for 'arguments'.");
+        is(localNodes[10].querySelector(".info").textContent,
+         "[object Arguments]",
+         "Should have the right property value for 'arguments'.");
 
-        //is(localNodes[10].querySelector(".property > .title > .key")
-        //                .textContent, "length",
-        //  "Should have the right property name for 'length'.");
+        is(localNodes[10].querySelectorAll(".property > .title > .key")[7]
+                       .textContent, "length",
+         "Should have the right property name for 'length'.");
 
-        //is(localNodes[10].querySelector(".property > .title > .value")
-        //                .textContent, 5,
-        //  "Should have the right argument length.");
+        is(localNodes[10].querySelectorAll(".property > .title > .value")[7]
+                       .textContent, 5,
+         "Should have the right argument length.");
 
         resumeAndFinish();
       }, 100);
     }}, 0);
   }, false);
 
   EventUtils.sendMouseEvent({ type: "click" },
     content.document.querySelector("button"),
--- a/browser/devtools/jar.mn
+++ b/browser/devtools/jar.mn
@@ -18,9 +18,10 @@ browser.jar:
     content/browser/devtools/layoutview/view.css  (layoutview/view.css)
     content/browser/orion.js                      (sourceeditor/orion/orion.js)
 *   content/browser/source-editor-overlay.xul     (sourceeditor/source-editor-overlay.xul)
 *   content/browser/debugger.xul                  (debugger/debugger.xul)
     content/browser/debugger.css                  (debugger/debugger.css)
     content/browser/debugger-controller.js        (debugger/debugger-controller.js)
     content/browser/debugger-view.js              (debugger/debugger-view.js)
     content/browser/devtools/gcli.css             (commandline/gcli.css)
-    content/browser/devtools/gcliblank.xhtml      (commandline/gcliblank.xhtml)
+    content/browser/devtools/gclioutput.xhtml     (commandline/gclioutput.xhtml)
+    content/browser/devtools/gclitooltip.xhtml    (commandline/gclitooltip.xhtml)
--- a/browser/devtools/shared/DeveloperToolbar.jsm
+++ b/browser/devtools/shared/DeveloperToolbar.jsm
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const EXPORTED_SYMBOLS = [ "DeveloperToolbar" ];
 
 const NS_XHTML = "http://www.w3.org/1999/xhtml";
-const URI_GCLIBLANK = "chrome://browser/content/devtools/gcliblank.xhtml";
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "gcli", function() {
   let obj = {};
   Components.utils.import("resource:///modules/devtools/gcli.jsm", obj);
   Components.utils.import("resource:///modules/devtools/GcliCommands.jsm", {});
@@ -74,17 +73,16 @@ Object.defineProperty(DeveloperToolbar.p
  * toggle the toolbar
  */
 DeveloperToolbar.prototype.toggle = function DT_toggle()
 {
   if (this.visible) {
     this.hide();
   } else {
     this.show();
-    this._input.focus();
   }
 };
 
 /**
  * Even if the user has not clicked on 'Got it' in the intro, we only show it
  * once per session.
  * Warning this is slightly messed up because this.DeveloperToolbar is not the
  * same as this.DeveloperToolbar when in browser.js context.
@@ -149,19 +147,21 @@ DeveloperToolbar.prototype._onload = fun
     scratchpad: null
   });
 
   this.display.onVisibilityChange.add(this.outputPanel._visibilityChanged, this.outputPanel);
   this.display.onVisibilityChange.add(this.tooltipPanel._visibilityChanged, this.tooltipPanel);
   this.display.onOutput.add(this.outputPanel._outputChanged, this.outputPanel);
 
   this._chromeWindow.getBrowser().tabContainer.addEventListener("TabSelect", this, false);
-  this._chromeWindow.getBrowser().addEventListener("load", this, true); 
+  this._chromeWindow.getBrowser().addEventListener("load", this, true);
+  this._chromeWindow.addEventListener("resize", this, false);
 
   this._element.hidden = false;
+  this._input.focus();
 
   this._notify(NOTIFICATIONS.SHOW);
   if (this._pendingShowCallback) {
     this._pendingShowCallback.call();
     this._pendingShowCallback = undefined;
   }
 
   // If a hide event happened while we were loading, then we need to hide.
@@ -258,111 +258,55 @@ DeveloperToolbar.prototype.handleEvent =
         chromeWindow: this._chromeWindow,
         environment: {
           chromeDocument: this._doc,
           contentDocument: contentDocument
         },
       });
     }
   }
+  else if (aEvent.type == "resize") {
+    this.outputPanel._resize();
+  }
 };
 
 /**
- * Add class="gcli-panel-inner-arrowcontent" to a panel's
- * |<xul:box class="panel-inner-arrowcontent">| so we can alter the styling
- * without complex CSS expressions.
- * @param aPanel The panel to affect
- */
-function getContentBox(aPanel)
-{
-  let container = aPanel.ownerDocument.getAnonymousElementByAttribute(
-          aPanel, "anonid", "container");
-  return container.querySelector(".panel-inner-arrowcontent");
-}
-
-/**
- * Helper function to calculate the sum of the vertical padding and margins
- * between a nested node |aNode| and an ancestor |aRoot|. Iff all of the
- * children of aRoot are 'only-childs' until you get to aNode then to avoid
- * scroll-bars, the 'correct' height of aRoot is verticalSpacing + aNode.height.
- * @param aNode The child node whose height is known.
- * @param aRoot The parent height whose height we can affect.
- * @return The sum of the vertical padding/margins in between aNode and aRoot.
- */
-function getVerticalSpacing(aNode, aRoot)
-{
-  let win = aNode.ownerDocument.defaultView;
-
-  function pxToNum(styles, property) {
-    return parseInt(styles.getPropertyValue(property).replace(/px$/, ''), 10);
-  }
-
-  let vertSpacing = 0;
-  do {
-    let styles = win.getComputedStyle(aNode);
-    vertSpacing += pxToNum(styles, "padding-top");
-    vertSpacing += pxToNum(styles, "padding-bottom");
-    vertSpacing += pxToNum(styles, "margin-top");
-    vertSpacing += pxToNum(styles, "margin-bottom");
-    vertSpacing += pxToNum(styles, "border-top-width");
-    vertSpacing += pxToNum(styles, "border-bottom-width");
-
-    let prev = aNode.previousSibling;
-    while (prev != null) {
-      vertSpacing += prev.clientHeight;
-      prev = prev.previousSibling;
-    }
-
-    let next = aNode.nextSibling;
-    while (next != null) {
-      vertSpacing += next.clientHeight;
-      next = next.nextSibling;
-    }
-
-    aNode = aNode.parentNode;
-  } while (aNode !== aRoot);
-
-  return vertSpacing + 9;
-}
-
-/**
  * Panel to handle command line output.
  * @param aChromeDoc document from which we can pull the parts we need.
  * @param aInput the input element that should get focus.
  * @param aLoadCallback called when the panel is loaded properly.
  */
 function OutputPanel(aChromeDoc, aInput, aLoadCallback)
 {
   this._input = aInput;
-  this._anchor = aChromeDoc.getElementById("developer-toolbar");
+  this._toolbar = aChromeDoc.getElementById("developer-toolbar");
 
   this._loadCallback = aLoadCallback;
 
   /*
   <panel id="gcli-output"
-         type="arrow"
          noautofocus="true"
          noautohide="true"
          class="gcli-panel">
-    <iframe id="gcli-output-frame"
-            src=URI_GCLIBLANK
-            flex="1"/>
+    <html:iframe xmlns:html="http://www.w3.org/1999/xhtml"
+                 id="gcli-output-frame"
+                 src="chrome://browser/content/devtools/gclioutput.xhtml"
+                 flex="1"/>
   </panel>
   */
   this._panel = aChromeDoc.createElement("panel");
   this._panel.id = "gcli-output";
   this._panel.classList.add("gcli-panel");
-  this._panel.setAttribute("type", "arrow");
   this._panel.setAttribute("noautofocus", "true");
   this._panel.setAttribute("noautohide", "true");
-  this._anchor.parentElement.insertBefore(this._panel, this._anchor);
+  this._toolbar.parentElement.insertBefore(this._panel, this._toolbar);
 
-  this._frame = aChromeDoc.createElement("iframe");
+  this._frame = aChromeDoc.createElementNS(NS_XHTML, "iframe");
   this._frame.id = "gcli-output-frame";
-  this._frame.setAttribute("src", URI_GCLIBLANK);
+  this._frame.setAttribute("src", "chrome://browser/content/devtools/gclioutput.xhtml");
   this._frame.setAttribute("flex", "1");
   this._panel.appendChild(this._frame);
 
   this.displayedOutput = undefined;
 
   this._onload = this._onload.bind(this);
   this._frame.addEventListener("load", this._onload, true);
 
@@ -372,57 +316,59 @@ function OutputPanel(aChromeDoc, aInput,
 /**
  * Wire up the element from the iframe, and inform the _loadCallback.
  */
 OutputPanel.prototype._onload = function OP_onload()
 {
   this._frame.removeEventListener("load", this._onload, true);
   delete this._onload;
 
-  this._content = getContentBox(this._panel);
-  this._content.classList.add("gcli-panel-inner-arrowcontent");
+  this.document = this._frame.contentDocument;
 
-  this.document = this._frame.contentDocument;
-  this.document.body.classList.add("gclichrome-output");
-
-  this._div = this.document.querySelector("div");
+  this._div = this.document.getElementById("gcli-output-root");
   this._div.classList.add('gcli-row-out');
   this._div.setAttribute('aria-live', 'assertive');
 
   this.loaded = true;
   if (this._loadCallback) {
     this._loadCallback();
     delete this._loadCallback;
   }
 };
 
 /**
  * Display the OutputPanel.
  */
 OutputPanel.prototype.show = function OP_show()
 {
+  // This is nasty, but displaying the panel causes it to re-flow, which can
+  // change the size it should be, so we need to resize the iframe after the
+  // panel has displayed
   this._panel.ownerDocument.defaultView.setTimeout(function() {
     this._resize();
   }.bind(this), 0);
 
+  this._panel.openPopup(this._input, "before_start", 0, 0, false, false, null);
   this._resize();
-  this._panel.openPopup(this._anchor, "before_end", -300, 0, false, false, null);
 
   this._input.focus();
 };
 
 /**
  * Internal helper to set the height of the output panel to fit the available
  * content;
  */
 OutputPanel.prototype._resize = function CLP_resize()
 {
-  let vertSpacing = getVerticalSpacing(this._content, this._panel);
-  let idealHeight = this.document.body.scrollHeight + vertSpacing;
-  this._panel.sizeTo(400, Math.min(idealHeight, 500));
+  if (this._panel == null || this.document == null || !this._panel.state == "closed") {
+    return
+  }
+
+  this._frame.height = this.document.body.scrollHeight;
+  this._frame.width = this._input.clientWidth + 2;
 };
 
 /**
  * Called by GCLI when a command is executed.
  */
 OutputPanel.prototype._outputChanged = function OP_outputChanged(aEvent)
 {
   if (aEvent.output.hidden) {
@@ -471,20 +417,20 @@ OutputPanel.prototype.remove = function 
 /**
  * Detach listeners from the currently displayed Output.
  */
 OutputPanel.prototype.destroy = function OP_destroy()
 {
   this.remove();
 
   this._panel.removeChild(this._frame);
-  this._anchor.parentElement.removeChild(this._panel);
+  this._toolbar.parentElement.removeChild(this._panel);
 
   delete this._input;
-  delete this._anchor;
+  delete this._toolbar;
   delete this._panel;
   delete this._frame;
   delete this._content;
   delete this._div;
   delete this.document;
 };
 
 /**
@@ -505,83 +451,122 @@ OutputPanel.prototype._visibilityChanged
  * Panel to handle tooltips.
  * @param aChromeDoc document from which we can pull the parts we need.
  * @param aInput the input element that should get focus.
  * @param aLoadCallback called when the panel is loaded properly.
  */
 function TooltipPanel(aChromeDoc, aInput, aLoadCallback)
 {
   this._input = aInput;
-  this._anchor = aChromeDoc.getElementById("developer-toolbar");
+  this._toolbar = aChromeDoc.getElementById("developer-toolbar");
+  this._dimensions = { start: 0, end: 0 };
 
   this._onload = this._onload.bind(this);
   this._loadCallback = aLoadCallback;
   /*
   <panel id="gcli-tooltip"
          type="arrow"
          noautofocus="true"
          noautohide="true"
          class="gcli-panel">
-    <iframe id="gcli-tooltip-frame"
-            src=URI_GCLIBLANK
-            flex="1"/>
+    <html:iframe xmlns:html="http://www.w3.org/1999/xhtml"
+                 id="gcli-tooltip-frame"
+                 src="chrome://browser/content/devtools/gclitooltip.xhtml"
+                 flex="1"/>
   </panel>
   */
   this._panel = aChromeDoc.createElement("panel");
   this._panel.id = "gcli-tooltip";
   this._panel.classList.add("gcli-panel");
-  this._panel.setAttribute("type", "arrow");
   this._panel.setAttribute("noautofocus", "true");
   this._panel.setAttribute("noautohide", "true");
-  this._anchor.parentElement.insertBefore(this._panel, this._anchor);
+  this._toolbar.parentElement.insertBefore(this._panel, this._toolbar);
 
-  this._frame = aChromeDoc.createElement("iframe");
+  this._frame = aChromeDoc.createElementNS(NS_XHTML, "iframe");
   this._frame.id = "gcli-tooltip-frame";
-  this._frame.setAttribute("src", URI_GCLIBLANK);
+  this._frame.setAttribute("src", "chrome://browser/content/devtools/gclitooltip.xhtml");
   this._frame.setAttribute("flex", "1");
   this._panel.appendChild(this._frame);
 
   this._frame.addEventListener("load", this._onload, true);
   this.loaded = false;
 }
 
 /**
  * Wire up the element from the iframe, and inform the _loadCallback.
  */
 TooltipPanel.prototype._onload = function TP_onload()
 {
   this._frame.removeEventListener("load", this._onload, true);
 
-  this._content = getContentBox(this._panel);
-  this._content.classList.add("gcli-panel-inner-arrowcontent");
-
   this.document = this._frame.contentDocument;
-  this.document.body.classList.add("gclichrome-tooltip");
-
-  this.hintElement = this.document.querySelector("div");
+  this.hintElement = this.document.getElementById("gcli-tooltip-root");
+  this._connector = this.document.getElementById("gcli-tooltip-connector");
 
   this.loaded = true;
 
   if (this._loadCallback) {
     this._loadCallback();
     delete this._loadCallback;
   }
 };
 
 /**
  * Display the TooltipPanel.
  */
-TooltipPanel.prototype.show = function TP_show()
+TooltipPanel.prototype.show = function TP_show(aDimensions)
 {
-  let vertSpacing = getVerticalSpacing(this._content, this._panel);
-  let idealHeight = this.document.body.scrollHeight + vertSpacing;
-  this._panel.sizeTo(350, Math.min(idealHeight, 500));
-  this._panel.openPopup(this._anchor, "before_start", 0, 0, false, false, null);
+  if (!aDimensions) {
+    aDimensions = { start: 0, end: 0 };
+  }
+  this._dimensions = aDimensions;
+
+  // This is nasty, but displaying the panel causes it to re-flow, which can
+  // change the size it should be, so we need to resize the iframe after the
+  // panel has displayed
+  this._panel.ownerDocument.defaultView.setTimeout(function() {
+    this._resize();
+  }.bind(this), 0);
+
+  this._resize();
+  this._panel.openPopup(this._input, "before_start", aDimensions.start * 10, 0, false, false, null);
+  this._input.focus();
+};
 
-  this._input.focus();
+/**
+ * One option is to spend lots of time taking an average width of characters
+ * in the current font, dynamically, and weighting for the frequency of use of
+ * various characters, or even to render the given string off screen, and then
+ * measure the width.
+ * Or we could do this...
+ */
+const AVE_CHAR_WIDTH = 4.5;
+
+/**
+ * Display the TooltipPanel.
+ */
+TooltipPanel.prototype._resize = function TP_resize()
+{
+  if (this._panel == null || this.document == null || !this._panel.state == "closed") {
+    return
+  }
+
+  let offset = 10 + Math.floor(this._dimensions.start * AVE_CHAR_WIDTH);
+  this._frame.style.marginLeft = offset + "px";
+
+  /*
+  // Bug 744906: UX review - Not sure if we want this code to fatten connector
+  // with param width
+  let width = Math.floor(this._dimensions.end * AVE_CHAR_WIDTH);
+  width = Math.min(width, 100);
+  width = Math.max(width, 10);
+  this._connector.style.width = width + "px";
+  */
+
+  this._frame.height = this.document.body.scrollHeight;
 };
 
 /**
  * Hide the TooltipPanel.
  */
 TooltipPanel.prototype.remove = function TP_remove()
 {
   this._panel.hidePopup();
@@ -590,32 +575,34 @@ TooltipPanel.prototype.remove = function
 /**
  * Hide the TooltipPanel.
  */
 TooltipPanel.prototype.destroy = function TP_destroy()
 {
   this.remove();
 
   this._panel.removeChild(this._frame);
-  this._anchor.parentElement.removeChild(this._panel);
+  this._toolbar.parentElement.removeChild(this._panel);
 
+  delete this._connector;
+  delete this._dimensions;
   delete this._input;
   delete this._onload;
   delete this._panel;
   delete this._frame;
-  delete this._anchor;
+  delete this._toolbar;
   delete this._content;
   delete this.document;
   delete this.hintElement;
 };
 
 /**
  * Called by GCLI to indicate that we should show or hide one either the
  * tooltip panel or the output panel.
  */
 TooltipPanel.prototype._visibilityChanged = function TP_visibilityChanged(aEvent)
 {
   if (aEvent.tooltipVisible === true) {
-    this.show();
+    this.show(aEvent.dimensions);
   } else {
     this._panel.hidePopup();
   }
 };
--- a/browser/devtools/shared/test/Makefile.in
+++ b/browser/devtools/shared/test/Makefile.in
@@ -13,16 +13,17 @@ include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_TEST_FILES = \
   browser_browser_basic.js \
   browser_promise_basic.js \
   browser_require_basic.js \
   browser_templater_basic.js \
   browser_toolbar_basic.js \
+  browser_toolbar_tooltip.js \
   head.js \
   $(NULL)
 
 _BROWSER_TEST_PAGES = \
   browser_templater_basic.html \
   browser_toolbar_basic.html \
   $(NULL)
 
--- a/browser/devtools/shared/test/browser_toolbar_basic.js
+++ b/browser/devtools/shared/test/browser_toolbar_basic.js
@@ -4,20 +4,20 @@
 // Tests that the developer toolbar works properly
 
 let imported = {};
 Components.utils.import("resource:///modules/HUDService.jsm", imported);
 registerCleanupFunction(function() {
   imported = {};
 });
 
-const URL = "http://example.com/browser/browser/devtools/shared/test/browser_toolbar_basic.html";
+const TEST_URI = "http://example.com/browser/browser/devtools/shared/test/browser_toolbar_basic.html";
 
 function test() {
-  addTab(URL, function(browser, tab) {
+  addTab(TEST_URI, function(browser, tab) {
     info("Starting browser_toolbar_basic.js");
     runTest();
   });
 }
 
 function runTest() {
   ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in runTest");
 
new file mode 100755
--- /dev/null
+++ b/browser/devtools/shared/test/browser_toolbar_tooltip.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests that the developer toolbar works properly
+
+const TEST_URI = "data:text/html;charset=utf-8,<p>Tooltip Tests</p>";
+
+function test() {
+  DeveloperToolbarTest.test(TEST_URI, function(browser, tab) {
+    runTest();
+    finish();
+  });
+}
+
+function runTest() {
+  let tooltipPanel = DeveloperToolbar.tooltipPanel;
+
+  DeveloperToolbar.display.focusManager.helpRequest();
+  DeveloperToolbar.display.inputter.setInput('help help');
+
+  DeveloperToolbar.display.inputter.setCursor({ start: 'help help'.length });
+  is(tooltipPanel._dimensions.start, 'help '.length,
+          'search param start, when cursor at end');
+  ok(getLeftMargin() > 30, 'tooltip offset, when cursor at end')
+
+  DeveloperToolbar.display.inputter.setCursor({ start: 'help'.length });
+  is(tooltipPanel._dimensions.start, 0,
+          'search param start, when cursor at end of command');
+  ok(getLeftMargin() > 9, 'tooltip offset, when cursor at end of command')
+
+  DeveloperToolbar.display.inputter.setCursor({ start: 'help help'.length - 1 });
+  is(tooltipPanel._dimensions.start, 'help '.length,
+          'search param start, when cursor at penultimate position');
+  ok(getLeftMargin() > 30, 'tooltip offset, when cursor at penultimate position')
+
+  DeveloperToolbar.display.inputter.setCursor({ start: 0 });
+  is(tooltipPanel._dimensions.start, 0,
+          'search param start, when cursor at start');
+  ok(getLeftMargin() > 9, 'tooltip offset, when cursor at start')
+}
+
+function getLeftMargin() {
+  let style = DeveloperToolbar.tooltipPanel._frame.style.marginLeft;
+  return parseInt(style.slice(0, -2), 10);
+}
--- a/browser/devtools/shared/test/head.js
+++ b/browser/devtools/shared/test/head.js
@@ -62,17 +62,65 @@ let DeveloperToolbarTest = {
   hide: function DTT_hide() {
     if (!DeveloperToolbar.visible) {
       ok(false, "!DeveloperToolbar.visible at start of closeDeveloperToolbar");
     }
     else {
       DeveloperToolbar.display.inputter.setInput("");
       DeveloperToolbar.hide();
     }
-  }
+  },
+
+  /**
+   * Quick wrapper around the things you need to do to run DeveloperToolbar
+   * command tests:
+   * - Set the pref 'devtools.toolbar.enabled' to true
+   * - Add a tab pointing at |uri|
+   * - Open the DeveloperToolbar
+   * - Register a cleanup function to undo the above
+   * - Run the tests
+   *
+   * @param uri The uri of a page to load. Can be 'about:blank' or 'data:...'
+   * @param testFunc A function containing the tests to run. This should
+   * arrange for 'finish()' to be called on completion.
+   */
+  test: function DTT_test(uri, testFunc) {
+    let menuItem = document.getElementById("menu_devToolbar");
+    let command = document.getElementById("Tools:DevToolbar");
+    let appMenuItem = document.getElementById("appmenu_devToolbar");
+
+    registerCleanupFunction(function() {
+      DeveloperToolbarTest.hide();
+
+      // a.k.a Services.prefs.clearUserPref("devtools.toolbar.enabled");
+      if (menuItem) menuItem.hidden = true;
+      if (command) command.setAttribute("disabled", "true");
+      if (appMenuItem) appMenuItem.hidden = true;
+    });
+
+    // a.k.a: Services.prefs.setBoolPref("devtools.toolbar.enabled", true);
+    if (menuItem) menuItem.hidden = false;
+    if (command) command.removeAttribute("disabled");
+    if (appMenuItem) appMenuItem.hidden = false;
+
+    addTab(uri, function(browser, tab) {
+      DeveloperToolbarTest.show(function() {
+
+        try {
+          testFunc(browser, tab);
+        }
+        catch (ex) {
+          ok(false, "" + ex);
+          console.error(ex);
+          finish();
+          throw ex;
+        }
+      });
+    });
+  },
 };
 
 function catchFail(func) {
   return function() {
     try {
       return func.apply(null, arguments);
     }
     catch (ex) {
--- a/browser/devtools/webconsole/HUDService.jsm
+++ b/browser/devtools/webconsole/HUDService.jsm
@@ -1753,16 +1753,17 @@ HUD_SERVICE.prototype =
 
     // Make sure that the console panel does not try to call
     // deactivateHUDForContext() again.
     hud.consoleWindowUnregisterOnHide = false;
 
     // Remove the HUDBox and the consolePanel if the Web Console is inside a
     // floating panel.
     if (hud.consolePanel && hud.consolePanel.parentNode) {
+      hud.consolePanel.hidePopup();
       hud.consolePanel.parentNode.removeChild(hud.consolePanel);
       hud.consolePanel.removeAttribute("hudId");
       hud.consolePanel = null;
     }
 
     hud.HUDBox.parentNode.removeChild(hud.HUDBox);
 
     if (hud.splitter.parentNode) {
new file mode 100644
--- /dev/null
+++ b/browser/extensions/Makefile.in
@@ -0,0 +1,35 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH      = ../..
+topsrcdir  = @top_srcdir@
+srcdir     = @srcdir@
+VPATH      = @srcdir@
+
+CHROMEDIR = $(call core_abspath,$(DIST))/bin/chrome
+
+include $(DEPTH)/config/autoconf.mk
+
+TEST_DIRS += pdfjs/test
+
+include $(topsrcdir)/config/rules.mk
+
+exclude_files = \
+  test \
+  install.rdf \
+  bootstrap.js \
+  icon.png \
+  icon64.png \
+  $(NULL)
+
+$(DIST)/bin/chrome/pdfjs.manifest: $(GLOBAL_DEPS)
+	printf "manifest pdfjs/chrome.manifest" > $@
+
+libs:: $(DIST)/bin/chrome/pdfjs.manifest
+	$(PYTHON) $(topsrcdir)/config/nsinstall.py \
+	  $(srcdir)/pdfjs \
+          $(foreach exclude,$(exclude_files), -X $(srcdir)/pdfjs/$(exclude)) \
+          $(DIST)/bin/chrome
+	$(PYTHON) $(MOZILLA_DIR)/config/buildlist.py \
+	  $(DIST)/bin/chrome.manifest "manifest chrome/pdfjs.manifest"
rename from browser/app/profile/extensions/uriloader@pdf.js/LICENSE
rename to browser/extensions/pdfjs/LICENSE
rename from browser/app/profile/extensions/uriloader@pdf.js/README.mozilla
rename to browser/extensions/pdfjs/README.mozilla
rename from browser/app/profile/extensions/uriloader@pdf.js/bootstrap.js
rename to browser/extensions/pdfjs/bootstrap.js
new file mode 100644
--- /dev/null
+++ b/browser/extensions/pdfjs/chrome.manifest
@@ -0,0 +1,3 @@
+resource pdf.js content/
+component {6457a96b-2d68-439a-bcfa-44465fbcdbb1} components/PdfStreamConverter.js
+contract @mozilla.org/streamconv;1?from=application/pdf&to=*/* {6457a96b-2d68-439a-bcfa-44465fbcdbb1}
rename from browser/app/profile/extensions/uriloader@pdf.js/components/PdfStreamConverter.js
rename to browser/extensions/pdfjs/components/PdfStreamConverter.js
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/debugger.js
rename to browser/extensions/pdfjs/content/web/debugger.js
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/bookmark.svg
rename to browser/extensions/pdfjs/content/web/images/bookmark.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/check.svg
rename to browser/extensions/pdfjs/content/web/images/check.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/comment.svg
rename to browser/extensions/pdfjs/content/web/images/comment.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/document-print.svg
rename to browser/extensions/pdfjs/content/web/images/document-print.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/download.svg
rename to browser/extensions/pdfjs/content/web/images/download.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/go-down.svg
rename to browser/extensions/pdfjs/content/web/images/go-down.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/go-up.svg
rename to browser/extensions/pdfjs/content/web/images/go-up.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/loading-icon.gif
rename to browser/extensions/pdfjs/content/web/images/loading-icon.gif
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/nav-outline.svg
rename to browser/extensions/pdfjs/content/web/images/nav-outline.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/nav-thumbs.svg
rename to browser/extensions/pdfjs/content/web/images/nav-thumbs.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/pin-down.svg
rename to browser/extensions/pdfjs/content/web/images/pin-down.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/pin-up.svg
rename to browser/extensions/pdfjs/content/web/images/pin-up.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/zoom-in.svg
rename to browser/extensions/pdfjs/content/web/images/zoom-in.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/images/zoom-out.svg
rename to browser/extensions/pdfjs/content/web/images/zoom-out.svg
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer-snippet-firefox-extension.html
rename to browser/extensions/pdfjs/content/web/viewer-snippet-firefox-extension.html
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer.css
rename to browser/extensions/pdfjs/content/web/viewer.css
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer.html
rename to browser/extensions/pdfjs/content/web/viewer.html
rename from browser/app/profile/extensions/uriloader@pdf.js/content/web/viewer.js
rename to browser/extensions/pdfjs/content/web/viewer.js
rename from browser/app/profile/extensions/uriloader@pdf.js/extension-files
rename to browser/extensions/pdfjs/extension-files
rename from browser/app/profile/extensions/uriloader@pdf.js/icon.png
rename to browser/extensions/pdfjs/icon.png
rename from browser/app/profile/extensions/uriloader@pdf.js/icon64.png
rename to browser/extensions/pdfjs/icon64.png
rename from browser/app/profile/extensions/uriloader@pdf.js/install.rdf.in
rename to browser/extensions/pdfjs/install.rdf.in
rename from browser/app/profile/extensions/uriloader@pdf.js/test/Makefile.in
rename to browser/extensions/pdfjs/test/Makefile.in
--- a/browser/app/profile/extensions/uriloader@pdf.js/test/Makefile.in
+++ b/browser/extensions/pdfjs/test/Makefile.in
@@ -1,17 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DEPTH     = ../../../../../..
+DEPTH     = ../../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
-relativesrcdir  = browser/app/profile/extensions/uriloader@pdf.js/test
+relativesrcdir  = browser/features/pdfjs/test
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_TEST_FILES = \
   browser_pdfjs_main.js \
   file_pdfjs_test.pdf \
   $(NULL)
rename from browser/app/profile/extensions/uriloader@pdf.js/test/browser_pdfjs_main.js
rename to browser/extensions/pdfjs/test/browser_pdfjs_main.js
--- a/browser/app/profile/extensions/uriloader@pdf.js/test/browser_pdfjs_main.js
+++ b/browser/extensions/pdfjs/test/browser_pdfjs_main.js
@@ -1,31 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
-const RELATIVE_DIR = "browser/app/profile/extensions/uriloader@pdf.js/test/";
+const RELATIVE_DIR = "browser/features/pdfjs/test/";
 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
 
 function test() {
   waitForExplicitFinish();
 
-  AddonManager.getAddonByID("uriloader@pdf.js", function(aAddon) {
-    is(aAddon.userDisabled, true, 'Pdf.js addon must be disabled by default');
-    aAddon.userDisabled = false;
-
-    registerCleanupFunction(function() {
-      aAddon.userDisabled = true;
-    });
-
-    continueTest();
-  });
-}
-
-function continueTest() {
   var tab = gBrowser.addTab(TESTROOT + "file_pdfjs_test.pdf");
   var newTabBrowser = gBrowser.getBrowserForTab(tab);
   newTabBrowser.addEventListener("load", function onLoad() {
     newTabBrowser.removeEventListener("load", onLoad, true);
 
     var hasViewer = newTabBrowser.contentDocument.querySelector('div#viewer');
     var hasPDFJS = 'PDFJS' in newTabBrowser.contentWindow.wrappedJSObject;
 
rename from browser/app/profile/extensions/uriloader@pdf.js/test/file_pdfjs_test.pdf
rename to browser/extensions/pdfjs/test/file_pdfjs_test.pdf
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -19,16 +19,18 @@
 
 #filter substitution
 
 #ifdef XP_MACOSX
 ; Mac bundle stuff
 @APPNAME@/Contents/Info.plist
 @APPNAME@/Contents/PkgInfo
 @APPNAME@/Contents/Resources/
+@APPNAME@/Contents/CodeResources
+@APPNAME@/Contents/_CodeSignature/CodeResources
 #endif
 
 [@AB_CD@]
 @BINPATH@/chrome/@AB_CD@@JAREXT@
 @BINPATH@/chrome/@AB_CD@.manifest
 @BINPATH@/defaults/profile/bookmarks.html
 @BINPATH@/defaults/profile/chrome/*
 @BINPATH@/defaults/profile/localstore.rdf
@@ -475,19 +477,20 @@
 @BINPATH@/libGLESv2.dll
 @BINPATH@/@MOZ_D3DX9_DLL@
 @BINPATH@/@MOZ_D3DCOMPILER_DLL@
 #endif
 
 ; [Browser Chrome Files]
 @BINPATH@/chrome/browser@JAREXT@
 @BINPATH@/chrome/browser.manifest
+@BINPATH@/chrome/pdfjs.manifest
+@BINPATH@/chrome/pdfjs/*
 @BINPATH@/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}/install.rdf
 @BINPATH@/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}/icon.png
-@BINPATH@/extensions/uriloader@pdf.js.xpi
 #ifdef SHIP_FEEDBACK
 @BINPATH@/distribution/extensions/testpilot@labs.mozilla.com.xpi
 #endif
 @BINPATH@/chrome/toolkit@JAREXT@
 @BINPATH@/chrome/toolkit.manifest
 #ifdef MOZ_GTK2
 @BINPATH@/chrome/icons/default/default16.png
 @BINPATH@/chrome/icons/default/default32.png
--- a/browser/installer/windows/nsis/installer.nsi
+++ b/browser/installer/windows/nsis/installer.nsi
@@ -1087,24 +1087,24 @@ Function .onInit
   ; Setup the components.ini file for the Components Page
   WriteINIStr "$PLUGINSDIR\components.ini" "Settings" NumFields "2"
 
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Type   "label"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Text   "$(OPTIONAL_COMPONENTS_DESC)"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Left   "0"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Right  "-1"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Top    "5"
-  WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Bottom "15"
+  WriteINIStr "$PLUGINSDIR\components.ini" "Field 1" Bottom "25"
 
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Type   "checkbox"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Text   "$(MAINTENANCE_SERVICE_CHECKBOX_DESC)"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Left   "0"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Right  "-1"
-  WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Top    "20"
-  WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Bottom "30"
+  WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Top    "27"
+  WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Bottom "37"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" State  "1"
   WriteINIStr "$PLUGINSDIR\components.ini" "Field 2" Flags  "GROUP"
 
   ; There must always be a core directory.
   ${GetSize} "$EXEDIR\core\" "/S=0K" $R5 $R7 $R8
   SectionSetSize ${APP_IDX} $R5
 
   ; Initialize $hHeaderBitmap to prevent redundant changing of the bitmap if
--- a/browser/locales/en-US/chrome/browser/aboutDialog.dtd
+++ b/browser/locales/en-US/chrome/browser/aboutDialog.dtd
@@ -64,13 +64,15 @@
 <!-- LOCALIZATION NOTE (update.downloading.start,update.downloading.end): update.downloading.start and 
      update.downloading.end all go into one line, with the amount downloaded inserted in between. As this
      is all in one line, try to make the localized text short (see bug 596813 for screenshots). The — is
      the "em dash" (long dash).
      example: Downloading update — 111 KB of 13 MB -->
 <!ENTITY update.downloading.start   "Downloading update — ">
 <!ENTITY update.downloading.end     "">
 
+<!ENTITY update.applying            "Applying update…">
+
 <!-- LOCALIZATION NOTE (channel.description.start,channel.description.end): channel.description.start and
      channel.description.end create one sentence, with the current channel label inserted in between.
      example: You are currently on the _Stable_ update channel. -->
 <!ENTITY channel.description.start  "You are currently on the ">
 <!ENTITY channel.description.end    " update channel. ">
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -224,19 +224,19 @@ These should match what Safari and other
 <!ENTITY scratchpad.label             "Scratchpad">
 <!ENTITY scratchpad.accesskey         "s">
 <!ENTITY scratchpad.keycode           "VK_F4">
 <!ENTITY scratchpad.keytext           "F4">
 
 <!ENTITY inspectCloseButton.tooltiptext "Close Inspector">
 
 <!ENTITY devToolbarCloseButton.tooltiptext "Close Developer Toolbar">
-<!ENTITY devToolbarMenu.label "Developer Toolbar">
-<!ENTITY devToolbarMenu.accesskey "v">
-<!ENTITY devToolbar.commandkey "v">
+<!ENTITY devToolbarMenu.label              "Developer Toolbar">
+<!ENTITY devToolbarMenu.accesskey          "v">
+<!ENTITY devToolbar.commandkey             "v">
 
 <!ENTITY webConsoleButton.label "Web Console">
 <!ENTITY inspectorButton.label "Inspector">
 <!ENTITY scriptsButton.label "Scripts">
 
 <!ENTITY inspectorHTMLCopyInner.label       "Copy Inner HTML">
 <!ENTITY inspectorHTMLCopyInner.accesskey   "I">
 
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -151,16 +151,18 @@ sanitizeSelectedWarning=All selected ite
 update.checkInsideButton.label=Check for Updates
 update.checkInsideButton.accesskey=C
 update.resumeButton.label=Resume Downloading %S…
 update.resumeButton.accesskey=D
 update.openUpdateUI.applyButton.label=Apply Update…
 update.openUpdateUI.applyButton.accesskey=A
 update.restart.updateButton.label=Restart to Update
 update.restart.updateButton.accesskey=R
+update.restart.restartButton.label=Update & Restart
+update.restart.restartButton.accesskey=R
 update.openUpdateUI.upgradeButton.label=Upgrade Now…
 update.openUpdateUI.upgradeButton.accesskey=U
 update.restart.upgradeButton.label=Upgrade Now
 update.restart.upgradeButton.accesskey=U
 
 # RSS Pretty Print
 feedShowFeedNew=Subscribe to '%S'…
 
--- a/browser/makefiles.sh
+++ b/browser/makefiles.sh
@@ -42,16 +42,17 @@ browser/devtools/debugger/Makefile
 browser/devtools/highlighter/Makefile
 browser/devtools/scratchpad/Makefile
 browser/devtools/shared/Makefile
 browser/devtools/sourceeditor/Makefile
 browser/devtools/styleeditor/Makefile
 browser/devtools/styleinspector/Makefile
 browser/devtools/tilt/Makefile
 browser/devtools/webconsole/Makefile
+browser/extensions/Makefile
 browser/fuel/Makefile
 browser/fuel/public/Makefile
 browser/fuel/src/Makefile
 browser/installer/Makefile
 browser/locales/Makefile
 browser/modules/Makefile
 browser/themes/Makefile
 $MOZ_BRANDING_DIRECTORY/Makefile
--- a/browser/modules/WebappsInstaller.jsm
+++ b/browser/modules/WebappsInstaller.jsm
@@ -103,16 +103,21 @@ function NativeApp(aData) {
                 ? firstLine
                 : firstLine.substr(0, 253) + "...";
   }
   this.shortDescription = sanitize(shortDesc);
 
   this.manifest = app.manifest;
 
   this.profileFolder = Services.dirsvc.get("ProfD", Ci.nsIFile);
+
+  this.webappJson = {
+    "registryDir": this.profileFolder.path,
+    "app": app
+  };
 }
 
 #ifdef XP_WIN
 /*************************************
  * Windows app installer
  *
  * The Windows installation process will generate the following files:
  *
@@ -283,24 +288,19 @@ WinNativeApp.prototype = {
     uninstaller.copyTo(this.uninstallDir, this.uninstallerFile.leafName);
   },
 
   /**
    * Creates the configuration files into their destination folders.
    */
   _createConfigFiles: function() {
     // ${InstallDir}/webapp.json
-    let json = {
-      "registryDir": this.profileFolder.path,
-      "app": this.app
-    };
-
     let configJson = this.installDir.clone();
     configJson.append("webapp.json");
-    writeToFile(configJson, JSON.stringify(json), function() {});
+    writeToFile(configJson, JSON.stringify(this.webappJson), function() {});
 
     // ${InstallDir}/webapp.ini
     let webappINI = this.installDir.clone().QueryInterface(Ci.nsILocalFile);
     webappINI.append("webapp.ini");
 
     let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
                     .getService(Ci.nsIINIParserFactory);
 
@@ -533,28 +533,19 @@ MacNativeApp.prototype = {
   _copyPrebuiltFiles: function() {
     let webapprt = this.processFolder.clone();
     webapprt.append("webapprt-stub");
     webapprt.copyTo(this.macOSDir, "webapprt");
   },
 
   _createConfigFiles: function() {
     // ${ProfileDir}/webapp.json
-    let json = {
-      "registryDir": this.profileFolder.path,
-      "app": {
-        "origin": this.launchURI.prePath,
-        "installOrigin": "apps.mozillalabs.com",
-        "manifest": this.manifest
-       }
-    };
-
     let configJson = this.appProfileDir.clone();
     configJson.append("webapp.json");
-    writeToFile(configJson, JSON.stringify(json), function() {});
+    writeToFile(configJson, JSON.stringify(this.webappJson), function() {});
 
     // ${InstallDir}/Contents/MacOS/webapp.ini
     let applicationINI = this.macOSDir.clone().QueryInterface(Ci.nsILocalFile);
     applicationINI.append("webapp.ini");
 
     let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"]
                     .getService(Ci.nsIINIParserFactory);
 
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -326,16 +326,17 @@ user_pref("javascript.options.jit_harden
 user_pref("gfx.color_management.force_srgb", true);
 user_pref("network.manage-offline-status", false);
 user_pref("test.mousescroll", true);
 user_pref("security.default_personal_cert", "Select Automatically"); // Need to client auth test be w/o any dialogs
 user_pref("network.http.prompt-temp-redirect", false);
 user_pref("media.cache_size", 100);
 user_pref("security.warn_viewing_mixed", false);
 user_pref("app.update.enabled", false);
+user_pref("app.update.stage.enabled", false);
 user_pref("browser.panorama.experienced_first_run", true); // Assume experienced
 user_pref("dom.w3c_touch_events.enabled", true);
 user_pref("toolkit.telemetry.prompted", 2);
 // Existing tests assume there is no font size inflation.
 user_pref("font.size.inflation.emPerLine", 0);
 user_pref("font.size.inflation.minTwips", 0);
 
 // Only load extensions from the application and user profile
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -472,18 +472,20 @@ NSPR_CFLAGS	= @NSPR_CFLAGS@
 NSPR_LIBS	= @NSPR_LIBS@
 
 NSS_CONFIG	= @NSS_CONFIG@
 NSS_CFLAGS	= @NSS_CFLAGS@
 NSS_LIBS	= @NSS_LIBS@
 NSS_DEP_LIBS	= @NSS_DEP_LIBS@
 NSS_DISABLE_DBM = @NSS_DISABLE_DBM@
 
-XPCOM_GLUE_LDOPTS = @XPCOM_GLUE_LDOPTS@
-XPCOM_STANDALONE_GLUE_LDOPTS = @XPCOM_STANDALONE_GLUE_LDOPTS@
+XPCOM_GLUE_LDOPTS	= @XPCOM_GLUE_LDOPTS@
+XPCOM_STANDALONE_GLUE_LDOPTS	= @XPCOM_STANDALONE_GLUE_LDOPTS@
+XPCOM_STATICRUNTIME_GLUE_LDOPTS	= @XPCOM_STATICRUNTIME_GLUE_LDOPTS@
+XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS	= @XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS@
 
 USE_DEPENDENT_LIBS = @USE_DEPENDENT_LIBS@
 
 # UNIX98 iconv support
 LIBICONV = @LIBICONV@
 
 # MKSHLIB_FORCE_ALL is used to force the linker to include all object
 # files present in an archive. MKSHLIB_UNFORCE_ALL reverts the linker
--- a/config/nsinstall.py
+++ b/config/nsinstall.py
@@ -29,16 +29,18 @@ def nsinstall(argv):
   p.add_option('-d', action="store_true",
                help="Create directories in target")
   p.add_option('-R', action="store_true",
                help="Use relative symbolic links (ignored)")
   p.add_option('-l', action="store_true",
                help="Create link (ignored)")
   p.add_option('-L', action="store", metavar="linkprefix",
                help="Link prefix (ignored)")
+  p.add_option('-X', action="append", metavar="file",
+               help="Ignore a file when installing a directory recursively.")
 
   # The remaining arguments are not used in our tree, thus they're not
   # implented.
   def BadArg(option, opt, value, parser):
     parser.error('option not supported: %s' % opt)
     
   p.add_option('-C', action="callback", metavar="CWD",
                callback=BadArg,
@@ -70,22 +72,28 @@ def nsinstall(argv):
         os.chmod(args[0], options.m)
       sys.exit()
     if options.m:
       os.makedirs(args[0], options.m)
     else:
       os.makedirs(args[0])
     return 0
 
+  if options.X:
+    options.X = [os.path.abspath(p) for p in options.X]
+
   # nsinstall arg1 [...] directory
   if len(args) < 2:
     p.error('not enough arguments')
 
   def copy_all_entries(entries, target):
     for e in entries:
+      if options.X and os.path.abspath(e) in options.X:
+        continue
+
       dest = os.path.join(target,
                           os.path.basename(os.path.normpath(e)))
       handleTarget(e, dest)
       if options.m:
         os.chmod(dest, options.m)
 
   # set up handler
   if options.d:
--- a/config/system-headers
+++ b/config/system-headers
@@ -16,18 +16,16 @@ afxpriv.h
 afxtempl.h
 afxwin.h
 algorithm
 Aliases.h
 all.h
 alloca.h
 alloc.h
 alsa/asoundlib.h
-alsa/pcm.h
-alsa/mixer.h
 android/log.h
 ansi_parms.h
 a.out.h
 app/Cursor.h
 Appearance.h
 AppFileInfo.h
 AppKit.h
 AppleEvents.h
--- a/config/tests/unit-nsinstall.py
+++ b/config/tests/unit-nsinstall.py
@@ -42,21 +42,35 @@ class TestNsinstall(unittest.TestCase):
         testdir = self.mkdirs("testdir")
         self.assertEqual(nsinstall([testfile, testdir]), 0)
         self.assert_(os.path.isfile(os.path.join(testdir, "testfile")))
 
     def test_nsinstall_basic_recursive(self):
         "Test nsinstall <dir> <dest dir>"
         sourcedir = self.mkdirs("sourcedir")
         self.touch("testfile", sourcedir)
+        Xfile = self.touch("Xfile", sourcedir)
+        copieddir = self.mkdirs("sourcedir/copieddir")
+        self.touch("testfile2", copieddir)
+        Xdir = self.mkdirs("sourcedir/Xdir")
+        self.touch("testfile3", Xdir)
+
         destdir = self.mkdirs("destdir")
-        self.assertEqual(nsinstall([sourcedir, destdir]), 0)
+
+        self.assertEqual(nsinstall([sourcedir, destdir,
+                                    '-X', Xfile,
+                                    '-X', Xdir]), 0)
+
         testdir = os.path.join(destdir, "sourcedir")
         self.assert_(os.path.isdir(testdir))
         self.assert_(os.path.isfile(os.path.join(testdir, "testfile")))
+        self.assert_(not os.path.exists(os.path.join(testdir, "Xfile")))
+        self.assert_(os.path.isdir(os.path.join(testdir, "copieddir")))
+        self.assert_(os.path.isfile(os.path.join(testdir, "copieddir", "testfile2")))
+        self.assert_(not os.path.exists(os.path.join(testdir, "Xdir")))
 
     def test_nsinstall_multiple(self):
         "Test nsinstall <three files> <dest dir>"
         testfiles = [self.touch("testfile1"),
                      self.touch("testfile2"),
                      self.touch("testfile3")]
         testdir = self.mkdirs("testdir")
         self.assertEqual(nsinstall(testfiles + [testdir]), 0)
--- a/configure.in
+++ b/configure.in
@@ -1303,16 +1303,28 @@ MOZ_JS_STATIC_LIBS='$(call EXPAND_LIBNAM
 MOZ_JS_SHARED_LIBS='$(call EXPAND_LIBNAME_PATH,mozjs,$(LIBXUL_DIST)/lib)'
 DYNAMIC_XPCOM_LIBS='-L$(LIBXUL_DIST)/bin -lxpcom -lxpcom_core -lmozalloc'
 MOZ_FIX_LINK_PATHS='-Wl,-rpath-link,$(LIBXUL_DIST)/bin -Wl,-rpath-link,$(prefix)/lib'
 XPCOM_FROZEN_LDOPTS='-L$(LIBXUL_DIST)/bin -lxpcom -lmozalloc'
 LIBXUL_LIBS='$(XPCOM_FROZEN_LDOPTS) -lxul'
 XPCOM_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) $(XPCOM_FROZEN_LDOPTS)'
 XPCOM_STANDALONE_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX)'
 
+# These are specially defined on Windows only
+case "$target" in
+*-mingw*)
+  XPCOM_STATICRUNTIME_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_staticruntime_s.$(LIB_SUFFIX) $(XPCOM_FROZEN_LDOPTS)'
+  XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_staticruntime.$(LIB_SUFFIX)'
+  ;;
+*)
+  XPCOM_STATICRUNTIME_GLUE_LDOPTS=$XPCOM_GLUE_LDOPTS
+  XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS=$XPCOM_STANDALONE_GLUE_LDOPTS
+  ;;
+esac
+
 MOZ_FS_LAYOUT=unix
 
 MOZ_COMPONENT_NSPR_LIBS='-L$(LIBXUL_DIST)/bin $(NSPR_LIBS)'
 
 USE_DEPENDENT_LIBS=1
 
 _PLATFORM_DEFAULT_TOOLKIT=cairo-gtk2
 
@@ -5738,16 +5750,22 @@ if test -n "$MOZ_SYDNEYAUDIO"; then
 fi
 
 if test -n "$MOZ_SPEEX_RESAMPLER"; then
     AC_DEFINE(MOZ_SPEEX_RESAMPLER)
 fi
 
 if test -n "$MOZ_CUBEB"; then
     case "$target" in
+    *-android*|*-linuxandroid*)
+        dnl No Android implementation of libcubeb yet.
+        ;;
+    *-linux*)
+        AC_DEFINE(MOZ_CUBEB)
+        ;;
     *-mingw*)
         AC_DEFINE(MOZ_CUBEB)
         ;;
     *)
         dnl Other targets will be enabled soon.
         ;;
     esac
 fi
@@ -8419,16 +8437,18 @@ AC_SUBST(INCREMENTAL_LINKER)
 AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
 AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
 
 AC_SUBST(MOZ_FIX_LINK_PATHS)
 AC_SUBST(XPCOM_LIBS)
 AC_SUBST(XPCOM_FROZEN_LDOPTS)
 AC_SUBST(XPCOM_GLUE_LDOPTS)
 AC_SUBST(XPCOM_STANDALONE_GLUE_LDOPTS)
+AC_SUBST(XPCOM_STATICRUNTIME_GLUE_LDOPTS)
+AC_SUBST(XPCOM_STANDALONE_STATICRUNTIME_GLUE_LDOPTS)
 
 AC_SUBST(USE_DEPENDENT_LIBS)
 
 AC_SUBST(MOZ_BUILD_ROOT)
 AC_SUBST(MOZ_OS2_TOOLS)
 
 AC_SUBST(MOZ_POST_DSO_LIB_COMMAND)
 AC_SUBST(MOZ_POST_PROGRAM_COMMAND)
@@ -8835,21 +8855,21 @@ HAVE_WCRTOMB
 AC_CONFIG_HEADER(
 netwerk/necko-config.h
 xpcom/xpcom-config.h
 xpcom/xpcom-private.h
 )
 
 # Hack around an Apple bug that effects the egrep that comes with OS X 10.7.
 # "arch -arch i386 egrep" always uses the 32-bit Intel part of the egrep fat
-# binary, even on 64-bit systems.  It should work on OS X 10.4.5 and up.  We
-# (apparently) only need this hack when egrep's "pattern" is particularly
-# long (as in the following code).  See bug 655339.
+# binary, even on 64-bit systems. We (apparently) only need this hack when
+# egrep's "pattern" is particularly long (as in the following code).
+# See bug 655339.
 case "$host" in
-*-apple-darwin*)
+*-apple-darwin11*)
     FIXED_EGREP="arch -arch i386 egrep"
     ;;
 *)
     FIXED_EGREP="egrep"
     ;;
 esac
 
 # Save the defines header file before autoconf removes it.
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -588,16 +588,19 @@ public:
   static bool IsSitePermAllow(nsIPrincipal* aPrincipal, const char* aType);
 
   // Get a permission-manager setting for the given principal and type.
   // If the pref doesn't exist or if it isn't DENY_ACTION, false is
   // returned, otherwise true is returned. Always returns false for the
   // system principal, and true for a null principal.
   static bool IsSitePermDeny(nsIPrincipal* aPrincipal, const char* aType);
 
+  // Returns true if aDoc1 and aDoc2 have equal NodePrincipal()s.
+  static bool HaveEqualPrincipals(nsIDocument* aDoc1, nsIDocument* aDoc2);
+
   static nsILineBreaker* LineBreaker()
   {
     return sLineBreaker;
   }
 
   static nsIWordBreaker* WordBreaker()
   {
     return sWordBreaker;
--- a/content/base/public/nsDOMFile.h
+++ b/content/base/public/nsDOMFile.h
@@ -178,16 +178,17 @@ public:
                         JSContext* aCx,
                         JSObject* aObj,
                         PRUint32 aArgc,
                         jsval* aArgv);
 
   // Overrides
   NS_IMETHOD GetSize(PRUint64* aSize);
   NS_IMETHOD GetType(nsAString& aType);
+  NS_IMETHOD GetLastModifiedDate(JSContext* cx, JS::Value *aLastModifiedDate);
   NS_IMETHOD GetMozFullPathInternal(nsAString& aFullPath);
   NS_IMETHOD GetInternalStream(nsIInputStream**);
 
   // DOMClassInfo constructor (for File("foo"))
   static nsresult
   NewFile(nsISupports* *aNewObject);
 
 protected:
--- a/content/base/public/nsIDOMFile.idl
+++ b/content/base/public/nsIDOMFile.idl
@@ -51,20 +51,24 @@ interface nsIDOMBlob : nsISupports
   // the blob is initialized from a database. It can be called on any thread.
   [notxpcom] void addFileInfo(in FileInfo aFileInfo);
 
   // Called before the blob is stored in a database to decide if it can be
   // shared or needs to be copied. It can be called on any thread.
   [notxpcom] FileInfo getFileInfo(in FileManager aFileManager);
 };
 
-[scriptable, builtinclass, uuid(b096ef67-7b77-47f8-8e70-5d8ee36416bf)]
+[scriptable, builtinclass, uuid(eee028d1-8ce9-4c6c-b9ce-d89b656e1e17)]
 interface nsIDOMFile : nsIDOMBlob
 {
   readonly attribute DOMString name;
+
+  [implicit_jscontext]
+  readonly attribute jsval lastModifiedDate;
+
   readonly attribute DOMString mozFullPath;
 
   // This performs no security checks!
   [noscript] readonly attribute DOMString mozFullPathInternal;
 };
 
 [scriptable, builtinclass, uuid(57195950-edd9-496b-9b45-e4893a9ffca9)]
 interface nsIDOMMozBlobBuilder : nsISupports
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -87,19 +87,18 @@ class Loader;
 
 namespace dom {
 class Link;
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 #define NS_IDOCUMENT_IID \
-{ 0x8e51e6d9, 0x914d, 0x46ba, \
-  { 0xb3, 0x11, 0x2f, 0x27, 0x3d, 0xe6, 0x0d, 0x19 } }
-
+{ 0x88d887da, 0xd228, 0x41c2, \
+  { 0xb8, 0x0a, 0x42, 0xec, 0xf0, 0xcb, 0xce, 0x37 } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 // Enum for requesting a particular type of document when creating a doc
 enum DocumentFlavor {
   DocumentFlavorLegacyGuess, // compat with old code until made HTML5-compliant
   DocumentFlavorHTML, // HTMLDocument with HTMLness bit set to true
@@ -740,16 +739,24 @@ public:
   virtual void RestorePreviousFullScreenState() = 0;
 
   /**
    * Returns true if this document is in full-screen mode.
    */
   virtual bool IsFullScreenDoc() = 0;
 
   /**
+   * Sets whether this document is approved for fullscreen mode.
+   * Documents aren't approved for fullscreen until chrome has sent a
+   * "fullscreen-approved" notification with a subject which is a pointer
+   * to the approved document.
+   */
+  virtual void SetApprovedForFullscreen(bool aIsApproved) = 0;
+
+  /**
    * Exits all documents from DOM full-screen mode, and moves the top-level
    * browser window out of full-screen mode. If aRunAsync is true, this runs
    * asynchronously.
    */
   static void ExitFullScreen(bool aRunAsync);
 
 
   virtual void RequestPointerLock(Element* aElement) = 0;
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -411,29 +411,72 @@ nsContentSink::LinkContextIsOurDocument(
   if (NS_FAILED(rv)) {
     // comparison failed
     return false;
   }
 
   return same;
 }
 
+// Decode a parameter value using the encoding defined in RFC 5987 (in place)
+//
+//   charset  "'" [ language ] "'" value-chars
+//
+// returns true when decoding happened successfully (otherwise leaves
+// passed value alone)
+bool
+nsContentSink::Decode5987Format(nsAString& aEncoded) {
+
+  nsresult rv;
+  nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar =
+  do_GetService(NS_MIMEHEADERPARAM_CONTRACTID, &rv);
+  if (NS_FAILED(rv))
+    return false;
+
+  nsCAutoString asciiValue;
+
+  const PRUnichar* encstart = aEncoded.BeginReading();
+  const PRUnichar* encend = aEncoded.EndReading();
+
+  // create a plain ASCII string, aborting if we can't do that
+  // converted form is always shorter than input
+  while (encstart != encend) {
+    if (*encstart > 0 && *encstart < 128) {
+      asciiValue.Append((char)*encstart);
+    } else {
+      return false;
+    }
+    encstart++;
+  }
+
+  nsAutoString decoded;
+  nsCAutoString language;
+
+  rv = mimehdrpar->DecodeRFC5987Param(asciiValue, language, decoded);
+  if (NS_FAILED(rv))
+    return false;
+
+  aEncoded = decoded;
+  return true;
+}
+
 nsresult
 nsContentSink::ProcessLinkHeader(nsIContent* aElement,
                                  const nsAString& aLinkData)
 {
   nsresult rv = NS_OK;
 
   // keep track where we are within the header field
   bool seenParameters = false;
 
   // parse link content and call process style link
   nsAutoString href;
   nsAutoString rel;
   nsAutoString title;
+  nsAutoString titleStar;
   nsAutoString type;
   nsAutoString media;
   nsAutoString anchor;
 
   // copy to work buffer
   nsAutoString stringList(aLinkData);
 
   // put an extra null at the end
@@ -448,38 +491,38 @@ nsContentSink::ProcessLinkHeader(nsICont
     // skip leading space
     while ((*start != kNullCh) && nsCRT::IsAsciiSpace(*start)) {
       ++start;
     }
 
     end = start;
     last = end - 1;
 
-    bool needsUnescape = false;
+    bool wasQuotedString = false;
     
     // look for semicolon or comma
     while (*end != kNullCh && *end != kSemicolon && *end != kComma) {
       PRUnichar ch = *end;
 
       if (ch == kQuote || ch == kLessThan) {
         // quoted string
 
         PRUnichar quote = ch;
         if (quote == kLessThan) {
           quote = kGreaterThan;
         }
         
-        needsUnescape = (ch == kQuote);
+        wasQuotedString = (ch == kQuote);
         
         PRUnichar* closeQuote = (end + 1);
 
         // seek closing quote
         while (*closeQuote != kNullCh && quote != *closeQuote) {
           // in quoted-string, "\" is an escape character
-          if (needsUnescape && *closeQuote == kBackSlash && *(closeQuote + 1) != kNullCh) {
+          if (wasQuotedString && *closeQuote == kBackSlash && *(closeQuote + 1) != kNullCh) {
             ++closeQuote;
           }
 
           ++closeQuote;
         }
 
         if (quote == *closeQuote) {
           // found closer
@@ -544,17 +587,17 @@ nsContentSink::ProcessLinkHeader(nsICont
             value++;
           }
 
           if ((*value == kQuote) && (*value == *last)) {
             *last = kNullCh;
             value++;
           }
 
-          if (needsUnescape) {
+          if (wasQuotedString) {
             // unescape in-place
             PRUnichar* unescaped = value;
             PRUnichar *src = value;
             
             while (*src != kNullCh) {
               if (*src == kBackSlash && *(src + 1) != kNullCh) {
                 src++;
               }
@@ -569,16 +612,30 @@ nsContentSink::ProcessLinkHeader(nsICont
               rel = value;
               rel.CompressWhitespace();
             }
           } else if (attr.LowerCaseEqualsLiteral("title")) {
             if (title.IsEmpty()) {
               title = value;
               title.CompressWhitespace();
             }
+          } else if (attr.LowerCaseEqualsLiteral("title*")) {
+            if (titleStar.IsEmpty() && !wasQuotedString) {
+              // RFC 5987 encoding; uses token format only, so skip if we get
+              // here with a quoted-string
+              nsAutoString tmp;
+              tmp = value;
+              if (Decode5987Format(tmp)) {
+                titleStar = tmp;
+                titleStar.CompressWhitespace();
+              } else {
+                // header value did not parse, throw it away
+                titleStar.Truncate();
+              }
+            }
           } else if (attr.LowerCaseEqualsLiteral("type")) {
             if (type.IsEmpty()) {
               type = value;
               type.StripWhitespace();
             }
           } else if (attr.LowerCaseEqualsLiteral("media")) {
             if (media.IsEmpty()) {
               media = value;
@@ -597,17 +654,20 @@ nsContentSink::ProcessLinkHeader(nsICont
       }
     }
 
     if (endCh == kComma) {
       // hit a comma, process what we've got so far
 
       href.Trim(" \t\n\r\f"); // trim HTML5 whitespace
       if (!href.IsEmpty() && !rel.IsEmpty()) {
-        rv = ProcessLink(aElement, anchor, href, rel, title, type, media);
+        rv = ProcessLink(aElement, anchor, href, rel,
+                         // prefer RFC 5987 variant over non-I18zed version
+                         titleStar.IsEmpty() ? title : titleStar,
+                         type, media);
       }
 
       href.Truncate();
       rel.Truncate();
       title.Truncate();
       type.Truncate();
       media.Truncate();
       anchor.Truncate();
@@ -615,17 +675,20 @@ nsContentSink::ProcessLinkHeader(nsICont
       seenParameters = false;
     }
 
     start = ++end;
   }
                 
   href.Trim(" \t\n\r\f"); // trim HTML5 whitespace
   if (!href.IsEmpty() && !rel.IsEmpty()) {
-    rv = ProcessLink(aElement, anchor, href, rel, title, type, media);
+    rv = ProcessLink(aElement, anchor, href, rel,
+                     // prefer RFC 5987 variant over non-I18zed version
+                     titleStar.IsEmpty() ? title : titleStar,
+                     type, media);
   }
 
   return rv;
 }
 
 
 nsresult
 nsContentSink::ProcessLink(nsIContent* aElement,
--- a/content/base/src/nsContentSink.h
+++ b/content/base/src/nsContentSink.h
@@ -112,16 +112,17 @@ class nsContentSink : public nsICSSLoade
   // nsIDocumentObserver
   NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE
   NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE
 
   virtual void UpdateChildCounts() = 0;
 
   bool IsTimeToNotify();
   bool LinkContextIsOurDocument(const nsSubstring& aAnchor);
+  bool Decode5987Format(nsAString& aEncoded);
 
   static void InitializeStatics();
 
 protected:
   nsContentSink();
   virtual ~nsContentSink();
 
   enum CacheSelectionAction {
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -6486,16 +6486,28 @@ nsContentUtils::IsFullScreenApiEnabled()
 bool
 nsContentUtils::IsRequestFullScreenAllowed()
 {
   return !sTrustedFullScreenOnly ||
          nsEventStateManager::IsHandlingUserInput() ||
          IsCallerChrome();
 }
 
+/* static */
+bool
+nsContentUtils::HaveEqualPrincipals(nsIDocument* aDoc1, nsIDocument* aDoc2)
+{
+  if (!aDoc1 || !aDoc2) {
+    return false;
+  }
+  bool principalsEqual = false;
+  aDoc1->NodePrincipal()->Equals(aDoc2->NodePrincipal(), &principalsEqual);
+  return principalsEqual;
+}
+
 static void
 CheckForWindowedPlugins(nsIContent* aContent, void* aResult)
 {
   if (!aContent->IsInDoc()) {
     return;
   }
   nsCOMPtr<nsIObjectLoadingContent> olc(do_QueryInterface(aContent));
   if (!olc) {
--- a/content/base/src/nsDOMFile.cpp
+++ b/content/base/src/nsDOMFile.cpp
@@ -124,16 +124,23 @@ NS_IMETHODIMP
 nsDOMFileBase::GetName(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
   aFileName = mName;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDOMFileBase::GetLastModifiedDate(JSContext* cx, JS::Value *aLastModifiedDate)
+{
+  aLastModifiedDate->setNull();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDOMFileBase::GetMozFullPath(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
 
   // It is unsafe to call CallerHasUniversalXPConnect on a non-main thread. If
   // you hit the following assertion you need to figure out some other way to
   // determine privileges and call GetMozFullPathInternal.
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@@ -413,16 +420,32 @@ nsDOMFileFile::NewFile(nsISupports* *aNe
 NS_IMETHODIMP
 nsDOMFileFile::GetMozFullPathInternal(nsAString &aFilename)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
   return mFile->GetPath(aFilename);
 }
 
 NS_IMETHODIMP
+nsDOMFileFile::GetLastModifiedDate(JSContext* cx, JS::Value *aLastModifiedDate)
+{
+  PRInt64 msecs;
+  mFile->GetLastModifiedTime(&msecs);
+  JSObject* date = JS_NewDateObjectMsec(cx, msecs);
+  if (date) {
+    aLastModifiedDate->setObject(*date);
+  }
+  else {
+    aLastModifiedDate->setNull();
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDOMFileFile::GetSize(PRUint64 *aFileSize)
 {
   if (IsSizeUnknown()) {
     NS_ASSERTION(mWholeFile,
                  "Should only use lazy size when using the whole file");
     PRInt64 fileSize;
     nsresult rv = mFile->GetFileSize(&fileSize);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -7386,17 +7386,17 @@ nsDocument::OnPageHide(bool aPersisted,
     // A full-screen doc has been hidden. We need to ensure we exit
     // full-screen, i.e. remove full-screen state from all full-screen
     // documents, and exit the top-level window from full-screen mode.
     // By the time a doc is hidden, it has been removed from the doc tree,
     // so nsIDocument::ExitFullScreen() won't be able to traverse to this
     // document to reset its state, so reset full-screen state in *this*
     // document. OnPageHide() is called in every hidden document, so doing
     // this ensures all hidden documents have their full-screen state reset.
-    ClearFullScreenStack();
+    CleanupFullscreenState();
 
     // Next reset full-screen state in all visible documents in the doctree.
     nsIDocument::ExitFullScreen(false);
   }
 }
 
 void
 nsDocument::WillDispatchMutationEvent(nsINode* aTarget)
@@ -8576,17 +8576,17 @@ nsIDocument::ExitFullScreen(bool aRunAsy
     return;
   }
   nsDocument::ExitFullScreen();
 }
 
 static bool
 ResetFullScreen(nsIDocument* aDocument, void* aData) {
   if (aDocument->IsFullScreenDoc()) {
-    static_cast<nsDocument*>(aDocument)->ClearFullScreenStack();
+    static_cast<nsDocument*>(aDocument)->CleanupFullscreenState();
     NS_ASSERTION(!aDocument->IsFullScreenDoc(), "Should reset full-screen");
     nsTArray<nsIDocument*>* changed = reinterpret_cast<nsTArray<nsIDocument*>*>(aData);
     changed->AppendElement(aDocument);
     aDocument->EnumerateSubDocuments(ResetFullScreen, aData);
   }
   return true;
 }
 
@@ -8654,42 +8654,45 @@ nsDocument::RestorePreviousFullScreenSta
     UnlockPointer();
   }
 
   // Clear full-screen stacks in all descendant documents, bottom up.
   nsCOMPtr<nsIDocument> fullScreenDoc(do_QueryReferent(sFullScreenDoc));
   nsIDocument* doc = fullScreenDoc;
   while (doc != this) {
     NS_ASSERTION(doc->IsFullScreenDoc(), "Should be full-screen doc");
-    static_cast<nsDocument*>(doc)->ClearFullScreenStack();
+    static_cast<nsDocument*>(doc)->CleanupFullscreenState();
     UnlockPointer();
     DispatchFullScreenChange(doc);
     doc = doc->GetParentDocument();
   }
 
   // Roll-back full-screen state to previous full-screen element.
   NS_ASSERTION(doc == this, "Must have reached this doc.");
   while (doc != nsnull) {
     static_cast<nsDocument*>(doc)->FullScreenStackPop();
     UnlockPointer();
     DispatchFullScreenChange(doc);
     if (static_cast<nsDocument*>(doc)->mFullScreenStack.IsEmpty()) {
       // Full-screen stack in document is empty. Go back up to the parent
       // document. We'll pop the containing element off its stack, and use
       // its next full-screen element as the full-screen element.
+      static_cast<nsDocument*>(doc)->CleanupFullscreenState();
       doc = doc->GetParentDocument();
     } else {
       // Else we popped the top of the stack, and there's still another
       // element in there, so that will become the full-screen element.
       if (fullScreenDoc != doc) {
         // We've popped so enough off the stack that we've rolled back to
         // a fullscreen element in a parent document. If this document isn't
-        // authorized for fullscreen, dispatch an event to chrome so it
-        // knows to show the authorization UI.
-        if (!nsContentUtils::IsSitePermAllow(doc->NodePrincipal(), "fullscreen")) {
+        // approved for fullscreen, or if it's cross origin, dispatch an
+        // event to chrome so it knows to show the authorization/warning UI.
+        if (!nsContentUtils::HaveEqualPrincipals(fullScreenDoc, doc) ||
+            (!nsContentUtils::IsSitePermAllow(doc->NodePrincipal(), "fullscreen") &&
+             !static_cast<nsDocument*>(doc)->mIsApprovedForFullscreen)) {
           nsRefPtr<nsAsyncDOMEvent> e =
             new nsAsyncDOMEvent(doc,
                                 NS_LITERAL_STRING("MozEnteredDomFullscreen"),
                                 true,
                                 true);
           e->PostDOMEvent();
         }
       }
@@ -8763,31 +8766,56 @@ LogFullScreenDenied(bool aLogFailure, co
                         false);
   e->PostDOMEvent();
   nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                   "DOM", aDoc,
                                   nsContentUtils::eDOM_PROPERTIES,
                                   aMessage);
 }
 
-void
-nsDocument::ClearFullScreenStack()
-{
-  if (mFullScreenStack.IsEmpty()) {
-    return;
-  }
-  // The top element in the full-screen stack will have full-screen
-  // style bits set on it and its ancestors. Remove the style bits.
-  // Note the non-top elements won't have the style bits set.
-  Element* top = FullScreenStackTop();
-  NS_ASSERTION(top, "Should have a top when full-screen stack isn't empty");
-  if (top) {
-    nsEventStateManager::SetFullScreenState(top, false);
-  }
-  mFullScreenStack.Clear();
+nsresult
+nsDocument::AddFullscreenApprovedObserver()
+{
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
+
+  nsresult res = os->AddObserver(this, "fullscreen-approved", true);
+  NS_ENSURE_SUCCESS(res, res);
+
+  return NS_OK;
+}
+
+nsresult
+nsDocument::RemoveFullscreenApprovedObserver()
+{
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
+
+  nsresult res = os->RemoveObserver(this, "fullscreen-approved");
+  NS_ENSURE_SUCCESS(res, res);
+
+  return NS_OK;
+}
+
+void
+nsDocument::CleanupFullscreenState()
+{
+  if (!mFullScreenStack.IsEmpty()) {
+    // The top element in the full-screen stack will have full-screen
+    // style bits set on it and its ancestors. Remove the style bits.
+    // Note the non-top elements won't have the style bits set.
+    Element* top = FullScreenStackTop();
+    NS_ASSERTION(top, "Should have a top when full-screen stack isn't empty");
+    if (top) {
+      nsEventStateManager::SetFullScreenState(top, false);
+    }
+    mFullScreenStack.Clear();
+  }
+  SetApprovedForFullscreen(false);
+  RemoveFullscreenApprovedObserver();
 }
 
 bool
 nsDocument::FullScreenStackPush(Element* aElement)
 {
   NS_ASSERTION(aElement, "Must pass non-null to FullScreenStackPush()");
   Element* top = FullScreenStackTop();
   if (top == aElement || !aElement) {
@@ -8945,16 +8973,18 @@ nsDocument::RequestFullScreen(Element* a
   if (focusedElement) {
     nsCOMPtr<nsIContent> content = do_QueryInterface(focusedElement);
     if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(content)) {
       LogFullScreenDenied(true, "FullScreenDeniedFocusedPlugin", this);
       return;
     }
   }
 
+  AddFullscreenApprovedObserver();
+
   // Stores a list of documents which we must dispatch "mozfullscreenchange"
   // too. We're required by the spec to dispatch the events in root-to-leaf
   // order, but we traverse the doctree in a leaf-to-root order, so we save
   // references to the documents we must dispatch to so that we get the order
   // as specified.
   nsAutoTArray<nsIDocument*, 8> changed;
 
   // Remember the root document, so that if a full-screen document is hidden
@@ -9006,22 +9036,40 @@ nsDocument::RequestFullScreen(Element* a
 
   // Dispatch "mozfullscreenchange" events. Note this loop is in reverse
   // order so that the events for the root document arrives before the leaf
   // document, as required by the spec.
   for (PRUint32 i = 0; i < changed.Length(); ++i) {
     DispatchFullScreenChange(changed[changed.Length() - i - 1]);
   }
 
-  nsRefPtr<nsAsyncDOMEvent> e =
-    new nsAsyncDOMEvent(this,
-                        NS_LITERAL_STRING("MozEnteredDomFullscreen"),
-                        true,
-                        true);
-  e->PostDOMEvent();
+  // If this document hasn't already been approved in this session,
+  // check to see if the user has granted the fullscreen access
+  // to the document's principal's host, if it has one.
+  if (!mIsApprovedForFullscreen) {
+    mIsApprovedForFullscreen =
+      nsContentUtils::IsSitePermAllow(NodePrincipal(), "fullscreen");
+  }
+
+  // If this document, or a document with the same principal has not
+  // already been approved for fullscreen this fullscreen-session, dispatch
+  // an event so that chrome knows to pop up a warning/approval UI.
+  nsCOMPtr<nsIDocument> previousFullscreenDoc(do_QueryReferent(sFullScreenDoc));
+  // Note previousFullscreenDoc=nsnull upon first entry, so we always
+  // take this path on the first time we enter fullscreen in a fullscreen
+  // session.
+  if (!mIsApprovedForFullscreen ||
+      !nsContentUtils::HaveEqualPrincipals(previousFullscreenDoc, this)) {
+    nsRefPtr<nsAsyncDOMEvent> e =
+      new nsAsyncDOMEvent(this,
+                          NS_LITERAL_STRING("MozEnteredDomFullscreen"),
+                          true,
+                          true);
+    e->PostDOMEvent();
+  }
 
   // Remember this is the requesting full-screen document.
   sFullScreenDoc = do_GetWeakReference(static_cast<nsIDocument*>(this));
 
 #ifdef DEBUG
   // Note assertions must run before SetWindowFullScreen() as that does
   // synchronous event dispatch which can run script which exits full-screen!
   NS_ASSERTION(GetFullScreenElement() == aElement,
@@ -9241,29 +9289,16 @@ nsDocument::ClearPendingPointerLockReque
 {
   nsAsyncPointerLockRequest::Cancel();
 
   if (!sPendingPointerLockDoc) {
     // No pending request.
     return;
   }
   nsCOMPtr<nsIDocument> doc(do_QueryReferent(sPendingPointerLockDoc));
-  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-  if (!os) {
-    NS_WARNING("Lost observer service in ClearPendingPointerLockRequest()!");
-    return;
-  }
-
-  nsCOMPtr<nsIObserver> obs(do_QueryInterface(doc));
-  if (!os) {
-    NS_WARNING("Document must implement nsIObserver");
-    return;
-  }
-  os->RemoveObserver(obs, "perm-changed");
-
   if (aDispatchErrorEvents) {
     DispatchPointerLockError(doc);
   }
   nsCOMPtr<Element> element(do_QueryReferent(sPendingPointerLockElement));
 #ifdef DEBUG
   nsCOMPtr<Element> pointerLockedElement =
     do_QueryReferent(nsEventStateManager::sPointerLockedElement);
   NS_ASSERTION(pointerLockedElement != element,
@@ -9280,46 +9315,50 @@ nsDocument::ClearPendingPointerLockReque
 nsresult
 nsDocument::SetPendingPointerLockRequest(Element* aElement)
 {
   // If there's an existing pending pointer lock request, deny it.
   ClearPendingPointerLockRequest(true);
 
   NS_ENSURE_TRUE(aElement != nsnull, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-  NS_ENSURE_TRUE(os != nsnull, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIObserver> obs(do_QueryInterface(aElement->OwnerDoc()));
-  NS_ENSURE_TRUE(obs != nsnull, NS_ERROR_FAILURE);
-
-  nsresult res = os->AddObserver(obs, "perm-changed", true);
-  NS_ENSURE_SUCCESS(res, res);
-
   sPendingPointerLockDoc = do_GetWeakReference(aElement->OwnerDoc());
   sPendingPointerLockElement = do_GetWeakReference(aElement);
 
   // Set the pointer lock flag, so that if the element is removed from
   // its document we know to cancel the pending request.
   aElement->SetPointerLock();
 
   return NS_OK;
 }
 
+void
+nsDocument::SetApprovedForFullscreen(bool aIsApproved)
+{
+  mIsApprovedForFullscreen = aIsApproved;
+}
+
 nsresult
 nsDocument::Observe(nsISupports *aSubject,
                     const char *aTopic,
                     const PRUnichar *aData)
 {
-  if (strcmp("perm-changed", aTopic) == 0) {
+  if (strcmp("fullscreen-approved", aTopic) == 0) {
+    nsCOMPtr<nsIDocument> subject(do_QueryInterface(aSubject));
+    if (subject != this) {
+      return NS_OK;
+    }
+    SetApprovedForFullscreen(true);
     nsCOMPtr<nsIDocument> doc(do_QueryReferent(sPendingPointerLockDoc));
-    if (nsContentUtils::IsSitePermAllow(doc->NodePrincipal(), "fullscreen")) {
+    if (this == doc) {
+      // This doc has a pointer lock request, waiting for fullscreen to be
+      // approved before it can be granted. Process the pointer lock request.
       nsCOMPtr<Element> element(do_QueryReferent(sPendingPointerLockElement));
       nsDocument::ClearPendingPointerLockRequest(false);
-      nsAsyncPointerLockRequest::Request(element, doc);
+      nsAsyncPointerLockRequest::Request(element, this);
     }
   }
   return NS_OK;
 }
 
 void
 nsDocument::RequestPointerLock(Element* aElement)
 {
@@ -9332,19 +9371,19 @@ nsDocument::RequestPointerLock(Element* 
     DispatchPointerLockChange(this);
     return;
   }
 
   if (!ShouldLockPointer(aElement)) {
     DispatchPointerLockError(this);
     return;
   }
-    
-  if (!nsContentUtils::IsSitePermAllow(NodePrincipal(), "fullscreen")) {
-    // Domain isn't yet approved for fullscreen, so we must wait until
+
+  if (!mIsApprovedForFullscreen) {
+    // Document isn't yet approved for fullscreen, so we must wait until
     // it's been approved.
     if (NS_FAILED(SetPendingPointerLockRequest(aElement))) {
       NS_WARNING("Failed to make pointer lock request pending!");
       DispatchPointerLockError(this);
     }
     return;
   }
 
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -924,27 +924,36 @@ public:
   {
     return mHasAudioAvailableListener;
   }
 
   virtual Element* GetFullScreenElement();
   virtual void AsyncRequestFullScreen(Element* aElement);
   virtual void RestorePreviousFullScreenState();
   virtual bool IsFullScreenDoc();
+  virtual void SetApprovedForFullscreen(bool aIsApproved);
+
   static void ExitFullScreen();
 
   // This is called asynchronously by nsIDocument::AsyncRequestFullScreen()
   // to move document into full-screen mode if allowed. aWasCallerChrome
   // should be true when nsIDocument::AsyncRequestFullScreen() was called
   // by chrome code.
   void RequestFullScreen(Element* aElement, bool aWasCallerChrome);
 
   // Removes all elements from the full-screen stack, removing full-scren
   // styles from the top element in the stack.
-  void ClearFullScreenStack();
+  void CleanupFullscreenState();
+
+  // Add/remove "fullscreen-approved" observer service notification listener.
+  // Chrome sends us a notification when fullscreen is approved for a
+  // document, with the notification subject as the document that was approved.
+  // We maintain this listener while in fullscreen mode.
+  nsresult AddFullscreenApprovedObserver();
+  nsresult RemoveFullscreenApprovedObserver();
 
   // Pushes aElement onto the full-screen stack, and removes full-screen styles
   // from the former full-screen stack top, and its ancestors, and applies the
   // styles to aElement. aElement becomes the new "full-screen element".
   bool FullScreenStackPush(Element* aElement);
 
   // Remove the top element from the full-screen stack. Removes the full-screen
   // styles from the former top element, and applies them to the new top
@@ -1175,16 +1184,31 @@ protected:
   // Whether we're currently under a FlushPendingNotifications call to
   // our presshell.  This is used to handle flush reentry correctly.
   bool mInFlush:1;
 
   // Parser aborted. True if the parser of this document was forcibly
   // terminated instead of letting it finish at its own pace.
   bool mParserAborted:1;
 
+  // Whether this document has been approved for fullscreen, either by explicit
+  // approval via the fullscreen-approval UI, or because it received
+  // approval because its document's host already had the "fullscreen"
+  // permission granted when the document requested fullscreen.
+  // 
+  // Note if a document's principal doesn't have a host, the permission manager
+  // can't store permissions for it, so we can only manage approval using this
+  // flag.
+  //
+  // Note we must track this separately from the "fullscreen" permission,
+  // so that pending pointer lock requests can determine whether documents
+  // whose principal doesn't have a host (i.e. those which can't store
+  // permissions in the permission manager) have been approved for fullscreen.
+  bool mIsApprovedForFullscreen:1;
+
   PRUint8 mXMLDeclarationBits;
 
   nsInterfaceHashtable<nsPtrHashKey<nsIContent>, nsPIBoxObject> *mBoxObjectTable;
 
   // The channel that got passed to StartDocumentLoad(), if any
   nsCOMPtr<nsIChannel> mChannel;
   nsRefPtr<nsHTMLCSSStyleSheet> mStyleAttrStyleSheet;
   nsRefPtr<nsXMLEventsManager> mXMLEventsManager;
--- a/content/base/test/test_bug403852.html
+++ b/content/base/test/test_bug403852.html
@@ -29,11 +29,16 @@ testFile.append("prefs.js");
 var fileList = document.getElementById('fileList');
 fileList.value = testFile.path;
 
 // Make sure the file is accessible with indexed notation
 var domFile = fileList.files[0];
 
 is(domFile.name, "prefs.js", "fileName should be prefs.js");
 
+ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
+
+var d = new Date(testFile.lastModifiedTime);
+ok(d.getTime() == domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same.");
+
 </script>
 </pre>
 </body> </html>
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -2517,18 +2517,17 @@ GetScrollableLineHeight(nsIFrame* aTarge
     nsIScrollableFrame* sf = f->GetScrollTargetFrame();
     if (sf)
       return sf->GetLineScrollAmount().height;
   }
 
   // Fall back to the font height of the target frame.
   nsRefPtr<nsFontMetrics> fm;
   nsLayoutUtils::GetFontMetricsForFrame(aTargetFrame, getter_AddRefs(fm),
-    nsLayoutUtils::FontSizeInflationFor(aTargetFrame,
-                                        nsLayoutUtils::eNotInReflow));
+    nsLayoutUtils::FontSizeInflationFor(aTargetFrame));
   NS_ASSERTION(fm, "FontMetrics is null!");
   if (fm)
     return fm->MaxHeight();
   return 0;
 }
 
 void
 nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
--- a/content/svg/content/src/SVGFragmentIdentifier.cpp
+++ b/content/svg/content/src/SVGFragmentIdentifier.cpp
@@ -6,22 +6,16 @@
 #include "SVGFragmentIdentifier.h"
 #include "mozilla/CharTokenizer.h"
 #include "nsIDOMSVGDocument.h"
 #include "nsSVGSVGElement.h"
 #include "nsSVGViewElement.h"
 
 using namespace mozilla;
 
-static nsSVGEnumMapping sZoomAndPanMap[] = {
-  {&nsGkAtoms::disable, nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_DISABLE},
-  {&nsGkAtoms::magnify, nsIDOMSVGZoomAndPan::SVG_ZOOMANDPAN_MAGNIFY},
-  {nsnull, 0}
-};
-
 static bool
 IsMatchingParameter(const nsAString &aString, const nsAString &aParameterName)
 {
   // The first two tests ensure aString.Length() > aParameterName.Length()
   // so it's then safe to do the third test
   return StringBeginsWith(aString, aParameterName) &&
          aString.Last() == ')' &&
          aString.CharAt(aParameterName.Length()) == '(';
@@ -143,33 +137,30 @@ SVGFragmentIdentifier::ProcessSVGViewSpe
       }
       zoomAndPanParams = &params;
     } else {
       // We don't support transform or viewTarget currently
       return false;
     }
   }
 
-  const nsSVGViewBoxRect *oldViewBoxPtr = root->GetViewBoxProperty();
   if (viewBoxParams) {
     SaveOldViewBox(root);
     root->mViewBox.SetBaseValueString(*viewBoxParams, root);
   } else {
     RestoreOldViewBox(root);
   }
 
-  const SVGPreserveAspectRatio *oldPARPtr = root->GetPreserveAspectRatioProperty();
   if (preserveAspectRatioParams) {
     SaveOldPreserveAspectRatio(root);
     root->mPreserveAspectRatio.SetBaseValueString(*preserveAspectRatioParams, root);
   } else {
     RestoreOldPreserveAspectRatio(root);
   }
 
-  const PRUint16 *oldZoomAndPanPtr = root->GetZoomAndPanProperty();
   if (zoomAndPanParams) {
     SaveOldZoomAndPan(root);
     nsCOMPtr<nsIAtom> valAtom = do_GetAtom(*zoomAndPanParams);
     const nsSVGEnumMapping *mapping = root->sZoomAndPanMap;
     while (mapping->mKey) {
       if (valAtom == *(mapping->mKey)) {
         root->mEnumAttributes[nsSVGSVGElement::ZOOMANDPAN].SetBaseValue(mapping->mVal, root);
         break;
--- a/dom/base/DOMRequestHelper.jsm
+++ b/dom/base/DOMRequestHelper.jsm
@@ -52,33 +52,46 @@ DOMRequestIpcHelper.prototype = {
   },
 
   observe: function(aSubject, aTopic, aData) {
     let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
     if (wId == this.innerWindowID) {
       Services.obs.removeObserver(this, "inner-window-destroyed");
       this._requests = [];
       this._window = null;
-      this._messages.forEach((function(msgName) {
-        cpmm.removeMessageListener(msgName, this);
-      }).bind(this));
+      this.removeMessageListener();
       if(this.uninit)
         this.uninit();
     }
   },
 
-  initHelper: function(aWindow, aMessages) {
+  initRequests: function initRequests() {
+    this._requests = [];
+  },
+
+  initMessageListener: function initMessageListener(aMessages) {
     this._messages = aMessages;
-    this._requests = [];
+    this._messages.forEach((function(msgName) {
+      cpmm.addMessageListener(msgName, this);
+    }).bind(this));
+  },
+  
+  initHelper: function(aWindow, aMessages) {
+    this.initMessageListener(aMessages);
+    this.initRequests();
+    this._id = this._getRandomId();
+    Services.obs.addObserver(this, "inner-window-destroyed", false);
     this._window = aWindow;
     let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
     this.innerWindowID = util.currentInnerWindowID;
-    this._id = this._getRandomId();
-    Services.obs.addObserver(this, "inner-window-destroyed", false);
+  },
+
+  removeMessageListener: function removeMessageListener() {
     this._messages.forEach((function(msgName) {
-      cpmm.addMessageListener(msgName, this);
-    }).bind(this));
+        cpmm.removeMessageListener(msgName, this);
+      }).bind(this));
+    this._messages = null;
   },
 
   createRequest: function() {
     return Services.DOMRequest.createRequest(this._window);
   }
 }
--- a/dom/network/interfaces/nsIDOMMobileConnection.idl
+++ b/dom/network/interfaces/nsIDOMMobileConnection.idl
@@ -3,17 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIDOMEventTarget.idl"
 
 interface nsIDOMEventListener;
 interface nsIDOMDOMRequest;
 interface nsIDOMMozMobileConnectionInfo;
 
-[scriptable, uuid(ba2be619-fed6-4652-865a-c61f88ffeaa8)]
+[scriptable, uuid(962298cd-3443-423e-9e47-f22e24ad850b)]
 interface nsIDOMMozMobileConnection : nsIDOMEventTarget
 {
   /**
    * Indicates the state of the device's ICC card.
    *
    * Possible values: null, 'absent', 'pinRequired', 'pukRequired',
    * 'networkLocked', 'ready'.
    */
@@ -49,16 +49,121 @@ interface nsIDOMMozMobileConnection : ns
   attribute nsIDOMEventListener onvoicechange;
 
   /**
    * The 'datachange' event is notified whenever the data connection object
    * changes values.
    */
   attribute nsIDOMEventListener ondatachange;
 
+  /**
+   * Find out about the status of an ICC lock (e.g. the PIN lock).
+   *
+   * @param lockType
+   *        Identifies the lock type, e.g. "pin" for the PIN lock.
+   *
+   * @return a DOM Request.
+   *         The request's result will be an object containing 
+   *         information about the specified lock's status,
+   *         e.g. {lockType: "pin", enabled: true}.
+   */
+  nsIDOMDOMRequest getCardLock(in DOMString lockType);
+
+  /**
+   * Unlock a card lock.
+   *
+   * @param info
+   *        An object containing the information necessary to unlock
+   *        the given lock. At a minimum, this object must have a
+   *        "lockType" attribute which specifies the type of lock, e.g.
+   *        "pin" for the PIN lock. Other attributes are dependent on
+   *        the lock type.
+   *
+   * Examples:
+   *
+   * (1) Unlocking the PIN:
+   *
+   *   unlockCardLock({lockType: "pin",
+   *                   pin: "..."});
+   *
+   * (2) Unlocking the PUK and supplying a new PIN:
+   *
+   *   unlockCardLock({lockType: "puk",
+   *                   puk: "...",
+   *                   newPin: "..."});
+   *
+   * @return a nsIDOMDOMRequest.
+   *         The request's result will be an object containing 
+   *         information about the unlock operation.
+   *
+   * Examples:
+   *
+   * (1) Unlocking failed:
+   *
+   *     {
+   *       lockType:   "pin",
+   *       result:     false,
+   *       retryCount: 2
+   *     }
+   *
+   * (2) Unlocking succeeded:
+   *
+   *     {
+   *       lockType:  "pin",
+   *       result:    true
+   *     }
+   */
+  nsIDOMDOMRequest unlockCardLock(in jsval info);
+
+  /**
+   * Modify the state of a card lock.
+   *
+   * @param info
+   *        An object containing information about the lock and
+   *        how to modify its state. At a minimum, this object
+   *        must have a "lockType" attribute which specifies the
+   *        type of lock, e.g. "pin" for the PIN lock. Other
+   *        attributes are dependent on the lock type.
+   *
+   * Examples:
+   *
+   * (1) Disabling the PIN lock:
+   *
+   *   setCardLock({lockType: "pin",
+   *                pin: "...",
+   *                enabled: false});
+   *
+   * (2) Changing the PIN:
+   *
+   *   setCardLock({lockType: "pin",
+   *                pin: "...",
+   *                newPin: "..."});
+   *
+   * @return a nsIDOMDOMRequest.
+   *         The request's result will be an object containing 
+   *         information about the operation.
+   *
+   * Examples:
+   *
+   * (1) Enabling/Disabling card lock failed or change card lock failed.
+   *
+   *     {
+   *       lockType: "pin",
+   *       result: false,
+   *       retryCount: 2
+   *     }
+   *
+   * (2) Enabling/Disabling card lock succeed or change card lock succeed.
+   *
+   *     {
+   *       lockType: "pin",
+   *       result: true
+   *     }
+   */
+  nsIDOMDOMRequest setCardLock(in jsval info);
 };
 
 [scriptable, uuid(f3bb0611-5e4a-46f1-a8f5-cf592b37596e)]
 interface nsIDOMMozMobileConnectionInfo : nsISupports
 {
   /**
    * Indicates whether the device is connected to a mobile network.
    */
--- a/dom/network/interfaces/nsIMobileConnectionProvider.idl
+++ b/dom/network/interfaces/nsIMobileConnectionProvider.idl
@@ -7,17 +7,20 @@
 interface nsIDOMMozMobileConnectionInfo;
 interface nsIDOMDOMRequest;
 interface nsIDOMWindow;
 
 /**
  * XPCOM component (in the content process) that provides the mobile
  * network information.
  */
-[scriptable, uuid(1ecd19eb-15d4-47c0-a2cf-80cfa3b94eeb)]
+[scriptable, uuid(93202514-9ae9-482e-95bc-9c6ed62aea99)]
 interface nsIMobileConnectionProvider : nsISupports
 {
   readonly attribute DOMString cardState;
   readonly attribute nsIDOMMozMobileConnectionInfo voiceConnectionInfo;
   readonly attribute nsIDOMMozMobileConnectionInfo dataConnectionInfo;
 
   nsIDOMDOMRequest getNetworks(in nsIDOMWindow window);
+  nsIDOMDOMRequest getCardLock(in nsIDOMWindow window, in DOMString lockType);
+  nsIDOMDOMRequest unlockCardLock(in nsIDOMWindow window, in jsval info);
+  nsIDOMDOMRequest setCardLock(in nsIDOMWindow window, in jsval info);
 };
--- a/dom/network/src/MobileConnection.cpp
+++ b/dom/network/src/MobileConnection.cpp
@@ -157,16 +157,52 @@ MobileConnection::GetNetworks(nsIDOMDOMR
 
   if (!mProvider) {
     return NS_ERROR_FAILURE;
   }
 
   return mProvider->GetNetworks(GetOwner(), request);
 }
 
+NS_IMETHODIMP
+MobileConnection::GetCardLock(const nsAString& aLockType, nsIDOMDOMRequest** aDomRequest)
+{
+  *aDomRequest = nsnull;
+
+  if (!mProvider) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return mProvider->GetCardLock(GetOwner(), aLockType, aDomRequest);
+}
+
+NS_IMETHODIMP
+MobileConnection::UnlockCardLock(const jsval& aInfo, nsIDOMDOMRequest** aDomRequest)
+{
+  *aDomRequest = nsnull;
+
+  if (!mProvider) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return mProvider->UnlockCardLock(GetOwner(), aInfo, aDomRequest);
+}
+
+NS_IMETHODIMP
+MobileConnection::SetCardLock(const jsval& aInfo, nsIDOMDOMRequest** aDomRequest)
+{
+  *aDomRequest = nsnull;
+
+  if (!mProvider) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return mProvider->SetCardLock(GetOwner(), aInfo, aDomRequest);
+}
+
 nsresult
 MobileConnection::InternalDispatchEvent(const nsAString& aType)
 {
   nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nsnull, nsnull);
   nsresult rv = event->InitEvent(aType, false, false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = event->SetTrusted(true);
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -410,16 +410,29 @@ nsNPAPIPluginInstance::Start()
   if (!library)
     return NS_ERROR_FAILURE;
 
   // Mark this instance as running before calling NPP_New because the plugin may
   // call other NPAPI functions, like NPN_GetURLNotify, that assume this is set
   // before returning. If the plugin returns failure, we'll clear it out below.
   mRunning = RUNNING;
 
+#if MOZ_WIDGET_ANDROID
+  // Flash creates some local JNI references during initialization (NPP_New). It does not
+  // remove these references later, so essentially they are leaked. AutoLocalJNIFrame
+  // prevents this by pushing a JNI frame. As a result, all local references created
+  // by Flash are contained in this frame. AutoLocalJNIFrame pops the frame once we
+  // go out of scope and the local references are deleted, preventing the leak.
+  JNIEnv* env = AndroidBridge::GetJNIEnv();
+  if (!env)
+    return NS_ERROR_FAILURE;
+
+  mozilla::AutoLocalJNIFrame frame(env);
+#endif
+
   nsresult newResult = library->NPP_New((char*)mimetype, &mNPP, (PRUint16)mode, count, (char**)names, (char**)values, NULL, &error);
   mInPluginInitCall = oldVal;
 
   NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
   ("NPP New called: this=%p, npp=%p, mime=%s, mode=%d, argc=%d, return=%d\n",
   this, &mNPP, mimetype, mode, count, error));
 
   if (NS_FAILED(newResult) || error != NPERR_NO_ERROR) {
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -3,16 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
 
 var RIL = {};
 Cu.import("resource://gre/modules/ril_consts.js", RIL);
 
 const DEBUG = false; // set to true to see debug messages
 
 const RILCONTENTHELPER_CID =
   Components.ID("{472816e1-1fd6-4405-996c-806f9ea68174}");
@@ -21,16 +22,22 @@ const MOBILECONNECTIONINFO_CID =
 
 const RIL_IPC_MSG_NAMES = [
   "RIL:CardStateChanged",
   "RIL:VoiceInfoChanged",
   "RIL:DataInfoChanged",
   "RIL:EnumerateCalls",
   "RIL:CallStateChanged",
   "RIL:CallError",
+  "RIL:GetCardLock:Return:OK",
+  "RIL:GetCardLock:Return:KO",
+  "RIL:SetCardLock:Return:OK",
+  "RIL:SetCardLock:Return:KO",
+  "RIL:UnlockCardLock:Return:OK",
+  "RIL:UnlockCardLock:Return:KO",
 ];
 
 const kVoiceChangedTopic     = "mobile-connection-voice-changed";
 const kDataChangedTopic      = "mobile-connection-data-changed";
 const kCardStateChangedTopic = "mobile-connection-cardstate-changed";
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
@@ -58,19 +65,18 @@ MobileConnectionInfo.prototype = {
   relSignalStrength: null
 };
 
 
 function RILContentHelper() {
   this.voiceConnectionInfo = new MobileConnectionInfo();
   this.dataConnectionInfo = new MobileConnectionInfo();
 
-  for each (let msgname in RIL_IPC_MSG_NAMES) {
-    cpmm.addMessageListener(msgname, this);
-  }
+  this.initRequests();
+  this.initMessageListener(RIL_IPC_MSG_NAMES);
   Services.obs.addObserver(this, "xpcom-shutdown", false);
 
   // Request initial state.
   let radioState = cpmm.QueryInterface(Ci.nsISyncMessageSender)
                        .sendSyncMessage("RIL:GetRadioState")[0];
   if (!radioState) {
     debug("Received null radioState from chrome process.");
     return;
@@ -79,16 +85,18 @@ function RILContentHelper() {
   for (let key in radioState.voice) {
     this.voiceConnectionInfo[key] = radioState.voice[key];
   }
   for (let key in radioState.data) {
     this.dataConnectionInfo[key] = radioState.data[key];
   }
 }
 RILContentHelper.prototype = {
+  __proto__: DOMRequestIpcHelper.prototype,
+
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionProvider,
                                          Ci.nsIRILContentHelper,
                                          Ci.nsIObserver]),
   classID:   RILCONTENTHELPER_CID,
   classInfo: XPCOMUtils.generateCI({classID: RILCONTENTHELPER_CID,
                                     classDescription: "RILContentHelper",
                                     interfaces: [Ci.nsIMobileConnectionProvider,
                                                  Ci.nsIRILContentHelper]}),
@@ -99,16 +107,49 @@ RILContentHelper.prototype = {
   voiceConnectionInfo: null,
   dataConnectionInfo:  null,
 
   getNetworks: function getNetworks(window) {
     //TODO bug 744344
     throw Components.Exception("Not implemented", Cr.NS_ERROR_NOT_IMPLEMENTED);
   },
 
+  getCardLock: function getCardLock(window, lockType) {
+    if (window == null) {
+      throw Components.Exception("Can't get window object",
+                                  Cr.NS_ERROR_UNEXPECTED);
+    }
+    let request = Services.DOMRequest.createRequest(window);
+    let requestId = this.getRequestId(request);
+    cpmm.sendAsyncMessage("RIL:GetCardLock", {lockType: lockType, requestId: requestId});
+    return request;
+  },
+
+  unlockCardLock: function unlockCardLock(window, info) {
+    if (window == null) {
+      throw Components.Exception("Can't get window object",
+                                  Cr.NS_ERROR_UNEXPECTED);
+    }
+    let request = Services.DOMRequest.createRequest(window);
+    info.requestId = this.getRequestId(request);
+    cpmm.sendAsyncMessage("RIL:UnlockCardLock", info);
+    return request;
+  },
+
+  setCardLock: function setCardLock(window, info) {
+    if (window == null) {
+      throw Components.Exception("Can't get window object",
+                                  Cr.NS_ERROR_UNEXPECTED);
+    }
+    let request = Services.DOMRequest.createRequest(window);
+    info.requestId = this.getRequestId(request);
+    cpmm.sendAsyncMessage("RIL:SetCardLock", info);
+    return request;
+  },
+
   _telephonyCallbacks: null,
   _enumerationTelephonyCallbacks: null,
 
   registerTelephonyCallback: function registerTelephonyCallback(callback) {
     if (this._telephonyCallbacks) {
       if (this._telephonyCallbacks.indexOf(callback) != -1) {
         throw new Error("Already registered this callback!");
       }
@@ -190,27 +231,26 @@ RILContentHelper.prototype = {
   set speakerEnabled(value) {
     cpmm.sendAsyncMessage("RIL:SetSpeakerEnabled", value);
   },
 
   // nsIObserver
 
   observe: function observe(subject, topic, data) {
     if (topic == "xpcom-shutdown") {
-      for each (let msgname in RIL_IPC_MSG_NAMES) {
-        cpmm.removeMessageListener(msgname, this);
-      }
+      this.removeMessageListener();
       Services.obs.removeObserver(this, "xpcom-shutdown");
       cpmm = null;
     }
   },
 
   // nsIFrameMessageListener
 
   receiveMessage: function receiveMessage(msg) {
+    let request;
     debug("Received message '" + msg.name + "': " + JSON.stringify(msg.json));
     switch (msg.name) {
       case "RIL:CardStateChanged":
         if (this.cardState != msg.json.cardState) {
           this.cardState = msg.json.cardState;
           Services.obs.notifyObservers(null, kCardStateChangedTopic, null);
         }
         break;
@@ -234,16 +274,32 @@ RILContentHelper.prototype = {
                                        [msg.json.callIndex, msg.json.state,
                                         msg.json.number, msg.json.isActive]);
         break;
       case "RIL:CallError":
         this._deliverTelephonyCallback("notifyError",
                                         [msg.json.callIndex, 
                                          msg.json.error]);    	  
     	break;
+      case "RIL:GetCardLock:Return:OK":
+      case "RIL:SetCardLock:Return:OK":
+      case "RIL:UnlockCardLock:Return:OK":
+        request = this.getRequest(msg.json.requestId);
+        if (request) {
+          Services.DOMRequest.fireSuccess(request, msg.json);
+        }
+        break;
+      case "RIL:GetCardLock:Return:KO":
+      case "RIL:SetCardLock:Return:KO":
+      case "RIL:UnlockCardLock:Return:KO":
+        request = this.getRequest(msg.json.requestId);
+        if (request) {
+          Services.DOMRequest.fireError(request, msg.json.errorMsg);
+        }
+        break;
     }
   },
 
   handleEnumerateCalls: function handleEnumerateCalls(calls) {
     debug("handleEnumerateCalls: " + JSON.stringify(calls));
     let callback = this._enumerationTelephonyCallbacks.shift();
     for (let i in calls) {
       let call = calls[i];
@@ -279,17 +335,16 @@ RILContentHelper.prototype = {
       }
       try {
         handler.apply(callback, args);
       } catch (e) {
         debug("callback handler for " + name + " threw an exception: " + e);
       }
     }
   },
-
 };
 
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([RILContentHelper]);
 
 let debug;
 if (DEBUG) {
   debug = function (s) {
     dump("-*- RILContentHelper: " + s + "\n");
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -39,16 +39,19 @@ const RIL_IPC_MSG_NAMES = [
   "RIL:StartTone",
   "RIL:StopTone",
   "RIL:Dial",
   "RIL:HangUp",
   "RIL:AnswerCall",
   "RIL:RejectCall",
   "RIL:HoldCall",
   "RIL:ResumeCall",
+  "RIL:GetCardLock",
+  "RIL:UnlockCardLock",
+  "RIL:SetCardLock"
 ];
 
 XPCOMUtils.defineLazyServiceGetter(this, "gSmsService",
                                    "@mozilla.org/sms/smsservice;1",
                                    "nsISmsService");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gSmsRequestManager",
                                    "@mozilla.org/sms/smsrequestmanager;1",
@@ -216,16 +219,25 @@ RadioInterfaceLayer.prototype = {
         this.rejectCall(msg.json);
         break;
       case "RIL:HoldCall":
         this.holdCall(msg.json);
         break;
       case "RIL:ResumeCall":
         this.resumeCall(msg.json);
         break;
+      case "RIL:GetCardLock":
+        this.getCardLock(msg.json);
+        break;
+      case "RIL:UnlockCardLock":
+        this.unlockCardLock(msg.json);
+        break;
+      case "RIL:SetCardLock":
+        this.setCardLock(msg.json);
+        break;
     }
   },
 
   onerror: function onerror(event) {
     debug("Got an error: " + event.filename + ":" +
           event.lineno + ": " + event.message + "\n");
     event.preventDefault();
   },
@@ -304,16 +316,25 @@ RadioInterfaceLayer.prototype = {
         debug("nitzTime networkTime=" + message.networkTimeInSeconds +
               " timezone=" + message.networkTimeZoneInMinutes +
               " dst=" + message.dstFlag +
               " timestamp=" + message.localTimeStampInMS);
         break;
       case "iccinfochange":
         this.radioState.icc = message;
         break;
+      case "iccgetcardlock":
+        this.handleICCGetCardLock(message);
+        break;
+      case "iccsetcardlock":
+        this.handleICCSetCardLock(message);
+        break;
+      case "iccunlockcardlock":
+        this.handleICCUnlockCardLock(message);
+        break;
       default:
         throw new Error("Don't know about this message type: " + message.type);
     }
   },
 
   updateVoiceConnection: function updateVoiceConnection(state) {
     let voiceInfo = this.radioState.voice;
     voiceInfo.type = "gsm"; //TODO see bug 726098.
@@ -629,16 +650,28 @@ RadioInterfaceLayer.prototype = {
       RILNetworkInterface.disconnect();
     }
     if (setting.value && !RILNetworkInterface.connected) {
       debug("Data call settings connect data call.");
       RILNetworkInterface.connect();
     }
   },
 
+  handleICCGetCardLock: function handleICCGetCardLock(message) {
+    ppmm.sendAsyncMessage("RIL:GetCardLock:Return:OK", message);
+  },
+
+  handleICCSetCardLock: function handleICCSetCardLock(message) {
+    ppmm.sendAsyncMessage("RIL:SetCardLock:Return:OK", message);
+  },
+
+  handleICCUnlockCardLock: function handleICCUnlockCardLock(message) {
+    ppmm.sendAsyncMessage("RIL:UnlockCardLock:Return:OK", message);
+  },
+
   // nsIObserver
 
   observe: function observe(subject, topic, data) {
     switch (topic) {
       case kMozSettingsChangedObserverTopic:
         let setting = JSON.parse(data);
         this.handleMozSettingsChanged(setting);
         break;
@@ -1191,19 +1224,82 @@ RadioInterfaceLayer.prototype = {
                              cid: cid,
                              reason: reason});
   },
 
   getDataCallList: function getDataCallList() {
     this.worker.postMessage({type: "getDataCallList"});
   },
 
+  getCardLock: function getCardLock(message) {
+    // Currently only support pin.
+    switch (message.lockType) {
+      case "pin" :
+        message.type = "getICCPinLock";
+        break;
+      default:
+        ppmm.sendAsyncMessage("RIL:GetCardLock:Return:KO",
+                              {errorMsg: "Unsupported Card Lock.",
+                               requestId: message.requestId});
+        return;
+    }
+    this.worker.postMessage(message);
+  },
+
+  unlockCardLock: function unlockCardLock(message) {
+    switch (message.lockType) {
+      case "pin":
+        message.type = "enterICCPIN";
+        break;
+      case "pin2":
+        message.type = "enterICCPIN2";
+        break;
+      case "puk":
+        message.type = "enterICCPUK";
+        break;
+      case "puk2":
+        message.type = "enterICCPUK2";
+        break;
+      default:
+        ppmm.sendAsyncMessage("RIL:UnlockCardLock:Return:KO",
+                              {errorMsg: "Unsupported Card Lock.",
+                               requestId: message.requestId});
+        return;
+    }
+    this.worker.postMessage(message);
+  },
+
+  setCardLock: function setCardLock(message) {
+    // Change pin.
+    if (message.newPin !== undefined) {
+      switch (message.lockType) {
+        case "pin":
+          message.type = "changeICCPIN";
+          break;
+        case "pin2":
+          message.type = "changeICCPIN2";
+          break;
+        default:
+          ppmm.sendAsyncMessage("RIL:SetCardLock:Return:KO",
+                                {errorMsg: "Unsupported Card Lock.",
+                                 requestId: message.requestId});
+          return;
+      }
+    } else { // Enable/Disable pin lock.
+      if (message.lockType != "pin") {
+          ppmm.sendAsyncMessage("RIL:SetCardLock:Return:KO",
+                                {errorMsg: "Unsupported Card Lock.",
+                                 requestId: message.requestId});
+      }
+      message.type = "setICCPinLock";
+    }
+    this.worker.postMessage(message);
+  }
 };
 
-
 let RILNetworkInterface = {
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface,
                                          Ci.nsIRILDataCallback]),
 
   // nsINetworkInterface
 
   NETWORK_STATE_UNKNOWN:       Ci.nsINetworkInterface.NETWORK_STATE_UNKNOWN,
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -418,16 +418,33 @@ const EF_PATH_DF_GSM = "7f20";
 const ICC_STATUS_NORMAL_ENDING = 0x90;
 const ICC_STATUS_NORMAL_ENDING_WITH_EXTRA = 0x91;
 const ICC_STATUS_WITH_SIM_DATA = 0x9e;
 const ICC_STATUS_WITH_RESPONSE_DATA = 0x9f;
 const ICC_STATUS_ERROR_WRONG_LENGTH = 0x67;
 const ICC_STATUS_ERROR_COMMAND_NOT_ALLOWED = 0x69;
 const ICC_STATUS_ERROR_WRONG_PARAMETERS = 0x6a;
 
+// ICC call barring facility.
+// TS 27.007, clause 7.4, +CLCK
+const ICC_CB_FACILITY_SIM = "SC";
+
+// ICC service class
+// TS 27.007, clause 7.4, +CLCK
+const ICC_SERVICE_CLASS_NONE = 0; // no user input
+const ICC_SERVICE_CLASS_VOICE = (1 << 0);
+const ICC_SERVICE_CLASS_DATA = (1 << 1);
+const ICC_SERVICE_CLASS_FAX = (1 << 2);
+const ICC_SERVICE_CLASS_SMS = (1 << 3);
+const ICC_SERVICE_CLASS_DATA_SYNC = (1 << 4);
+const ICC_SERVICE_CLASS_DATA_ASYNC = (1 << 5);
+const ICC_SERVICE_CLASS_PACKET = (1 << 6);
+const ICC_SERVICE_CLASS_PAD = (1 << 7);
+const ICC_SERVICE_CLASS_MAX = (1 << 7); // Max ICC_SERVICE_CLASS value
+
 /**
  * GSM PDU constants
  */
 
 // PDU TYPE-OF-ADDRESS
 const PDU_TOA_UNKNOWN       = 0x80; // Unknown. This is used when the user or
                                     // network has no a priori information
                                     // about the numbering plan.
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -757,56 +757,177 @@ let RIL = {
 
   /**
    * Enter a PIN to unlock the ICC.
    *
    * @param pin
    *        String containing the PIN.
    */
   enterICCPIN: function enterICCPIN(options) {
-    Buf.newParcel(REQUEST_ENTER_SIM_PIN);
+    Buf.newParcel(REQUEST_ENTER_SIM_PIN, options);
+    Buf.writeUint32(1);
+    Buf.writeString(options.pin);
+    Buf.sendParcel();
+  },
+
+  /**
+   * Enter a PIN2 to unlock the ICC.
+   *
+   * @param pin
+   *        String containing the PIN2.
+   */
+  enterICCPIN2: function enterICCPIN2(options) {
+    Buf.newParcel(REQUEST_ENTER_SIM_PIN2, options);
     Buf.writeUint32(1);
     Buf.writeString(options.pin);
     Buf.sendParcel();
   },
 
   /**
-   * Change the current ICC PIN number
+   * Change the current ICC PIN number.
    *
-   * @param oldPin
+   * @param pin
    *        String containing the old PIN value
    * @param newPin
    *        String containing the new PIN value
    */
   changeICCPIN: function changeICCPIN(options) {
-    Buf.newParcel(REQUEST_CHANGE_SIM_PIN);
+    Buf.newParcel(REQUEST_CHANGE_SIM_PIN, options);
     Buf.writeUint32(2);
-    Buf.writeString(options.oldPin);
+    Buf.writeString(options.pin);
     Buf.writeString(options.newPin);
     Buf.sendParcel();
   },
 
   /**
-   * Supplies SIM PUK and a new PIN to unlock the ICC
+   * Change the current ICC PIN2 number.
+   *
+   * @param pin
+   *        String containing the old PIN2 value
+   * @param newPin
+   *        String containing the new PIN2 value
+   */
+  changeICCPIN2: function changeICCPIN2(options) {
+    Buf.newParcel(REQUEST_CHANGE_SIM_PIN2, options);
+    Buf.writeUint32(2);
+    Buf.writeString(options.pin);
+    Buf.writeString(options.newPin);
+    Buf.sendParcel();
+  },
+  /**
+   * Supplies ICC PUK and a new PIN to unlock the ICC.
    *
    * @param puk
    *        String containing the PUK value.
    * @param newPin
    *        String containing the new PIN value.
    *
    */
    enterICCPUK: function enterICCPUK(options) {
-     Buf.newParcel(REQUEST_ENTER_SIM_PUK);
+     Buf.newParcel(REQUEST_ENTER_SIM_PUK, options);
+     Buf.writeUint32(2);
+     Buf.writeString(options.puk);
+     Buf.writeString(options.newPin);
+     Buf.sendParcel();
+   },
+
+  /**
+   * Supplies ICC PUK2 and a new PIN2 to unlock the ICC.
+   *
+   * @param puk
+   *        String containing the PUK2 value.
+   * @param newPin
+   *        String containing the new PIN2 value.
+   *
+   */
+   enterICCPUK2: function enterICCPUK2(options) {
+     Buf.newParcel(REQUEST_ENTER_SIM_PUK2, options);
      Buf.writeUint32(2);
      Buf.writeString(options.puk);
      Buf.writeString(options.newPin);
      Buf.sendParcel();
    },
 
   /**
+   * Get ICC Pin lock. A wrapper call to queryICCFacilityLock.
+   *
+   * @param requestId
+   *        Request Id from RadioInterfaceLayer.
+   */
+  getICCPinLock: function getICCPinLock(options) {
+    options.facility = ICC_CB_FACILITY_SIM;
+    options.password = ""; // For query no need to provide pin.
+    options.serviceClass = ICC_SERVICE_CLASS_VOICE |
+                           ICC_SERVICE_CLASS_DATA  |
+                           ICC_SERVICE_CLASS_FAX,
+    this.queryICCFacilityLock(options);
+  },
+
+  /**
+   *  Query ICC facility lock.
+   *
+   *  @param facility
+   *         One of ICC_CB_FACILITY_*.
+   *  @param password
+   *         Password for the facility, or "" if not required.
+   *  @param serviceClass
+   *         One of ICC_SERVICE_CLASS_*.
+   */
+  queryICCFacilityLock: function queryICCFacilityLock(options) {
+    Buf.newParcel(REQUEST_QUERY_FACILITY_LOCK, options);
+    Buf.writeUint32(3);
+    Buf.writeString(options.facility);
+    Buf.writeString(options.password);
+    Buf.writeString(options.serviceClass.toString());
+    Buf.sendParcel();
+  },
+
+  /**
+   * Set ICC Pin lock. A wrapper call to setICCFacilityLock.
+   *
+   * @param enabled
+   *        true to enable, false to disable.
+   * @param pin
+   *        Pin code.
+   * @param requestId
+   *        Request Id from RadioInterfaceLayer.
+   */
+  setICCPinLock: function setICCPinLock(options) {
+    options.facility = ICC_CB_FACILITY_SIM;
+    options.enabled = options.enabled;
+    options.password = options.pin;
+    options.serviceClass = ICC_SERVICE_CLASS_VOICE |
+                           ICC_SERVICE_CLASS_DATA  |
+                           ICC_SERVICE_CLASS_FAX,
+    this.setICCFacilityLock(options);
+  },
+
+  /**
+   * Set ICC facility lock.
+   *
+   * @param facility
+   *        One of ICC_CB_FACILITY_*.
+   * @param enabled
+   *        true to enable, false to disable.
+   * @param password
+   *        Password for the facility, or "" if not required.
+   * @param serviceClass
+   *        One of ICC_SERVICE_CLASS_*.
+   */
+  setICCFacilityLock: function setICCFacilityLock(options) {
+    Buf.newParcel(REQUEST_SET_FACILITY_LOCK, options);
+    Buf.writeUint32(4);
+    Buf.writeString(options.facility);
+    Buf.writeString(options.enabled ? "1" : "0");
+    Buf.writeString(options.password);
+    Buf.writeString(options.serviceClass.toString());
+    Buf.sendParcel();
+  },
+
+  /**
    *  Request an ICC I/O operation.
    * 
    *  See TS 27.007 "restricted SIM" operation, "AT Command +CRSM".
    *  The sequence is in the same order as how libril reads this parcel,
    *  see the struct RIL_SIM_IO_v5 or RIL_SIM_IO_v6 defined in ril.h
    *
    *  @param command 
    *         The I/O command, one of the ICC_COMMAND_* constants.
@@ -2149,35 +2270,57 @@ RIL[REQUEST_GET_SIM_STATUS] = function R
       pin2:           Buf.readUint32()
     });
   }
 
   if (DEBUG) debug("iccStatus: " + JSON.stringify(iccStatus));
   this._processICCStatus(iccStatus);
 };
 RIL[REQUEST_ENTER_SIM_PIN] = function REQUEST_ENTER_SIM_PIN(length, options) {
-  if (options.rilRequestError) {
-    return;
-  }
-
-  let response = Buf.readUint32List();
-  if (DEBUG) debug("REQUEST_ENTER_SIM_PIN returned " + response);
+  this.sendDOMMessage({type: "iccunlockcardlock",
+                       lockType: "pin",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
 };
 RIL[REQUEST_ENTER_SIM_PUK] = function REQUEST_ENTER_SIM_PUK(length, options) {
-  if (options.rilRequestError) {
-    return;
-  }
-
-  let response = Buf.readUint32List();
-  if (DEBUG) debug("REQUEST_ENTER_SIM_PUK returned " + response);
+  this.sendDOMMessage({type: "iccunlockcardlock",
+                       lockType: "puk",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
+};
+RIL[REQUEST_ENTER_SIM_PIN2] = function REQUEST_ENTER_SIM_PIN2(length, options) {
+  this.sendDOMMessage({type: "iccunlockcardlock",
+                       lockType: "pin2",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
 };
-RIL[REQUEST_ENTER_SIM_PIN2] = null;
-RIL[REQUEST_ENTER_SIM_PUK2] = null;
-RIL[REQUEST_CHANGE_SIM_PIN] = null;
-RIL[REQUEST_CHANGE_SIM_PIN2] = null;
+RIL[REQUEST_ENTER_SIM_PUK2] = function REQUEST_ENTER_SIM_PUK(length, options) {
+  this.sendDOMMessage({type: "iccunlockcardlock",
+                       lockType: "puk2",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
+};
+RIL[REQUEST_CHANGE_SIM_PIN] = function REQUEST_CHANGE_SIM_PIN(length, options) {
+  this.sendDOMMessage({type: "iccsetcardlock",
+                       lockType: "pin",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
+};
+RIL[REQUEST_CHANGE_SIM_PIN2] = function REQUEST_CHANGE_SIM_PIN2(length, options) {
+  this.sendDOMMessage({type: "iccsetcardlock",
+                       lockType: "pin2",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
+};
 RIL[REQUEST_ENTER_NETWORK_DEPERSONALIZATION] = null;
 RIL[REQUEST_GET_CURRENT_CALLS] = function REQUEST_GET_CURRENT_CALLS(length, options) {
   if (options.rilRequestError) {
     return;
   }
 
   this.initRILQuirks();
 
@@ -2529,18 +2672,34 @@ RIL[REQUEST_DEACTIVATE_DATA_CALL] = func
   }
 
   let datacall = this.currentDataCalls[options.cid];
   delete this.currentDataCalls[options.cid];
   datacall.state = GECKO_NETWORK_STATE_DISCONNECTED;
   this.sendDOMMessage({type: "datacallstatechange",
                        datacall: datacall});
 };
-RIL[REQUEST_QUERY_FACILITY_LOCK] = null;
-RIL[REQUEST_SET_FACILITY_LOCK] = null;
+RIL[REQUEST_QUERY_FACILITY_LOCK] = function REQUEST_QUERY_FACILITY_LOCK(length, options) {
+  if (options.rilRequestError) {
+    return;
+  }
+
+  let response = Buf.readUint32List()[0];
+  this.sendDOMMessage({type: "iccgetcardlock",
+                       lockType: "pin",
+                       enabled: response == 0 ? false : true,
+                       requestId: options.requestId});
+};
+RIL[REQUEST_SET_FACILITY_LOCK] = function REQUEST_SET_FACILITY_LOCK(length, options) {
+  this.sendDOMMessage({type: "iccsetcardlock",
+                       lockType: "pin",
+                       result: options.rilRequestError == 0 ? true : false,
+                       retryCount: length ? Buf.readUint32List()[0] : -1,
+                       requestId: options.requestId});
+};
 RIL[REQUEST_CHANGE_BARRING_PASSWORD] = null;
 RIL[REQUEST_QUERY_NETWORK_SELECTION_MODE] = function REQUEST_QUERY_NETWORK_SELECTION_MODE(length, options) {
   if (options.rilRequestError) {
     return;
   }
 
   let mode = Buf.readUint32List();
   this.networkSelectionMode = mode[0];
--- a/dom/tests/mochitest/pointerlock/file_movementXY.html
+++ b/dom/tests/mochitest/pointerlock/file_movementXY.html
@@ -78,26 +78,36 @@ https://bugzilla.mozilla.org/show_bug.cg
           secondMove.screenY = e.screenY;
           secondMove.mozMovementX = e.mozMovementX;
           secondMove.mozMovementY = e.mozMovementY;
 
           div.removeEventListener("mousemove", moveMouseAgain, false);
           document.mozCancelFullScreen();
         };
 
-        document.addEventListener("mozfullscreenchange", function() {
+        function fullscreenchange() {
           if (document.mozFullScreenElement === div) {
+            var screenX = window.screenX;
+            var screenY = window.screenY;
+            if (screenX != 0 || screenY != 0) {
+              todo(screenX == 0 && screenY == 0,
+                "We should only receive fullscreenchange once we've finished fullscreen transition");
+              setTimeout(fullscreenchange, 250);
+              return;
+            } 
             div.addEventListener("mousemove", moveMouse, false);
             synthesizeMouseAtCenter(div, {type: "mousemove"}, window);
           }
           else {
             runTests();
             SimpleTest.finish();
           }
-        }, false);
+        }
+        
+        document.addEventListener("mozfullscreenchange", fullscreenchange, false);
 
         function start() {
           div.mozRequestFullScreen();
         }
       </script>
     </pre>
   </body>
 </html>
--- a/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html
+++ b/dom/tests/mochitest/pointerlock/file_screenClientXYConst.html
@@ -80,25 +80,35 @@ https://bugzilla.mozilla.org/show_bug.cg
           div.addEventListener("mousemove", moveLocked, false);
           divRect = div.getBoundingClientRect();
           synthesizeMouse(div, (divRect.width / 4) * 3, (divRect.height / 4) * 3, {
             type: "mousemove"
           }, window);
         }
       }, false);
 
-      document.addEventListener("mozfullscreenchange", function() {
+      function fullscreenchange() {
+        var screenX = window.screenX;
+        var screenY = window.screenY;
         if (document.mozFullScreenElement === div) {
+          if (screenX != 0 || screenY != 0) {
+            todo(screenX == 0 && screenY == 0,
+              "We should only receive fullscreenchange once we've finished fullscreen transition " +
+              "window.screenX=" + screenX + " window.screenY=" + screenY);
+            setTimeout(fullscreenchange, 250);
+            return;
+          }
           div.addEventListener("mousemove", moveUnlocked, false);
           synthesizeMouseAtCenter(div, { type: "mousemove" }, window);
         } else {
           runTests();
           SimpleTest.finish();
         }
-      }, false);
+      }
+      document.addEventListener("mozfullscreenchange", fullscreenchange, false);
 
       function start() {
         div = document.getElementById("div");
         div.mozRequestFullScreen();
       }
   </script>
 </body>
 </html>
--- a/embedding/android/GeckoNetworkManager.java
+++ b/embedding/android/GeckoNetworkManager.java
@@ -181,37 +181,49 @@ public class GeckoNetworkManager
       stopListening();
     }
   }
 
   private static NetworkType getNetworkType() {
     ConnectivityManager cm =
       (ConnectivityManager)GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
 
-    if (cm.getActiveNetworkInfo() == null) {
+    if (cm == null) {
+      Log.w("GeckoNetworkManager", "Could not access Connectivity service");
       return NetworkType.NETWORK_NONE;
     }
 
-    switch (cm.getActiveNetworkInfo().getType()) {
+    NetworkInfo ni = cm.getActiveNetworkInfo();
+
+    if (ni == null) {
+      return NetworkType.NETWORK_NONE;
+    }
+
+    switch (ni.getType()) {
       case ConnectivityManager.TYPE_ETHERNET:
         return NetworkType.NETWORK_ETHERNET;
       case ConnectivityManager.TYPE_WIFI:
         return NetworkType.NETWORK_WIFI;
       case ConnectivityManager.TYPE_WIMAX:
         return NetworkType.NETWORK_WIMAX;
       case ConnectivityManager.TYPE_MOBILE:
         break; // We will handle sub-types after the switch.
       default:
         Log.w("GeckoNetworkManager", "Ignoring the current network type.");
         return NetworkType.NETWORK_UNKNOWN;
     }
 
     TelephonyManager tm =
       (TelephonyManager)GeckoApp.mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
 
+    if (tm == null) {
+      Log.w("GeckoNetworkManager", "Could not access Telephony service");
+      return NetworkType.NETWORK_UNKNOWN;
+    }
+
     switch (tm.getNetworkType()) {
       case TelephonyManager.NETWORK_TYPE_IDEN:
       case TelephonyManager.NETWORK_TYPE_CDMA:
         return NetworkType.NETWORK_2_G;
       case TelephonyManager.NETWORK_TYPE_GPRS:
       case TelephonyManager.NETWORK_TYPE_1xRTT:
         return NetworkType.NETWORK_2_5_G;
       case TelephonyManager.NETWORK_TYPE_EDGE:
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -743,18 +743,18 @@ public:
 
   void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
     mUserData.Add(key, userData, destroy);
   }
   void *GetUserData(UserDataKey *key) {
     return mUserData.Get(key);
   }
 
-  /* Within this rectangle all pixels will be opaque by the time the result of
-   * this DrawTarget is first used for drawing. Either by the underlying surface
+  /* Within this rectangle all pixels will be opaque by the time the result of
+   * this DrawTarget is first used for drawing. Either by the underlying surface
    * being used as an input to external drawing, or Snapshot() being called.
    * This rectangle is specified in device space.
    */
   void SetOpaqueRect(const IntRect &aRect) {
     mOpaqueRect = aRect;
   }
 
   const IntRect &GetOpaqueRect() const {
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -687,24 +687,23 @@ DrawTargetCG::FillGlyphs(ScaledFont *aFo
   CGContextSetFontSize(cg, cgFont->mSize);
 
   //XXX: we should use a stack vector here when we have a class like that
   std::vector<CGGlyph> glyphs;
   std::vector<CGPoint> positions;
   glyphs.resize(aBuffer.mNumGlyphs);
   positions.resize(aBuffer.mNumGlyphs);
 
-  CGFloat xprev = aBuffer.mGlyphs[0].mPosition.x;
-  CGFloat yprev = aBuffer.mGlyphs[0].mPosition.y;
-  CGContextSetTextPosition(cg, xprev, yprev);
-
   // Handle the flip
-  CGAffineTransform matrix = CGAffineTransformMakeScale(1, -1);//CGAffineTransformMake(1, 0, 0, -1, 0, -mSize.height);
-  // "Note that the text matrix is not a part of the graphics state"
-  CGContextSetTextMatrix(cg, matrix);
+  CGAffineTransform matrix = CGAffineTransformMakeScale(1, -1);
+  CGContextConcatCTM(cg, matrix);
+  // CGContextSetTextMatrix works differently with kCGTextClip && kCGTextFill
+  // It seems that it transforms the positions with TextFill and not with TextClip
+  // Therefore we'll avoid it. See also:
+  // http://cgit.freedesktop.org/cairo/commit/?id=9c0d761bfcdd28d52c83d74f46dd3c709ae0fa69
 
   for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
     glyphs[i] = aBuffer.mGlyphs[i].mIndex;
     // XXX: CGPointMake might not be inlined
     positions[i] = CGPointMake(aBuffer.mGlyphs[i].mPosition.x,
                               -aBuffer.mGlyphs[i].mPosition.y);
   }
 
--- a/gfx/2d/ShadersD2D.h
+++ b/gfx/2d/ShadersD2D.h
@@ -1,11202 +1,11202 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#if 0
-//
-// FX Version: fx_4_0
-// Child effect (requires effect pool): false
-//
-// 3 local buffer(s)
-//
-cbuffer cb0
-{
-    float4  QuadDesc;                   // Offset:    0, size:   16
-    float4  TexCoords;                  // Offset:   16, size:   16
-    float4  MaskTexCoords;              // Offset:   32, size:   16
-    float4  TextColor;                  // Offset:   48, size:   16
-}
-
-cbuffer cb1
-{
-    float4  BlurOffsetsH[3];            // Offset:    0, size:   48
-    float4  BlurOffsetsV[3];            // Offset:   48, size:   48
-    float4  BlurWeights[3];             // Offset:   96, size:   48
-    float4  ShadowColor;                // Offset:  144, size:   16
-}
-
-cbuffer cb2
-{
-    float3x3 DeviceSpaceToUserSpace;    // Offset:    0, size:   44
-    float2  dimensions;                 // Offset:   48, size:    8
-    float3  diff;                       // Offset:   64, size:   12
-    float2  center1;                    // Offset:   80, size:    8
-    float   A;                          // Offset:   88, size:    4
-    float   radius1;                    // Offset:   92, size:    4
-    float   sq_radius1;                 // Offset:   96, size:    4
-}
-
-//
-// 11 local object(s)
-//
-Texture2D tex;
-Texture2D mask;
-SamplerState sSampler
-{
-    Filter   = uint(MIN_MAG_MIP_LINEAR /* 21 */);
-    Texture  = tex;
-    AddressU = uint(CLAMP /* 3 */);
-    AddressV = uint(CLAMP /* 3 */);
-};
-SamplerState sWrapSampler
-{
-    Filter   = uint(MIN_MAG_MIP_LINEAR /* 21 */);
-    Texture  = tex;
-    AddressU = uint(WRAP /* 1 */);
-    AddressV = uint(WRAP /* 1 */);
-};
-SamplerState sMirrorSampler
-{
-    Filter   = uint(MIN_MAG_MIP_LINEAR /* 21 */);
-    Texture  = tex;
-    AddressU = uint(MIRROR /* 2 */);
-    AddressV = uint(MIRROR /* 2 */);
-};
-SamplerState sMaskSampler
-{
-    Filter   = uint(MIN_MAG_MIP_LINEAR /* 21 */);
-    Texture  = mask;
-    AddressU = uint(CLAMP /* 3 */);
-    AddressV = uint(CLAMP /* 3 */);
-};
-SamplerState sShadowSampler
-{
-    Filter   = uint(MIN_MAG_MIP_LINEAR /* 21 */);
-    Texture  = tex;
-    AddressU = uint(BORDER /* 4 */);
-    AddressV = uint(BORDER /* 4 */);
-    BorderColor = float4(0, 0, 0, 0);
-};
-RasterizerState TextureRast
-{
-    ScissorEnable = bool(FALSE /* 0 */);
-    CullMode = uint(NONE /* 1 */);
-};
-BlendState ShadowBlendH
-{
-    BlendEnable[0] = bool(FALSE /* 0 */);
-    RenderTargetWriteMask[0] = byte(0x0f);
-};
-BlendState ShadowBlendV
-{
-    BlendEnable[0] = bool(TRUE /* 1 */);
-    SrcBlend[0] = uint(ONE /* 2 */);
-    DestBlend[0] = uint(INV_SRC_ALPHA /* 6 */);
-    BlendOp[0] = uint(ADD /* 1 */);
-    SrcBlendAlpha[0] = uint(ONE /* 2 */);
-    DestBlendAlpha[0] = uint(INV_SRC_ALPHA /* 6 */);
-    BlendOpAlpha[0] = uint(ADD /* 1 */);
-    RenderTargetWriteMask[0] = byte(0x0f);
-};
-BlendState bTextBlend
-{
-    AlphaToCoverageEnable = bool(FALSE /* 0 */);
-    BlendEnable[0] = bool(TRUE /* 1 */);
-    SrcBlend[0] = uint(SRC1_COLOR /* 16 */);
-    DestBlend[0] = uint(INV_SRC1_COLOR /* 17 */);
-    BlendOp[0] = uint(ADD /* 1 */);
-    SrcBlendAlpha[0] = uint(SRC1_ALPHA /* 18 */);
-    DestBlendAlpha[0] = uint(INV_SRC1_ALPHA /* 19 */);
-    BlendOpAlpha[0] = uint(ADD /* 1 */);
-    RenderTargetWriteMask[0] = byte(0x0f);
-};
-
-//
-// 5 technique(s)
-//
-technique10 SampleTexture
-{
-    pass P0
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sSampler                          sampler      NA          NA    0        1
-            // tex                               texture  float4          2d    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float       
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                texld r0, t0, s0
-                mov oC0, r0
-            
-            // approximately 2 instruction slots used (1 texture, 1 arithmetic)
-            ps_4_0
-            dcl_sampler s0, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_input_ps linear v1.xy
-            dcl_output o0.xyzw
-            sample o0.xyzw, v1.xyxx, t0.xyzw, s0
-            ret 
-            // Approximately 2 instruction slots used
-                    
-        };
-    }
-
-}
-
-technique10 SampleRadialGradient
-{
-    pass APos
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44
-            //   float2 dimensions;                 // Offset:   48 Size:     8
-            //   float3 diff;                       // Offset:   64 Size:    12 [unused]
-            //   float2 center1;                    // Offset:   80 Size:     8 [unused]
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4 [unused]
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            // cb2                               cbuffer      NA          NA    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         1  ( FLT, FLT, FLT, FLT)
-            // c2         cb0             2         1  ( FLT, FLT, FLT, FLT)
-            // c3         cb1             0         2  ( FLT, FLT, FLT, FLT)
-            // c5         cb1             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c6, 1, 0.5, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad r0.xy, v0, c1.zwzw, c1
-                add r0.z, r0.x, c6.x
-                mul r0.z, r0.z, c5.x
-                mul r1.x, r0.z, c6.y
-                add r0.z, -r0.y, c6.x
-                add oPos.xy, r0, c0
-                mul r0.x, r0.z, c5.y
-                mul r1.y, r0.x, c6.y
-                mov r1.z, c6.x
-                dp3 oT0.w, r1, c3
-                dp3 oT0.z, r1, c4
-                mov oPos.zw, c6.xyzx
-            
-            // approximately 13 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_constantbuffer cb1[4], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            dcl_temps 2
-            mov o0.zw, l(0,0,0,1.000000)
-            mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.xy, r0.xyxx
-            add r0.x, r0.x, l(1.000000)
-            add r0.y, -r0.y, l(1.000000)
-            mul r0.xy, r0.xyxx, cb1[3].xyxx
-            mul r1.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
-            mov r1.z, l(1.000000)
-            dp3 o1.z, r1.xyzx, cb1[0].xyzx
-            dp3 o1.w, r1.xyzx, cb1[1].xyzx
-            mad o1.xy, v0.xyxx, cb0[2].zwzz, cb0[2].xyxx
-            ret 
-            // Approximately 12 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44 [unused]
-            //   float2 dimensions;                 // Offset:   48 Size:     8 [unused]
-            //   float3 diff;                       // Offset:   64 Size:    12
-            //   float2 center1;                    // Offset:   80 Size:     8
-            //   float A;                           // Offset:   88 Size:     4
-            //   float radius1;                     // Offset:   92 Size:     4
-            //   float sq_radius1;                  // Offset:   96 Size:     4
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sSampler                          sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb2                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             4         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                def c3, 0.5, 0, 0, 0
-                def c4, 1, -1, 0, -0
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                add r0.xy, t0.wzzw, -c1
-                dp2add r0.w, r0, r0, -c2.x
-                mul r0.w, r0.w, c1.z
-                mov r0.z, c1.w
-                dp3 r0.x, r0, c0
-                mad r0.y, r0.x, r0.x, -r0.w
-                abs r0.z, r0.y
-                rsq r0.z, r0.z
-                rcp r1.x, r0.z
-                mov r1.yz, -r1.x
-                add r0.xzw, r0.x, r1.xyyz
-                rcp r1.x, c1.z
-                mul r0.xzw, r0, r1.x
-                mov r1.w, c1.w
-                mad r1.xyz, r0.xzww, c0.z, r1.w
-                cmp r2.x, r1.x, r0.x, r0.w
-                cmp r0.xzw, r1.xyyz, c4.xyxy, c4.zyzw
-                mov r2.y, c3.x
-                texld r1, t0, s1
-                texld r2, r2, s0
-                mul r2.xyz, r2.w, r2
-                mul r1, r1.w, r2
-                add r0.w, r0.w, r0.x
-                cmp r0.x, r0.w, r0.x, r0.z
-                cmp r1, -r0.x, c4.z, r1
-                cmp r0, r0.y, r1, c4.z
-                mov oC0, r0
-            
-            // approximately 28 instruction slots used (2 texture, 26 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[7], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 3
-            add r0.xy, v1.zwzz, -cb0[5].xyxx
-            mov r0.z, cb0[5].w
-            dp3 r0.z, r0.xyzx, cb0[4].xyzx
-            dp2 r0.x, r0.xyxx, r0.xyxx
-            add r0.x, r0.x, -cb0[6].x
-            mul r0.x, r0.x, cb0[5].z
-            mad r0.x, r0.z, r0.z, -r0.x
-            lt r0.y, r0.x, l(0.000000)
-            sqrt r1.x, |r0.x|
-            mov r1.y, -r1.x
-            add r0.xz, r0.zzzz, r1.xxyx
-            div r0.xz, r0.xxzx, cb0[5].zzzz
-            mul r1.xy, r0.xzxx, cb0[4].zzzz
-            ge r1.xy, r1.xyxx, -cb0[5].wwww
-            and r1.xy, r1.xyxx, l(0x3f800000, 0x3f800000, 0, 0)
-            add r0.x, -r0.z, r0.x
-            mad r2.x, r1.x, r0.x, r0.z
-            mov r2.y, l(0.500000)
-            sample r2.xyzw, r2.xyxx, t0.xyzw, s0
-            if_nz r0.y
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            max r0.x, r1.y, r1.x
-            ge r0.x, l(0.000000), r0.x
-            if_nz r0.x
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            mul r2.xyz, r2.wwww, r2.xyzx
-            sample r0.xyzw, v1.xyxx, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, r2.xyzw
-            ret 
-            // Approximately 33 instruction slots used
-                    
-        };
-    }
-
-    pass A0
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44
-            //   float2 dimensions;                 // Offset:   48 Size:     8
-            //   float3 diff;                       // Offset:   64 Size:    12 [unused]
-            //   float2 center1;                    // Offset:   80 Size:     8 [unused]
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4 [unused]
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            // cb2                               cbuffer      NA          NA    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         1  ( FLT, FLT, FLT, FLT)
-            // c2         cb0             2         1  ( FLT, FLT, FLT, FLT)
-            // c3         cb1             0         2  ( FLT, FLT, FLT, FLT)
-            // c5         cb1             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c6, 1, 0.5, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad r0.xy, v0, c1.zwzw, c1
-                add r0.z, r0.x, c6.x
-                mul r0.z, r0.z, c5.x
-                mul r1.x, r0.z, c6.y
-                add r0.z, -r0.y, c6.x
-                add oPos.xy, r0, c0
-                mul r0.x, r0.z, c5.y
-                mul r1.y, r0.x, c6.y
-                mov r1.z, c6.x
-                dp3 oT0.w, r1, c3
-                dp3 oT0.z, r1, c4
-                mov oPos.zw, c6.xyzx
-            
-            // approximately 13 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_constantbuffer cb1[4], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            dcl_temps 2
-            mov o0.zw, l(0,0,0,1.000000)
-            mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.xy, r0.xyxx
-            add r0.x, r0.x, l(1.000000)
-            add r0.y, -r0.y, l(1.000000)
-            mul r0.xy, r0.xyxx, cb1[3].xyxx
-            mul r1.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
-            mov r1.z, l(1.000000)
-            dp3 o1.z, r1.xyzx, cb1[0].xyzx
-            dp3 o1.w, r1.xyzx, cb1[1].xyzx
-            mad o1.xy, v0.xyxx, cb0[2].zwzz, cb0[2].xyxx
-            ret 
-            // Approximately 12 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44 [unused]
-            //   float2 dimensions;                 // Offset:   48 Size:     8 [unused]
-            //   float3 diff;                       // Offset:   64 Size:    12
-            //   float2 center1;                    // Offset:   80 Size:     8
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sSampler                          sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb2                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             4         2  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                def c2, 0.5, 0, 0, 0
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                mul r0.w, c1.w, c1.w
-                add r0.xy, t0.wzzw, -c1
-                dp2add r0.w, r0, r0, -r0.w
-                mul r0.w, r0.w, c2.x
-                mov r0.z, c1.w
-                dp3 r0.x, r0, c0
-                rcp r0.x, r0.x
-                mul r0.x, r0.x, r0.w
-                mov r0.y, c2.x
-                texld r1, t0, s1
-                texld r2, r0, s0
-                mov r0.w, c1.w
-                mad r0.x, r0.x, -c0.z, -r0.w
-                mul r2.xyz, r2.w, r2
-                mul r1, r1.w, r2
-                cmp r0, r0.x, c2.y, r1
-                mov oC0, r0
-            
-            // approximately 18 instruction slots used (2 texture, 16 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[6], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 2
-            add r0.xy, v1.zwzz, -cb0[5].xyxx
-            mov r0.z, cb0[5].w
-            dp3 r0.z, r0.xyzx, cb0[4].xyzx
-            dp2 r0.x, r0.xyxx, r0.xyxx
-            mad r0.x, -cb0[5].w, cb0[5].w, r0.x
-            mul r0.x, r0.x, l(0.500000)
-            div r0.x, r0.x, r0.z
-            mul r0.z, r0.x, cb0[4].z
-            ge r0.z, -cb0[5].w, r0.z
-            mov r0.y, l(0.500000)
-            sample r1.xyzw, r0.xyxx, t0.xyzw, s0
-            if_nz r0.z
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            mul r1.xyz, r1.wwww, r1.xyzx
-            sample r0.xyzw, v1.xyxx, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, r1.xyzw
-            ret 
-            // Approximately 19 instruction slots used
-                    
-        };
-    }
-
-    pass APosWrap
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44
-            //   float2 dimensions;                 // Offset:   48 Size:     8
-            //   float3 diff;                       // Offset:   64 Size:    12 [unused]
-            //   float2 center1;                    // Offset:   80 Size:     8 [unused]
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4 [unused]
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            // cb2                               cbuffer      NA          NA    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         1  ( FLT, FLT, FLT, FLT)
-            // c2         cb0             2         1  ( FLT, FLT, FLT, FLT)
-            // c3         cb1             0         2  ( FLT, FLT, FLT, FLT)
-            // c5         cb1             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c6, 1, 0.5, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad r0.xy, v0, c1.zwzw, c1
-                add r0.z, r0.x, c6.x
-                mul r0.z, r0.z, c5.x
-                mul r1.x, r0.z, c6.y
-                add r0.z, -r0.y, c6.x
-                add oPos.xy, r0, c0
-                mul r0.x, r0.z, c5.y
-                mul r1.y, r0.x, c6.y
-                mov r1.z, c6.x
-                dp3 oT0.w, r1, c3
-                dp3 oT0.z, r1, c4
-                mov oPos.zw, c6.xyzx
-            
-            // approximately 13 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_constantbuffer cb1[4], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            dcl_temps 2
-            mov o0.zw, l(0,0,0,1.000000)
-            mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.xy, r0.xyxx
-            add r0.x, r0.x, l(1.000000)
-            add r0.y, -r0.y, l(1.000000)
-            mul r0.xy, r0.xyxx, cb1[3].xyxx
-            mul r1.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
-            mov r1.z, l(1.000000)
-            dp3 o1.z, r1.xyzx, cb1[0].xyzx
-            dp3 o1.w, r1.xyzx, cb1[1].xyzx
-            mad o1.xy, v0.xyxx, cb0[2].zwzz, cb0[2].xyxx
-            ret 
-            // Approximately 12 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44 [unused]
-            //   float2 dimensions;                 // Offset:   48 Size:     8 [unused]
-            //   float3 diff;                       // Offset:   64 Size:    12
-            //   float2 center1;                    // Offset:   80 Size:     8
-            //   float A;                           // Offset:   88 Size:     4
-            //   float radius1;                     // Offset:   92 Size:     4
-            //   float sq_radius1;                  // Offset:   96 Size:     4
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sWrapSampler                      sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb2                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             4         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                def c3, 0.5, 0, 0, 0
-                def c4, 1, -1, 0, -0
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                add r0.xy, t0.wzzw, -c1
-                dp2add r0.w, r0, r0, -c2.x
-                mul r0.w, r0.w, c1.z
-                mov r0.z, c1.w
-                dp3 r0.x, r0, c0
-                mad r0.y, r0.x, r0.x, -r0.w
-                abs r0.z, r0.y
-                rsq r0.z, r0.z
-                rcp r1.x, r0.z
-                mov r1.yz, -r1.x
-                add r0.xzw, r0.x, r1.xyyz
-                rcp r1.x, c1.z
-                mul r0.xzw, r0, r1.x
-                mov r1.w, c1.w
-                mad r1.xyz, r0.xzww, c0.z, r1.w
-                cmp r2.x, r1.x, r0.x, r0.w
-                cmp r0.xzw, r1.xyyz, c4.xyxy, c4.zyzw
-                mov r2.y, c3.x
-                texld r1, t0, s1
-                texld r2, r2, s0
-                mul r2.xyz, r2.w, r2
-                mul r1, r1.w, r2
-                add r0.w, r0.w, r0.x
-                cmp r0.x, r0.w, r0.x, r0.z
-                cmp r1, -r0.x, c4.z, r1
-                cmp r0, r0.y, r1, c4.z
-                mov oC0, r0
-            
-            // approximately 28 instruction slots used (2 texture, 26 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[7], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 3
-            add r0.xy, v1.zwzz, -cb0[5].xyxx
-            mov r0.z, cb0[5].w
-            dp3 r0.z, r0.xyzx, cb0[4].xyzx
-            dp2 r0.x, r0.xyxx, r0.xyxx
-            add r0.x, r0.x, -cb0[6].x
-            mul r0.x, r0.x, cb0[5].z
-            mad r0.x, r0.z, r0.z, -r0.x
-            lt r0.y, r0.x, l(0.000000)
-            sqrt r1.x, |r0.x|
-            mov r1.y, -r1.x
-            add r0.xz, r0.zzzz, r1.xxyx
-            div r0.xz, r0.xxzx, cb0[5].zzzz
-            mul r1.xy, r0.xzxx, cb0[4].zzzz
-            ge r1.xy, r1.xyxx, -cb0[5].wwww
-            and r1.xy, r1.xyxx, l(0x3f800000, 0x3f800000, 0, 0)
-            add r0.x, -r0.z, r0.x
-            mad r2.x, r1.x, r0.x, r0.z
-            mov r2.y, l(0.500000)
-            sample r2.xyzw, r2.xyxx, t0.xyzw, s0
-            if_nz r0.y
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            max r0.x, r1.y, r1.x
-            ge r0.x, l(0.000000), r0.x
-            if_nz r0.x
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            mul r2.xyz, r2.wwww, r2.xyzx
-            sample r0.xyzw, v1.xyxx, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, r2.xyzw
-            ret 
-            // Approximately 33 instruction slots used
-                    
-        };
-    }
-
-    pass A0Wrap
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44
-            //   float2 dimensions;                 // Offset:   48 Size:     8
-            //   float3 diff;                       // Offset:   64 Size:    12 [unused]
-            //   float2 center1;                    // Offset:   80 Size:     8 [unused]
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4 [unused]
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            // cb2                               cbuffer      NA          NA    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         1  ( FLT, FLT, FLT, FLT)
-            // c2         cb0             2         1  ( FLT, FLT, FLT, FLT)
-            // c3         cb1             0         2  ( FLT, FLT, FLT, FLT)
-            // c5         cb1             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c6, 1, 0.5, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad r0.xy, v0, c1.zwzw, c1
-                add r0.z, r0.x, c6.x
-                mul r0.z, r0.z, c5.x
-                mul r1.x, r0.z, c6.y
-                add r0.z, -r0.y, c6.x
-                add oPos.xy, r0, c0
-                mul r0.x, r0.z, c5.y
-                mul r1.y, r0.x, c6.y
-                mov r1.z, c6.x
-                dp3 oT0.w, r1, c3
-                dp3 oT0.z, r1, c4
-                mov oPos.zw, c6.xyzx
-            
-            // approximately 13 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_constantbuffer cb1[4], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            dcl_temps 2
-            mov o0.zw, l(0,0,0,1.000000)
-            mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.xy, r0.xyxx
-            add r0.x, r0.x, l(1.000000)
-            add r0.y, -r0.y, l(1.000000)
-            mul r0.xy, r0.xyxx, cb1[3].xyxx
-            mul r1.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
-            mov r1.z, l(1.000000)
-            dp3 o1.z, r1.xyzx, cb1[0].xyzx
-            dp3 o1.w, r1.xyzx, cb1[1].xyzx
-            mad o1.xy, v0.xyxx, cb0[2].zwzz, cb0[2].xyxx
-            ret 
-            // Approximately 12 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44 [unused]
-            //   float2 dimensions;                 // Offset:   48 Size:     8 [unused]
-            //   float3 diff;                       // Offset:   64 Size:    12
-            //   float2 center1;                    // Offset:   80 Size:     8
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sWrapSampler                      sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb2                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             4         2  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                def c2, 0.5, 0, 0, 0
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                mul r0.w, c1.w, c1.w
-                add r0.xy, t0.wzzw, -c1
-                dp2add r0.w, r0, r0, -r0.w
-                mul r0.w, r0.w, c2.x
-                mov r0.z, c1.w
-                dp3 r0.x, r0, c0
-                rcp r0.x, r0.x
-                mul r0.x, r0.x, r0.w
-                mov r0.y, c2.x
-                texld r1, t0, s1
-                texld r2, r0, s0
-                mov r0.w, c1.w
-                mad r0.x, r0.x, -c0.z, -r0.w
-                mul r2.xyz, r2.w, r2
-                mul r1, r1.w, r2
-                cmp r0, r0.x, c2.y, r1
-                mov oC0, r0
-            
-            // approximately 18 instruction slots used (2 texture, 16 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[6], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 2
-            add r0.xy, v1.zwzz, -cb0[5].xyxx
-            mov r0.z, cb0[5].w
-            dp3 r0.z, r0.xyzx, cb0[4].xyzx
-            dp2 r0.x, r0.xyxx, r0.xyxx
-            mad r0.x, -cb0[5].w, cb0[5].w, r0.x
-            mul r0.x, r0.x, l(0.500000)
-            div r0.x, r0.x, r0.z
-            mul r0.z, r0.x, cb0[4].z
-            ge r0.z, -cb0[5].w, r0.z
-            mov r0.y, l(0.500000)
-            sample r1.xyzw, r0.xyxx, t0.xyzw, s0
-            if_nz r0.z
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            mul r1.xyz, r1.wwww, r1.xyzx
-            sample r0.xyzw, v1.xyxx, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, r1.xyzw
-            ret 
-            // Approximately 19 instruction slots used
-                    
-        };
-    }
-
-    pass APosMirror
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44
-            //   float2 dimensions;                 // Offset:   48 Size:     8
-            //   float3 diff;                       // Offset:   64 Size:    12 [unused]
-            //   float2 center1;                    // Offset:   80 Size:     8 [unused]
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4 [unused]
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            // cb2                               cbuffer      NA          NA    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         1  ( FLT, FLT, FLT, FLT)
-            // c2         cb0             2         1  ( FLT, FLT, FLT, FLT)
-            // c3         cb1             0         2  ( FLT, FLT, FLT, FLT)
-            // c5         cb1             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c6, 1, 0.5, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad r0.xy, v0, c1.zwzw, c1
-                add r0.z, r0.x, c6.x
-                mul r0.z, r0.z, c5.x
-                mul r1.x, r0.z, c6.y
-                add r0.z, -r0.y, c6.x
-                add oPos.xy, r0, c0
-                mul r0.x, r0.z, c5.y
-                mul r1.y, r0.x, c6.y
-                mov r1.z, c6.x
-                dp3 oT0.w, r1, c3
-                dp3 oT0.z, r1, c4
-                mov oPos.zw, c6.xyzx
-            
-            // approximately 13 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_constantbuffer cb1[4], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            dcl_temps 2
-            mov o0.zw, l(0,0,0,1.000000)
-            mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.xy, r0.xyxx
-            add r0.x, r0.x, l(1.000000)
-            add r0.y, -r0.y, l(1.000000)
-            mul r0.xy, r0.xyxx, cb1[3].xyxx
-            mul r1.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
-            mov r1.z, l(1.000000)
-            dp3 o1.z, r1.xyzx, cb1[0].xyzx
-            dp3 o1.w, r1.xyzx, cb1[1].xyzx
-            mad o1.xy, v0.xyxx, cb0[2].zwzz, cb0[2].xyxx
-            ret 
-            // Approximately 12 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44 [unused]
-            //   float2 dimensions;                 // Offset:   48 Size:     8 [unused]
-            //   float3 diff;                       // Offset:   64 Size:    12
-            //   float2 center1;                    // Offset:   80 Size:     8
-            //   float A;                           // Offset:   88 Size:     4
-            //   float radius1;                     // Offset:   92 Size:     4
-            //   float sq_radius1;                  // Offset:   96 Size:     4
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sMirrorSampler                    sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb2                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             4         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                def c3, 0.5, 0, 0, 0
-                def c4, 1, -1, 0, -0
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                add r0.xy, t0.wzzw, -c1
-                dp2add r0.w, r0, r0, -c2.x
-                mul r0.w, r0.w, c1.z
-                mov r0.z, c1.w
-                dp3 r0.x, r0, c0
-                mad r0.y, r0.x, r0.x, -r0.w
-                abs r0.z, r0.y
-                rsq r0.z, r0.z
-                rcp r1.x, r0.z
-                mov r1.yz, -r1.x
-                add r0.xzw, r0.x, r1.xyyz
-                rcp r1.x, c1.z
-                mul r0.xzw, r0, r1.x
-                mov r1.w, c1.w
-                mad r1.xyz, r0.xzww, c0.z, r1.w
-                cmp r2.x, r1.x, r0.x, r0.w
-                cmp r0.xzw, r1.xyyz, c4.xyxy, c4.zyzw
-                mov r2.y, c3.x
-                texld r1, t0, s1
-                texld r2, r2, s0
-                mul r2.xyz, r2.w, r2
-                mul r1, r1.w, r2
-                add r0.w, r0.w, r0.x
-                cmp r0.x, r0.w, r0.x, r0.z
-                cmp r1, -r0.x, c4.z, r1
-                cmp r0, r0.y, r1, c4.z
-                mov oC0, r0
-            
-            // approximately 28 instruction slots used (2 texture, 26 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[7], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 3
-            add r0.xy, v1.zwzz, -cb0[5].xyxx
-            mov r0.z, cb0[5].w
-            dp3 r0.z, r0.xyzx, cb0[4].xyzx
-            dp2 r0.x, r0.xyxx, r0.xyxx
-            add r0.x, r0.x, -cb0[6].x
-            mul r0.x, r0.x, cb0[5].z
-            mad r0.x, r0.z, r0.z, -r0.x
-            lt r0.y, r0.x, l(0.000000)
-            sqrt r1.x, |r0.x|
-            mov r1.y, -r1.x
-            add r0.xz, r0.zzzz, r1.xxyx
-            div r0.xz, r0.xxzx, cb0[5].zzzz
-            mul r1.xy, r0.xzxx, cb0[4].zzzz
-            ge r1.xy, r1.xyxx, -cb0[5].wwww
-            and r1.xy, r1.xyxx, l(0x3f800000, 0x3f800000, 0, 0)
-            add r0.x, -r0.z, r0.x
-            mad r2.x, r1.x, r0.x, r0.z
-            mov r2.y, l(0.500000)
-            sample r2.xyzw, r2.xyxx, t0.xyzw, s0
-            if_nz r0.y
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            max r0.x, r1.y, r1.x
-            ge r0.x, l(0.000000), r0.x
-            if_nz r0.x
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            mul r2.xyz, r2.wwww, r2.xyzx
-            sample r0.xyzw, v1.xyxx, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, r2.xyzw
-            ret 
-            // Approximately 33 instruction slots used
-                    
-        };
-    }
-
-    pass A0Mirror
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44
-            //   float2 dimensions;                 // Offset:   48 Size:     8
-            //   float3 diff;                       // Offset:   64 Size:    12 [unused]
-            //   float2 center1;                    // Offset:   80 Size:     8 [unused]
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4 [unused]
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            // cb2                               cbuffer      NA          NA    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         1  ( FLT, FLT, FLT, FLT)
-            // c2         cb0             2         1  ( FLT, FLT, FLT, FLT)
-            // c3         cb1             0         2  ( FLT, FLT, FLT, FLT)
-            // c5         cb1             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c6, 1, 0.5, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad r0.xy, v0, c1.zwzw, c1
-                add r0.z, r0.x, c6.x
-                mul r0.z, r0.z, c5.x
-                mul r1.x, r0.z, c6.y
-                add r0.z, -r0.y, c6.x
-                add oPos.xy, r0, c0
-                mul r0.x, r0.z, c5.y
-                mul r1.y, r0.x, c6.y
-                mov r1.z, c6.x
-                dp3 oT0.w, r1, c3
-                dp3 oT0.z, r1, c4
-                mov oPos.zw, c6.xyzx
-            
-            // approximately 13 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_constantbuffer cb1[4], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            dcl_temps 2
-            mov o0.zw, l(0,0,0,1.000000)
-            mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.xy, r0.xyxx
-            add r0.x, r0.x, l(1.000000)
-            add r0.y, -r0.y, l(1.000000)
-            mul r0.xy, r0.xyxx, cb1[3].xyxx
-            mul r1.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
-            mov r1.z, l(1.000000)
-            dp3 o1.z, r1.xyzx, cb1[0].xyzx
-            dp3 o1.w, r1.xyzx, cb1[1].xyzx
-            mad o1.xy, v0.xyxx, cb0[2].zwzz, cb0[2].xyxx
-            ret 
-            // Approximately 12 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb2
-            // {
-            //
-            //   float3x3 DeviceSpaceToUserSpace;   // Offset:    0 Size:    44 [unused]
-            //   float2 dimensions;                 // Offset:   48 Size:     8 [unused]
-            //   float3 diff;                       // Offset:   64 Size:    12
-            //   float2 center1;                    // Offset:   80 Size:     8
-            //   float A;                           // Offset:   88 Size:     4 [unused]
-            //   float radius1;                     // Offset:   92 Size:     4
-            //   float sq_radius1;                  // Offset:   96 Size:     4 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sMirrorSampler                    sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb2                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             4         2  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                def c2, 0.5, 0, 0, 0
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                mul r0.w, c1.w, c1.w
-                add r0.xy, t0.wzzw, -c1
-                dp2add r0.w, r0, r0, -r0.w
-                mul r0.w, r0.w, c2.x
-                mov r0.z, c1.w
-                dp3 r0.x, r0, c0
-                rcp r0.x, r0.x
-                mul r0.x, r0.x, r0.w
-                mov r0.y, c2.x
-                texld r1, t0, s1
-                texld r2, r0, s0
-                mov r0.w, c1.w
-                mad r0.x, r0.x, -c0.z, -r0.w
-                mul r2.xyz, r2.w, r2
-                mul r1, r1.w, r2
-                cmp r0, r0.x, c2.y, r1
-                mov oC0, r0
-            
-            // approximately 18 instruction slots used (2 texture, 16 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[6], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 2
-            add r0.xy, v1.zwzz, -cb0[5].xyxx
-            mov r0.z, cb0[5].w
-            dp3 r0.z, r0.xyzx, cb0[4].xyzx
-            dp2 r0.x, r0.xyxx, r0.xyxx
-            mad r0.x, -cb0[5].w, cb0[5].w, r0.x
-            mul r0.x, r0.x, l(0.500000)
-            div r0.x, r0.x, r0.z
-            mul r0.z, r0.x, cb0[4].z
-            ge r0.z, -cb0[5].w, r0.z
-            mov r0.y, l(0.500000)
-            sample r1.xyzw, r0.xyxx, t0.xyzw, s0
-            if_nz r0.z
-              mov o0.xyzw, l(0,0,0,0)
-              ret 
-            endif 
-            mul r1.xyz, r1.wwww, r1.xyzx
-            sample r0.xyzw, v1.xyxx, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, r1.xyzw
-            ret 
-            // Approximately 19 instruction slots used
-                    
-        };
-    }
-
-}
-
-technique10 SampleMaskedTexture
-{
-    pass P0
-    {
-        RasterizerState = TextureRast;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sSampler                          sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                mov r0.xy, t0.wzzw
-                texld r1, t0, s0
-                texld r0, r0, s1
-                mul r0, r0.w, r1
-                mov oC0, r0
-            
-            // approximately 5 instruction slots used (2 texture, 3 arithmetic)
-            ps_4_0
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 2
-            sample r0.xyzw, v1.xyxx, t0.xyzw, s0
-            sample r1.xyzw, v1.zwzz, t1.xyzw, s1
-            mul o0.xyzw, r0.xyzw, r1.wwww
-            ret 
-            // Approximately 4 instruction slots used
-                    
-        };
-    }
-
-}
-
-technique10 SampleTextureWithShadow
-{
-    pass P0
-    {
-        RasterizerState = TextureRast;
-        AB_BlendFactor = float4(1, 1, 1, 1);
-        AB_SampleMask = uint(0xffffffff);
-        BlendState = ShadowBlendH;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb1
-            // {
-            //
-            //   float4 BlurOffsetsH[3];            // Offset:    0 Size:    48
-            //   float4 BlurOffsetsV[3];            // Offset:   48 Size:    48 [unused]
-            //   float4 BlurWeights[3];             // Offset:   96 Size:    48
-            //   float4 ShadowColor;                // Offset:  144 Size:    16
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sShadowSampler                    sampler      NA          NA    0        1
-            // tex                               texture  float4          2d    0        1
-            // cb1                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float       
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            // c3         cb0             6         4  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                add r0.x, t0.x, c0.y
-                mov r0.y, t0.y
-                add r1.x, t0.x, c0.x
-                mov r1.y, t0.y
-                texld r0, r0, s0
-                texld r1, r1, s0
-                mul r0.x, r0.w, c3.y
-                mad r0.x, c3.x, r1.w, r0.x
-                add r1.x, t0.x, c0.z
-                mov r1.y, t0.y
-                add r2.x, t0.x, c0.w
-                mov r2.y, t0.y
-                texld r1, r1, s0
-                texld r2, r2, s0
-                mad r0.x, c3.z, r1.w, r0.x
-                mad r0.x, c3.w, r2.w, r0.x
-                add r1.x, t0.x, c1.x
-                mov r1.y, t0.y
-                add r2.x, t0.x, c1.y
-                mov r2.y, t0.y
-                texld r1, r1, s0
-                texld r2, r2, s0
-                mad r0.x, c4.x, r1.w, r0.x
-                mad r0.x, c4.y, r2.w, r0.x
-                add r1.x, t0.x, c1.z
-                mov r1.y, t0.y
-                add r2.x, t0.x, c1.w
-                mov r2.y, t0.y
-                texld r1, r1, s0
-                texld r2, r2, s0
-                mad r0.x, c4.z, r1.w, r0.x
-                mad r0.x, c4.w, r2.w, r0.x
-                add r1.x, t0.x, c2.x
-                mov r1.y, t0.y
-                texld r1, r1, s0
-                mad r0.x, c5.x, r1.w, r0.x
-                mul r0, r0.x, c6
-                mov oC0, r0
-            
-            // approximately 38 instruction slots used (9 texture, 29 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[10], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_input_ps linear v1.xy
-            dcl_output o0.xyzw
-            dcl_temps 4
-            add r0.xyzw, v1.xxxx, cb0[0].zxwy
-            mov r1.xz, r0.yywy
-            mov r1.yw, v1.yyyy
-            sample r2.xyzw, r1.zwzz, t0.xyzw, s0
-            sample r1.xyzw, r1.xyxx, t0.xyzw, s0
-            mul r1.x, r2.w, cb0[6].y
-            mad r1.x, cb0[6].x, r1.w, r1.x
-            mov r0.yw, v1.yyyy
-            sample r2.xyzw, r0.xyxx, t0.xyzw, s0
-            sample r0.xyzw, r0.zwzz, t0.xyzw, s0
-            mad r0.x, cb0[6].z, r2.w, r1.x
-            mad r0.x, cb0[6].w, r0.w, r0.x
-            add r1.xyzw, v1.xxxx, cb0[1].zxwy
-            mov r2.xz, r1.yywy
-            mov r2.yw, v1.yyyy
-            sample r3.xyzw, r2.xyxx, t0.xyzw, s0
-            sample r2.xyzw, r2.zwzz, t0.xyzw, s0
-            mad r0.x, cb0[7].x, r3.w, r0.x
-            mad r0.x, cb0[7].y, r2.w, r0.x
-            mov r1.yw, v1.yyyy
-            sample r2.xyzw, r1.xyxx, t0.xyzw, s0
-            sample r1.xyzw, r1.zwzz, t0.xyzw, s0
-            mad r0.x, cb0[7].z, r2.w, r0.x
-            mad r0.x, cb0[7].w, r1.w, r0.x
-            add r1.x, v1.x, cb0[2].x
-            mov r1.y, v1.y
-            sample r1.xyzw, r1.xyxx, t0.xyzw, s0
-            mad r0.x, cb0[8].x, r1.w, r0.x
-            mul o0.xyzw, r0.xxxx, cb0[9].xyzw
-            ret 
-            // Approximately 30 instruction slots used
-                    
-        };
-    }
-
-    pass P1
-    {
-        RasterizerState = TextureRast;
-        AB_BlendFactor = float4(1, 1, 1, 1);
-        AB_SampleMask = uint(0xffffffff);
-        BlendState = ShadowBlendV;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb1
-            // {
-            //
-            //   float4 BlurOffsetsH[3];            // Offset:    0 Size:    48 [unused]
-            //   float4 BlurOffsetsV[3];            // Offset:   48 Size:    48
-            //   float4 BlurWeights[3];             // Offset:   96 Size:    48
-            //   float4 ShadowColor;                // Offset:  144 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sShadowSampler                    sampler      NA          NA    0        1
-            // tex                               texture  float4          2d    0        1
-            // cb1                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float       
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             3         6  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                add r0.y, t0.y, c0.y
-                mov r0.x, t0.x
-                add r1.y, t0.y, c0.x
-                mov r1.x, t0.x
-                texld r0, r0, s0
-                texld r1, r1, s0
-                mul r0, r0, c3.y
-                mad r0, c3.x, r1, r0
-                add r1.y, t0.y, c0.z
-                mov r1.x, t0.x
-                add r2.y, t0.y, c0.w
-                mov r2.x, t0.x
-                texld r1, r1, s0
-                texld r2, r2, s0
-                mad r0, c3.z, r1, r0
-                mad r0, c3.w, r2, r0
-                add r1.y, t0.y, c1.x
-                mov r1.x, t0.x
-                add r2.y, t0.y, c1.y
-                mov r2.x, t0.x
-                texld r1, r1, s0
-                texld r2, r2, s0
-                mad r0, c4.x, r1, r0
-                mad r0, c4.y, r2, r0
-                add r1.y, t0.y, c1.z
-                mov r1.x, t0.x
-                add r2.y, t0.y, c1.w
-                mov r2.x, t0.x
-                texld r1, r1, s0
-                texld r2, r2, s0
-                mad r0, c4.z, r1, r0
-                mad r0, c4.w, r2, r0
-                add r1.y, t0.y, c2.x
-                mov r1.x, t0.x
-                texld r1, r1, s0
-                mad r0, c5.x, r1, r0
-                mov oC0, r0
-            
-            // approximately 37 instruction slots used (9 texture, 28 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[9], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_input_ps linear v1.xy
-            dcl_output o0.xyzw
-            dcl_temps 4
-            mov r0.xz, v1.xxxx
-            add r1.xyzw, v1.yyyy, cb0[3].xzyw
-            mov r0.yw, r1.xxxz
-            sample r2.xyzw, r0.zwzz, t0.xyzw, s0
-            sample r0.xyzw, r0.xyxx, t0.xyzw, s0
-            mul r2.xyzw, r2.xyzw, cb0[6].yyyy
-            mad r0.xyzw, cb0[6].xxxx, r0.xyzw, r2.xyzw
-            mov r1.xz, v1.xxxx
-            sample r2.xyzw, r1.xyxx, t0.xyzw, s0
-            sample r1.xyzw, r1.zwzz, t0.xyzw, s0
-            mad r0.xyzw, cb0[6].zzzz, r2.xyzw, r0.xyzw
-            mad r0.xyzw, cb0[6].wwww, r1.xyzw, r0.xyzw
-            mov r1.xz, v1.xxxx
-            add r2.xyzw, v1.yyyy, cb0[4].xzyw
-            mov r1.yw, r2.xxxz
-            sample r3.xyzw, r1.xyxx, t0.xyzw, s0
-            sample r1.xyzw, r1.zwzz, t0.xyzw, s0
-            mad r0.xyzw, cb0[7].xxxx, r3.xyzw, r0.xyzw
-            mad r0.xyzw, cb0[7].yyyy, r1.xyzw, r0.xyzw
-            mov r2.xz, v1.xxxx
-            sample r1.xyzw, r2.xyxx, t0.xyzw, s0
-            sample r2.xyzw, r2.zwzz, t0.xyzw, s0
-            mad r0.xyzw, cb0[7].zzzz, r1.xyzw, r0.xyzw
-            mad r0.xyzw, cb0[7].wwww, r2.xyzw, r0.xyzw
-            add r1.y, v1.y, cb0[5].x
-            mov r1.x, v1.x
-            sample r1.xyzw, r1.xyxx, t0.xyzw, s0
-            mad o0.xyzw, cb0[8].xxxx, r1.xyzw, r0.xyzw
-            ret 
-            // Approximately 29 instruction slots used
-                    
-        };
-    }
-
-    pass P2
-    {
-        RasterizerState = TextureRast;
-        AB_BlendFactor = float4(1, 1, 1, 1);
-        AB_SampleMask = uint(0xffffffff);
-        BlendState = ShadowBlendV;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb1
-            // {
-            //
-            //   float4 BlurOffsetsH[3];            // Offset:    0 Size:    48 [unused]
-            //   float4 BlurOffsetsV[3];            // Offset:   48 Size:    48
-            //   float4 BlurWeights[3];             // Offset:   96 Size:    48
-            //   float4 ShadowColor;                // Offset:  144 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sMaskSampler                      sampler      NA          NA    0        1
-            // sShadowSampler                    sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb1                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             3         6  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t1               
-            // s1             s1              t0               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                add r0.y, t0.y, c0.y
-                mov r0.x, t0.x
-                add r1.y, t0.y, c0.x
-                mov r1.x, t0.x
-                texld r0, r0, s1
-                texld r1, r1, s1
-                mul r0, r0, c3.y
-                mad r0, c3.x, r1, r0
-                add r1.y, t0.y, c0.z
-                mov r1.x, t0.x
-                add r2.y, t0.y, c0.w
-                mov r2.x, t0.x
-                texld r1, r1, s1
-                texld r2, r2, s1
-                mad r0, c3.z, r1, r0
-                mad r0, c3.w, r2, r0
-                add r1.y, t0.y, c1.x
-                mov r1.x, t0.x
-                add r2.y, t0.y, c1.y
-                mov r2.x, t0.x
-                texld r1, r1, s1
-                texld r2, r2, s1
-                mad r0, c4.x, r1, r0
-                mad r0, c4.y, r2, r0
-                add r1.y, t0.y, c1.z
-                mov r1.x, t0.x
-                add r2.y, t0.y, c1.w
-                mov r2.x, t0.x
-                texld r1, r1, s1
-                texld r2, r2, s1
-                mad r0, c4.z, r1, r0
-                mad r0, c4.w, r2, r0
-                add r1.y, t0.y, c2.x
-                mov r1.x, t0.x
-                mov r2.xy, t0.wzzw
-                texld r1, r1, s1
-                texld r2, r2, s0
-                mad r0, c5.x, r1, r0
-                mul r0, r2.w, r0
-                mov oC0, r0
-            
-            // approximately 40 instruction slots used (10 texture, 30 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[9], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_temps 4
-            mov r0.xz, v1.xxxx
-            add r1.xyzw, v1.yyyy, cb0[3].xzyw
-            mov r0.yw, r1.xxxz
-            sample r2.xyzw, r0.zwzz, t0.xyzw, s1
-            sample r0.xyzw, r0.xyxx, t0.xyzw, s1
-            mul r2.xyzw, r2.xyzw, cb0[6].yyyy
-            mad r0.xyzw, cb0[6].xxxx, r0.xyzw, r2.xyzw
-            mov r1.xz, v1.xxxx
-            sample r2.xyzw, r1.xyxx, t0.xyzw, s1
-            sample r1.xyzw, r1.zwzz, t0.xyzw, s1
-            mad r0.xyzw, cb0[6].zzzz, r2.xyzw, r0.xyzw
-            mad r0.xyzw, cb0[6].wwww, r1.xyzw, r0.xyzw
-            mov r1.xz, v1.xxxx
-            add r2.xyzw, v1.yyyy, cb0[4].xzyw
-            mov r1.yw, r2.xxxz
-            sample r3.xyzw, r1.xyxx, t0.xyzw, s1
-            sample r1.xyzw, r1.zwzz, t0.xyzw, s1
-            mad r0.xyzw, cb0[7].xxxx, r3.xyzw, r0.xyzw
-            mad r0.xyzw, cb0[7].yyyy, r1.xyzw, r0.xyzw
-            mov r2.xz, v1.xxxx
-            sample r1.xyzw, r2.xyxx, t0.xyzw, s1
-            sample r2.xyzw, r2.zwzz, t0.xyzw, s1
-            mad r0.xyzw, cb0[7].zzzz, r1.xyzw, r0.xyzw
-            mad r0.xyzw, cb0[7].wwww, r2.xyzw, r0.xyzw
-            add r1.y, v1.y, cb0[5].x
-            mov r1.x, v1.x
-            sample r1.xyzw, r1.xyxx, t0.xyzw, s1
-            mad r0.xyzw, cb0[8].xxxx, r1.xyzw, r0.xyzw
-            sample r1.xyzw, v1.zwzz, t1.xyzw, s0
-            mul o0.xyzw, r0.xyzw, r1.wwww
-            ret 
-            // Approximately 31 instruction slots used
-                    
-        };
-    }
-
-}
-
-technique10 SampleTextTexture
-{
-    pass Unmasked
-    {
-        AB_BlendFactor = float4(0, 0, 0, 0);
-        AB_SampleMask = uint(0xffffffff);
-        BlendState = bTextBlend;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16 [unused]
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16 [unused]
-            //   float4 TextColor;                  // Offset:   48 Size:    16
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sSampler                          sampler      NA          NA    0        1
-            // tex                               texture  float4          2d    0        1
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float       
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            // SV_Target                1   xyzw        1   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                mov oC0, c0
-                texld r0, t0, s0
-                mul r0, r0.zyxy, c0.w
-                mov oC1, r0
-            
-            // approximately 4 instruction slots used (1 texture, 3 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[4], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_input_ps linear v1.xy
-            dcl_output o0.xyzw
-            dcl_output o1.xyzw
-            dcl_temps 1
-            mov o0.xyzw, cb0[3].xyzw
-            sample r0.xyzw, v1.xyxx, t0.xyzw, s0
-            mul o1.xyzw, r0.zyxy, cb0[3].wwww
-            ret 
-            // Approximately 4 instruction slots used
-                    
-        };
-    }
-
-    pass Masked
-    {
-        AB_BlendFactor = float4(0, 0, 0, 0);
-        AB_SampleMask = uint(0xffffffff);
-        BlendState = bTextBlend;
-        VertexShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16
-            //   float4 TexCoords;                  // Offset:   16 Size:    16
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16
-            //   float4 TextColor;                  // Offset:   48 Size:    16 [unused]
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // POSITION                 0   xyz         0     NONE  float   xy  
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float   xyzw
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c1         cb0             0         3  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Runtime generated constant mappings:
-            //
-            // Target Reg                               Constant Description
-            // ---------- --------------------------------------------------
-            // c0                              Vertex Shader position offset
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                vs_2_x
-                def c4, 0, 1, 0, 0
-                dcl_texcoord v0
-                mad oT0.xy, v0, c2.zwzw, c2
-                mad oT0.zw, v0.xyyx, c3.xywz, c3.xyyx
-                mad r0.xy, v0, c1.zwzw, c1
-                add oPos.xy, r0, c0
-                mov oPos.zw, c4.xyxy
-            
-            // approximately 5 instruction slots used
-            vs_4_0
-            dcl_constantbuffer cb0[3], immediateIndexed
-            dcl_input v0.xy
-            dcl_output_siv o0.xyzw, position
-            dcl_output o1.xy
-            dcl_output o1.zw
-            mad o0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
-            mov o0.zw, l(0,0,0,1.000000)
-            mad o1.xy, v0.xyxx, cb0[1].zwzz, cb0[1].xyxx
-            mad o1.zw, v0.xxxy, cb0[2].zzzw, cb0[2].xxxy
-            ret 
-            // Approximately 5 instruction slots used
-                    
-        };
-        GeometryShader = NULL;
-        PixelShader = asm {
-            //
-            // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
-            //
-            //
-            // Buffer Definitions: 
-            //
-            // cbuffer cb0
-            // {
-            //
-            //   float4 QuadDesc;                   // Offset:    0 Size:    16 [unused]
-            //   float4 TexCoords;                  // Offset:   16 Size:    16 [unused]
-            //   float4 MaskTexCoords;              // Offset:   32 Size:    16 [unused]
-            //   float4 TextColor;                  // Offset:   48 Size:    16
-            //
-            // }
-            //
-            //
-            // Resource Bindings:
-            //
-            // Name                                 Type  Format         Dim Slot Elements
-            // ------------------------------ ---------- ------- ----------- ---- --------
-            // sSampler                          sampler      NA          NA    0        1
-            // sMaskSampler                      sampler      NA          NA    1        1
-            // tex                               texture  float4          2d    0        1
-            // mask                              texture  float4          2d    1        1
-            // cb0                               cbuffer      NA          NA    0        1
-            //
-            //
-            //
-            // Input signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Position              0   xyzw        0      POS  float       
-            // TEXCOORD                 0   xy          1     NONE  float   xy  
-            // TEXCOORD                 1     zw        1     NONE  float     zw
-            //
-            //
-            // Output signature:
-            //
-            // Name                 Index   Mask Register SysValue Format   Used
-            // -------------------- ----- ------ -------- -------- ------ ------
-            // SV_Target                0   xyzw        0   TARGET  float   xyzw
-            // SV_Target                1   xyzw        1   TARGET  float   xyzw
-            //
-            //
-            // Constant buffer to DX9 shader constant mappings:
-            //
-            // Target Reg Buffer  Start Reg # of Regs        Data Conversion
-            // ---------- ------- --------- --------- ----------------------
-            // c0         cb0             3         1  ( FLT, FLT, FLT, FLT)
-            //
-            //
-            // Sampler/Resource to DX9 shader sampler mappings:
-            //
-            // Target Sampler Source Sampler  Source Resource
-            // -------------- --------------- ----------------
-            // s0             s0              t0               
-            // s1             s1              t1               
-            //
-            //
-            // Level9 shader bytecode:
-            //
-                ps_2_x
-                dcl t0
-                dcl_2d s0
-                dcl_2d s1
-                mov r0.xy, t0.wzzw
-                texld r1, t0, s0
-                texld r0, r0, s1
-                mul r2, r0.w, c0
-                mov oC0, r2
-                mul r1, r1.zyxy, c0.w
-                mul r0, r0.w, r1
-                mov oC1, r0
-            
-            // approximately 8 instruction slots used (2 texture, 6 arithmetic)
-            ps_4_0
-            dcl_constantbuffer cb0[4], immediateIndexed
-            dcl_sampler s0, mode_default
-            dcl_sampler s1, mode_default
-            dcl_resource_texture2d (float,float,float,float) t0
-            dcl_resource_texture2d (float,float,float,float) t1
-            dcl_input_ps linear v1.xy
-            dcl_input_ps linear v1.zw
-            dcl_output o0.xyzw
-            dcl_output o1.xyzw
-            dcl_temps 2
-            sample r0.xyzw, v1.zwzz, t1.xyzw, s1
-            mul o0.xyzw, r0.wwww, cb0[3].xyzw
-            sample r1.xyzw, v1.xyxx, t0.xyzw, s0
-            mul r1.xyzw, r1.zyxy, cb0[3].wwww
-            mul o1.xyzw, r0.wwww, r1.xyzw
-            ret 
-            // Approximately 6 instruction slots used
-                    
-        };
-    }
-
-}
-
-#endif
-
-const BYTE d2deffect[] =
-{
-     68,  88,  66,  67,  19, 211, 
-     25,  11, 246, 253,  65, 136, 
-    245,  66, 166, 250, 155,   0, 
-    197,  65,   1,   0,   0,   0, 
-    240, 190,   0,   0,   1,   0, 
-      0,   0,  36,   0,   0,   0, 
-     70,  88,  49,  48, 196, 190, 
-      0,   0,   1,  16, 255, 254, 
-      3,   0,   0,   0,  15,   0, 
-      0,   0,  11,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      5,   0,   0,   0,   4, 180, 
-      0,   0,   0,   0,   0,   0, 
-      2,   0,   0,   0,   0,   0, 
-      0,   0,   3,   0,   0,   0, 
-      1,   0,   0,   0,   5,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,  26,   0, 
-      0,   0,  26,   0,   0,   0, 
-      0,   0,   0,   0,  99,  98, 
-     48,   0, 102, 108, 111,  97, 
-    116,  52,   0,   8,   0,   0, 
-      0,   1,   0,   0,   0,   0, 
-      0,   0,   0,  16,   0,   0, 
-      0,  16,   0,   0,   0,  16, 
-      0,   0,   0,  10,  33,   0, 
-      0,  81, 117,  97, 100,  68, 
-    101, 115,  99,   0,  84, 101, 
-    120,  67, 111, 111, 114, 100, 
-    115,   0,  77,  97, 115, 107, 
-     84, 101, 120,  67, 111, 111, 
-    114, 100, 115,   0,  84, 101, 
-    120, 116,  67, 111, 108, 111, 
-    114,   0,  99,  98,  49,   0, 
-      8,   0,   0,   0,   1,   0, 
-      0,   0,   3,   0,   0,   0, 
-     48,   0,   0,   0,  16,   0, 
-      0,   0,  48,   0,   0,   0, 
-     10,  33,   0,   0,  66, 108, 
-    117, 114,  79, 102, 102, 115, 
-    101, 116, 115,  72,   0,  66, 
-    108, 117, 114,  79, 102, 102, 
-    115, 101, 116, 115,  86,   0, 
-     66, 108, 117, 114,  87, 101, 
-    105, 103, 104, 116, 115,   0, 
-     83, 104,  97, 100, 111, 119, 
-     67, 111, 108, 111, 114,   0, 
-     99,  98,  50,   0, 102, 108, 
-    111,  97, 116,  51, 120,  51, 
-      0, 172,   0,   0,   0,   1, 
-      0,   0,   0,   0,   0,   0, 
-      0,  44,   0,   0,   0,  48, 
-      0,   0,   0,  36,   0,   0, 
-      0,  11,  91,   0,   0,  68, 
-    101, 118, 105,  99, 101,  83, 
-    112,  97,  99, 101,  84, 111, 
-     85, 115, 101, 114,  83, 112, 
-     97,  99, 101,   0, 102, 108, 
-    111,  97, 116,  50,   0, 232, 
-      0,   0,   0,   1,   0,   0, 
-      0,   0,   0,   0,   0,   8, 
-      0,   0,   0,  16,   0,   0, 
-      0,   8,   0,   0,   0,  10, 
-     17,   0,   0, 100, 105, 109, 
-    101, 110, 115, 105, 111, 110, 
-    115,   0, 102, 108, 111,  97, 
-    116,  51,   0,  22,   1,   0, 
-      0,   1,   0,   0,   0,   0, 
-      0,   0,   0,  12,   0,   0, 
-      0,  16,   0,   0,   0,  12, 
-      0,   0,   0,  10,  25,   0, 
-      0, 100, 105, 102, 102,   0, 
-     99, 101, 110, 116, 101, 114, 
-     49,   0, 102, 108, 111,  97, 
-    116,   0,  70,   1,   0,   0, 
-      1,   0,   0,   0,   0,   0, 
-      0,   0,   4,   0,   0,   0, 
-     16,   0,   0,   0,   4,   0, 
-      0,   0,   9,   9,   0,   0, 
-     65,   0, 114,  97, 100, 105, 
-    117, 115,  49,   0, 115, 113, 
-     95, 114,  97, 100, 105, 117, 
-    115,  49,   0,  84, 101, 120, 
-    116, 117, 114, 101,  50,  68, 
-      0, 125,   1,   0,   0,   2, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,  12,   0,   0,   0, 116, 
-    101, 120,   0, 109,  97, 115, 
-    107,   0,  83,  97, 109, 112, 
-    108, 101, 114,  83, 116,  97, 
-    116, 101,   0, 172,   1,   0, 
-      0,   2,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,  21,   0,   0, 
-      0, 115,  83,  97, 109, 112, 
-    108, 101, 114,   0,   1,   0, 
-      0,   0,   2,   0,   0,   0, 
-     21,   0,   0,   0,   1,   0, 
-      0,   0,   2,   0,   0,   0, 
-      3,   0,   0,   0,   1,   0, 
-      0,   0,   2,   0,   0,   0, 
-      3,   0,   0,   0, 115,  87, 
-    114,  97, 112,  83,  97, 109, 
-    112, 108, 101, 114,   0,   1, 
-      0,   0,   0,   2,   0,   0, 
-      0,  21,   0,   0,   0,   1, 
-      0,   0,   0,   2,   0,   0, 
-      0,   1,   0,   0,   0,   1, 
-      0,   0,   0,   2,   0,   0, 
-      0,   1,   0,   0,   0, 115, 
-     77, 105, 114, 114, 111, 114, 
-     83,  97, 109, 112, 108, 101, 
-    114,   0,   1,   0,   0,   0, 
-      2,   0,   0,   0,  21,   0, 
-      0,   0,   1,   0,   0,   0, 
-      2,   0,   0,   0,   2,   0, 
-      0,   0,   1,   0,   0,   0, 
-      2,   0,   0,   0,   2,   0, 
-      0,   0, 115,  77,  97, 115, 
-    107,  83,  97, 109, 112, 108, 
-    101, 114,   0,   1,   0,   0, 
-      0,   2,   0,   0,   0,  21, 
-      0,   0,   0,   1,   0,   0, 
-      0,   2,   0,   0,   0,   3, 
-      0,   0,   0,   1,   0,   0, 
-      0,   2,   0,   0,   0,   3, 
-      0,   0,   0, 115,  83, 104, 
-     97, 100, 111, 119,  83,  97, 
-    109, 112, 108, 101, 114,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,  21,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   4,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   4,   0,   0,   0, 
-      4,   0,   0,   0,   1,   0, 
-      0,   0,   0,   0,   0,   0, 
-      1,   0,   0,   0,   0,   0, 
-      0,   0,   1,   0,   0,   0, 
-      0,   0,   0,   0,   1,   0, 
-      0,   0,   0,   0,   0,   0, 
-     82,  97, 115, 116, 101, 114, 
-    105, 122, 101, 114,  83, 116, 
-     97, 116, 101,   0, 238,   2, 
-      0,   0,   2,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   4,   0, 
-      0,   0,  84, 101, 120, 116, 
-    117, 114, 101,  82,  97, 115, 
-    116,   0,   1,   0,   0,   0, 
-      2,   0,   0,   0,   0,   0, 
-      0,   0,   1,   0,   0,   0, 
-      2,   0,   0,   0,   1,   0, 
-      0,   0,  66, 108, 101, 110, 
-    100,  83, 116,  97, 116, 101, 
-      0,  62,   3,   0,   0,   2, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   2,   0,   0,   0,  83, 
-    104,  97, 100, 111, 119,  66, 
-    108, 101, 110, 100,  72,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   0,   0,   0,   0, 
-      1,   0,   0,   0,   3,   0, 
-      0,   0,  15,   0,   0,   0, 
-     83, 104,  97, 100, 111, 119, 
-     66, 108, 101, 110, 100,  86, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   1,   0,   0, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   2,   0,   0, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   6,   0,   0, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   1,   0,   0, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   2,   0,   0, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   6,   0,   0, 
-      0,   1,   0,   0,   0,   2, 
-      0,   0,   0,   1,   0,   0, 
-      0,   1,   0,   0,   0,   3, 
-      0,   0,   0,  15,   0,   0, 
-      0,  98,  84, 101, 120, 116, 
-     66, 108, 101, 110, 100,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   0,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   1,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,  16,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,  17,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   1,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,  18,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,  19,   0,   0,   0, 
-      1,   0,   0,   0,   2,   0, 
-      0,   0,   1,   0,   0,   0, 
-      1,   0,   0,   0,   3,   0, 
-      0,   0,  15,   0,   0,   0, 
-     83,  97, 109, 112, 108, 101, 
-     84, 101, 120, 116, 117, 114, 
-    101,   0,  80,  48,   0,  68, 
-      4,   0,   0,  68,  88,  66, 
-     67,  26, 214, 157, 140, 185, 
-     91, 182, 211, 177, 171, 114, 
-    225, 174, 107,  56, 117,   1, 
-      0,   0,   0,  68,   4,   0, 
-      0,   6,   0,   0,   0,  56, 
-      0,   0,   0, 248,   0,   0, 
-      0, 244,   1,   0,   0, 112, 
-      2,   0,   0, 160,   3,   0, 
-      0, 212,   3,   0,   0,  65, 
-    111, 110,  57, 184,   0,   0, 
-      0, 184,   0,   0,   0,   0, 
-      2, 254, 255, 132,   0,   0, 
-      0,  52,   0,   0,   0,   1, 
-      0,  36,   0,   0,   0,  48, 
-      0,   0,   0,  48,   0,   0, 
-      0,  36,   0,   1,   0,  48, 
-      0,   0,   0,   0,   0,   3, 
-      0,   1,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   1, 
-      2, 254, 255,  81,   0,   0, 
-      5,   4,   0,  15, 160,   0, 
-      0,   0,   0,   0,   0, 128, 
-     63,   0,   0,   0,   0,   0, 
-      0,   0,   0,  31,   0,   0, 
-      2,   5,   0,   0, 128,   0, 
-      0,  15, 144,   4,   0,   0, 
-      4,   0,   0,   3, 224,   0, 
-      0, 228, 144,   2,   0, 238, 
-    160,   2,   0, 228, 160,   4, 
-      0,   0,   4,   0,   0,  12, 
-    224,   0,   0,  20, 144,   3, 
-      0, 180, 160,   3,   0,  20, 
-    160,   4,   0,   0,   4,   0, 
-      0,   3, 128,   0,   0, 228, 
-    144,   1,   0, 238, 160,   1, 
-      0, 228, 160,   2,   0,   0, 
-      3,   0,   0,   3, 192,   0, 
-      0, 228, 128,   0,   0, 228, 
-    160,   1,   0,   0,   2,   0, 
-      0,  12, 192,   4,   0,  68, 
-    160, 255, 255,   0,   0,  83, 
-     72,  68,  82, 244,   0,   0, 
-      0,  64,   0,   1,   0,  61, 
-      0,   0,   0,  89,   0,   0, 
-      4,  70, 142,  32,   0,   0, 
-      0,   0,   0,   3,   0,   0, 
-      0,  95,   0,   0,   3,  50, 
-     16,  16,   0,   0,   0,   0, 
-      0, 103,   0,   0,   4, 242, 
-     32,  16,   0,   0,   0,   0, 
-      0,   1,   0,   0,   0, 101, 
-      0,   0,   3,  50,  32,  16, 
-      0,   1,   0,   0,   0, 101, 
-      0,   0,   3, 194,  32,  16, 
-      0,   1,   0,   0,   0,  50, 
-      0,   0,  11,  50,  32,  16, 
-      0,   0,   0,   0,   0,  70, 
-     16,  16,   0,   0,   0,   0, 
-      0, 230, 138,  32,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,  70, 128,  32,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,  54,   0,   0,   8, 194, 
-     32,  16,   0,   0,   0,   0, 
-      0,   2,  64,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0, 128,  63,  50,   0,   0, 
-     11,  50,  32,  16,   0,   1, 
-      0,   0,   0,  70,  16,  16, 
-      0,   0,   0,   0,   0, 230, 
-    138,  32,   0,   0,   0,   0, 
-      0,   1,   0,   0,   0,  70, 
-    128,  32,   0,   0,   0,   0, 
-      0,   1,   0,   0,   0,  50, 
-      0,   0,  11, 194,  32,  16, 
-      0,   1,   0,   0,   0,   6, 
-     20,  16,   0,   0,   0,   0, 
-      0, 166, 142,  32,   0,   0, 
-      0,   0,   0,   2,   0,   0, 
-      0,   6, 132,  32,   0,   0, 
-      0,   0,   0,   2,   0,   0, 
-      0,  62,   0,   0,   1,  83, 
-     84,  65,  84, 116,   0,   0, 
-      0,   5,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   4,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   1, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   1, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,  82,  68,  69, 
-     70,  40,   1,   0,   0,   1, 
-      0,   0,   0,  64,   0,   0, 
-      0,   1,   0,   0,   0,  28, 
-      0,   0,   0,   0,   4, 254, 
-    255,   0,   1,   0,   0, 246, 
-      0,   0,   0,  60,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   1,   0,   0, 
-      0,   0,   0,   0,   0,  99, 
-     98,  48,   0,  60,   0,   0, 
-      0,   4,   0,   0,   0,  88, 
-      0,   0,   0,  64,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0, 184,   0,   0, 
-      0,   0,   0,   0,   0,  16, 
-      0,   0,   0,   2,   0,   0, 
-      0, 196,   0,   0,   0,   0, 
-      0,   0,   0, 212,   0,   0, 
-      0,  16,   0,   0,   0,  16, 
-      0,   0,   0,   2,   0,   0, 
-      0, 196,   0,   0,   0,   0, 
-      0,   0,   0, 222,   0,   0, 
-      0,  32,   0,   0,   0,  16, 
-      0,   0,   0,   2,   0,   0, 
-      0, 196,   0,   0,   0,   0, 
-      0,   0,   0, 236,   0,   0, 
-      0,  48,   0,   0,   0,  16, 
-      0,   0,   0,   0,   0,   0, 
-      0, 196,   0,   0,   0,   0, 
-      0,   0,   0,  81, 117,  97, 
-    100,  68, 101, 115,  99,   0, 
-    171, 171, 171,   1,   0,   3, 
-      0,   1,   0,   4,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,  84, 101, 120,  67, 111, 
-    111, 114, 100, 115,   0,  77, 
-     97, 115, 107,  84, 101, 120, 
-     67, 111, 111, 114, 100, 115, 
-      0,  84, 101, 120, 116,  67, 
-    111, 108, 111, 114,   0,  77, 
-    105,  99, 114, 111, 115, 111, 
-    102, 116,  32,  40,  82,  41, 
-     32,  72,  76,  83,  76,  32, 
-     83, 104,  97, 100, 101, 114, 
-     32,  67, 111, 109, 112, 105, 
-    108, 101, 114,  32,  57,  46, 
-     50,  57,  46,  57,  53,  50, 
-     46,  51,  49,  49,  49,   0, 
-    171,  73,  83,  71,  78,  44, 
-      0,   0,   0,   1,   0,   0, 
-      0,   8,   0,   0,   0,  32, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   3, 
-      0,   0,   0,   0,   0,   0, 
-      0,   7,   3,   0,   0,  80, 
-     79,  83,  73,  84,  73,  79, 
-     78,   0, 171, 171, 171,  79, 
-     83,  71,  78, 104,   0,   0, 
-      0,   3,   0,   0,   0,   8, 
-      0,   0,   0,  80,   0,   0, 
-      0,   0,   0,   0,   0,   1, 
-      0,   0,   0,   3,   0,   0, 
-      0,   0,   0,   0,   0,  15, 
-      0,   0,   0,  92,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   3,   0,   0, 
-      0,   1,   0,   0,   0,   3, 
-     12,   0,   0,  92,   0,   0, 
-      0,   1,   0,   0,   0,   0, 
-      0,   0,   0,   3,   0,   0, 
-      0,   1,   0,   0,   0,  12, 
-      3,   0,   0,  83,  86,  95, 
-     80, 111, 115, 105, 116, 105, 
-    111, 110,   0,  84,  69,  88, 
-     67,  79,  79,  82,  68,   0, 
-    171, 171, 171, 127,   4,   0, 
-      0,   0,   0,   0,   0,   1, 
-      0,   0,   0,   2,   0,   0, 
-      0,   0,   0,   0,   0, 212, 
-      2,   0,   0,  68,  88,  66, 
-     67,  22, 206,  82, 103, 196, 
-    235,  84, 233, 156,  39, 210, 
-    152,  32, 145, 169, 162,   1, 
-      0,   0,   0, 212,   2,   0, 
-      0,   6,   0,   0,   0,  56, 
-      0,   0,   0, 164,   0,   0, 
-      0,  16,   1,   0,   0, 140, 
-      1,   0,   0,  48,   2,   0, 
-      0, 160,   2,   0,   0,  65, 
-    111, 110,  57, 100,   0,   0, 
-      0, 100,   0,   0,   0,   0, 
-      2, 255, 255,  60,   0,   0, 
-      0,  40,   0,   0,   0,   0, 
-      0,  40,   0,   0,   0,  40, 
-      0,   0,   0,  40,   0,   1, 
-      0,  36,   0,   0,   0,  40, 
-      0,   0,   0,   0,   0,   1, 
-      2, 255, 255,  31,   0,   0, 
-      2,   0,   0,   0, 128,   0, 
-      0,  15, 176,  31,   0,   0, 
-      2,   0,   0,   0, 144,   0, 
-      8,  15, 160,  66,   0,   0, 
-      3,   0,   0,  15, 128,   0, 
-      0, 228, 176,   0,   8, 228, 
-    160,   1,   0,   0,   2,   0, 
-      8,  15, 128,   0,   0, 228, 
-    128, 255, 255,   0,   0,  83, 
-     72,  68,  82, 100,   0,   0, 
-      0,  64,   0,   0,   0,  25, 
-      0,   0,   0,  90,   0,   0, 
-      3,   0,  96,  16,   0,   0, 
-      0,   0,   0,  88,  24,   0, 
-      4,   0, 112,  16,   0,   0, 
-      0,   0,   0,  85,  85,   0, 
-      0,  98,  16,   0,   3,  50, 
-     16,  16,   0,   1,   0,   0, 
-      0, 101,   0,   0,   3, 242, 
-     32,  16,   0,   0,   0,   0, 
-      0,  69,   0,   0,   9, 242, 
-     32,  16,   0,   0,   0,   0, 
-      0,  70,  16,  16,   0,   1, 
-      0,   0,   0,  70, 126,  16, 
-      0,   0,   0,   0,   0,   0, 
-     96,  16,   0,   0,   0,   0, 
-      0,  62,   0,   0,   1,  83, 
-     84,  65,  84, 116,   0,   0, 
-      0,   2,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   2,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   1, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   1,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,  82,  68,  69, 
-     70, 156,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   2,   0,   0,   0,  28, 
-      0,   0,   0,   0,   4, 255, 
-    255,   0,   1,   0,   0, 105, 
-      0,   0,   0,  92,   0,   0, 
-      0,   3,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   1,   0,   0, 
-      0,   0,   0,   0,   0, 101, 
-      0,   0,   0,   2,   0,   0, 
-      0,   5,   0,   0,   0,   4, 
-      0,   0,   0, 255, 255, 255, 
-    255,   0,   0,   0,   0,   1, 
-      0,   0,   0,  12,   0,   0, 
-      0, 115,  83,  97, 109, 112, 
-    108, 101, 114,   0, 116, 101, 
-    120,   0,  77, 105,  99, 114, 
-    111, 115, 111, 102, 116,  32, 
-     40,  82,  41,  32,  72,  76, 
-     83,  76,  32,  83, 104,  97, 
-    100, 101, 114,  32,  67, 111, 
-    109, 112, 105, 108, 101, 114, 
-     32,  57,  46,  50,  57,  46, 
-     57,  53,  50,  46,  51,  49, 
-     49,  49,   0, 171, 171,  73, 
-     83,  71,  78, 104,   0,   0, 
-      0,   3,   0,   0,   0,   8, 
-      0,   0,   0,  80,   0,   0, 
-      0,   0,   0,   0,   0,   1, 
-      0,   0,   0,   3,   0,   0, 
-      0,   0,   0,   0,   0,  15, 
-      0,   0,   0,  92,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   0,   0,   3,   0,   0, 
-      0,   1,   0,   0,   0,   3, 
-      3,   0,   0,  92,   0,   0, 
-      0,   1,   0,   0,   0,   0, 
-      0,   0,   0,   3,   0,   0, 
-      0,   1,   0,   0,   0,  12, 
-      0,   0,   0,  83,  86,  95, 
-     80, 111, 115, 105, 116, 105, 
-    111, 110,   0,  84,  69,  88, 
-     67,  79,  79,  82,  68,   0, 
-    171, 171, 171,  79,  83,  71, 
-     78,  44,   0,   0,   0,   1, 
-      0,   0,   0,   8,   0,   0, 
-      0,  32,   0,   0,   0,   0, 
-      0,   0,   0,   0,   0,   0, 
-      0,   3,   0,   0,   0,   0, 
-      0,   0,   0,  15,   0,   0, 
-      0,  83,  86,  95,  84,  97, 
-    114, 103, 101, 116,   0, 171, 
-    171, 219,   8,   0,   0,   0, 
-      0,   0,   0,  83,  97, 109, 
-    112, 108, 101,  82,  97, 100, 
-    105,  97, 108,  71, 114,  97, 
-    100, 105, 101, 110, 116,   0, 
-     65,  80, 111, 115,   0,  40, 
-      7,   0,   0,  68,  88,  66, 
-     67, 237,  58, 124, 168, 122, 
-    234, 242,   5,  75,  29, 195, 
-      6, 241, 206, 131, 117,   1, 
-      0,   0,   0,  40,   7,   0, 
-      0,   6,   0,   0,   0,  56, 
-      0,   0,   0, 148,   1,   0, 
-      0, 104,   3,   0,   0, 228, 
-      3,   0,   0, 132,   6,   0, 
-      0, 184,   6,   0,   0,  65, 
-    111, 110,  57,  84,   1,   0, 
-      0,  84,   1,   0,   0,   0, 
-      2, 254, 255, 252,   0,   0,