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 "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" |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 contents_mime_type_ == "text/xml" || | 927 contents_mime_type_ == "text/xml" || |
| 928 contents_mime_type_ == "application/xhtml+xml" || | 928 contents_mime_type_ == "application/xhtml+xml" || |
| 929 contents_mime_type_ == "text/plain" || | 929 contents_mime_type_ == "text/plain" || |
| 930 contents_mime_type_ == "text/css" || | 930 contents_mime_type_ == "text/css" || |
| 931 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str()); | 931 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str()); |
| 932 } | 932 } |
| 933 | 933 |
| 934 void TabContents::OnSavePage() { | 934 void TabContents::OnSavePage() { |
| 935 // If we can not save the page, try to download it. | 935 // If we can not save the page, try to download it. |
| 936 if (!IsSavable()) { | 936 if (!IsSavable()) { |
| 937 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); | 937 SaveURL(GetURL(), GURL()); |
| 938 const GURL& current_page_url = GetURL(); | 938 download_stats::RecordDownloadCount( |
| 939 if (dlm && current_page_url.is_valid()) { | 939 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT); |
| 940 DownloadSaveInfo save_info; | 940 return; |
| 941 save_info.prompt_for_save_location = true; | |
| 942 dlm->DownloadUrl(current_page_url, | |
| 943 GURL(), | |
| 944 "", | |
| 945 true, // prefer_cache | |
| 946 save_info, | |
| 947 this); | |
| 948 download_stats::RecordDownloadCount( | |
| 949 download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT); | |
| 950 return; | |
| 951 } | |
| 952 } | 941 } |
| 953 | 942 |
| 954 Stop(); | 943 Stop(); |
| 955 | 944 |
| 956 // Create the save package and possibly prompt the user for the name to save | 945 // Create the save package and possibly prompt the user for the name to save |
| 957 // the page as. The user prompt is an asynchronous operation that runs on | 946 // the page as. The user prompt is an asynchronous operation that runs on |
| 958 // another thread. | 947 // another thread. |
| 959 save_package_ = new SavePackage(this); | 948 save_package_ = new SavePackage(this); |
| 960 save_package_->GetSaveInfo(); | 949 save_package_->GetSaveInfo(); |
| 961 } | 950 } |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1418 | 1407 |
| 1419 void TabContents::OnUpdateZoomLimits(int minimum_percent, | 1408 void TabContents::OnUpdateZoomLimits(int minimum_percent, |
| 1420 int maximum_percent, | 1409 int maximum_percent, |
| 1421 bool remember) { | 1410 bool remember) { |
| 1422 minimum_zoom_percent_ = minimum_percent; | 1411 minimum_zoom_percent_ = minimum_percent; |
| 1423 maximum_zoom_percent_ = maximum_percent; | 1412 maximum_zoom_percent_ = maximum_percent; |
| 1424 temporary_zoom_settings_ = !remember; | 1413 temporary_zoom_settings_ = !remember; |
| 1425 } | 1414 } |
| 1426 | 1415 |
| 1427 void TabContents::OnSaveURL(const GURL& url) { | 1416 void TabContents::OnSaveURL(const GURL& url) { |
| 1428 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); | 1417 SaveURL(url, GetURL()); |
| 1429 DownloadSaveInfo save_info; | |
| 1430 save_info.prompt_for_save_location = true; | |
| 1431 dlm->DownloadUrl(url, GetURL(), "", true, save_info, this); | |
| 1432 } | 1418 } |
| 1433 | 1419 |
| 1434 void TabContents::OnEnumerateDirectory(int request_id, | 1420 void TabContents::OnEnumerateDirectory(int request_id, |
| 1435 const FilePath& path) { | 1421 const FilePath& path) { |
| 1436 delegate_->EnumerateDirectory(this, request_id, path); | 1422 delegate_->EnumerateDirectory(this, request_id, path); |
| 1437 } | 1423 } |
| 1438 | 1424 |
| 1439 void TabContents::OnJSOutOfMemory() { | 1425 void TabContents::OnJSOutOfMemory() { |
| 1440 delegate_->JSOutOfMemory(this); | 1426 delegate_->JSOutOfMemory(this); |
| 1441 } | 1427 } |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2281 } | 2267 } |
| 2282 is_showing_before_unload_dialog_ = false; | 2268 is_showing_before_unload_dialog_ = false; |
| 2283 rvh->JavaScriptDialogClosed(reply_msg, success, user_input); | 2269 rvh->JavaScriptDialogClosed(reply_msg, success, user_input); |
| 2284 } | 2270 } |
| 2285 | 2271 |
| 2286 void TabContents::SetEncoding(const std::string& encoding) { | 2272 void TabContents::SetEncoding(const std::string& encoding) { |
| 2287 encoding_ = content::GetContentClient()->browser()-> | 2273 encoding_ = content::GetContentClient()->browser()-> |
| 2288 GetCanonicalEncodingNameByAliasName(encoding); | 2274 GetCanonicalEncodingNameByAliasName(encoding); |
| 2289 } | 2275 } |
| 2290 | 2276 |
| 2277 void TabContents::SaveURL(const GURL& url, const GURL& referrer) { | |
| 2278 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); | |
| 2279 if (!dlm) | |
| 2280 return; | |
| 2281 int64 post_id = -1; | |
| 2282 // Check if the URL to save matches the URL of the page itself. One | |
| 2283 // circumstance where this may not happen is when an embedded instance of the | |
| 2284 // PDF viewer plugin has the save button clicked. | |
|
jam
2012/02/03 20:52:42
we avoid talking about chrome features in content
cbentzel
2012/02/04 14:59:08
Done.
| |
| 2285 if (url == GetURL()) { | |
| 2286 const NavigationEntry* entry = controller_.GetActiveEntry(); | |
| 2287 if (entry) | |
| 2288 post_id = entry->GetPostID(); | |
| 2289 } | |
| 2290 DownloadSaveInfo save_info; | |
| 2291 save_info.prompt_for_save_location = true; | |
| 2292 dlm->DownloadUrl(url, | |
| 2293 referrer, | |
| 2294 "", | |
| 2295 true, // prefer_cache | |
| 2296 post_id, | |
| 2297 save_info, | |
| 2298 this); | |
| 2299 } | |
| 2300 | |
| 2291 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { | 2301 void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
| 2292 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); | 2302 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
| 2293 // Can be NULL during tests. | 2303 // Can be NULL during tests. |
| 2294 if (rwh_view) | 2304 if (rwh_view) |
| 2295 rwh_view->SetSize(GetView()->GetContainerSize()); | 2305 rwh_view->SetSize(GetView()->GetContainerSize()); |
| 2296 } | 2306 } |
| OLD | NEW |