Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "chrome/browser/extensions/extension_function.h" | 12 #include "chrome/browser/extensions/extension_function.h" |
| 13 #include "googleurl/src/url_util.h" | |
| 13 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 14 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 14 | 15 |
| 15 // Implements the Chrome Extension local File API. | 16 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method. |
| 17 class RequestLocalFileSystemFunctionBase : public AsyncExtensionFunction { | |
| 18 protected: | |
| 19 friend class LocalFileSystemCallbackDispatcher; | |
| 20 // AsyncExtensionFunction overrides. | |
| 21 virtual bool RunImpl() OVERRIDE; | |
| 22 void RespondSuccessOnUIThread(const std::string& name, | |
| 23 const FilePath& path, | |
| 24 const std::string& file_url); | |
| 25 void RespondFailedOnUIThread(base::PlatformFileError error_code); | |
| 26 void RequestOnFileThread(const GURL& source_url, const std::string& file_url); | |
| 27 }; | |
| 28 | |
| 29 // Implements the chrome.fileBrowserPrivate.requestLocalFileSystem method. | |
| 16 class RequestLocalFileSystemFunction | 30 class RequestLocalFileSystemFunction |
| 17 : public AsyncExtensionFunction { | 31 : public RequestLocalFileSystemFunctionBase { |
| 18 public: | 32 private: |
| 19 RequestLocalFileSystemFunction(); | 33 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem"); |
| 34 }; | |
| 20 | 35 |
| 36 // Implements the chrome.fileBrowserPrivate.getFileTasks method. | |
| 37 class GetFileTasksFileBrowserFunction : public AsyncExtensionFunction { | |
| 21 protected: | 38 protected: |
| 22 virtual ~RequestLocalFileSystemFunction(); | |
| 23 | |
| 24 // AsyncExtensionFunction overrides. | 39 // AsyncExtensionFunction overrides. |
| 25 virtual bool RunImpl() OVERRIDE; | 40 virtual bool RunImpl() OVERRIDE; |
| 26 | 41 |
| 27 private: | 42 private: |
| 28 friend class LocalFileSystemCallbackDispatcher; | |
| 29 void RespondSuccessOnUIThread(const std::string& name, | |
| 30 const FilePath& path); | |
| 31 void RespondFailedOnUIThread(base::PlatformFileError error_code); | |
| 32 | 43 |
| 33 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.requestLocalFileSystem"); | 44 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getFileTasks"); |
| 45 }; | |
| 46 | |
| 47 | |
| 48 // Implements the chrome.fileBrowserPrivate.executeTask method. | |
| 49 class ExecuteTasksFileBrowserFunction : public AsyncExtensionFunction { | |
| 50 protected: | |
| 51 // AsyncExtensionFunction overrides. | |
| 52 virtual bool RunImpl() OVERRIDE; | |
| 53 | |
| 54 private: | |
| 55 // Converts |origin_file_url| to a url that is safe to be used within the | |
| 56 // context of targeted extension. First, this method removes the id of the | |
| 57 // file browser extension and replaces it with that of the handler extension | |
| 58 // we're invoking. Then it generates a hash code that | |
| 59 // this routine attached to it. The hash ensures that generated filesystem: | |
|
ericu
2011/04/06 03:50:09
The sentence that starts with "Then it generates"
zel
2011/04/06 05:25:17
Done.
| |
| 60 // url can be safely used within the context of the handler extension and | |
|
ericu
2011/04/06 03:50:09
What the hash does is allow us to validate that th
zel
2011/04/06 05:25:17
Done.
| |
| 61 // nowhere else. chrome.fileSystem.resolveFileSystemUrl function will verify | |
| 62 // correctness of the hash. Urls generated this way are safe to use by the | |
| 63 // handler extension only during the lifetime of the current browser process. | |
| 64 std::string MakeSafeFileUrl(const std::string& origin_file_url, | |
| 65 const std::string& extension_id); | |
| 66 | |
| 67 // Executes context menu tasks for each element of |files_list|. | |
| 68 bool ExecuteContextMenuTasks(const std::string& extension_id, | |
| 69 const std::string& action_id, | |
| 70 ListValue* files_list); | |
| 71 DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.executeTask"); | |
| 34 }; | 72 }; |
| 35 | 73 |
| 36 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ | 74 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_BROWSER_PRIVATE_API_H_ |
| OLD | NEW |