| 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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 | 771 |
| 771 Stop(); | 772 Stop(); |
| 772 | 773 |
| 773 // Create the save package and possibly prompt the user for the name to save | 774 // Create the save package and possibly prompt the user for the name to save |
| 774 // the page as. The user prompt is an asynchronous operation that runs on | 775 // the page as. The user prompt is an asynchronous operation that runs on |
| 775 // another thread. | 776 // another thread. |
| 776 save_package_ = new SavePackage(this); | 777 save_package_ = new SavePackage(this); |
| 777 save_package_->GetSaveInfo(); | 778 save_package_->GetSaveInfo(); |
| 778 } | 779 } |
| 779 | 780 |
| 780 // Used in automated testing to bypass prompting the user for file names. | |
| 781 // Instead, the names and paths are hard coded rather than running them through | |
| 782 // file name sanitation and extension / mime checking. | |
| 783 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, | 781 bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
| 784 SavePackage::SavePackageType save_type) { | 782 SavePackage::SavePackageType save_type) { |
| 785 // Stop the page from navigating. | 783 // Stop the page from navigating. |
| 786 Stop(); | 784 Stop(); |
| 787 | 785 |
| 788 save_package_ = new SavePackage(this, save_type, main_file, dir_path); | 786 save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
| 787 // Skips GetSaveInfo() and directly calls Init(). |
| 788 // We do not have to explicitly disable the select file dialog |
| 789 // since we skip the process that can show the dialog. |
| 789 return save_package_->Init(); | 790 return save_package_->Init(); |
| 790 } | 791 } |
| 791 | 792 |
| 793 string16 TabContents::SavePageBasedOnDefaultPrefs() { |
| 794 Stop(); |
| 795 |
| 796 save_package_ = new SavePackage(this); |
| 797 // Disables the select file dialog. |
| 798 SavePackageFilePicker::SetShouldPromptUser(false); |
| 799 // This GetSaveInfo() calls save_package_->Init() in the background. |
| 800 save_package_->GetSaveInfo(); |
| 801 return GetTitle(); |
| 802 } |
| 803 |
| 792 void TabContents::OnSaveURL(const GURL& url) { | 804 void TabContents::OnSaveURL(const GURL& url) { |
| 793 DownloadManager* dlm = browser_context()->GetDownloadManager(); | 805 DownloadManager* dlm = browser_context()->GetDownloadManager(); |
| 794 dlm->DownloadUrl(url, GetURL(), "", this); | 806 dlm->DownloadUrl(url, GetURL(), "", this); |
| 795 } | 807 } |
| 796 | 808 |
| 797 bool TabContents::IsActiveEntry(int32 page_id) { | 809 bool TabContents::IsActiveEntry(int32 page_id) { |
| 798 NavigationEntry* active_entry = controller_.GetActiveEntry(); | 810 NavigationEntry* active_entry = controller_.GetActiveEntry(); |
| 799 return (active_entry != NULL && | 811 return (active_entry != NULL && |
| 800 active_entry->site_instance() == GetSiteInstance() && | 812 active_entry->site_instance() == GetSiteInstance() && |
| 801 active_entry->page_id() == page_id); | 813 active_entry->page_id() == page_id); |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 } | 1949 } |
| 1938 | 1950 |
| 1939 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { | 1951 void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) { |
| 1940 render_manager_.SwapInRenderViewHost(rvh); | 1952 render_manager_.SwapInRenderViewHost(rvh); |
| 1941 } | 1953 } |
| 1942 | 1954 |
| 1943 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 1955 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 1944 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); | 1956 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); |
| 1945 rwh_view->SetSize(view()->GetContainerSize()); | 1957 rwh_view->SetSize(view()->GetContainerSize()); |
| 1946 } | 1958 } |
| OLD | NEW |