| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/webui/options/cookies_view_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_cookies_view_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 29 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
| 31 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
| 32 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
| 33 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
| 34 | 34 |
| 35 namespace storage { | 35 namespace storage { |
| 36 class FileSystemContext; | 36 class FileSystemContext; |
| 37 } | 37 } |
| 38 | 38 |
| 39 namespace options { | 39 namespace settings { |
| 40 | 40 |
| 41 CookiesViewHandler::CookiesViewHandler() | 41 CookiesViewHandler::CookiesViewHandler() |
| 42 : batch_update_(false), | 42 : batch_update_(false), |
| 43 model_util_(new CookiesTreeModelUtil) { | 43 model_util_(new CookiesTreeModelUtil) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 CookiesViewHandler::~CookiesViewHandler() { | 46 CookiesViewHandler::~CookiesViewHandler() { |
| 47 } | 47 } |
| 48 | 48 |
| 49 void CookiesViewHandler::GetLocalizedValues( | 49 void CookiesViewHandler::OnJavascriptAllowed() { |
| 50 base::DictionaryValue* localized_strings) { | 50 } |
| 51 DCHECK(localized_strings); | |
| 52 | 51 |
| 53 static OptionsStringResource resources[] = { | 52 void CookiesViewHandler::OnJavascriptDisallowed() { |
| 54 {"label_cookie_name", IDS_COOKIES_COOKIE_NAME_LABEL}, | |
| 55 {"label_cookie_content", IDS_COOKIES_COOKIE_CONTENT_LABEL}, | |
| 56 {"label_cookie_domain", IDS_COOKIES_COOKIE_DOMAIN_LABEL}, | |
| 57 {"label_cookie_path", IDS_COOKIES_COOKIE_PATH_LABEL}, | |
| 58 {"label_cookie_send_for", IDS_COOKIES_COOKIE_SENDFOR_LABEL}, | |
| 59 {"label_cookie_accessible_to_script", | |
| 60 IDS_COOKIES_COOKIE_ACCESSIBLE_TO_SCRIPT_LABEL}, | |
| 61 {"label_cookie_created", IDS_COOKIES_COOKIE_CREATED_LABEL}, | |
| 62 {"label_cookie_expires", IDS_COOKIES_COOKIE_EXPIRES_LABEL}, | |
| 63 {"label_webdb_desc", IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL}, | |
| 64 {"label_local_storage_size", | |
| 65 IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL}, | |
| 66 {"label_local_storage_last_modified", | |
| 67 IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL}, | |
| 68 {"label_local_storage_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL}, | |
| 69 {"label_indexed_db_size", IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL}, | |
| 70 {"label_indexed_db_last_modified", | |
| 71 IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL}, | |
| 72 {"label_indexed_db_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL}, | |
| 73 {"label_service_worker_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL}, | |
| 74 {"label_service_worker_size", | |
| 75 IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL}, | |
| 76 {"label_service_worker_scopes", IDS_COOKIES_SERVICE_WORKER_SCOPES_LABEL}, | |
| 77 {"label_cache_storage_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL}, | |
| 78 {"label_cache_storage_size", | |
| 79 IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL}, | |
| 80 {"label_cache_storage_last_modified", | |
| 81 IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL}, | |
| 82 {"label_app_cache_manifest", | |
| 83 IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL}, | |
| 84 {"label_cookie_last_accessed", IDS_COOKIES_LAST_ACCESSED_LABEL}, | |
| 85 {"cookie_domain", IDS_COOKIES_DOMAIN_COLUMN_HEADER}, | |
| 86 {"cookie_local_data", IDS_COOKIES_DATA_COLUMN_HEADER}, | |
| 87 {"cookie_singular", IDS_COOKIES_SINGLE_COOKIE}, | |
| 88 {"cookie_plural", IDS_COOKIES_PLURAL_COOKIES}, | |
| 89 {"cookie_database_storage", IDS_COOKIES_DATABASE_STORAGE}, | |
| 90 {"cookie_indexed_db", IDS_COOKIES_INDEXED_DB}, | |
| 91 {"cookie_local_storage", IDS_COOKIES_LOCAL_STORAGE}, | |
| 92 {"cookie_app_cache", IDS_COOKIES_APPLICATION_CACHE}, | |
| 93 {"cookie_service_worker", IDS_COOKIES_SERVICE_WORKER}, | |
| 94 {"cookie_cache_storage", IDS_COOKIES_CACHE_STORAGE}, | |
| 95 {"cookie_flash_lso", IDS_COOKIES_FLASH_LSO}, | |
| 96 {"search_cookies", IDS_COOKIES_SEARCH_COOKIES}, | |
| 97 {"remove_cookie", IDS_COOKIES_REMOVE_LABEL}, | |
| 98 {"remove_all_cookie", IDS_COOKIES_REMOVE_ALL_LABEL}, | |
| 99 {"remove_all_shown_cookie", IDS_COOKIES_REMOVE_ALL_SHOWN_LABEL}, | |
| 100 {"cookie_file_system", IDS_COOKIES_FILE_SYSTEM}, | |
| 101 {"label_file_system_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL}, | |
| 102 {"label_file_system_temporary_usage", | |
| 103 IDS_COOKIES_FILE_SYSTEM_TEMPORARY_USAGE_LABEL}, | |
| 104 {"label_file_system_persistent_usage", | |
| 105 IDS_COOKIES_FILE_SYSTEM_PERSISTENT_USAGE_LABEL}, | |
| 106 {"cookie_channel_id", IDS_COOKIES_CHANNEL_ID}, | |
| 107 {"label_channel_id_server_id", IDS_COOKIES_CHANNEL_ID_ORIGIN_LABEL}, | |
| 108 {"label_channel_id_type", IDS_COOKIES_CHANNEL_ID_TYPE_LABEL}, | |
| 109 {"label_channel_id_created", IDS_COOKIES_CHANNEL_ID_CREATED_LABEL}, | |
| 110 {"label_channel_id_expires", IDS_COOKIES_CHANNEL_ID_EXPIRES_LABEL}, | |
| 111 {"label_protected_by_apps", | |
| 112 IDS_GEOLOCATION_SET_BY_HOVER}, // TODO(bauerb): Use a better string | |
| 113 }; | |
| 114 | |
| 115 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 116 RegisterTitle(localized_strings, "cookiesViewPage", | |
| 117 IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); | |
| 118 } | 53 } |
| 119 | 54 |
| 120 void CookiesViewHandler::RegisterMessages() { | 55 void CookiesViewHandler::RegisterMessages() { |
| 121 web_ui()->RegisterMessageCallback("updateCookieSearchResults", | 56 web_ui()->RegisterMessageCallback("updateCookieSearchResults", |
| 122 base::Bind(&CookiesViewHandler::UpdateSearchResults, | 57 base::Bind(&CookiesViewHandler::UpdateSearchResults, |
| 123 base::Unretained(this))); | 58 base::Unretained(this))); |
| 124 web_ui()->RegisterMessageCallback("removeAllCookies", | 59 web_ui()->RegisterMessageCallback("removeAllCookies", |
| 125 base::Bind(&CookiesViewHandler::RemoveAll, | 60 base::Bind(&CookiesViewHandler::RemoveAll, |
| 126 base::Unretained(this))); | 61 base::Unretained(this))); |
| 127 web_ui()->RegisterMessageCallback("removeCookie", | 62 web_ui()->RegisterMessageCallback("removeCookie", |
| 128 base::Bind(&CookiesViewHandler::Remove, | 63 base::Bind(&CookiesViewHandler::Remove, |
| 129 base::Unretained(this))); | 64 base::Unretained(this))); |
| 130 web_ui()->RegisterMessageCallback("loadCookie", | 65 web_ui()->RegisterMessageCallback("loadCookie", |
| 131 base::Bind(&CookiesViewHandler::LoadChildren, | 66 base::Bind(&CookiesViewHandler::LoadChildren, |
| 132 base::Unretained(this))); | 67 base::Unretained(this))); |
| 133 web_ui()->RegisterMessageCallback("reloadCookies", | 68 web_ui()->RegisterMessageCallback("reloadCookies", |
| 134 base::Bind(&CookiesViewHandler::ReloadCookies, | 69 base::Bind(&CookiesViewHandler::ReloadCookies, |
| 135 base::Unretained(this))); | 70 base::Unretained(this))); |
| 136 } | 71 } |
| 137 | 72 |
| 138 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, | 73 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, |
| 139 ui::TreeModelNode* parent, | 74 ui::TreeModelNode* parent, |
| 140 int start, | 75 int start, |
| 141 int count) { | 76 int count) { |
| 142 // Skip if there is a batch update in progress. | 77 // Skip if there is a batch update in progress. |
| 143 if (batch_update_) | 78 if (batch_update_) |
| 144 return; | 79 return; |
| 145 | 80 |
| 81 AllowJavascript(); |
| 82 |
| 146 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | 83 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
| 147 CookieTreeNode* parent_node = tree_model->AsNode(parent); | 84 CookieTreeNode* parent_node = tree_model->AsNode(parent); |
| 148 | 85 |
| 149 std::unique_ptr<base::ListValue> children(new base::ListValue); | 86 std::unique_ptr<base::ListValue> children(new base::ListValue); |
| 150 model_util_->GetChildNodeList(parent_node, start, count, children.get()); | 87 model_util_->GetChildNodeList(parent_node, start, count, children.get()); |
| 151 | 88 |
| 152 base::ListValue args; | 89 base::ListValue args; |
| 153 if (parent == tree_model->GetRoot()) | 90 if (parent == tree_model->GetRoot()) |
| 154 args.Append(base::Value::CreateNullValue()); | 91 args.Append(base::Value::CreateNullValue()); |
| 155 else | 92 else |
| 156 args.AppendString(model_util_->GetTreeNodeId(parent_node)); | 93 args.AppendString(model_util_->GetTreeNodeId(parent_node)); |
| 157 args.AppendInteger(start); | 94 args.AppendInteger(start); |
| 158 args.Append(std::move(children)); | 95 args.Append(std::move(children)); |
| 159 web_ui()->CallJavascriptFunctionUnsafe("CookiesView.onTreeItemAdded", args); | 96 CallJavascriptFunction("cr.webUIListenerCallback", |
| 97 base::StringValue("onTreeItemAdded"), |
| 98 args); |
| 160 } | 99 } |
| 161 | 100 |
| 162 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, | 101 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
| 163 ui::TreeModelNode* parent, | 102 ui::TreeModelNode* parent, |
| 164 int start, | 103 int start, |
| 165 int count) { | 104 int count) { |
| 166 // Skip if there is a batch update in progress. | 105 // Skip if there is a batch update in progress. |
| 167 if (batch_update_) | 106 if (batch_update_) |
| 168 return; | 107 return; |
| 169 | 108 |
| 109 AllowJavascript(); |
| 110 |
| 170 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | 111 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
| 171 | 112 |
| 172 base::ListValue args; | 113 base::ListValue args; |
| 173 if (parent == tree_model->GetRoot()) | 114 if (parent == tree_model->GetRoot()) |
| 174 args.Append(base::Value::CreateNullValue()); | 115 args.Append(base::Value::CreateNullValue()); |
| 175 else | 116 else |
| 176 args.AppendString(model_util_->GetTreeNodeId(tree_model->AsNode(parent))); | 117 args.AppendString(model_util_->GetTreeNodeId(tree_model->AsNode(parent))); |
| 177 args.AppendInteger(start); | 118 args.AppendInteger(start); |
| 178 args.AppendInteger(count); | 119 args.AppendInteger(count); |
| 179 web_ui()->CallJavascriptFunctionUnsafe("CookiesView.onTreeItemRemoved", args); | 120 CallJavascriptFunction("cr.webUIListenerCallback", |
| 121 base::StringValue("onTreeItemRemoved"), |
| 122 args); |
| 180 } | 123 } |
| 181 | 124 |
| 182 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { | 125 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
| 183 DCHECK(!batch_update_); // There should be no nested batch begin. | 126 DCHECK(!batch_update_); // There should be no nested batch begin. |
| 184 batch_update_ = true; | 127 batch_update_ = true; |
| 185 } | 128 } |
| 186 | 129 |
| 187 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { | 130 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { |
| 188 DCHECK(batch_update_); | 131 DCHECK(batch_update_); |
| 189 batch_update_ = false; | 132 batch_update_ = false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 202 |
| 260 EnsureCookiesTreeModelCreated(); | 203 EnsureCookiesTreeModelCreated(); |
| 261 | 204 |
| 262 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( | 205 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( |
| 263 cookies_tree_model_->GetRoot(), node_path); | 206 cookies_tree_model_->GetRoot(), node_path); |
| 264 if (node) | 207 if (node) |
| 265 SendChildren(node); | 208 SendChildren(node); |
| 266 } | 209 } |
| 267 | 210 |
| 268 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { | 211 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { |
| 212 AllowJavascript(); |
| 213 |
| 269 std::unique_ptr<base::ListValue> children(new base::ListValue); | 214 std::unique_ptr<base::ListValue> children(new base::ListValue); |
| 270 model_util_->GetChildNodeList(parent, 0, parent->child_count(), | 215 model_util_->GetChildNodeList(parent, 0, parent->child_count(), |
| 271 children.get()); | 216 children.get()); |
| 272 | 217 |
| 273 base::ListValue args; | 218 base::ListValue args; |
| 274 if (parent == cookies_tree_model_->GetRoot()) | 219 if (parent == cookies_tree_model_->GetRoot()) |
| 275 args.Append(base::Value::CreateNullValue()); | 220 args.Append(base::Value::CreateNullValue()); |
| 276 else | 221 else |
| 277 args.AppendString(model_util_->GetTreeNodeId(parent)); | 222 args.AppendString(model_util_->GetTreeNodeId(parent)); |
| 278 args.Append(std::move(children)); | 223 args.Append(std::move(children)); |
| 279 | 224 |
| 280 web_ui()->CallJavascriptFunctionUnsafe("CookiesView.loadChildren", args); | 225 CallJavascriptFunction("cr.webUIListenerCallback", |
| 226 base::StringValue("loadChildren"), |
| 227 args); |
| 281 } | 228 } |
| 282 | 229 |
| 283 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) { | 230 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) { |
| 284 cookies_tree_model_.reset(); | 231 cookies_tree_model_.reset(); |
| 285 | 232 |
| 286 EnsureCookiesTreeModelCreated(); | 233 EnsureCookiesTreeModelCreated(); |
| 287 } | 234 } |
| 288 | 235 |
| 289 } // namespace options | 236 } // namespace settings |
| OLD | NEW |