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 "ash/shell.h" | 6 #include "ash/shell.h" |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 page_url = GURL(entry_proto->file_specific_info().alternate_url()); | 256 page_url = GURL(entry_proto->file_specific_info().alternate_url()); |
257 } else { | 257 } else { |
258 NOTREACHED(); | 258 NOTREACHED(); |
259 } | 259 } |
260 OpenNewTab(page_url, profile); | 260 OpenNewTab(page_url, profile); |
261 } else { | 261 } else { |
262 ShowWarningMessageBox(profile, file_path); | 262 ShowWarningMessageBox(profile, file_path); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
| 266 void InstallCRX(Browser* browser, const FilePath& path) { |
| 267 ExtensionService* service = |
| 268 extensions::ExtensionSystem::Get(browser->profile())->extension_service(); |
| 269 CHECK(service); |
| 270 |
| 271 content::WebContents* web_contents = |
| 272 browser->tab_strip_model()->GetActiveWebContents(); |
| 273 scoped_refptr<extensions::CrxInstaller> installer( |
| 274 extensions::CrxInstaller::Create( |
| 275 service, |
| 276 new ExtensionInstallPrompt(web_contents))); |
| 277 installer->set_error_on_unsupported_requirements(true); |
| 278 installer->set_is_gallery_install(false); |
| 279 installer->set_allow_silent_install(false); |
| 280 installer->InstallCrx(path); |
| 281 } |
| 282 |
266 // Called when a crx file on Drive was downloaded. | 283 // Called when a crx file on Drive was downloaded. |
267 void OnCRXDownloadCallback(Browser* browser, | 284 void OnCRXDownloadCallback(Browser* browser, |
268 drive::DriveFileError error, | 285 drive::DriveFileError error, |
269 const FilePath& file, | 286 const FilePath& file, |
270 const std::string& unused_mime_type, | 287 const std::string& unused_mime_type, |
271 drive::DriveFileType file_type) { | 288 drive::DriveFileType file_type) { |
272 if (error != drive::DRIVE_FILE_OK || file_type != drive::REGULAR_FILE) | 289 if (error != drive::DRIVE_FILE_OK || file_type != drive::REGULAR_FILE) |
273 return; | 290 return; |
274 InstallCRX(browser, file); | 291 InstallCRX(browser, file); |
275 } | 292 } |
276 | 293 |
277 } // namespace | |
278 | |
279 GURL GetFileBrowserExtensionUrl() { | |
280 return GURL(kFileBrowserExtensionUrl); | |
281 } | |
282 | |
283 GURL GetFileBrowserUrl() { | |
284 return GURL(kBaseFileBrowserUrl); | |
285 } | |
286 | |
287 GURL GetMediaPlayerUrl() { | |
288 return GURL(kMediaPlayerUrl); | |
289 } | |
290 | |
291 GURL GetVideoPlayerUrl(const GURL& source_url) { | |
292 return GURL(kVideoPlayerUrl + std::string("?") + source_url.spec()); | |
293 } | |
294 | |
295 bool ConvertFileToFileSystemUrl(Profile* profile, | |
296 const FilePath& full_file_path, | |
297 const std::string& extension_id, | |
298 GURL* url) { | |
299 GURL origin_url = Extension::GetBaseURLFromExtensionId(extension_id); | |
300 FilePath virtual_path; | |
301 if (!ConvertFileToRelativeFileSystemPath(profile, extension_id, | |
302 full_file_path, &virtual_path)) { | |
303 return false; | |
304 } | |
305 | |
306 GURL base_url = fileapi::GetFileSystemRootURI(origin_url, | |
307 fileapi::kFileSystemTypeExternal); | |
308 *url = GURL(base_url.spec() + virtual_path.value()); | |
309 return true; | |
310 } | |
311 | |
312 bool ConvertFileToRelativeFileSystemPath( | |
313 Profile* profile, | |
314 const std::string& extension_id, | |
315 const FilePath& full_file_path, | |
316 FilePath* virtual_path) { | |
317 ExtensionService* service = | |
318 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
319 // May be NULL during unit_tests. | |
320 if (!service) | |
321 return false; | |
322 | |
323 // File browser APIs are ment to be used only from extension context, so the | |
324 // extension's site is the one in whose file system context the virtual path | |
325 // should be found. | |
326 GURL site = service->GetSiteForExtensionId(extension_id); | |
327 fileapi::ExternalFileSystemMountPointProvider* provider = | |
328 BrowserContext::GetStoragePartitionForSite(profile, site)-> | |
329 GetFileSystemContext()->external_provider(); | |
330 if (!provider) | |
331 return false; | |
332 | |
333 // Find if this file path is managed by the external provider. | |
334 if (!provider->GetVirtualPath(full_file_path, virtual_path)) | |
335 return false; | |
336 | |
337 return true; | |
338 } | |
339 | |
340 GURL GetFileBrowserUrlWithParams( | |
341 ui::SelectFileDialog::Type type, | |
342 const string16& title, | |
343 const FilePath& default_virtual_path, | |
344 const ui::SelectFileDialog::FileTypeInfo* file_types, | |
345 int file_type_index, | |
346 const FilePath::StringType& default_extension) { | |
347 DictionaryValue arg_value; | |
348 arg_value.SetString("type", GetDialogTypeAsString(type)); | |
349 arg_value.SetString("title", title); | |
350 arg_value.SetString("defaultPath", default_virtual_path.value()); | |
351 arg_value.SetString("defaultExtension", default_extension); | |
352 | |
353 if (file_types) { | |
354 ListValue* types_list = new ListValue(); | |
355 for (size_t i = 0; i < file_types->extensions.size(); ++i) { | |
356 ListValue* extensions_list = new ListValue(); | |
357 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { | |
358 extensions_list->Append( | |
359 new base::StringValue(file_types->extensions[i][j])); | |
360 } | |
361 | |
362 DictionaryValue* dict = new DictionaryValue(); | |
363 dict->Set("extensions", extensions_list); | |
364 | |
365 if (i < file_types->extension_description_overrides.size()) { | |
366 string16 desc = file_types->extension_description_overrides[i]; | |
367 dict->SetString("description", desc); | |
368 } | |
369 | |
370 // file_type_index is 1-based. 0 means no selection at all. | |
371 dict->SetBoolean("selected", | |
372 (static_cast<size_t>(file_type_index) == (i + 1))); | |
373 | |
374 types_list->Set(i, dict); | |
375 } | |
376 arg_value.Set("typeList", types_list); | |
377 | |
378 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); | |
379 } | |
380 | |
381 // Disable showing GDrive unless it's specifically supported. | |
382 arg_value.SetBoolean("disableGData", | |
383 !file_types || !file_types->support_gdata); | |
384 | |
385 std::string json_args; | |
386 base::JSONWriter::Write(&arg_value, &json_args); | |
387 | |
388 // kChromeUIFileManagerURL could not be used since query parameters are not | |
389 // supported for it. | |
390 std::string url = GetFileBrowserUrl().spec() + | |
391 '?' + net::EscapeUrlEncodedData(json_args, false); | |
392 return GURL(url); | |
393 } | |
394 | |
395 string16 GetTitleFromType(ui::SelectFileDialog::Type dialog_type) { | |
396 string16 title; | |
397 switch (dialog_type) { | |
398 case ui::SelectFileDialog::SELECT_NONE: | |
399 // Full page file manager doesn't need a title. | |
400 break; | |
401 | |
402 case ui::SelectFileDialog::SELECT_FOLDER: | |
403 title = l10n_util::GetStringUTF16( | |
404 IDS_FILE_BROWSER_SELECT_FOLDER_TITLE); | |
405 break; | |
406 | |
407 case ui::SelectFileDialog::SELECT_SAVEAS_FILE: | |
408 title = l10n_util::GetStringUTF16( | |
409 IDS_FILE_BROWSER_SELECT_SAVEAS_FILE_TITLE); | |
410 break; | |
411 | |
412 case ui::SelectFileDialog::SELECT_OPEN_FILE: | |
413 title = l10n_util::GetStringUTF16( | |
414 IDS_FILE_BROWSER_SELECT_OPEN_FILE_TITLE); | |
415 break; | |
416 | |
417 case ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE: | |
418 title = l10n_util::GetStringUTF16( | |
419 IDS_FILE_BROWSER_SELECT_OPEN_MULTI_FILE_TITLE); | |
420 break; | |
421 | |
422 default: | |
423 NOTREACHED(); | |
424 } | |
425 | |
426 return title; | |
427 } | |
428 | |
429 enum TAB_REUSE_MODE { | 294 enum TAB_REUSE_MODE { |
430 REUSE_ANY_FILE_MANAGER, | 295 REUSE_ANY_FILE_MANAGER, |
431 REUSE_SAME_PATH, | 296 REUSE_SAME_PATH, |
432 REUSE_NEVER | 297 REUSE_NEVER |
433 }; | 298 }; |
434 | 299 |
435 bool FileManageTabExists(const FilePath& path, TAB_REUSE_MODE mode) { | 300 bool FileManageTabExists(const FilePath& path, TAB_REUSE_MODE mode) { |
436 if (mode == REUSE_NEVER) | 301 if (mode == REUSE_NEVER) |
437 return false; | 302 return false; |
438 | 303 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 for (int idx = 0; idx < tab_strip->count(); idx++) { | 423 for (int idx = 0; idx < tab_strip->count(); idx++) { |
559 content::WebContents* web_contents = tab_strip->GetWebContentsAt(idx); | 424 content::WebContents* web_contents = tab_strip->GetWebContentsAt(idx); |
560 const GURL& url = web_contents->GetURL(); | 425 const GURL& url = web_contents->GetURL(); |
561 if (url == target_url) | 426 if (url == target_url) |
562 return browser; | 427 return browser; |
563 } | 428 } |
564 } | 429 } |
565 return NULL; | 430 return NULL; |
566 } | 431 } |
567 | 432 |
568 void ViewRemovableDrive(const FilePath& path) { | |
569 OpenFileBrowser(path, REUSE_ANY_FILE_MANAGER, "auto-open"); | |
570 } | |
571 | |
572 void OpenActionChoiceDialog(const FilePath& path) { | |
573 const int kDialogWidth = 394; | |
574 // TODO(dgozman): remove 50, which is a title height once popup window | |
575 // will have no title. | |
576 const int kDialogHeight = 316 + 50; | |
577 | |
578 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
579 | |
580 FilePath virtual_path; | |
581 if (!ConvertFileToRelativeFileSystemPath(profile, kFileBrowserDomain, path, | |
582 &virtual_path)) | |
583 return; | |
584 std::string url = kActionChoiceUrl; | |
585 url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false); | |
586 GURL dialog_url(url); | |
587 | |
588 const gfx::Size screen = ash::Shell::GetScreen()->GetPrimaryDisplay().size(); | |
589 const gfx::Rect bounds((screen.width() - kDialogWidth) / 2, | |
590 (screen.height() - kDialogHeight) / 2, | |
591 kDialogWidth, | |
592 kDialogHeight); | |
593 | |
594 Browser* browser = GetBrowserForUrl(dialog_url); | |
595 | |
596 if (!browser) { | |
597 browser = new Browser( | |
598 Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP, | |
599 "action_choice", | |
600 bounds, | |
601 profile)); | |
602 | |
603 chrome::AddSelectedTabWithURL(browser, dialog_url, | |
604 content::PAGE_TRANSITION_LINK); | |
605 } | |
606 browser->window()->Show(); | |
607 } | |
608 | |
609 void ShowFileInFolder(const FilePath& path) { | |
610 // This action changes the selection so we do not reuse existing tabs. | |
611 OpenFileBrowser(path, REUSE_NEVER, "select"); | |
612 } | |
613 | |
614 void ViewFolder(const FilePath& path) { | |
615 OpenFileBrowser(path, REUSE_SAME_PATH, "open"); | |
616 } | |
617 | |
618 bool ExecuteDefaultHandler(Profile* profile, const FilePath& path) { | 433 bool ExecuteDefaultHandler(Profile* profile, const FilePath& path) { |
619 GURL url; | 434 GURL url; |
620 if (!ConvertFileToFileSystemUrl(profile, path, kFileBrowserDomain, &url)) | 435 if (!ConvertFileToFileSystemUrl(profile, path, kFileBrowserDomain, &url)) |
621 return false; | 436 return false; |
622 | 437 |
623 const FileBrowserHandler* handler; | 438 const FileBrowserHandler* handler; |
624 if (!file_handler_util::GetTaskForURL(profile, url, &handler)) | 439 if (!file_handler_util::GetTaskForURL(profile, url, &handler)) |
625 return false; | 440 return false; |
626 | 441 |
627 std::string extension_id = handler->extension_id(); | 442 std::string extension_id = handler->extension_id(); |
(...skipping 29 matching lines...) Expand all Loading... |
657 OpenFileBrowser(path, REUSE_SAME_PATH, ""); | 472 OpenFileBrowser(path, REUSE_SAME_PATH, ""); |
658 return true; | 473 return true; |
659 } | 474 } |
660 return ExecuteBuiltinHandler(browser, path, action_id); | 475 return ExecuteBuiltinHandler(browser, path, action_id); |
661 } | 476 } |
662 | 477 |
663 ExecuteHandler(profile, extension_id, action_id, url); | 478 ExecuteHandler(profile, extension_id, action_id, url); |
664 return true; | 479 return true; |
665 } | 480 } |
666 | 481 |
667 void ViewFile(const FilePath& path) { | |
668 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); | |
669 if (!ExecuteDefaultHandler(profile, path)) | |
670 ShowWarningMessageBox(profile, path); | |
671 } | |
672 | |
673 // Reads an entire file into a string. Fails is the file is 4K or longer. | 482 // Reads an entire file into a string. Fails is the file is 4K or longer. |
674 bool ReadSmallFileToString(const FilePath& path, std::string* contents) { | 483 bool ReadSmallFileToString(const FilePath& path, std::string* contents) { |
675 FILE* file = file_util::OpenFile(path, "rb"); | 484 FILE* file = file_util::OpenFile(path, "rb"); |
676 if (!file) { | 485 if (!file) { |
677 return false; | 486 return false; |
678 } | 487 } |
679 | 488 |
680 char buf[1 << 12]; // 4K | 489 char buf[1 << 12]; // 4K |
681 size_t len = fread(buf, 1, sizeof(buf), file); | 490 size_t len = fread(buf, 1, sizeof(buf), file); |
682 if (len > 0) { | 491 if (len > 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
706 !root_value->GetAsDictionary(&dictionary_value) || | 515 !root_value->GetAsDictionary(&dictionary_value) || |
707 !dictionary_value->GetString("url", &edit_url_string)) { | 516 !dictionary_value->GetString("url", &edit_url_string)) { |
708 LOG(ERROR) << "Invalid JSON in " << file_path.value(); | 517 LOG(ERROR) << "Invalid JSON in " << file_path.value(); |
709 return; | 518 return; |
710 } | 519 } |
711 | 520 |
712 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 521 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
713 base::Bind(OpenNewTab, GURL(edit_url_string), (Profile*)NULL)); | 522 base::Bind(OpenNewTab, GURL(edit_url_string), (Profile*)NULL)); |
714 } | 523 } |
715 | 524 |
| 525 } // namespace |
| 526 |
| 527 GURL GetFileBrowserExtensionUrl() { |
| 528 return GURL(kFileBrowserExtensionUrl); |
| 529 } |
| 530 |
| 531 GURL GetFileBrowserUrl() { |
| 532 return GURL(kBaseFileBrowserUrl); |
| 533 } |
| 534 |
| 535 GURL GetMediaPlayerUrl() { |
| 536 return GURL(kMediaPlayerUrl); |
| 537 } |
| 538 |
| 539 GURL GetVideoPlayerUrl(const GURL& source_url) { |
| 540 return GURL(kVideoPlayerUrl + std::string("?") + source_url.spec()); |
| 541 } |
| 542 |
| 543 bool ConvertFileToFileSystemUrl(Profile* profile, |
| 544 const FilePath& full_file_path, |
| 545 const std::string& extension_id, |
| 546 GURL* url) { |
| 547 GURL origin_url = Extension::GetBaseURLFromExtensionId(extension_id); |
| 548 FilePath virtual_path; |
| 549 if (!ConvertFileToRelativeFileSystemPath(profile, extension_id, |
| 550 full_file_path, &virtual_path)) { |
| 551 return false; |
| 552 } |
| 553 |
| 554 GURL base_url = fileapi::GetFileSystemRootURI(origin_url, |
| 555 fileapi::kFileSystemTypeExternal); |
| 556 *url = GURL(base_url.spec() + virtual_path.value()); |
| 557 return true; |
| 558 } |
| 559 |
| 560 bool ConvertFileToRelativeFileSystemPath( |
| 561 Profile* profile, |
| 562 const std::string& extension_id, |
| 563 const FilePath& full_file_path, |
| 564 FilePath* virtual_path) { |
| 565 ExtensionService* service = |
| 566 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 567 // May be NULL during unit_tests. |
| 568 if (!service) |
| 569 return false; |
| 570 |
| 571 // File browser APIs are ment to be used only from extension context, so the |
| 572 // extension's site is the one in whose file system context the virtual path |
| 573 // should be found. |
| 574 GURL site = service->GetSiteForExtensionId(extension_id); |
| 575 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 576 BrowserContext::GetStoragePartitionForSite(profile, site)-> |
| 577 GetFileSystemContext()->external_provider(); |
| 578 if (!provider) |
| 579 return false; |
| 580 |
| 581 // Find if this file path is managed by the external provider. |
| 582 if (!provider->GetVirtualPath(full_file_path, virtual_path)) |
| 583 return false; |
| 584 |
| 585 return true; |
| 586 } |
| 587 |
| 588 GURL GetFileBrowserUrlWithParams( |
| 589 ui::SelectFileDialog::Type type, |
| 590 const string16& title, |
| 591 const FilePath& default_virtual_path, |
| 592 const ui::SelectFileDialog::FileTypeInfo* file_types, |
| 593 int file_type_index, |
| 594 const FilePath::StringType& default_extension) { |
| 595 DictionaryValue arg_value; |
| 596 arg_value.SetString("type", GetDialogTypeAsString(type)); |
| 597 arg_value.SetString("title", title); |
| 598 arg_value.SetString("defaultPath", default_virtual_path.value()); |
| 599 arg_value.SetString("defaultExtension", default_extension); |
| 600 |
| 601 if (file_types) { |
| 602 ListValue* types_list = new ListValue(); |
| 603 for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
| 604 ListValue* extensions_list = new ListValue(); |
| 605 for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { |
| 606 extensions_list->Append( |
| 607 new base::StringValue(file_types->extensions[i][j])); |
| 608 } |
| 609 |
| 610 DictionaryValue* dict = new DictionaryValue(); |
| 611 dict->Set("extensions", extensions_list); |
| 612 |
| 613 if (i < file_types->extension_description_overrides.size()) { |
| 614 string16 desc = file_types->extension_description_overrides[i]; |
| 615 dict->SetString("description", desc); |
| 616 } |
| 617 |
| 618 // file_type_index is 1-based. 0 means no selection at all. |
| 619 dict->SetBoolean("selected", |
| 620 (static_cast<size_t>(file_type_index) == (i + 1))); |
| 621 |
| 622 types_list->Set(i, dict); |
| 623 } |
| 624 arg_value.Set("typeList", types_list); |
| 625 |
| 626 arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); |
| 627 } |
| 628 |
| 629 // Disable showing GDrive unless it's specifically supported. |
| 630 arg_value.SetBoolean("disableGData", |
| 631 !file_types || !file_types->support_gdata); |
| 632 |
| 633 std::string json_args; |
| 634 base::JSONWriter::Write(&arg_value, &json_args); |
| 635 |
| 636 // kChromeUIFileManagerURL could not be used since query parameters are not |
| 637 // supported for it. |
| 638 std::string url = GetFileBrowserUrl().spec() + |
| 639 '?' + net::EscapeUrlEncodedData(json_args, false); |
| 640 return GURL(url); |
| 641 } |
| 642 |
| 643 string16 GetTitleFromType(ui::SelectFileDialog::Type dialog_type) { |
| 644 string16 title; |
| 645 switch (dialog_type) { |
| 646 case ui::SelectFileDialog::SELECT_NONE: |
| 647 // Full page file manager doesn't need a title. |
| 648 break; |
| 649 |
| 650 case ui::SelectFileDialog::SELECT_FOLDER: |
| 651 title = l10n_util::GetStringUTF16( |
| 652 IDS_FILE_BROWSER_SELECT_FOLDER_TITLE); |
| 653 break; |
| 654 |
| 655 case ui::SelectFileDialog::SELECT_SAVEAS_FILE: |
| 656 title = l10n_util::GetStringUTF16( |
| 657 IDS_FILE_BROWSER_SELECT_SAVEAS_FILE_TITLE); |
| 658 break; |
| 659 |
| 660 case ui::SelectFileDialog::SELECT_OPEN_FILE: |
| 661 title = l10n_util::GetStringUTF16( |
| 662 IDS_FILE_BROWSER_SELECT_OPEN_FILE_TITLE); |
| 663 break; |
| 664 |
| 665 case ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
| 666 title = l10n_util::GetStringUTF16( |
| 667 IDS_FILE_BROWSER_SELECT_OPEN_MULTI_FILE_TITLE); |
| 668 break; |
| 669 |
| 670 default: |
| 671 NOTREACHED(); |
| 672 } |
| 673 |
| 674 return title; |
| 675 } |
| 676 |
| 677 void ViewRemovableDrive(const FilePath& path) { |
| 678 OpenFileBrowser(path, REUSE_ANY_FILE_MANAGER, "auto-open"); |
| 679 } |
| 680 |
| 681 void OpenActionChoiceDialog(const FilePath& path) { |
| 682 const int kDialogWidth = 394; |
| 683 // TODO(dgozman): remove 50, which is a title height once popup window |
| 684 // will have no title. |
| 685 const int kDialogHeight = 316 + 50; |
| 686 |
| 687 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 688 |
| 689 FilePath virtual_path; |
| 690 if (!ConvertFileToRelativeFileSystemPath(profile, kFileBrowserDomain, path, |
| 691 &virtual_path)) |
| 692 return; |
| 693 std::string url = kActionChoiceUrl; |
| 694 url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false); |
| 695 GURL dialog_url(url); |
| 696 |
| 697 const gfx::Size screen = ash::Shell::GetScreen()->GetPrimaryDisplay().size(); |
| 698 const gfx::Rect bounds((screen.width() - kDialogWidth) / 2, |
| 699 (screen.height() - kDialogHeight) / 2, |
| 700 kDialogWidth, |
| 701 kDialogHeight); |
| 702 |
| 703 Browser* browser = GetBrowserForUrl(dialog_url); |
| 704 |
| 705 if (!browser) { |
| 706 browser = new Browser( |
| 707 Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP, |
| 708 "action_choice", |
| 709 bounds, |
| 710 profile)); |
| 711 |
| 712 chrome::AddSelectedTabWithURL(browser, dialog_url, |
| 713 content::PAGE_TRANSITION_LINK); |
| 714 } |
| 715 browser->window()->Show(); |
| 716 } |
| 717 |
| 718 void ViewFolder(const FilePath& path) { |
| 719 OpenFileBrowser(path, REUSE_SAME_PATH, "open"); |
| 720 } |
| 721 |
| 722 void ViewFile(const FilePath& path) { |
| 723 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 724 if (!ExecuteDefaultHandler(profile, path)) |
| 725 ShowWarningMessageBox(profile, path); |
| 726 } |
| 727 |
| 728 void ShowFileInFolder(const FilePath& path) { |
| 729 // This action changes the selection so we do not reuse existing tabs. |
| 730 OpenFileBrowser(path, REUSE_NEVER, "select"); |
| 731 } |
| 732 |
716 bool ExecuteBuiltinHandler(Browser* browser, const FilePath& path, | 733 bool ExecuteBuiltinHandler(Browser* browser, const FilePath& path, |
717 const std::string& internal_task_id) { | 734 const std::string& internal_task_id) { |
718 | 735 |
719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
720 | 737 |
721 Profile* profile = browser->profile(); | 738 Profile* profile = browser->profile(); |
722 std::string file_extension = path.Extension(); | 739 std::string file_extension = path.Extension(); |
723 // For things supported natively by the browser, we should open it | 740 // For things supported natively by the browser, we should open it |
724 // in a tab. | 741 // in a tab. |
725 if (IsSupportedBrowserExtension(file_extension.data()) || | 742 if (IsSupportedBrowserExtension(file_extension.data()) || |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // Unknown file type. Record UMA and show an error message. | 834 // Unknown file type. Record UMA and show an error message. |
818 size_t extension_index = UMAExtensionIndex(file_extension.data(), | 835 size_t extension_index = UMAExtensionIndex(file_extension.data(), |
819 kUMATrackingExtensions, | 836 kUMATrackingExtensions, |
820 arraysize(kUMATrackingExtensions)); | 837 arraysize(kUMATrackingExtensions)); |
821 UMA_HISTOGRAM_ENUMERATION("FileBrowser.OpeningFileType", | 838 UMA_HISTOGRAM_ENUMERATION("FileBrowser.OpeningFileType", |
822 extension_index, | 839 extension_index, |
823 arraysize(kUMATrackingExtensions) - 1); | 840 arraysize(kUMATrackingExtensions) - 1); |
824 return false; | 841 return false; |
825 } | 842 } |
826 | 843 |
827 void InstallCRX(Browser* browser, const FilePath& path) { | |
828 ExtensionService* service = | |
829 extensions::ExtensionSystem::Get(browser->profile())->extension_service(); | |
830 CHECK(service); | |
831 | |
832 content::WebContents* web_contents = | |
833 browser->tab_strip_model()->GetActiveWebContents(); | |
834 scoped_refptr<extensions::CrxInstaller> installer( | |
835 extensions::CrxInstaller::Create( | |
836 service, | |
837 new ExtensionInstallPrompt(web_contents))); | |
838 installer->set_error_on_unsupported_requirements(true); | |
839 installer->set_is_gallery_install(false); | |
840 installer->set_allow_silent_install(false); | |
841 installer->InstallCrx(path); | |
842 } | |
843 | |
844 // If pdf plugin is enabled, we should open pdf files in a tab. | 844 // If pdf plugin is enabled, we should open pdf files in a tab. |
845 bool ShouldBeOpenedWithPdfPlugin(Profile* profile, const char* file_extension) { | 845 bool ShouldBeOpenedWithPdfPlugin(Profile* profile, const char* file_extension) { |
846 if (base::strcasecmp(file_extension, kPdfExtension) != 0) | 846 if (base::strcasecmp(file_extension, kPdfExtension) != 0) |
847 return false; | 847 return false; |
848 | 848 |
849 FilePath pdf_path; | 849 FilePath pdf_path; |
850 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 850 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
851 | 851 |
852 content::PepperPluginInfo* pepper_info = | 852 content::PepperPluginInfo* pepper_info = |
853 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(pdf_path); | 853 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(pdf_path); |
(...skipping 15 matching lines...) Expand all Loading... |
869 for (google_apis::OperationProgressStatusList::const_iterator iter = | 869 for (google_apis::OperationProgressStatusList::const_iterator iter = |
870 list.begin(); | 870 list.begin(); |
871 iter != list.end(); ++iter) { | 871 iter != list.end(); ++iter) { |
872 result_list->Append( | 872 result_list->Append( |
873 ProgessStatusToDictionaryValue(profile, extension_id, *iter)); | 873 ProgessStatusToDictionaryValue(profile, extension_id, *iter)); |
874 } | 874 } |
875 return result_list.release(); | 875 return result_list.release(); |
876 } | 876 } |
877 | 877 |
878 } // namespace file_manager_util | 878 } // namespace file_manager_util |
OLD | NEW |