Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/browser/download/save_package.cc

Issue 4431001: Revert 64960 - Turn on file access checks on Win.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/shared_resources_data_source.cc ('k') | chrome/browser/io_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/download/save_package.h" 5 #include "chrome/browser/download/save_package.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/i18n/file_util_icu.h" 10 #include "base/i18n/file_util_icu.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "base/thread_restrictions.h"
17 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
18 #include "base/task.h" 17 #include "base/task.h"
19 #include "base/thread.h" 18 #include "base/thread.h"
20 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/browser_thread.h" 20 #include "chrome/browser/browser_thread.h"
22 #include "chrome/browser/download/download_item.h" 21 #include "chrome/browser/download/download_item.h"
23 #include "chrome/browser/download/download_item_model.h" 22 #include "chrome/browser/download/download_item_model.h"
24 #include "chrome/browser/download/download_manager.h" 23 #include "chrome/browser/download/download_manager.h"
25 #include "chrome/browser/download/download_shelf.h" 24 #include "chrome/browser/download/download_shelf.h"
26 #include "chrome/browser/download/download_util.h" 25 #include "chrome/browser/download/download_util.h"
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 // Adjust extension for complete types. 1151 // Adjust extension for complete types.
1153 if (can_save_as_complete) 1152 if (can_save_as_complete)
1154 name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext); 1153 name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext);
1155 1154
1156 FilePath::StringType file_name = name_with_proper_ext.value(); 1155 FilePath::StringType file_name = name_with_proper_ext.value();
1157 file_util::ReplaceIllegalCharactersInPath(&file_name, ' '); 1156 file_util::ReplaceIllegalCharactersInPath(&file_name, ' ');
1158 return FilePath(file_name); 1157 return FilePath(file_name);
1159 } 1158 }
1160 1159
1161 FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) { 1160 FilePath SavePackage::EnsureHtmlExtension(const FilePath& name) {
1162 // The GetMimeTypeFromExtension call will end up going to disk. Do this on
1163 // another thread to avoid slowing the UI thread. http://crbug.com/61775
1164 base::ThreadRestrictions::ScopedAllowIO allow_io;
1165
1166 // If the file name doesn't have an extension suitable for HTML files, 1161 // If the file name doesn't have an extension suitable for HTML files,
1167 // append one. 1162 // append one.
1168 FilePath::StringType ext = name.Extension(); 1163 FilePath::StringType ext = name.Extension();
1169 if (!ext.empty()) 1164 if (!ext.empty())
1170 ext.erase(ext.begin()); // Erase preceding '.'. 1165 ext.erase(ext.begin()); // Erase preceding '.'.
1171 std::string mime_type; 1166 std::string mime_type;
1172 if (!net::GetMimeTypeFromExtension(ext, &mime_type) || 1167 if (!net::GetMimeTypeFromExtension(ext, &mime_type) ||
1173 !CanSaveAsComplete(mime_type)) { 1168 !CanSaveAsComplete(mime_type)) {
1174 return FilePath(name.value() + FILE_PATH_LITERAL(".") + 1169 return FilePath(name.value() + FILE_PATH_LITERAL(".") +
1175 kDefaultHtmlExtension); 1170 kDefaultHtmlExtension);
1176 } 1171 }
1177 return name; 1172 return name;
1178 } 1173 }
1179 1174
1180 FilePath SavePackage::EnsureMimeExtension(const FilePath& name, 1175 FilePath SavePackage::EnsureMimeExtension(const FilePath& name,
1181 const FilePath::StringType& contents_mime_type) { 1176 const FilePath::StringType& contents_mime_type) {
1182 // The GetMimeTypeFromExtension call will end up going to disk. Do this on
1183 // another thread to avoid slowing the UI thread. http://crbug.com/61775
1184 base::ThreadRestrictions::ScopedAllowIO allow_io;
1185
1186 // Start extension at 1 to skip over period if non-empty. 1177 // Start extension at 1 to skip over period if non-empty.
1187 FilePath::StringType ext = name.Extension().length() ? 1178 FilePath::StringType ext = name.Extension().length() ?
1188 name.Extension().substr(1) : name.Extension(); 1179 name.Extension().substr(1) : name.Extension();
1189 FilePath::StringType suggested_extension = 1180 FilePath::StringType suggested_extension =
1190 ExtensionForMimeType(contents_mime_type); 1181 ExtensionForMimeType(contents_mime_type);
1191 std::string mime_type; 1182 std::string mime_type;
1192 if (!suggested_extension.empty() && 1183 if (!suggested_extension.empty() &&
1193 (!net::GetMimeTypeFromExtension(ext, &mime_type) || 1184 (!net::GetMimeTypeFromExtension(ext, &mime_type) ||
1194 !IsSavableContents(mime_type))) { 1185 !IsSavableContents(mime_type))) {
1195 // Extension is absent or needs to be updated. 1186 // Extension is absent or needs to be updated.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 int index, void* params) { 1395 int index, void* params) {
1405 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); 1396 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params);
1406 ContinueSave(save_params, path, index); 1397 ContinueSave(save_params, path, index);
1407 delete save_params; 1398 delete save_params;
1408 } 1399 }
1409 1400
1410 void SavePackage::FileSelectionCanceled(void* params) { 1401 void SavePackage::FileSelectionCanceled(void* params) {
1411 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params); 1402 SavePackageParam* save_params = reinterpret_cast<SavePackageParam*>(params);
1412 delete save_params; 1403 delete save_params;
1413 } 1404 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/shared_resources_data_source.cc ('k') | chrome/browser/io_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698