| Index: chrome/browser/file_select_helper.cc
|
| diff --git a/chrome/browser/file_select_helper.cc b/chrome/browser/file_select_helper.cc
|
| index 22a8fb4a866605ad216f8e3ba34418afeaa4f3cf..92f3b96796bb70658df62f0bb047db15a7a5e464 100644
|
| --- a/chrome/browser/file_select_helper.cc
|
| +++ b/chrome/browser/file_select_helper.cc
|
| @@ -292,6 +292,16 @@ void FileSelectHelper::DeleteTemporaryFiles() {
|
| temporary_files_.clear();
|
| }
|
|
|
| +void FileSelectHelper::CleanUpOnRenderViewHostChange() {
|
| + if (!temporary_files_.empty()) {
|
| + DeleteTemporaryFiles();
|
| +
|
| + // Now that the temporary files have been scheduled for deletion, there
|
| + // is no longer any reason to keep this instance around.
|
| + Release();
|
| + }
|
| +}
|
| +
|
| scoped_ptr<ui::SelectFileDialog::FileTypeInfo>
|
| FileSelectHelper::GetFileTypesFromAcceptType(
|
| const std::vector<base::string16>& accept_types) {
|
| @@ -390,16 +400,11 @@ void FileSelectHelper::RunFileChooser(RenderViewHost* render_view_host,
|
| render_view_host_ = render_view_host;
|
| web_contents_ = web_contents;
|
| notification_registrar_.RemoveAll();
|
| - notification_registrar_.Add(this,
|
| - content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
|
| - content::Source<WebContents>(web_contents_));
|
| + content::WebContentsObserver::Observe(web_contents_);
|
| notification_registrar_.Add(
|
| this,
|
| content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
|
| content::Source<RenderWidgetHost>(render_view_host_));
|
| - notification_registrar_.Add(
|
| - this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| - content::Source<WebContents>(web_contents_));
|
|
|
| BrowserThread::PostTask(
|
| BrowserThread::FILE, FROM_HERE,
|
| @@ -534,29 +539,21 @@ void FileSelectHelper::Observe(int type,
|
| render_view_host_ = NULL;
|
| break;
|
| }
|
| -
|
| - case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: {
|
| - DCHECK(content::Source<WebContents>(source).ptr() == web_contents_);
|
| - web_contents_ = NULL;
|
| - }
|
| -
|
| - // Intentional fall through.
|
| - case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED:
|
| - if (!temporary_files_.empty()) {
|
| - DeleteTemporaryFiles();
|
| -
|
| - // Now that the temporary files have been scheduled for deletion, there
|
| - // is no longer any reason to keep this instance around.
|
| - Release();
|
| - }
|
| -
|
| - break;
|
| -
|
| default:
|
| NOTREACHED();
|
| }
|
| }
|
|
|
| +void FileSelectHelper::RenderViewHostChanged(RenderViewHost* old_host,
|
| + RenderViewHost* new_host) {
|
| + CleanUpOnRenderViewHostChange();
|
| +}
|
| +
|
| +void FileSelectHelper::WebContentsDestroyed() {
|
| + web_contents_ = nullptr;
|
| + CleanUpOnRenderViewHostChange();
|
| +}
|
| +
|
| // static
|
| bool FileSelectHelper::IsAcceptTypeValid(const std::string& accept_type) {
|
| // TODO(raymes): This only does some basic checks, extend to test more cases.
|
|
|