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

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

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