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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: TaskType enum Created 8 years, 3 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
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 #include "chrome/browser/chromeos/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/gdata/gdata_util.h" 14 #include "chrome/browser/chromeos/gdata/gdata_util.h"
15 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 15 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
16 #include "chrome/browser/chromeos/gdata/drive_task_executor.h" 16 #include "chrome/browser/chromeos/gdata/drive_task_executor.h"
17 #include "chrome/browser/extensions/event_router.h" 17 #include "chrome/browser/extensions/event_router.h"
18 #include "chrome/browser/extensions/extension_host.h" 18 #include "chrome/browser/extensions/extension_host.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.h"
21 #include "chrome/browser/extensions/extension_tab_util.h" 21 #include "chrome/browser/extensions/extension_tab_util.h"
22 #include "chrome/browser/extensions/lazy_background_task_queue.h" 22 #include "chrome/browser/extensions/lazy_background_task_queue.h"
23 #include "chrome/browser/extensions/platform_app_launcher.h"
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" 24 #include "chrome/browser/prefs/scoped_user_pref_update.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_tabstrip.h" 29 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/common/extensions/file_browser_handler.h" 30 #include "chrome/common/extensions/file_browser_handler.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/child_process_security_policy.h" 33 #include "content/public/browser/child_process_security_policy.h"
33 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/site_instance.h" 35 #include "content/public/browser/site_instance.h"
35 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
36 #include "net/base/escape.h" 37 #include "net/base/escape.h"
37 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" 38 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
38 #include "webkit/fileapi/file_system_context.h" 39 #include "webkit/fileapi/file_system_context.h"
39 #include "webkit/fileapi/file_system_url.h" 40 #include "webkit/fileapi/file_system_url.h"
40 #include "webkit/fileapi/file_system_util.h" 41 #include "webkit/fileapi/file_system_util.h"
42 #include "webkit/fileapi/isolated_context.h"
41 43
42 using content::BrowserContext; 44 using content::BrowserContext;
43 using content::BrowserThread; 45 using content::BrowserThread;
44 using content::ChildProcessSecurityPolicy; 46 using content::ChildProcessSecurityPolicy;
45 using content::SiteInstance; 47 using content::SiteInstance;
46 using content::WebContents; 48 using content::WebContents;
47 using extensions::Extension; 49 using extensions::Extension;
48 50
49 namespace file_handler_util { 51 namespace file_handler_util {
50 52
51 // The prefix used to differentiate drive extensions from Chrome extensions.
52 const char FileTaskExecutor::kDriveTaskExtensionPrefix[] = "drive-app:";
53 const size_t FileTaskExecutor::kDriveTaskExtensionPrefixLength =
54 arraysize(FileTaskExecutor::kDriveTaskExtensionPrefix) - 1;
55
56 namespace { 53 namespace {
57 54
58 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN | 55 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN |
59 base::PLATFORM_FILE_CREATE | 56 base::PLATFORM_FILE_CREATE |
60 base::PLATFORM_FILE_OPEN_ALWAYS | 57 base::PLATFORM_FILE_OPEN_ALWAYS |
61 base::PLATFORM_FILE_CREATE_ALWAYS | 58 base::PLATFORM_FILE_CREATE_ALWAYS |
62 base::PLATFORM_FILE_OPEN_TRUNCATED | 59 base::PLATFORM_FILE_OPEN_TRUNCATED |
63 base::PLATFORM_FILE_READ | 60 base::PLATFORM_FILE_READ |
64 base::PLATFORM_FILE_WRITE | 61 base::PLATFORM_FILE_WRITE |
65 base::PLATFORM_FILE_EXCLUSIVE_READ | 62 base::PLATFORM_FILE_EXCLUSIVE_READ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 extension->file_browser_handlers()->begin(); 110 extension->file_browser_handlers()->begin();
114 action_iter != extension->file_browser_handlers()->end(); 111 action_iter != extension->file_browser_handlers()->end();
115 ++action_iter) { 112 ++action_iter) {
116 if (action_iter->get()->id() == action_id) 113 if (action_iter->get()->id() == action_id)
117 return action_iter->get(); 114 return action_iter->get();
118 } 115 }
119 return NULL; 116 return NULL;
120 } 117 }
121 118
122 unsigned int GetAccessPermissionsForHandler(const Extension* extension, 119 unsigned int GetAccessPermissionsForHandler(const Extension* extension,
123 const std::string& action_id) { 120 const std::string& action_id,
121 TaskType task_type) {
122 if (task_type == TASK_WEBINTENT)
123 return kReadOnlyFilePermissions;
124
124 const FileBrowserHandler* action = 125 const FileBrowserHandler* action =
125 FindFileBrowserHandler(extension, action_id); 126 FindFileBrowserHandler(extension, action_id);
126 if (!action) 127 if (!action)
127 return 0; 128 return 0;
128 unsigned int result = 0; 129 unsigned int result = 0;
129 if (action->CanRead()) 130 if (action->CanRead())
130 result |= kReadOnlyFilePermissions; 131 result |= kReadOnlyFilePermissions;
131 if (action->CanWrite()) 132 if (action->CanWrite())
132 result |= kReadWriteFilePermissions; 133 result |= kReadWriteFilePermissions;
133 // TODO(tbarzic): We don't handle Create yet. 134 // TODO(tbarzic): We don't handle Create yet.
134 return result; 135 return result;
135 } 136 }
136 137
137
138 std::string EscapedUtf8ToLower(const std::string& str) { 138 std::string EscapedUtf8ToLower(const std::string& str) {
139 string16 utf16 = UTF8ToUTF16( 139 string16 utf16 = UTF8ToUTF16(
140 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); 140 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL));
141 return net::EscapeUrlEncodedData( 141 return net::EscapeUrlEncodedData(
142 UTF16ToUTF8(base::i18n::ToLower(utf16)), 142 UTF16ToUTF8(base::i18n::ToLower(utf16)),
143 false /* do not replace space with plus */); 143 false /* do not replace space with plus */);
144 } 144 }
145 145
146 bool GetFileBrowserHandlers(Profile* profile, 146 bool GetFileBrowserHandlers(Profile* profile,
147 const GURL& selected_file_url, 147 const GURL& selected_file_url,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const LastUsedHandler& b) { 182 const LastUsedHandler& b) {
183 return a.timestamp > b.timestamp; 183 return a.timestamp > b.timestamp;
184 } 184 }
185 185
186 // TODO(zelidrag): Wire this with ICU to make this sort I18N happy. 186 // TODO(zelidrag): Wire this with ICU to make this sort I18N happy.
187 bool SortByTaskName(const LastUsedHandler& a, const LastUsedHandler& b) { 187 bool SortByTaskName(const LastUsedHandler& a, const LastUsedHandler& b) {
188 return base::strcasecmp(a.handler->title().c_str(), 188 return base::strcasecmp(a.handler->title().c_str(),
189 b.handler->title().c_str()) > 0; 189 b.handler->title().c_str()) > 0;
190 } 190 }
191 191
192 // Does this LastUsedHandlerList contain entries with only a common timestamp?
193 bool HasCommonTimestamp(LastUsedHandlerList* list) {
benwells 2012/08/30 08:09:03 Now I understand. Can you rename this to AllHaveSa
thorogood 2012/08/31 01:27:32 Done.
194 DCHECK(!list->empty());
195 int common_timestamp = list->begin()->timestamp;
196 for (LastUsedHandlerList::const_iterator iter = list->begin() + 1;
197 iter != list->end(); ++iter) {
198 if (common_timestamp != iter->timestamp)
199 return false;
200 }
201 return true;
202 }
203
192 void SortLastUsedHandlerList(LastUsedHandlerList *list) { 204 void SortLastUsedHandlerList(LastUsedHandlerList *list) {
193 // Sort by the last used descending. 205 // If we've got one element or fewer, the list is already sorted. If the
194 std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc); 206 // handlers have a common timestamp (e.g., if no handlers have ever been
195 if (list->size() > 1) { 207 // invoked), just sort by name. Otherwise, bring the last used handler to
196 // Sort the rest by name. 208 // the front and sort the rest by name.
209 if (list->size() <= 1) {
210 // do nothing
211 } else if (HasCommonTimestamp(list)) {
212 std::sort(list->begin(), list->end(), SortByTaskName);
213 } else {
214 std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc);
197 std::sort(list->begin() + 1, list->end(), SortByTaskName); 215 std::sort(list->begin() + 1, list->end(), SortByTaskName);
198 } 216 }
199 } 217 }
200 218
201 } // namespace 219 } // namespace
202 220
203 // Update file handler usage stats. 221 // Update file handler usage stats.
204 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id) { 222 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id) {
205 if (!profile || !profile->GetPrefs()) 223 if (!profile || !profile->GetPrefs())
206 return; 224 return;
207 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(), 225 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(),
208 prefs::kLastUsedFileBrowserHandlers); 226 prefs::kLastUsedFileBrowserHandlers);
209 prefs_usage_update->SetWithoutPathExpansion(task_id, 227 prefs_usage_update->SetWithoutPathExpansion(task_id,
210 new base::FundamentalValue( 228 new base::FundamentalValue(
211 static_cast<int>(base::Time::Now().ToInternalValue()/ 229 static_cast<int>(base::Time::Now().ToInternalValue()/
212 base::Time::kMicrosecondsPerSecond))); 230 base::Time::kMicrosecondsPerSecond)));
213 } 231 }
214 232
215 int GetReadWritePermissions() { 233 int GetReadWritePermissions() {
216 return kReadWriteFilePermissions; 234 return kReadWriteFilePermissions;
217 } 235 }
218 236
219 int GetReadOnlyPermissions() { 237 int GetReadOnlyPermissions() {
220 return kReadOnlyFilePermissions; 238 return kReadOnlyFilePermissions;
221 } 239 }
222 240
223 std::string MakeTaskID(const std::string& extension_id, 241 std::string MakeTaskID(const std::string& extension_id,
242 TaskType task_type,
224 const std::string& action_id) { 243 const std::string& action_id) {
225 return base::StringPrintf("%s|%s", extension_id.c_str(), action_id.c_str()); 244 DCHECK(task_type == TASK_FILE
245 || task_type == TASK_DRIVE
246 || task_type == TASK_WEBINTENT);
247
248 std::string out = base::StringPrintf("%s|%d|%s",
249 extension_id.c_str(),
250 task_type,
251 action_id.c_str());
252
253 LOG(INFO) << "Made task_id=" << out
benwells 2012/08/30 08:09:03 Make this VLOG(1) (then it will only show up with
thorogood 2012/08/31 01:27:32 Removed actually. Was just for testing.
254 << ", ext=" << extension_id
255 << ", type=" << task_type
256 << ", action=" << action_id;
257
258 return out;
226 } 259 }
227 260
228 std::string MakeDriveTaskID(const std::string& app_id,
229 const std::string& action_id) {
230 return MakeTaskID(FileTaskExecutor::kDriveTaskExtensionPrefix + app_id,
231 action_id);
232 }
233
234
235 // Breaks down task_id that is used between getFileTasks() and executeTask() on 261 // Breaks down task_id that is used between getFileTasks() and executeTask() on
236 // its building blocks. task_id field the following structure: 262 // its building blocks. task_id field the following structure:
237 // <extension-id>|<task-action-id> 263 // <extension-id>|<task-type>|<task-action-id>
238 // Currently, the only supported task-type is of 'context'. 264 // Currently, the only supported task-type is of 'context'.
239 bool CrackTaskID(const std::string& task_id, 265 bool CrackTaskID(const std::string& task_id,
240 std::string* extension_id, 266 std::string* extension_id,
267 TaskType* task_type,
241 std::string* action_id) { 268 std::string* action_id) {
242 std::vector<std::string> result; 269 std::vector<std::string> result;
243 int count = Tokenize(task_id, std::string("|"), &result); 270 int count = Tokenize(task_id, std::string("|"), &result);
244 if (count != 2) 271 if (count != 3)
245 return false; 272 return false;
246 *extension_id = result[0]; 273 *extension_id = result[0];
247 *action_id = result[1]; 274
275 *task_type = file_handler_util::TaskType(atoi(result[1].c_str()));
276 DCHECK(*task_type == TASK_FILE
277 || *task_type == TASK_DRIVE
278 || *task_type == TASK_WEBINTENT);
279
280 *action_id = result[2];
281
282 LOG(INFO) << "Cracked task_id=" << task_id
283 << ", ext=" << *extension_id
284 << ", type=" << *task_type
285 << ", action=" << *action_id;
286
248 return true; 287 return true;
249 } 288 }
250 289
251 // Find a specific handler in the handler list. 290 // Find a specific handler in the handler list.
252 LastUsedHandlerList::iterator FindHandler( 291 LastUsedHandlerList::iterator FindHandler(
253 LastUsedHandlerList* list, 292 LastUsedHandlerList* list,
254 const std::string& extension_id, 293 const std::string& extension_id,
255 const std::string& id) { 294 const std::string& id) {
256 LastUsedHandlerList::iterator iter = list->begin(); 295 LastUsedHandlerList::iterator iter = list->begin();
257 while (iter != list->end() && 296 while (iter != list->end() &&
258 !(iter->handler->extension_id() == extension_id && 297 !(iter->handler->extension_id() == extension_id &&
259 iter->handler->id() == id)) { 298 iter->handler->id() == id)) {
260 iter++; 299 iter++;
261 } 300 }
262 return iter; 301 return iter;
263 } 302 }
264 303
265 // Given the list of selected files, returns array of context menu tasks 304 // Given the list of selected files, returns array of file action tasks
266 // that are shared 305 // that are shared between them.
267 bool FindCommonTasks(Profile* profile, 306 bool FindCommonTasks(Profile* profile,
268 const std::vector<GURL>& files_list, 307 const std::vector<GURL>& files_list,
269 LastUsedHandlerList* named_action_list) { 308 LastUsedHandlerList* named_action_list) {
270 named_action_list->clear(); 309 named_action_list->clear();
271 ActionSet common_tasks; 310 ActionSet common_tasks;
272 for (std::vector<GURL>::const_iterator it = files_list.begin(); 311 for (std::vector<GURL>::const_iterator it = files_list.begin();
273 it != files_list.end(); ++it) { 312 it != files_list.end(); ++it) {
274 ActionSet file_actions; 313 ActionSet file_actions;
275 if (!GetFileBrowserHandlers(profile, *it, &file_actions)) 314 if (!GetFileBrowserHandlers(profile, *it, &file_actions))
276 return false; 315 return false;
(...skipping 24 matching lines...) Expand all
301 for (ActionSet::const_iterator iter = common_tasks.begin(); 340 for (ActionSet::const_iterator iter = common_tasks.begin();
302 iter != common_tasks.end(); ++iter) { 341 iter != common_tasks.end(); ++iter) {
303 // Get timestamp of when this task was used last time. 342 // Get timestamp of when this task was used last time.
304 int last_used_timestamp = 0; 343 int last_used_timestamp = 0;
305 344
306 if ((*iter)->extension_id() == kFileBrowserDomain) { 345 if ((*iter)->extension_id() == kFileBrowserDomain) {
307 // Give a little bump to the action from File Browser extension 346 // Give a little bump to the action from File Browser extension
308 // to make sure it is the default on a fresh profile. 347 // to make sure it is the default on a fresh profile.
309 last_used_timestamp = 1; 348 last_used_timestamp = 1;
310 } 349 }
311 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()), 350 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(),
351 TASK_FILE,
352 (*iter)->id()),
312 &last_used_timestamp); 353 &last_used_timestamp);
313 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list); 354 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list);
314 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter, 355 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter,
315 matching_patterns)); 356 matching_patterns));
316 } 357 }
317 358
318 LastUsedHandlerList::iterator watch_iter = FindHandler( 359 LastUsedHandlerList::iterator watch_iter = FindHandler(
319 named_action_list, kFileBrowserDomain, kFileBrowserWatchTaskId); 360 named_action_list, kFileBrowserDomain, kFileBrowserWatchTaskId);
320 LastUsedHandlerList::iterator gallery_iter = FindHandler( 361 LastUsedHandlerList::iterator gallery_iter = FindHandler(
321 named_action_list, kFileBrowserDomain, kFileBrowserGalleryTaskId); 362 named_action_list, kFileBrowserDomain, kFileBrowserGalleryTaskId);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, 399 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
359 const FileTaskFinishedCallback& done) OVERRIDE; 400 const FileTaskFinishedCallback& done) OVERRIDE;
360 401
361 private: 402 private:
362 // FileTaskExecutor is the only class allowed to create one. 403 // FileTaskExecutor is the only class allowed to create one.
363 friend class FileTaskExecutor; 404 friend class FileTaskExecutor;
364 405
365 ExtensionTaskExecutor(Profile* profile, 406 ExtensionTaskExecutor(Profile* profile,
366 const GURL source_url, 407 const GURL source_url,
367 const std::string& extension_id, 408 const std::string& extension_id,
409 TaskType task_type,
368 const std::string& action_id); 410 const std::string& action_id);
369 virtual ~ExtensionTaskExecutor(); 411 virtual ~ExtensionTaskExecutor();
370 412
371 struct FileDefinition { 413 struct FileDefinition {
372 FileDefinition(); 414 FileDefinition();
373 ~FileDefinition(); 415 ~FileDefinition();
374 416
375 GURL target_file_url; 417 GURL target_file_url;
376 FilePath virtual_path; 418 FilePath virtual_path;
377 FilePath absolute_path; 419 FilePath absolute_path;
(...skipping 18 matching lines...) Expand all
396 const GURL& file_system_root, 438 const GURL& file_system_root,
397 const FileDefinitionList& file_list, 439 const FileDefinitionList& file_list,
398 int handler_pid_in, 440 int handler_pid_in,
399 extensions::ExtensionHost* host); 441 extensions::ExtensionHost* host);
400 442
401 // Populates |handler_host_permissions| with file path-permissions pairs that 443 // Populates |handler_host_permissions| with file path-permissions pairs that
402 // will be given to the handler extension host process. 444 // will be given to the handler extension host process.
403 void InitHandlerHostFileAccessPermissions( 445 void InitHandlerHostFileAccessPermissions(
404 const FileDefinitionList& file_list, 446 const FileDefinitionList& file_list,
405 const extensions::Extension* handler_extension, 447 const extensions::Extension* handler_extension,
406 const std::string& action_id,
407 const base::Closure& callback); 448 const base::Closure& callback);
408 449
409 // Invoked upon completion of InitHandlerHostFileAccessPermissions initiated 450 // Invoked upon completion of InitHandlerHostFileAccessPermissions initiated
410 // by ExecuteFileActionsOnUIThread. 451 // by ExecuteFileActionsOnUIThread.
411 void OnInitAccessForExecuteFileActionsOnUIThread( 452 void OnInitAccessForExecuteFileActionsOnUIThread(
412 const std::string& file_system_name, 453 const std::string& file_system_name,
413 const GURL& file_system_root, 454 const GURL& file_system_root,
414 const FileDefinitionList& file_list, 455 const FileDefinitionList& file_list,
415 int handler_pid); 456 int handler_pid);
416 457
417 // Registers file permissions from |handler_host_permissions_| with 458 // Registers file permissions from |handler_host_permissions_| with
418 // ChildProcessSecurityPolicy for process with id |handler_pid|. 459 // ChildProcessSecurityPolicy for process with id |handler_pid|.
419 void SetupHandlerHostFileAccessPermissions(int handler_pid); 460 void SetupHandlerHostFileAccessPermissions(int handler_pid);
420 461
421 // Helper function to get the extension pointer. 462 // Helper function to get the extension pointer.
422 const extensions::Extension* GetExtension(); 463 const extensions::Extension* GetExtension();
423 464
424 const GURL source_url_; 465 const GURL source_url_;
425 const std::string extension_id_; 466 const std::string extension_id_;
467 TaskType task_type_;
426 const std::string action_id_; 468 const std::string action_id_;
427 FileTaskFinishedCallback done_; 469 FileTaskFinishedCallback done_;
428 470
429 // (File path, permission for file path) pairs for the handler. 471 // (File path, permission for file path) pairs for the handler.
430 std::vector<std::pair<FilePath, int> > handler_host_permissions_; 472 std::vector<std::pair<FilePath, int> > handler_host_permissions_;
431 }; 473 };
432 474
433 // static 475 // static
434 FileTaskExecutor* FileTaskExecutor::Create(Profile* profile, 476 FileTaskExecutor* FileTaskExecutor::Create(Profile* profile,
435 const GURL source_url, 477 const GURL source_url,
436 const std::string& extension_id, 478 const std::string& extension_id,
479 TaskType task_type,
437 const std::string& action_id) { 480 const std::string& action_id) {
438 // Check out the extension ID and see if this is a drive task, 481 if (task_type == TASK_DRIVE) {
439 // and instantiate drive-specific executor if so.
440 if (StartsWithASCII(extension_id,
441 FileTaskExecutor::kDriveTaskExtensionPrefix,
442 false)) {
443 return new gdata::DriveTaskExecutor(profile, 482 return new gdata::DriveTaskExecutor(profile,
444 extension_id, // really app_id 483 extension_id, // really app_id
445 action_id); 484 action_id);
446 } else { 485 } else {
447 return new ExtensionTaskExecutor(profile, 486 return new ExtensionTaskExecutor(profile,
448 source_url, 487 source_url,
449 extension_id, 488 extension_id,
489 task_type,
450 action_id); 490 action_id);
451 } 491 }
452 } 492 }
453 493
454 FileTaskExecutor::FileTaskExecutor(Profile* profile) : profile_(profile) { 494 FileTaskExecutor::FileTaskExecutor(Profile* profile) : profile_(profile) {
455 } 495 }
456 496
457 FileTaskExecutor::~FileTaskExecutor() { 497 FileTaskExecutor::~FileTaskExecutor() {
458 } 498 }
459 499
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 int handler_pid_; 673 int handler_pid_;
634 std::string action_id_; 674 std::string action_id_;
635 std::vector<GURL> origin_file_urls_; 675 std::vector<GURL> origin_file_urls_;
636 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); 676 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher);
637 }; 677 };
638 678
639 ExtensionTaskExecutor::ExtensionTaskExecutor( 679 ExtensionTaskExecutor::ExtensionTaskExecutor(
640 Profile* profile, 680 Profile* profile,
641 const GURL source_url, 681 const GURL source_url,
642 const std::string& extension_id, 682 const std::string& extension_id,
683 TaskType task_type,
643 const std::string& action_id) 684 const std::string& action_id)
644 : FileTaskExecutor(profile), 685 : FileTaskExecutor(profile),
645 source_url_(source_url), 686 source_url_(source_url),
646 extension_id_(extension_id), 687 extension_id_(extension_id),
688 task_type_(task_type),
647 action_id_(action_id) { 689 action_id_(action_id) {
648 } 690 }
649 691
650 ExtensionTaskExecutor::~ExtensionTaskExecutor() {} 692 ExtensionTaskExecutor::~ExtensionTaskExecutor() {}
651 693
652 bool ExtensionTaskExecutor::ExecuteAndNotify( 694 bool ExtensionTaskExecutor::ExecuteAndNotify(
653 const std::vector<GURL>& file_urls, 695 const std::vector<GURL>& file_urls,
654 const FileTaskFinishedCallback& done) { 696 const FileTaskFinishedCallback& done) {
655 ExtensionService* service = profile()->GetExtensionService(); 697 ExtensionService* service = profile()->GetExtensionService();
656 if (!service) 698 if (!service)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 772
731 const Extension* extension = GetExtension(); 773 const Extension* extension = GetExtension();
732 if (!extension) { 774 if (!extension) {
733 ExecuteDoneOnUIThread(false); 775 ExecuteDoneOnUIThread(false);
734 return; 776 return;
735 } 777 }
736 778
737 InitHandlerHostFileAccessPermissions( 779 InitHandlerHostFileAccessPermissions(
738 file_list, 780 file_list,
739 extension, 781 extension,
740 action_id_,
741 base::Bind( 782 base::Bind(
742 &ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread, 783 &ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread,
743 this, 784 this,
744 file_system_name, 785 file_system_name,
745 file_system_root, 786 file_system_root,
746 file_list, 787 file_list,
747 handler_pid)); 788 handler_pid));
748 } 789 }
749 790
750 void ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread( 791 void ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 int handler_pid_in, 828 int handler_pid_in,
788 extensions::ExtensionHost* host) { 829 extensions::ExtensionHost* host) {
789 int handler_pid = host ? host->render_process_host()->GetID() : 830 int handler_pid = host ? host->render_process_host()->GetID() :
790 handler_pid_in; 831 handler_pid_in;
791 832
792 if (handler_pid <= 0) { 833 if (handler_pid <= 0) {
793 ExecuteDoneOnUIThread(false); 834 ExecuteDoneOnUIThread(false);
794 return; 835 return;
795 } 836 }
796 837
838 // If we're a Web Intent action (to an extension), short-circuit and deliver
839 // the Web Intent via LaunchPlatformAppWithPath.
840 if (task_type_ == TASK_WEBINTENT) {
841 for (FileDefinitionList::const_iterator iter = file_list.begin();
842 iter != file_list.end(); ++iter) {
843 extensions::LaunchPlatformAppWithPath(
844 profile(), GetExtension(), iter->absolute_path);
845 }
846 ExecuteDoneOnUIThread(true);
847 return;
848 }
849 DCHECK(task_type_ == TASK_FILE);
850
797 extensions::EventRouter* event_router = profile()->GetExtensionEventRouter(); 851 extensions::EventRouter* event_router = profile()->GetExtensionEventRouter();
798 if (!event_router) { 852 if (!event_router) {
799 ExecuteDoneOnUIThread(false); 853 ExecuteDoneOnUIThread(false);
800 return; 854 return;
801 } 855 }
802 856
803 SetupHandlerHostFileAccessPermissions(handler_pid); 857 SetupHandlerHostFileAccessPermissions(handler_pid);
804 858
805 scoped_ptr<ListValue> event_args(new ListValue()); 859 scoped_ptr<ListValue> event_args(new ListValue());
806 event_args->Append(Value::CreateStringValue(action_id_)); 860 event_args->Append(Value::CreateStringValue(action_id_));
(...skipping 26 matching lines...) Expand all
833 887
834 event_router->DispatchEventToExtension( 888 event_router->DispatchEventToExtension(
835 extension_id_, std::string("fileBrowserHandler.onExecute"), 889 extension_id_, std::string("fileBrowserHandler.onExecute"),
836 event_args.Pass(), profile(), GURL()); 890 event_args.Pass(), profile(), GURL());
837 ExecuteDoneOnUIThread(true); 891 ExecuteDoneOnUIThread(true);
838 } 892 }
839 893
840 void ExtensionTaskExecutor::InitHandlerHostFileAccessPermissions( 894 void ExtensionTaskExecutor::InitHandlerHostFileAccessPermissions(
841 const FileDefinitionList& file_list, 895 const FileDefinitionList& file_list,
842 const Extension* handler_extension, 896 const Extension* handler_extension,
843 const std::string& action_id,
844 const base::Closure& callback) { 897 const base::Closure& callback) {
845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
846 899
847 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>); 900 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>);
848 for (FileDefinitionList::const_iterator iter = file_list.begin(); 901 for (FileDefinitionList::const_iterator iter = file_list.begin();
849 iter != file_list.end(); 902 iter != file_list.end();
850 ++iter) { 903 ++iter) {
851 // Setup permission for file's absolute file. 904 // Setup permission for file's absolute file.
852 handler_host_permissions_.push_back(std::make_pair( 905 handler_host_permissions_.push_back(std::make_pair(iter->absolute_path,
853 iter->absolute_path, 906 GetAccessPermissionsForHandler(handler_extension,
854 GetAccessPermissionsForHandler(handler_extension, action_id))); 907 action_id_,
908 task_type_)));
855 909
856 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) 910 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path))
857 gdata_paths->push_back(iter->virtual_path); 911 gdata_paths->push_back(iter->virtual_path);
858 } 912 }
859 913
860 if (gdata_paths->empty()) { 914 if (gdata_paths->empty()) {
861 // Invoke callback if none of the files are on gdata mount point. 915 // Invoke callback if none of the files are on gdata mount point.
862 callback.Run(); 916 callback.Run();
863 return; 917 return;
864 } 918 }
(...skipping 13 matching lines...) Expand all
878 handler_pid, 932 handler_pid,
879 handler_host_permissions_[i].first, 933 handler_host_permissions_[i].first,
880 handler_host_permissions_[i].second); 934 handler_host_permissions_[i].second);
881 } 935 }
882 936
883 // We don't need this anymore. 937 // We don't need this anymore.
884 handler_host_permissions_.clear(); 938 handler_host_permissions_.clear();
885 } 939 }
886 940
887 } // namespace file_handler_util 941 } // namespace file_handler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698