| 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 "ash/frame/frame_util.h" | 7 #include "ash/frame/frame_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 14 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_a
pi.h" |
| 15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 16 #include "chrome/browser/chromeos/file_manager/app_installer.h" | 16 #include "chrome/browser/chromeos/file_manager/app_installer.h" |
| 17 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" | 17 #include "chrome/browser/chromeos/file_manager/zip_file_creator.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chrome/browser/devtools/devtools_window.h" | 20 #include "chrome/browser/devtools/devtools_window.h" |
| 21 #include "chrome/browser/drive/event_logger.h" | 21 #include "chrome/browser/drive/event_logger.h" |
| 22 #include "chrome/browser/extensions/devtools_util.h" | 22 #include "chrome/browser/extensions/devtools_util.h" |
| 23 #include "chrome/browser/lifetime/application_lifetime.h" | 23 #include "chrome/browser/lifetime/application_lifetime.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/profiles/profile_manager.h" |
| 26 #include "chrome/browser/profiles/profiles_state.h" | 26 #include "chrome/browser/profiles/profiles_state.h" |
| 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 28 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 29 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 29 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 30 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 30 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 31 #include "chrome/common/extensions/api/file_browser_private.h" | 31 #include "chrome/common/extensions/api/file_manager_private.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 33 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 34 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
| 35 #include "components/user_manager/user_manager.h" | 35 #include "components/user_manager/user_manager.h" |
| 36 #include "content/public/browser/render_view_host.h" | 36 #include "content/public/browser/render_view_host.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/common/page_zoom.h" | 38 #include "content/public/common/page_zoom.h" |
| 39 #include "extensions/browser/app_window/app_window.h" | 39 #include "extensions/browser/app_window/app_window.h" |
| 40 #include "extensions/browser/app_window/app_window_registry.h" | 40 #include "extensions/browser/app_window/app_window_registry.h" |
| 41 #include "google_apis/drive/auth_service.h" | 41 #include "google_apis/drive/auth_service.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 AppWindowRegistry* const app_window_registry = | 53 AppWindowRegistry* const app_window_registry = |
| 54 AppWindowRegistry::Get(function->GetProfile()); | 54 AppWindowRegistry::Get(function->GetProfile()); |
| 55 content::WebContents* const contents = function->GetAssociatedWebContents(); | 55 content::WebContents* const contents = function->GetAssociatedWebContents(); |
| 56 content::RenderViewHost* const render_view_host = | 56 content::RenderViewHost* const render_view_host = |
| 57 contents ? contents->GetRenderViewHost() : NULL; | 57 contents ? contents->GetRenderViewHost() : NULL; |
| 58 return render_view_host ? app_window_registry->GetAppWindowForRenderViewHost( | 58 return render_view_host ? app_window_registry->GetAppWindowForRenderViewHost( |
| 59 render_view_host) | 59 render_view_host) |
| 60 : NULL; | 60 : NULL; |
| 61 } | 61 } |
| 62 | 62 |
| 63 std::vector<linked_ptr<api::file_browser_private::ProfileInfo> > | 63 std::vector<linked_ptr<api::file_manager_private::ProfileInfo> > |
| 64 GetLoggedInProfileInfoList() { | 64 GetLoggedInProfileInfoList() { |
| 65 DCHECK(user_manager::UserManager::IsInitialized()); | 65 DCHECK(user_manager::UserManager::IsInitialized()); |
| 66 const std::vector<Profile*>& profiles = | 66 const std::vector<Profile*>& profiles = |
| 67 g_browser_process->profile_manager()->GetLoadedProfiles(); | 67 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 68 std::set<Profile*> original_profiles; | 68 std::set<Profile*> original_profiles; |
| 69 std::vector<linked_ptr<api::file_browser_private::ProfileInfo> > | 69 std::vector<linked_ptr<api::file_manager_private::ProfileInfo> > |
| 70 result_profiles; | 70 result_profiles; |
| 71 | 71 |
| 72 for (size_t i = 0; i < profiles.size(); ++i) { | 72 for (size_t i = 0; i < profiles.size(); ++i) { |
| 73 // Filter the profile. | 73 // Filter the profile. |
| 74 Profile* const profile = profiles[i]->GetOriginalProfile(); | 74 Profile* const profile = profiles[i]->GetOriginalProfile(); |
| 75 if (original_profiles.count(profile)) | 75 if (original_profiles.count(profile)) |
| 76 continue; | 76 continue; |
| 77 original_profiles.insert(profile); | 77 original_profiles.insert(profile); |
| 78 const user_manager::User* const user = | 78 const user_manager::User* const user = |
| 79 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 79 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 80 if (!user || !user->is_logged_in()) | 80 if (!user || !user->is_logged_in()) |
| 81 continue; | 81 continue; |
| 82 | 82 |
| 83 // Make a ProfileInfo. | 83 // Make a ProfileInfo. |
| 84 linked_ptr<api::file_browser_private::ProfileInfo> profile_info( | 84 linked_ptr<api::file_manager_private::ProfileInfo> profile_info( |
| 85 new api::file_browser_private::ProfileInfo()); | 85 new api::file_manager_private::ProfileInfo()); |
| 86 profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile); | 86 profile_info->profile_id = multi_user_util::GetUserIDFromProfile(profile); |
| 87 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName()); | 87 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName()); |
| 88 // TODO(hirono): Remove the property from the profile_info. | 88 // TODO(hirono): Remove the property from the profile_info. |
| 89 profile_info->is_current_profile = true; | 89 profile_info->is_current_profile = true; |
| 90 | 90 |
| 91 result_profiles.push_back(profile_info); | 91 result_profiles.push_back(profile_info); |
| 92 } | 92 } |
| 93 | 93 |
| 94 return result_profiles; | 94 return result_profiles; |
| 95 } | 95 } |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 bool FileBrowserPrivateLogoutUserForReauthenticationFunction::RunSync() { | 98 bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { |
| 99 user_manager::User* user = | 99 user_manager::User* user = |
| 100 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); | 100 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); |
| 101 if (user) { | 101 if (user) { |
| 102 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 102 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
| 103 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); | 103 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); |
| 104 } | 104 } |
| 105 | 105 |
| 106 chrome::AttemptUserExit(); | 106 chrome::AttemptUserExit(); |
| 107 return true; | 107 return true; |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool FileBrowserPrivateGetPreferencesFunction::RunSync() { | 110 bool FileManagerPrivateGetPreferencesFunction::RunSync() { |
| 111 api::file_browser_private::Preferences result; | 111 api::file_manager_private::Preferences result; |
| 112 const PrefService* const service = GetProfile()->GetPrefs(); | 112 const PrefService* const service = GetProfile()->GetPrefs(); |
| 113 | 113 |
| 114 result.drive_enabled = drive::util::IsDriveEnabledForProfile(GetProfile()); | 114 result.drive_enabled = drive::util::IsDriveEnabledForProfile(GetProfile()); |
| 115 result.cellular_disabled = | 115 result.cellular_disabled = |
| 116 service->GetBoolean(prefs::kDisableDriveOverCellular); | 116 service->GetBoolean(prefs::kDisableDriveOverCellular); |
| 117 result.hosted_files_disabled = | 117 result.hosted_files_disabled = |
| 118 service->GetBoolean(prefs::kDisableDriveHostedFiles); | 118 service->GetBoolean(prefs::kDisableDriveHostedFiles); |
| 119 result.use24hour_clock = service->GetBoolean(prefs::kUse24HourClock); | 119 result.use24hour_clock = service->GetBoolean(prefs::kUse24HourClock); |
| 120 result.allow_redeem_offers = true; | 120 result.allow_redeem_offers = true; |
| 121 if (!chromeos::CrosSettings::Get()->GetBoolean( | 121 if (!chromeos::CrosSettings::Get()->GetBoolean( |
| 122 chromeos::kAllowRedeemChromeOsRegistrationOffers, | 122 chromeos::kAllowRedeemChromeOsRegistrationOffers, |
| 123 &result.allow_redeem_offers)) { | 123 &result.allow_redeem_offers)) { |
| 124 result.allow_redeem_offers = true; | 124 result.allow_redeem_offers = true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 SetResult(result.ToValue().release()); | 127 SetResult(result.ToValue().release()); |
| 128 | 128 |
| 129 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 129 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 130 if (logger) | 130 if (logger) |
| 131 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); | 131 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool FileBrowserPrivateSetPreferencesFunction::RunSync() { | 135 bool FileManagerPrivateSetPreferencesFunction::RunSync() { |
| 136 using extensions::api::file_browser_private::SetPreferences::Params; | 136 using extensions::api::file_manager_private::SetPreferences::Params; |
| 137 const scoped_ptr<Params> params(Params::Create(*args_)); | 137 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 138 EXTENSION_FUNCTION_VALIDATE(params); | 138 EXTENSION_FUNCTION_VALIDATE(params); |
| 139 | 139 |
| 140 PrefService* const service = GetProfile()->GetPrefs(); | 140 PrefService* const service = GetProfile()->GetPrefs(); |
| 141 | 141 |
| 142 if (params->change_info.cellular_disabled) | 142 if (params->change_info.cellular_disabled) |
| 143 service->SetBoolean(prefs::kDisableDriveOverCellular, | 143 service->SetBoolean(prefs::kDisableDriveOverCellular, |
| 144 *params->change_info.cellular_disabled); | 144 *params->change_info.cellular_disabled); |
| 145 | 145 |
| 146 if (params->change_info.hosted_files_disabled) | 146 if (params->change_info.hosted_files_disabled) |
| 147 service->SetBoolean(prefs::kDisableDriveHostedFiles, | 147 service->SetBoolean(prefs::kDisableDriveHostedFiles, |
| 148 *params->change_info.hosted_files_disabled); | 148 *params->change_info.hosted_files_disabled); |
| 149 | 149 |
| 150 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 150 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 151 if (logger) | 151 if (logger) |
| 152 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); | 152 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 FileBrowserPrivateZipSelectionFunction:: | 156 FileManagerPrivateZipSelectionFunction:: |
| 157 FileBrowserPrivateZipSelectionFunction() {} | 157 FileManagerPrivateZipSelectionFunction() {} |
| 158 | 158 |
| 159 FileBrowserPrivateZipSelectionFunction:: | 159 FileManagerPrivateZipSelectionFunction:: |
| 160 ~FileBrowserPrivateZipSelectionFunction() {} | 160 ~FileManagerPrivateZipSelectionFunction() {} |
| 161 | 161 |
| 162 bool FileBrowserPrivateZipSelectionFunction::RunAsync() { | 162 bool FileManagerPrivateZipSelectionFunction::RunAsync() { |
| 163 using extensions::api::file_browser_private::ZipSelection::Params; | 163 using extensions::api::file_manager_private::ZipSelection::Params; |
| 164 const scoped_ptr<Params> params(Params::Create(*args_)); | 164 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 165 EXTENSION_FUNCTION_VALIDATE(params); | 165 EXTENSION_FUNCTION_VALIDATE(params); |
| 166 | 166 |
| 167 // First param is the source directory URL. | 167 // First param is the source directory URL. |
| 168 if (params->dir_url.empty()) | 168 if (params->dir_url.empty()) |
| 169 return false; | 169 return false; |
| 170 | 170 |
| 171 base::FilePath src_dir = file_manager::util::GetLocalPathFromURL( | 171 base::FilePath src_dir = file_manager::util::GetLocalPathFromURL( |
| 172 render_view_host(), GetProfile(), GURL(params->dir_url)); | 172 render_view_host(), GetProfile(), GURL(params->dir_url)); |
| 173 if (src_dir.empty()) | 173 if (src_dir.empty()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 201 const base::FilePath& file_path = files[i]; | 201 const base::FilePath& file_path = files[i]; |
| 202 | 202 |
| 203 // Obtain the relative path of |file_path| under |src_dir|. | 203 // Obtain the relative path of |file_path| under |src_dir|. |
| 204 base::FilePath relative_path; | 204 base::FilePath relative_path; |
| 205 if (!src_dir.AppendRelativePath(file_path, &relative_path)) | 205 if (!src_dir.AppendRelativePath(file_path, &relative_path)) |
| 206 return false; | 206 return false; |
| 207 src_relative_paths.push_back(relative_path); | 207 src_relative_paths.push_back(relative_path); |
| 208 } | 208 } |
| 209 | 209 |
| 210 (new file_manager::ZipFileCreator( | 210 (new file_manager::ZipFileCreator( |
| 211 base::Bind(&FileBrowserPrivateZipSelectionFunction::OnZipDone, this), | 211 base::Bind(&FileManagerPrivateZipSelectionFunction::OnZipDone, this), |
| 212 src_dir, | 212 src_dir, |
| 213 src_relative_paths, | 213 src_relative_paths, |
| 214 dest_file))->Start(); | 214 dest_file))->Start(); |
| 215 return true; | 215 return true; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void FileBrowserPrivateZipSelectionFunction::OnZipDone(bool success) { | 218 void FileManagerPrivateZipSelectionFunction::OnZipDone(bool success) { |
| 219 SetResult(new base::FundamentalValue(success)); | 219 SetResult(new base::FundamentalValue(success)); |
| 220 SendResponse(true); | 220 SendResponse(true); |
| 221 } | 221 } |
| 222 | 222 |
| 223 bool FileBrowserPrivateZoomFunction::RunSync() { | 223 bool FileManagerPrivateZoomFunction::RunSync() { |
| 224 using extensions::api::file_browser_private::Zoom::Params; | 224 using extensions::api::file_manager_private::Zoom::Params; |
| 225 const scoped_ptr<Params> params(Params::Create(*args_)); | 225 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 226 EXTENSION_FUNCTION_VALIDATE(params); | 226 EXTENSION_FUNCTION_VALIDATE(params); |
| 227 | 227 |
| 228 content::PageZoom zoom_type; | 228 content::PageZoom zoom_type; |
| 229 switch (params->operation) { | 229 switch (params->operation) { |
| 230 case api::file_browser_private::ZOOM_OPERATION_TYPE_IN: | 230 case api::file_manager_private::ZOOM_OPERATION_TYPE_IN: |
| 231 zoom_type = content::PAGE_ZOOM_IN; | 231 zoom_type = content::PAGE_ZOOM_IN; |
| 232 break; | 232 break; |
| 233 case api::file_browser_private::ZOOM_OPERATION_TYPE_OUT: | 233 case api::file_manager_private::ZOOM_OPERATION_TYPE_OUT: |
| 234 zoom_type = content::PAGE_ZOOM_OUT; | 234 zoom_type = content::PAGE_ZOOM_OUT; |
| 235 break; | 235 break; |
| 236 case api::file_browser_private::ZOOM_OPERATION_TYPE_RESET: | 236 case api::file_manager_private::ZOOM_OPERATION_TYPE_RESET: |
| 237 zoom_type = content::PAGE_ZOOM_RESET; | 237 zoom_type = content::PAGE_ZOOM_RESET; |
| 238 break; | 238 break; |
| 239 default: | 239 default: |
| 240 NOTREACHED(); | 240 NOTREACHED(); |
| 241 return false; | 241 return false; |
| 242 } | 242 } |
| 243 render_view_host()->Zoom(zoom_type); | 243 render_view_host()->Zoom(zoom_type); |
| 244 return true; | 244 return true; |
| 245 } | 245 } |
| 246 | 246 |
| 247 bool FileBrowserPrivateInstallWebstoreItemFunction::RunAsync() { | 247 bool FileManagerPrivateInstallWebstoreItemFunction::RunAsync() { |
| 248 using extensions::api::file_browser_private::InstallWebstoreItem::Params; | 248 using extensions::api::file_manager_private::InstallWebstoreItem::Params; |
| 249 const scoped_ptr<Params> params(Params::Create(*args_)); | 249 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 250 EXTENSION_FUNCTION_VALIDATE(params); | 250 EXTENSION_FUNCTION_VALIDATE(params); |
| 251 | 251 |
| 252 if (params->item_id.empty()) | 252 if (params->item_id.empty()) |
| 253 return false; | 253 return false; |
| 254 | 254 |
| 255 const extensions::WebstoreStandaloneInstaller::Callback callback = | 255 const extensions::WebstoreStandaloneInstaller::Callback callback = |
| 256 base::Bind( | 256 base::Bind( |
| 257 &FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete, | 257 &FileManagerPrivateInstallWebstoreItemFunction::OnInstallComplete, |
| 258 this); | 258 this); |
| 259 | 259 |
| 260 // Only GoogleCastAPI extension can use silent installation. | 260 // Only GoogleCastAPI extension can use silent installation. |
| 261 if (params->silent_installation && | 261 if (params->silent_installation && |
| 262 params->item_id != kGoogleCastApiExtensionId) { | 262 params->item_id != kGoogleCastApiExtensionId) { |
| 263 SetError("Only whitelisted items can do silent installation."); | 263 SetError("Only whitelisted items can do silent installation."); |
| 264 return false; | 264 return false; |
| 265 } | 265 } |
| 266 | 266 |
| 267 scoped_refptr<file_manager::AppInstaller> installer( | 267 scoped_refptr<file_manager::AppInstaller> installer( |
| 268 new file_manager::AppInstaller(GetAssociatedWebContents(), | 268 new file_manager::AppInstaller(GetAssociatedWebContents(), |
| 269 params->item_id, | 269 params->item_id, |
| 270 GetProfile(), | 270 GetProfile(), |
| 271 params->silent_installation, | 271 params->silent_installation, |
| 272 callback)); | 272 callback)); |
| 273 // installer will be AddRef()'d in BeginInstall(). | 273 // installer will be AddRef()'d in BeginInstall(). |
| 274 installer->BeginInstall(); | 274 installer->BeginInstall(); |
| 275 return true; | 275 return true; |
| 276 } | 276 } |
| 277 | 277 |
| 278 void FileBrowserPrivateInstallWebstoreItemFunction::OnInstallComplete( | 278 void FileManagerPrivateInstallWebstoreItemFunction::OnInstallComplete( |
| 279 bool success, | 279 bool success, |
| 280 const std::string& error, | 280 const std::string& error, |
| 281 extensions::webstore_install::Result result) { | 281 extensions::webstore_install::Result result) { |
| 282 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 282 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 283 if (success) { | 283 if (success) { |
| 284 if (logger) { | 284 if (logger) { |
| 285 logger->Log(logging::LOG_INFO, | 285 logger->Log(logging::LOG_INFO, |
| 286 "App install succeeded. (item id: %s)", | 286 "App install succeeded. (item id: %s)", |
| 287 webstore_item_id_.c_str()); | 287 webstore_item_id_.c_str()); |
| 288 } | 288 } |
| 289 } else { | 289 } else { |
| 290 if (logger) { | 290 if (logger) { |
| 291 logger->Log(logging::LOG_ERROR, | 291 logger->Log(logging::LOG_ERROR, |
| 292 "App install failed. (item id: %s, reason: %s)", | 292 "App install failed. (item id: %s, reason: %s)", |
| 293 webstore_item_id_.c_str(), | 293 webstore_item_id_.c_str(), |
| 294 error.c_str()); | 294 error.c_str()); |
| 295 } | 295 } |
| 296 SetError(error); | 296 SetError(error); |
| 297 } | 297 } |
| 298 | 298 |
| 299 SendResponse(success); | 299 SendResponse(success); |
| 300 } | 300 } |
| 301 | 301 |
| 302 FileBrowserPrivateRequestWebStoreAccessTokenFunction:: | 302 FileManagerPrivateRequestWebStoreAccessTokenFunction:: |
| 303 FileBrowserPrivateRequestWebStoreAccessTokenFunction() { | 303 FileManagerPrivateRequestWebStoreAccessTokenFunction() { |
| 304 } | 304 } |
| 305 | 305 |
| 306 FileBrowserPrivateRequestWebStoreAccessTokenFunction:: | 306 FileManagerPrivateRequestWebStoreAccessTokenFunction:: |
| 307 ~FileBrowserPrivateRequestWebStoreAccessTokenFunction() { | 307 ~FileManagerPrivateRequestWebStoreAccessTokenFunction() { |
| 308 } | 308 } |
| 309 | 309 |
| 310 bool FileBrowserPrivateRequestWebStoreAccessTokenFunction::RunAsync() { | 310 bool FileManagerPrivateRequestWebStoreAccessTokenFunction::RunAsync() { |
| 311 std::vector<std::string> scopes; | 311 std::vector<std::string> scopes; |
| 312 scopes.push_back(kCWSScope); | 312 scopes.push_back(kCWSScope); |
| 313 | 313 |
| 314 ProfileOAuth2TokenService* oauth_service = | 314 ProfileOAuth2TokenService* oauth_service = |
| 315 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); | 315 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
| 316 net::URLRequestContextGetter* url_request_context_getter = | 316 net::URLRequestContextGetter* url_request_context_getter = |
| 317 g_browser_process->system_request_context(); | 317 g_browser_process->system_request_context(); |
| 318 | 318 |
| 319 if (!oauth_service) { | 319 if (!oauth_service) { |
| 320 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 320 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 321 if (logger) { | 321 if (logger) { |
| 322 logger->Log(logging::LOG_ERROR, | 322 logger->Log(logging::LOG_ERROR, |
| 323 "CWS OAuth token fetch failed. OAuth2TokenService can't " | 323 "CWS OAuth token fetch failed. OAuth2TokenService can't " |
| 324 "be retrieved."); | 324 "be retrieved."); |
| 325 } | 325 } |
| 326 SetResult(base::Value::CreateNullValue()); | 326 SetResult(base::Value::CreateNullValue()); |
| 327 return false; | 327 return false; |
| 328 } | 328 } |
| 329 | 329 |
| 330 SigninManagerBase* signin_manager = | 330 SigninManagerBase* signin_manager = |
| 331 SigninManagerFactory::GetForProfile(GetProfile()); | 331 SigninManagerFactory::GetForProfile(GetProfile()); |
| 332 auth_service_.reset(new google_apis::AuthService( | 332 auth_service_.reset(new google_apis::AuthService( |
| 333 oauth_service, | 333 oauth_service, |
| 334 signin_manager->GetAuthenticatedAccountId(), | 334 signin_manager->GetAuthenticatedAccountId(), |
| 335 url_request_context_getter, | 335 url_request_context_getter, |
| 336 scopes)); | 336 scopes)); |
| 337 auth_service_->StartAuthentication(base::Bind( | 337 auth_service_->StartAuthentication(base::Bind( |
| 338 &FileBrowserPrivateRequestWebStoreAccessTokenFunction:: | 338 &FileManagerPrivateRequestWebStoreAccessTokenFunction:: |
| 339 OnAccessTokenFetched, | 339 OnAccessTokenFetched, |
| 340 this)); | 340 this)); |
| 341 | 341 |
| 342 return true; | 342 return true; |
| 343 } | 343 } |
| 344 | 344 |
| 345 void FileBrowserPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched( | 345 void FileManagerPrivateRequestWebStoreAccessTokenFunction::OnAccessTokenFetched( |
| 346 google_apis::GDataErrorCode code, | 346 google_apis::GDataErrorCode code, |
| 347 const std::string& access_token) { | 347 const std::string& access_token) { |
| 348 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 348 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 349 | 349 |
| 350 if (code == google_apis::HTTP_SUCCESS) { | 350 if (code == google_apis::HTTP_SUCCESS) { |
| 351 DCHECK(auth_service_->HasAccessToken()); | 351 DCHECK(auth_service_->HasAccessToken()); |
| 352 DCHECK(access_token == auth_service_->access_token()); | 352 DCHECK(access_token == auth_service_->access_token()); |
| 353 if (logger) | 353 if (logger) |
| 354 logger->Log(logging::LOG_INFO, "CWS OAuth token fetch succeeded."); | 354 logger->Log(logging::LOG_INFO, "CWS OAuth token fetch succeeded."); |
| 355 SetResult(new base::StringValue(access_token)); | 355 SetResult(new base::StringValue(access_token)); |
| 356 SendResponse(true); | 356 SendResponse(true); |
| 357 } else { | 357 } else { |
| 358 if (logger) { | 358 if (logger) { |
| 359 logger->Log(logging::LOG_ERROR, | 359 logger->Log(logging::LOG_ERROR, |
| 360 "CWS OAuth token fetch failed. (GDataErrorCode: %s)", | 360 "CWS OAuth token fetch failed. (GDataErrorCode: %s)", |
| 361 google_apis::GDataErrorCodeToString(code).c_str()); | 361 google_apis::GDataErrorCodeToString(code).c_str()); |
| 362 } | 362 } |
| 363 SetResult(base::Value::CreateNullValue()); | 363 SetResult(base::Value::CreateNullValue()); |
| 364 SendResponse(false); | 364 SendResponse(false); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool FileBrowserPrivateGetProfilesFunction::RunSync() { | 368 bool FileManagerPrivateGetProfilesFunction::RunSync() { |
| 369 #if defined(USE_ATHENA) | 369 #if defined(USE_ATHENA) |
| 370 // TODO(oshima): Figure out what to do. | 370 // TODO(oshima): Figure out what to do. |
| 371 return false; | 371 return false; |
| 372 #endif | 372 #endif |
| 373 | 373 |
| 374 const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >& | 374 const std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >& |
| 375 profiles = GetLoggedInProfileInfoList(); | 375 profiles = GetLoggedInProfileInfoList(); |
| 376 | 376 |
| 377 // Obtains the display profile ID. | 377 // Obtains the display profile ID. |
| 378 AppWindow* const app_window = GetCurrentAppWindow(this); | 378 AppWindow* const app_window = GetCurrentAppWindow(this); |
| 379 chrome::MultiUserWindowManager* const window_manager = | 379 chrome::MultiUserWindowManager* const window_manager = |
| 380 chrome::MultiUserWindowManager::GetInstance(); | 380 chrome::MultiUserWindowManager::GetInstance(); |
| 381 const std::string current_profile_id = | 381 const std::string current_profile_id = |
| 382 multi_user_util::GetUserIDFromProfile(GetProfile()); | 382 multi_user_util::GetUserIDFromProfile(GetProfile()); |
| 383 const std::string display_profile_id = | 383 const std::string display_profile_id = |
| 384 window_manager && app_window ? window_manager->GetUserPresentingWindow( | 384 window_manager && app_window ? window_manager->GetUserPresentingWindow( |
| 385 app_window->GetNativeWindow()) | 385 app_window->GetNativeWindow()) |
| 386 : ""; | 386 : ""; |
| 387 | 387 |
| 388 results_ = api::file_browser_private::GetProfiles::Results::Create( | 388 results_ = api::file_manager_private::GetProfiles::Results::Create( |
| 389 profiles, | 389 profiles, |
| 390 current_profile_id, | 390 current_profile_id, |
| 391 display_profile_id.empty() ? current_profile_id : display_profile_id); | 391 display_profile_id.empty() ? current_profile_id : display_profile_id); |
| 392 return true; | 392 return true; |
| 393 } | 393 } |
| 394 | 394 |
| 395 bool FileBrowserPrivateVisitDesktopFunction::RunSync() { | 395 bool FileManagerPrivateVisitDesktopFunction::RunSync() { |
| 396 using api::file_browser_private::VisitDesktop::Params; | 396 using api::file_manager_private::VisitDesktop::Params; |
| 397 const scoped_ptr<Params> params(Params::Create(*args_)); | 397 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 398 const std::vector<linked_ptr<api::file_browser_private::ProfileInfo> >& | 398 const std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >& |
| 399 profiles = GetLoggedInProfileInfoList(); | 399 profiles = GetLoggedInProfileInfoList(); |
| 400 | 400 |
| 401 chrome::MultiUserWindowManager* const window_manager = | 401 chrome::MultiUserWindowManager* const window_manager = |
| 402 chrome::MultiUserWindowManager::GetInstance(); | 402 chrome::MultiUserWindowManager::GetInstance(); |
| 403 DCHECK(window_manager); | 403 DCHECK(window_manager); |
| 404 | 404 |
| 405 // Check if the target user is logged-in or not. | 405 // Check if the target user is logged-in or not. |
| 406 bool logged_in = false; | 406 bool logged_in = false; |
| 407 for (size_t i = 0; i < profiles.size(); ++i) { | 407 for (size_t i = 0; i < profiles.size(); ++i) { |
| 408 if (profiles[i]->profile_id == params->profile_id) { | 408 if (profiles[i]->profile_id == params->profile_id) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 429 // Check the result. | 429 // Check the result. |
| 430 if (!window_manager->IsWindowOnDesktopOfUser(app_window->GetNativeWindow(), | 430 if (!window_manager->IsWindowOnDesktopOfUser(app_window->GetNativeWindow(), |
| 431 params->profile_id)) { | 431 params->profile_id)) { |
| 432 SetError("The window cannot visit the desktop."); | 432 SetError("The window cannot visit the desktop."); |
| 433 return false; | 433 return false; |
| 434 } | 434 } |
| 435 | 435 |
| 436 return true; | 436 return true; |
| 437 } | 437 } |
| 438 | 438 |
| 439 bool FileBrowserPrivateOpenInspectorFunction::RunSync() { | 439 bool FileManagerPrivateOpenInspectorFunction::RunSync() { |
| 440 using extensions::api::file_browser_private::OpenInspector::Params; | 440 using extensions::api::file_manager_private::OpenInspector::Params; |
| 441 const scoped_ptr<Params> params(Params::Create(*args_)); | 441 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 442 EXTENSION_FUNCTION_VALIDATE(params); | 442 EXTENSION_FUNCTION_VALIDATE(params); |
| 443 | 443 |
| 444 switch (params->type) { | 444 switch (params->type) { |
| 445 case extensions::api::file_browser_private::INSPECTION_TYPE_NORMAL: | 445 case extensions::api::file_manager_private::INSPECTION_TYPE_NORMAL: |
| 446 // Open inspector for foreground page. | 446 // Open inspector for foreground page. |
| 447 DevToolsWindow::OpenDevToolsWindow( | 447 DevToolsWindow::OpenDevToolsWindow( |
| 448 content::WebContents::FromRenderViewHost(render_view_host())); | 448 content::WebContents::FromRenderViewHost(render_view_host())); |
| 449 break; | 449 break; |
| 450 case extensions::api::file_browser_private::INSPECTION_TYPE_CONSOLE: | 450 case extensions::api::file_manager_private::INSPECTION_TYPE_CONSOLE: |
| 451 // Open inspector for foreground page and bring focus to the console. | 451 // Open inspector for foreground page and bring focus to the console. |
| 452 DevToolsWindow::OpenDevToolsWindow( | 452 DevToolsWindow::OpenDevToolsWindow( |
| 453 content::WebContents::FromRenderViewHost(render_view_host()), | 453 content::WebContents::FromRenderViewHost(render_view_host()), |
| 454 DevToolsToggleAction::ShowConsole()); | 454 DevToolsToggleAction::ShowConsole()); |
| 455 break; | 455 break; |
| 456 case extensions::api::file_browser_private::INSPECTION_TYPE_ELEMENT: | 456 case extensions::api::file_manager_private::INSPECTION_TYPE_ELEMENT: |
| 457 // Open inspector for foreground page in inspect element mode. | 457 // Open inspector for foreground page in inspect element mode. |
| 458 DevToolsWindow::OpenDevToolsWindow( | 458 DevToolsWindow::OpenDevToolsWindow( |
| 459 content::WebContents::FromRenderViewHost(render_view_host()), | 459 content::WebContents::FromRenderViewHost(render_view_host()), |
| 460 DevToolsToggleAction::Inspect()); | 460 DevToolsToggleAction::Inspect()); |
| 461 break; | 461 break; |
| 462 case extensions::api::file_browser_private::INSPECTION_TYPE_BACKGROUND: | 462 case extensions::api::file_manager_private::INSPECTION_TYPE_BACKGROUND: |
| 463 // Open inspector for background page. | 463 // Open inspector for background page. |
| 464 extensions::devtools_util::InspectBackgroundPage(extension(), | 464 extensions::devtools_util::InspectBackgroundPage(extension(), |
| 465 GetProfile()); | 465 GetProfile()); |
| 466 break; | 466 break; |
| 467 default: | 467 default: |
| 468 NOTREACHED(); | 468 NOTREACHED(); |
| 469 SetError( | 469 SetError( |
| 470 base::StringPrintf("Unexpected inspection type(%d) is specified.", | 470 base::StringPrintf("Unexpected inspection type(%d) is specified.", |
| 471 static_cast<int>(params->type))); | 471 static_cast<int>(params->type))); |
| 472 return false; | 472 return false; |
| 473 } | 473 } |
| 474 return true; | 474 return true; |
| 475 } | 475 } |
| 476 | 476 |
| 477 } // namespace extensions | 477 } // namespace extensions |
| OLD | NEW |