OLD | NEW |
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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/download/download_crx_util.h" | 19 #include "chrome/browser/download/download_crx_util.h" |
19 #include "chrome/browser/download/download_extensions.h" | 20 #include "chrome/browser/download/download_extensions.h" |
20 #include "chrome/browser/download/download_file_picker.h" | 21 #include "chrome/browser/download/download_file_picker.h" |
21 #include "chrome/browser/download/download_history.h" | 22 #include "chrome/browser/download/download_history.h" |
22 #include "chrome/browser/download/download_prefs.h" | 23 #include "chrome/browser/download/download_prefs.h" |
23 #include "chrome/browser/download/download_status_updater.h" | 24 #include "chrome/browser/download/download_status_updater.h" |
24 #include "chrome/browser/download/download_util.h" | 25 #include "chrome/browser/download/download_util.h" |
25 #include "chrome/browser/download/save_package_file_picker.h" | 26 #include "chrome/browser/download/save_package_file_picker.h" |
26 #include "chrome/browser/extensions/crx_installer.h" | 27 #include "chrome/browser/extensions/crx_installer.h" |
27 #include "chrome/browser/extensions/extension_service.h" | 28 #include "chrome/browser/extensions/extension_service.h" |
28 #include "chrome/browser/prefs/pref_member.h" | 29 #include "chrome/browser/prefs/pref_member.h" |
29 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
32 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/extensions/user_script.h" | 35 #include "chrome/common/extensions/user_script.h" |
35 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
36 #include "content/public/browser/download_item.h" | 37 #include "content/public/browser/download_item.h" |
37 #include "content/public/browser/download_manager.h" | 38 #include "content/public/browser/download_manager.h" |
38 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
39 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/browser/web_intents_dispatcher.h" |
40 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
41 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "webkit/glue/web_intent_data.h" |
42 | 45 |
43 #if !defined(OS_ANDROID) | 46 #if !defined(OS_ANDROID) |
44 #include "chrome/browser/ui/browser.h" | 47 #include "chrome/browser/ui/browser.h" |
45 #include "chrome/browser/ui/browser_list.h" | 48 #include "chrome/browser/ui/browser_list.h" |
46 #endif | 49 #endif |
47 | 50 |
48 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
49 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 52 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
50 #include "chrome/browser/download/download_file_picker_chromeos.h" | 53 #include "chrome/browser/download/download_file_picker_chromeos.h" |
51 #endif | 54 #endif |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 #if defined(OS_CHROMEOS) | 221 #if defined(OS_CHROMEOS) |
219 // If there's a GData upload associated with this download, we wait until that | 222 // If there's a GData upload associated with this download, we wait until that |
220 // is complete before allowing the download item to complete. | 223 // is complete before allowing the download item to complete. |
221 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item)) | 224 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item)) |
222 return false; | 225 return false; |
223 #endif | 226 #endif |
224 return true; | 227 return true; |
225 } | 228 } |
226 | 229 |
227 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 230 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
228 if (!IsExtensionDownload(item)) { | 231 if (IsExtensionDownload(item)) { |
| 232 scoped_refptr<CrxInstaller> crx_installer = |
| 233 download_crx_util::OpenChromeExtension(profile_, *item); |
| 234 |
| 235 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
| 236 // will call DelayedDownloadOpened() on this item. If this DownloadItem is |
| 237 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. |
| 238 registrar_.Add(this, |
| 239 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 240 content::Source<CrxInstaller>(crx_installer.get())); |
| 241 |
| 242 crx_installers_[crx_installer.get()] = item->GetId(); |
| 243 // The status text and percent complete indicator will change now |
| 244 // that we are installing a CRX. Update observers so that they pick |
| 245 // up the change. |
| 246 item->UpdateObservers(); |
| 247 return false; |
| 248 } |
| 249 |
| 250 if (ShouldOpenWithWebIntents(item)) { |
| 251 OpenWithWebIntent(item); |
| 252 item->DelayedDownloadOpened(); |
| 253 return false; |
| 254 } |
| 255 |
| 256 return true; |
| 257 } |
| 258 |
| 259 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents( |
| 260 const DownloadItem* item) { |
| 261 std::string mime_type = item->GetMimeType(); |
| 262 if (mime_type == "application/rss+xml" || |
| 263 mime_type == "application/atom+xml") { |
229 return true; | 264 return true; |
230 } | 265 } |
| 266 return false; |
| 267 } |
231 | 268 |
232 scoped_refptr<CrxInstaller> crx_installer = | 269 void ChromeDownloadManagerDelegate::OpenWithWebIntent( |
233 download_crx_util::OpenChromeExtension(profile_, *item); | 270 const DownloadItem* item) { |
| 271 webkit_glue::WebIntentData intent_data( |
| 272 ASCIIToUTF16("http://webintents.org/view"), |
| 273 ASCIIToUTF16(item->GetMimeType()), |
| 274 item->GetFullPath().AsUTF8Unsafe(), |
| 275 item->GetReceivedBytes()); |
234 | 276 |
235 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 277 // TODO(gbillock): Should we pass this? RCH specifies that the receiver gets |
236 // will call DelayedDownloadOpened() on this item. If this DownloadItem is | 278 // the url, but with web intents we don't need to pass it. |
237 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. | 279 intent_data.extra_data.insert(make_pair( |
238 registrar_.Add(this, | 280 ASCIIToUTF16("url"), ASCIIToUTF16(item->GetURL().spec()))); |
239 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | |
240 content::Source<CrxInstaller>(crx_installer.get())); | |
241 | 281 |
242 crx_installers_[crx_installer.get()] = item->GetId(); | 282 content::WebIntentsDispatcher* dispatcher = |
243 // The status text and percent complete indicator will change now | 283 content::WebIntentsDispatcher::Create(intent_data); |
244 // that we are installing a CRX. Update observers so that they pick | 284 item->GetWebContents()->GetDelegate()->WebIntentDispatch( |
245 // up the change. | 285 item->GetWebContents(), dispatcher); |
246 item->UpdateObservers(); | |
247 return false; | |
248 } | 286 } |
249 | 287 |
250 bool ChromeDownloadManagerDelegate::GenerateFileHash() { | 288 bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
251 #if defined(ENABLE_SAFE_BROWSING) | 289 #if defined(ENABLE_SAFE_BROWSING) |
252 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 290 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
253 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); | 291 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); |
254 #else | 292 #else |
255 return false; | 293 return false; |
256 #endif | 294 #endif |
257 } | 295 } |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 int32 download_id, int64 db_handle) { | 672 int32 download_id, int64 db_handle) { |
635 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 673 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
636 // call this function with an invalid |db_handle|. For instance, this can | 674 // call this function with an invalid |db_handle|. For instance, this can |
637 // happen when the history database is offline. We cannot have multiple | 675 // happen when the history database is offline. We cannot have multiple |
638 // DownloadItems with the same invalid db_handle, so we need to assign a | 676 // DownloadItems with the same invalid db_handle, so we need to assign a |
639 // unique |db_handle| here. | 677 // unique |db_handle| here. |
640 if (db_handle == DownloadItem::kUninitializedHandle) | 678 if (db_handle == DownloadItem::kUninitializedHandle) |
641 db_handle = download_history_->GetNextFakeDbHandle(); | 679 db_handle = download_history_->GetNextFakeDbHandle(); |
642 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 680 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
643 } | 681 } |
OLD | NEW |