summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkkanetkar@chromium.org <kkanetkar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-27 01:36:43 +0000
committerkkanetkar@chromium.org <kkanetkar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-27 01:36:43 +0000
commit042ecea347c6984c3263671f45ebec79e9fbb26f (patch)
treebfedface274ededad945b9c7d7871a19941d56ee
parent43929df205159d29c8e968e93c8572b05c92de17 (diff)
downloadchromium_src-042ecea347c6984c3263671f45ebec79e9fbb26f.zip
chromium_src-042ecea347c6984c3263671f45ebec79e9fbb26f.tar.gz
chromium_src-042ecea347c6984c3263671f45ebec79e9fbb26f.tar.bz2
A basic implementation of information about appcache. Lists manifest files, time and size information.
BUG=38463 TEST=Run chrome, navigate to about:appcache-internals. Review URL: http://codereview.chromium.org/1109009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42888 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/appcache/view_appcache_internals_job_factory.cc28
-rw-r--r--chrome/browser/appcache/view_appcache_internals_job_factory.h19
-rw-r--r--chrome/browser/browser_about_handler.cc6
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.cc6
-rwxr-xr-xchrome/chrome_browser.gypi2
-rw-r--r--chrome/common/url_constants.cc3
-rw-r--r--chrome/common/url_constants.h4
-rw-r--r--net/url_request/url_request_simple_job.h3
-rw-r--r--webkit/appcache/view_appcache_internals_job.cc167
-rw-r--r--webkit/appcache/view_appcache_internals_job.h54
-rw-r--r--webkit/appcache/webkit_appcache.gypi2
11 files changed, 292 insertions, 2 deletions
diff --git a/chrome/browser/appcache/view_appcache_internals_job_factory.cc b/chrome/browser/appcache/view_appcache_internals_job_factory.cc
new file mode 100644
index 0000000..3f908af
--- /dev/null
+++ b/chrome/browser/appcache/view_appcache_internals_job_factory.cc
@@ -0,0 +1,28 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/appcache/view_appcache_internals_job_factory.h"
+
+#include "chrome/browser/net/chrome_url_request_context.h"
+#include "chrome/common/url_constants.h"
+#include "webkit/appcache/appcache_service.h"
+#include "webkit/appcache/view_appcache_internals_job.h"
+
+// static.
+bool ViewAppCacheInternalsJobFactory::IsSupportedURL(const GURL& url) {
+ return StartsWithASCII(url.spec(),
+ chrome::kAppCacheViewInternalsURL,
+ true /*case_sensitive*/);
+}
+
+// static.
+URLRequestJob* ViewAppCacheInternalsJobFactory::CreateJobForRequest(
+ URLRequest* request) {
+ URLRequestContext* context = request->context();
+ ChromeURLRequestContext* chrome_request_context =
+ reinterpret_cast<ChromeURLRequestContext*>(context);
+ return new appcache::ViewAppCacheInternalsJob(
+ request, chrome_request_context->appcache_service());
+}
+
diff --git a/chrome/browser/appcache/view_appcache_internals_job_factory.h b/chrome/browser/appcache/view_appcache_internals_job_factory.h
new file mode 100644
index 0000000..50ee303
--- /dev/null
+++ b/chrome/browser/appcache/view_appcache_internals_job_factory.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_APPCACHE_VIEW_APPCACHE_INTERNALS_JOB_FACTORY_H_
+#define CHROME_BROWSER_APPCACHE_VIEW_APPCACHE_INTERNALS_JOB_FACTORY_H_
+
+class GURL;
+class URLRequest;
+class URLRequestJob;
+
+class ViewAppCacheInternalsJobFactory {
+ public:
+ static bool IsSupportedURL(const GURL& url);
+ static URLRequestJob* CreateJobForRequest(URLRequest* request);
+};
+
+#endif // CHROME_BROWSER_APPCACHE_VIEW_APPCACHE_INTERNALS_JOB_FACTORY_H_
+
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index 91be7c2..04955ec 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -895,6 +895,12 @@ bool WillHandleBrowserAboutURL(GURL* url, Profile* profile) {
return true;
}
+ // Rewrite about:appcache-internals/* URLs to chrome://appcache/*
+ if (StartsWithAboutSpecifier(*url, chrome::kAboutAppCacheInternalsURL)) {
+ *url = RemapAboutURL(chrome::kAppCacheViewInternalsURL, *url);
+ return true;
+ }
+
// Rewrite about:plugins to chrome://plugins/.
if (LowerCaseEqualsASCII(url->spec(), chrome::kAboutPluginsURL)) {
*url = GURL(chrome::kChromeUIPluginsURL);
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc
index 46a26f4..73594d4 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc
@@ -16,6 +16,7 @@
#if defined(OS_WIN)
#include "base/win_util.h"
#endif
+#include "chrome/browser/appcache/view_appcache_internals_job_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/net/chrome_url_request_context.h"
@@ -31,7 +32,6 @@
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job.h"
-
// URLRequestChromeJob is a URLRequestJob that manages running chrome-internal
// resource requests asynchronously.
// It hands off URL requests to ChromeURLDataManager, which asynchronously
@@ -314,6 +314,10 @@ URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request,
if (ViewNetInternalsJobFactory::IsSupportedURL(request->url()))
return ViewNetInternalsJobFactory::CreateJobForRequest(request);
+ // Next check for chrome://appcache-internals/, which uses its own job type.
+ if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url()))
+ return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request);
+
// Fall back to using a custom handler
return new URLRequestChromeJob(request);
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 665c2ed..fffb3d3 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -73,6 +73,8 @@
'browser/appcache/appcache_frontend_proxy.h',
'browser/appcache/chrome_appcache_service.cc',
'browser/appcache/chrome_appcache_service.h',
+ 'browser/appcache/view_appcache_internals_job_factory.cc',
+ 'browser/appcache/view_appcache_internals_job_factory.h',
'browser/autocomplete/autocomplete.cc',
'browser/autocomplete/autocomplete.h',
'browser/autocomplete/autocomplete_accessibility.cc',
diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc
index fc7198d..efb6d25 100644
--- a/chrome/common/url_constants.cc
+++ b/chrome/common/url_constants.cc
@@ -36,6 +36,7 @@ const char* kSavableSchemes[] = {
NULL
};
+const char kAboutAppCacheInternalsURL[] = "about:appcache-internals";
const char kAboutBlankURL[] = "about:blank";
const char kAboutCacheURL[] = "about:cache";
const char kAboutCrashURL[] = "about:crash";
@@ -94,6 +95,8 @@ const char kSyncThrobberPath[] = "throbber.png";
const char kSyncSetupFlowPath[] = "setup";
const char kSyncSetupDonePath[] = "setupdone";
+const char kAppCacheViewInternalsURL[] = "chrome://appcache-internals/";
+
const char kNetworkViewInternalsURL[] = "chrome://net-internals/";
const char kNetworkViewCacheURL[] = "chrome://net-internals/view-cache";
diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h
index 4118a99..7748df8 100644
--- a/chrome/common/url_constants.h
+++ b/chrome/common/url_constants.h
@@ -33,6 +33,7 @@ extern const char kStandardSchemeSeparator[];
extern const char* kSavableSchemes[];
// About URLs (including schemes).
+extern const char kAboutAppCacheInternalsURL[];
extern const char kAboutBlankURL[];
extern const char kAboutBrowserCrash[];
extern const char kAboutCacheURL[];
@@ -92,6 +93,9 @@ extern const char kSyncThrobberPath[];
extern const char kSyncSetupFlowPath[];
extern const char kSyncSetupDonePath[];
+// AppCache related URL.
+extern const char kAppCacheViewInternalsURL[];
+
// Network related URLs.
extern const char kNetworkViewCacheURL[];
extern const char kNetworkViewInternalsURL[];
diff --git a/net/url_request/url_request_simple_job.h b/net/url_request/url_request_simple_job.h
index 786d2e4..4ea856c 100644
--- a/net/url_request/url_request_simple_job.h
+++ b/net/url_request/url_request_simple_job.h
@@ -28,9 +28,10 @@ class URLRequestSimpleJob : public URLRequestJob {
std::string* charset,
std::string* data) const = 0;
- private:
+ protected:
void StartAsync();
+ private:
std::string mime_type_;
std::string charset_;
std::string data_;
diff --git a/webkit/appcache/view_appcache_internals_job.cc b/webkit/appcache/view_appcache_internals_job.cc
new file mode 100644
index 0000000..49384ac
--- /dev/null
+++ b/webkit/appcache/view_appcache_internals_job.cc
@@ -0,0 +1,167 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/appcache/view_appcache_internals_job.h"
+
+#include "base/logging.h"
+#include "base/format_macros.h"
+#include "base/utf_string_conversions.h"
+#include "base/i18n/time_formatting.h"
+#include "base/string_util.h"
+#include "webkit/appcache/appcache_service.h"
+
+namespace {
+
+const char kErrorMessage[] = "Error in retrieving Application caches.";
+const char kEmptyAppCachesMessage[] = "No available Application caches.";
+
+void StartHTML(std::string* out) {
+ DCHECK(out);
+ out->append(
+ "<!DOCTYPE HTML>"
+ "<html><head><title>AppCache Internals</title>"
+ "<style>"
+ "body { font-family: sans-serif; font-size: 0.8em; }\n"
+ "tt, code, pre { font-family: WebKitHack, monospace; }\n"
+ ".subsection_body { margin: 10px 0 10px 2em; }\n"
+ ".subsection_title { font-weight: bold; }\n"
+ "</style>");
+}
+
+void EndHTML(std::string* out) {
+ DCHECK(out);
+ out->append("</body></html>");
+}
+
+void AddLiTag(const std::string& element_title,
+ const std::string& element_data, std::string* out) {
+ DCHECK(out);
+ out->append("<li>");
+ out->append(element_title);
+ out->append(element_data);
+ out->append("</li>");
+}
+
+void WrapInHREF(const std::string& in, std::string* out) {
+ out->append("<a href='");
+ out->append(in);
+ out->append("'>");
+ out->append(in);
+ out->append("</a><br/>");
+}
+
+void AddHTMLFromAppCacheToOutput(
+ const appcache::AppCacheInfoVector& appcaches, std::string* out) {
+ for (std::vector<appcache::AppCacheInfo>::const_iterator info =
+ appcaches.begin();
+ info != appcaches.end(); ++info) {
+ out->append("<p>");
+ std::string anchored_manifest;
+ WrapInHREF(info->manifest_url.spec(), &anchored_manifest);
+ out->append("Manifest: ");
+ out->append(anchored_manifest);
+ out->append("<ul>");
+
+ AddLiTag("Size: ",
+ WideToUTF8(FormatBytes(
+ info->size, GetByteDisplayUnits(info->size), true)),
+ out);
+ AddLiTag("Creation Time: ",
+ WideToUTF8(TimeFormatFriendlyDateAndTime(
+ info->creation_time)),
+ out);
+ AddLiTag("Last Access Time: ",
+ WideToUTF8(
+ TimeFormatFriendlyDateAndTime(info->last_access_time)),
+ out);
+ AddLiTag("Last Update Time: ",
+ WideToUTF8(TimeFormatFriendlyDateAndTime(info->last_update_time)),
+ out);
+
+ out->append("</ul></p></br>");
+ }
+}
+
+struct ManifestURLComparator {
+ public:
+ bool operator() (
+ const appcache::AppCacheInfo& lhs,
+ const appcache::AppCacheInfo& rhs) const {
+ return (lhs.manifest_url.spec() < rhs.manifest_url.spec());
+ }
+} manifest_url_comparator;
+
+
+} // namespace
+
+namespace appcache {
+
+ViewAppCacheInternalsJob::ViewAppCacheInternalsJob(
+ URLRequest* request,
+ AppCacheService* service) : URLRequestSimpleJob(request),
+ appcache_service_(service) {
+}
+
+ViewAppCacheInternalsJob::~ViewAppCacheInternalsJob() {
+ // Cancel callback if job is destroyed before callback is called.
+ if (appcache_info_callback_)
+ appcache_info_callback_.release()->Cancel();
+}
+
+void ViewAppCacheInternalsJob::Start() {
+ if (!request_)
+ return;
+
+ info_collection_ = new AppCacheInfoCollection;
+ appcache_info_callback_ =
+ new net::CancelableCompletionCallback<ViewAppCacheInternalsJob>(
+ this, &ViewAppCacheInternalsJob::OnGotAppCacheInfo);
+
+ appcache_service_->GetAllAppCacheInfo(
+ info_collection_, appcache_info_callback_);
+}
+
+void ViewAppCacheInternalsJob::GenerateHTMLAppCacheInfo(
+ std::string* out) const {
+ typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin;
+ AppCacheInfoVector appcaches;
+ for (InfoByOrigin::const_iterator origin =
+ info_collection_->infos_by_origin.begin();
+ origin != info_collection_->infos_by_origin.end(); ++origin) {
+ for (AppCacheInfoVector::const_iterator info =
+ origin->second.begin(); info != origin->second.end(); ++info)
+ appcaches.push_back(*info);
+ }
+
+ std::sort(appcaches.begin(), appcaches.end(), manifest_url_comparator);
+
+ AddHTMLFromAppCacheToOutput(appcaches, out);
+}
+
+void ViewAppCacheInternalsJob::OnGotAppCacheInfo(int rv) {
+ appcache_info_callback_ = NULL;
+ if (rv != net::OK)
+ info_collection_ = NULL;
+ StartAsync();
+}
+
+bool ViewAppCacheInternalsJob::GetData(std::string* mime_type,
+ std::string* charset,
+ std::string* data) const {
+ mime_type->assign("text/html");
+ charset->assign("UTF-8");
+
+ data->clear();
+ StartHTML(data);
+ if (!info_collection_.get())
+ data->append(kErrorMessage);
+ else if (info_collection_->infos_by_origin.empty())
+ data->append(kEmptyAppCachesMessage);
+ else
+ GenerateHTMLAppCacheInfo(data);
+ EndHTML(data);
+ return true;
+}
+
+} // namespace appcache
diff --git a/webkit/appcache/view_appcache_internals_job.h b/webkit/appcache/view_appcache_internals_job.h
new file mode 100644
index 0000000..dd5c9cf
--- /dev/null
+++ b/webkit/appcache/view_appcache_internals_job.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_APPCACHE_VIEW_APPCACHE_INTERNALS_JOB_H_
+#define WEBKIT_APPCACHE_VIEW_APPCACHE_INTERNALS_JOB_H_
+
+#include <string>
+
+#include "net/url_request/url_request_simple_job.h"
+#include "webkit/appcache/appcache_service.h"
+
+class URLRequest;
+
+namespace appcache {
+
+// A job subclass that implements a protocol to inspect the internal
+// state of appcache service.
+class ViewAppCacheInternalsJob : public URLRequestSimpleJob {
+ public:
+ // Stores handle to appcache service for getting information.
+ ViewAppCacheInternalsJob(URLRequest* request, AppCacheService* service);
+
+ // Fetches the AppCache Info and calls StartAsync after it is done.
+ virtual void Start();
+
+ // URLRequestSimpleJob methods:
+ virtual bool GetData(std::string* mime_type,
+ std::string* charset,
+ std::string* data) const;
+
+ // Callback after asynchronously fetching contents for appcache service.
+ void OnGotAppCacheInfo(int rv);
+
+ private:
+ ~ViewAppCacheInternalsJob();
+
+ // Adds HTML from appcache information to out.
+ void GenerateHTMLAppCacheInfo(std::string* out) const;
+
+ // Callback for post-processing.
+ scoped_refptr<net::CancelableCompletionCallback<ViewAppCacheInternalsJob> >
+ appcache_info_callback_;
+ // Store appcache information.
+ scoped_refptr<AppCacheInfoCollection> info_collection_;
+ // Not owned.
+ AppCacheService* appcache_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(ViewAppCacheInternalsJob);
+};
+
+} // namespace appcache
+
+#endif // WEBKIT_APPCACHE_VIEW_APPCACHE_INTERNALS_JOB_H_
diff --git a/webkit/appcache/webkit_appcache.gypi b/webkit/appcache/webkit_appcache.gypi
index 61400af..968c525 100644
--- a/webkit/appcache/webkit_appcache.gypi
+++ b/webkit/appcache/webkit_appcache.gypi
@@ -56,6 +56,8 @@
'manifest_parser.h',
'mock_appcache_storage.cc',
'mock_appcache_storage.h',
+ 'view_appcache_internals_job.h',
+ 'view_appcache_internals_job.cc',
'web_application_cache_host_impl.cc',
'web_application_cache_host_impl.h',
],