Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: chrome/browser/ui/webui/options/cookies_view_handler.cc

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options/cookies_view_handler.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "chrome/browser/browsing_data_appcache_helper.h"
12 #include "chrome/browser/browsing_data_cookie_helper.h"
13 #include "chrome/browser/browsing_data_database_helper.h"
14 #include "chrome/browser/browsing_data_file_system_helper.h"
15 #include "chrome/browser/browsing_data_indexed_db_helper.h"
16 #include "chrome/browser/browsing_data_quota_helper.h"
17 #include "chrome/browser/browsing_data_local_storage_helper.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/webui/cookies_tree_model_util.h"
20 #include "content/public/browser/web_ui.h"
21 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 CookiesViewHandler::CookiesViewHandler() : batch_update_(false) {
25 }
26
27 CookiesViewHandler::~CookiesViewHandler() {
28 }
29
30 void CookiesViewHandler::GetLocalizedValues(
31 DictionaryValue* localized_strings) {
32 DCHECK(localized_strings);
33
34 static OptionsStringResource resources[] = {
35 { "label_cookie_name", IDS_COOKIES_COOKIE_NAME_LABEL },
36 { "label_cookie_content", IDS_COOKIES_COOKIE_CONTENT_LABEL },
37 { "label_cookie_domain", IDS_COOKIES_COOKIE_DOMAIN_LABEL },
38 { "label_cookie_path", IDS_COOKIES_COOKIE_PATH_LABEL },
39 { "label_cookie_send_for", IDS_COOKIES_COOKIE_SENDFOR_LABEL },
40 { "label_cookie_accessible_to_script",
41 IDS_COOKIES_COOKIE_ACCESSIBLE_TO_SCRIPT_LABEL },
42 { "label_cookie_created", IDS_COOKIES_COOKIE_CREATED_LABEL },
43 { "label_cookie_expires", IDS_COOKIES_COOKIE_EXPIRES_LABEL },
44 { "label_webdb_desc", IDS_COOKIES_WEB_DATABASE_DESCRIPTION_LABEL },
45 { "label_local_storage_size",
46 IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL },
47 { "label_local_storage_last_modified",
48 IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL },
49 { "label_local_storage_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL },
50 { "label_indexed_db_size", IDS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL },
51 { "label_indexed_db_last_modified",
52 IDS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL },
53 { "label_indexed_db_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL },
54 { "label_app_cache_manifest",
55 IDS_COOKIES_APPLICATION_CACHE_MANIFEST_LABEL },
56 { "label_cookie_last_accessed", IDS_COOKIES_LAST_ACCESSED_LABEL },
57 { "cookie_domain", IDS_COOKIES_DOMAIN_COLUMN_HEADER },
58 { "cookie_local_data", IDS_COOKIES_DATA_COLUMN_HEADER },
59 { "cookie_singular", IDS_COOKIES_SINGLE_COOKIE },
60 { "cookie_plural", IDS_COOKIES_PLURAL_COOKIES },
61 { "cookie_database_storage", IDS_COOKIES_DATABASE_STORAGE },
62 { "cookie_indexed_db", IDS_COOKIES_INDEXED_DB },
63 { "cookie_local_storage", IDS_COOKIES_LOCAL_STORAGE },
64 { "cookie_app_cache", IDS_COOKIES_APPLICATION_CACHE },
65 { "search_cookies", IDS_COOKIES_SEARCH_COOKIES },
66 { "remove_cookie", IDS_COOKIES_REMOVE_LABEL },
67 { "remove_all_cookie", IDS_COOKIES_REMOVE_ALL_LABEL },
68 { "cookie_file_system", IDS_COOKIES_FILE_SYSTEM },
69 { "label_file_system_origin", IDS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL },
70 { "label_file_system_temporary_usage",
71 IDS_COOKIES_FILE_SYSTEM_TEMPORARY_USAGE_LABEL },
72 { "label_file_system_persistent_usage",
73 IDS_COOKIES_FILE_SYSTEM_PERSISTENT_USAGE_LABEL },
74 };
75
76 RegisterStrings(localized_strings, resources, arraysize(resources));
77 RegisterTitle(localized_strings, "cookiesViewPage",
78 IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE);
79 }
80
81 void CookiesViewHandler::RegisterMessages() {
82 web_ui()->RegisterMessageCallback("updateCookieSearchResults",
83 base::Bind(&CookiesViewHandler::UpdateSearchResults,
84 base::Unretained(this)));
85 web_ui()->RegisterMessageCallback("removeAllCookies",
86 base::Bind(&CookiesViewHandler::RemoveAll,
87 base::Unretained(this)));
88 web_ui()->RegisterMessageCallback("removeCookie",
89 base::Bind(&CookiesViewHandler::Remove,
90 base::Unretained(this)));
91 web_ui()->RegisterMessageCallback("loadCookie",
92 base::Bind(&CookiesViewHandler::LoadChildren,
93 base::Unretained(this)));
94 }
95
96 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model,
97 ui::TreeModelNode* parent,
98 int start,
99 int count) {
100 // Skip if there is a batch update in progress.
101 if (batch_update_)
102 return;
103
104 CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent);
105
106 ListValue* children = new ListValue;
107 cookies_tree_model_util::GetChildNodeList(parent_node, start, count,
108 children);
109
110 ListValue args;
111 args.Append(parent == cookies_tree_model_->GetRoot() ?
112 Value::CreateNullValue() :
113 Value::CreateStringValue(
114 cookies_tree_model_util::GetTreeNodeId(parent_node)));
115 args.Append(Value::CreateIntegerValue(start));
116 args.Append(children);
117 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args);
118 }
119
120 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model,
121 ui::TreeModelNode* parent,
122 int start,
123 int count) {
124 // Skip if there is a batch update in progress.
125 if (batch_update_)
126 return;
127
128 ListValue args;
129 args.Append(parent == cookies_tree_model_->GetRoot() ?
130 Value::CreateNullValue() :
131 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(
132 cookies_tree_model_->AsNode(parent))));
133 args.Append(Value::CreateIntegerValue(start));
134 args.Append(Value::CreateIntegerValue(count));
135 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args);
136 }
137
138 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) {
139 DCHECK(!batch_update_); // There should be no nested batch begin.
140 batch_update_ = true;
141 }
142
143 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) {
144 DCHECK(batch_update_);
145 batch_update_ = false;
146
147 SendChildren(cookies_tree_model_->GetRoot());
148 }
149
150 void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
151 if (!cookies_tree_model_.get()) {
152 Profile* profile = Profile::FromWebUI(web_ui());
153 cookies_tree_model_.reset(new CookiesTreeModel(
154 new BrowsingDataCookieHelper(profile),
155 new BrowsingDataDatabaseHelper(profile),
156 new BrowsingDataLocalStorageHelper(profile),
157 NULL,
158 new BrowsingDataAppCacheHelper(profile),
159 BrowsingDataIndexedDBHelper::Create(profile),
160 BrowsingDataFileSystemHelper::Create(profile),
161 BrowsingDataQuotaHelper::Create(profile),
162 false));
163 cookies_tree_model_->AddCookiesTreeObserver(this);
164 }
165 }
166
167 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) {
168 std::string query;
169 if (!args->GetString(0, &query)) {
170 return;
171 }
172
173 EnsureCookiesTreeModelCreated();
174
175 cookies_tree_model_->UpdateSearchResults(UTF8ToWide(query));
176 }
177
178 void CookiesViewHandler::RemoveAll(const ListValue* args) {
179 EnsureCookiesTreeModelCreated();
180 cookies_tree_model_->DeleteAllStoredObjects();
181 }
182
183 void CookiesViewHandler::Remove(const ListValue* args) {
184 std::string node_path;
185 if (!args->GetString(0, &node_path)) {
186 return;
187 }
188
189 EnsureCookiesTreeModelCreated();
190
191 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath(
192 cookies_tree_model_->GetRoot(), node_path);
193 if (node)
194 cookies_tree_model_->DeleteCookieNode(node);
195 }
196
197 void CookiesViewHandler::LoadChildren(const ListValue* args) {
198 std::string node_path;
199 if (!args->GetString(0, &node_path)) {
200 return;
201 }
202
203 EnsureCookiesTreeModelCreated();
204
205 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath(
206 cookies_tree_model_->GetRoot(), node_path);
207 if (node)
208 SendChildren(node);
209 }
210
211 void CookiesViewHandler::SendChildren(CookieTreeNode* parent) {
212 ListValue* children = new ListValue;
213 cookies_tree_model_util::GetChildNodeList(parent, 0, parent->child_count(),
214 children);
215
216 ListValue args;
217 args.Append(parent == cookies_tree_model_->GetRoot() ?
218 Value::CreateNullValue() :
219 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent)));
220 args.Append(children);
221
222 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args);
223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698