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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.h

Issue 11574006: Implement chrome.downloads.onDeterminingFilename() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r185012 Created 7 years, 9 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/hash_tables.h"
11 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/download/all_download_item_notifier.h" 15 #include "chrome/browser/download/all_download_item_notifier.h"
16 #include "chrome/browser/extensions/event_router.h"
15 #include "chrome/browser/extensions/extension_function.h" 17 #include "chrome/browser/extensions/extension_function.h"
16 #include "content/public/browser/download_id.h" 18 #include "content/public/browser/download_id.h"
17 #include "content/public/browser/download_item.h" 19 #include "content/public/browser/download_item.h"
18 #include "content/public/browser/download_manager.h" 20 #include "content/public/browser/download_manager.h"
19 21
20 class DownloadFileIconExtractor; 22 class DownloadFileIconExtractor;
21 class DownloadQuery; 23 class DownloadQuery;
22 24
23 namespace content { 25 namespace content {
24 class ResourceContext; 26 class ResourceContext;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DownloadsEraseFunction(); 121 DownloadsEraseFunction();
120 virtual bool RunImpl() OVERRIDE; 122 virtual bool RunImpl() OVERRIDE;
121 123
122 protected: 124 protected:
123 virtual ~DownloadsEraseFunction(); 125 virtual ~DownloadsEraseFunction();
124 126
125 private: 127 private:
126 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); 128 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction);
127 }; 129 };
128 130
129 class DownloadsSetDestinationFunction : public AsyncExtensionFunction {
130 public:
131 DECLARE_EXTENSION_FUNCTION("downloads.setDestination",
132 DOWNLOADS_SETDESTINATION)
133 DownloadsSetDestinationFunction();
134 virtual bool RunImpl() OVERRIDE;
135
136 protected:
137 virtual ~DownloadsSetDestinationFunction();
138
139 private:
140 DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction);
141 };
142
143 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { 131 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction {
144 public: 132 public:
145 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER) 133 DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER)
146 DownloadsAcceptDangerFunction(); 134 DownloadsAcceptDangerFunction();
147 virtual bool RunImpl() OVERRIDE; 135 virtual bool RunImpl() OVERRIDE;
148 136
149 protected: 137 protected:
150 virtual ~DownloadsAcceptDangerFunction(); 138 virtual ~DownloadsAcceptDangerFunction();
151 void DangerPromptCallback(bool accept, int download_id); 139 void DangerPromptCallback(bool accept, int download_id);
152 140
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 193
206 private: 194 private:
207 void OnIconURLExtracted(const std::string& url); 195 void OnIconURLExtracted(const std::string& url);
208 base::FilePath path_; 196 base::FilePath path_;
209 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; 197 scoped_ptr<DownloadFileIconExtractor> icon_extractor_;
210 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); 198 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction);
211 }; 199 };
212 200
213 // Observes a single DownloadManager and many DownloadItems and dispatches 201 // Observes a single DownloadManager and many DownloadItems and dispatches
214 // onCreated and onErased events. 202 // onCreated and onErased events.
215 class ExtensionDownloadsEventRouter 203 class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer,
216 : public AllDownloadItemNotifier::Observer { 204 public AllDownloadItemNotifier::Observer {
217 public: 205 public:
206 typedef base::Callback<void(const base::FilePath& changed_filename,
207 bool overwrite)> FilenameChangedCallback;
208
209 // A downloads.onDeterminingFilename listener has returned. If the extension
210 // wishes to override the download's filename, then |filename| will be
211 // non-empty. |filename| will be interpreted as a relative path, appended to
212 // the default downloads directory. If the extension wishes to overwrite any
213 // existing files, then |overwrite| will be true. Returns true on success,
214 // false otherwise.
215 static bool DetermineFilename(
216 Profile* profile,
217 bool include_incognito,
218 const std::string& ext_id,
219 int download_id,
220 const base::FilePath& filename,
221 bool overwrite);
222
218 explicit ExtensionDownloadsEventRouter( 223 explicit ExtensionDownloadsEventRouter(
219 Profile* profile, content::DownloadManager* manager); 224 Profile* profile, content::DownloadManager* manager);
220 virtual ~ExtensionDownloadsEventRouter(); 225 virtual ~ExtensionDownloadsEventRouter();
221 226
222 // AllDownloadItemNotifier::Observer interface 227 // Called by ChromeDownloadManagerDelegate during the filename determination
228 // process, allows extensions to change the item's target filename. If no
229 // extension wants to change the target filename, then |no_change| will be
230 // called and the filename determination process will continue as normal. If
231 // an extension wants to change the target filename, then |change| will be
232 // called with the new filename and a flag indicating whether the new file
233 // should overwrite any old files of the same name.
234 void OnDeterminingFilename(
235 content::DownloadItem* item,
236 const base::FilePath& suggested_path,
237 const base::Closure& no_change,
238 const FilenameChangedCallback& change);
239
240 // AllDownloadItemNotifier::Observer
223 virtual void OnDownloadCreated( 241 virtual void OnDownloadCreated(
224 content::DownloadManager* manager, 242 content::DownloadManager* manager,
225 content::DownloadItem* download_item) OVERRIDE; 243 content::DownloadItem* download_item) OVERRIDE;
226 virtual void OnDownloadUpdated( 244 virtual void OnDownloadUpdated(
227 content::DownloadManager* manager, 245 content::DownloadManager* manager,
228 content::DownloadItem* download_item) OVERRIDE; 246 content::DownloadItem* download_item) OVERRIDE;
229 virtual void OnDownloadRemoved( 247 virtual void OnDownloadRemoved(
230 content::DownloadManager* manager, 248 content::DownloadManager* manager,
231 content::DownloadItem* download_item) OVERRIDE; 249 content::DownloadItem* download_item) OVERRIDE;
232 250
251 // extensions::EventRouter::Observer
252 virtual void OnListenerRemoved(
253 const extensions::EventListenerInfo& details) OVERRIDE;
254
233 // Used for testing. 255 // Used for testing.
234 struct DownloadsNotificationSource { 256 struct DownloadsNotificationSource {
235 std::string event_name; 257 std::string event_name;
236 Profile* profile; 258 Profile* profile;
237 }; 259 };
238 260
239 private: 261 private:
240 void DispatchEvent(const char* event_name, base::Value* json_arg); 262 void DispatchEvent(
263 const char* event_name,
264 bool include_incognito,
265 base::Value* json_arg);
241 266
242 Profile* profile_; 267 Profile* profile_;
243 AllDownloadItemNotifier notifier_; 268 AllDownloadItemNotifier notifier_;
244 269
245 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); 270 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
246 }; 271 };
247 272
248 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ 273 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698