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

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

Issue 10399069: Reland 137540 - Disable off-store extension installs by default. Also get rid of ExtensionService::… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | « no previous file | chrome/browser/download/download_browsertest.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) 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 14 matching lines...) Expand all
25 #include "chrome/browser/download/download_util.h" 25 #include "chrome/browser/download/download_util.h"
26 #include "chrome/browser/download/save_package_file_picker.h" 26 #include "chrome/browser/download/save_package_file_picker.h"
27 #include "chrome/browser/extensions/crx_installer.h" 27 #include "chrome/browser/extensions/crx_installer.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/prefs/pref_member.h" 29 #include "chrome/browser/prefs/pref_member.h"
30 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
31 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 32 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
33 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
34 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
35 #include "chrome/common/extensions/extension_switch_utils.h"
35 #include "chrome/common/extensions/user_script.h" 36 #include "chrome/common/extensions/user_script.h"
36 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
37 #include "content/public/browser/download_item.h" 38 #include "content/public/browser/download_item.h"
38 #include "content/public/browser/download_manager.h" 39 #include "content/public/browser/download_manager.h"
39 #include "content/public/browser/notification_source.h" 40 #include "content/public/browser/notification_source.h"
40 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
41 #include "content/public/browser/web_contents_delegate.h" 42 #include "content/public/browser/web_contents_delegate.h"
42 #include "content/public/browser/web_intents_dispatcher.h" 43 #include "content/public/browser/web_intents_dispatcher.h"
43 #include "grit/generated_resources.h" 44 #include "grit/generated_resources.h"
44 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 86 }
86 87
87 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { 88 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
88 } 89 }
89 90
90 bool ChromeDownloadManagerDelegate::IsExtensionDownload( 91 bool ChromeDownloadManagerDelegate::IsExtensionDownload(
91 const DownloadItem* item) { 92 const DownloadItem* item) {
92 if (item->PromptUserForSaveLocation()) 93 if (item->PromptUserForSaveLocation())
93 return false; 94 return false;
94 95
95 if ((item->GetMimeType() != Extension::kMimeType) && 96 if (item->GetMimeType() == Extension::kMimeType ||
96 !UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType())) { 97 UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType())) {
98 return true;
99 } else {
97 return false; 100 return false;
98 } 101 }
99
100 return download_crx_util::ShouldOpenExtensionDownload(*item);
101 } 102 }
102 103
103 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { 104 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
104 download_manager_ = dm; 105 download_manager_ = dm;
105 download_history_.reset(new DownloadHistory(profile_)); 106 download_history_.reset(new DownloadHistory(profile_));
106 download_history_->Load( 107 download_history_->Load(
107 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete, 108 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete,
108 base::Unretained(dm))); 109 base::Unretained(dm)));
109 } 110 }
110 111
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // If there's a GData upload associated with this download, we wait until that 247 // If there's a GData upload associated with this download, we wait until that
247 // is complete before allowing the download item to complete. 248 // is complete before allowing the download item to complete.
248 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item)) 249 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item))
249 return false; 250 return false;
250 #endif 251 #endif
251 return true; 252 return true;
252 } 253 }
253 254
254 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { 255 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) {
255 if (IsExtensionDownload(item)) { 256 if (IsExtensionDownload(item)) {
256 scoped_refptr<CrxInstaller> crx_installer = 257 // We can open extensions if either they came from the store, or
257 download_crx_util::OpenChromeExtension(profile_, *item); 258 // off-store-install is enabled.
259 if (extensions::switch_utils::IsOffStoreInstallEnabled() ||
260 WebstoreInstaller::GetAssociatedApproval(*item)) {
261 scoped_refptr<CrxInstaller> crx_installer =
262 download_crx_util::OpenChromeExtension(profile_, *item);
258 263
259 // CRX_INSTALLER_DONE will fire when the install completes. Observe() 264 // CRX_INSTALLER_DONE will fire when the install completes. Observe()
260 // will call DelayedDownloadOpened() on this item. If this DownloadItem is 265 // will call DelayedDownloadOpened() on this item. If this DownloadItem
261 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. 266 // is not around when CRX_INSTALLER_DONE fires, Complete() will not be
262 registrar_.Add(this, 267 // called.
263 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 268 registrar_.Add(this,
264 content::Source<CrxInstaller>(crx_installer.get())); 269 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
270 content::Source<CrxInstaller>(crx_installer.get()));
265 271
266 crx_installers_[crx_installer.get()] = item->GetId(); 272 crx_installers_[crx_installer.get()] = item->GetId();
267 // The status text and percent complete indicator will change now 273 // The status text and percent complete indicator will change now
268 // that we are installing a CRX. Update observers so that they pick 274 // that we are installing a CRX. Update observers so that they pick
269 // up the change. 275 // up the change.
270 item->UpdateObservers(); 276 item->UpdateObservers();
271 return false; 277 return false;
278 }
272 } 279 }
273 280
274 if (ShouldOpenWithWebIntents(item)) { 281 if (ShouldOpenWithWebIntents(item)) {
275 OpenWithWebIntent(item); 282 OpenWithWebIntent(item);
276 item->DelayedDownloadOpened(); 283 item->DelayedDownloadOpened();
277 return false; 284 return false;
278 } 285 }
279 286
280 return true; 287 return true;
281 } 288 }
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 const DownloadItem& download, 693 const DownloadItem& download,
687 const DownloadStateInfo& state, 694 const DownloadStateInfo& state,
688 bool visited_referrer_before) { 695 bool visited_referrer_before) {
689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
690 697
691 // Anything loaded directly from the address bar is OK. 698 // Anything loaded directly from the address bar is OK.
692 if (state.transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR) 699 if (state.transition_type & content::PAGE_TRANSITION_FROM_ADDRESS_BAR)
693 return false; 700 return false;
694 701
695 // Extensions that are not from the gallery are considered dangerous. 702 // Extensions that are not from the gallery are considered dangerous.
696 if (IsExtensionDownload(&download)) { 703 // When off-store install is disabled we skip this, since in this case, we
697 ExtensionService* service = profile_->GetExtensionService(); 704 // will not offer to install the extension.
698 if (!service || !service->IsDownloadFromGallery(download.GetURL(), 705 if (extensions::switch_utils::IsOffStoreInstallEnabled() &&
699 download.GetReferrerUrl())) 706 IsExtensionDownload(&download) &&
700 return true; 707 !WebstoreInstaller::GetAssociatedApproval(download)) {
708 return true;
701 } 709 }
702 710
703 // Anything the user has marked auto-open is OK if it's user-initiated. 711 // Anything the user has marked auto-open is OK if it's user-initiated.
704 if (ShouldOpenFileBasedOnExtension(state.suggested_path) && 712 if (ShouldOpenFileBasedOnExtension(state.suggested_path) &&
705 state.has_user_gesture) 713 state.has_user_gesture)
706 return false; 714 return false;
707 715
708 // "Allow on user gesture" is OK when we have a user gesture and the hosting 716 // "Allow on user gesture" is OK when we have a user gesture and the hosting
709 // page has been visited before today. 717 // page has been visited before today.
710 download_util::DownloadDangerLevel danger_level = 718 download_util::DownloadDangerLevel danger_level =
711 download_util::GetFileDangerLevel(state.suggested_path.BaseName()); 719 download_util::GetFileDangerLevel(state.suggested_path.BaseName());
712 if (danger_level == download_util::AllowOnUserGesture) 720 if (danger_level == download_util::AllowOnUserGesture)
713 return !state.has_user_gesture || !visited_referrer_before; 721 return !state.has_user_gesture || !visited_referrer_before;
714 722
715 return danger_level == download_util::Dangerous; 723 return danger_level == download_util::Dangerous;
716 } 724 }
717 725
718 void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore( 726 void ChromeDownloadManagerDelegate::OnItemAddedToPersistentStore(
719 int32 download_id, int64 db_handle) { 727 int32 download_id, int64 db_handle) {
720 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 728 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
721 // call this function with an invalid |db_handle|. For instance, this can 729 // call this function with an invalid |db_handle|. For instance, this can
722 // happen when the history database is offline. We cannot have multiple 730 // happen when the history database is offline. We cannot have multiple
723 // DownloadItems with the same invalid db_handle, so we need to assign a 731 // DownloadItems with the same invalid db_handle, so we need to assign a
724 // unique |db_handle| here. 732 // unique |db_handle| here.
725 if (db_handle == DownloadItem::kUninitializedHandle) 733 if (db_handle == DownloadItem::kUninitializedHandle)
726 db_handle = download_history_->GetNextFakeDbHandle(); 734 db_handle = download_history_->GetNextFakeDbHandle();
727 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 735 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
728 } 736 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698