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

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

Issue 1403001: Modifying the "dangerous download" algorithm. (Closed)
Patch Set: Moving extension methods out of download_util.h Created 10 years 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
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 // Download utility implementation 5 // Download utility implementation
6 6
7 #include "chrome/browser/download/download_util.h" 7 #include "chrome/browser/download/download_util.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shobjidl.h> 10 #include <shobjidl.h>
(...skipping 11 matching lines...) Expand all
22 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
23 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
24 #include "base/sys_string_conversions.h" 24 #include "base/sys_string_conversions.h"
25 #include "base/thread_restrictions.h" 25 #include "base/thread_restrictions.h"
26 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "base/win/windows_version.h" 28 #include "base/win/windows_version.h"
29 #include "chrome/browser/browser_list.h" 29 #include "chrome/browser/browser_list.h"
30 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/browser_thread.h" 31 #include "chrome/browser/browser_thread.h"
32 #include "chrome/browser/download/download_extensions.h"
32 #include "chrome/browser/download/download_item.h" 33 #include "chrome/browser/download/download_item.h"
33 #include "chrome/browser/download/download_item_model.h" 34 #include "chrome/browser/download/download_item_model.h"
34 #include "chrome/browser/download/download_manager.h" 35 #include "chrome/browser/download/download_manager.h"
35 #include "chrome/browser/extensions/crx_installer.h" 36 #include "chrome/browser/extensions/crx_installer.h"
36 #include "chrome/browser/extensions/extension_install_ui.h" 37 #include "chrome/browser/extensions/extension_install_ui.h"
37 #include "chrome/browser/extensions/extensions_service.h" 38 #include "chrome/browser/extensions/extensions_service.h"
38 #include "chrome/browser/history/download_create_info.h" 39 #include "chrome/browser/history/download_create_info.h"
39 #include "chrome/browser/net/chrome_url_request_context.h" 40 #include "chrome/browser/net/chrome_url_request_context.h"
40 #include "chrome/browser/profile.h" 41 #include "chrome/browser/profile.h"
41 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 42 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 FilePath::StringType file_name; 726 FilePath::StringType file_name;
726 base::SStringPrintf( 727 base::SStringPrintf(
727 &file_name, 728 &file_name,
728 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), 729 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
729 suggested_path.value().c_str()); 730 suggested_path.value().c_str());
730 return FilePath(file_name); 731 return FilePath(file_name);
731 } 732 }
732 733
733 // TODO(erikkay,phajdan.jr): This is apparently not being exercised in tests. 734 // TODO(erikkay,phajdan.jr): This is apparently not being exercised in tests.
734 bool IsDangerous(DownloadCreateInfo* info, Profile* profile) { 735 bool IsDangerous(DownloadCreateInfo* info, Profile* profile) {
735 // Downloads can be marked as dangerous for two reasons: 736 DownloadDangerLevel danger_level = GetFileDangerLevel(
736 // a) They have a dangerous-looking filename 737 info->suggested_path.BaseName());
737 // b) They are an extension that is not from the gallery 738
738 if (IsExecutableFile(info->suggested_path.BaseName())) { 739 if (danger_level == Dangerous) {
740 return true;
741 } else if (danger_level == AllowOnUserGesture && !info->has_user_gesture) {
739 return true; 742 return true;
740 } else if (info->is_extension_install) { 743 } else if (info->is_extension_install) {
741 ExtensionsService* service = profile->GetExtensionsService(); 744 ExtensionsService* service = profile->GetExtensionsService();
742 if (!service || 745 if (!service ||
743 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { 746 !service->IsDownloadFromGallery(info->url, info->referrer_url)) {
747 // Extensions that are not from the gallery are considered dangerous.
744 return true; 748 return true;
745 } 749 }
746 } 750 }
751
747 return false; 752 return false;
748 } 753 }
749 754
750 } // namespace download_util 755 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698