OLD | NEW |
---|---|
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_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | |
10 | |
9 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
10 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/url_pattern_set.h" | 13 #include "chrome/common/extensions/url_pattern_set.h" |
14 #include "content/public/browser/notification_observer.h" | |
15 #include "content/public/browser/notification_registrar.h" | |
12 | 16 |
13 class Browser; | 17 class Browser; |
14 class FileBrowserHandler; | 18 class FileBrowserHandler; |
15 class GURL; | 19 class GURL; |
16 class Profile; | 20 class Profile; |
17 | 21 |
18 namespace file_handler_util { | 22 namespace file_handler_util { |
19 | 23 |
20 // Gets read-write file access permission flags. | 24 // Gets read-write file access permission flags. |
21 int GetReadWritePermissions(); | 25 int GetReadWritePermissions(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 const std::vector<GURL>& files_list, | 57 const std::vector<GURL>& files_list, |
54 LastUsedHandlerList* named_action_list); | 58 LastUsedHandlerList* named_action_list); |
55 | 59 |
56 // Find the default task for a file whose url is |url|. (The default task is the | 60 // Find the default task for a file whose url is |url|. (The default task is the |
57 // task that is assigned to file browser task button by default). | 61 // task that is assigned to file browser task button by default). |
58 bool GetDefaultTask(Profile* profile, | 62 bool GetDefaultTask(Profile* profile, |
59 const GURL& url, | 63 const GURL& url, |
60 const FileBrowserHandler** handler); | 64 const FileBrowserHandler** handler); |
61 | 65 |
62 // Helper class for executing file browser file action. | 66 // Helper class for executing file browser file action. |
63 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { | 67 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor>, |
68 public content::NotificationObserver { | |
64 public: | 69 public: |
65 | 70 |
66 FileTaskExecutor(Profile* profile, | 71 FileTaskExecutor(Profile* profile, |
67 const GURL source_url, | 72 const GURL source_url, |
68 const std::string& extension_id, | 73 const std::string& extension_id, |
69 const std::string& action_id); | 74 const std::string& action_id); |
70 | 75 |
71 virtual ~FileTaskExecutor(); | 76 virtual ~FileTaskExecutor(); |
72 | 77 |
73 // Initiates execution of file handler task for each element of |file_urls|. | 78 // Initiates execution of file handler task for each element of |file_urls|. |
74 // Return |false| if the execution cannot be initiated. | 79 // Return |false| if the execution cannot be initiated. |
75 // Otherwise returns |true| and then eventually calls |Done|. | 80 // Otherwise returns |true| and then eventually calls |Done|. |
76 bool Execute(const std::vector<GURL>& file_urls); | 81 bool Execute(const std::vector<GURL>& file_urls); |
77 | 82 |
78 protected: | 83 protected: |
79 virtual Browser* browser() = 0; | 84 virtual Browser* browser() = 0; |
80 virtual void Done(bool success) = 0; | 85 virtual void Done(bool success) = 0; |
81 | 86 |
82 private: | 87 private: |
83 struct FileDefinition { | 88 struct FileDefinition { |
84 FileDefinition(); | 89 FileDefinition(); |
85 ~FileDefinition(); | 90 ~FileDefinition(); |
86 | 91 |
87 GURL target_file_url; | 92 GURL target_file_url; |
88 FilePath virtual_path; | 93 FilePath virtual_path; |
89 FilePath absolute_path; | 94 FilePath absolute_path; |
90 bool is_directory; | 95 bool is_directory; |
91 }; | 96 }; |
97 | |
92 typedef std::vector<FileDefinition> FileDefinitionList; | 98 typedef std::vector<FileDefinition> FileDefinitionList; |
93 class ExecuteTasksFileSystemCallbackDispatcher; | 99 class ExecuteTasksFileSystemCallbackDispatcher; |
94 void RequestFileEntryOnFileThread( | 100 void RequestFileEntryOnFileThread( |
95 const GURL& handler_base_url, | 101 const GURL& handler_base_url, |
96 const scoped_refptr<const Extension>& handler, | 102 const scoped_refptr<const Extension>& handler, |
97 int handler_pid, | 103 int handler_pid, |
98 const std::vector<GURL>& file_urls); | 104 const std::vector<GURL>& file_urls); |
99 void SetupFileAccessPermissionsForGDataCache( | 105 |
100 const FileDefinitionList& file_list, | 106 void ExecuteFailedOnUIThread(); |
101 int handler_pid); | |
102 void RespondFailedOnUIThread(base::PlatformFileError error_code); | |
103 void ExecuteFileActionsOnUIThread(const std::string& file_system_name, | 107 void ExecuteFileActionsOnUIThread(const std::string& file_system_name, |
104 const GURL& file_system_root, | 108 const GURL& file_system_root, |
105 const FileDefinitionList& file_list, | 109 const FileDefinitionList& file_list, |
106 int handler_id); | 110 int handler_id); |
107 void ExecuteFailedOnUIThread(); | 111 |
112 // Populates |handler_host_permissions| with file path-permissions pairs that | |
113 // will be given to the handler extension host process. | |
114 void InitHandlerHostFileAccessPermissions( | |
115 const FileDefinitionList& file_list, | |
116 const Extension* handler_extension, | |
117 const std::string& action_id); | |
Matt Perry
2012/04/13 18:45:17
add blank line here
| |
118 // Registers file permissions from |handler_host_permissions_| with | |
119 // ChildProcessSecurityPolicy for process with id |handler_pid|. | |
120 void SetupHandlerHostFileAccessPermissions(int handler_pid); | |
121 | |
122 // If the handler has lazy background page, we'll have to wait until the | |
123 // extension host is loaded until we can setup file access permissions. To do | |
124 // that, we'll have to listen for notifications. | |
125 // Registers notifications we listen to. | |
126 void RegisterNotificationObservers(); | |
127 | |
128 // content::NotificationObserver interface. | |
129 // Called when observed notification is detected. | |
130 virtual void Observe(int type, | |
131 const content::NotificationSource& source, | |
132 const content::NotificationDetails& details) OVERRIDE; | |
108 | 133 |
109 Profile* profile_; | 134 Profile* profile_; |
110 const GURL source_url_; | 135 const GURL source_url_; |
111 const std::string extension_id_; | 136 const std::string extension_id_; |
112 const std::string action_id_; | 137 const std::string action_id_; |
138 | |
139 // (File path, permission for file path) pairs for the handler. | |
140 std::vector<std::pair<FilePath, int> > handler_host_permissions_; | |
141 content::NotificationRegistrar registrar_; | |
113 }; | 142 }; |
114 | 143 |
115 } // namespace file_handler_util | 144 } // namespace file_handler_util |
116 | 145 |
117 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ | 146 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ |
OLD | NEW |