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 | 4 |
5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" | 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 } | 158 } |
159 | 159 |
160 // static | 160 // static |
161 scoped_ptr<WebstoreInstaller::Approval> | 161 scoped_ptr<WebstoreInstaller::Approval> |
162 WebstorePrivateApi::PopApprovalForTesting( | 162 WebstorePrivateApi::PopApprovalForTesting( |
163 Profile* profile, const std::string& extension_id) { | 163 Profile* profile, const std::string& extension_id) { |
164 return g_pending_approvals.Get().PopApproval(profile, extension_id); | 164 return g_pending_approvals.Get().PopApproval(profile, extension_id); |
165 } | 165 } |
166 | 166 |
167 WebstorePrivateBeginInstallWithManifest3Function:: | 167 WebstorePrivateBeginInstallWithManifest3Function:: |
168 WebstorePrivateBeginInstallWithManifest3Function() { | 168 WebstorePrivateBeginInstallWithManifest3Function() : chrome_details_(this) { |
169 } | 169 } |
170 | 170 |
171 WebstorePrivateBeginInstallWithManifest3Function:: | 171 WebstorePrivateBeginInstallWithManifest3Function:: |
172 ~WebstorePrivateBeginInstallWithManifest3Function() { | 172 ~WebstorePrivateBeginInstallWithManifest3Function() { |
173 } | 173 } |
174 | 174 |
175 bool WebstorePrivateBeginInstallWithManifest3Function::RunAsync() { | 175 ExtensionFunction::ResponseAction |
176 WebstorePrivateBeginInstallWithManifest3Function::Run() { | |
176 params_ = BeginInstallWithManifest3::Params::Create(*args_); | 177 params_ = BeginInstallWithManifest3::Params::Create(*args_); |
177 EXTENSION_FUNCTION_VALIDATE(params_); | 178 EXTENSION_FUNCTION_VALIDATE(params_); |
178 | 179 |
179 if (!crx_file::id_util::IdIsValid(params_->details.id)) { | 180 if (!crx_file::id_util::IdIsValid(params_->details.id)) |
180 SetResultCode(INVALID_ID); | 181 return RespondNowWithError(INVALID_ID, kInvalidIdError); |
181 error_ = kInvalidIdError; | |
182 return false; | |
183 } | |
184 | 182 |
185 if (params_->details.icon_data && params_->details.icon_url) { | 183 if (params_->details.icon_data && params_->details.icon_url) |
186 SetResultCode(ICON_ERROR); | 184 return RespondNowWithError(ICON_ERROR, kCannotSpecifyIconDataAndUrlError); |
187 error_ = kCannotSpecifyIconDataAndUrlError; | |
188 return false; | |
189 } | |
190 | 185 |
191 GURL icon_url; | 186 GURL icon_url; |
192 if (params_->details.icon_url) { | 187 if (params_->details.icon_url) { |
193 std::string tmp_url; | 188 std::string tmp_url; |
194 icon_url = source_url().Resolve(*params_->details.icon_url); | 189 icon_url = source_url().Resolve(*params_->details.icon_url); |
195 if (!icon_url.is_valid()) { | 190 if (!icon_url.is_valid()) |
196 SetResultCode(INVALID_ICON_URL); | 191 return RespondNowWithError(INVALID_ICON_URL, kInvalidIconUrlError); |
197 error_ = kInvalidIconUrlError; | |
198 return false; | |
199 } | |
200 } | 192 } |
201 | 193 |
202 if (params_->details.authuser) { | 194 if (params_->details.authuser) { |
203 authuser_ = *params_->details.authuser; | 195 authuser_ = *params_->details.authuser; |
204 } | 196 } |
205 | 197 |
206 std::string icon_data = params_->details.icon_data ? | 198 std::string icon_data = params_->details.icon_data ? |
207 *params_->details.icon_data : std::string(); | 199 *params_->details.icon_data : std::string(); |
208 | 200 |
209 Profile* profile = GetProfile(); | 201 InstallTracker* tracker = InstallTracker::Get(browser_context()); |
210 InstallTracker* tracker = InstallTracker::Get(profile); | |
211 DCHECK(tracker); | 202 DCHECK(tracker); |
212 if (util::IsExtensionInstalledPermanently(params_->details.id, profile) || | 203 if (util::IsExtensionInstalledPermanently(params_->details.id, |
204 browser_context()) || | |
213 tracker->GetActiveInstall(params_->details.id)) { | 205 tracker->GetActiveInstall(params_->details.id)) { |
214 SetResultCode(ALREADY_INSTALLED); | 206 return RespondNowWithError(ALREADY_INSTALLED, kAlreadyInstalledError); |
215 error_ = kAlreadyInstalledError; | |
216 return false; | |
217 } | 207 } |
218 ActiveInstallData install_data(params_->details.id); | 208 ActiveInstallData install_data(params_->details.id); |
219 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); | 209 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); |
220 | 210 |
221 net::URLRequestContextGetter* context_getter = NULL; | 211 net::URLRequestContextGetter* context_getter = NULL; |
222 if (!icon_url.is_empty()) | 212 if (!icon_url.is_empty()) |
223 context_getter = GetProfile()->GetRequestContext(); | 213 context_getter = browser_context()->GetRequestContext(); |
224 | 214 |
225 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | 215 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
226 this, params_->details.id, params_->details.manifest, icon_data, icon_url, | 216 this, params_->details.id, params_->details.manifest, icon_data, icon_url, |
227 context_getter); | 217 context_getter); |
228 | 218 |
229 // The helper will call us back via OnWebstoreParseSuccess or | 219 // The helper will call us back via OnWebstoreParseSuccess or |
230 // OnWebstoreParseFailure. | 220 // OnWebstoreParseFailure. |
231 helper->Start(); | 221 helper->Start(); |
232 | 222 |
233 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. | 223 // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. |
234 AddRef(); | 224 AddRef(); |
235 | 225 |
236 // The response is sent asynchronously in OnWebstoreParseSuccess/ | 226 // The response is sent asynchronously in OnWebstoreParseSuccess/ |
237 // OnWebstoreParseFailure. | 227 // OnWebstoreParseFailure. |
238 return true; | 228 return RespondLater(); |
239 } | |
240 | |
241 const char* WebstorePrivateBeginInstallWithManifest3Function:: | |
242 ResultCodeToString(ResultCode code) { | |
243 switch (code) { | |
244 case ERROR_NONE: | |
245 return ""; | |
246 case UNKNOWN_ERROR: | |
247 return "unknown_error"; | |
248 case USER_CANCELLED: | |
249 return "user_cancelled"; | |
250 case MANIFEST_ERROR: | |
251 return "manifest_error"; | |
252 case ICON_ERROR: | |
253 return "icon_error"; | |
254 case INVALID_ID: | |
255 return "invalid_id"; | |
256 case PERMISSION_DENIED: | |
257 return "permission_denied"; | |
258 case INVALID_ICON_URL: | |
259 return "invalid_icon_url"; | |
260 case ALREADY_INSTALLED: | |
261 return "already_installed"; | |
262 } | |
263 NOTREACHED(); | |
264 return ""; | |
265 } | |
266 | |
267 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( | |
268 ResultCode code) { | |
269 results_ = BeginInstallWithManifest3::Results::Create( | |
270 ResultCodeToString(code)); | |
271 } | 229 } |
272 | 230 |
273 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( | 231 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( |
274 const std::string& id, | 232 const std::string& id, |
275 const SkBitmap& icon, | 233 const SkBitmap& icon, |
276 base::DictionaryValue* parsed_manifest) { | 234 base::DictionaryValue* parsed_manifest) { |
277 CHECK_EQ(params_->details.id, id); | 235 CHECK_EQ(params_->details.id, id); |
278 CHECK(parsed_manifest); | 236 CHECK(parsed_manifest); |
279 icon_ = icon; | 237 icon_ = icon; |
280 parsed_manifest_.reset(parsed_manifest); | 238 parsed_manifest_.reset(parsed_manifest); |
(...skipping 29 matching lines...) Expand all Loading... | |
310 // Control flow finishes up in InstallUIProceed or InstallUIAbort. | 268 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
311 } | 269 } |
312 | 270 |
313 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( | 271 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( |
314 const std::string& id, | 272 const std::string& id, |
315 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, | 273 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
316 const std::string& error_message) { | 274 const std::string& error_message) { |
317 CHECK_EQ(params_->details.id, id); | 275 CHECK_EQ(params_->details.id, id); |
318 | 276 |
319 // Map from WebstoreInstallHelper's result codes to ours. | 277 // Map from WebstoreInstallHelper's result codes to ours. |
278 ResultCode code; | |
320 switch (result_code) { | 279 switch (result_code) { |
321 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: | 280 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
322 SetResultCode(UNKNOWN_ERROR); | 281 code = UNKNOWN_ERROR; |
323 break; | 282 break; |
324 case WebstoreInstallHelper::Delegate::ICON_ERROR: | 283 case WebstoreInstallHelper::Delegate::ICON_ERROR: |
325 SetResultCode(ICON_ERROR); | 284 code = ICON_ERROR; |
326 break; | 285 break; |
327 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: | 286 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
328 SetResultCode(MANIFEST_ERROR); | 287 code = MANIFEST_ERROR; |
329 break; | 288 break; |
330 default: | 289 default: |
not at google - send to devlin
2015/02/05 17:16:17
It's better to leave out the default case so that
Marc Treib
2015/02/06 10:26:15
Done.
| |
331 CHECK(false); | 290 CHECK(false); |
332 } | 291 } |
333 error_ = error_message; | 292 RespondWithError(code, error_message); |
334 SendResponse(false); | |
335 | 293 |
336 // Matches the AddRef in RunAsync(). | 294 // Matches the AddRef in RunAsync(). |
337 Release(); | 295 Release(); |
338 } | 296 } |
339 | 297 |
340 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { | 298 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { |
341 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in | 299 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in |
342 // the future we may also want to add time-based expiration, where a whitelist | 300 // the future we may also want to add time-based expiration, where a whitelist |
343 // entry is only valid for some number of minutes. | 301 // entry is only valid for some number of minutes. |
344 scoped_ptr<WebstoreInstaller::Approval> approval( | 302 scoped_ptr<WebstoreInstaller::Approval> approval( |
345 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 303 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
346 GetProfile(), params_->details.id, parsed_manifest_.Pass(), false)); | 304 chrome_details_.GetProfile(), |
305 params_->details.id, | |
306 parsed_manifest_.Pass(), | |
307 false)); | |
347 approval->use_app_installed_bubble = params_->details.app_install_bubble; | 308 approval->use_app_installed_bubble = params_->details.app_install_bubble; |
348 approval->enable_launcher = params_->details.enable_launcher; | 309 approval->enable_launcher = params_->details.enable_launcher; |
349 // If we are enabling the launcher, we should not show the app list in order | 310 // If we are enabling the launcher, we should not show the app list in order |
350 // to train the user to open it themselves at least once. | 311 // to train the user to open it themselves at least once. |
351 approval->skip_post_install_ui = params_->details.enable_launcher; | 312 approval->skip_post_install_ui = params_->details.enable_launcher; |
352 approval->dummy_extension = dummy_extension_; | 313 approval->dummy_extension = dummy_extension_; |
353 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); | 314 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); |
354 approval->authuser = authuser_; | 315 approval->authuser = authuser_; |
355 g_pending_approvals.Get().PushApproval(approval.Pass()); | 316 g_pending_approvals.Get().PushApproval(approval.Pass()); |
356 | 317 |
357 DCHECK(scoped_active_install_.get()); | 318 DCHECK(scoped_active_install_.get()); |
358 scoped_active_install_->CancelDeregister(); | 319 scoped_active_install_->CancelDeregister(); |
359 | 320 |
360 SetResultCode(ERROR_NONE); | 321 RespondWithSuccess(); |
361 SendResponse(true); | |
362 | 322 |
363 // The Permissions_Install histogram is recorded from the ExtensionService | 323 // The Permissions_Install histogram is recorded from the ExtensionService |
364 // for all extension installs, so we only need to record the web store | 324 // for all extension installs, so we only need to record the web store |
365 // specific histogram here. | 325 // specific histogram here. |
366 ExtensionService::RecordPermissionMessagesHistogram( | 326 ExtensionService::RecordPermissionMessagesHistogram( |
367 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall2"); | 327 dummy_extension_.get(), "Extensions.Permissions_WebStoreInstall2"); |
368 | 328 |
369 // Matches the AddRef in RunAsync(). | 329 // Matches the AddRef in RunAsync(). |
370 Release(); | 330 Release(); |
371 } | 331 } |
372 | 332 |
373 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( | 333 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( |
374 bool user_initiated) { | 334 bool user_initiated) { |
375 error_ = kUserCancelledError; | 335 RespondWithError(USER_CANCELLED, kUserCancelledError); |
376 SetResultCode(USER_CANCELLED); | |
377 SendResponse(false); | |
378 | 336 |
379 // The web store install histograms are a subset of the install histograms. | 337 // The web store install histograms are a subset of the install histograms. |
380 // We need to record both histograms here since CrxInstaller::InstallUIAbort | 338 // We need to record both histograms here since CrxInstaller::InstallUIAbort |
381 // is never called for web store install cancellations. | 339 // is never called for web store install cancellations. |
382 std::string histogram_name = | 340 std::string histogram_name = |
383 user_initiated ? "Extensions.Permissions_WebStoreInstallCancel2" | 341 user_initiated ? "Extensions.Permissions_WebStoreInstallCancel2" |
384 : "Extensions.Permissions_WebStoreInstallAbort2"; | 342 : "Extensions.Permissions_WebStoreInstallAbort2"; |
385 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), | 343 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
386 histogram_name.c_str()); | 344 histogram_name.c_str()); |
387 | 345 |
388 histogram_name = user_initiated ? "Extensions.Permissions_InstallCancel2" | 346 histogram_name = user_initiated ? "Extensions.Permissions_InstallCancel2" |
389 : "Extensions.Permissions_InstallAbort2"; | 347 : "Extensions.Permissions_InstallAbort2"; |
390 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), | 348 ExtensionService::RecordPermissionMessagesHistogram(dummy_extension_.get(), |
391 histogram_name.c_str()); | 349 histogram_name.c_str()); |
392 | 350 |
393 // Matches the AddRef in RunAsync(). | 351 // Matches the AddRef in RunAsync(). |
394 Release(); | 352 Release(); |
395 } | 353 } |
396 | 354 |
355 const char* WebstorePrivateBeginInstallWithManifest3Function:: | |
356 ResultCodeToString(ResultCode code) const { | |
357 switch (code) { | |
358 case ERROR_NONE: | |
359 return ""; | |
360 case UNKNOWN_ERROR: | |
361 return "unknown_error"; | |
362 case USER_CANCELLED: | |
363 return "user_cancelled"; | |
364 case MANIFEST_ERROR: | |
365 return "manifest_error"; | |
366 case ICON_ERROR: | |
367 return "icon_error"; | |
368 case INVALID_ID: | |
369 return "invalid_id"; | |
370 case PERMISSION_DENIED: | |
371 return "permission_denied"; | |
372 case INVALID_ICON_URL: | |
373 return "invalid_icon_url"; | |
374 case ALREADY_INSTALLED: | |
375 return "already_installed"; | |
376 } | |
377 NOTREACHED(); | |
378 return ""; | |
379 } | |
380 | |
381 ExtensionFunction::ResponseValue | |
382 WebstorePrivateBeginInstallWithManifest3Function::BuildResponseForSuccess() { | |
383 return ArgumentList( | |
384 BeginInstallWithManifest3::Results::Create( | |
385 ResultCodeToString(ERROR_NONE))); | |
386 } | |
387 | |
388 ExtensionFunction::ResponseValue | |
389 WebstorePrivateBeginInstallWithManifest3Function::BuildResponseForError( | |
390 ResultCode code, const std::string& error) { | |
391 return ArgumentListWithError( | |
392 BeginInstallWithManifest3::Results::Create(ResultCodeToString(code)), | |
393 error); | |
394 } | |
395 | |
396 ExtensionFunction::ResponseAction | |
397 WebstorePrivateBeginInstallWithManifest3Function::RespondNowWithError( | |
not at google - send to devlin
2015/02/05 17:16:17
IMO - suggestion - these 3 functions below don't s
Marc Treib
2015/02/06 10:26:15
I've removed the convenience functions. You're rig
| |
398 ResultCode code, const std::string& error) { | |
399 return RespondNow(BuildResponseForError(code, error)); | |
400 } | |
401 | |
402 void WebstorePrivateBeginInstallWithManifest3Function::RespondWithSuccess() { | |
403 Respond(BuildResponseForSuccess()); | |
404 } | |
405 | |
406 void WebstorePrivateBeginInstallWithManifest3Function::RespondWithError( | |
407 ResultCode code, const std::string& error) { | |
408 Respond(BuildResponseForError(code, error)); | |
409 } | |
410 | |
397 WebstorePrivateCompleteInstallFunction:: | 411 WebstorePrivateCompleteInstallFunction:: |
398 WebstorePrivateCompleteInstallFunction() {} | 412 WebstorePrivateCompleteInstallFunction() {} |
399 | 413 |
400 WebstorePrivateCompleteInstallFunction:: | 414 WebstorePrivateCompleteInstallFunction:: |
401 ~WebstorePrivateCompleteInstallFunction() {} | 415 ~WebstorePrivateCompleteInstallFunction() {} |
402 | 416 |
403 bool WebstorePrivateCompleteInstallFunction::RunAsync() { | 417 bool WebstorePrivateCompleteInstallFunction::RunAsync() { |
404 scoped_ptr<CompleteInstall::Params> params( | 418 scoped_ptr<CompleteInstall::Params> params( |
405 CompleteInstall::Params::Create(*args_)); | 419 CompleteInstall::Params::Create(*args_)); |
406 EXTENSION_FUNCTION_VALIDATE(params); | 420 EXTENSION_FUNCTION_VALIDATE(params); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 715 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
702 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 716 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
703 | 717 |
704 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() { | 718 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() { |
705 results_ = GetEphemeralAppsEnabled::Results::Create( | 719 results_ = GetEphemeralAppsEnabled::Results::Create( |
706 EphemeralAppLauncher::IsFeatureEnabledInWebstore()); | 720 EphemeralAppLauncher::IsFeatureEnabledInWebstore()); |
707 return true; | 721 return true; |
708 } | 722 } |
709 | 723 |
710 } // namespace extensions | 724 } // namespace extensions |
OLD | NEW |