Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / cookies_tree_model_util.cc
index 520e799..6ee0e4a 100644 (file)
@@ -15,6 +15,7 @@
 #include "base/values.h"
 #include "chrome/browser/browsing_data/cookies_tree_model.h"
 #include "content/public/browser/indexed_db_context.h"
+#include "content/public/browser/service_worker_context.h"
 #include "grit/generated_resources.h"
 #include "net/cookies/canonical_cookie.h"
 #include "net/ssl/ssl_client_cert_type.h"
 #include "ui/base/text/bytes_formatting.h"
 #include "webkit/common/fileapi/file_system_types.h"
 
+#if defined(ENABLE_EXTENSIONS)
+#include "extensions/common/extension_set.h"
+#endif
+
 namespace {
 
 const char kKeyId[] = "id";
@@ -30,7 +35,9 @@ const char kKeyIcon[] = "icon";
 const char kKeyType[] = "type";
 const char kKeyHasChildren[] = "hasChildren";
 
+#if defined(ENABLE_EXTENSIONS)
 const char kKeyAppsProtectingThis[] = "appsProtectingThis";
+#endif
 const char kKeyName[] = "name";
 const char kKeyContent[] = "content";
 const char kKeyDomain[] = "domain";
@@ -57,6 +64,8 @@ const char kKeyPersistentUsage[] = "persistentUsage";
 
 const char kKeyCertType[] = "certType";
 
+const char kKeyScopes[] = "scopes";
+
 const int64 kNegligibleUsage = 1024;  // 1KiB
 
 std::string ClientCertTypeToString(net::SSLClientCertType type) {
@@ -123,9 +132,9 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
           l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_ACCESSIBLE_TO_SCRIPT_NO) :
           l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_ACCESSIBLE_TO_SCRIPT_YES);
       dict->SetString(kKeyAccessibleToScript, accessible);
-      dict->SetString(kKeyCreated, UTF16ToUTF8(
+      dict->SetString(kKeyCreated, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(cookie.CreationDate())));
-      dict->SetString(kKeyExpires, cookie.IsPersistent() ? UTF16ToUTF8(
+      dict->SetString(kKeyExpires, cookie.IsPersistent() ? base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(cookie.ExpiryDate())) :
           l10n_util::GetStringUTF8(IDS_COOKIES_COOKIE_EXPIRES_SESSION));
 
@@ -143,7 +152,7 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
           database_info.database_name);
       dict->SetString(kKeyDesc, database_info.description);
       dict->SetString(kKeySize, ui::FormatBytes(database_info.size));
-      dict->SetString(kKeyModified, UTF16ToUTF8(
+      dict->SetString(kKeyModified, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(database_info.last_modified)));
 
       break;
@@ -157,7 +166,7 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
 
       dict->SetString(kKeyOrigin, local_storage_info.origin_url.spec());
       dict->SetString(kKeySize, ui::FormatBytes(local_storage_info.size));
-      dict->SetString(kKeyModified, UTF16ToUTF8(
+      dict->SetString(kKeyModified, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(
               local_storage_info.last_modified)));
 
@@ -167,14 +176,14 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
       dict->SetString(kKeyType, "app_cache");
       dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON");
 
-      const appcache::AppCacheInfo& appcache_info =
+      const content::AppCacheInfo& appcache_info =
           *node.GetDetailedInfo().appcache_info;
 
       dict->SetString(kKeyManifest, appcache_info.manifest_url.spec());
       dict->SetString(kKeySize, ui::FormatBytes(appcache_info.size));
-      dict->SetString(kKeyCreated, UTF16ToUTF8(
+      dict->SetString(kKeyCreated, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(appcache_info.creation_time)));
-      dict->SetString(kKeyAccessed, UTF16ToUTF8(
+      dict->SetString(kKeyAccessed, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(appcache_info.last_access_time)));
 
       break;
@@ -188,7 +197,7 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
 
       dict->SetString(kKeyOrigin, indexed_db_info.origin_.spec());
       dict->SetString(kKeySize, ui::FormatBytes(indexed_db_info.size_));
-      dict->SetString(kKeyModified, UTF16ToUTF8(
+      dict->SetString(kKeyModified, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(indexed_db_info.last_modified_)));
 
       break;
@@ -205,13 +214,13 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
       dict->SetString(kKeyOrigin, file_system_info.origin.spec());
       dict->SetString(kKeyPersistent,
                       ContainsKey(file_system_info.usage_map, kPerm) ?
-                          UTF16ToUTF8(ui::FormatBytes(
+                          base::UTF16ToUTF8(ui::FormatBytes(
                               file_system_info.usage_map.find(kPerm)->second)) :
                           l10n_util::GetStringUTF8(
                               IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
       dict->SetString(kKeyTemporary,
                       ContainsKey(file_system_info.usage_map, kTemp) ?
-                          UTF16ToUTF8(ui::FormatBytes(
+                          base::UTF16ToUTF8(ui::FormatBytes(
                               file_system_info.usage_map.find(kTemp)->second)) :
                           l10n_util::GetStringUTF8(
                               IDS_COOKIES_FILE_SYSTEM_USAGE_NONE));
@@ -229,30 +238,48 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
 
       dict->SetString(kKeyOrigin, quota_info.host);
       dict->SetString(kKeyTotalUsage,
-                      UTF16ToUTF8(ui::FormatBytes(
+                      base::UTF16ToUTF8(ui::FormatBytes(
                           quota_info.temporary_usage +
                           quota_info.persistent_usage)));
       dict->SetString(kKeyTemporaryUsage,
-                      UTF16ToUTF8(ui::FormatBytes(
+                      base::UTF16ToUTF8(ui::FormatBytes(
                           quota_info.temporary_usage)));
       dict->SetString(kKeyPersistentUsage,
-                      UTF16ToUTF8(ui::FormatBytes(
+                      base::UTF16ToUTF8(ui::FormatBytes(
                           quota_info.persistent_usage)));
       break;
     }
-    case CookieTreeNode::DetailedInfo::TYPE_SERVER_BOUND_CERT: {
-      dict->SetString(kKeyType, "server_bound_cert");
+    case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: {
+      dict->SetString(kKeyType, "channel_id");
       dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_ICON");
 
-      const net::ServerBoundCertStore::ServerBoundCert& server_bound_cert =
-          *node.GetDetailedInfo().server_bound_cert;
+      const net::ChannelIDStore::ChannelID& channel_id =
+          *node.GetDetailedInfo().channel_id;
 
-      dict->SetString(kKeyServerId, server_bound_cert.server_identifier());
+      dict->SetString(kKeyServerId, channel_id.server_identifier());
       dict->SetString(kKeyCertType,
                       ClientCertTypeToString(net::CLIENT_CERT_ECDSA_SIGN));
-      dict->SetString(kKeyCreated, UTF16ToUTF8(
+      dict->SetString(kKeyCreated, base::UTF16ToUTF8(
           base::TimeFormatFriendlyDateAndTime(
-              server_bound_cert.creation_time())));
+              channel_id.creation_time())));
+      break;
+    }
+    case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: {
+      dict->SetString(kKeyType, "service_worker");
+      dict->SetString(kKeyIcon, "chrome://theme/IDR_COOKIE_STORAGE_ICON");
+
+      const content::ServiceWorkerUsageInfo& service_worker_info =
+          *node.GetDetailedInfo().service_worker_info;
+
+      dict->SetString(kKeyOrigin, service_worker_info.origin.spec());
+      base::ListValue* scopes = new base::ListValue;
+      for (std::vector<GURL>::const_iterator it =
+               service_worker_info.scopes.begin();
+           it != service_worker_info.scopes.end();
+           ++it) {
+        scopes->AppendString(it->spec());
+      }
+      dict->Set(kKeyScopes, scopes);
       break;
     }
     case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: {
@@ -268,11 +295,12 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
       break;
   }
 
-  const ExtensionSet* protecting_apps =
+#if defined(ENABLE_EXTENSIONS)
+  const extensions::ExtensionSet* protecting_apps =
       node.GetModel()->ExtensionsProtectingNode(node);
   if (protecting_apps && !protecting_apps->is_empty()) {
     base::ListValue* app_infos = new base::ListValue;
-    for (ExtensionSet::const_iterator it = protecting_apps->begin();
+    for (extensions::ExtensionSet::const_iterator it = protecting_apps->begin();
          it != protecting_apps->end(); ++it) {
       base::DictionaryValue* app_info = new base::DictionaryValue();
       app_info->SetString(kKeyId, (*it)->id());
@@ -281,6 +309,7 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary(
     }
     dict->Set(kKeyAppsProtectingThis, app_infos);
   }
+#endif
 
   return true;
 }
@@ -290,7 +319,7 @@ void CookiesTreeModelUtil::GetChildNodeList(const CookieTreeNode* parent,
                                             int count,
                                             base::ListValue* nodes) {
   for (int i = 0; i < count; ++i) {
-    scoped_ptr<base::DictionaryValue> dict(new DictionaryValue);
+    scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
     const CookieTreeNode* child = parent->GetChild(start + i);
     if (GetCookieTreeNodeDictionary(*child, dict.get()))
       nodes->Append(dict.release());