| 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" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 net::NetworkDelegate* network_delegate, | 328 net::NetworkDelegate* network_delegate, |
| 329 AppCacheService* service) | 329 AppCacheService* service) |
| 330 : BaseInternalsJob(request, network_delegate, service), | 330 : BaseInternalsJob(request, network_delegate, service), |
| 331 weak_factory_(this) { | 331 weak_factory_(this) { |
| 332 } | 332 } |
| 333 | 333 |
| 334 virtual void Start() OVERRIDE { | 334 virtual void Start() OVERRIDE { |
| 335 DCHECK(request_); | 335 DCHECK(request_); |
| 336 info_collection_ = new AppCacheInfoCollection; | 336 info_collection_ = new AppCacheInfoCollection; |
| 337 appcache_service_->GetAllAppCacheInfo( | 337 appcache_service_->GetAllAppCacheInfo( |
| 338 info_collection_, base::Bind(&MainPageJob::OnGotInfoComplete, | 338 info_collection_.get(), |
| 339 weak_factory_.GetWeakPtr())); | 339 base::Bind(&MainPageJob::OnGotInfoComplete, |
| 340 weak_factory_.GetWeakPtr())); |
| 340 } | 341 } |
| 341 | 342 |
| 342 // Produces a page containing the listing | 343 // Produces a page containing the listing |
| 343 virtual int GetData(std::string* mime_type, | 344 virtual int GetData(std::string* mime_type, |
| 344 std::string* charset, | 345 std::string* charset, |
| 345 std::string* out, | 346 std::string* out, |
| 346 const net::CompletionCallback& callback) const OVERRIDE { | 347 const net::CompletionCallback& callback) const OVERRIDE { |
| 347 mime_type->assign("text/html"); | 348 mime_type->assign("text/html"); |
| 348 charset->assign("UTF-8"); | 349 charset->assign("UTF-8"); |
| 349 | 350 |
| 350 out->clear(); | 351 out->clear(); |
| 351 EmitPageStart(out); | 352 EmitPageStart(out); |
| 352 if (!info_collection_) { | 353 if (!info_collection_.get()) { |
| 353 out->append(kErrorMessage); | 354 out->append(kErrorMessage); |
| 354 } else if (info_collection_->infos_by_origin.empty()) { | 355 } else if (info_collection_->infos_by_origin.empty()) { |
| 355 out->append(kEmptyAppCachesMessage); | 356 out->append(kEmptyAppCachesMessage); |
| 356 } else { | 357 } else { |
| 357 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; | 358 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; |
| 358 AppCacheInfoVector appcaches; | 359 AppCacheInfoVector appcaches; |
| 359 for (InfoByOrigin::const_iterator origin = | 360 for (InfoByOrigin::const_iterator origin = |
| 360 info_collection_->infos_by_origin.begin(); | 361 info_collection_->infos_by_origin.begin(); |
| 361 origin != info_collection_->infos_by_origin.end(); ++origin) { | 362 origin != info_collection_->infos_by_origin.end(); ++origin) { |
| 362 appcaches.insert(appcaches.end(), | 363 appcaches.insert(appcaches.end(), |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 virtual int GetData(std::string* mime_type, | 542 virtual int GetData(std::string* mime_type, |
| 542 std::string* charset, | 543 std::string* charset, |
| 543 std::string* out, | 544 std::string* out, |
| 544 const net::CompletionCallback& callback) const OVERRIDE { | 545 const net::CompletionCallback& callback) const OVERRIDE { |
| 545 mime_type->assign("text/html"); | 546 mime_type->assign("text/html"); |
| 546 charset->assign("UTF-8"); | 547 charset->assign("UTF-8"); |
| 547 out->clear(); | 548 out->clear(); |
| 548 EmitPageStart(out); | 549 EmitPageStart(out); |
| 549 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); | 550 EmitAnchor(entry_url_.spec(), entry_url_.spec(), out); |
| 550 out->append("<br/>\n"); | 551 out->append("<br/>\n"); |
| 551 if (response_info_) { | 552 if (response_info_.get()) { |
| 552 if (response_info_->http_response_info()) | 553 if (response_info_->http_response_info()) |
| 553 EmitResponseHeaders(response_info_->http_response_info()->headers, out); | 554 EmitResponseHeaders(response_info_->http_response_info()->headers.get(), |
| 555 out); |
| 554 else | 556 else |
| 555 out->append("Failed to read response headers.<br>"); | 557 out->append("Failed to read response headers.<br>"); |
| 556 | 558 |
| 557 if (response_data_) { | 559 if (response_data_.get()) { |
| 558 EmitHexDump(response_data_->data(), amount_read_, | 560 EmitHexDump(response_data_->data(), |
| 559 response_info_->response_data_size(), out); | 561 amount_read_, |
| 562 response_info_->response_data_size(), |
| 563 out); |
| 560 } else { | 564 } else { |
| 561 out->append("Failed to read response data.<br>"); | 565 out->append("Failed to read response data.<br>"); |
| 562 } | 566 } |
| 563 } else { | 567 } else { |
| 564 out->append("Failed to read response headers and data.<br>"); | 568 out->append("Failed to read response headers and data.<br>"); |
| 565 } | 569 } |
| 566 EmitPageEnd(out); | 570 EmitPageEnd(out); |
| 567 return net::OK; | 571 return net::OK; |
| 568 } | 572 } |
| 569 | 573 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 582 | 586 |
| 583 // Read the response data, truncating if its too large. | 587 // Read the response data, truncating if its too large. |
| 584 const int64 kLimit = 100 * 1000; | 588 const int64 kLimit = 100 * 1000; |
| 585 int64 amount_to_read = | 589 int64 amount_to_read = |
| 586 std::min(kLimit, response_info->response_data_size()); | 590 std::min(kLimit, response_info->response_data_size()); |
| 587 response_data_ = new net::IOBuffer(amount_to_read); | 591 response_data_ = new net::IOBuffer(amount_to_read); |
| 588 | 592 |
| 589 reader_.reset(appcache_service_->storage()->CreateResponseReader( | 593 reader_.reset(appcache_service_->storage()->CreateResponseReader( |
| 590 manifest_url_, group_id_, response_id_)); | 594 manifest_url_, group_id_, response_id_)); |
| 591 reader_->ReadData( | 595 reader_->ReadData( |
| 592 response_data_, amount_to_read, | 596 response_data_.get(), |
| 597 amount_to_read, |
| 593 base::Bind(&ViewEntryJob::OnReadComplete, base::Unretained(this))); | 598 base::Bind(&ViewEntryJob::OnReadComplete, base::Unretained(this))); |
| 594 } | 599 } |
| 595 | 600 |
| 596 void OnReadComplete(int result) { | 601 void OnReadComplete(int result) { |
| 597 reader_.reset(); | 602 reader_.reset(); |
| 598 amount_read_ = result; | 603 amount_read_ = result; |
| 599 if (result < 0) | 604 if (result < 0) |
| 600 response_data_ = NULL; | 605 response_data_ = NULL; |
| 601 StartAsync(); | 606 StartAsync(); |
| 602 } | 607 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 return new ViewEntryJob(request, network_delegate, service, | 646 return new ViewEntryJob(request, network_delegate, service, |
| 642 DecodeBase64URL(tokens[0]), // manifest url | 647 DecodeBase64URL(tokens[0]), // manifest url |
| 643 DecodeBase64URL(tokens[1]), // entry url | 648 DecodeBase64URL(tokens[1]), // entry url |
| 644 response_id, group_id); | 649 response_id, group_id); |
| 645 } | 650 } |
| 646 | 651 |
| 647 return new RedirectToMainPageJob(request, network_delegate, service); | 652 return new RedirectToMainPageJob(request, network_delegate, service); |
| 648 } | 653 } |
| 649 | 654 |
| 650 } // namespace appcache | 655 } // namespace appcache |
| OLD | NEW |