Fixed service side implementation of glTexStorage2DEXT to only initialize the number of
[chromium-blink-merge.git] / content / shell / shell_download_manager_delegate.cc
blob4660f0bd6d099ba802d768b5d14515ca5b8397fd
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
3 // found in the LICENSE file.
5 #include "content/shell/shell_download_manager_delegate.h"
7 #if defined(OS_WIN)
8 #include <windows.h>
9 #include <commdlg.h>
10 #endif
12 #include "base/bind.h"
13 #include "base/file_util.h"
14 #include "base/logging.h"
15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h"
17 #include "content/browser/browser_context.h"
18 #include "content/browser/download/download_manager.h"
19 #include "content/browser/download/download_state_info.h"
20 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "net/base/net_util.h"
24 namespace content {
26 ShellDownloadManagerDelegate::ShellDownloadManagerDelegate()
27 : download_manager_(NULL) {
30 ShellDownloadManagerDelegate::~ShellDownloadManagerDelegate(){
34 void ShellDownloadManagerDelegate::SetDownloadManager(
35 DownloadManager* download_manager) {
36 download_manager_ = download_manager;
39 void ShellDownloadManagerDelegate::Shutdown() {
42 bool ShellDownloadManagerDelegate::ShouldStartDownload(int32 download_id) {
43 DownloadItem* download =
44 download_manager_->GetActiveDownloadItem(download_id);
45 DownloadStateInfo state = download->GetStateInfo();
47 if (!state.force_file_name.empty())
48 return true;
50 FilePath generated_name = net::GenerateFileName(
51 download->GetURL(),
52 download->GetContentDisposition(),
53 download->GetReferrerCharset(),
54 download->GetSuggestedFilename(),
55 download->GetMimeType(),
56 "download");
58 // Since we have no download UI, show the user a dialog always.
59 state.prompt_user_for_save_location = true;
61 BrowserThread::PostTask(
62 BrowserThread::FILE,
63 FROM_HERE,
64 base::Bind(
65 &ShellDownloadManagerDelegate::GenerateFilename,
66 this, download_id, state, generated_name));
67 return false;
70 void ShellDownloadManagerDelegate::GenerateFilename(
71 int32 download_id,
72 DownloadStateInfo state,
73 const FilePath& generated_name) {
74 if (state.suggested_path.empty()) {
75 state.suggested_path = download_manager_->BrowserContext()->GetPath().
76 Append(FILE_PATH_LITERAL("Downloads"));
77 if (!file_util::PathExists(state.suggested_path))
78 file_util::CreateDirectory(state.suggested_path);
81 state.suggested_path = state.suggested_path.Append(generated_name);
83 BrowserThread::PostTask(
84 BrowserThread::UI,
85 FROM_HERE,
86 base::Bind(
87 &ShellDownloadManagerDelegate::RestartDownload,
88 this, download_id, state));
91 void ShellDownloadManagerDelegate::RestartDownload(
92 int32 download_id,
93 DownloadStateInfo state) {
94 DownloadItem* download =
95 download_manager_->GetActiveDownloadItem(download_id);
96 if (!download)
97 return;
98 download->SetFileCheckResults(state);
99 download_manager_->RestartDownload(download_id);
102 void ShellDownloadManagerDelegate::ChooseDownloadPath(
103 TabContents* tab_contents,
104 const FilePath& suggested_path,
105 void* data) {
106 FilePath result;
107 #if defined(OS_WIN)
108 std::wstring file_part = FilePath(suggested_path).BaseName().value();
109 wchar_t file_name[MAX_PATH];
110 base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name));
111 OPENFILENAME save_as;
112 ZeroMemory(&save_as, sizeof(save_as));
113 save_as.lStructSize = sizeof(OPENFILENAME);
114 save_as.hwndOwner = tab_contents->GetNativeView();
115 save_as.lpstrFile = file_name;
116 save_as.nMaxFile = arraysize(file_name);
118 std::wstring directory;
119 if (!suggested_path.empty())
120 directory = suggested_path.DirName().value();
122 save_as.lpstrInitialDir = directory.c_str();
123 save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING |
124 OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST;
126 if (GetSaveFileName(&save_as))
127 result = FilePath(std::wstring(save_as.lpstrFile));
128 #else
129 NOTIMPLEMENTED();
130 #endif
132 if (result.empty()) {
133 download_manager_->FileSelectionCanceled(data);
134 } else {
135 download_manager_->FileSelected(result, data);
139 bool ShellDownloadManagerDelegate::OverrideIntermediatePath(
140 DownloadItem* item,
141 FilePath* intermediate_path) {
142 return false;
145 TabContents* ShellDownloadManagerDelegate::
146 GetAlternativeTabContentsToNotifyForDownload() {
147 return NULL;
150 bool ShellDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
151 const FilePath& path) {
152 return false;
155 bool ShellDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) {
156 return true;
159 bool ShellDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) {
160 return true;
163 bool ShellDownloadManagerDelegate::GenerateFileHash() {
164 return false;
167 void ShellDownloadManagerDelegate::OnResponseCompleted(DownloadItem* item) {
170 void ShellDownloadManagerDelegate::AddItemToPersistentStore(
171 DownloadItem* item) {
174 void ShellDownloadManagerDelegate::UpdateItemInPersistentStore(
175 DownloadItem* item) {
178 void ShellDownloadManagerDelegate::UpdatePathForItemInPersistentStore(
179 DownloadItem* item,
180 const FilePath& new_path) {
183 void ShellDownloadManagerDelegate::RemoveItemFromPersistentStore(
184 DownloadItem* item) {
187 void ShellDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween(
188 const base::Time remove_begin,
189 const base::Time remove_end) {
192 void ShellDownloadManagerDelegate::GetSaveDir(
193 TabContents* tab_contents,
194 FilePath* website_save_dir,
195 FilePath* download_save_dir) {
198 void ShellDownloadManagerDelegate::ChooseSavePath(
199 const base::WeakPtr<SavePackage>& save_package,
200 const FilePath& suggested_path,
201 bool can_save_as_complete) {
204 void ShellDownloadManagerDelegate::DownloadProgressUpdated() {
207 } // namespace content