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

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

Issue 2479593006: Move enable extensions define to a build flag. (Closed)
Patch Set: Merge Created 4 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
OLDNEW
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 "chrome/browser/download/chrome_download_manager_delegate.h" 5 #include "chrome/browser/download/chrome_download_manager_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
46 #include "chrome/common/safe_browsing/file_type_policies.h" 46 #include "chrome/common/safe_browsing/file_type_policies.h"
47 #include "chrome/grit/generated_resources.h" 47 #include "chrome/grit/generated_resources.h"
48 #include "components/pref_registry/pref_registry_syncable.h" 48 #include "components/pref_registry/pref_registry_syncable.h"
49 #include "components/prefs/pref_member.h" 49 #include "components/prefs/pref_member.h"
50 #include "components/prefs/pref_service.h" 50 #include "components/prefs/pref_service.h"
51 #include "content/public/browser/download_item.h" 51 #include "content/public/browser/download_item.h"
52 #include "content/public/browser/download_manager.h" 52 #include "content/public/browser/download_manager.h"
53 #include "content/public/browser/notification_source.h" 53 #include "content/public/browser/notification_source.h"
54 #include "content/public/browser/page_navigator.h" 54 #include "content/public/browser/page_navigator.h"
55 #include "extensions/features/features.h"
55 #include "net/base/filename_util.h" 56 #include "net/base/filename_util.h"
56 #include "net/base/mime_util.h" 57 #include "net/base/mime_util.h"
57 #include "ui/base/l10n/l10n_util.h" 58 #include "ui/base/l10n/l10n_util.h"
58 59
59 #if BUILDFLAG(ANDROID_JAVA_UI) 60 #if BUILDFLAG(ANDROID_JAVA_UI)
60 #include "chrome/browser/android/download/chrome_duplicate_download_infobar_dele gate.h" 61 #include "chrome/browser/android/download/chrome_duplicate_download_infobar_dele gate.h"
61 #include "chrome/browser/infobars/infobar_service.h" 62 #include "chrome/browser/infobars/infobar_service.h"
62 #endif 63 #endif
63 64
64 #if defined(OS_CHROMEOS) 65 #if defined(OS_CHROMEOS)
65 #include "chrome/browser/chromeos/drive/download_handler.h" 66 #include "chrome/browser/chromeos/drive/download_handler.h"
66 #include "chrome/browser/chromeos/drive/file_system_util.h" 67 #include "chrome/browser/chromeos/drive/file_system_util.h"
67 #endif 68 #endif
68 69
69 #if defined(ENABLE_EXTENSIONS) 70 #if BUILDFLAG(ENABLE_EXTENSIONS)
70 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 71 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
71 #include "chrome/browser/extensions/crx_installer.h" 72 #include "chrome/browser/extensions/crx_installer.h"
72 #include "chrome/browser/extensions/webstore_installer.h" 73 #include "chrome/browser/extensions/webstore_installer.h"
73 #include "extensions/browser/notification_types.h" 74 #include "extensions/browser/notification_types.h"
74 #include "extensions/common/constants.h" 75 #include "extensions/common/constants.h"
75 #endif 76 #endif
76 77
77 using content::BrowserThread; 78 using content::BrowserThread;
78 using content::DownloadItem; 79 using content::DownloadItem;
79 using content::DownloadManager; 80 using content::DownloadManager;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 this, 282 this,
282 target_determined_callback); 283 target_determined_callback);
283 return true; 284 return true;
284 } 285 }
285 286
286 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( 287 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
287 const base::FilePath& path) { 288 const base::FilePath& path) {
288 DCHECK_CURRENTLY_ON(BrowserThread::UI); 289 DCHECK_CURRENTLY_ON(BrowserThread::UI);
289 if (path.Extension().empty()) 290 if (path.Extension().empty())
290 return false; 291 return false;
291 #if defined(ENABLE_EXTENSIONS) 292 #if BUILDFLAG(ENABLE_EXTENSIONS)
292 // TODO(asanka): This determination is done based on |path|, while 293 // TODO(asanka): This determination is done based on |path|, while
293 // ShouldOpenDownload() detects extension downloads based on the 294 // ShouldOpenDownload() detects extension downloads based on the
294 // characteristics of the download. Reconcile this. http://crbug.com/167702 295 // characteristics of the download. Reconcile this. http://crbug.com/167702
295 if (path.MatchesExtension(extensions::kExtensionFileExtension)) 296 if (path.MatchesExtension(extensions::kExtensionFileExtension))
296 return false; 297 return false;
297 #endif 298 #endif
298 return download_prefs_->IsAutoOpenEnabledBasedOnExtension(path); 299 return download_prefs_->IsAutoOpenEnabledBasedOnExtension(path);
299 } 300 }
300 301
301 // static 302 // static
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( 378 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(
378 DownloadItem* item, 379 DownloadItem* item,
379 const base::Closure& user_complete_callback) { 380 const base::Closure& user_complete_callback) {
380 return IsDownloadReadyForCompletion(item, base::Bind( 381 return IsDownloadReadyForCompletion(item, base::Bind(
381 &ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal, 382 &ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal,
382 weak_ptr_factory_.GetWeakPtr(), item->GetId(), user_complete_callback)); 383 weak_ptr_factory_.GetWeakPtr(), item->GetId(), user_complete_callback));
383 } 384 }
384 385
385 bool ChromeDownloadManagerDelegate::ShouldOpenDownload( 386 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(
386 DownloadItem* item, const content::DownloadOpenDelayedCallback& callback) { 387 DownloadItem* item, const content::DownloadOpenDelayedCallback& callback) {
387 #if defined(ENABLE_EXTENSIONS) 388 #if BUILDFLAG(ENABLE_EXTENSIONS)
388 if (download_crx_util::IsExtensionDownload(*item) && 389 if (download_crx_util::IsExtensionDownload(*item) &&
389 !extensions::WebstoreInstaller::GetAssociatedApproval(*item)) { 390 !extensions::WebstoreInstaller::GetAssociatedApproval(*item)) {
390 scoped_refptr<extensions::CrxInstaller> crx_installer = 391 scoped_refptr<extensions::CrxInstaller> crx_installer =
391 download_crx_util::OpenChromeExtension(profile_, *item); 392 download_crx_util::OpenChromeExtension(profile_, *item);
392 393
393 // CRX_INSTALLER_DONE will fire when the install completes. At that 394 // CRX_INSTALLER_DONE will fire when the install completes. At that
394 // time, Observe() will call the passed callback. 395 // time, Observe() will call the passed callback.
395 registrar_.Add( 396 registrar_.Add(
396 this, 397 this,
397 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 398 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 563 }
563 #endif 564 #endif
564 return NULL; 565 return NULL;
565 } 566 }
566 567
567 void ChromeDownloadManagerDelegate::NotifyExtensions( 568 void ChromeDownloadManagerDelegate::NotifyExtensions(
568 DownloadItem* download, 569 DownloadItem* download,
569 const base::FilePath& virtual_path, 570 const base::FilePath& virtual_path,
570 const NotifyExtensionsCallback& callback) { 571 const NotifyExtensionsCallback& callback) {
571 DCHECK_CURRENTLY_ON(BrowserThread::UI); 572 DCHECK_CURRENTLY_ON(BrowserThread::UI);
572 #if defined(ENABLE_EXTENSIONS) 573 #if BUILDFLAG(ENABLE_EXTENSIONS)
573 extensions::ExtensionDownloadsEventRouter* router = 574 extensions::ExtensionDownloadsEventRouter* router =
574 DownloadServiceFactory::GetForBrowserContext(profile_) 575 DownloadServiceFactory::GetForBrowserContext(profile_)
575 ->GetExtensionEventRouter(); 576 ->GetExtensionEventRouter();
576 if (router) { 577 if (router) {
577 base::Closure original_path_callback = 578 base::Closure original_path_callback =
578 base::Bind(callback, base::FilePath(), 579 base::Bind(callback, base::FilePath(),
579 DownloadPathReservationTracker::UNIQUIFY); 580 DownloadPathReservationTracker::UNIQUIFY);
580 router->OnDeterminingFilename(download, virtual_path.BaseName(), 581 router->OnDeterminingFilename(download, virtual_path.BaseName(),
581 original_path_callback, 582 original_path_callback,
582 callback); 583 callback);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 item->GetUserData(&kSafeBrowsingUserDataKey)); 745 item->GetUserData(&kSafeBrowsingUserDataKey));
745 state->CompleteDownload(); 746 state->CompleteDownload();
746 } 747 }
747 #endif // FULL_SAFE_BROWSING 748 #endif // FULL_SAFE_BROWSING
748 749
749 // content::NotificationObserver implementation. 750 // content::NotificationObserver implementation.
750 void ChromeDownloadManagerDelegate::Observe( 751 void ChromeDownloadManagerDelegate::Observe(
751 int type, 752 int type,
752 const content::NotificationSource& source, 753 const content::NotificationSource& source,
753 const content::NotificationDetails& details) { 754 const content::NotificationDetails& details) {
754 #if defined(ENABLE_EXTENSIONS) 755 #if BUILDFLAG(ENABLE_EXTENSIONS)
755 DCHECK_EQ(extensions::NOTIFICATION_CRX_INSTALLER_DONE, type); 756 DCHECK_EQ(extensions::NOTIFICATION_CRX_INSTALLER_DONE, type);
756 757
757 registrar_.Remove(this, extensions::NOTIFICATION_CRX_INSTALLER_DONE, source); 758 registrar_.Remove(this, extensions::NOTIFICATION_CRX_INSTALLER_DONE, source);
758 759
759 scoped_refptr<extensions::CrxInstaller> installer = 760 scoped_refptr<extensions::CrxInstaller> installer =
760 content::Source<extensions::CrxInstaller>(source).ptr(); 761 content::Source<extensions::CrxInstaller>(source).ptr();
761 content::DownloadOpenDelayedCallback callback = 762 content::DownloadOpenDelayedCallback callback =
762 crx_installers_[installer.get()]; 763 crx_installers_[installer.get()];
763 crx_installers_.erase(installer.get()); 764 crx_installers_.erase(installer.get());
764 callback.Run(installer->did_handle_successfully()); 765 callback.Run(installer->did_handle_successfully());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || 813 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) ||
813 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || 814 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) ||
814 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || 815 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) ||
815 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || 816 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) ||
816 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { 817 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) {
817 return true; 818 return true;
818 } 819 }
819 #endif 820 #endif
820 return false; 821 return false;
821 } 822 }
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.h ('k') | chrome/browser/download/download_history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698