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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_set.h" |
11 #include "chrome/browser/browsing_data_appcache_helper.h" | 13 #include "chrome/browser/browsing_data_appcache_helper.h" |
12 #include "chrome/browser/browsing_data_cookie_helper.h" | 14 #include "chrome/browser/browsing_data_cookie_helper.h" |
13 #include "chrome/browser/browsing_data_database_helper.h" | 15 #include "chrome/browser/browsing_data_database_helper.h" |
14 #include "chrome/browser/browsing_data_file_system_helper.h" | 16 #include "chrome/browser/browsing_data_file_system_helper.h" |
15 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 17 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
16 #include "chrome/browser/browsing_data_local_storage_helper.h" | 18 #include "chrome/browser/browsing_data_local_storage_helper.h" |
17 #include "chrome/browser/browsing_data_quota_helper.h" | 19 #include "chrome/browser/browsing_data_quota_helper.h" |
18 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" | 20 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" | 23 #include "chrome/browser/ui/webui/cookies_tree_model_util.h" |
21 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
22 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
24 | 27 |
25 namespace options2 { | 28 namespace options2 { |
26 | 29 |
27 CookiesViewHandler::CookiesViewHandler() : batch_update_(false) { | 30 CookiesViewHandler::CookiesViewHandler() : batch_update_(false) { |
28 } | 31 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 109 } |
107 | 110 |
108 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, | 111 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, |
109 ui::TreeModelNode* parent, | 112 ui::TreeModelNode* parent, |
110 int start, | 113 int start, |
111 int count) { | 114 int count) { |
112 // Skip if there is a batch update in progress. | 115 // Skip if there is a batch update in progress. |
113 if (batch_update_) | 116 if (batch_update_) |
114 return; | 117 return; |
115 | 118 |
| 119 LOG(ERROR) << "TreeNodesAdded: " << start << "|" << count; |
| 120 |
116 CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent); | 121 CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent); |
117 | 122 |
118 ListValue* children = new ListValue; | 123 ListValue* children = new ListValue; |
119 cookies_tree_model_util::GetChildNodeList(parent_node, start, count, | 124 cookies_tree_model_util::GetChildNodeList(parent_node, start, count, |
120 children); | 125 children); |
121 | 126 |
122 ListValue args; | 127 ListValue args; |
123 args.Append(parent == cookies_tree_model_->GetRoot() ? | 128 args.Append(parent == cookies_tree_model_->GetRoot() ? |
124 Value::CreateNullValue() : | 129 Value::CreateNullValue() : |
125 Value::CreateStringValue( | 130 Value::CreateStringValue( |
126 cookies_tree_model_util::GetTreeNodeId(parent_node))); | 131 cookies_tree_model_util::GetTreeNodeId(parent_node))); |
127 args.Append(Value::CreateIntegerValue(start)); | 132 args.Append(Value::CreateIntegerValue(start)); |
128 args.Append(children); | 133 args.Append(children); |
| 134 |
| 135 LOG(ERROR) << "TreeNodesAdded: " << |
| 136 cookies_tree_model_util::GetTreeNodeId(parent_node) << " -> " << |
| 137 parent_node->child_count(); |
| 138 |
129 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); | 139 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); |
130 } | 140 } |
131 | 141 |
132 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, | 142 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
133 ui::TreeModelNode* parent, | 143 ui::TreeModelNode* parent, |
134 int start, | 144 int start, |
135 int count) { | 145 int count) { |
136 // Skip if there is a batch update in progress. | 146 // Skip if there is a batch update in progress. |
137 if (batch_update_) | 147 if (batch_update_) |
138 return; | 148 return; |
139 | 149 |
| 150 LOG(ERROR) << "TreeNodesRemoved: " << start << "|" << count; |
| 151 |
140 ListValue args; | 152 ListValue args; |
141 args.Append(parent == cookies_tree_model_->GetRoot() ? | 153 args.Append(parent == cookies_tree_model_->GetRoot() ? |
142 Value::CreateNullValue() : | 154 Value::CreateNullValue() : |
143 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId( | 155 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId( |
144 cookies_tree_model_->AsNode(parent)))); | 156 cookies_tree_model_->AsNode(parent)))); |
145 args.Append(Value::CreateIntegerValue(start)); | 157 args.Append(Value::CreateIntegerValue(start)); |
146 args.Append(Value::CreateIntegerValue(count)); | 158 args.Append(Value::CreateIntegerValue(count)); |
147 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); | 159 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); |
148 } | 160 } |
149 | 161 |
150 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { | 162 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
151 DCHECK(!batch_update_); // There should be no nested batch begin. | 163 DCHECK(!batch_update_); // There should be no nested batch begin. |
152 batch_update_ = true; | 164 batch_update_ = true; |
| 165 LOG(ERROR) << "TreeModelBeginBatch"; |
153 } | 166 } |
154 | 167 |
155 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { | 168 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { |
156 DCHECK(batch_update_); | 169 DCHECK(batch_update_); |
157 batch_update_ = false; | 170 batch_update_ = false; |
158 | 171 |
| 172 LOG(ERROR) << "TreeModelEndBatch"; |
159 SendChildren(cookies_tree_model_->GetRoot()); | 173 SendChildren(cookies_tree_model_->GetRoot()); |
160 } | 174 } |
161 | 175 |
162 void CookiesViewHandler::EnsureCookiesTreeModelCreated() { | 176 void CookiesViewHandler::EnsureCookiesTreeModelCreated() { |
163 if (!cookies_tree_model_.get()) { | 177 if (!cookies_tree_model_.get()) { |
164 Profile* profile = Profile::FromWebUI(web_ui()); | 178 Profile* profile = Profile::FromWebUI(web_ui()); |
165 cookies_tree_model_.reset(new CookiesTreeModel( | 179 //string16 name = ASCIIToUTF16("Drive-By-Web"); |
| 180 string16 name = ASCIIToUTF16("Drive-By-Web"); |
| 181 string16 id = ASCIIToUTF16(""); |
| 182 |
| 183 ContainerMap apps_map; |
| 184 LocalDataContainer* container; |
| 185 |
| 186 container = new LocalDataContainer( |
| 187 name, id, |
166 new BrowsingDataCookieHelper(profile->GetRequestContext()), | 188 new BrowsingDataCookieHelper(profile->GetRequestContext()), |
167 new BrowsingDataDatabaseHelper(profile), | 189 new BrowsingDataDatabaseHelper(profile), |
168 new BrowsingDataLocalStorageHelper(profile), | 190 new BrowsingDataLocalStorageHelper(profile), |
169 NULL, | 191 NULL, |
170 new BrowsingDataAppCacheHelper(profile), | 192 new BrowsingDataAppCacheHelper(profile), |
171 BrowsingDataIndexedDBHelper::Create(profile), | 193 BrowsingDataIndexedDBHelper::Create(profile), |
172 BrowsingDataFileSystemHelper::Create(profile), | 194 BrowsingDataFileSystemHelper::Create(profile), |
173 BrowsingDataQuotaHelper::Create(profile), | 195 BrowsingDataQuotaHelper::Create(profile), |
174 BrowsingDataServerBoundCertHelper::Create(profile), | 196 BrowsingDataServerBoundCertHelper::Create(profile), |
175 false)); | 197 false |
| 198 ); |
| 199 |
| 200 apps_map[id] = container; |
| 201 |
| 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 name = ASCIIToUTF16((*it)->name()); |
| 211 id = ASCIIToUTF16((*it)->id()); |
| 212 container = new LocalDataContainer( |
| 213 name, id, |
| 214 new BrowsingDataCookieHelper(context_getter), |
| 215 new BrowsingDataDatabaseHelper(profile), |
| 216 new BrowsingDataLocalStorageHelper(profile), |
| 217 NULL, |
| 218 new BrowsingDataAppCacheHelper(profile), |
| 219 BrowsingDataIndexedDBHelper::Create(profile), |
| 220 BrowsingDataFileSystemHelper::Create(profile), |
| 221 BrowsingDataQuotaHelper::Create(profile), |
| 222 BrowsingDataServerBoundCertHelper::Create(profile), |
| 223 false |
| 224 ); |
| 225 apps_map[id] = container; |
| 226 } |
| 227 } |
| 228 } |
| 229 |
| 230 |
| 231 cookies_tree_model_.reset(new CookiesTreeModel(apps_map)); |
176 cookies_tree_model_->AddCookiesTreeObserver(this); | 232 cookies_tree_model_->AddCookiesTreeObserver(this); |
177 } | 233 } |
178 } | 234 } |
179 | 235 |
180 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) { | 236 void CookiesViewHandler::UpdateSearchResults(const ListValue* args) { |
181 std::string query; | 237 std::string query; |
182 if (!args->GetString(0, &query)) { | 238 if (!args->GetString(0, &query)) { |
183 return; | 239 return; |
184 } | 240 } |
185 | 241 |
186 EnsureCookiesTreeModelCreated(); | 242 EnsureCookiesTreeModelCreated(); |
187 | 243 |
| 244 LOG(ERROR) << "UpdateSearchResults"; |
| 245 |
188 cookies_tree_model_->UpdateSearchResults(UTF8ToWide(query)); | 246 cookies_tree_model_->UpdateSearchResults(UTF8ToWide(query)); |
189 } | 247 } |
190 | 248 |
191 void CookiesViewHandler::RemoveAll(const ListValue* args) { | 249 void CookiesViewHandler::RemoveAll(const ListValue* args) { |
192 EnsureCookiesTreeModelCreated(); | 250 EnsureCookiesTreeModelCreated(); |
| 251 LOG(ERROR) << "RemoveAll"; |
193 cookies_tree_model_->DeleteAllStoredObjects(); | 252 cookies_tree_model_->DeleteAllStoredObjects(); |
194 } | 253 } |
195 | 254 |
196 void CookiesViewHandler::Remove(const ListValue* args) { | 255 void CookiesViewHandler::Remove(const ListValue* args) { |
197 std::string node_path; | 256 std::string node_path; |
198 if (!args->GetString(0, &node_path)) { | 257 if (!args->GetString(0, &node_path)) { |
199 return; | 258 return; |
200 } | 259 } |
201 | 260 |
202 EnsureCookiesTreeModelCreated(); | 261 EnsureCookiesTreeModelCreated(); |
203 | 262 |
204 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( | 263 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( |
205 cookies_tree_model_->GetRoot(), node_path); | 264 cookies_tree_model_->GetRoot(), node_path); |
| 265 LOG(ERROR) << "RemoveChildren: " << node_path << "|" << node; |
206 if (node) | 266 if (node) |
207 cookies_tree_model_->DeleteCookieNode(node); | 267 cookies_tree_model_->DeleteCookieNode(node); |
208 } | 268 } |
209 | 269 |
210 void CookiesViewHandler::LoadChildren(const ListValue* args) { | 270 void CookiesViewHandler::LoadChildren(const ListValue* args) { |
211 std::string node_path; | 271 std::string node_path; |
212 if (!args->GetString(0, &node_path)) { | 272 if (!args->GetString(0, &node_path)) { |
213 return; | 273 return; |
214 } | 274 } |
215 | 275 |
216 EnsureCookiesTreeModelCreated(); | 276 EnsureCookiesTreeModelCreated(); |
217 | 277 |
218 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( | 278 CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( |
219 cookies_tree_model_->GetRoot(), node_path); | 279 cookies_tree_model_->GetRoot(), node_path); |
| 280 |
| 281 LOG(ERROR) << "LoadChildren: " << node_path << "|" << node; |
| 282 |
220 if (node) | 283 if (node) |
221 SendChildren(node); | 284 SendChildren(node); |
222 } | 285 } |
223 | 286 |
224 void CookiesViewHandler::SendChildren(CookieTreeNode* parent) { | 287 void CookiesViewHandler::SendChildren(CookieTreeNode* parent) { |
225 ListValue* children = new ListValue; | 288 ListValue* children = new ListValue; |
226 cookies_tree_model_util::GetChildNodeList(parent, 0, parent->child_count(), | 289 cookies_tree_model_util::GetChildNodeList(parent, 0, parent->child_count(), |
227 children); | 290 children); |
228 | 291 |
| 292 LOG(ERROR) << "SendChildren: " << |
| 293 cookies_tree_model_util::GetTreeNodeId(parent) << " -> " << |
| 294 parent->child_count(); |
| 295 |
229 ListValue args; | 296 ListValue args; |
230 args.Append(parent == cookies_tree_model_->GetRoot() ? | 297 args.Append(parent == cookies_tree_model_->GetRoot() ? |
231 Value::CreateNullValue() : | 298 Value::CreateNullValue() : |
232 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent))); | 299 Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent))); |
233 args.Append(children); | 300 args.Append(children); |
234 | 301 |
235 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); | 302 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); |
236 } | 303 } |
237 | 304 |
238 } // namespace options2 | 305 } // namespace options2 |
OLD | NEW |