Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/file_select_helper.h" | 5 #include "chrome/browser/file_select_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/chrome_select_file_policy.h" | 27 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 28 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
| 31 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 32 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 33 #include "content/public/browser/render_frame_host.h" | |
| 34 #include "content/public/browser/render_process_host.h" | |
| 33 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 34 #include "content/public/browser/render_widget_host.h" | 36 #include "content/public/browser/render_widget_host.h" |
| 35 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
| 36 #include "content/public/browser/storage_partition.h" | 38 #include "content/public/browser/storage_partition.h" |
| 37 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/common/file_chooser_file_info.h" | 40 #include "content/public/common/file_chooser_file_info.h" |
| 39 #include "content/public/common/file_chooser_params.h" | 41 #include "content/public/common/file_chooser_params.h" |
| 40 #include "net/base/filename_util.h" | 42 #include "net/base/filename_util.h" |
| 41 #include "net/base/mime_util.h" | 43 #include "net/base/mime_util.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 ActiveDirectoryEnumeration() : rvh_(NULL) {} | 125 ActiveDirectoryEnumeration() : rvh_(NULL) {} |
| 124 | 126 |
| 125 std::unique_ptr<DirectoryListerDispatchDelegate> delegate_; | 127 std::unique_ptr<DirectoryListerDispatchDelegate> delegate_; |
| 126 std::unique_ptr<net::DirectoryLister> lister_; | 128 std::unique_ptr<net::DirectoryLister> lister_; |
| 127 RenderViewHost* rvh_; | 129 RenderViewHost* rvh_; |
| 128 std::vector<base::FilePath> results_; | 130 std::vector<base::FilePath> results_; |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 FileSelectHelper::FileSelectHelper(Profile* profile) | 133 FileSelectHelper::FileSelectHelper(Profile* profile) |
| 132 : profile_(profile), | 134 : profile_(profile), |
| 133 render_view_host_(NULL), | 135 render_frame_host_(nullptr), |
| 134 web_contents_(NULL), | 136 web_contents_(nullptr), |
| 135 select_file_dialog_(), | 137 select_file_dialog_(), |
| 136 select_file_types_(), | 138 select_file_types_(), |
| 137 dialog_type_(ui::SelectFileDialog::SELECT_OPEN_FILE), | 139 dialog_type_(ui::SelectFileDialog::SELECT_OPEN_FILE), |
| 138 dialog_mode_(FileChooserParams::Open) { | 140 dialog_mode_(FileChooserParams::Open) {} |
| 139 } | |
| 140 | 141 |
| 141 FileSelectHelper::~FileSelectHelper() { | 142 FileSelectHelper::~FileSelectHelper() { |
| 142 // There may be pending file dialogs, we need to tell them that we've gone | 143 // There may be pending file dialogs, we need to tell them that we've gone |
| 143 // away so they don't try and call back to us. | 144 // away so they don't try and call back to us. |
| 144 if (select_file_dialog_.get()) | 145 if (select_file_dialog_.get()) |
| 145 select_file_dialog_->ListenerDestroyed(); | 146 select_file_dialog_->ListenerDestroyed(); |
| 146 | 147 |
| 147 // Stop any pending directory enumeration, prevent a callback, and free | 148 // Stop any pending directory enumeration, prevent a callback, and free |
| 148 // allocated memory. | 149 // allocated memory. |
| 149 std::map<int, ActiveDirectoryEnumeration*>::iterator iter; | 150 std::map<int, ActiveDirectoryEnumeration*>::iterator iter; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 169 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); | 170 FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void FileSelectHelper::FileSelectedWithExtraInfo( | 173 void FileSelectHelper::FileSelectedWithExtraInfo( |
| 173 const ui::SelectedFileInfo& file, | 174 const ui::SelectedFileInfo& file, |
| 174 int index, | 175 int index, |
| 175 void* params) { | 176 void* params) { |
| 176 if (IsValidProfile(profile_)) | 177 if (IsValidProfile(profile_)) |
| 177 profile_->set_last_selected_directory(file.file_path.DirName()); | 178 profile_->set_last_selected_directory(file.file_path.DirName()); |
| 178 | 179 |
| 179 if (!render_view_host_) { | 180 if (!render_frame_host_) { |
| 180 RunFileChooserEnd(); | 181 RunFileChooserEnd(); |
| 181 return; | 182 return; |
| 182 } | 183 } |
| 183 | 184 |
| 184 const base::FilePath& path = file.local_path; | 185 const base::FilePath& path = file.local_path; |
| 185 if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) { | 186 if (dialog_type_ == ui::SelectFileDialog::SELECT_UPLOAD_FOLDER) { |
| 186 StartNewEnumeration(path, kFileSelectEnumerationId, render_view_host_); | 187 StartNewEnumeration(path, kFileSelectEnumerationId, |
| 188 render_frame_host_->GetRenderViewHost()); | |
| 187 return; | 189 return; |
| 188 } | 190 } |
| 189 | 191 |
| 190 std::vector<ui::SelectedFileInfo> files; | 192 std::vector<ui::SelectedFileInfo> files; |
| 191 files.push_back(file); | 193 files.push_back(file); |
| 192 | 194 |
| 193 #if defined(OS_MACOSX) | 195 #if defined(OS_MACOSX) |
| 194 content::BrowserThread::PostTask( | 196 content::BrowserThread::PostTask( |
| 195 content::BrowserThread::FILE_USER_BLOCKING, | 197 content::BrowserThread::FILE_USER_BLOCKING, |
| 196 FROM_HERE, | 198 FROM_HERE, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 if (id == kFileSelectEnumerationId) { | 281 if (id == kFileSelectEnumerationId) { |
| 280 NotifyRenderViewHostAndEnd(selected_files); | 282 NotifyRenderViewHostAndEnd(selected_files); |
| 281 } else { | 283 } else { |
| 282 entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); | 284 entry->rvh_->DirectoryEnumerationFinished(id, entry->results_); |
| 283 EnumerateDirectoryEnd(); | 285 EnumerateDirectoryEnd(); |
| 284 } | 286 } |
| 285 } | 287 } |
| 286 | 288 |
| 287 void FileSelectHelper::NotifyRenderViewHostAndEnd( | 289 void FileSelectHelper::NotifyRenderViewHostAndEnd( |
| 288 const std::vector<ui::SelectedFileInfo>& files) { | 290 const std::vector<ui::SelectedFileInfo>& files) { |
| 289 if (!render_view_host_) { | 291 if (!render_frame_host_) { |
| 290 RunFileChooserEnd(); | 292 RunFileChooserEnd(); |
| 291 return; | 293 return; |
| 292 } | 294 } |
| 293 | 295 |
| 294 #if defined(OS_CHROMEOS) | 296 #if defined(OS_CHROMEOS) |
| 295 if (!files.empty()) { | 297 if (!files.empty()) { |
| 296 if (!IsValidProfile(profile_)) { | 298 if (!IsValidProfile(profile_)) { |
| 297 RunFileChooserEnd(); | 299 RunFileChooserEnd(); |
| 298 return; | 300 return; |
| 299 } | 301 } |
| 300 // Converts |files| into FileChooserFileInfo with handling of non-native | 302 // Converts |files| into FileChooserFileInfo with handling of non-native |
| 301 // files. | 303 // files. |
| 302 storage::FileSystemContext* file_system_context = | 304 storage::FileSystemContext* file_system_context = |
| 303 content::BrowserContext::GetStoragePartition( | 305 content::BrowserContext::GetStoragePartition( |
| 304 profile_, render_view_host_->GetSiteInstance())-> | 306 profile_, render_frame_host_->GetSiteInstance()) |
| 305 GetFileSystemContext(); | 307 ->GetFileSystemContext(); |
|
Lei Zhang
2016/06/10 17:02:41
Is this clang-format's choosing? Maybe have a loca
nasko
2016/06/10 17:19:09
Yes, indeed this is clang-format.
| |
| 306 file_manager::util::ConvertSelectedFileInfoListToFileChooserFileInfoList( | 308 file_manager::util::ConvertSelectedFileInfoListToFileChooserFileInfoList( |
| 307 file_system_context, | 309 file_system_context, |
| 308 web_contents_->GetSiteInstance()->GetSiteURL(), | 310 render_frame_host_->GetSiteInstance()->GetSiteURL(), |
| 309 files, | 311 files, |
| 310 base::Bind( | 312 base::Bind( |
| 311 &FileSelectHelper::NotifyRenderViewHostAndEndAfterConversion, | 313 &FileSelectHelper::NotifyRenderViewHostAndEndAfterConversion, |
| 312 this)); | 314 this)); |
| 313 return; | 315 return; |
| 314 } | 316 } |
| 315 #endif // defined(OS_CHROMEOS) | 317 #endif // defined(OS_CHROMEOS) |
| 316 | 318 |
| 317 std::vector<content::FileChooserFileInfo> chooser_files; | 319 std::vector<content::FileChooserFileInfo> chooser_files; |
| 318 for (const auto& file : files) { | 320 for (const auto& file : files) { |
| 319 content::FileChooserFileInfo chooser_file; | 321 content::FileChooserFileInfo chooser_file; |
| 320 chooser_file.file_path = file.local_path; | 322 chooser_file.file_path = file.local_path; |
| 321 chooser_file.display_name = file.display_name; | 323 chooser_file.display_name = file.display_name; |
| 322 chooser_files.push_back(chooser_file); | 324 chooser_files.push_back(chooser_file); |
| 323 } | 325 } |
| 324 | 326 |
| 325 NotifyRenderViewHostAndEndAfterConversion(chooser_files); | 327 NotifyRenderViewHostAndEndAfterConversion(chooser_files); |
| 326 } | 328 } |
| 327 | 329 |
| 328 void FileSelectHelper::NotifyRenderViewHostAndEndAfterConversion( | 330 void FileSelectHelper::NotifyRenderViewHostAndEndAfterConversion( |
| 329 const std::vector<content::FileChooserFileInfo>& list) { | 331 const std::vector<content::FileChooserFileInfo>& list) { |
| 330 if (render_view_host_) | 332 if (render_frame_host_) |
| 331 render_view_host_->FilesSelectedInChooser(list, dialog_mode_); | 333 render_frame_host_->FilesSelectedInChooser(list, dialog_mode_); |
| 332 | 334 |
| 333 // No members should be accessed from here on. | 335 // No members should be accessed from here on. |
| 334 RunFileChooserEnd(); | 336 RunFileChooserEnd(); |
| 335 } | 337 } |
| 336 | 338 |
| 337 void FileSelectHelper::DeleteTemporaryFiles() { | 339 void FileSelectHelper::DeleteTemporaryFiles() { |
| 338 BrowserThread::PostTask(BrowserThread::FILE, | 340 BrowserThread::PostTask(BrowserThread::FILE, |
| 339 FROM_HERE, | 341 FROM_HERE, |
| 340 base::Bind(&DeleteFiles, temporary_files_)); | 342 base::Bind(&DeleteFiles, temporary_files_)); |
| 341 temporary_files_.clear(); | 343 temporary_files_.clear(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 | 415 |
| 414 if (description_id) { | 416 if (description_id) { |
| 415 file_type->extension_description_overrides.push_back( | 417 file_type->extension_description_overrides.push_back( |
| 416 l10n_util::GetStringUTF16(description_id)); | 418 l10n_util::GetStringUTF16(description_id)); |
| 417 } | 419 } |
| 418 | 420 |
| 419 return file_type; | 421 return file_type; |
| 420 } | 422 } |
| 421 | 423 |
| 422 // static | 424 // static |
| 423 void FileSelectHelper::RunFileChooser(content::WebContents* tab, | 425 void FileSelectHelper::RunFileChooser( |
| 424 const FileChooserParams& params) { | 426 content::RenderFrameHost* render_frame_host, |
| 425 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 427 const FileChooserParams& params) { |
| 428 Profile* profile = Profile::FromBrowserContext( | |
| 429 render_frame_host->GetProcess()->GetBrowserContext()); | |
| 426 // FileSelectHelper will keep itself alive until it sends the result message. | 430 // FileSelectHelper will keep itself alive until it sends the result message. |
| 427 scoped_refptr<FileSelectHelper> file_select_helper( | 431 scoped_refptr<FileSelectHelper> file_select_helper( |
| 428 new FileSelectHelper(profile)); | 432 new FileSelectHelper(profile)); |
| 429 file_select_helper->RunFileChooser( | 433 file_select_helper->RunFileChooser( |
| 430 tab->GetRenderViewHost(), tab, | 434 render_frame_host, |
| 431 base::WrapUnique(new content::FileChooserParams(params))); | 435 base::WrapUnique(new content::FileChooserParams(params))); |
| 432 } | 436 } |
| 433 | 437 |
| 434 // static | 438 // static |
| 435 void FileSelectHelper::EnumerateDirectory(content::WebContents* tab, | 439 void FileSelectHelper::EnumerateDirectory(content::WebContents* tab, |
| 436 int request_id, | 440 int request_id, |
| 437 const base::FilePath& path) { | 441 const base::FilePath& path) { |
| 438 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 442 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
| 439 // FileSelectHelper will keep itself alive until it sends the result message. | 443 // FileSelectHelper will keep itself alive until it sends the result message. |
| 440 scoped_refptr<FileSelectHelper> file_select_helper( | 444 scoped_refptr<FileSelectHelper> file_select_helper( |
| 441 new FileSelectHelper(profile)); | 445 new FileSelectHelper(profile)); |
| 442 file_select_helper->EnumerateDirectory( | 446 file_select_helper->EnumerateDirectory( |
| 443 request_id, tab->GetRenderViewHost(), path); | 447 request_id, tab->GetRenderViewHost(), path); |
| 444 } | 448 } |
| 445 | 449 |
| 446 void FileSelectHelper::RunFileChooser( | 450 void FileSelectHelper::RunFileChooser( |
| 447 RenderViewHost* render_view_host, | 451 content::RenderFrameHost* render_frame_host, |
| 448 content::WebContents* web_contents, | |
| 449 std::unique_ptr<FileChooserParams> params) { | 452 std::unique_ptr<FileChooserParams> params) { |
| 450 DCHECK(!render_view_host_); | 453 DCHECK(!render_frame_host_); |
| 451 DCHECK(!web_contents_); | 454 DCHECK(!web_contents_); |
| 452 DCHECK(params->default_file_name.empty() || | 455 DCHECK(params->default_file_name.empty() || |
| 453 params->mode == FileChooserParams::Save) | 456 params->mode == FileChooserParams::Save) |
| 454 << "The default_file_name parameter should only be specified for Save " | 457 << "The default_file_name parameter should only be specified for Save " |
| 455 "file choosers"; | 458 "file choosers"; |
| 456 DCHECK(params->default_file_name == params->default_file_name.BaseName()) | 459 DCHECK(params->default_file_name == params->default_file_name.BaseName()) |
| 457 << "The default_file_name parameter should not contain path separators"; | 460 << "The default_file_name parameter should not contain path separators"; |
| 458 | 461 |
| 459 render_view_host_ = render_view_host; | 462 render_frame_host_ = render_frame_host; |
| 460 web_contents_ = web_contents; | 463 web_contents_ = WebContents::FromRenderFrameHost(render_frame_host); |
| 461 notification_registrar_.RemoveAll(); | 464 notification_registrar_.RemoveAll(); |
| 462 content::WebContentsObserver::Observe(web_contents_); | 465 content::WebContentsObserver::Observe(web_contents_); |
| 463 notification_registrar_.Add( | 466 notification_registrar_.Add( |
| 464 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 467 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 465 content::Source<RenderWidgetHost>(render_view_host_->GetWidget())); | 468 content::Source<RenderWidgetHost>( |
| 469 render_frame_host_->GetRenderViewHost()->GetWidget())); | |
| 466 | 470 |
| 467 BrowserThread::PostTask( | 471 BrowserThread::PostTask( |
| 468 BrowserThread::FILE, FROM_HERE, | 472 BrowserThread::FILE, FROM_HERE, |
| 469 base::Bind(&FileSelectHelper::GetFileTypesOnFileThread, this, | 473 base::Bind(&FileSelectHelper::GetFileTypesOnFileThread, this, |
| 470 base::Passed(¶ms))); | 474 base::Passed(¶ms))); |
| 471 | 475 |
| 472 // Because this class returns notifications to the RenderViewHost, it is | 476 // Because this class returns notifications to the RenderViewHost, it is |
| 473 // difficult for callers to know how long to keep a reference to this | 477 // difficult for callers to know how long to keep a reference to this |
| 474 // instance. We AddRef() here to keep the instance alive after we return | 478 // instance. We AddRef() here to keep the instance alive after we return |
| 475 // to the caller, until the last callback is received from the file dialog. | 479 // to the caller, until the last callback is received from the file dialog. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 return; | 547 return; |
| 544 } | 548 } |
| 545 RunFileChooserOnUIThread(default_file_path, std::move(params)); | 549 RunFileChooserOnUIThread(default_file_path, std::move(params)); |
| 546 } | 550 } |
| 547 #endif | 551 #endif |
| 548 | 552 |
| 549 void FileSelectHelper::RunFileChooserOnUIThread( | 553 void FileSelectHelper::RunFileChooserOnUIThread( |
| 550 const base::FilePath& default_file_path, | 554 const base::FilePath& default_file_path, |
| 551 std::unique_ptr<FileChooserParams> params) { | 555 std::unique_ptr<FileChooserParams> params) { |
| 552 DCHECK(params); | 556 DCHECK(params); |
| 553 if (!render_view_host_ || !web_contents_ || !IsValidProfile(profile_) || | 557 if (!render_frame_host_ || !web_contents_ || !IsValidProfile(profile_) || |
| 554 !render_view_host_->GetWidget()->GetView()) { | 558 !web_contents_->GetNativeView()) { |
| 555 // If the renderer was destroyed before we started, just cancel the | 559 // If the renderer was destroyed before we started, just cancel the |
| 556 // operation. | 560 // operation. |
| 557 RunFileChooserEnd(); | 561 RunFileChooserEnd(); |
| 558 return; | 562 return; |
| 559 } | 563 } |
| 560 | 564 |
| 561 select_file_dialog_ = ui::SelectFileDialog::Create( | 565 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 562 this, new ChromeSelectFilePolicy(web_contents_)); | 566 this, new ChromeSelectFilePolicy(web_contents_)); |
| 563 if (!select_file_dialog_.get()) | 567 if (!select_file_dialog_.get()) |
| 564 return; | 568 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 576 break; | 580 break; |
| 577 case FileChooserParams::Save: | 581 case FileChooserParams::Save: |
| 578 dialog_type_ = ui::SelectFileDialog::SELECT_SAVEAS_FILE; | 582 dialog_type_ = ui::SelectFileDialog::SELECT_SAVEAS_FILE; |
| 579 break; | 583 break; |
| 580 default: | 584 default: |
| 581 // Prevent warning. | 585 // Prevent warning. |
| 582 dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE; | 586 dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE; |
| 583 NOTREACHED(); | 587 NOTREACHED(); |
| 584 } | 588 } |
| 585 | 589 |
| 586 gfx::NativeWindow owning_window = platform_util::GetTopLevel( | 590 gfx::NativeWindow owning_window = |
| 587 render_view_host_->GetWidget()->GetView()->GetNativeView()); | 591 platform_util::GetTopLevel(web_contents_->GetNativeView()); |
| 588 | 592 |
| 589 #if defined(OS_ANDROID) | 593 #if defined(OS_ANDROID) |
| 590 // Android needs the original MIME types and an additional capture value. | 594 // Android needs the original MIME types and an additional capture value. |
| 591 std::pair<std::vector<base::string16>, bool> accept_types = | 595 std::pair<std::vector<base::string16>, bool> accept_types = |
| 592 std::make_pair(params->accept_types, params->capture); | 596 std::make_pair(params->accept_types, params->capture); |
| 593 #endif | 597 #endif |
| 594 | 598 |
| 595 select_file_dialog_->SelectFile( | 599 select_file_dialog_->SelectFile( |
| 596 dialog_type_, params->title, default_file_path, select_file_types_.get(), | 600 dialog_type_, params->title, default_file_path, select_file_types_.get(), |
| 597 select_file_types_.get() && !select_file_types_->extensions.empty() | 601 select_file_types_.get() && !select_file_types_->extensions.empty() |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 611 // This method is called when we receive the last callback from the file | 615 // This method is called when we receive the last callback from the file |
| 612 // chooser dialog. Perform any cleanup and release the reference we added | 616 // chooser dialog. Perform any cleanup and release the reference we added |
| 613 // in RunFileChooser(). | 617 // in RunFileChooser(). |
| 614 void FileSelectHelper::RunFileChooserEnd() { | 618 void FileSelectHelper::RunFileChooserEnd() { |
| 615 // If there are temporary files, then this instance needs to stick around | 619 // If there are temporary files, then this instance needs to stick around |
| 616 // until web_contents_ is destroyed, so that this instance can delete the | 620 // until web_contents_ is destroyed, so that this instance can delete the |
| 617 // temporary files. | 621 // temporary files. |
| 618 if (!temporary_files_.empty()) | 622 if (!temporary_files_.empty()) |
| 619 return; | 623 return; |
| 620 | 624 |
| 621 render_view_host_ = NULL; | 625 render_frame_host_ = nullptr; |
| 622 web_contents_ = NULL; | 626 web_contents_ = nullptr; |
| 623 Release(); | 627 Release(); |
| 624 } | 628 } |
| 625 | 629 |
| 626 void FileSelectHelper::EnumerateDirectory(int request_id, | 630 void FileSelectHelper::EnumerateDirectory(int request_id, |
| 627 RenderViewHost* render_view_host, | 631 RenderViewHost* render_view_host, |
| 628 const base::FilePath& path) { | 632 const base::FilePath& path) { |
| 629 | 633 |
| 630 // Because this class returns notifications to the RenderViewHost, it is | 634 // Because this class returns notifications to the RenderViewHost, it is |
| 631 // difficult for callers to know how long to keep a reference to this | 635 // difficult for callers to know how long to keep a reference to this |
| 632 // instance. We AddRef() here to keep the instance alive after we return | 636 // instance. We AddRef() here to keep the instance alive after we return |
| 633 // to the caller, until the last callback is received from the enumeration | 637 // to the caller, until the last callback is received from the enumeration |
| 634 // code. At that point, we must call EnumerateDirectoryEnd(). | 638 // code. At that point, we must call EnumerateDirectoryEnd(). |
| 635 AddRef(); | 639 AddRef(); |
| 636 StartNewEnumeration(path, request_id, render_view_host); | 640 StartNewEnumeration(path, request_id, render_view_host); |
| 637 } | 641 } |
| 638 | 642 |
| 639 // This method is called when we receive the last callback from the enumeration | 643 // This method is called when we receive the last callback from the enumeration |
| 640 // code. Perform any cleanup and release the reference we added in | 644 // code. Perform any cleanup and release the reference we added in |
| 641 // EnumerateDirectory(). | 645 // EnumerateDirectory(). |
| 642 void FileSelectHelper::EnumerateDirectoryEnd() { | 646 void FileSelectHelper::EnumerateDirectoryEnd() { |
| 643 Release(); | 647 Release(); |
| 644 } | 648 } |
| 645 | 649 |
| 646 void FileSelectHelper::Observe(int type, | 650 void FileSelectHelper::Observe(int type, |
| 647 const content::NotificationSource& source, | 651 const content::NotificationSource& source, |
| 648 const content::NotificationDetails& details) { | 652 const content::NotificationDetails& details) { |
| 649 switch (type) { | 653 switch (type) { |
| 650 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { | 654 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 651 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == | 655 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == |
| 652 render_view_host_->GetWidget()); | 656 render_frame_host_->GetRenderViewHost()->GetWidget()); |
| 653 render_view_host_ = NULL; | 657 render_frame_host_ = NULL; |
| 654 break; | 658 break; |
| 655 } | 659 } |
| 656 default: | 660 default: |
| 657 NOTREACHED(); | 661 NOTREACHED(); |
| 658 } | 662 } |
| 659 } | 663 } |
| 660 | 664 |
| 661 void FileSelectHelper::RenderViewHostChanged(RenderViewHost* old_host, | 665 void FileSelectHelper::RenderViewHostChanged(RenderViewHost* old_host, |
| 662 RenderViewHost* new_host) { | 666 RenderViewHost* new_host) { |
| 663 CleanUpOnRenderViewHostChange(); | 667 CleanUpOnRenderViewHostChange(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 685 | 689 |
| 686 // static | 690 // static |
| 687 base::FilePath FileSelectHelper::GetSanitizedFileName( | 691 base::FilePath FileSelectHelper::GetSanitizedFileName( |
| 688 const base::FilePath& suggested_filename) { | 692 const base::FilePath& suggested_filename) { |
| 689 if (suggested_filename.empty()) | 693 if (suggested_filename.empty()) |
| 690 return base::FilePath(); | 694 return base::FilePath(); |
| 691 return net::GenerateFileName( | 695 return net::GenerateFileName( |
| 692 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), | 696 GURL(), std::string(), std::string(), suggested_filename.AsUTF8Unsafe(), |
| 693 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); | 697 std::string(), l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); |
| 694 } | 698 } |
| OLD | NEW |