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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "webkit/appcache/view_appcache_internals_job.h" | 8 #include "webkit/appcache/view_appcache_internals_job.h" |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
21 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
| 22 #include "net/base/net_errors.h" |
22 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
23 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
24 #include "net/url_request/url_request_simple_job.h" | 25 #include "net/url_request/url_request_simple_job.h" |
25 #include "net/url_request/view_cache_helper.h" | 26 #include "net/url_request/view_cache_helper.h" |
26 #include "webkit/appcache/appcache.h" | 27 #include "webkit/appcache/appcache.h" |
27 #include "webkit/appcache/appcache_group.h" | 28 #include "webkit/appcache/appcache_group.h" |
28 #include "webkit/appcache/appcache_policy.h" | 29 #include "webkit/appcache/appcache_policy.h" |
29 #include "webkit/appcache/appcache_response.h" | 30 #include "webkit/appcache/appcache_response.h" |
30 #include "webkit/appcache/appcache_service.h" | 31 #include "webkit/appcache/appcache_service.h" |
31 | 32 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 328 |
328 virtual void Start() { | 329 virtual void Start() { |
329 DCHECK(request_); | 330 DCHECK(request_); |
330 info_collection_ = new AppCacheInfoCollection; | 331 info_collection_ = new AppCacheInfoCollection; |
331 appcache_service_->GetAllAppCacheInfo( | 332 appcache_service_->GetAllAppCacheInfo( |
332 info_collection_, base::Bind(&MainPageJob::OnGotInfoComplete, | 333 info_collection_, base::Bind(&MainPageJob::OnGotInfoComplete, |
333 weak_factory_.GetWeakPtr())); | 334 weak_factory_.GetWeakPtr())); |
334 } | 335 } |
335 | 336 |
336 // Produces a page containing the listing | 337 // Produces a page containing the listing |
337 virtual bool GetData(std::string* mime_type, | 338 virtual int GetData(std::string* mime_type, |
338 std::string* charset, | 339 std::string* charset, |
339 std::string* out) const { | 340 std::string* out, |
| 341 const net::CompletionCallback& callback) const OVERRIDE { |
340 mime_type->assign("text/html"); | 342 mime_type->assign("text/html"); |
341 charset->assign("UTF-8"); | 343 charset->assign("UTF-8"); |
342 | 344 |
343 out->clear(); | 345 out->clear(); |
344 EmitPageStart(out); | 346 EmitPageStart(out); |
345 if (!info_collection_.get()) { | 347 if (!info_collection_.get()) { |
346 out->append(kErrorMessage); | 348 out->append(kErrorMessage); |
347 } else if (info_collection_->infos_by_origin.empty()) { | 349 } else if (info_collection_->infos_by_origin.empty()) { |
348 out->append(kEmptyAppCachesMessage); | 350 out->append(kEmptyAppCachesMessage); |
349 } else { | 351 } else { |
350 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; | 352 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; |
351 AppCacheInfoVector appcaches; | 353 AppCacheInfoVector appcaches; |
352 for (InfoByOrigin::const_iterator origin = | 354 for (InfoByOrigin::const_iterator origin = |
353 info_collection_->infos_by_origin.begin(); | 355 info_collection_->infos_by_origin.begin(); |
354 origin != info_collection_->infos_by_origin.end(); ++origin) { | 356 origin != info_collection_->infos_by_origin.end(); ++origin) { |
355 appcaches.insert(appcaches.end(), | 357 appcaches.insert(appcaches.end(), |
356 origin->second.begin(), origin->second.end()); | 358 origin->second.begin(), origin->second.end()); |
357 } | 359 } |
358 std::sort(appcaches.begin(), appcaches.end(), SortByManifestUrl); | 360 std::sort(appcaches.begin(), appcaches.end(), SortByManifestUrl); |
359 | 361 |
360 GURL base_url = ClearQuery(request_->url()); | 362 GURL base_url = ClearQuery(request_->url()); |
361 EmitAppCacheInfoVector(base_url, appcache_service_, appcaches, out); | 363 EmitAppCacheInfoVector(base_url, appcache_service_, appcaches, out); |
362 } | 364 } |
363 EmitPageEnd(out); | 365 EmitPageEnd(out); |
364 return true; | 366 return net::OK; |
365 } | 367 } |
366 | 368 |
367 private: | 369 private: |
368 virtual ~MainPageJob() {} | 370 virtual ~MainPageJob() {} |
369 | 371 |
370 void OnGotInfoComplete(int rv) { | 372 void OnGotInfoComplete(int rv) { |
371 if (rv != net::OK) | 373 if (rv != net::OK) |
372 info_collection_ = NULL; | 374 info_collection_ = NULL; |
373 StartAsync(); | 375 StartAsync(); |
374 } | 376 } |
375 | 377 |
376 base::WeakPtrFactory<MainPageJob> weak_factory_; | 378 base::WeakPtrFactory<MainPageJob> weak_factory_; |
377 scoped_refptr<AppCacheInfoCollection> info_collection_; | 379 scoped_refptr<AppCacheInfoCollection> info_collection_; |
378 DISALLOW_COPY_AND_ASSIGN(MainPageJob); | 380 DISALLOW_COPY_AND_ASSIGN(MainPageJob); |
379 }; | 381 }; |
380 | 382 |
381 // Job that redirects back to the main appcache internals page. | 383 // Job that redirects back to the main appcache internals page. |
382 class RedirectToMainPageJob : public BaseInternalsJob { | 384 class RedirectToMainPageJob : public BaseInternalsJob { |
383 public: | 385 public: |
384 RedirectToMainPageJob(net::URLRequest* request, AppCacheService* service) | 386 RedirectToMainPageJob(net::URLRequest* request, AppCacheService* service) |
385 : BaseInternalsJob(request, service) {} | 387 : BaseInternalsJob(request, service) {} |
386 | 388 |
387 virtual bool GetData(std::string* mime_type, | 389 virtual int GetData(std::string* mime_type, |
388 std::string* charset, | 390 std::string* charset, |
389 std::string* data) const { | 391 std::string* data, |
390 return true; // IsRedirectResponse induces a redirect. | 392 const net::CompletionCallback& callback) const OVERRIDE { |
| 393 return net::OK; // IsRedirectResponse induces a redirect. |
391 } | 394 } |
392 | 395 |
393 virtual bool IsRedirectResponse(GURL* location, int* http_status_code) { | 396 virtual bool IsRedirectResponse(GURL* location, int* http_status_code) { |
394 *location = ClearQuery(request_->url()); | 397 *location = ClearQuery(request_->url()); |
395 *http_status_code = 307; | 398 *http_status_code = 307; |
396 return true; | 399 return true; |
397 } | 400 } |
398 | 401 |
399 protected: | 402 protected: |
400 virtual ~RedirectToMainPageJob() {} | 403 virtual ~RedirectToMainPageJob() {} |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 const GURL& manifest_url) | 443 const GURL& manifest_url) |
441 : BaseInternalsJob(request, service), | 444 : BaseInternalsJob(request, service), |
442 manifest_url_(manifest_url) {} | 445 manifest_url_(manifest_url) {} |
443 | 446 |
444 virtual void Start() { | 447 virtual void Start() { |
445 DCHECK(request_); | 448 DCHECK(request_); |
446 appcache_service_->storage()->LoadOrCreateGroup(manifest_url_, this); | 449 appcache_service_->storage()->LoadOrCreateGroup(manifest_url_, this); |
447 } | 450 } |
448 | 451 |
449 // Produces a page containing the entries listing. | 452 // Produces a page containing the entries listing. |
450 virtual bool GetData(std::string* mime_type, | 453 virtual int GetData(std::string* mime_type, |
451 std::string* charset, | 454 std::string* charset, |
452 std::string* out) const { | 455 std::string* out, |
| 456 const net::CompletionCallback& callback) const OVERRIDE { |
453 mime_type->assign("text/html"); | 457 mime_type->assign("text/html"); |
454 charset->assign("UTF-8"); | 458 charset->assign("UTF-8"); |
455 out->clear(); | 459 out->clear(); |
456 EmitPageStart(out); | 460 EmitPageStart(out); |
457 if (appcache_info_.manifest_url.is_empty()) { | 461 if (appcache_info_.manifest_url.is_empty()) { |
458 out->append(kManifestNotFoundMessage); | 462 out->append(kManifestNotFoundMessage); |
459 } else { | 463 } else { |
460 GURL base_url = ClearQuery(request_->url()); | 464 GURL base_url = ClearQuery(request_->url()); |
461 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out); | 465 EmitAppCacheInfo(base_url, appcache_service_, &appcache_info_, out); |
462 EmitAppCacheResourceInfoVector(base_url, | 466 EmitAppCacheResourceInfoVector(base_url, |
463 manifest_url_, | 467 manifest_url_, |
464 resource_infos_, | 468 resource_infos_, |
465 appcache_info_.group_id, | 469 appcache_info_.group_id, |
466 out); | 470 out); |
467 } | 471 } |
468 EmitPageEnd(out); | 472 EmitPageEnd(out); |
469 return true; | 473 return net::OK; |
470 } | 474 } |
471 | 475 |
472 private: | 476 private: |
473 virtual ~ViewAppCacheJob() { | 477 virtual ~ViewAppCacheJob() { |
474 appcache_service_->storage()->CancelDelegateCallbacks(this); | 478 appcache_service_->storage()->CancelDelegateCallbacks(this); |
475 } | 479 } |
476 | 480 |
477 // AppCacheStorage::Delegate override | 481 // AppCacheStorage::Delegate override |
478 virtual void OnGroupLoaded( | 482 virtual void OnGroupLoaded( |
479 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE { | 483 AppCacheGroup* group, const GURL& manifest_url) OVERRIDE { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 response_id_(response_id), group_id_(group_id), amount_read_(0) { | 516 response_id_(response_id), group_id_(group_id), amount_read_(0) { |
513 } | 517 } |
514 | 518 |
515 virtual void Start() { | 519 virtual void Start() { |
516 DCHECK(request_); | 520 DCHECK(request_); |
517 appcache_service_->storage()->LoadResponseInfo( | 521 appcache_service_->storage()->LoadResponseInfo( |
518 manifest_url_, group_id_, response_id_, this); | 522 manifest_url_, group_id_, response_id_, this); |
519 } | 523 } |
520 | 524 |
521 // Produces a page containing the response headers and data. | 525 // Produces a page containing the response headers and data. |
522 virtual bool GetData(std::string* mime_type, | 526 virtual int GetData(std::string* mime_type, |
523 std::string* charset, | 527 std::string* charset, |
524 std::string* out) const { | 528 std::string* out, |
| 529 const net::CompletionCallback& callback) const OVERRIDE { |
525 mime_type->assign("text/html"); | 530 mime_type->assign("text/html"); |
526 charset->assign("UTF-8"); | 531 charset->assign("UTF-8"); |
527 out->clear(); | 532 out->clear(); |
528 EmitPageStart(out); | 533 EmitPageStart(out); |
529 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); | 534 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); |
530 out->append("<br/>\n"); | 535 out->append("<br/>\n"); |
531 if (response_info_) { | 536 if (response_info_) { |
532 if (response_info_->http_response_info()) | 537 if (response_info_->http_response_info()) |
533 EmitResponseHeaders(response_info_->http_response_info()->headers, out); | 538 EmitResponseHeaders(response_info_->http_response_info()->headers, out); |
534 else | 539 else |
535 out->append("Failed to read response headers.<br>"); | 540 out->append("Failed to read response headers.<br>"); |
536 | 541 |
537 if (response_data_) { | 542 if (response_data_) { |
538 EmitHexDump(response_data_->data(), amount_read_, | 543 EmitHexDump(response_data_->data(), amount_read_, |
539 response_info_->response_data_size(), out); | 544 response_info_->response_data_size(), out); |
540 } else { | 545 } else { |
541 out->append("Failed to read response data.<br>"); | 546 out->append("Failed to read response data.<br>"); |
542 } | 547 } |
543 } else { | 548 } else { |
544 out->append("Failed to read response headers and data.<br>"); | 549 out->append("Failed to read response headers and data.<br>"); |
545 } | 550 } |
546 EmitPageEnd(out); | 551 EmitPageEnd(out); |
547 return true; | 552 return net::OK; |
548 } | 553 } |
549 | 554 |
550 private: | 555 private: |
551 virtual ~ViewEntryJob() { | 556 virtual ~ViewEntryJob() { |
552 appcache_service_->storage()->CancelDelegateCallbacks(this); | 557 appcache_service_->storage()->CancelDelegateCallbacks(this); |
553 } | 558 } |
554 | 559 |
555 virtual void OnResponseInfoLoaded( | 560 virtual void OnResponseInfoLoaded( |
556 AppCacheResponseInfo* response_info, int64 response_id) OVERRIDE { | 561 AppCacheResponseInfo* response_info, int64 response_id) OVERRIDE { |
557 if (!response_info) { | 562 if (!response_info) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 return new ViewEntryJob(request, service, | 624 return new ViewEntryJob(request, service, |
620 DecodeBase64URL(tokens[0]), // manifest url | 625 DecodeBase64URL(tokens[0]), // manifest url |
621 DecodeBase64URL(tokens[1]), // entry url | 626 DecodeBase64URL(tokens[1]), // entry url |
622 response_id, group_id); | 627 response_id, group_id); |
623 } | 628 } |
624 | 629 |
625 return new RedirectToMainPageJob(request, service); | 630 return new RedirectToMainPageJob(request, service); |
626 } | 631 } |
627 | 632 |
628 } // namespace appcache | 633 } // namespace appcache |
OLD | NEW |