Commit 33f8ad52 authored by mihaip@chromium.org's avatar mihaip@chromium.org

Move RunFileChooserHelper and EnumerateDirectoryHelper out of Browser.

R=sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10411064

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138296 0039d316-1c4b-4281-b951-d872f2087c98
parent 1072e0b0
......@@ -20,6 +20,7 @@
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_window_controller.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
#include "chrome/browser/ui/browser.h"
......@@ -536,7 +537,7 @@ content::JavaScriptDialogCreator* ExtensionHost::GetJavaScriptDialogCreator() {
void ExtensionHost::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) {
Browser::RunFileChooserHelper(tab, params);
FileSelectHelper::RunFileChooser(tab, params);
}
void ExtensionHost::AddNewContents(WebContents* source,
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/debugger/devtools_toggle_action.h"
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/history/history_tab_helper.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/infobars/infobar_tab_helper.h"
......@@ -720,12 +721,12 @@ void ExternalTabContainer::ShowRepostFormWarningDialog(
void ExternalTabContainer::RunFileChooser(
WebContents* tab, const content::FileChooserParams& params) {
Browser::RunFileChooserHelper(tab, params);
FileSelectHelper::RunFileChooser(tab, params);
}
void ExternalTabContainer::EnumerateDirectory(WebContents* tab, int request_id,
const FilePath& path) {
Browser::EnumerateDirectoryHelper(tab, request_id, path);
FileSelectHelper::EnumerateDirectory(tab, request_id, path);
}
void ExternalTabContainer::JSOutOfMemory(WebContents* tab) {
......
......@@ -21,6 +21,7 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/file_chooser_params.h"
#include "content/public/common/selected_file_info.h"
#include "grit/generated_resources.h"
......@@ -28,6 +29,7 @@
#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
using content::FileChooserParams;
using content::RenderViewHost;
using content::RenderWidgetHost;
using content::WebContents;
......@@ -300,10 +302,31 @@ SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType(
return file_type.release();
}
void FileSelectHelper::RunFileChooser(
RenderViewHost* render_view_host,
content::WebContents* web_contents,
const content::FileChooserParams& params) {
// static
void FileSelectHelper::RunFileChooser(content::WebContents* tab,
const FileChooserParams& params) {
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
// FileSelectHelper will keep itself alive until it sends the result message.
scoped_refptr<FileSelectHelper> file_select_helper(
new FileSelectHelper(profile));
file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params);
}
// static
void FileSelectHelper::EnumerateDirectory(content::WebContents* tab,
int request_id,
const FilePath& path) {
Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
// FileSelectHelper will keep itself alive until it sends the result message.
scoped_refptr<FileSelectHelper> file_select_helper(
new FileSelectHelper(profile));
file_select_helper->EnumerateDirectory(
request_id, tab->GetRenderViewHost(), path);
}
void FileSelectHelper::RunFileChooser(RenderViewHost* render_view_host,
content::WebContents* web_contents,
const FileChooserParams& params) {
DCHECK(!render_view_host_);
DCHECK(!web_contents_);
render_view_host_ = render_view_host;
......@@ -329,7 +352,7 @@ void FileSelectHelper::RunFileChooser(
}
void FileSelectHelper::RunFileChooserOnFileThread(
const content::FileChooserParams& params) {
const FileChooserParams& params) {
select_file_types_.reset(
GetFileTypesFromAcceptType(params.accept_types));
......@@ -339,7 +362,7 @@ void FileSelectHelper::RunFileChooserOnFileThread(
}
void FileSelectHelper::RunFileChooserOnUIThread(
const content::FileChooserParams& params) {
const FileChooserParams& params) {
if (!render_view_host_ || !web_contents_) {
// If the renderer was destroyed before we started, just cancel the
// operation.
......@@ -351,16 +374,16 @@ void FileSelectHelper::RunFileChooserOnUIThread(
select_file_dialog_ = SelectFileDialog::Create(this);
switch (params.mode) {
case content::FileChooserParams::Open:
case FileChooserParams::Open:
dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE;
break;
case content::FileChooserParams::OpenMultiple:
case FileChooserParams::OpenMultiple:
dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
break;
case content::FileChooserParams::OpenFolder:
case FileChooserParams::OpenFolder:
dialog_type_ = SelectFileDialog::SELECT_FOLDER;
break;
case content::FileChooserParams::Save:
case FileChooserParams::Save:
dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE;
break;
default:
......@@ -400,7 +423,6 @@ void FileSelectHelper::RunFileChooserEnd() {
void FileSelectHelper::EnumerateDirectory(int request_id,
RenderViewHost* render_view_host,
const FilePath& path) {
DCHECK_NE(kFileSelectEnumerationId, request_id);
// Because this class returns notifications to the RenderViewHost, it is
// difficult for callers to know how long to keep a reference to this
......
......@@ -31,20 +31,19 @@ class FileSelectHelper
public SelectFileDialog::Listener,
public content::NotificationObserver {
public:
explicit FileSelectHelper(Profile* profile);
// Show the file chooser dialog.
void RunFileChooser(content::RenderViewHost* render_view_host,
content::WebContents* tab_contents,
const content::FileChooserParams& params);
static void RunFileChooser(content::WebContents* tab,
const content::FileChooserParams& params);
// Enumerates all the files in directory.
void EnumerateDirectory(int request_id,
content::RenderViewHost* render_view_host,
const FilePath& path);
static void EnumerateDirectory(content::WebContents* tab,
int request_id,
const FilePath& path);
private:
friend class base::RefCountedThreadSafe<FileSelectHelper>;
explicit FileSelectHelper(Profile* profile);
virtual ~FileSelectHelper();
// Utility class which can listen for directory lister events and relay
......@@ -71,6 +70,9 @@ class FileSelectHelper
DISALLOW_COPY_AND_ASSIGN(DirectoryListerDispatchDelegate);
};
void RunFileChooser(content::RenderViewHost* render_view_host,
content::WebContents* tab_contents,
const content::FileChooserParams& params);
void RunFileChooserOnFileThread(
const content::FileChooserParams& params);
void RunFileChooserOnUIThread(
......@@ -99,6 +101,10 @@ class FileSelectHelper
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void EnumerateDirectory(int request_id,
content::RenderViewHost* render_view_host,
const FilePath& path);
// Kicks off a new directory enumeration.
void StartNewEnumeration(const FilePath& path,
int request_id,
......
......@@ -2503,34 +2503,6 @@ bool Browser::RunUnloadEventsHelper(WebContents* contents) {
return false;
}
// static
void Browser::RunFileChooserHelper(
WebContents* tab, const content::FileChooserParams& params) {
Profile* profile =
Profile::FromBrowserContext(tab->GetBrowserContext());
// FileSelectHelper adds a reference to itself and only releases it after
// sending the result message. It won't be destroyed when this reference
// goes out of scope.
scoped_refptr<FileSelectHelper> file_select_helper(
new FileSelectHelper(profile));
file_select_helper->RunFileChooser(tab->GetRenderViewHost(), tab, params);
}
// static
void Browser::EnumerateDirectoryHelper(WebContents* tab, int request_id,
const FilePath& path) {
Profile* profile =
Profile::FromBrowserContext(tab->GetBrowserContext());
// FileSelectHelper adds a reference to itself and only releases it after
// sending the result message. It won't be destroyed when this reference
// goes out of scope.
scoped_refptr<FileSelectHelper> file_select_helper(
new FileSelectHelper(profile));
file_select_helper->EnumerateDirectory(request_id,
tab->GetRenderViewHost(),
path);
}
// static
void Browser::JSOutOfMemoryHelper(WebContents* tab) {
TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents(
......@@ -3889,12 +3861,13 @@ void Browser::DidEndColorChooser() {
void Browser::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) {
RunFileChooserHelper(tab, params);
FileSelectHelper::RunFileChooser(tab, params);
}
void Browser::EnumerateDirectory(WebContents* tab, int request_id,
void Browser::EnumerateDirectory(WebContents* tab,
int request_id,
const FilePath& path) {
EnumerateDirectoryHelper(tab, request_id, path);
FileSelectHelper::EnumerateDirectory(tab, request_id, path);
}
void Browser::ToggleFullscreenModeForTab(WebContents* tab,
......
......@@ -683,15 +683,6 @@ class Browser : public TabStripModelDelegate,
// Helper function to run unload listeners on a WebContents.
static bool RunUnloadEventsHelper(content::WebContents* contents);
// Helper function to display the file selection dialog.
static void RunFileChooserHelper(
content::WebContents* tab, const content::FileChooserParams& params);
// Helper function to enumerate a directory.
static void EnumerateDirectoryHelper(content::WebContents* tab,
int request_id,
const FilePath& path);
// Helper function to handle JS out of memory notifications
static void JSOutOfMemoryHelper(content::WebContents* tab);
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/extensions/extension_tabs_module_constants.h"
#include "chrome/browser/extensions/extension_window_controller.h"
#include "chrome/browser/extensions/shell_window_registry.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/intents/web_intents_util.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
......@@ -172,7 +173,7 @@ void ShellWindow::WebIntentDispatch(
void ShellWindow::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) {
Browser::RunFileChooserHelper(tab, params);
FileSelectHelper::RunFileChooser(tab, params);
}
void ShellWindow::Observe(int type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment