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 "chrome/browser/ui/webui/options2/cookies_view_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/cookies_view_handler2.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/common/extensions/extension.h" | |
14 #include "chrome/common/extensions/extension_set.h" | |
13 #include "chrome/browser/browsing_data_appcache_helper.h" | 15 #include "chrome/browser/browsing_data_appcache_helper.h" |
14 #include "chrome/browser/browsing_data_cookie_helper.h" | 16 #include "chrome/browser/browsing_data_cookie_helper.h" |
15 #include "chrome/browser/browsing_data_database_helper.h" | 17 #include "chrome/browser/browsing_data_database_helper.h" |
16 #include "chrome/browser/browsing_data_file_system_helper.h" | 18 #include "chrome/browser/browsing_data_file_system_helper.h" |
17 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 19 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
18 #include "chrome/browser/browsing_data_local_storage_helper.h" | 20 #include "chrome/browser/browsing_data_local_storage_helper.h" |
19 #include "chrome/browser/browsing_data_quota_helper.h" | 21 #include "chrome/browser/browsing_data_quota_helper.h" |
20 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" | 22 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" |
23 #include "chrome/browser/extensions/extension_service.h" | |
21 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" | 25 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" |
23 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
24 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
25 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
26 | 29 |
27 namespace options2 { | 30 namespace options2 { |
28 | 31 |
29 CookiesViewHandler::CookiesViewHandler() | 32 CookiesViewHandler::CookiesViewHandler() |
30 : batch_update_(false), | 33 : batch_update_(false), |
31 model_util_(new CookiesTreeModelUtil) { | 34 app_context_(false), |
35 model_util_(new CookiesTreeModelUtil) { | |
32 } | 36 } |
33 | 37 |
34 CookiesViewHandler::~CookiesViewHandler() { | 38 CookiesViewHandler::~CookiesViewHandler() { |
35 } | 39 } |
36 | 40 |
37 void CookiesViewHandler::GetLocalizedValues( | 41 void CookiesViewHandler::GetLocalizedValues( |
38 DictionaryValue* localized_strings) { | 42 DictionaryValue* localized_strings) { |
39 DCHECK(localized_strings); | 43 DCHECK(localized_strings); |
40 | 44 |
41 static OptionsStringResource resources[] = { | 45 static OptionsStringResource resources[] = { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 IDS_COOKIES_SERVER_BOUND_CERT_TYPE_LABEL }, | 89 IDS_COOKIES_SERVER_BOUND_CERT_TYPE_LABEL }, |
86 { "label_server_bound_cert_created", | 90 { "label_server_bound_cert_created", |
87 IDS_COOKIES_SERVER_BOUND_CERT_CREATED_LABEL }, | 91 IDS_COOKIES_SERVER_BOUND_CERT_CREATED_LABEL }, |
88 { "label_server_bound_cert_expires", | 92 { "label_server_bound_cert_expires", |
89 IDS_COOKIES_SERVER_BOUND_CERT_EXPIRES_LABEL }, | 93 IDS_COOKIES_SERVER_BOUND_CERT_EXPIRES_LABEL }, |
90 }; | 94 }; |
91 | 95 |
92 RegisterStrings(localized_strings, resources, arraysize(resources)); | 96 RegisterStrings(localized_strings, resources, arraysize(resources)); |
93 RegisterTitle(localized_strings, "cookiesViewPage", | 97 RegisterTitle(localized_strings, "cookiesViewPage", |
94 IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); | 98 IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); |
99 RegisterTitle(localized_strings, "appCookiesViewPage", | |
100 IDS_APP_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); | |
95 } | 101 } |
96 | 102 |
97 void CookiesViewHandler::RegisterMessages() { | 103 void CookiesViewHandler::RegisterMessages() { |
98 web_ui()->RegisterMessageCallback("updateCookieSearchResults", | 104 web_ui()->RegisterMessageCallback("updateCookieSearchResults", |
99 base::Bind(&CookiesViewHandler::UpdateSearchResults, | 105 base::Bind(&CookiesViewHandler::UpdateSearchResults, |
100 base::Unretained(this))); | 106 base::Unretained(this))); |
101 web_ui()->RegisterMessageCallback("removeAllCookies", | 107 web_ui()->RegisterMessageCallback("removeAllCookies", |
102 base::Bind(&CookiesViewHandler::RemoveAll, | 108 base::Bind(&CookiesViewHandler::RemoveAll, |
103 base::Unretained(this))); | 109 base::Unretained(this))); |
104 web_ui()->RegisterMessageCallback("removeCookie", | 110 web_ui()->RegisterMessageCallback("removeCookie", |
105 base::Bind(&CookiesViewHandler::Remove, | 111 base::Bind(&CookiesViewHandler::Remove, |
106 base::Unretained(this))); | 112 base::Unretained(this))); |
107 web_ui()->RegisterMessageCallback("loadCookie", | 113 web_ui()->RegisterMessageCallback("loadCookie", |
108 base::Bind(&CookiesViewHandler::LoadChildren, | 114 base::Bind(&CookiesViewHandler::LoadChildren, |
109 base::Unretained(this))); | 115 base::Unretained(this))); |
116 web_ui()->RegisterMessageCallback("setViewContext", | |
117 base::Bind(&CookiesViewHandler::SetViewContext, | |
118 base::Unretained(this))); | |
110 } | 119 } |
111 | 120 |
112 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, | 121 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, |
113 ui::TreeModelNode* parent, | 122 ui::TreeModelNode* parent, |
114 int start, | 123 int start, |
115 int count) { | 124 int count) { |
116 // Skip if there is a batch update in progress. | 125 // Skip if there is a batch update in progress. |
117 if (batch_update_) | 126 if (batch_update_) |
118 return; | 127 return; |
119 | 128 |
120 CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent); | 129 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
130 CookieTreeNode* parent_node = tree_model->AsNode(parent); | |
121 | 131 |
122 ListValue* children = new ListValue; | 132 ListValue* children = new ListValue; |
123 model_util_->GetChildNodeList(parent_node, start, count, | 133 model_util_->GetChildNodeList(parent_node, start, count, |
124 children); | 134 children); |
125 | 135 |
126 ListValue args; | 136 ListValue args; |
127 args.Append(parent == cookies_tree_model_->GetRoot() ? | 137 args.Append(parent == tree_model->GetRoot() ? |
128 Value::CreateNullValue() : | 138 Value::CreateNullValue() : |
129 Value::CreateStringValue( | 139 Value::CreateStringValue( |
130 model_util_->GetTreeNodeId(parent_node))); | 140 model_util_->GetTreeNodeId(parent_node))); |
131 args.Append(Value::CreateIntegerValue(start)); | 141 args.Append(Value::CreateIntegerValue(start)); |
132 args.Append(children); | 142 args.Append(children); |
133 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); | 143 web_ui()->CallJavascriptFunction( |
144 GetCallback("onTreeItemAdded", GetTreeModel()), args); | |
134 } | 145 } |
135 | 146 |
136 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, | 147 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
137 ui::TreeModelNode* parent, | 148 ui::TreeModelNode* parent, |
138 int start, | 149 int start, |
139 int count) { | 150 int count) { |
140 // Skip if there is a batch update in progress. | 151 // Skip if there is a batch update in progress. |
141 if (batch_update_) | 152 if (batch_update_) |
142 return; | 153 return; |
143 | 154 |
155 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | |
156 | |
144 ListValue args; | 157 ListValue args; |
145 args.Append(parent == cookies_tree_model_->GetRoot() ? | 158 args.Append(parent == tree_model->GetRoot() ? |
146 Value::CreateNullValue() : | 159 Value::CreateNullValue() : |
147 Value::CreateStringValue(model_util_->GetTreeNodeId( | 160 Value::CreateStringValue(model_util_->GetTreeNodeId( |
148 cookies_tree_model_->AsNode(parent)))); | 161 tree_model->AsNode(parent)))); |
149 args.Append(Value::CreateIntegerValue(start)); | 162 args.Append(Value::CreateIntegerValue(start)); |
150 args.Append(Value::CreateIntegerValue(count)); | 163 args.Append(Value::CreateIntegerValue(count)); |
151 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); | 164 web_ui()->CallJavascriptFunction( |
165 GetCallback("onTreeItemRemoved", GetTreeModel()), args); | |
152 } | 166 } |
153 | 167 |
154 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { | 168 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
155 DCHECK(!batch_update_); // There should be no nested batch begin. | 169 DCHECK(!batch_update_); // There should be no nested batch begin. |
156 batch_update_ = true; | 170 batch_update_ = true; |
157 } | 171 } |
158 | 172 |
159 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { | 173 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { |
160 DCHECK(batch_update_); | 174 DCHECK(batch_update_); |
161 batch_update_ = false; | 175 batch_update_ = false; |
162 | 176 |
163 SendChildren(cookies_tree_model_->GetRoot()); | 177 SendChildren(model->GetRoot()); |
164 } | 178 } |
165 | 179 |
166 void CookiesViewHandler::EnsureCookiesTreeModelCreated() { | 180 void CookiesViewHandler::EnsureCookiesTreeModelCreated() { |
Bernhard Bauer
2012/07/10 18:18:03
Hmm, it looks like exactly one of |app_cookies_tre
nasko
2012/07/10 19:54:10
There is one CookiesViewHandler for the lifetime o
| |
167 if (!cookies_tree_model_.get()) { | 181 if (!app_context_ && !cookies_tree_model_.get()) { |
168 Profile* profile = Profile::FromWebUI(web_ui()); | 182 Profile* profile = Profile::FromWebUI(web_ui()); |
169 cookies_tree_model_.reset(new CookiesTreeModel( | 183 ContainerMap apps_map; |
184 apps_map[std::string()] = new LocalDataContainer( | |
185 "Site Data", std::string(), | |
170 new BrowsingDataCookieHelper(profile->GetRequestContext()), | 186 new BrowsingDataCookieHelper(profile->GetRequestContext()), |
171 new BrowsingDataDatabaseHelper(profile), | 187 new BrowsingDataDatabaseHelper(profile), |
172 new BrowsingDataLocalStorageHelper(profile), | 188 new BrowsingDataLocalStorageHelper(profile), |
173 NULL, | 189 NULL, |
174 new BrowsingDataAppCacheHelper(profile), | 190 new BrowsingDataAppCacheHelper(profile), |
175 BrowsingDataIndexedDBHelper::Create(profile), | 191 BrowsingDataIndexedDBHelper::Create(profile), |
176 BrowsingDataFileSystemHelper::Create(profile), | 192 BrowsingDataFileSystemHelper::Create(profile), |
177 BrowsingDataQuotaHelper::Create(profile), | 193 BrowsingDataQuotaHelper::Create(profile), |
178 BrowsingDataServerBoundCertHelper::Create(profile), | 194 BrowsingDataServerBoundCertHelper::Create(profile)); |
179 false)); | 195 cookies_tree_model_.reset(new CookiesTreeModel(apps_map, false)); |
180 cookies_tree_model_->AddCookiesTreeObserver(this); | 196 cookies_tree_model_->AddCookiesTreeObserver(this); |
181 } | 197 } |
198 | |
199 if (app_context_ && !app_cookies_tree_model_.get()) { | |
200 Profile* profile = Profile::FromWebUI(web_ui()); | |
201 ContainerMap apps_map; | |
202 const ExtensionService* service = profile->GetExtensionService(); | |
203 if (service) { | |
204 const ExtensionSet* extensions = service->extensions(); | |
205 for (ExtensionSet::const_iterator it = extensions->begin(); | |
206 it != extensions->end(); ++it) { | |
207 if ((*it)->is_storage_isolated()) { | |
208 net::URLRequestContextGetter* context_getter = | |
209 profile->GetRequestContextForIsolatedApp((*it)->id()); | |
210 // TODO(nasko): When new types of storage are isolated, add the | |
211 // appropriate browsing data helper objects to the consutrctor. | |
Bernhard Bauer
2012/07/10 18:18:03
Nit: constructor
nasko
2012/07/10 19:54:10
Done.
| |
212 // For now, just cookies are isolated, so other parameters are NULL. | |
213 apps_map[(*it)->id()] = new LocalDataContainer( | |
214 (*it)->name(), (*it)->id(), | |
215 new BrowsingDataCookieHelper(context_getter), | |
216 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); | |
217 } | |
218 } | |
219 app_cookies_tree_model_.reset(new CookiesTreeModel(apps_map, false)); | |
220 app_cookies_tree_model_->AddCookiesTreeObserver(this); | |
221 } | |
222 } | |
182 } | 223 } |
183 | 224 |
184 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) { | 225 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) { |
185 std::string query; | 226 string16 query; |
186 if (!args->GetString(0, &query)) { | 227 if (!args->GetString(0, &query)) { |
187 return; | 228 return; |
188 } | 229 } |
189 | 230 |
190 EnsureCookiesTreeModelCreated(); | 231 EnsureCookiesTreeModelCreated(); |
191 | 232 |
192 cookies_tree_model_->UpdateSearchResults(UTF8ToWide(query)); | 233 GetTreeModel()->UpdateSearchResults(query); |
193 } | 234 } |
194 | 235 |
195 void CookiesViewHandler::RemoveAll(const ListValue* args) { | 236 void CookiesViewHandler::RemoveAll(const ListValue* args) { |
196 EnsureCookiesTreeModelCreated(); | 237 EnsureCookiesTreeModelCreated(); |
197 cookies_tree_model_->DeleteAllStoredObjects(); | 238 GetTreeModel()->DeleteAllStoredObjects(); |
198 } | 239 } |
199 | 240 |
200 void CookiesViewHandler::Remove(const ListValue* args) { | 241 void CookiesViewHandler::Remove(const ListValue* args) { |
201 std::string node_path; | 242 std::string node_path; |
202 if (!args->GetString(0, &node_path)) { | 243 if (!args->GetString(0, &node_path)) { |
203 return; | 244 return; |
204 } | 245 } |
205 | 246 |
206 EnsureCookiesTreeModelCreated(); | 247 EnsureCookiesTreeModelCreated(); |
207 | 248 |
208 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( | 249 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( |
209 cookies_tree_model_->GetRoot(), node_path); | 250 GetTreeModel()->GetRoot(), node_path); |
210 if (node) | 251 if (node) |
211 cookies_tree_model_->DeleteCookieNode(const_cast<CookieTreeNode*>(node)); | 252 GetTreeModel()->DeleteCookieNode(const_cast<CookieTreeNode*>(node)); |
212 } | 253 } |
213 | 254 |
214 void CookiesViewHandler::LoadChildren(const ListValue* args) { | 255 void CookiesViewHandler::LoadChildren(const ListValue* args) { |
215 std::string node_path; | 256 std::string node_path; |
216 if (!args->GetString(0, &node_path)) { | 257 if (!args->GetString(0, &node_path)) { |
217 return; | 258 return; |
218 } | 259 } |
219 | 260 |
220 EnsureCookiesTreeModelCreated(); | 261 EnsureCookiesTreeModelCreated(); |
221 | 262 |
222 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( | 263 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( |
223 cookies_tree_model_->GetRoot(), node_path); | 264 GetTreeModel()->GetRoot(), node_path); |
224 if (node) | 265 if (node) |
225 SendChildren(node); | 266 SendChildren(node); |
226 } | 267 } |
227 | 268 |
228 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { | 269 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { |
229 ListValue* children = new ListValue; | 270 ListValue* children = new ListValue; |
230 model_util_->GetChildNodeList(parent, 0, parent->child_count(), | 271 model_util_->GetChildNodeList(parent, 0, parent->child_count(), |
231 children); | 272 children); |
232 | 273 |
233 ListValue args; | 274 ListValue args; |
234 args.Append(parent == cookies_tree_model_->GetRoot() ? | 275 args.Append(parent == GetTreeModel()->GetRoot() ? |
235 Value::CreateNullValue() : | 276 Value::CreateNullValue() : |
236 Value::CreateStringValue(model_util_->GetTreeNodeId(parent))); | 277 Value::CreateStringValue(model_util_->GetTreeNodeId(parent))); |
237 args.Append(children); | 278 args.Append(children); |
238 | 279 |
239 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); | 280 web_ui()->CallJavascriptFunction( |
281 GetCallback("loadChildren", GetTreeModel()), args); | |
282 } | |
283 | |
284 void CookiesViewHandler::SetViewContext(const base::ListValue* args) { | |
285 bool app_context = false; | |
286 if (args->GetBoolean(0, &app_context)) | |
287 app_context_ = app_context; | |
288 } | |
289 | |
290 CookiesTreeModel* CookiesViewHandler::GetTreeModel() { | |
291 CookiesTreeModel* model = app_context_ ? | |
292 app_cookies_tree_model_.get() : cookies_tree_model_.get(); | |
293 DCHECK(model); | |
294 return model; | |
295 } | |
296 | |
297 std::string CookiesViewHandler::GetCallback( | |
298 std::string method, CookiesTreeModel* model) { | |
Bernhard Bauer
2012/07/10 18:18:03
You're always calling this method with GetTreeMode
nasko
2012/07/10 19:54:10
This should be acting on the model. I've changed t
| |
299 std::string callback("CookiesView"); | |
300 | |
301 if (model == app_cookies_tree_model_) { | |
Bernhard Bauer
2012/07/10 18:18:03
Nit: braces are unnecessary.
nasko
2012/07/10 19:54:10
Done.
| |
302 callback.append("App"); | |
303 } | |
304 return callback.append(".").append(method); | |
240 } | 305 } |
241 | 306 |
242 } // namespace options2 | 307 } // namespace options2 |
OLD | NEW |