Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / extensions / file_manager / private_api_misc.cc
index 5540993..a2e96df 100644 (file)
@@ -4,8 +4,6 @@
 
 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h"
 
-#include "apps/app_window.h"
-#include "apps/app_window_registry.h"
 #include "ash/frame/frame_util.h"
 #include "base/files/file_path.h"
 #include "base/prefs/pref_service.h"
@@ -13,8 +11,6 @@
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/browser/browser_process.h"
 #include "chrome/browser/chromeos/drive/file_system_util.h"
-#include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
-#include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h"
 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
 #include "chrome/browser/chromeos/file_manager/app_installer.h"
 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h"
@@ -31,7 +27,7 @@
 #include "chrome/browser/signin/signin_manager_factory.h"
 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
-#include "chrome/common/extensions/api/file_browser_private.h"
+#include "chrome/common/extensions/api/file_manager_private.h"
 #include "chrome/common/pref_names.h"
 #include "components/signin/core/browser/profile_oauth2_token_service.h"
 #include "components/signin/core/browser/signin_manager.h"
@@ -39,6 +35,8 @@
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/web_contents.h"
 #include "content/public/common/page_zoom.h"
+#include "extensions/browser/app_window/app_window.h"
+#include "extensions/browser/app_window/app_window_registry.h"
 #include "google_apis/drive/auth_service.h"
 #include "ui/base/webui/web_ui_util.h"
 #include "url/gurl.h"
@@ -50,9 +48,9 @@ const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore";
 const char kGoogleCastApiExtensionId[] = "mafeflapfdfljijmlienjedomfjfmhpd";
 
 // Obtains the current app window.
-apps::AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) {
-  apps::AppWindowRegistry* const app_window_registry =
-      apps::AppWindowRegistry::Get(function->GetProfile());
+AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) {
+  AppWindowRegistry* const app_window_registry =
+      AppWindowRegistry::Get(function->GetProfile());
   content::WebContents* const contents = function->GetAssociatedWebContents();
   content::RenderViewHost* const render_view_host =
       contents ? contents->GetRenderViewHost() : NULL;
@@ -61,13 +59,13 @@ apps::AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) {
                           : NULL;
 }
 
-std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >
+std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >
 GetLoggedInProfileInfoList() {
   DCHECK(user_manager::UserManager::IsInitialized());
   const std::vector<Profile*>& profiles =
       g_browser_process->profile_manager()->GetLoadedProfiles();
   std::set<Profile*> original_profiles;
-  std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >
+  std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >
       result_profiles;
 
   for (size_t i = 0; i < profiles.size(); ++i) {
@@ -82,8 +80,8 @@ GetLoggedInProfileInfoList() {
       continue;
 
     // Make a ProfileInfo.
-    linked_ptr<api::file_browser_private::ProfileInfo> profile_info(
-        new api::file_browser_private::ProfileInfo());
+    linked_ptr<api::file_manager_private::ProfileInfo> profile_info(
+        new api::file_manager_private::ProfileInfo());
     profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile);
     profile_info->display_name = UTF16ToUTF8(user->GetDisplayName());
     // TODO(hirono): Remove the property from the profile_info.
@@ -96,7 +94,7 @@ GetLoggedInProfileInfoList() {
 }
 } // namespace
 
-bool FileBrowserPrivateLogoutUserForReauthenticationFunction::RunSync() {
+bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() {
   user_manager::User* user =
       chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile());
   if (user) {
@@ -108,8 +106,8 @@ bool FileBrowserPrivateLogoutUserForReauthenticationFunction::RunSync() {
   return true;
 }
 
-bool FileBrowserPrivateGetPreferencesFunction::RunSync() {
-  api::file_browser_private::Preferences result;
+bool FileManagerPrivateGetPreferencesFunction::RunSync() {
+  api::file_manager_private::Preferences result;
   const PrefService* const service = GetProfile()->GetPrefs();
 
   result.drive_enabled = drive::util::IsDriveEnabledForProfile(GetProfile());
@@ -133,8 +131,8 @@ bool FileBrowserPrivateGetPreferencesFunction::RunSync() {
   return true;
 }
 
-bool FileBrowserPrivateSetPreferencesFunction::RunSync() {
-  using extensions::api::file_browser_private::SetPreferences::Params;
+bool FileManagerPrivateSetPreferencesFunction::RunSync() {
+  using extensions::api::file_manager_private::SetPreferences::Params;
   const scoped_ptr<Params> params(Params::Create(*args_));
   EXTENSION_FUNCTION_VALIDATE(params);
 
@@ -154,14 +152,14 @@ bool FileBrowserPrivateSetPreferencesFunction::RunSync() {
   return true;
 }
 
-FileBrowserPrivateZipSelectionFunction::
-    FileBrowserPrivateZipSelectionFunction() {}
+FileManagerPrivateZipSelectionFunction::
+    FileManagerPrivateZipSelectionFunction() {}
 
-FileBrowserPrivateZipSelectionFunction::
-    ~FileBrowserPrivateZipSelectionFunction() {}
+FileManagerPrivateZipSelectionFunction::
+    ~FileManagerPrivateZipSelectionFunction() {}
 
-bool FileBrowserPrivateZipSelectionFunction::RunAsync() {
-  using extensions::api::file_browser_private::ZipSelection::Params;
+bool FileManagerPrivateZipSelectionFunction::RunAsync() {
+  using extensions::api::file_manager_private::ZipSelection::Params;
   const scoped_ptr<Params> params(Params::Create(*args_));
   EXTENSION_FUNCTION_VALIDATE(params);
 
@@ -209,32 +207,32 @@ bool FileBrowserPrivateZipSelectionFunction::RunAsync() {
   }
 
   (new file_manager::ZipFileCreator(
-       base::Bind(&FileBrowserPrivateZipSelectionFunction::OnZipDone, this),
+       base::Bind(&FileManagerPrivateZipSelectionFunction::OnZipDone, this),
        src_dir,
        src_relative_paths,
        dest_file))->Start();
   return true;
 }
 
-void FileBrowserPrivateZipSelectionFunction::OnZipDone(bool success) {
+void FileManagerPrivateZipSelectionFunction::OnZipDone(bool success) {
   SetResult(new base::FundamentalValue(success));
   SendResponse(true);
 }
 
-bool FileBrowserPrivateZoomFunction::RunSync() {
-  using extensions::api::file_browser_private::Zoom::Params;
+bool FileManagerPrivateZoomFunction::RunSync() {
+  using extensions::api::file_manager_private::Zoom::Params;
   const scoped_ptr<Params> params(Params::Create(*args_));
   EXTENSION_FUNCTION_VALIDATE(params);
 
   content::PageZoom zoom_type;
   switch (params->operation) {
-    case api::file_browser_private::ZOOM_OPERATION_TYPE_IN:
+    case api::file_manager_private::ZOOM_OPERATION_TYPE_IN:
       zoom_type = content::PAGE_ZOOM_IN;
       break;
-    case api::file_browser_private::ZOOM_OPERATION_TYPE_OUT:
+    case api::file_manager_private::ZOOM_OPERATION_TYPE_OUT:
       zoom_type = content::PAGE_ZOOM_OUT;
       break;
-    case api::file_browser_private::ZOOM_OPERATION_TYPE_RESET:
+    case api::file_manager_private::ZOOM_OPERATION_TYPE_RESET:
       zoom_type = content::PAGE_ZOOM_RESET;
       break;
     default:
@@ -245,8 +243,8 @@ bool FileBrowserPrivateZoomFunction::RunSync() {
   return true;
 }
 
-bool FileBrowserPrivateInstallWebstoreItemFunction::RunAsync() {
-  using extensions::api::file_browser_private::InstallWebstoreItem::Params;
+bool FileManagerPrivateInstallWebstoreItemFunction::RunAsync() {
+  using extensions::api::file_manager_private::InstallWebstoreItem::Params;
   const scoped_ptr<Params> params(Params::Create(*args_));
   EXTENSION_FUNCTION_VALIDATE(params);
 
@@ -255,7 +253,7 @@ bool FileBrowserPrivateInstallWebstoreItemFunction::RunAsync() {
 
   const extensions::WebstoreStandaloneInstaller::Callback callback =
       base::Bind(
-          &FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete,
+          &FileManagerPrivateInstallWebstoreItemFunction::OnInstallComplete,
           this);
 
   // Only GoogleCastAPI extension can use silent installation.
@@ -276,7 +274,7 @@ bool FileBrowserPrivateInstallWebstoreItemFunction::RunAsync() {
   return true;
 }
 
-void FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete(
+void FileManagerPrivateInstallWebstoreItemFunction::OnInstallComplete(
     bool success,
     const std::string& error,
     extensions::webstore_install::Result result) {
@@ -300,15 +298,15 @@ void FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete(
   SendResponse(success);
 }
 
-FileBrowserPrivateRequestWebStoreAccessTokenFunction::
-    FileBrowserPrivateRequestWebStoreAccessTokenFunction() {
+FileManagerPrivateRequestWebStoreAccessTokenFunction::
+    FileManagerPrivateRequestWebStoreAccessTokenFunction() {
 }
 
-FileBrowserPrivateRequestWebStoreAccessTokenFunction::
-    ~FileBrowserPrivateRequestWebStoreAccessTokenFunction() {
+FileManagerPrivateRequestWebStoreAccessTokenFunction::
+    ~FileManagerPrivateRequestWebStoreAccessTokenFunction() {
 }
 
-bool FileBrowserPrivateRequestWebStoreAccessTokenFunction::RunAsync() {
+bool FileManagerPrivateRequestWebStoreAccessTokenFunction::RunAsync() {
   std::vector<std::string> scopes;
   scopes.push_back(kCWSScope);
 
@@ -336,14 +334,14 @@ bool FileBrowserPrivateRequestWebStoreAccessTokenFunction::RunAsync() {
       url_request_context_getter,
       scopes));
   auth_service_->StartAuthentication(base::Bind(
-      &FileBrowserPrivateRequestWebStoreAccessTokenFunction::
+      &FileManagerPrivateRequestWebStoreAccessTokenFunction::
           OnAccessTokenFetched,
       this));
 
   return true;
 }
 
-void FileBrowserPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched(
+void FileManagerPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched(
     google_apis::GDataErrorCode code,
     const std::string& access_token) {
   drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
@@ -366,12 +364,17 @@ void FileBrowserPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched(
   }
 }
 
-bool FileBrowserPrivateGetProfilesFunction::RunSync() {
-  const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >&
+bool FileManagerPrivateGetProfilesFunction::RunSync() {
+#if defined(USE_ATHENA)
+  // TODO(oshima): Figure out what to do.
+  return false;
+#endif
+
+  const std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >&
       profiles = GetLoggedInProfileInfoList();
 
   // Obtains the display profile ID.
-  apps::AppWindow* const app_window = GetCurrentAppWindow(this);
+  AppWindow* const app_window = GetCurrentAppWindow(this);
   chrome::MultiUserWindowManager* const window_manager =
       chrome::MultiUserWindowManager::GetInstance();
   const std::string current_profile_id =
@@ -381,17 +384,17 @@ bool FileBrowserPrivateGetProfilesFunction::RunSync() {
                                          app_window->GetNativeWindow())
                                    : "";
 
-  results_ = api::file_browser_private::GetProfiles::Results::Create(
+  results_ = api::file_manager_private::GetProfiles::Results::Create(
       profiles,
       current_profile_id,
       display_profile_id.empty() ? current_profile_id : display_profile_id);
   return true;
 }
 
-bool FileBrowserPrivateVisitDesktopFunction::RunSync() {
-  using api::file_browser_private::VisitDesktop::Params;
+bool FileManagerPrivateVisitDesktopFunction::RunSync() {
+  using api::file_manager_private::VisitDesktop::Params;
   const scoped_ptr<Params> params(Params::Create(*args_));
-  const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >&
+  const std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >&
       profiles = GetLoggedInProfileInfoList();
 
   chrome::MultiUserWindowManager* const window_manager =
@@ -412,17 +415,12 @@ bool FileBrowserPrivateVisitDesktopFunction::RunSync() {
   }
 
   // Look for the current app window.
-  apps::AppWindow* const app_window = GetCurrentAppWindow(this);
+  AppWindow* const app_window = GetCurrentAppWindow(this);
   if (!app_window) {
     SetError("Target window is not found.");
     return false;
   }
 
-  // Observe owner changes of windows.
-  file_manager::EventRouter* const event_router =
-      file_manager::FileBrowserPrivateAPI::Get(GetProfile())->event_router();
-  event_router->RegisterMultiUserWindowManagerObserver();
-
   // Move the window to the user's desktop.
   window_manager->ShowWindowForUser(app_window->GetNativeWindow(),
                                     params->profile_id);
@@ -437,30 +435,30 @@ bool FileBrowserPrivateVisitDesktopFunction::RunSync() {
   return true;
 }
 
-bool FileBrowserPrivateOpenInspectorFunction::RunSync() {
-  using extensions::api::file_browser_private::OpenInspector::Params;
+bool FileManagerPrivateOpenInspectorFunction::RunSync() {
+  using extensions::api::file_manager_private::OpenInspector::Params;
   const scoped_ptr<Params> params(Params::Create(*args_));
   EXTENSION_FUNCTION_VALIDATE(params);
 
   switch (params->type) {
-    case extensions::api::file_browser_private::INSPECTION_TYPE_NORMAL:
+    case extensions::api::file_manager_private::INSPECTION_TYPE_NORMAL:
       // Open inspector for foreground page.
       DevToolsWindow::OpenDevToolsWindow(
           content::WebContents::FromRenderViewHost(render_view_host()));
       break;
-    case extensions::api::file_browser_private::INSPECTION_TYPE_CONSOLE:
+    case extensions::api::file_manager_private::INSPECTION_TYPE_CONSOLE:
       // Open inspector for foreground page and bring focus to the console.
       DevToolsWindow::OpenDevToolsWindow(
           content::WebContents::FromRenderViewHost(render_view_host()),
           DevToolsToggleAction::ShowConsole());
       break;
-    case extensions::api::file_browser_private::INSPECTION_TYPE_ELEMENT:
+    case extensions::api::file_manager_private::INSPECTION_TYPE_ELEMENT:
       // Open inspector for foreground page in inspect element mode.
       DevToolsWindow::OpenDevToolsWindow(
           content::WebContents::FromRenderViewHost(render_view_host()),
           DevToolsToggleAction::Inspect());
       break;
-    case extensions::api::file_browser_private::INSPECTION_TYPE_BACKGROUND:
+    case extensions::api::file_manager_private::INSPECTION_TYPE_BACKGROUND:
       // Open inspector for background page.
       extensions::devtools_util::InspectBackgroundPage(extension(),
                                                        GetProfile());