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. | |
fukino
2015/09/17 05:23:04
Is it guaranteed that paths are sorted?
If not, pl
mtomasz
2015/09/17 06:12:40
Oh, I didn't know about it. Done.
| |
143 paths->erase(std::unique(paths->begin(), paths->end()), paths->end()); | |
144 return true; | |
145 } | |
146 | |
100 } // namespace | 147 } // namespace |
101 | 148 |
102 bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { | 149 bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { |
103 const user_manager::User* user = | 150 const user_manager::User* user = |
104 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); | 151 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); |
105 if (user) { | 152 if (user) { |
106 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 153 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
107 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); | 154 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); |
108 } | 155 } |
109 | 156 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 void FileManagerPrivateConfigureVolumeFunction::OnCompleted( | 577 void FileManagerPrivateConfigureVolumeFunction::OnCompleted( |
531 base::File::Error result) { | 578 base::File::Error result) { |
532 if (result != base::File::FILE_OK) { | 579 if (result != base::File::FILE_OK) { |
533 Respond(Error("Failed to complete configuration.")); | 580 Respond(Error("Failed to complete configuration.")); |
534 return; | 581 return; |
535 } | 582 } |
536 | 583 |
537 Respond(NoArguments()); | 584 Respond(NoArguments()); |
538 } | 585 } |
539 | 586 |
540 FileManagerPrivateInternalGetEntryActionsFunction:: | 587 FileManagerPrivateInternalGetCustomActionsFunction:: |
541 FileManagerPrivateInternalGetEntryActionsFunction() | 588 FileManagerPrivateInternalGetCustomActionsFunction() |
542 : chrome_details_(this) { | 589 : chrome_details_(this) {} |
543 } | |
544 | 590 |
545 ExtensionFunction::ResponseAction | 591 ExtensionFunction::ResponseAction |
546 FileManagerPrivateInternalGetEntryActionsFunction::Run() { | 592 FileManagerPrivateInternalGetCustomActionsFunction::Run() { |
547 using extensions::api::file_manager_private_internal::GetEntryActions::Params; | 593 using extensions::api::file_manager_private_internal::GetCustomActions:: |
594 Params; | |
548 const scoped_ptr<Params> params(Params::Create(*args_)); | 595 const scoped_ptr<Params> params(Params::Create(*args_)); |
549 EXTENSION_FUNCTION_VALIDATE(params); | 596 EXTENSION_FUNCTION_VALIDATE(params); |
550 | 597 |
551 const scoped_refptr<storage::FileSystemContext> file_system_context = | 598 const scoped_refptr<storage::FileSystemContext> file_system_context = |
552 file_manager::util::GetFileSystemContextForRenderFrameHost( | 599 file_manager::util::GetFileSystemContextForRenderFrameHost( |
553 chrome_details_.GetProfile(), render_frame_host()); | 600 chrome_details_.GetProfile(), render_frame_host()); |
554 | 601 |
555 const storage::FileSystemURL file_system_url( | 602 std::vector<base::FilePath> paths; |
556 file_system_context->CrackURL(GURL(params->url))); | 603 chromeos::file_system_provider::ProvidedFileSystemInterface* file_system = |
604 nullptr; | |
605 std::string error; | |
557 | 606 |
558 chromeos::file_system_provider::util::FileSystemURLParser parser( | 607 if (!ConvertURLsToProvidedInfo(file_system_context, params->urls, |
559 file_system_url); | 608 &file_system, &paths, &error)) { |
560 if (!parser.Parse()) | 609 return RespondNow(Error(error)); |
561 return RespondNow(Error("Related provided file system not found.")); | 610 } |
562 | 611 |
563 parser.file_system()->GetActions( | 612 DCHECK(file_system); |
564 parser.file_path(), | 613 file_system->GetActions( |
614 paths, | |
565 base::Bind( | 615 base::Bind( |
566 &FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted, | 616 &FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted, |
567 this)); | 617 this)); |
568 return RespondLater(); | 618 return RespondLater(); |
569 } | 619 } |
570 | 620 |
571 void FileManagerPrivateInternalGetEntryActionsFunction::OnCompleted( | 621 void FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted( |
572 const chromeos::file_system_provider::Actions& actions, | 622 const chromeos::file_system_provider::Actions& actions, |
573 base::File::Error result) { | 623 base::File::Error result) { |
574 if (result != base::File::FILE_OK) { | 624 if (result != base::File::FILE_OK) { |
575 Respond(Error("Failed to fetch actions.")); | 625 Respond(Error("Failed to fetch actions.")); |
576 return; | 626 return; |
577 } | 627 } |
578 | 628 |
579 using api::file_system_provider::Action; | 629 using api::file_system_provider::Action; |
580 std::vector<linked_ptr<Action>> items; | 630 std::vector<linked_ptr<Action>> items; |
581 for (const auto& action : actions) { | 631 for (const auto& action : actions) { |
582 const linked_ptr<Action> item(new Action); | 632 const linked_ptr<Action> item(new Action); |
583 item->id = action.id; | 633 item->id = action.id; |
584 item->title.reset(new std::string(action.title)); | 634 item->title.reset(new std::string(action.title)); |
585 items.push_back(item); | 635 items.push_back(item); |
586 } | 636 } |
587 | 637 |
588 Respond(ArgumentList( | 638 Respond(ArgumentList( |
589 api::file_manager_private_internal::GetEntryActions::Results::Create( | 639 api::file_manager_private_internal::GetCustomActions::Results::Create( |
590 items))); | 640 items))); |
591 } | 641 } |
592 | 642 |
593 FileManagerPrivateInternalExecuteEntryActionFunction:: | 643 FileManagerPrivateInternalExecuteCustomActionFunction:: |
594 FileManagerPrivateInternalExecuteEntryActionFunction() | 644 FileManagerPrivateInternalExecuteCustomActionFunction() |
595 : chrome_details_(this) { | 645 : chrome_details_(this) {} |
596 } | |
597 | 646 |
598 ExtensionFunction::ResponseAction | 647 ExtensionFunction::ResponseAction |
599 FileManagerPrivateInternalExecuteEntryActionFunction::Run() { | 648 FileManagerPrivateInternalExecuteCustomActionFunction::Run() { |
600 using extensions::api::file_manager_private_internal::ExecuteEntryAction:: | 649 using extensions::api::file_manager_private_internal::ExecuteCustomAction:: |
601 Params; | 650 Params; |
602 const scoped_ptr<Params> params(Params::Create(*args_)); | 651 const scoped_ptr<Params> params(Params::Create(*args_)); |
603 EXTENSION_FUNCTION_VALIDATE(params); | 652 EXTENSION_FUNCTION_VALIDATE(params); |
604 | 653 |
605 const scoped_refptr<storage::FileSystemContext> file_system_context = | 654 const scoped_refptr<storage::FileSystemContext> file_system_context = |
606 file_manager::util::GetFileSystemContextForRenderFrameHost( | 655 file_manager::util::GetFileSystemContextForRenderFrameHost( |
607 chrome_details_.GetProfile(), render_frame_host()); | 656 chrome_details_.GetProfile(), render_frame_host()); |
608 | 657 |
609 const storage::FileSystemURL file_system_url( | 658 std::vector<base::FilePath> paths; |
610 file_system_context->CrackURL(GURL(params->url))); | 659 chromeos::file_system_provider::ProvidedFileSystemInterface* file_system = |
660 nullptr; | |
661 std::string error; | |
611 | 662 |
612 chromeos::file_system_provider::util::FileSystemURLParser parser( | 663 if (!ConvertURLsToProvidedInfo(file_system_context, params->urls, |
613 file_system_url); | 664 &file_system, &paths, &error)) { |
614 if (!parser.Parse()) | 665 return RespondNow(Error(error)); |
615 return RespondNow(Error("Related provided file system not found.")); | 666 } |
616 | 667 |
617 parser.file_system()->ExecuteAction( | 668 DCHECK(file_system); |
618 parser.file_path(), params->action_id, | 669 file_system->ExecuteAction( |
670 paths, params->action_id, | |
619 base::Bind( | 671 base::Bind( |
620 &FileManagerPrivateInternalExecuteEntryActionFunction::OnCompleted, | 672 &FileManagerPrivateInternalExecuteCustomActionFunction::OnCompleted, |
621 this)); | 673 this)); |
622 return RespondLater(); | 674 return RespondLater(); |
623 } | 675 } |
624 | 676 |
625 void FileManagerPrivateInternalExecuteEntryActionFunction::OnCompleted( | 677 void FileManagerPrivateInternalExecuteCustomActionFunction::OnCompleted( |
626 base::File::Error result) { | 678 base::File::Error result) { |
627 if (result != base::File::FILE_OK) { | 679 if (result != base::File::FILE_OK) { |
628 Respond(Error("Failed to execute the action.")); | 680 Respond(Error("Failed to execute the action.")); |
629 return; | 681 return; |
630 } | 682 } |
631 | 683 |
632 Respond(NoArguments()); | 684 Respond(NoArguments()); |
633 } | 685 } |
634 | 686 |
635 } // namespace extensions | 687 } // namespace extensions |
OLD | NEW |