diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 18:50:54 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-11 18:50:54 +0000 |
commit | aaed25234a6000a0f35eda3c5c4b1e58d9a401de (patch) | |
tree | ba46f11711cde21dfdcdef395e9b50a88585d6e0 /chrome | |
parent | 6b7a5e329b36cbda1f8e432fbc92cc7acb5ede4c (diff) | |
download | chromium_src-aaed25234a6000a0f35eda3c5c4b1e58d9a401de.zip chromium_src-aaed25234a6000a0f35eda3c5c4b1e58d9a401de.tar.gz chromium_src-aaed25234a6000a0f35eda3c5c4b1e58d9a401de.tar.bz2 |
Pull the file picker code out of TabContents.
BUG=71097
TEST=hammer on the HTML file selection dialogs. No visible change; no crashes, nothing.
Review URL: http://codereview.chromium.org/6680002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77835 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/file_select_helper.cc | 29 | ||||
-rw-r--r-- | chrome/browser/file_select_helper.h | 47 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents_wrapper.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/tab_contents_wrapper.h | 12 |
4 files changed, 75 insertions, 16 deletions
diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc index 81616d5..1a38437 100644 --- a/chrome/browser/file_select_helper.cc +++ b/chrome/browser/file_select_helper.cc @@ -12,9 +12,11 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/render_widget_host_view.h" +#include "content/browser/tab_contents/tab_contents.h" #include "content/common/notification_details.h" #include "content/common/notification_source.h" #include "grit/generated_resources.h" @@ -192,7 +194,7 @@ SelectFileDialog::FileTypeInfo* FileSelectHelper::GetFileTypesFromAcceptType( void FileSelectHelper::RunFileChooser( RenderViewHost* render_view_host, - const ViewHostMsg_RunFileChooser_Params ¶ms) { + const ViewHostMsg_RunFileChooser_Params& params) { DCHECK(!render_view_host_); render_view_host_ = render_view_host; notification_registrar_.RemoveAll(); @@ -245,3 +247,28 @@ void FileSelectHelper::Observe(NotificationType type, DCHECK(Details<RenderViewHost>(details).ptr() == render_view_host_); render_view_host_ = NULL; } + +FileSelectObserver::FileSelectObserver(TabContents* tab_contents) + : TabContentsObserver(tab_contents) { +} + +FileSelectObserver::~FileSelectObserver() { +} + +bool FileSelectObserver::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(FileSelectObserver, message) + IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +void FileSelectObserver::OnRunFileChooser( + const ViewHostMsg_RunFileChooser_Params& params) { + if (!file_select_helper_.get()) + file_select_helper_.reset(new FileSelectHelper(tab_contents()->profile())); + file_select_helper_->RunFileChooser(tab_contents()->render_view_host(), + params); +} diff --git a/chrome/browser/file_select_helper.h b/chrome/browser/file_select_helper.h index 5a2b4d6..0aa29af 100644 --- a/chrome/browser/file_select_helper.h +++ b/chrome/browser/file_select_helper.h @@ -8,7 +8,9 @@ #include <vector> +#include "base/compiler_specific.h" #include "chrome/browser/ui/shell_dialogs.h" +#include "content/browser/tab_contents/tab_contents_observer.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" #include "net/base/directory_lister.h" @@ -25,26 +27,27 @@ class FileSelectHelper explicit FileSelectHelper(Profile* profile); ~FileSelectHelper(); - // SelectFileDialog::Listener - virtual void FileSelected(const FilePath& path, int index, void* params); - virtual void MultiFilesSelected(const std::vector<FilePath>& files, - void* params); - virtual void FileSelectionCanceled(void* params); - - // net::DirectoryLister::DirectoryListerDelegate - virtual void OnListFile( - const net::DirectoryLister::DirectoryListerData& data); - virtual void OnListDone(int error); - // Show the file chooser dialog. void RunFileChooser(RenderViewHost* render_view_host, const ViewHostMsg_RunFileChooser_Params& params); private: - // NotificationObserver implementation. + // SelectFileDialog::Listener overrides. + virtual void FileSelected( + const FilePath& path, int index, void* params) OVERRIDE; + virtual void MultiFilesSelected(const std::vector<FilePath>& files, + void* params) OVERRIDE; + virtual void FileSelectionCanceled(void* params) OVERRIDE; + + // net::DirectoryLister::DirectoryListerDelegate overrides. + virtual void OnListFile( + const net::DirectoryLister::DirectoryListerData& data) OVERRIDE; + virtual void OnListDone(int error) OVERRIDE; + + // NotificationObserver overrides. virtual void Observe(NotificationType type, const NotificationSource& source, - const NotificationDetails& details); + const NotificationDetails& details) OVERRIDE; // Helper method for handling the SelectFileDialog::Listener callbacks. void DirectorySelected(const FilePath& path); @@ -80,4 +83,22 @@ class FileSelectHelper DISALLOW_COPY_AND_ASSIGN(FileSelectHelper); }; +class FileSelectObserver : public TabContentsObserver { + public: + explicit FileSelectObserver(TabContents* tab_contents); + ~FileSelectObserver(); + + private: + // TabContentsObserver overrides. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + // Called when a file selection is to be done. + void OnRunFileChooser(const ViewHostMsg_RunFileChooser_Params& params); + + // FileSelectHelper, lazily created. + scoped_ptr<FileSelectHelper> file_select_helper_; + + DISALLOW_COPY_AND_ASSIGN(FileSelectObserver); +}; + #endif // CHROME_BROWSER_FILE_SELECT_HELPER_H_ diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 496b1fb..ad5b5a1 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -8,6 +8,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" +#include "chrome/browser/file_select_helper.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager_delegate_impl.h" #include "chrome/browser/prefs/pref_service.h" @@ -56,6 +57,8 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, NotificationService::AllSources()); + // Create the per-tab observers. + file_select_observer_.reset(new FileSelectObserver(contents)); prerender_observer_.reset(new prerender::PrerenderObserver(contents)); } diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 0c075aa..4baec54 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -18,6 +18,7 @@ class PrerenderObserver; } class Extension; +class FileSelectObserver; class FindTabHelper; class NavigationController; class PasswordManager; @@ -134,6 +135,8 @@ class TabContentsWrapper : public NotificationObserver, bool is_starred_; // Tab Helpers --------------------------------------------------------------- + // (These provide API for callers and have a getter function listed in the + // "Tab Helpers" section in the member functions area, above.) scoped_ptr<FindTabHelper> find_tab_helper_; @@ -142,10 +145,15 @@ class TabContentsWrapper : public NotificationObserver, scoped_ptr<PasswordManagerDelegate> password_manager_delegate_; scoped_ptr<PasswordManager> password_manager_; - scoped_ptr<prerender::PrerenderObserver> prerender_observer_; - scoped_ptr<SearchEngineTabHelper> search_engine_tab_helper_; + // Per-tab observers --------------------------------------------------------- + // (These provide no API for callers; objects that need to exist 1:1 with tabs + // and silently do their thing live here.) + + scoped_ptr<FileSelectObserver> file_select_observer_; + scoped_ptr<prerender::PrerenderObserver> prerender_observer_; + // TabContents (MUST BE LAST) ------------------------------------------------ // The supporting objects need to outlive the TabContents dtor (as they may |