Bug 1086684 - Stash the full path for file inputs to avoid doing IPC at inopportune times. r=ehsan
☠☠ backed out by 2fd02f191756 ☠ ☠
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 20 Mar 2015 12:04:58 -0700
changeset 252102 5832c2042614f3831651193058847ce485e5e5c1
parent 252101 ca7617c40ed6293e14bfd631d43fc6c7959d79bf
child 252103 992c504934d3cd580a0239983e0926bae8007b99
push id1174
push usernsm.nikhil@gmail.com
push dateSun, 22 Mar 2015 01:24:25 +0000
reviewersehsan
bugs1086684
milestone39.0a1
Bug 1086684 - Stash the full path for file inputs to avoid doing IPC at inopportune times. r=ehsan
dom/html/HTMLInputElement.cpp
dom/html/HTMLInputElement.h
dom/html/moz.build
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -1,9 +1,10 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
 /* 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/. */
 
 #include "mozilla/dom/HTMLInputElement.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/AsyncEventDispatcher.h"
@@ -1686,22 +1687,21 @@ HTMLInputElement::GetValueInternal(nsASt
         mInputData.mState->GetValue(aValue, true);
       } else {
         aValue.Assign(mInputData.mValue);
       }
       return NS_OK;
 
     case VALUE_MODE_FILENAME:
       if (nsContentUtils::IsCallerChrome()) {
-        if (!mFiles.IsEmpty()) {
-          return mFiles[0]->GetMozFullPath(aValue);
-        }
-        else {
-          aValue.Truncate();
-        }
+#ifndef MOZ_CHILD_PERMISSIONS
+        aValue.Assign(mFirstFilePath);
+#else
+        MOZ_ASSERT_UNREACHABLE("This doesn't happen with a sane security model");
+#endif
       } else {
         // Just return the leaf name
         if (mFiles.IsEmpty() || NS_FAILED(mFiles[0]->GetName(aValue))) {
           aValue.Truncate();
         }
       }
 
       return NS_OK;
@@ -2641,16 +2641,29 @@ HTMLInputElement::AfterSetFiles(bool aSe
   // new value.  We just want the display to update as needed.
   nsIFormControlFrame* formControlFrame = GetFormControlFrame(false);
   if (formControlFrame) {
     nsAutoString readableValue;
     GetDisplayFileName(readableValue);
     formControlFrame->SetFormProperty(nsGkAtoms::value, readableValue);
   }
 
+#ifndef MOZ_CHILD_PERMISSIONS
+  // Grab the full path here for any chrome callers who access our .value via a
+  // CPOW. This path won't be called from a CPOW meaning the potential sync IPC
+  // call under GetMozFullPath won't be rejected for not being urgent.
+  // XXX Protected by the ifndef because the blob code doesn't allow us to send
+  // this message in b2g.
+  if (mFiles.IsEmpty()) {
+    mFirstFilePath.Truncate();
+  } else {
+    mFiles[0]->GetMozFullPath(mFirstFilePath);
+  }
+#endif
+
   UpdateFileList();
 
   if (aSetValueChanged) {
     SetValueChanged(true);
   }
 
   UpdateAllValidityStates(true);
 }
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -1249,28 +1249,34 @@ protected:
      * The current value of the input if it has been changed from the default
      */
     char16_t*               mValue;
     /**
      * The state of the text editor associated with the text/password input
      */
     nsTextEditorState*       mState;
   } mInputData;
+
   /**
    * The value of the input if it is a file input. This is the list of filenames
    * used when uploading a file. It is vital that this is kept separate from
    * mValue so that it won't be possible to 'leak' the value from a text-input
    * to a file-input. Additionally, the logic for this value is kept as simple
    * as possible to avoid accidental errors where the wrong filename is used.
    * Therefor the list of filenames is always owned by this member, never by
    * the frame. Whenever the frame wants to change the filename it has to call
    * SetFileNames to update this member.
    */
   nsTArray<nsRefPtr<File>> mFiles;
 
+  /**
+   * Hack for bug 1086684: Stash the .value when we're a file picker.
+   */
+  nsString mFirstFilePath;
+
   nsRefPtr<FileList>  mFileList;
 
   nsRefPtr<DirPickerFileListBuilderTask> mDirPickerFileListBuilderTask;
 
   nsString mStaticDocFileList;
   
   /** 
    * The value of the input element when first initialized and it is updated
--- a/dom/html/moz.build
+++ b/dom/html/moz.build
@@ -239,9 +239,12 @@ LOCAL_INCLUDES += [
     '/layout/forms',
     '/layout/generic',
     '/layout/style',
     '/layout/tables',
     '/layout/xul',
     '/netwerk/base',
 ]
 
+if CONFIG['MOZ_CHILD_PERMISSIONS']:
+    DEFINES['MOZ_CHILD_PERMISSIONS'] = True
+
 FINAL_LIBRARY = 'xul'