Permalink
Browse files

.: FormController, WebHistoryItem: Enable reading selected file names…

… from document state


https://bugs.webkit.org/show_bug.cgi?id=91231

Patch by Marja Hölttä <marja@chromium.org> on 2012-08-16
Reviewed by Jochen Eisinger.

This change enables Chromium to set up file permissions properly when
the session restore feature restores a page with selected files.

* Source/autotools/symbols.filter: Exported FormController::getReferencedFilePaths and HistoryController::saveDocumentAndScrollState.

Source/WebCore: FormController, FileInputType: Enable reading selected file names from document state
https://bugs.webkit.org/show_bug.cgi?id=91231

Patch by Marja Hölttä <marja@chromium.org> on 2012-08-16
Reviewed by Jochen Eisinger.

This change enables Chromium to set up file permissions properly when
the session restore feature restores a page with selected files.

Test: fast/forms/file/selected-files-from-history-state.html

* WebCore.exp.in: Exported FormController::getReferencedFilePaths.
* html/FileInputType.cpp:
(WebCore::FileInputType::filesFromFormControlState): Added. Extracts FileChooserFileInfos from a FormControlState.
(WebCore):
(WebCore::FileInputType::restoreFormControlState): Refactored to use filesFromFormControlState.
* html/FileInputType.h:
(FileInputType): Added filesFromFormControlState.
* html/FormController.cpp:
(SavedFormState): Added getReferencedFilePaths.
(WebCore::SavedFormState::getReferencedFilePaths): Added. Extracts selected file paths from SavedFormState.
(WebCore):
(WebCore::FormController::setStateForNewFormElements): Refactored to use formStatesFromStateVector.
(WebCore::FormController::formStatesFromStateVector):
(WebCore::FormController::getReferencedFilePaths): Added. Static. Extracts selected file paths from a document state.
* html/FormController.h:
(FormController): Added getReferencedFilePaths and formStatesFromStateVector.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::filesFromFileInputFormControlState): Added. Delegates to FileInputType::filesFromFormControlState.
(WebCore):
* html/HTMLInputElement.h: Added filesFromFileInputFormControlState.
(HTMLInputElement):
* testing/Internals.cpp:
(WebCore::Internals::getReferencedFilePaths): Calls FormController::getReferencedFilePaths.
(WebCore):
* testing/Internals.h:
(Internals): Added getReferencedFilePaths.
* testing/Internals.idl: Added binding for getReferencedFilePaths.

Source/WebKit/chromium: WebHistoryItem: Enable reading selected file names from document state
https://bugs.webkit.org/show_bug.cgi?id=91231

Patch by Marja Hölttä <marja@chromium.org> on 2012-08-16
Reviewed by Jochen Eisinger.

This change enables Chromium to set up file permissions properly when
the session restore feature restores a page with selected files.

* public/WebHistoryItem.h:
(WebHistoryItem): Added getReferencedFilePaths.
* src/WebHistoryItem.cpp:
(WebKit::WebHistoryItem::getReferencedFilePaths): Extracts selected and posted file paths from a document state.
(WebKit):

Source/WebKit2: FormController, WebHistoryItem: Enable reading selected file names from document state
https://bugs.webkit.org/show_bug.cgi?id=91231

Patch by Marja Hölttä <marja@chromium.org> on 2012-08-16
Reviewed by Jochen Eisinger.

This change enables Chromium to set up file permissions properly when
the session restore feature restores a page with selected files.

* win/WebKit2.def: Exported FormController::getReferencedFilePaths and HistoryController::saveDocumentAndScrollState.

LayoutTests: FormController: Enable reading selected file names from document state
https://bugs.webkit.org/show_bug.cgi?id=91231

Patch by Marja Hölttä <marja@chromium.org> on 2012-08-16
Reviewed by Jochen Eisinger.

This change enables Chromium to set up file permissions properly when
the session restore feature restores a page with selected files.

* fast/forms/file/selected-files-from-history-state-expected.txt: Added.
* fast/forms/file/selected-files-from-history-state.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@125759 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information...
1 parent 032071c commit 50434f25c20a0bcb1e409dcb2435773f00a11553 commit-queue committed Aug 16, 2012
View
@@ -1,3 +1,15 @@
+2012-08-16 Marja Hölttä <marja@chromium.org>
+
+ FormController, WebHistoryItem: Enable reading selected file names from document state
+ https://bugs.webkit.org/show_bug.cgi?id=91231
+
+ Reviewed by Jochen Eisinger.
+
+ This change enables Chromium to set up file permissions properly when
+ the session restore feature restores a page with selected files.
+
+ * Source/autotools/symbols.filter: Exported FormController::getReferencedFilePaths and HistoryController::saveDocumentAndScrollState.
+
2012-08-15 Kent Tamura <tkent@chromium.org>
Calendar Picker: Localize numbers in a calendar picker
View
@@ -1,3 +1,16 @@
+2012-08-16 Marja Hölttä <marja@chromium.org>
+
+ FormController: Enable reading selected file names from document state
+ https://bugs.webkit.org/show_bug.cgi?id=91231
+
+ Reviewed by Jochen Eisinger.
+
+ This change enables Chromium to set up file permissions properly when
+ the session restore feature restores a page with selected files.
+
+ * fast/forms/file/selected-files-from-history-state-expected.txt: Added.
+ * fast/forms/file/selected-files-from-history-state.html: Added.
+
2012-08-15 Shawn Singh <shawnsingh@chromium.org>
[chromium] set scissorRect per quad so that quads are correctly clipped
@@ -0,0 +1,9 @@
+Tests that selected files in file input elements are correctly retrieved by FormController::getReferencedFilePaths.
+
+
+
+PASS
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script>
+window.jsTestIsAsync = true;
+function onLoad() {
+ setTimeout(runTest, 0);
+}
+
+function runTest() {
+ if (!window.internals) {
+ testFailed('This test requires window.internals.');
+ return;
+ }
+
+ var onChangeFired = 0;
+ var input1 = document.getElementById('fileinput1');
+ input1.onchange = function() {
+ ++onChangeFired;
+ };
+ var input2 = document.getElementById('fileinput2');
+ input2.onchange = function() {
+ ++onChangeFired;
+ };
+
+ eventSender.beginDragWithFiles(['/home/user/testfile.txt']);
+ var centerX = input1.offsetLeft + input1.offsetWidth / 2;
+ var centerY = input1.offsetTop + input1.offsetHeight / 2;
+ eventSender.mouseMoveTo(centerX, centerY);
+ eventSender.mouseUp();
+
+ eventSender.beginDragWithFiles(['/home/user/testfile2.txt']);
+ centerX = input2.offsetLeft + input2.offsetWidth / 2;
+ centerY = input2.offsetTop + input2.offsetHeight / 2;
+ eventSender.mouseMoveTo(centerX, centerY);
+ eventSender.mouseUp();
+
+ if (onChangeFired != 2) {
+ testFailed('onchange fired unexpected times: ' + onChangeFired);
+ }
+
+ var files = internals.getReferencedFilePaths();
+ if (files.length == 2 &&
+ ((files[0] == '/home/user/testfile.txt' && files[1] == '/home/user/testfile2.txt') ||
+ (files[1] == '/home/user/testfile.txt' && files[0] == '/home/user/testfile2.txt'))) {
+ testPassed('');
+ } else {
+ testFailed('Unexpected files: ' + files);
+ }
+ finishJSTest();
+}
+</script>
+</head>
+<body onload="onLoad();">
+<p id="description">Tests that selected files in file input elements are correctly retrieved by FormController::getReferencedFilePaths.</p>
+<div id="container">
+<form id="form1">
+<input id="fileinput1" type="file" />
+</form>
+<form id="form2">
+<input id="fileinput2" type="file" />
+</form>
+</div>
+<div id="console"></div>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
@@ -1,3 +1,43 @@
+2012-08-16 Marja Hölttä <marja@chromium.org>
+
+ FormController, FileInputType: Enable reading selected file names from document state
+ https://bugs.webkit.org/show_bug.cgi?id=91231
+
+ Reviewed by Jochen Eisinger.
+
+ This change enables Chromium to set up file permissions properly when
+ the session restore feature restores a page with selected files.
+
+ Test: fast/forms/file/selected-files-from-history-state.html
+
+ * WebCore.exp.in: Exported FormController::getReferencedFilePaths.
+ * html/FileInputType.cpp:
+ (WebCore::FileInputType::filesFromFormControlState): Added. Extracts FileChooserFileInfos from a FormControlState.
+ (WebCore):
+ (WebCore::FileInputType::restoreFormControlState): Refactored to use filesFromFormControlState.
+ * html/FileInputType.h:
+ (FileInputType): Added filesFromFormControlState.
+ * html/FormController.cpp:
+ (SavedFormState): Added getReferencedFilePaths.
+ (WebCore::SavedFormState::getReferencedFilePaths): Added. Extracts selected file paths from SavedFormState.
+ (WebCore):
+ (WebCore::FormController::setStateForNewFormElements): Refactored to use formStatesFromStateVector.
+ (WebCore::FormController::formStatesFromStateVector):
+ (WebCore::FormController::getReferencedFilePaths): Added. Static. Extracts selected file paths from a document state.
+ * html/FormController.h:
+ (FormController): Added getReferencedFilePaths and formStatesFromStateVector.
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::filesFromFileInputFormControlState): Added. Delegates to FileInputType::filesFromFormControlState.
+ (WebCore):
+ * html/HTMLInputElement.h: Added filesFromFileInputFormControlState.
+ (HTMLInputElement):
+ * testing/Internals.cpp:
+ (WebCore::Internals::getReferencedFilePaths): Calls FormController::getReferencedFilePaths.
+ (WebCore):
+ * testing/Internals.h:
+ (Internals): Added getReferencedFilePaths.
+ * testing/Internals.idl: Added binding for getReferencedFilePaths.
+
2012-08-15 Shawn Singh <shawnsingh@chromium.org>
[chromium] set scissorRect per quad so that quads are correctly clipped
@@ -253,6 +253,7 @@ __ZN7WebCore14DocumentLoaderD2Ev
__ZNK7WebCore14DocumentLoader17reportMemoryUsageEPNS_16MemoryObjectInfoE
__ZN7WebCore14DocumentWriter11setEncodingERKN3WTF6StringEb
__ZN7WebCore14FileIconLoader14notifyFinishedEN3WTF10PassRefPtrINS_4IconEEE
+__ZN7WebCore14FormController22getReferencedFilePathsERKN3WTF6VectorINS1_6StringELm0EEE
__ZN7WebCore14FrameSelection10setFocusedEb
__ZN7WebCore14FrameSelection12setSelectionERKNS_16VisibleSelectionEjNS0_19CursorAlignOnScrollENS_15TextGranularityE
__ZN7WebCore14FrameSelection15revealSelectionERKNS_15ScrollAlignmentENS_18RevealExtentOptionE
@@ -96,6 +96,18 @@ PassOwnPtr<InputType> FileInputType::create(HTMLInputElement* element)
return adoptPtr(new FileInputType(element));
}
+Vector<FileChooserFileInfo> FileInputType::filesFromFormControlState(const FormControlState& state)
+{
+ Vector<FileChooserFileInfo> files;
+ for (size_t i = 0; i < state.valueSize(); i += 2) {
+ if (!state[i + 1].isEmpty())
+ files.append(FileChooserFileInfo(state[i], state[i + 1]));
+ else
+ files.append(FileChooserFileInfo(state[i]));
+ }
+ return files;
+}
+
const AtomicString& FileInputType::formControlType() const
{
return InputTypeNames::file();
@@ -118,14 +130,7 @@ void FileInputType::restoreFormControlState(const FormControlState& state)
{
if (state.valueSize() % 2)
return;
- Vector<FileChooserFileInfo> files;
- for (size_t i = 0; i < state.valueSize(); i += 2) {
- if (!state[i + 1].isEmpty())
- files.append(FileChooserFileInfo(state[i], state[i + 1]));
- else
- files.append(FileChooserFileInfo(state[i]));
- }
- filesChosen(files);
+ filesChosen(filesFromFormControlState(state));
}
bool FileInputType::appendFormData(FormDataList& encoding, bool multipart) const
@@ -45,6 +45,7 @@ class FileList;
class FileInputType : public BaseClickableWithKeyInputType, private FileChooserClient, private FileIconLoaderClient {
public:
static PassOwnPtr<InputType> create(HTMLInputElement*);
+ static Vector<FileChooserFileInfo> filesFromFormControlState(const FormControlState&);
private:
FileInputType(HTMLInputElement*);
@@ -21,8 +21,10 @@
#include "config.h"
#include "FormController.h"
+#include "FileChooser.h"
#include "HTMLFormControlElementWithState.h"
#include "HTMLFormElement.h"
+#include "HTMLInputElement.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -180,6 +182,8 @@ class SavedFormState {
void appendControlState(const AtomicString& name, const AtomicString& type, const FormControlState&);
FormControlState takeControlState(const AtomicString& name, const AtomicString& type);
+ Vector<String> getReferencedFilePaths() const;
+
private:
SavedFormState() : m_controlStateCount(0) { }
@@ -263,6 +267,23 @@ FormControlState SavedFormState::takeControlState(const AtomicString& name, cons
return state;
}
+Vector<String> SavedFormState::getReferencedFilePaths() const
+{
+ Vector<String> toReturn;
+ for (FormElementStateMap::const_iterator it = m_stateForNewFormElements.begin(); it != m_stateForNewFormElements.end(); ++it) {
+ const FormElementKey& key = it->first;
+ if (AtomicString(key.type()) != AtomicString("file"))
+ continue;
+ const Deque<FormControlState>& queue = it->second;
+ for (Deque<FormControlState>::const_iterator queIterator = queue.begin(); queIterator != queue.end(); ++queIterator) {
+ const Vector<FileChooserFileInfo>& selectedFiles = HTMLInputElement::filesFromFileInputFormControlState(*queIterator);
+ for (size_t i = 0; i < selectedFiles.size(); ++i)
+ toReturn.append(selectedFiles[i].path);
+ }
+ }
+ return toReturn;
+}
+
// ----------------------------------------------------------------------------
class FormKeyGenerator {
@@ -408,23 +429,7 @@ Vector<String> FormController::formElementsState() const
void FormController::setStateForNewFormElements(const Vector<String>& stateVector)
{
- m_formElementsWithState.clear();
-
- size_t i = 0;
- if (stateVector.size() < 1 || stateVector[i++] != formStateSignature())
- return;
-
- while (i + 1 < stateVector.size()) {
- AtomicString formKey = stateVector[i++];
- OwnPtr<SavedFormState> state = SavedFormState::deserialize(stateVector, i);
- if (!state) {
- i = 0;
- break;
- }
- m_savedFormStateMap.add(formKey.impl(), state.release());
- }
- if (i != stateVector.size())
- m_savedFormStateMap.clear();
+ formStatesFromStateVector(stateVector, m_savedFormStateMap);
}
FormControlState FormController::takeStateForFormElement(const HTMLFormControlElementWithState& control)
@@ -442,6 +447,27 @@ FormControlState FormController::takeStateForFormElement(const HTMLFormControlEl
return state;
}
+void FormController::formStatesFromStateVector(const Vector<String>& stateVector, SavedFormStateMap& map)
+{
+ map.clear();
+
+ size_t i = 0;
+ if (stateVector.size() < 1 || stateVector[i++] != formStateSignature())
+ return;
+
+ while (i + 1 < stateVector.size()) {
+ AtomicString formKey = stateVector[i++];
+ OwnPtr<SavedFormState> state = SavedFormState::deserialize(stateVector, i);
+ if (!state) {
+ i = 0;
+ break;
+ }
+ map.add(formKey.impl(), state.release());
+ }
+ if (i != stateVector.size())
+ map.clear();
+}
+
void FormController::willDeleteForm(HTMLFormElement* form)
{
if (m_formKeyGenerator)
@@ -479,5 +505,14 @@ void FormController::restoreControlStateIn(HTMLFormElement& form)
}
}
-} // namespace WebCore
+Vector<String> FormController::getReferencedFilePaths(const Vector<String>& stateVector)
+{
+ Vector<String> toReturn;
+ SavedFormStateMap map;
+ formStatesFromStateVector(stateVector, map);
+ for (SavedFormStateMap::const_iterator it = map.begin(); it != map.end(); ++it)
+ toReturn.append(it->second->getReferencedFilePaths());
+ return toReturn;
+}
+} // namespace WebCore
@@ -92,13 +92,16 @@ class FormController {
void restoreControlStateFor(HTMLFormControlElementWithState&);
void restoreControlStateIn(HTMLFormElement&);
+ static Vector<String> getReferencedFilePaths(const Vector<String>& stateVector);
+
private:
typedef ListHashSet<HTMLFormControlElementWithState*, 64> FormElementListHashSet;
typedef HashMap<RefPtr<AtomicStringImpl>, OwnPtr<SavedFormState> > SavedFormStateMap;
FormController();
static PassOwnPtr<SavedFormStateMap> createSavedFormStateMap(const FormElementListHashSet&);
FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&);
+ static void formStatesFromStateVector(const Vector<String>&, SavedFormStateMap&);
CheckedRadioButtons m_checkedRadioButtons;
FormElementListHashSet m_formElementsWithState;
@@ -36,6 +36,7 @@
#include "Document.h"
#include "EventNames.h"
#include "ExceptionCode.h"
+#include "FileInputType.h"
#include "FileList.h"
#include "FormController.h"
#include "Frame.h"
@@ -159,6 +160,11 @@ const AtomicString& HTMLInputElement::name() const
return m_name.isNull() ? emptyAtom : m_name;
}
+Vector<FileChooserFileInfo> HTMLInputElement::filesFromFileInputFormControlState(const FormControlState& state)
+{
+ return FileInputType::filesFromFormControlState(state);
+}
+
HTMLElement* HTMLInputElement::containerElement() const
{
return m_inputType->containerElement();
@@ -25,6 +25,7 @@
#ifndef HTMLInputElement_h
#define HTMLInputElement_h
+#include "FileChooser.h"
#include "HTMLTextFormControlElement.h"
#include "ImageLoaderClient.h"
#include "StepRange.h"
@@ -277,6 +278,8 @@ class HTMLInputElement : public HTMLTextFormControlElement, public ImageLoaderCl
virtual const AtomicString& name() const OVERRIDE;
+ static Vector<FileChooserFileInfo> filesFromFileInputFormControlState(const FormControlState&);
+
protected:
HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement*, bool createdByParser);
void createShadowSubtree();
Oops, something went wrong.

0 comments on commit 50434f2

Please sign in to comment.