From a17036919b6002c74cbe5b4cd5fb89c7651b1ead Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Thu, 5 Sep 2013 13:24:26 +1100 Subject: [PATCH] possibility to set default file name to write to using nwsaveas --- Source/WebKit/chromium/src/ChromeClientImpl.cpp | 5 ++++- Source/core/html/FileInputType.cpp | 1 + Source/core/html/HTMLInputElement.cpp | 10 ++++++++++ Source/core/html/HTMLInputElement.h | 3 +++ Source/core/html/HTMLInputElement.idl | 2 ++ Source/core/platform/FileChooser.h | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Source/WebKit/chromium/src/ChromeClientImpl.cpp b/Source/WebKit/chromium/src/ChromeClientImpl.cpp index 3fa9db543b9..44af0a5cc83 100644 --- a/Source/WebKit/chromium/src/ChromeClientImpl.cpp +++ b/Source/WebKit/chromium/src/ChromeClientImpl.cpp @@ -651,8 +651,11 @@ void ChromeClientImpl::runOpenPanel(Frame* frame, PassRefPtr fileCh params.directory = fileChooser->settings().directoryChooser || fileChooser->settings().allowsDirectoryUpload; params.acceptTypes = fileChooser->settings().acceptTypes(); params.selectedFiles = fileChooser->settings().selectedFiles; - if (params.selectedFiles.size() > 0) + if (params.selectedFiles.size() > 0) { params.initialValue = params.selectedFiles[0]; + } else { + params.initialValue = fileChooser->settings().initialValue; + } params.extractDirectory = fileChooser->settings().allowsDirectoryUpload; params.saveAs = fileChooser->settings().saveAs; #if ENABLE(MEDIA_CAPTURE) diff --git a/Source/core/html/FileInputType.cpp b/Source/core/html/FileInputType.cpp index d4e274c9824..a4b548246b7 100644 --- a/Source/core/html/FileInputType.cpp +++ b/Source/core/html/FileInputType.cpp @@ -156,6 +156,7 @@ void FileInputType::handleDOMActivateEvent(Event* event) settings.capture = input->capture(); #endif settings.initialPath = input->nwworkingdir(); + settings.initialValue = input->nwsaveas(); chrome->runOpenPanel(input->document()->frame(), newFileChooser(settings)); } event->setDefaultHandled(); diff --git a/Source/core/html/HTMLInputElement.cpp b/Source/core/html/HTMLInputElement.cpp index 4b4119babe7..498c3ac8dfd 100644 --- a/Source/core/html/HTMLInputElement.cpp +++ b/Source/core/html/HTMLInputElement.cpp @@ -1776,6 +1776,16 @@ void HTMLInputElement::setNwworkingdir(const String& value) setAttribute(nwworkingdirAttr, value); } +String HTMLInputElement::nwsaveas() const +{ + return fastGetAttribute(nwsaveasAttr); +} + +void HTMLInputElement::setNwsaveas(const String& value) +{ + setAttribute(nwsaveasAttr, value); +} + bool HTMLInputElement::isInRequiredRadioButtonGroup() { ASSERT(isRadioButton()); diff --git a/Source/core/html/HTMLInputElement.h b/Source/core/html/HTMLInputElement.h index 98ea6b59918..39487c6fa6c 100644 --- a/Source/core/html/HTMLInputElement.h +++ b/Source/core/html/HTMLInputElement.h @@ -268,6 +268,9 @@ class HTMLInputElement : public HTMLTextFormControlElement { String nwworkingdir() const; void setNwworkingdir(const String& value); + String nwsaveas() const; + void setNwsaveas(const String& value); + static const int maximumLength; unsigned height() const; diff --git a/Source/core/html/HTMLInputElement.idl b/Source/core/html/HTMLInputElement.idl index 24cd106854c..dd370aba1fd 100644 --- a/Source/core/html/HTMLInputElement.idl +++ b/Source/core/html/HTMLInputElement.idl @@ -98,5 +98,7 @@ // See http://www.w3.org/TR/html-media-capture/ [Conditional=MEDIA_CAPTURE] attribute DOMString capture; + attribute DOMString nwworkingdir; + attribute DOMString nwsaveas; }; diff --git a/Source/core/platform/FileChooser.h b/Source/core/platform/FileChooser.h index c240c6fd392..ea3632aba49 100644 --- a/Source/core/platform/FileChooser.h +++ b/Source/core/platform/FileChooser.h @@ -65,6 +65,7 @@ struct FileChooserSettings { Vector acceptTypes() const; String initialPath; + String initialValue; }; class FileChooserClient {