| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tab_contents/web_contents.h" | 5 #include "chrome/browser/tab_contents/web_contents.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 void WebContents::OnSavePage() { | 646 void WebContents::OnSavePage() { |
| 647 // If we can not save the page, try to download it. | 647 // If we can not save the page, try to download it. |
| 648 if (!SavePackage::IsSavableContents(contents_mime_type())) { | 648 if (!SavePackage::IsSavableContents(contents_mime_type())) { |
| 649 DownloadManager* dlm = profile()->GetDownloadManager(); | 649 DownloadManager* dlm = profile()->GetDownloadManager(); |
| 650 const GURL& current_page_url = GetURL(); | 650 const GURL& current_page_url = GetURL(); |
| 651 if (dlm && current_page_url.is_valid()) | 651 if (dlm && current_page_url.is_valid()) |
| 652 dlm->DownloadUrl(current_page_url, GURL(), this); | 652 dlm->DownloadUrl(current_page_url, GURL(), this); |
| 653 return; | 653 return; |
| 654 } | 654 } |
| 655 | 655 |
| 656 // Get our user preference state. | 656 Stop(); |
| 657 PrefService* prefs = profile()->GetPrefs(); | |
| 658 DCHECK(prefs); | |
| 659 | 657 |
| 660 FilePath suggest_name = SavePackage::GetSuggestNameForSaveAs(prefs, | 658 // Create the save package and possibly prompt the user for the name to save |
| 661 FilePath::FromWStringHack(UTF16ToWideHack(GetTitle()))); | 659 // the page as. The user prompt is an asynchronous operation that runs on |
| 662 | 660 // another thread. |
| 663 SavePackage::SavePackageParam param(contents_mime_type()); | 661 save_package_ = new SavePackage(this); |
| 664 param.prefs = prefs; | 662 save_package_->GetSaveInfo(); |
| 665 | |
| 666 // TODO(rocking): Use new asynchronous dialog boxes to prevent the SaveAs | |
| 667 // dialog blocking the UI thread. See bug: http://b/issue?id=1129694. | |
| 668 if (SavePackage::GetSaveInfo(suggest_name, view_->GetNativeView(), | |
| 669 ¶m, profile()->GetDownloadManager())) { | |
| 670 SavePage(param.saved_main_file_path.ToWStringHack(), | |
| 671 param.dir.ToWStringHack(), | |
| 672 param.save_type); | |
| 673 } | |
| 674 } | 663 } |
| 675 | 664 |
| 665 // Used in automated testing to bypass prompting the user for file names. |
| 666 // Instead, the names and paths are hard coded rather than running them through |
| 667 // file name sanitation and extension / mime checking. |
| 676 void WebContents::SavePage(const std::wstring& main_file, | 668 void WebContents::SavePage(const std::wstring& main_file, |
| 677 const std::wstring& dir_path, | 669 const std::wstring& dir_path, |
| 678 SavePackage::SavePackageType save_type) { | 670 SavePackage::SavePackageType save_type) { |
| 679 // Stop the page from navigating. | 671 // Stop the page from navigating. |
| 680 Stop(); | 672 Stop(); |
| 681 | 673 |
| 682 save_package_ = new SavePackage(this, save_type, | 674 save_package_ = new SavePackage(this, save_type, |
| 683 FilePath::FromWStringHack(main_file), | 675 FilePath::FromWStringHack(main_file), |
| 684 FilePath::FromWStringHack(dir_path)); | 676 FilePath::FromWStringHack(dir_path)); |
| 685 save_package_->Init(); | 677 save_package_->Init(); |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 | 1142 |
| 1151 void WebContents::RunFileChooser(bool multiple_files, | 1143 void WebContents::RunFileChooser(bool multiple_files, |
| 1152 const std::wstring& title, | 1144 const std::wstring& title, |
| 1153 const std::wstring& default_file, | 1145 const std::wstring& default_file, |
| 1154 const std::wstring& filter) { | 1146 const std::wstring& filter) { |
| 1155 if (!select_file_dialog_.get()) | 1147 if (!select_file_dialog_.get()) |
| 1156 select_file_dialog_ = SelectFileDialog::Create(this); | 1148 select_file_dialog_ = SelectFileDialog::Create(this); |
| 1157 SelectFileDialog::Type dialog_type = | 1149 SelectFileDialog::Type dialog_type = |
| 1158 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : | 1150 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE : |
| 1159 SelectFileDialog::SELECT_OPEN_FILE; | 1151 SelectFileDialog::SELECT_OPEN_FILE; |
| 1160 select_file_dialog_->SelectFile(dialog_type, title, default_file, filter, | 1152 select_file_dialog_->SelectFile(dialog_type, title, default_file, |
| 1161 std::wstring(), | 1153 filter, 0, std::wstring(), |
| 1162 view_->GetTopLevelNativeWindow(), NULL); | 1154 view_->GetTopLevelNativeWindow(), NULL); |
| 1163 } | 1155 } |
| 1164 | 1156 |
| 1165 void WebContents::RunJavaScriptMessage( | 1157 void WebContents::RunJavaScriptMessage( |
| 1166 const std::wstring& message, | 1158 const std::wstring& message, |
| 1167 const std::wstring& default_prompt, | 1159 const std::wstring& default_prompt, |
| 1168 const GURL& frame_url, | 1160 const GURL& frame_url, |
| 1169 const int flags, | 1161 const int flags, |
| 1170 IPC::Message* reply_msg, | 1162 IPC::Message* reply_msg, |
| 1171 bool* did_suppress_message) { | 1163 bool* did_suppress_message) { |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 Details<FindNotificationDetails>(&find_result_)); | 1558 Details<FindNotificationDetails>(&find_result_)); |
| 1567 } | 1559 } |
| 1568 | 1560 |
| 1569 bool WebContents::CanTerminate() const { | 1561 bool WebContents::CanTerminate() const { |
| 1570 if (!delegate()) | 1562 if (!delegate()) |
| 1571 return true; | 1563 return true; |
| 1572 | 1564 |
| 1573 return !delegate()->IsExternalTabContainer(); | 1565 return !delegate()->IsExternalTabContainer(); |
| 1574 } | 1566 } |
| 1575 | 1567 |
| 1576 void WebContents::FileSelected(const std::wstring& path, void* params) { | 1568 void WebContents::FileSelected(const std::wstring& path, |
| 1569 int index, void* params) { |
| 1577 render_view_host()->FileSelected(path); | 1570 render_view_host()->FileSelected(path); |
| 1578 } | 1571 } |
| 1579 | 1572 |
| 1580 void WebContents::MultiFilesSelected(const std::vector<std::wstring>& files, | 1573 void WebContents::MultiFilesSelected(const std::vector<std::wstring>& files, |
| 1581 void* params) { | 1574 void* params) { |
| 1582 render_view_host()->MultiFilesSelected(files); | 1575 render_view_host()->MultiFilesSelected(files); |
| 1583 } | 1576 } |
| 1584 | 1577 |
| 1585 void WebContents::FileSelectionCanceled(void* params) { | 1578 void WebContents::FileSelectionCanceled(void* params) { |
| 1586 // If the user cancels choosing a file to upload we pass back an | 1579 // If the user cancels choosing a file to upload we pass back an |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 // -> Use pending DOM UI if any. | 2030 // -> Use pending DOM UI if any. |
| 2038 // | 2031 // |
| 2039 // - Normal state with no load: committed nav entry + no pending nav entry: | 2032 // - Normal state with no load: committed nav entry + no pending nav entry: |
| 2040 // -> Use committed DOM UI. | 2033 // -> Use committed DOM UI. |
| 2041 if (controller()->GetPendingEntry() && | 2034 if (controller()->GetPendingEntry() && |
| 2042 (controller()->GetLastCommittedEntry() || | 2035 (controller()->GetLastCommittedEntry() || |
| 2043 render_manager_.pending_dom_ui())) | 2036 render_manager_.pending_dom_ui())) |
| 2044 return render_manager_.pending_dom_ui(); | 2037 return render_manager_.pending_dom_ui(); |
| 2045 return render_manager_.dom_ui(); | 2038 return render_manager_.dom_ui(); |
| 2046 } | 2039 } |
| OLD | NEW |