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

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

Issue 12225076: Delete most web intents code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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
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_prefs.h" 25 #include "chrome/browser/download/download_prefs.h"
26 #include "chrome/browser/download/download_status_updater.h" 26 #include "chrome/browser/download/download_status_updater.h"
27 #include "chrome/browser/download/download_util.h" 27 #include "chrome/browser/download/download_util.h"
28 #include "chrome/browser/download/save_package_file_picker.h" 28 #include "chrome/browser/download/save_package_file_picker.h"
29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 29 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
30 #include "chrome/browser/extensions/crx_installer.h" 30 #include "chrome/browser/extensions/crx_installer.h"
31 #include "chrome/browser/extensions/extension_service.h" 31 #include "chrome/browser/extensions/extension_service.h"
32 #include "chrome/browser/extensions/extension_system.h" 32 #include "chrome/browser/extensions/extension_system.h"
33 #include "chrome/browser/history/history_service.h" 33 #include "chrome/browser/history/history_service.h"
34 #include "chrome/browser/history/history_service_factory.h" 34 #include "chrome/browser/history/history_service_factory.h"
35 #include "chrome/browser/intents/web_intents_util.h"
36 #include "chrome/browser/platform_util.h" 35 #include "chrome/browser/platform_util.h"
37 #include "chrome/browser/prefs/pref_registry_syncable.h" 36 #include "chrome/browser/prefs/pref_registry_syncable.h"
38 #include "chrome/browser/prefs/pref_service.h" 37 #include "chrome/browser/prefs/pref_service.h"
39 #include "chrome/browser/profiles/profile.h" 38 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 39 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
41 #include "chrome/browser/ui/browser.h" 40 #include "chrome/browser/ui/browser.h"
42 #include "chrome/browser/ui/host_desktop.h" 41 #include "chrome/browser/ui/host_desktop.h"
43 #include "chrome/browser/ui/tabs/tab_strip_model.h" 42 #include "chrome/browser/ui/tabs/tab_strip_model.h"
44 #include "chrome/common/chrome_notification_types.h" 43 #include "chrome/common/chrome_notification_types.h"
45 #include "chrome/common/extensions/feature_switch.h" 44 #include "chrome/common/extensions/feature_switch.h"
46 #include "chrome/common/extensions/user_script.h" 45 #include "chrome/common/extensions/user_script.h"
47 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
48 #include "content/public/browser/download_item.h" 47 #include "content/public/browser/download_item.h"
49 #include "content/public/browser/download_manager.h" 48 #include "content/public/browser/download_manager.h"
50 #include "content/public/browser/notification_source.h" 49 #include "content/public/browser/notification_source.h"
51 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
52 #include "content/public/browser/web_contents_delegate.h" 51 #include "content/public/browser/web_contents_delegate.h"
53 #include "content/public/browser/web_intents_dispatcher.h"
54 #include "grit/generated_resources.h" 52 #include "grit/generated_resources.h"
55 #include "net/base/net_util.h" 53 #include "net/base/net_util.h"
56 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
57 #include "webkit/glue/web_intent_data.h"
58 #include "webkit/glue/web_intent_reply_data.h"
59 55
60 #if !defined(OS_ANDROID) 56 #if !defined(OS_ANDROID)
61 #include "chrome/browser/ui/browser.h" 57 #include "chrome/browser/ui/browser.h"
62 #include "chrome/browser/ui/browser_finder.h" 58 #include "chrome/browser/ui/browser_finder.h"
63 #endif 59 #endif
64 60
65 #if defined(OS_CHROMEOS) 61 #if defined(OS_CHROMEOS)
66 #include "chrome/browser/chromeos/drive/drive_download_handler.h" 62 #include "chrome/browser/chromeos/drive/drive_download_handler.h"
67 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 63 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
68 #include "chrome/browser/download/download_file_picker_chromeos.h" 64 #include "chrome/browser/download/download_file_picker_chromeos.h"
69 #include "chrome/browser/download/save_package_file_picker_chromeos.h" 65 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
70 #endif 66 #endif
71 67
72 using content::BrowserContext; 68 using content::BrowserContext;
73 using content::BrowserThread; 69 using content::BrowserThread;
74 using content::DownloadId; 70 using content::DownloadId;
75 using content::DownloadItem; 71 using content::DownloadItem;
76 using content::DownloadManager; 72 using content::DownloadManager;
77 using content::WebContents; 73 using content::WebContents;
78 using safe_browsing::DownloadProtectionService; 74 using safe_browsing::DownloadProtectionService;
79 75
80 namespace { 76 namespace {
81 77
82 // String pointer used for identifying safebrowing data associated with 78 // String pointer used for identifying safebrowing data associated with
83 // a download item. 79 // a download item.
84 static const char safe_browsing_id[] = "Safe Browsing ID"; 80 static const char safe_browsing_id[] = "Safe Browsing ID";
85 81
86 // String pointer used to set the local file extension to be used when a
87 // download is going to be dispatched with web intents.
88 static const base::FilePath::CharType kWebIntentsFileExtension[] =
89 FILE_PATH_LITERAL(".webintents");
90
91 // The state of a safebrowsing check. 82 // The state of a safebrowsing check.
92 class SafeBrowsingState : public DownloadCompletionBlocker { 83 class SafeBrowsingState : public DownloadCompletionBlocker {
93 public: 84 public:
94 SafeBrowsingState() 85 SafeBrowsingState()
95 : verdict_(DownloadProtectionService::SAFE) { 86 : verdict_(DownloadProtectionService::SAFE) {
96 } 87 }
97 88
98 virtual ~SafeBrowsingState(); 89 virtual ~SafeBrowsingState();
99 90
100 // The verdict that we got from calling CheckClientDownload. Only valid to 91 // The verdict that we got from calling CheckClientDownload. Only valid to
(...skipping 25 matching lines...) Expand all
126 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); 117 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
127 118
128 *generated_name = net::GenerateFileName(download_item.GetURL(), 119 *generated_name = net::GenerateFileName(download_item.GetURL(),
129 download_item.GetContentDisposition(), 120 download_item.GetContentDisposition(),
130 referrer_charset, 121 referrer_charset,
131 download_item.GetSuggestedFilename(), 122 download_item.GetSuggestedFilename(),
132 download_item.GetMimeType(), 123 download_item.GetMimeType(),
133 default_file_name); 124 default_file_name);
134 } 125 }
135 126
136 // Needed to give PostTask a void closure in OnWebIntentDispatchCompleted.
137 void DeleteFile(const base::FilePath& file_path) {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
139 file_util::Delete(file_path, false);
140 }
141
142 // Called when the web intents dispatch has completed. Deletes the |file_path|.
143 void OnWebIntentDispatchCompleted(
144 const base::FilePath& file_path,
145 webkit_glue::WebIntentReplyType intent_reply) {
146 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
147 base::Bind(&DeleteFile, file_path));
148 }
149
150 typedef base::Callback<void(bool)> VisitedBeforeCallback; 127 typedef base::Callback<void(bool)> VisitedBeforeCallback;
151 128
152 // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a 129 // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a
153 // single bool so that VisitedBeforeCallback can curry up to 5 other parameters 130 // single bool so that VisitedBeforeCallback can curry up to 5 other parameters
154 // without a struct. 131 // without a struct.
155 void VisitCountsToVisitedBefore( 132 void VisitCountsToVisitedBefore(
156 const VisitedBeforeCallback& callback, 133 const VisitedBeforeCallback& callback,
157 HistoryService::Handle unused_handle, 134 HistoryService::Handle unused_handle,
158 bool found_visits, 135 bool found_visits,
159 int count, 136 int count,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 content::Source<extensions::CrxInstaller>(crx_installer.get())); 362 content::Source<extensions::CrxInstaller>(crx_installer.get()));
386 363
387 crx_installers_[crx_installer.get()] = callback; 364 crx_installers_[crx_installer.get()] = callback;
388 // The status text and percent complete indicator will change now 365 // The status text and percent complete indicator will change now
389 // that we are installing a CRX. Update observers so that they pick 366 // that we are installing a CRX. Update observers so that they pick
390 // up the change. 367 // up the change.
391 item->UpdateObservers(); 368 item->UpdateObservers();
392 return false; 369 return false;
393 } 370 }
394 371
395 #if defined(ENABLE_WEB_INTENTS)
396 if (ShouldOpenWithWebIntents(item)) {
397 OpenWithWebIntent(item);
398 callback.Run(true);
399 return false;
400 }
401 #endif
402
403 return true; 372 return true;
404 } 373 }
405 374
406 #if defined(ENABLE_WEB_INTENTS)
407 bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents(
408 const DownloadItem* item) {
409 if (!web_intents::IsWebIntentsEnabledForProfile(profile_))
410 return false;
411
412 if ((item->GetWebContents() && !item->GetWebContents()->GetDelegate()) &&
413 !web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_)) {
414 return false;
415 }
416 if (!item->GetForcedFilePath().empty())
417 return false;
418 if (item->GetTargetDisposition() == DownloadItem::TARGET_DISPOSITION_PROMPT)
419 return false;
420
421 #if !defined(OS_CHROMEOS)
422 std::string mime_type = item->GetMimeType();
423
424 // If QuickOffice extension is installed, and we're not on ChromeOS,use web
425 // intents to handle the downloaded file.
426 const char kQuickOfficeExtensionId[] = "gbkeegbaiigmenfmjfclcdgdpimamgkj";
427 const char kQuickOfficeDevExtensionId[] = "ionpfmkccalenbmnddpbmocokhaknphg";
428 ExtensionServiceInterface* extension_service =
429 extensions::ExtensionSystem::Get(profile_)->extension_service();
430
431 bool use_quickoffice = false;
432 if (extension_service &&
433 extension_service->GetInstalledExtension(kQuickOfficeExtensionId) &&
434 extension_service->IsExtensionEnabled(kQuickOfficeExtensionId))
435 use_quickoffice = true;
436
437 if (extension_service &&
438 extension_service->GetInstalledExtension(kQuickOfficeDevExtensionId) &&
439 extension_service->IsExtensionEnabled(kQuickOfficeDevExtensionId))
440 use_quickoffice = true;
441
442 if (use_quickoffice) {
443 if (mime_type == "application/msword" ||
444 mime_type == "application/vnd.ms-powerpoint" ||
445 mime_type == "application/vnd.ms-excel" ||
446 mime_type == "application/vnd.openxmlformats-officedocument."
447 "wordprocessingml.document" ||
448 mime_type == "application/vnd.openxmlformats-officedocument."
449 "presentationml.presentation" ||
450 mime_type == "application/vnd.openxmlformats-officedocument."
451 "spreadsheetml.sheet") {
452 return true;
453 }
454 }
455 #endif // !defined(OS_CHROMEOS)
456
457 return false;
458 }
459
460 void ChromeDownloadManagerDelegate::OpenWithWebIntent(
461 const DownloadItem* item) {
462 webkit_glue::WebIntentData intent_data(
463 ASCIIToUTF16("http://webintents.org/view"),
464 ASCIIToUTF16(item->GetMimeType()),
465 item->GetFullPath(),
466 item->GetReceivedBytes());
467
468 // RCH specifies that the receiver gets the url, but with Web Intents
469 // it isn't really needed.
470 intent_data.extra_data.insert(make_pair(
471 ASCIIToUTF16("url"), ASCIIToUTF16(item->GetURL().spec())));
472
473 // Pass the downloaded filename to the service app as the name hint.
474 intent_data.extra_data.insert(
475 make_pair(ASCIIToUTF16("filename"),
476 item->GetFileNameToReportUser().LossyDisplayName()));
477
478 content::WebIntentsDispatcher* dispatcher =
479 content::WebIntentsDispatcher::Create(intent_data);
480 dispatcher->RegisterReplyNotification(
481 base::Bind(&OnWebIntentDispatchCompleted, item->GetFullPath()));
482
483 content::WebContentsDelegate* delegate = NULL;
484 #if !defined(OS_ANDROID)
485 if (item->GetWebContents() && item->GetWebContents()->GetDelegate()) {
486 delegate = item->GetWebContents()->GetDelegate();
487 } else {
488 delegate = web_intents::GetBrowserForBackgroundWebIntentDelivery(profile_);
489 }
490 #endif // !defined(OS_ANDROID)
491 DCHECK(delegate);
492 delegate->WebIntentDispatch(NULL, dispatcher);
493 }
494 #endif
495
496 bool ChromeDownloadManagerDelegate::GenerateFileHash() { 375 bool ChromeDownloadManagerDelegate::GenerateFileHash() {
497 #if defined(FULL_SAFE_BROWSING) 376 #if defined(FULL_SAFE_BROWSING)
498 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && 377 return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
499 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded(); 378 g_browser_process->safe_browsing_service()->DownloadBinHashNeeded();
500 #else 379 #else
501 return false; 380 return false;
502 #endif 381 #endif
503 } 382 }
504 383
505 void ChromeDownloadManagerDelegate::GetSaveDir( 384 void ChromeDownloadManagerDelegate::GetSaveDir(
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (should_prompt && !last_download_path_.empty()) 660 if (should_prompt && !last_download_path_.empty())
782 target_directory = last_download_path_; 661 target_directory = last_download_path_;
783 else 662 else
784 target_directory = download_prefs_->DownloadPath(); 663 target_directory = download_prefs_->DownloadPath();
785 suggested_path = target_directory.Append(generated_name); 664 suggested_path = target_directory.Append(generated_name);
786 } else { 665 } else {
787 DCHECK(!should_prompt); 666 DCHECK(!should_prompt);
788 suggested_path = download->GetForcedFilePath(); 667 suggested_path = download->GetForcedFilePath();
789 } 668 }
790 669
791 #if defined(ENABLE_WEB_INTENTS)
792 // If we will open the file with a web intents dispatch,
793 // give it a name that will not allow the OS to open it using usual
794 // associated apps.
795 if (ShouldOpenWithWebIntents(download)) {
796 download->SetDisplayName(suggested_path.BaseName());
797 suggested_path = suggested_path.AddExtension(kWebIntentsFileExtension);
798 }
799 #endif
800
801 // If the download hasn't already been marked dangerous (could be 670 // If the download hasn't already been marked dangerous (could be
802 // DANGEROUS_URL), check if it is a dangerous file. 671 // DANGEROUS_URL), check if it is a dangerous file.
803 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { 672 if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) {
804 if (!should_prompt && !is_forced_path && 673 if (!should_prompt && !is_forced_path &&
805 IsDangerousFile(*download, suggested_path, visited_referrer_before)) { 674 IsDangerousFile(*download, suggested_path, visited_referrer_before)) {
806 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; 675 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE;
807 } 676 }
808 677
809 #if defined(FULL_SAFE_BROWSING) 678 #if defined(FULL_SAFE_BROWSING)
810 DownloadProtectionService* service = GetDownloadProtectionService(); 679 DownloadProtectionService* service = GetDownloadProtectionService();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a 800 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a
932 // directory to persist. Or perhaps, if the Drive path 801 // directory to persist. Or perhaps, if the Drive path
933 // substitution logic is moved here, then we would have a 802 // substitution logic is moved here, then we would have a
934 // persistable path after the DownloadFilePicker is done. 803 // persistable path after the DownloadFilePicker is done.
935 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && 804 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT &&
936 !download->IsTemporary()) 805 !download->IsTemporary())
937 last_download_path_ = target_path.DirName(); 806 last_download_path_ = target_path.DirName();
938 } 807 }
939 callback.Run(target_path, disposition, danger_type, intermediate_path); 808 callback.Run(target_path, disposition, danger_type, intermediate_path);
940 } 809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698