OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/private_api_misc.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/frame/frame_util.h" | 10 #include "ash/frame/frame_util.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
17 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 18 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
18 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 19 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
19 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 20 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
20 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" | 21 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" |
21 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 22 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
(...skipping 23 matching lines...) Expand all Loading... |
45 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
46 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
47 #include "content/public/common/page_zoom.h" | 48 #include "content/public/common/page_zoom.h" |
48 #include "extensions/browser/app_window/app_window.h" | 49 #include "extensions/browser/app_window/app_window.h" |
49 #include "extensions/browser/app_window/app_window_registry.h" | 50 #include "extensions/browser/app_window/app_window_registry.h" |
50 #include "google_apis/drive/auth_service.h" | 51 #include "google_apis/drive/auth_service.h" |
51 #include "ui/base/webui/web_ui_util.h" | 52 #include "ui/base/webui/web_ui_util.h" |
52 #include "url/gurl.h" | 53 #include "url/gurl.h" |
53 | 54 |
54 namespace extensions { | 55 namespace extensions { |
| 56 namespace { |
55 | 57 |
56 namespace { | |
57 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore"; | 58 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore"; |
58 | 59 |
59 // Obtains the current app window. | 60 // Obtains the current app window. |
60 AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) { | 61 AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) { |
61 content::WebContents* const contents = function->GetSenderWebContents(); | 62 content::WebContents* const contents = function->GetSenderWebContents(); |
62 return contents ? | 63 return contents ? |
63 AppWindowRegistry::Get(function->GetProfile())-> | 64 AppWindowRegistry::Get(function->GetProfile())-> |
64 GetAppWindowForWebContents(contents) : nullptr; | 65 GetAppWindowForWebContents(contents) : nullptr; |
65 } | 66 } |
66 | 67 |
(...skipping 23 matching lines...) Expand all Loading... |
90 profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile); | 91 profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile); |
91 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName()); | 92 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName()); |
92 // TODO(hirono): Remove the property from the profile_info. | 93 // TODO(hirono): Remove the property from the profile_info. |
93 profile_info->is_current_profile = true; | 94 profile_info->is_current_profile = true; |
94 | 95 |
95 result_profiles.push_back(profile_info); | 96 result_profiles.push_back(profile_info); |
96 } | 97 } |
97 | 98 |
98 return result_profiles; | 99 return result_profiles; |
99 } | 100 } |
| 101 |
| 102 // Converts a list of file system urls (as strings) to a pair of a provided file |
| 103 // system object and a list of unique paths on the file system. In case of an |
| 104 // error, false is returned and the error message set. |
| 105 bool ConvertURLsToProvidedInfo( |
| 106 const scoped_refptr<storage::FileSystemContext>& file_system_context, |
| 107 const std::vector<std::string>& urls, |
| 108 chromeos::file_system_provider::ProvidedFileSystemInterface** file_system, |
| 109 std::vector<base::FilePath>* paths, |
| 110 std::string* error) { |
| 111 DCHECK(file_system); |
| 112 DCHECK(error); |
| 113 |
| 114 if (!urls.size()) { |
| 115 *error = "At least one file must be specified."; |
| 116 return false; |
| 117 } |
| 118 |
| 119 *file_system = nullptr; |
| 120 for (const auto url : urls) { |
| 121 const storage::FileSystemURL file_system_url( |
| 122 file_system_context->CrackURL(GURL(url))); |
| 123 |
| 124 chromeos::file_system_provider::util::FileSystemURLParser parser( |
| 125 file_system_url); |
| 126 if (!parser.Parse()) { |
| 127 *error = "Related provided file system not found."; |
| 128 return false; |
| 129 } |
| 130 |
| 131 if (*file_system != nullptr) { |
| 132 if (*file_system != parser.file_system()) { |
| 133 *error = "All entries must be on the same file system."; |
| 134 return false; |
| 135 } |
| 136 } else { |
| 137 *file_system = parser.file_system(); |
| 138 } |
| 139 paths->push_back(parser.file_path()); |
| 140 } |
| 141 |
| 142 // Erase duplicates. |
| 143 std::sort(paths->begin(), paths->end()); |
| 144 paths->erase(std::unique(paths->begin(), paths->end()), paths->end()); |
| 145 |
| 146 return true; |
| 147 } |
| 148 |
100 } // namespace | 149 } // namespace |
101 | 150 |
102 bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { | 151 bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { |
103 const user_manager::User* user = | 152 const user_manager::User* user = |
104 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); | 153 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); |
105 if (user) { | 154 if (user) { |
106 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 155 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
107 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); | 156 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); |
108 } | 157 } |
109 | 158 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 void FileManagerPrivateConfigureVolumeFunction::OnCompleted( | 579 void FileManagerPrivateConfigureVolumeFunction::OnCompleted( |
531 base::File::Error result) { | 580 base::File::Error result) { |
532 if (result != base::File::FILE_OK) { | 581 if (result != base::File::FILE_OK) { |
533 Respond(Error("Failed to complete configuration.")); | 582 Respond(Error("Failed to complete configuration.")); |
534 return; | 583 return; |
535 } | 584 } |
536 | 585 |
537 Respond(NoArguments()); | 586 Respond(NoArguments()); |
538 } | 587 } |
539 | 588 |
540 FileManagerPrivateInternalGetEntryActionsFunction:: | 589 FileManagerPrivateInternalGetCustomActionsFunction:: |
541 FileManagerPrivateInternalGetEntryActionsFunction() | 590 FileManagerPrivateInternalGetCustomActionsFunction() |
542 : chrome_details_(this) { | 591 : chrome_details_(this) {} |
543 } | |
544 | 592 |
545 ExtensionFunction::ResponseAction | 593 ExtensionFunction::ResponseAction |
546 FileManagerPrivateInternalGetEntryActionsFunction::Run() { | 594 FileManagerPrivateInternalGetCustomActionsFunction::Run() { |
547 using extensions::api::file_manager_private_internal::GetEntryActions::Params; | 595 using extensions::api::file_manager_private_internal::GetCustomActions:: |
| 596 Params; |
548 const scoped_ptr<Params> params(Params::Create(*args_)); | 597 const scoped_ptr<Params> params(Params::Create(*args_)); |
549 EXTENSION_FUNCTION_VALIDATE(params); | 598 EXTENSION_FUNCTION_VALIDATE(params); |
550 | 599 |
551 const scoped_refptr<storage::FileSystemContext> file_system_context = | 600 const scoped_refptr<storage::FileSystemContext> file_system_context = |
552 file_manager::util::GetFileSystemContextForRenderFrameHost( | 601 file_manager::util::GetFileSystemContextForRenderFrameHost( |
553 chrome_details_.GetProfile(), render_frame_host()); | 602 chrome_details_.GetProfile(), render_frame_host()); |
554 | 603 |
555 const storage::FileSystemURL file_system_url( | 604 std::vector<base::FilePath> paths; |
556 file_system_context->CrackURL(GURL(params->url))); | 605 chromeos::file_system_provider::ProvidedFileSystemInterface* file_system = |
| 606 nullptr; |
| 607 std::string error; |
557 | 608 |
558 chromeos::file_system_provider::util::FileSystemURLParser parser( | 609 if (!ConvertURLsToProvidedInfo(file_system_context, params->urls, |
559 file_system_url); | 610 &file_system, &paths, &error)) { |
560 if (!parser.Parse()) | 611 return RespondNow(Error(error)); |
561 return RespondNow(Error("Related provided file system not found.")); | 612 } |
562 | 613 |
563 parser.file_system()->GetActions( | 614 DCHECK(file_system); |
564 parser.file_path(), | 615 file_system->GetActions( |
| 616 paths, |
565 base::Bind( | 617 base::Bind( |
566 &FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted, | 618 &FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted, |
567 this)); | 619 this)); |
568 return RespondLater(); | 620 return RespondLater(); |
569 } | 621 } |
570 | 622 |
571 void FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted( | 623 void FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted( |
572 const chromeos::file_system_provider::Actions& actions, | 624 const chromeos::file_system_provider::Actions& actions, |
573 base::File::Error result) { | 625 base::File::Error result) { |
574 if (result != base::File::FILE_OK) { | 626 if (result != base::File::FILE_OK) { |
575 Respond(Error("Failed to fetch actions.")); | 627 Respond(Error("Failed to fetch actions.")); |
576 return; | 628 return; |
577 } | 629 } |
578 | 630 |
579 using api::file_system_provider::Action; | 631 using api::file_system_provider::Action; |
580 std::vector<linked_ptr<Action>> items; | 632 std::vector<linked_ptr<Action>> items; |
581 for (const auto& action : actions) { | 633 for (const auto& action : actions) { |
582 const linked_ptr<Action> item(new Action); | 634 const linked_ptr<Action> item(new Action); |
583 item->id = action.id; | 635 item->id = action.id; |
584 item->title.reset(new std::string(action.title)); | 636 item->title.reset(new std::string(action.title)); |
585 items.push_back(item); | 637 items.push_back(item); |
586 } | 638 } |
587 | 639 |
588 Respond(ArgumentList( | 640 Respond(ArgumentList( |
589 api::file_manager_private_internal::GetEntryActions::Results::Create( | 641 api::file_manager_private_internal::GetCustomActions::Results::Create( |
590 items))); | 642 items))); |
591 } | 643 } |
592 | 644 |
593 FileManagerPrivateInternalExecuteEntryActionFunction:: | 645 FileManagerPrivateInternalExecuteCustomActionFunction:: |
594 FileManagerPrivateInternalExecuteEntryActionFunction() | 646 FileManagerPrivateInternalExecuteCustomActionFunction() |
595 : chrome_details_(this) { | 647 : chrome_details_(this) {} |
596 } | |
597 | 648 |
598 ExtensionFunction::ResponseAction | 649 ExtensionFunction::ResponseAction |
599 FileManagerPrivateInternalExecuteEntryActionFunction::Run() { | 650 FileManagerPrivateInternalExecuteCustomActionFunction::Run() { |
600 using extensions::api::file_manager_private_internal::ExecuteEntryAction:: | 651 using extensions::api::file_manager_private_internal::ExecuteCustomAction:: |
601 Params; | 652 Params; |
602 const scoped_ptr<Params> params(Params::Create(*args_)); | 653 const scoped_ptr<Params> params(Params::Create(*args_)); |
603 EXTENSION_FUNCTION_VALIDATE(params); | 654 EXTENSION_FUNCTION_VALIDATE(params); |
604 | 655 |
605 const scoped_refptr<storage::FileSystemContext> file_system_context = | 656 const scoped_refptr<storage::FileSystemContext> file_system_context = |
606 file_manager::util::GetFileSystemContextForRenderFrameHost( | 657 file_manager::util::GetFileSystemContextForRenderFrameHost( |
607 chrome_details_.GetProfile(), render_frame_host()); | 658 chrome_details_.GetProfile(), render_frame_host()); |
608 | 659 |
609 const storage::FileSystemURL file_system_url( | 660 std::vector<base::FilePath> paths; |
610 file_system_context->CrackURL(GURL(params->url))); | 661 chromeos::file_system_provider::ProvidedFileSystemInterface* file_system = |
| 662 nullptr; |
| 663 std::string error; |
611 | 664 |
612 chromeos::file_system_provider::util::FileSystemURLParser parser( | 665 if (!ConvertURLsToProvidedInfo(file_system_context, params->urls, |
613 file_system_url); | 666 &file_system, &paths, &error)) { |
614 if (!parser.Parse()) | 667 return RespondNow(Error(error)); |
615 return RespondNow(Error("Related provided file system not found.")); | 668 } |
616 | 669 |
617 parser.file_system()->ExecuteAction( | 670 DCHECK(file_system); |
618 parser.file_path(), params->action_id, | 671 file_system->ExecuteAction( |
| 672 paths, params->action_id, |
619 base::Bind( | 673 base::Bind( |
620 &FileManagerPrivateInternalExecuteEntryActionFunction::OnCompleted, | 674 &FileManagerPrivateInternalExecuteCustomActionFunction::OnCompleted, |
621 this)); | 675 this)); |
622 return RespondLater(); | 676 return RespondLater(); |
623 } | 677 } |
624 | 678 |
625 void FileManagerPrivateInternalExecuteEntryActionFunction::OnCompleted( | 679 void FileManagerPrivateInternalExecuteCustomActionFunction::OnCompleted( |
626 base::File::Error result) { | 680 base::File::Error result) { |
627 if (result != base::File::FILE_OK) { | 681 if (result != base::File::FILE_OK) { |
628 Respond(Error("Failed to execute the action.")); | 682 Respond(Error("Failed to execute the action.")); |
629 return; | 683 return; |
630 } | 684 } |
631 | 685 |
632 Respond(NoArguments()); | 686 Respond(NoArguments()); |
633 } | 687 } |
634 | 688 |
635 } // namespace extensions | 689 } // namespace extensions |
OLD | NEW |