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

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

Issue 6459005: Cancel prerender when we discover a download starting from a page we are prer... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Moved notification to download_util to be more central Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Download utility implementation 5 // Download utility implementation
6 6
7 #include "chrome/browser/download/download_util.h" 7 #include "chrome/browser/download/download_util.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shobjidl.h> 10 #include <shobjidl.h>
(...skipping 18 matching lines...) Expand all
29 #include "chrome/browser/download/download_item.h" 29 #include "chrome/browser/download/download_item.h"
30 #include "chrome/browser/download/download_item_model.h" 30 #include "chrome/browser/download/download_item_model.h"
31 #include "chrome/browser/download/download_manager.h" 31 #include "chrome/browser/download/download_manager.h"
32 #include "chrome/browser/extensions/crx_installer.h" 32 #include "chrome/browser/extensions/crx_installer.h"
33 #include "chrome/browser/extensions/extension_install_ui.h" 33 #include "chrome/browser/extensions/extension_install_ui.h"
34 #include "chrome/browser/extensions/extension_service.h" 34 #include "chrome/browser/extensions/extension_service.h"
35 #include "chrome/browser/history/download_create_info.h" 35 #include "chrome/browser/history/download_create_info.h"
36 #include "chrome/browser/net/chrome_url_request_context.h" 36 #include "chrome/browser/net/chrome_url_request_context.h"
37 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 38 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
39 #include "chrome/browser/renderer_host/render_view_host.h"
39 #include "chrome/browser/tab_contents/tab_contents.h" 40 #include "chrome/browser/tab_contents/tab_contents.h"
40 #include "chrome/browser/ui/browser.h" 41 #include "chrome/browser/ui/browser.h"
41 #include "chrome/common/chrome_paths.h" 42 #include "chrome/common/chrome_paths.h"
42 #include "chrome/common/notification_service.h" 43 #include "chrome/common/notification_service.h"
43 #include "chrome/common/time_format.h" 44 #include "chrome/common/time_format.h"
44 #include "grit/generated_resources.h" 45 #include "grit/generated_resources.h"
45 #include "grit/locale_settings.h" 46 #include "grit/locale_settings.h"
46 #include "grit/theme_resources.h" 47 #include "grit/theme_resources.h"
47 #include "net/base/mime_util.h" 48 #include "net/base/mime_util.h"
48 #include "net/base/net_util.h" 49 #include "net/base/net_util.h"
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 Browser* browser = *browser_iterator; 681 Browser* browser = *browser_iterator;
681 BrowserWindow* window = browser->window(); 682 BrowserWindow* window = browser->window();
682 if (!window) 683 if (!window)
683 continue; 684 continue;
684 HWND frame = window->GetNativeHandle(); 685 HWND frame = window->GetNativeHandle();
685 if (download_count == 0 || progress == 1.0f) 686 if (download_count == 0 || progress == 1.0f)
686 taskbar->SetProgressState(frame, TBPF_NOPROGRESS); 687 taskbar->SetProgressState(frame, TBPF_NOPROGRESS);
687 else if (!progress_known) 688 else if (!progress_known)
688 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); 689 taskbar->SetProgressState(frame, TBPF_INDETERMINATE);
689 else 690 else
690 taskbar->SetProgressValue(frame, (int)(progress * 100), 100); 691 taskbar->SetProgressValue(frame, static_cast<int>(progress * 100), 100);
691 } 692 }
692 #endif 693 #endif
693 } 694 }
694 #endif 695 #endif
695 696
696 // Appends the passed the number between parenthesis the path before the 697 // Appends the passed the number between parenthesis the path before the
697 // extension. 698 // extension.
698 void AppendNumberToPath(FilePath* path, int number) { 699 void AppendNumberToPath(FilePath* path, int number) {
699 *path = path->InsertBeforeExtensionASCII(StringPrintf(" (%d)", number)); 700 *path = path->InsertBeforeExtensionASCII(StringPrintf(" (%d)", number));
700 } 701 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 request_context_getter->GetURLRequestContext(); 734 request_context_getter->GetURLRequestContext();
734 context->set_referrer_charset(referrer_charset); 735 context->set_referrer_charset(referrer_charset);
735 736
736 rdh->BeginDownload(url, 737 rdh->BeginDownload(url,
737 referrer, 738 referrer,
738 save_info, 739 save_info,
739 true, // Show "Save as" UI. 740 true, // Show "Save as" UI.
740 render_process_host_id, 741 render_process_host_id,
741 render_view_id, 742 render_view_id,
742 context); 743 context);
744
745 BrowserThread::PostTask(
746 BrowserThread::UI, FROM_HERE,
747 NewRunnableFunction(&NotifyDownloadInitiated,
748 render_process_host_id, render_view_id));
Randy Smith (Not in Mondays) 2011/02/14 19:20:51 See notes elsewhere; this either needs to be moved
dominich 2011/02/15 19:09:19 Done.
743 } 749 }
744 750
745 void CancelDownloadRequest(ResourceDispatcherHost* rdh, 751 void CancelDownloadRequest(ResourceDispatcherHost* rdh,
746 int render_process_id, 752 int render_process_id,
747 int request_id) { 753 int request_id) {
748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
749 rdh->CancelRequest(render_process_id, request_id, false); 755 rdh->CancelRequest(render_process_id, request_id, false);
750 } 756 }
751 757
758 void NotifyDownloadInitiated(int render_process_id, int render_view_id) {
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
760 RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
761 render_view_id);
762 if (!rvh)
763 return;
764
765 NotificationService::current()->Notify(NotificationType::DOWNLOAD_INITIATED,
766 Source<RenderViewHost>(rvh),
767 NotificationService::NoDetails());
Randy Smith (Not in Mondays) 2011/02/14 19:20:51 I'm happy with this location and structure.
dominich 2011/02/15 19:09:19 Done.
768 }
769
752 int GetUniquePathNumberWithCrDownload(const FilePath& path) { 770 int GetUniquePathNumberWithCrDownload(const FilePath& path) {
753 if (!file_util::PathExists(path) && 771 if (!file_util::PathExists(path) &&
754 !file_util::PathExists(GetCrDownloadPath(path))) 772 !file_util::PathExists(GetCrDownloadPath(path)))
755 return 0; 773 return 0;
756 774
757 FilePath new_path; 775 FilePath new_path;
758 for (int count = 1; count <= kMaxUniqueFiles; ++count) { 776 for (int count = 1; count <= kMaxUniqueFiles; ++count) {
759 new_path = FilePath(path); 777 new_path = FilePath(path);
760 AppendNumberToPath(&new_path, count); 778 AppendNumberToPath(&new_path, count);
761 779
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { 831 !service->IsDownloadFromGallery(info->url, info->referrer_url)) {
814 // Extensions that are not from the gallery are considered dangerous. 832 // Extensions that are not from the gallery are considered dangerous.
815 ret = true; 833 ret = true;
816 } 834 }
817 } 835 }
818 836
819 return ret; 837 return ret;
820 } 838 }
821 839
822 } // namespace download_util 840 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/prerender/prerender_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698