#include "config.h"
#include "FileChooser.h"
namespace WebCore {
FileChooserClient::~FileChooserClient()
{
discardChooser();
}
FileChooser* FileChooserClient::newFileChooser(const FileChooserSettings& settings)
{
discardChooser();
m_chooser = FileChooser::create(this, settings);
return m_chooser.get();
}
void FileChooserClient::discardChooser()
{
if (m_chooser)
m_chooser->disconnectClient();
}
inline FileChooser::FileChooser(FileChooserClient* client, const FileChooserSettings& settings)
: m_client(client)
, m_settings(settings)
{
}
PassRefPtr<FileChooser> FileChooser::create(FileChooserClient* client, const FileChooserSettings& settings)
{
return adoptRef(new FileChooser(client, settings));
}
FileChooser::~FileChooser()
{
}
void FileChooser::chooseFile(const String& filename)
{
Vector<String> filenames;
filenames.append(filename);
chooseFiles(filenames);
}
void FileChooser::chooseFiles(const Vector<String>& filenames)
{
if (m_settings.selectedFiles == filenames)
return;
if (m_client) {
Vector<FileChooserFileInfo> files;
for (unsigned i = 0; i < filenames.size(); ++i)
files.append(FileChooserFileInfo(filenames[i]));
m_client->filesChosen(files);
}
}
void FileChooser::chooseFiles(const Vector<FileChooserFileInfo>& files)
{
Vector<String> paths;
for (unsigned i = 0; i < files.size(); ++i)
paths.append(files[i].path);
if (m_settings.selectedFiles == paths)
return;
if (m_client)
m_client->filesChosen(files);
}
void FileChooser::chooseMediaFiles(const Vector<String>& filenames, const String& displayString, Icon* icon)
{
if (m_settings.selectedFiles == filenames)
return;
if (m_client) {
Vector<FileChooserFileInfo> files;
for (unsigned i = 0; i < filenames.size(); ++i)
files.append(FileChooserFileInfo(filenames[i]));
m_client->filesChosen(files, displayString, icon);
}
}
}