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 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 4 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
5 | 5 |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 16 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
17 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
18 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
19 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
20 #include "chrome/browser/extensions/crx_installer.h" | 20 #include "chrome/browser/extensions/crx_installer.h" |
21 #include "chrome/browser/extensions/extension_install_ui.h" | 21 #include "chrome/browser/extensions/extension_install_ui.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/plugin_prefs.h" | 23 #include "chrome/browser/plugin_prefs.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/profiles/profile_manager.h" | |
25 #include "chrome/browser/simple_message_box.h" | 26 #include "chrome/browser/simple_message_box.h" |
27 #include "chrome/browser/tabs/tab_strip_model.h" | |
26 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
28 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
29 #include "chrome/common/extensions/file_browser_handler.h" | 32 #include "chrome/common/extensions/file_browser_handler.h" |
30 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/plugin_service.h" | 36 #include "content/public/browser/plugin_service.h" |
34 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
38 #include "content/public/browser/web_contents.h" | |
35 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
36 #include "net/base/escape.h" | 40 #include "net/base/escape.h" |
37 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
38 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
39 #include "webkit/fileapi/file_system_context.h" | 43 #include "webkit/fileapi/file_system_context.h" |
40 #include "webkit/fileapi/file_system_mount_point_provider.h" | 44 #include "webkit/fileapi/file_system_mount_point_provider.h" |
41 #include "webkit/fileapi/file_system_util.h" | 45 #include "webkit/fileapi/file_system_util.h" |
42 #include "webkit/plugins/webplugininfo.h" | 46 #include "webkit/plugins/webplugininfo.h" |
43 | 47 |
44 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 IDS_FILE_BROWSER_SELECT_OPEN_MULTI_FILE_TITLE); | 363 IDS_FILE_BROWSER_SELECT_OPEN_MULTI_FILE_TITLE); |
360 break; | 364 break; |
361 | 365 |
362 default: | 366 default: |
363 NOTREACHED(); | 367 NOTREACHED(); |
364 } | 368 } |
365 | 369 |
366 return title; | 370 return title; |
367 } | 371 } |
368 | 372 |
369 void ViewRemovableDrive(const FilePath& dir) { | 373 enum TAB_REUSE_MODE { |
370 Browser* browser = BrowserList::GetLastActive(); | 374 REUSE_ANY_FILE_MANAGER, |
371 if (!browser) | 375 REUSE_SAME_PATH, |
376 REUSE_NEVER | |
377 }; | |
378 | |
379 bool FileManageTabExists(const FilePath& path, TAB_REUSE_MODE mode) { | |
380 if (mode == REUSE_NEVER) | |
381 return false; | |
382 | |
383 const std::string ref = std::string("/") + path.value(); | |
384 | |
385 for (BrowserList::const_iterator browser_iterator = BrowserList::begin(); | |
386 browser_iterator != BrowserList::end(); ++browser_iterator) { | |
387 Browser* browser = *browser_iterator; | |
388 TabStripModel* tab_strip = browser->tabstrip_model(); | |
389 for (int idx = 0; idx < tab_strip->count(); idx++) { | |
390 content::WebContents* web_contents = | |
391 tab_strip->GetTabContentsAt(idx)->web_contents(); | |
392 const GURL& url = web_contents->GetURL(); | |
393 if (url.GetOrigin().spec() == chrome::kChromeUIFileManagerURL) { | |
dgozman
2012/04/16 14:48:32
So, this does not work for 'chrome-extension://...
Vladislav Kaznacheev
2012/04/16 15:23:44
I have added a comment.
On 2012/04/16 14:48:32, d
| |
394 if (mode == REUSE_ANY_FILE_MANAGER || ref == url.ref()) { | |
395 if (mode == REUSE_SAME_PATH && tab_strip->active_index() != idx) { | |
396 browser->window()->Show(); | |
397 tab_strip->ActivateTabAt(idx, false); | |
398 } | |
399 return true; | |
400 } | |
401 } | |
402 } | |
403 } | |
404 | |
405 return false; | |
406 } | |
407 | |
408 void OpenFileBrowser(const FilePath& path, | |
409 TAB_REUSE_MODE mode, | |
410 const std::string& flag_name) { | |
411 if (FileManageTabExists(path, mode)) | |
372 return; | 412 return; |
373 | 413 |
414 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
415 | |
374 FilePath virtual_path; | 416 FilePath virtual_path; |
375 if (!ConvertFileToRelativeFileSystemPath(browser->profile(), dir, | 417 if (!ConvertFileToRelativeFileSystemPath(profile, path, &virtual_path)) |
376 &virtual_path)) { | |
377 return; | 418 return; |
378 } | |
379 | |
380 DictionaryValue arg_value; | |
381 arg_value.SetBoolean("mountTriggered", true); | |
382 | |
383 std::string json_args; | |
384 base::JSONWriter::Write(&arg_value, &json_args); | |
385 | 419 |
386 std::string url = chrome::kChromeUIFileManagerURL; | 420 std::string url = chrome::kChromeUIFileManagerURL; |
387 url += "?" + json_args + "#/" + | 421 if (flag_name.size()) { |
388 net::EscapeUrlEncodedData(virtual_path.value(), false); | 422 DictionaryValue arg_value; |
423 arg_value.SetBoolean(flag_name, "true"); | |
424 std::string query; | |
425 base::JSONWriter::Write(&arg_value, &query); | |
426 url += "?" + net::EscapeUrlEncodedData(query, false); | |
427 } | |
428 url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false); | |
429 | |
430 ExtensionService* service = profile->GetExtensionService(); | |
431 if (!service) | |
432 return; | |
433 | |
434 const Extension* extension = | |
435 service->GetExtensionById(kFileBrowserDomain, false); | |
436 if (!extension) | |
437 return; | |
438 | |
439 extension_misc::LaunchContainer launch_container = | |
440 service->extension_prefs()-> | |
441 GetLaunchContainer(extension, ExtensionPrefs::LAUNCH_DEFAULT); | |
389 | 442 |
390 content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); | 443 content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); |
391 browser->ShowSingletonTabRespectRef(GURL(url)); | 444 Browser::OpenApplication( |
445 profile, extension, launch_container, GURL(url), NEW_FOREGROUND_TAB); | |
392 } | 446 } |
393 | 447 |
394 void OpenFileBrowser(const FilePath& full_path) { | 448 void ViewRemovableDrive(const FilePath& path) { |
395 Browser* browser = BrowserList::GetLastActive(); | 449 OpenFileBrowser(path, REUSE_ANY_FILE_MANAGER, "mountTriggered"); |
dgozman
2012/04/16 14:48:32
Why reuse any? Maybe, REUSE_SAME_PATH?
Vladislav Kaznacheev
2012/04/16 15:23:44
This is what we want. I added a comment in the hea
| |
396 if (!browser) | |
397 return; | |
398 | |
399 FilePath virtual_path; | |
400 if (!ConvertFileToRelativeFileSystemPath(browser->profile(), full_path, | |
401 &virtual_path)) { | |
402 return; | |
403 } | |
404 | |
405 std::string url = chrome::kChromeUIFileManagerURL; | |
406 url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false); | |
407 | |
408 content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab")); | |
409 browser->ShowSingletonTabRespectRef(GURL(url)); | |
410 } | 450 } |
411 | 451 |
412 void ViewFolder(const FilePath& dir) { | 452 void ShowFileInFolder(const FilePath& path) { |
413 OpenFileBrowser(dir); | 453 // This action changes the selection so we do not reuse existing tabs. |
454 OpenFileBrowser(path, REUSE_NEVER, "selectOnly"); | |
455 } | |
456 | |
457 void ViewFolder(const FilePath& path) { | |
458 OpenFileBrowser(path, REUSE_SAME_PATH, ""); | |
414 } | 459 } |
415 | 460 |
416 class StandaloneExecutor : public FileTaskExecutor { | 461 class StandaloneExecutor : public FileTaskExecutor { |
417 public: | 462 public: |
418 StandaloneExecutor(Profile * profile, | 463 StandaloneExecutor(Profile * profile, |
419 const GURL& source_url, | 464 const GURL& source_url, |
420 const std::string& extension_id, | 465 const std::string& extension_id, |
421 const std::string& action_id) | 466 const std::string& action_id) |
422 : FileTaskExecutor(profile, source_url, extension_id, action_id) | 467 : FileTaskExecutor(profile, source_url, extension_id, action_id) |
423 {} | 468 {} |
424 | 469 |
425 protected : | 470 protected : |
426 // FileTaskExecutor overrides. | 471 // FileTaskExecutor overrides. |
427 virtual Browser* browser() { return BrowserList::GetLastActive(); } | 472 virtual Browser* browser() { |
473 return Browser::GetOrCreateTabbedBrowser(profile()); | |
474 } | |
428 virtual void Done(bool) {} | 475 virtual void Done(bool) {} |
429 }; | 476 }; |
430 | 477 |
431 bool TryOpeningFileBrowser(const FilePath& full_path) { | 478 bool TryOpeningFileBrowser(Profile* profile, const FilePath& path) { |
432 Browser* browser = BrowserList::GetLastActive(); | |
433 if (!browser) | |
434 return false; | |
435 | |
436 Profile* profile = browser->profile(); | |
437 | |
438 GURL url; | 479 GURL url; |
439 if (!ConvertFileToFileSystemUrl(profile, full_path, | 480 if (!ConvertFileToFileSystemUrl(profile, path, |
440 GetFileBrowserExtensionUrl().GetOrigin(), &url)) | 481 GetFileBrowserExtensionUrl().GetOrigin(), &url)) |
441 return false; | 482 return false; |
442 | 483 |
443 const FileBrowserHandler* handler; | 484 const FileBrowserHandler* handler; |
444 if (!file_handler_util::GetDefaultTask(profile, url, &handler)) | 485 if (!file_handler_util::GetDefaultTask(profile, url, &handler)) |
445 return false; | 486 return false; |
446 | 487 |
447 std::string extension_id = handler->extension_id(); | 488 std::string extension_id = handler->extension_id(); |
448 std::string action_id = handler->id(); | 489 std::string action_id = handler->id(); |
449 if (extension_id == kFileBrowserDomain) { | 490 if (extension_id == kFileBrowserDomain) { |
450 // Only two of the built-in File Browser tasks require opening the File | 491 // Only two of the built-in File Browser tasks require opening the File |
451 // Browser tab. Others just end up calling TryViewingFile. | 492 // Browser tab. Others just end up calling TryViewingFile. |
452 if (action_id == kFileBrowserGalleryTaskId || | 493 if (action_id == kFileBrowserGalleryTaskId || |
453 action_id == kFileBrowserMountArchiveTaskId) { | 494 action_id == kFileBrowserMountArchiveTaskId) { |
454 OpenFileBrowser(full_path); | 495 // Tab reuse currently does not work for these two tasks. |
496 // |gallery| tries to put the file url into the tab url but it does not | |
497 // work on Chrome OS. | |
498 // |mount-archive| does not even try. | |
499 OpenFileBrowser(path, REUSE_SAME_PATH, ""); | |
455 return true; | 500 return true; |
456 } | 501 } |
457 } else { | 502 } else { |
458 // We are executing the task on behalf of File Browser extension. | 503 // We are executing the task on behalf of File Browser extension. |
459 const GURL source_url(kBaseFileBrowserUrl); | 504 const GURL source_url(kBaseFileBrowserUrl); |
460 | 505 |
461 // If File Browser has not been open yet then it did not request access | 506 // If File Browser has not been open yet then it did not request access |
462 // to the file system. Do it now. | 507 // to the file system. Do it now. |
463 fileapi::ExternalFileSystemMountPointProvider* external_provider = | 508 fileapi::ExternalFileSystemMountPointProvider* external_provider = |
464 BrowserContext::GetFileSystemContext(profile)->external_provider(); | 509 BrowserContext::GetFileSystemContext(profile)->external_provider(); |
465 if (!external_provider) | 510 if (!external_provider) |
466 return false; | 511 return false; |
467 external_provider->GrantFullAccessToExtension(source_url.host()); | 512 external_provider->GrantFullAccessToExtension(source_url.host()); |
468 | 513 |
469 std::vector<GURL> urls; | 514 std::vector<GURL> urls; |
470 urls.push_back(url); | 515 urls.push_back(url); |
471 scoped_refptr<StandaloneExecutor> executor = new StandaloneExecutor( | 516 scoped_refptr<StandaloneExecutor> executor = new StandaloneExecutor( |
472 profile, source_url, extension_id, action_id); | 517 profile, source_url, extension_id, action_id); |
473 executor->Execute(urls); | 518 executor->Execute(urls); |
474 return true; | 519 return true; |
475 } | 520 } |
476 return false; | 521 return false; |
477 } | 522 } |
478 | 523 |
479 void ViewFile(const FilePath& full_path, bool enqueue) { | 524 void ViewFile(const FilePath& path) { |
480 if (!TryOpeningFileBrowser(full_path) && !TryViewingFile(full_path)) { | 525 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
481 Browser* browser = BrowserList::GetLastActive(); | 526 if (!TryOpeningFileBrowser(profile, path) && |
482 if (!browser) | 527 !TryViewingFile(profile, path)) { |
483 return; | 528 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); |
484 browser::ShowErrorBox( | 529 browser::ShowErrorBox( |
485 browser->window()->GetNativeHandle(), | 530 browser->window()->GetNativeHandle(), |
486 l10n_util::GetStringFUTF16( | 531 l10n_util::GetStringFUTF16( |
487 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, | 532 IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE, |
488 UTF8ToUTF16(full_path.BaseName().value())), | 533 UTF8ToUTF16(path.BaseName().value())), |
489 l10n_util::GetStringUTF16( | 534 l10n_util::GetStringUTF16( |
490 IDS_FILE_BROWSER_ERROR_VIEWING_FILE)); | 535 IDS_FILE_BROWSER_ERROR_VIEWING_FILE)); |
491 } | 536 } |
492 } | 537 } |
493 | 538 |
494 // Reads an entire file into a string. Fails is the file is 4K or longer. | 539 // Reads an entire file into a string. Fails is the file is 4K or longer. |
495 bool ReadSmallFileToString(const FilePath& path, std::string* contents) { | 540 bool ReadSmallFileToString(const FilePath& path, std::string* contents) { |
496 FILE* file = file_util::OpenFile(path, "rb"); | 541 FILE* file = file_util::OpenFile(path, "rb"); |
497 if (!file) { | 542 if (!file) { |
498 return false; | 543 return false; |
499 } | 544 } |
500 | 545 |
501 char buf[1 << 12]; // 4K | 546 char buf[1 << 12]; // 4K |
502 size_t len = fread(buf, 1, sizeof(buf), file); | 547 size_t len = fread(buf, 1, sizeof(buf), file); |
503 if (len > 0) { | 548 if (len > 0) { |
504 contents->append(buf, len); | 549 contents->append(buf, len); |
505 } | 550 } |
506 file_util::CloseFile(file); | 551 file_util::CloseFile(file); |
507 | 552 |
508 return len < sizeof(buf); | 553 return len < sizeof(buf); |
509 } | 554 } |
510 | 555 |
511 void OpenUrlOnUIThread(const GURL& url) { | 556 void OpenUrlOnUIThread(const GURL& url) { |
512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
513 Browser* browser = BrowserList::GetLastActive(); | 558 Browser* browser = Browser::GetOrCreateTabbedBrowser( |
514 if (!browser) | 559 ProfileManager::GetDefaultProfileOrOffTheRecord()); |
515 return; | |
516 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); | 560 browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK); |
517 } | 561 } |
518 | 562 |
519 // Reads JSON from a Google Docs file, extracts a document url and opens it | 563 // Reads JSON from a Google Docs file, extracts a document url and opens it |
520 // in a tab. | 564 // in a tab. |
521 void ReadUrlFromGDocOnFileThread(const FilePath& file_path) { | 565 void ReadUrlFromGDocOnFileThread(const FilePath& file_path) { |
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
523 std::string contents; | 567 std::string contents; |
524 if (!ReadSmallFileToString(file_path, &contents)) { | 568 if (!ReadSmallFileToString(file_path, &contents)) { |
525 LOG(ERROR) << "Error reading " << file_path.value(); | 569 LOG(ERROR) << "Error reading " << file_path.value(); |
526 return; | 570 return; |
527 } | 571 } |
528 | 572 |
529 scoped_ptr<base::Value> root_value; | 573 scoped_ptr<base::Value> root_value; |
530 root_value.reset(base::JSONReader::Read(contents)); | 574 root_value.reset(base::JSONReader::Read(contents)); |
531 | 575 |
532 DictionaryValue* dictionary_value; | 576 DictionaryValue* dictionary_value; |
533 std::string edit_url_string; | 577 std::string edit_url_string; |
534 if (!root_value.get() || | 578 if (!root_value.get() || |
535 !root_value->GetAsDictionary(&dictionary_value) || | 579 !root_value->GetAsDictionary(&dictionary_value) || |
536 !dictionary_value->GetString("url", &edit_url_string)) { | 580 !dictionary_value->GetString("url", &edit_url_string)) { |
537 LOG(ERROR) << "Invalid JSON in " << file_path.value(); | 581 LOG(ERROR) << "Invalid JSON in " << file_path.value(); |
538 return; | 582 return; |
539 } | 583 } |
540 | 584 |
541 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 585 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
542 base::Bind(OpenUrlOnUIThread, GURL(edit_url_string))); | 586 base::Bind(OpenUrlOnUIThread, GURL(edit_url_string))); |
543 } | 587 } |
544 | 588 |
545 bool TryViewingFile(const FilePath& full_path) { | 589 bool TryViewingFile(Profile* profile, const FilePath& path) { |
546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
547 | 591 |
548 // There is nothing we can do if the browser is not present. | 592 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); |
549 Browser* browser = BrowserList::GetLastActive(); | |
550 if (!browser) | |
551 return true; | |
552 | 593 |
553 std::string file_extension = full_path.Extension(); | 594 std::string file_extension = path.Extension(); |
554 // For things supported natively by the browser, we should open it | 595 // For things supported natively by the browser, we should open it |
555 // in a tab. | 596 // in a tab. |
556 if (IsSupportedBrowserExtension(file_extension.data()) || | 597 if (IsSupportedBrowserExtension(file_extension.data()) || |
557 ShouldBeOpenedWithPdfPlugin(file_extension.data())) { | 598 ShouldBeOpenedWithPdfPlugin(profile, file_extension.data())) { |
558 GURL page_url = net::FilePathToFileURL(full_path); | 599 GURL page_url = net::FilePathToFileURL(path); |
559 #if defined(OS_CHROMEOS) | 600 #if defined(OS_CHROMEOS) |
560 // Override gdata resource to point to internal handler instead of file: | 601 // Override gdata resource to point to internal handler instead of file: |
561 // URL. | 602 // URL. |
562 // There is nothing we can do if the browser is not present. | 603 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { |
563 if (gdata::util::GetSpecialRemoteRootPath().IsParent(full_path)) { | |
564 gdata::GDataSystemService* system_service = | 604 gdata::GDataSystemService* system_service = |
565 gdata::GDataSystemServiceFactory::GetForProfile(browser->profile()); | 605 gdata::GDataSystemServiceFactory::GetForProfile(profile); |
566 if (!system_service) | 606 if (!system_service) |
567 return false; | 607 return false; |
568 | 608 |
569 GetFilePropertiesDelegate delegate; | 609 GetFilePropertiesDelegate delegate; |
570 system_service->file_system()->FindFileByPathSync( | 610 system_service->file_system()->FindFileByPathSync( |
571 gdata::util::ExtractGDataPath(full_path), &delegate); | 611 gdata::util::ExtractGDataPath(path), &delegate); |
572 if (delegate.resource_id().empty()) | 612 if (delegate.resource_id().empty()) |
573 return false; | 613 return false; |
574 page_url = gdata::util::GetFileResourceUrl(delegate.resource_id(), | 614 page_url = gdata::util::GetFileResourceUrl(delegate.resource_id(), |
575 delegate.file_name()); | 615 delegate.file_name()); |
576 } | 616 } |
577 #endif | 617 #endif |
578 browser->AddSelectedTabWithURL(page_url, | 618 browser->AddSelectedTabWithURL(page_url, |
579 content::PAGE_TRANSITION_LINK); | 619 content::PAGE_TRANSITION_LINK); |
580 return true; | 620 return true; |
581 } | 621 } |
582 | 622 |
583 if (IsSupportedGDocsExtension(file_extension.data())) { | 623 if (IsSupportedGDocsExtension(file_extension.data())) { |
584 if (gdata::util::GetSpecialRemoteRootPath().IsParent(full_path)) { | 624 if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) { |
585 // The file is on Google Docs. Get the Docs from the GData service. | 625 // The file is on Google Docs. Get the Docs from the GData service. |
586 gdata::GDataSystemService* system_service = | 626 gdata::GDataSystemService* system_service = |
587 gdata::GDataSystemServiceFactory::GetForProfile(browser->profile()); | 627 gdata::GDataSystemServiceFactory::GetForProfile(profile); |
588 if (!system_service) | 628 if (!system_service) |
589 return false; | 629 return false; |
590 | 630 |
591 GetFilePropertiesDelegate delegate; | 631 GetFilePropertiesDelegate delegate; |
592 system_service->file_system()->FindFileByPathSync( | 632 system_service->file_system()->FindFileByPathSync( |
593 gdata::util::ExtractGDataPath(full_path), &delegate); | 633 gdata::util::ExtractGDataPath(path), &delegate); |
594 if (delegate.edit_url().spec().empty()) | 634 if (delegate.edit_url().spec().empty()) |
595 return false; | 635 return false; |
596 | 636 |
597 browser->AddSelectedTabWithURL(delegate.edit_url(), | 637 browser->AddSelectedTabWithURL(delegate.edit_url(), |
598 content::PAGE_TRANSITION_LINK); | 638 content::PAGE_TRANSITION_LINK); |
599 } else { | 639 } else { |
600 // The file is local (downloaded from an attachment or otherwise copied). | 640 // The file is local (downloaded from an attachment or otherwise copied). |
601 // Parse the file to extract the Docs url and open this url. | 641 // Parse the file to extract the Docs url and open this url. |
602 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 642 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
603 base::Bind(&ReadUrlFromGDocOnFileThread, full_path)); | 643 base::Bind(&ReadUrlFromGDocOnFileThread, path)); |
604 } | 644 } |
605 return true; | 645 return true; |
606 } | 646 } |
607 | 647 |
608 #if defined(OS_CHROMEOS) | 648 #if defined(OS_CHROMEOS) |
609 if (IsSupportedAVExtension(file_extension.data())) { | 649 if (IsSupportedAVExtension(file_extension.data())) { |
650 GURL url; | |
651 if (!ConvertFileToFileSystemUrl(profile, path, | |
652 GetFileBrowserExtensionUrl().GetOrigin(), &url)) | |
653 return false; | |
610 MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); | 654 MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); |
611 mediaplayer->PopupMediaPlayer(browser); | 655 mediaplayer->PopupMediaPlayer(); |
612 mediaplayer->ForcePlayMediaFile(browser->profile(), full_path); | 656 mediaplayer->ForcePlayMediaURL(url); |
613 return true; | 657 return true; |
614 } | 658 } |
615 #endif // OS_CHROMEOS | 659 #endif // OS_CHROMEOS |
616 | 660 |
617 if (IsCRXFile(file_extension.data())) { | 661 if (IsCRXFile(file_extension.data())) { |
618 InstallCRX(browser->profile(), full_path); | 662 InstallCRX(profile, path); |
619 return true; | 663 return true; |
620 } | 664 } |
621 | 665 |
622 // Unknown file type. Record UMA and show an error message. | 666 // Unknown file type. Record UMA and show an error message. |
623 size_t extension_index = UMAExtensionIndex(file_extension.data(), | 667 size_t extension_index = UMAExtensionIndex(file_extension.data(), |
624 kUMATrackingExtensions, | 668 kUMATrackingExtensions, |
625 arraysize(kUMATrackingExtensions)); | 669 arraysize(kUMATrackingExtensions)); |
626 UMA_HISTOGRAM_ENUMERATION("FileBrowser.OpeningFileType", | 670 UMA_HISTOGRAM_ENUMERATION("FileBrowser.OpeningFileType", |
627 extension_index, | 671 extension_index, |
628 arraysize(kUMATrackingExtensions) - 1); | 672 arraysize(kUMATrackingExtensions) - 1); |
629 return false; | 673 return false; |
630 } | 674 } |
631 | 675 |
632 void InstallCRX(Profile* profile, const FilePath& full_path) { | 676 void InstallCRX(Profile* profile, const FilePath& path) { |
633 ExtensionService* service = profile->GetExtensionService(); | 677 ExtensionService* service = profile->GetExtensionService(); |
634 CHECK(service); | 678 CHECK(service); |
635 if (!service) | 679 if (!service) |
636 return; | 680 return; |
637 | 681 |
638 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service, | 682 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service, |
639 new ExtensionInstallUI(profile))); | 683 new ExtensionInstallUI(profile))); |
640 installer->set_is_gallery_install(false); | 684 installer->set_is_gallery_install(false); |
641 installer->set_allow_silent_install(false); | 685 installer->set_allow_silent_install(false); |
642 installer->InstallCrx(full_path); | 686 installer->InstallCrx(path); |
643 } | 687 } |
644 | 688 |
645 // If pdf plugin is enabled, we should open pdf files in a tab. | 689 // If pdf plugin is enabled, we should open pdf files in a tab. |
646 bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) { | 690 bool ShouldBeOpenedWithPdfPlugin(Profile* profile, const char* file_extension) { |
647 if (base::strcasecmp(file_extension, kPdfExtension) != 0) | 691 if (base::strcasecmp(file_extension, kPdfExtension) != 0) |
648 return false; | 692 return false; |
649 | 693 |
650 Browser* browser = BrowserList::GetLastActive(); | |
651 if (!browser) | |
652 return false; | |
653 | |
654 FilePath pdf_path; | 694 FilePath pdf_path; |
655 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 695 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
656 | 696 |
657 webkit::WebPluginInfo plugin; | 697 webkit::WebPluginInfo plugin; |
658 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) | 698 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) |
659 return false; | 699 return false; |
660 | 700 |
661 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | 701 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
662 if (!plugin_prefs) | 702 if (!plugin_prefs) |
663 return false; | 703 return false; |
664 | 704 |
665 return plugin_prefs->IsPluginEnabled(plugin); | 705 return plugin_prefs->IsPluginEnabled(plugin); |
666 } | 706 } |
667 | 707 |
668 ListValue* ProgressStatusVectorToListValue( | 708 ListValue* ProgressStatusVectorToListValue( |
669 Profile* profile, const GURL& origin_url, | 709 Profile* profile, const GURL& origin_url, |
670 const std::vector<GDataOperationRegistry::ProgressStatus>& list) { | 710 const std::vector<GDataOperationRegistry::ProgressStatus>& list) { |
671 scoped_ptr<ListValue> result_list(new ListValue()); | 711 scoped_ptr<ListValue> result_list(new ListValue()); |
672 for (std::vector< | 712 for (std::vector< |
673 GDataOperationRegistry::ProgressStatus>::const_iterator iter = | 713 GDataOperationRegistry::ProgressStatus>::const_iterator iter = |
674 list.begin(); | 714 list.begin(); |
675 iter != list.end(); ++iter) { | 715 iter != list.end(); ++iter) { |
676 result_list->Append( | 716 result_list->Append( |
677 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); | 717 ProgessStatusToDictionaryValue(profile, origin_url, *iter)); |
678 } | 718 } |
679 return result_list.release(); | 719 return result_list.release(); |
680 } | 720 } |
681 | 721 |
682 } // namespace file_manager_util | 722 } // namespace file_manager_util |
OLD | NEW |