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 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_window_controller.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/profiles/profile.h"
#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -536,7 +537,7 @@ content::JavaScriptDialogCreator* ExtensionHost::GetJavaScriptDialogCreator() { ...@@ -536,7 +537,7 @@ content::JavaScriptDialogCreator* ExtensionHost::GetJavaScriptDialogCreator() {
void ExtensionHost::RunFileChooser(WebContents* tab, void ExtensionHost::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) { const content::FileChooserParams& params) {
Browser::RunFileChooserHelper(tab, params); FileSelectHelper::RunFileChooser(tab, params);
} }
void ExtensionHost::AddNewContents(WebContents* source, void ExtensionHost::AddNewContents(WebContents* source,
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/automation/automation_provider.h" #include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/debugger/devtools_toggle_action.h" #include "chrome/browser/debugger/devtools_toggle_action.h"
#include "chrome/browser/debugger/devtools_window.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_tab_helper.h"
#include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_types.h"
#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/infobars/infobar_tab_helper.h"
...@@ -720,12 +721,12 @@ void ExternalTabContainer::ShowRepostFormWarningDialog( ...@@ -720,12 +721,12 @@ void ExternalTabContainer::ShowRepostFormWarningDialog(
void ExternalTabContainer::RunFileChooser( void ExternalTabContainer::RunFileChooser(
WebContents* tab, const content::FileChooserParams& params) { WebContents* tab, const content::FileChooserParams& params) {
Browser::RunFileChooserHelper(tab, params); FileSelectHelper::RunFileChooser(tab, params);
} }
void ExternalTabContainer::EnumerateDirectory(WebContents* tab, int request_id, void ExternalTabContainer::EnumerateDirectory(WebContents* tab, int request_id,
const FilePath& path) { const FilePath& path) {
Browser::EnumerateDirectoryHelper(tab, request_id, path); FileSelectHelper::EnumerateDirectory(tab, request_id, path);
} }
void ExternalTabContainer::JSOutOfMemory(WebContents* tab) { void ExternalTabContainer::JSOutOfMemory(WebContents* tab) {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.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/file_chooser_params.h"
#include "content/public/common/selected_file_info.h" #include "content/public/common/selected_file_info.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
using content::BrowserThread; using content::BrowserThread;
using content::FileChooserParams;
using content::RenderViewHost; using content::RenderViewHost;
using content::RenderWidgetHost; using content::RenderWidgetHost;
using content::WebContents; using content::WebContents;
...@@ -300,10 +302,31 @@ SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType( ...@@ -300,10 +302,31 @@ SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType(
return file_type.release(); return file_type.release();
} }
void FileSelectHelper::RunFileChooser( // static
RenderViewHost* render_view_host, void FileSelectHelper::RunFileChooser(content::WebContents* tab,
content::WebContents* web_contents, const FileChooserParams& params) {
const content::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(!render_view_host_);
DCHECK(!web_contents_); DCHECK(!web_contents_);
render_view_host_ = render_view_host; render_view_host_ = render_view_host;
...@@ -329,7 +352,7 @@ void FileSelectHelper::RunFileChooser( ...@@ -329,7 +352,7 @@ void FileSelectHelper::RunFileChooser(
} }
void FileSelectHelper::RunFileChooserOnFileThread( void FileSelectHelper::RunFileChooserOnFileThread(
const content::FileChooserParams& params) { const FileChooserParams& params) {
select_file_types_.reset( select_file_types_.reset(
GetFileTypesFromAcceptType(params.accept_types)); GetFileTypesFromAcceptType(params.accept_types));
...@@ -339,7 +362,7 @@ void FileSelectHelper::RunFileChooserOnFileThread( ...@@ -339,7 +362,7 @@ void FileSelectHelper::RunFileChooserOnFileThread(
} }
void FileSelectHelper::RunFileChooserOnUIThread( void FileSelectHelper::RunFileChooserOnUIThread(
const content::FileChooserParams& params) { const FileChooserParams& params) {
if (!render_view_host_ || !web_contents_) { if (!render_view_host_ || !web_contents_) {
// If the renderer was destroyed before we started, just cancel the // If the renderer was destroyed before we started, just cancel the
// operation. // operation.
...@@ -351,16 +374,16 @@ void FileSelectHelper::RunFileChooserOnUIThread( ...@@ -351,16 +374,16 @@ void FileSelectHelper::RunFileChooserOnUIThread(
select_file_dialog_ = SelectFileDialog::Create(this); select_file_dialog_ = SelectFileDialog::Create(this);
switch (params.mode) { switch (params.mode) {
case content::FileChooserParams::Open: case FileChooserParams::Open:
dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE;
break; break;
case content::FileChooserParams::OpenMultiple: case FileChooserParams::OpenMultiple:
dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE; dialog_type_ = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
break; break;
case content::FileChooserParams::OpenFolder: case FileChooserParams::OpenFolder:
dialog_type_ = SelectFileDialog::SELECT_FOLDER; dialog_type_ = SelectFileDialog::SELECT_FOLDER;
break; break;
case content::FileChooserParams::Save: case FileChooserParams::Save:
dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE;
break; break;
default: default:
...@@ -400,7 +423,6 @@ void FileSelectHelper::RunFileChooserEnd() { ...@@ -400,7 +423,6 @@ void FileSelectHelper::RunFileChooserEnd() {
void FileSelectHelper::EnumerateDirectory(int request_id, void FileSelectHelper::EnumerateDirectory(int request_id,
RenderViewHost* render_view_host, RenderViewHost* render_view_host,
const FilePath& path) { const FilePath& path) {
DCHECK_NE(kFileSelectEnumerationId, request_id);
// Because this class returns notifications to the RenderViewHost, it is // Because this class returns notifications to the RenderViewHost, it is
// difficult for callers to know how long to keep a reference to this // difficult for callers to know how long to keep a reference to this
......
...@@ -31,20 +31,19 @@ class FileSelectHelper ...@@ -31,20 +31,19 @@ class FileSelectHelper
public SelectFileDialog::Listener, public SelectFileDialog::Listener,
public content::NotificationObserver { public content::NotificationObserver {
public: public:
explicit FileSelectHelper(Profile* profile);
// Show the file chooser dialog. // Show the file chooser dialog.
void RunFileChooser(content::RenderViewHost* render_view_host, static void RunFileChooser(content::WebContents* tab,
content::WebContents* tab_contents, const content::FileChooserParams& params);
const content::FileChooserParams& params);
// Enumerates all the files in directory. // Enumerates all the files in directory.
void EnumerateDirectory(int request_id, static void EnumerateDirectory(content::WebContents* tab,
content::RenderViewHost* render_view_host, int request_id,
const FilePath& path); const FilePath& path);
private: private:
friend class base::RefCountedThreadSafe<FileSelectHelper>; friend class base::RefCountedThreadSafe<FileSelectHelper>;
explicit FileSelectHelper(Profile* profile);
virtual ~FileSelectHelper(); virtual ~FileSelectHelper();
// Utility class which can listen for directory lister events and relay // Utility class which can listen for directory lister events and relay
...@@ -71,6 +70,9 @@ class FileSelectHelper ...@@ -71,6 +70,9 @@ class FileSelectHelper
DISALLOW_COPY_AND_ASSIGN(DirectoryListerDispatchDelegate); DISALLOW_COPY_AND_ASSIGN(DirectoryListerDispatchDelegate);
}; };
void RunFileChooser(content::RenderViewHost* render_view_host,
content::WebContents* tab_contents,
const content::FileChooserParams& params);
void RunFileChooserOnFileThread( void RunFileChooserOnFileThread(
const content::FileChooserParams& params); const content::FileChooserParams& params);
void RunFileChooserOnUIThread( void RunFileChooserOnUIThread(
...@@ -99,6 +101,10 @@ class FileSelectHelper ...@@ -99,6 +101,10 @@ class FileSelectHelper
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const content::NotificationDetails& details) OVERRIDE;
void EnumerateDirectory(int request_id,
content::RenderViewHost* render_view_host,
const FilePath& path);
// Kicks off a new directory enumeration. // Kicks off a new directory enumeration.
void StartNewEnumeration(const FilePath& path, void StartNewEnumeration(const FilePath& path,
int request_id, int request_id,
......
...@@ -2503,34 +2503,6 @@ bool Browser::RunUnloadEventsHelper(WebContents* contents) { ...@@ -2503,34 +2503,6 @@ bool Browser::RunUnloadEventsHelper(WebContents* contents) {
return false; 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 // static
void Browser::JSOutOfMemoryHelper(WebContents* tab) { void Browser::JSOutOfMemoryHelper(WebContents* tab) {
TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents(
...@@ -3889,12 +3861,13 @@ void Browser::DidEndColorChooser() { ...@@ -3889,12 +3861,13 @@ void Browser::DidEndColorChooser() {
void Browser::RunFileChooser(WebContents* tab, void Browser::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) { 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) { const FilePath& path) {
EnumerateDirectoryHelper(tab, request_id, path); FileSelectHelper::EnumerateDirectory(tab, request_id, path);
} }
void Browser::ToggleFullscreenModeForTab(WebContents* tab, void Browser::ToggleFullscreenModeForTab(WebContents* tab,
......
...@@ -683,15 +683,6 @@ class Browser : public TabStripModelDelegate, ...@@ -683,15 +683,6 @@ class Browser : public TabStripModelDelegate,
// Helper function to run unload listeners on a WebContents. // Helper function to run unload listeners on a WebContents.
static bool RunUnloadEventsHelper(content::WebContents* contents); 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 // Helper function to handle JS out of memory notifications
static void JSOutOfMemoryHelper(content::WebContents* tab); static void JSOutOfMemoryHelper(content::WebContents* tab);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/extensions/extension_tabs_module_constants.h" #include "chrome/browser/extensions/extension_tabs_module_constants.h"
#include "chrome/browser/extensions/extension_window_controller.h" #include "chrome/browser/extensions/extension_window_controller.h"
#include "chrome/browser/extensions/shell_window_registry.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/intents/web_intents_util.h"
#include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -172,7 +173,7 @@ void ShellWindow::WebIntentDispatch( ...@@ -172,7 +173,7 @@ void ShellWindow::WebIntentDispatch(
void ShellWindow::RunFileChooser(WebContents* tab, void ShellWindow::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) { const content::FileChooserParams& params) {
Browser::RunFileChooserHelper(tab, params); FileSelectHelper::RunFileChooser(tab, params);
} }
void ShellWindow::Observe(int type, 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