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