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

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

Issue 147017: Allow extension extensions to be case-insensitive. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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 | « base/file_path_unittest.cc ('k') | chrome/common/extensions/extension.h » ('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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/download_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/thread.h" 17 #include "base/thread.h"
18 #include "base/timer.h" 18 #include "base/timer.h"
19 #include "chrome/browser/browser_list.h" 19 #include "chrome/browser/browser_list.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/download/download_file.h" 21 #include "chrome/browser/download/download_file.h"
22 #include "chrome/browser/extensions/extensions_service.h" 22 #include "chrome/browser/extensions/extensions_service.h"
23 #include "chrome/browser/profile.h" 23 #include "chrome/browser/profile.h"
24 #include "chrome/browser/renderer_host/render_process_host.h" 24 #include "chrome/browser/renderer_host/render_process_host.h"
25 #include "chrome/browser/renderer_host/render_view_host.h" 25 #include "chrome/browser/renderer_host/render_view_host.h"
26 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 26 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
27 #include "chrome/browser/tab_contents/tab_util.h" 27 #include "chrome/browser/tab_contents/tab_util.h"
28 #include "chrome/browser/tab_contents/tab_contents.h" 28 #include "chrome/browser/tab_contents/tab_contents.h"
29 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/extensions/extension.h" 30 #include "chrome/common/extensions/extension.h"
32 #include "chrome/common/platform_util.h" 31 #include "chrome/common/platform_util.h"
33 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
34 #include "chrome/common/pref_service.h" 33 #include "chrome/common/pref_service.h"
35 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
36 #include "grit/chromium_strings.h" 35 #include "grit/chromium_strings.h"
37 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
38 #include "net/base/mime_util.h" 37 #include "net/base/mime_util.h"
39 #include "net/base/net_util.h" 38 #include "net/base/net_util.h"
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 this, &DownloadManager::ProceedWithFinishedDangerousDownload, 818 this, &DownloadManager::ProceedWithFinishedDangerousDownload,
820 download->db_handle(), 819 download->db_handle(),
821 download->full_path(), download->original_name())); 820 download->full_path(), download->original_name()));
822 return; 821 return;
823 } 822 }
824 ContinueDownloadFinished(download); 823 ContinueDownloadFinished(download);
825 } 824 }
826 825
827 void DownloadManager::DownloadRenamedToFinalName(int download_id, 826 void DownloadManager::DownloadRenamedToFinalName(int download_id,
828 const FilePath& full_path) { 827 const FilePath& full_path) {
829 FilePath::StringType extension = full_path.Extension(); 828 if (Extension::IsExtension(full_path))
830 // Drop the leading period.
831 if (extension.size() > 0)
832 extension = extension.substr(1);
833
834 if (extension == chrome::kExtensionFileExtension) {
835 OpenChromeExtension(full_path); 829 OpenChromeExtension(full_path);
836 }
837 } 830 }
838 831
839 void DownloadManager::ContinueDownloadFinished(DownloadItem* download) { 832 void DownloadManager::ContinueDownloadFinished(DownloadItem* download) {
840 // If this was a dangerous download, it has now been approved and must be 833 // If this was a dangerous download, it has now been approved and must be
841 // removed from dangerous_finished_ so it does not get deleted on shutdown. 834 // removed from dangerous_finished_ so it does not get deleted on shutdown.
842 DownloadMap::iterator it = dangerous_finished_.find(download->id()); 835 DownloadMap::iterator it = dangerous_finished_.find(download->id());
843 if (it != dangerous_finished_.end()) 836 if (it != dangerous_finished_.end())
844 dangerous_finished_.erase(it); 837 dangerous_finished_.erase(it);
845 838
846 // Notify our observers that we are complete (the call to Finished() set the 839 // Notify our observers that we are complete (the call to Finished() set the
847 // state to complete but did not notify). 840 // state to complete but did not notify).
848 download->UpdateObservers(); 841 download->UpdateObservers();
849 842
850 // Open the download if the user or user prefs indicate it should be. 843 // Open the download if the user or user prefs indicate it should be.
851 FilePath::StringType extension = download->full_path().Extension(); 844 FilePath::StringType extension = download->full_path().Extension();
852 // Drop the leading period.
853 if (extension.size() > 0)
854 extension = extension.substr(1);
855 845
856 // Handle chrome extensions explicitly and skip the shell execute. 846 // Handle chrome extensions explicitly and skip the shell execute.
857 if (extension == chrome::kExtensionFileExtension) { 847 if (Extension::IsExtension(download->full_path())) {
858 // Skip the shell execute. This will be handled in 848 // Skip the shell execute. This will be handled in
859 // DownloadRenamedToFinalName 849 // DownloadRenamedToFinalName
860 return; 850 return;
861 } 851 }
862 852
863 if (download->open_when_complete() || ShouldOpenFileExtension(extension)) 853 if (download->open_when_complete() || ShouldOpenFileExtension(extension))
864 OpenDownloadInShell(download, NULL); 854 OpenDownloadInShell(download, NULL);
865 } 855 }
866 856
867 // Called on the file thread. Renames the downloaded file to its original name. 857 // Called on the file thread. Renames the downloaded file to its original name.
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { 1201 void DownloadManager::ShowDownloadInShell(const DownloadItem* download) {
1212 DCHECK(file_manager_); 1202 DCHECK(file_manager_);
1213 file_loop_->PostTask(FROM_HERE, 1203 file_loop_->PostTask(FROM_HERE,
1214 NewRunnableMethod(file_manager_, 1204 NewRunnableMethod(file_manager_,
1215 &DownloadFileManager::OnShowDownloadInShell, 1205 &DownloadFileManager::OnShowDownloadInShell,
1216 FilePath(download->full_path()))); 1206 FilePath(download->full_path())));
1217 } 1207 }
1218 1208
1219 void DownloadManager::OpenDownload(const DownloadItem* download, 1209 void DownloadManager::OpenDownload(const DownloadItem* download,
1220 gfx::NativeView parent_window) { 1210 gfx::NativeView parent_window) {
1221 FilePath::StringType extension = download->full_path().Extension();
1222 // Drop the leading period.
1223 if (extension.size() > 0)
1224 extension = extension.substr(1);
1225
1226 // Open Chrome extensions with ExtensionsService. For everything else do shell 1211 // Open Chrome extensions with ExtensionsService. For everything else do shell
1227 // execute. 1212 // execute.
1228 if (extension == chrome::kExtensionFileExtension) { 1213 if (Extension::IsExtension(download->full_path())) {
1229 OpenChromeExtension(download->full_path()); 1214 OpenChromeExtension(download->full_path());
1230 } else { 1215 } else {
1231 OpenDownloadInShell(download, parent_window); 1216 OpenDownloadInShell(download, parent_window);
1232 } 1217 }
1233 } 1218 }
1234 1219
1235 void DownloadManager::OpenChromeExtension(const FilePath& full_path) { 1220 void DownloadManager::OpenChromeExtension(const FilePath& full_path) {
1236 profile_->GetOriginalProfile()->GetExtensionsService()-> 1221 profile_->GetOriginalProfile()->GetExtensionsService()->
1237 InstallExtension(full_path); 1222 InstallExtension(full_path);
1238 } 1223 }
(...skipping 14 matching lines...) Expand all
1253 else 1238 else
1254 auto_open_.erase(extension); 1239 auto_open_.erase(extension);
1255 SaveAutoOpens(); 1240 SaveAutoOpens();
1256 } 1241 }
1257 1242
1258 bool DownloadManager::ShouldOpenFileExtension( 1243 bool DownloadManager::ShouldOpenFileExtension(
1259 const FilePath::StringType& extension) { 1244 const FilePath::StringType& extension) {
1260 // Special-case Chrome extensions as always-open. 1245 // Special-case Chrome extensions as always-open.
1261 if (!IsExecutable(extension) && 1246 if (!IsExecutable(extension) &&
1262 (auto_open_.find(extension) != auto_open_.end() || 1247 (auto_open_.find(extension) != auto_open_.end() ||
1263 extension == chrome::kExtensionFileExtension)) 1248 Extension::IsExtension(FilePath(extension))))
1264 return true; 1249 return true;
1265 return false; 1250 return false;
1266 } 1251 }
1267 1252
1268 static const char* kExecutableWhiteList[] = { 1253 static const char* kExecutableWhiteList[] = {
1269 // JavaScript is just as powerful as EXE. 1254 // JavaScript is just as powerful as EXE.
1270 "text/javascript", 1255 "text/javascript",
1271 "text/javascript;version=*", 1256 "text/javascript;version=*",
1272 // Registry files can cause critical changes to the MS OS behavior. 1257 // Registry files can cause critical changes to the MS OS behavior.
1273 // Addition of this mimetype also addresses bug 7337. 1258 // Addition of this mimetype also addresses bug 7337.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 } 1462 }
1478 1463
1479 requestor->SetDownloads(searched_downloads); 1464 requestor->SetDownloads(searched_downloads);
1480 } 1465 }
1481 1466
1482 void DownloadManager::ShowDownloadInBrowser(const DownloadCreateInfo& info, 1467 void DownloadManager::ShowDownloadInBrowser(const DownloadCreateInfo& info,
1483 DownloadItem* download) { 1468 DownloadItem* download) {
1484 // Extension downloading skips the shelf. This is a temporary fix until 1469 // Extension downloading skips the shelf. This is a temporary fix until
1485 // we can modularize the download system and develop specific extensiona 1470 // we can modularize the download system and develop specific extensiona
1486 // install UI. 1471 // install UI.
1487 FilePath::StringType extension = info.path.Extension(); 1472 if (Extension::IsExtension(info.path))
1488 // Ignore the leading period.
1489 if (extension.find(chrome::kExtensionFileExtension) == 1)
1490 return; 1473 return;
1491 1474
1492 // The 'contents' may no longer exist if the user closed the tab before we get 1475 // The 'contents' may no longer exist if the user closed the tab before we get
1493 // this start completion event. If it does, tell the origin TabContents to 1476 // this start completion event. If it does, tell the origin TabContents to
1494 // display its download shelf. 1477 // display its download shelf.
1495 TabContents* contents = 1478 TabContents* contents =
1496 tab_util::GetTabContentsByID(info.render_process_id, info.render_view_id); 1479 tab_util::GetTabContentsByID(info.render_process_id, info.render_view_id);
1497 1480
1498 // If the contents no longer exists, we start the download in the last active 1481 // If the contents no longer exists, we start the download in the last active
1499 // browser. This is not ideal but better than fully hiding the download from 1482 // browser. This is not ideal but better than fully hiding the download from
1500 // the user. 1483 // the user.
1501 if (!contents) { 1484 if (!contents) {
1502 Browser* last_active = BrowserList::GetLastActive(); 1485 Browser* last_active = BrowserList::GetLastActive();
1503 if (last_active) 1486 if (last_active)
1504 contents = last_active->GetSelectedTabContents(); 1487 contents = last_active->GetSelectedTabContents();
1505 } 1488 }
1506 1489
1507 if (contents) 1490 if (contents)
1508 contents->OnStartDownload(download); 1491 contents->OnStartDownload(download);
1509 } 1492 }
1510 1493
1511 // Clears the last download path, used to initialize "save as" dialogs. 1494 // Clears the last download path, used to initialize "save as" dialogs.
1512 void DownloadManager::ClearLastDownloadPath() { 1495 void DownloadManager::ClearLastDownloadPath() {
1513 last_download_path_ = FilePath(); 1496 last_download_path_ = FilePath();
1514 } 1497 }
OLDNEW
« no previous file with comments | « base/file_path_unittest.cc ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698