| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/tab_contents/tab_contents.h" | 5 #include "content/browser/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/download/download_manager.h" | 16 #include "chrome/browser/download/download_manager.h" |
| 17 #include "chrome/browser/download/download_request_limiter.h" | 17 #include "chrome/browser/download/download_request_limiter.h" |
| 18 #include "chrome/browser/download/download_util.h" | 18 #include "chrome/browser/download/download_util.h" |
| 19 #include "content/browser/browser_context.h" | 19 #include "content/browser/browser_context.h" |
| 20 #include "chrome/browser/download/save_package_file_picker.h" |
| 20 #include "content/browser/child_process_security_policy.h" | 21 #include "content/browser/child_process_security_policy.h" |
| 21 #include "content/browser/content_browser_client.h" | 22 #include "content/browser/content_browser_client.h" |
| 22 #include "content/browser/debugger/devtools_manager.h" | 23 #include "content/browser/debugger/devtools_manager.h" |
| 23 #include "content/browser/host_zoom_map.h" | 24 #include "content/browser/host_zoom_map.h" |
| 24 #include "content/browser/in_process_webkit/session_storage_namespace.h" | 25 #include "content/browser/in_process_webkit/session_storage_namespace.h" |
| 25 #include "content/browser/load_from_memory_cache_details.h" | 26 #include "content/browser/load_from_memory_cache_details.h" |
| 26 #include "content/browser/load_notification_details.h" | 27 #include "content/browser/load_notification_details.h" |
| 27 #include "content/browser/renderer_host/render_process_host.h" | 28 #include "content/browser/renderer_host/render_process_host.h" |
| 28 #include "content/browser/renderer_host/render_view_host.h" | 29 #include "content/browser/renderer_host/render_view_host.h" |
| 29 #include "content/browser/renderer_host/render_widget_host_view.h" | 30 #include "content/browser/renderer_host/render_widget_host_view.h" |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 734 |
| 734 Stop(); | 735 Stop(); |
| 735 | 736 |
| 736 // Create the save package and possibly prompt the user for the name to save | 737 // Create the save package and possibly prompt the user for the name to save |
| 737 // the page as. The user prompt is an asynchronous operation that runs on | 738 // the page as. The user prompt is an asynchronous operation that runs on |
| 738 // another thread. | 739 // another thread. |
| 739 save_package_ = new SavePackage(this); | 740 save_package_ = new SavePackage(this); |
| 740 save_package_->GetSaveInfo(); | 741 save_package_->GetSaveInfo(); |
| 741 } | 742 } |
| 742 | 743 |
| 743 // Used in automated testing to bypass prompting the user for file names. | |
| 744 // Instead, the names and paths are hard coded rather than running them through | |
| 745 // file name sanitation and extension / mime checking. | |
| 746 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, | 744 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
| 747 SavePackage::SavePackageType save_type) { | 745 SavePackage::SavePackageType save_type) { |
| 748 // Stop the page from navigating. | 746 // Stop the page from navigating. |
| 749 Stop(); | 747 Stop(); |
| 750 | 748 |
| 751 save_package_ = new SavePackage(this, save_type, main_file, dir_path); | 749 save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
| 750 // Skips GetSaveInfo() and directly calls Init(). |
| 751 // We do not have to explicitly disable the select file dialog |
| 752 // since we skip the process that can show the dialog. |
| 752 return save_package_->Init(); | 753 return save_package_->Init(); |
| 753 } | 754 } |
| 754 | 755 |
| 756 string16 TabContents::SavePageBasedOnDefaultPrefs() { |
| 757 Stop(); |
| 758 |
| 759 save_package_ = new SavePackage(this); |
| 760 // Disables the select file dialog. |
| 761 SavePackageFilePicker::SetShouldPromptUser(false); |
| 762 // This GetSaveInfo() calls save_package_->Init() in the background. |
| 763 save_package_->GetSaveInfo(); |
| 764 return GetTitle(); |
| 765 } |
| 766 |
| 755 void TabContents::OnSaveURL(const GURL& url) { | 767 void TabContents::OnSaveURL(const GURL& url) { |
| 756 DownloadManager* dlm = browser_context()->GetDownloadManager(); | 768 DownloadManager* dlm = browser_context()->GetDownloadManager(); |
| 757 dlm->DownloadUrl(url, GetURL(), "", this); | 769 dlm->DownloadUrl(url, GetURL(), "", this); |
| 758 } | 770 } |
| 759 | 771 |
| 760 bool TabContents::IsActiveEntry(int32 page_id) { | 772 bool TabContents::IsActiveEntry(int32 page_id) { |
| 761 NavigationEntry* active_entry = controller_.GetActiveEntry(); | 773 NavigationEntry* active_entry = controller_.GetActiveEntry(); |
| 762 return (active_entry != NULL && | 774 return (active_entry != NULL && |
| 763 active_entry->site_instance() == GetSiteInstance() && | 775 active_entry->site_instance() == GetSiteInstance() && |
| 764 active_entry->page_id() == page_id); | 776 active_entry->page_id() == page_id); |
| (...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1889 } | 1901 } |
| 1890 | 1902 |
| 1891 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1903 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
| 1892 render_manager_.SwapInRenderViewHost(rvh); | 1904 render_manager_.SwapInRenderViewHost(rvh); |
| 1893 } | 1905 } |
| 1894 | 1906 |
| 1895 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1907 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 1896 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1908 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 1897 rwh_view->SetSize(view()->GetContainerSize()); | 1909 rwh_view->SetSize(view()->GetContainerSize()); |
| 1898 } | 1910 } |
| OLD | NEW |