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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 746 |
746 Stop(); | 747 Stop(); |
747 | 748 |
748 // Create the save package and possibly prompt the user for the name to save | 749 // Create the save package and possibly prompt the user for the name to save |
749 // the page as. The user prompt is an asynchronous operation that runs on | 750 // the page as. The user prompt is an asynchronous operation that runs on |
750 // another thread. | 751 // another thread. |
751 save_package_ = new SavePackage(this); | 752 save_package_ = new SavePackage(this); |
752 save_package_->GetSaveInfo(); | 753 save_package_->GetSaveInfo(); |
753 } | 754 } |
754 | 755 |
755 // Used in automated testing to bypass prompting the user for file names. | |
756 // Instead, the names and paths are hard coded rather than running them through | |
757 // file name sanitation and extension / mime checking. | |
758 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, | 756 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
759 SavePackage::SavePackageType save_type) { | 757 SavePackage::SavePackageType save_type) { |
760 // Stop the page from navigating. | 758 // Stop the page from navigating. |
761 Stop(); | 759 Stop(); |
762 | 760 |
763 save_package_ = new SavePackage(this, save_type, main_file, dir_path); | 761 save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
| 762 // Skips GetSaveInfo() and directly calls Init(). |
| 763 // We do not have to explicitly disable the select file dialog |
| 764 // since we skip the process that can show the dialog. |
764 return save_package_->Init(); | 765 return save_package_->Init(); |
765 } | 766 } |
766 | 767 |
| 768 string16 TabContents::SavePageBasedOnDefaultPrefs() { |
| 769 Stop(); |
| 770 |
| 771 save_package_ = new SavePackage(this); |
| 772 // Disables the select file dialog. |
| 773 SavePackageFilePicker::SetShouldPromptUser(false); |
| 774 // This GetSaveInfo() calls save_package_->Init() in the background. |
| 775 save_package_->GetSaveInfo(); |
| 776 return GetTitle(); |
| 777 } |
| 778 |
767 void TabContents::OnSaveURL(const GURL& url) { | 779 void TabContents::OnSaveURL(const GURL& url) { |
768 DownloadManager* dlm = browser_context()->GetDownloadManager(); | 780 DownloadManager* dlm = browser_context()->GetDownloadManager(); |
769 dlm->DownloadUrl(url, GetURL(), "", this); | 781 dlm->DownloadUrl(url, GetURL(), "", this); |
770 } | 782 } |
771 | 783 |
772 bool TabContents::IsActiveEntry(int32 page_id) { | 784 bool TabContents::IsActiveEntry(int32 page_id) { |
773 NavigationEntry* active_entry = controller_.GetActiveEntry(); | 785 NavigationEntry* active_entry = controller_.GetActiveEntry(); |
774 return (active_entry != NULL && | 786 return (active_entry != NULL && |
775 active_entry->site_instance() == GetSiteInstance() && | 787 active_entry->site_instance() == GetSiteInstance() && |
776 active_entry->page_id() == page_id); | 788 active_entry->page_id() == page_id); |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1912 } | 1924 } |
1913 | 1925 |
1914 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1926 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
1915 render_manager_.SwapInRenderViewHost(rvh); | 1927 render_manager_.SwapInRenderViewHost(rvh); |
1916 } | 1928 } |
1917 | 1929 |
1918 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1930 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
1919 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1931 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
1920 rwh_view->SetSize(view()->GetContainerSize()); | 1932 rwh_view->SetSize(view()->GetContainerSize()); |
1921 } | 1933 } |
OLD | NEW |