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 "content/browser/service_worker/service_worker_register_job.h" | 5 #include "content/browser/service_worker/service_worker_register_job.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 326 } |
327 | 327 |
328 void ServiceWorkerRegisterJob::OnStartWorkerFinished( | 328 void ServiceWorkerRegisterJob::OnStartWorkerFinished( |
329 ServiceWorkerStatusCode status) { | 329 ServiceWorkerStatusCode status) { |
330 if (status == SERVICE_WORKER_OK) { | 330 if (status == SERVICE_WORKER_OK) { |
331 InstallAndContinue(); | 331 InstallAndContinue(); |
332 return; | 332 return; |
333 } | 333 } |
334 | 334 |
335 // "If serviceWorker fails to start up..." then reject the promise with an | 335 // "If serviceWorker fails to start up..." then reject the promise with an |
336 // error and abort. When there is a main script network error, the status will | 336 // error and abort. |
337 // be updated to a more specific one. | 337 if (status == SERVICE_WORKER_ERROR_TIMEOUT) { |
| 338 Complete(status, "Timed out while trying to start the Service Worker."); |
| 339 return; |
| 340 } |
| 341 |
338 const net::URLRequestStatus& main_script_status = | 342 const net::URLRequestStatus& main_script_status = |
339 new_version()->script_cache_map()->main_script_status(); | 343 new_version()->script_cache_map()->main_script_status(); |
340 std::string message; | 344 std::string message; |
341 if (main_script_status.status() != net::URLRequestStatus::SUCCESS) { | 345 if (main_script_status.status() != net::URLRequestStatus::SUCCESS) { |
342 switch (main_script_status.error()) { | |
343 case net::ERR_INSECURE_RESPONSE: | |
344 case net::ERR_UNSAFE_REDIRECT: | |
345 status = SERVICE_WORKER_ERROR_SECURITY; | |
346 break; | |
347 case net::ERR_ABORTED: | |
348 status = SERVICE_WORKER_ERROR_ABORT; | |
349 break; | |
350 default: | |
351 status = SERVICE_WORKER_ERROR_NETWORK; | |
352 } | |
353 message = new_version()->script_cache_map()->main_script_status_message(); | 346 message = new_version()->script_cache_map()->main_script_status_message(); |
354 if (message.empty()) | 347 if (message.empty()) |
355 message = kFetchScriptError; | 348 message = kFetchScriptError; |
356 } | 349 } |
357 | |
358 if (status == SERVICE_WORKER_ERROR_TIMEOUT) | |
359 message = "Timed out while trying to start the Service Worker."; | |
360 | |
361 Complete(status, message); | 350 Complete(status, message); |
362 } | 351 } |
363 | 352 |
364 // This function corresponds to the spec's [[Install]] algorithm. | 353 // This function corresponds to the spec's [[Install]] algorithm. |
365 void ServiceWorkerRegisterJob::InstallAndContinue() { | 354 void ServiceWorkerRegisterJob::InstallAndContinue() { |
366 SetPhase(INSTALL); | 355 SetPhase(INSTALL); |
367 | 356 |
368 // "Set registration.installingWorker to worker." | 357 // "Set registration.installingWorker to worker." |
369 DCHECK(!registration()->installing_version()); | 358 DCHECK(!registration()->installing_version()); |
370 registration()->SetInstallingVersion(new_version()); | 359 registration()->SetInstallingVersion(new_version()); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 if (host->IsHostToRunningServiceWorker()) | 549 if (host->IsHostToRunningServiceWorker()) |
561 continue; | 550 continue; |
562 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), | 551 if (!ServiceWorkerUtils::ScopeMatches(registration->pattern(), |
563 host->document_url())) | 552 host->document_url())) |
564 continue; | 553 continue; |
565 host->AddMatchingRegistration(registration); | 554 host->AddMatchingRegistration(registration); |
566 } | 555 } |
567 } | 556 } |
568 | 557 |
569 } // namespace content | 558 } // namespace content |
OLD | NEW |