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

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

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

Powered by Google App Engine
This is Rietveld 408576698