Index: chrome/browser/ui/webui/options2/cookies_view_handler2.cc |
diff --git a/chrome/browser/ui/webui/options2/cookies_view_handler2.cc b/chrome/browser/ui/webui/options2/cookies_view_handler2.cc |
index e37cbd3f9d9a02fc490533238e7e43f96a48c4ab..56ef41aec70948db2661f5b7736b9db30ef74dd3 100644 |
--- a/chrome/browser/ui/webui/options2/cookies_view_handler2.cc |
+++ b/chrome/browser/ui/webui/options2/cookies_view_handler2.cc |
@@ -8,6 +8,8 @@ |
#include "base/bind_helpers.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
+#include "chrome/common/extensions/extension.h" |
+#include "chrome/common/extensions/extension_set.h" |
#include "chrome/browser/browsing_data_appcache_helper.h" |
#include "chrome/browser/browsing_data_cookie_helper.h" |
#include "chrome/browser/browsing_data_database_helper.h" |
@@ -16,6 +18,7 @@ |
#include "chrome/browser/browsing_data_local_storage_helper.h" |
#include "chrome/browser/browsing_data_quota_helper.h" |
#include "chrome/browser/browsing_data_server_bound_cert_helper.h" |
+#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/webui/cookies_tree_model_util.h" |
#include "content/public/browser/web_ui.h" |
@@ -24,7 +27,9 @@ |
namespace options2 { |
-CookiesViewHandler::CookiesViewHandler() : batch_update_(false) { |
+CookiesViewHandler::CookiesViewHandler() |
+ : batch_update_(false), |
+ app_context_(false) { |
} |
CookiesViewHandler::~CookiesViewHandler() { |
@@ -88,6 +93,8 @@ void CookiesViewHandler::GetLocalizedValues( |
RegisterStrings(localized_strings, resources, arraysize(resources)); |
RegisterTitle(localized_strings, "cookiesViewPage", |
IDS_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); |
+ RegisterTitle(localized_strings, "appCookiesViewPage", |
+ IDS_APP_COOKIES_WEBSITE_PERMISSIONS_WINDOW_TITLE); |
} |
void CookiesViewHandler::RegisterMessages() { |
@@ -103,6 +110,9 @@ void CookiesViewHandler::RegisterMessages() { |
web_ui()->RegisterMessageCallback("loadCookie", |
base::Bind(&CookiesViewHandler::LoadChildren, |
base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback("setViewContext", |
+ base::Bind(&CookiesViewHandler::SetViewContext, |
+ base::Unretained(this))); |
} |
void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, |
@@ -113,20 +123,21 @@ void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, |
if (batch_update_) |
return; |
- CookieTreeNode* parent_node = cookies_tree_model_->AsNode(parent); |
+ CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
+ CookieTreeNode* parent_node = tree_model->AsNode(parent); |
ListValue* children = new ListValue; |
cookies_tree_model_util::GetChildNodeList(parent_node, start, count, |
children); |
ListValue args; |
- args.Append(parent == cookies_tree_model_->GetRoot() ? |
+ args.Append(parent == tree_model->GetRoot() ? |
Value::CreateNullValue() : |
Value::CreateStringValue( |
cookies_tree_model_util::GetTreeNodeId(parent_node))); |
args.Append(Value::CreateIntegerValue(start)); |
args.Append(children); |
- web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); |
+ web_ui()->CallJavascriptFunction(GetCallback(onTreeItemAdded), args); |
} |
void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
@@ -137,14 +148,16 @@ void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
if (batch_update_) |
return; |
+ CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
+ |
ListValue args; |
- args.Append(parent == cookies_tree_model_->GetRoot() ? |
+ args.Append(parent == tree_model->GetRoot() ? |
Value::CreateNullValue() : |
Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId( |
- cookies_tree_model_->AsNode(parent)))); |
+ tree_model->AsNode(parent)))); |
args.Append(Value::CreateIntegerValue(start)); |
args.Append(Value::CreateIntegerValue(count)); |
- web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); |
+ web_ui()->CallJavascriptFunction(GetCallback(onTreeItemRemoved), args); |
} |
void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
@@ -156,13 +169,15 @@ void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { |
DCHECK(batch_update_); |
batch_update_ = false; |
- SendChildren(cookies_tree_model_->GetRoot()); |
+ SendChildren(model->GetRoot()); |
} |
void CookiesViewHandler::EnsureCookiesTreeModelCreated() { |
- if (!cookies_tree_model_.get()) { |
+ if (!app_context_ && !cookies_tree_model_.get()) { |
Profile* profile = Profile::FromWebUI(web_ui()); |
- cookies_tree_model_.reset(new CookiesTreeModel( |
+ ContainerMap apps_map; |
+ apps_map[std::string()] = new LocalDataContainer( |
+ "Site Data", std::string(), |
new BrowsingDataCookieHelper(profile->GetRequestContext()), |
new BrowsingDataDatabaseHelper(profile), |
new BrowsingDataLocalStorageHelper(profile), |
@@ -171,26 +186,51 @@ void CookiesViewHandler::EnsureCookiesTreeModelCreated() { |
BrowsingDataIndexedDBHelper::Create(profile), |
BrowsingDataFileSystemHelper::Create(profile), |
BrowsingDataQuotaHelper::Create(profile), |
- BrowsingDataServerBoundCertHelper::Create(profile), |
- false)); |
+ BrowsingDataServerBoundCertHelper::Create(profile)); |
+ cookies_tree_model_.reset(new CookiesTreeModel(apps_map, false)); |
cookies_tree_model_->AddCookiesTreeObserver(this); |
} |
+ |
+ if (app_context_ && !app_cookies_tree_model_.get()) { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ ContainerMap apps_map; |
+ const ExtensionService* service = profile->GetExtensionService(); |
+ if (service) { |
+ const ExtensionSet* extensions = service->extensions(); |
+ for (ExtensionSet::const_iterator it = extensions->begin(); |
+ it != extensions->end(); ++it) { |
+ if ((*it)->is_storage_isolated()) { |
+ net::URLRequestContextGetter* context_getter = |
+ profile->GetRequestContextForIsolatedApp((*it)->id()); |
+ // TODO(nasko): When new types of storage are isolated, add the |
+ // appropriate browsing data helper objects to the consutrctor. |
+ // For now, just cookies are isolated, so other parameters are NULL. |
+ apps_map[(*it)->id()] = new LocalDataContainer( |
+ (*it)->name(), (*it)->id(), |
+ new BrowsingDataCookieHelper(context_getter), |
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
+ } |
+ } |
+ app_cookies_tree_model_.reset(new CookiesTreeModel(apps_map, false)); |
+ app_cookies_tree_model_->AddCookiesTreeObserver(this); |
+ } |
+ } |
} |
void CookiesViewHandler::UpdateSearchResults(const ListValue* args) { |
- std::string query; |
+ string16 query; |
if (!args->GetString(0, &query)) { |
return; |
} |
EnsureCookiesTreeModelCreated(); |
- cookies_tree_model_->UpdateSearchResults(UTF8ToWide(query)); |
+ GetTreeModel()->UpdateSearchResults(query); |
} |
void CookiesViewHandler::RemoveAll(const ListValue* args) { |
EnsureCookiesTreeModelCreated(); |
- cookies_tree_model_->DeleteAllStoredObjects(); |
+ GetTreeModel()->DeleteAllStoredObjects(); |
} |
void CookiesViewHandler::Remove(const ListValue* args) { |
@@ -202,9 +242,9 @@ void CookiesViewHandler::Remove(const ListValue* args) { |
EnsureCookiesTreeModelCreated(); |
CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( |
- cookies_tree_model_->GetRoot(), node_path); |
+ GetTreeModel()->GetRoot(), node_path); |
if (node) |
- cookies_tree_model_->DeleteCookieNode(node); |
+ GetTreeModel()->DeleteCookieNode(node); |
} |
void CookiesViewHandler::LoadChildren(const ListValue* args) { |
@@ -216,7 +256,7 @@ void CookiesViewHandler::LoadChildren(const ListValue* args) { |
EnsureCookiesTreeModelCreated(); |
CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath( |
- cookies_tree_model_->GetRoot(), node_path); |
+ GetTreeModel()->GetRoot(), node_path); |
if (node) |
SendChildren(node); |
} |
@@ -227,12 +267,50 @@ void CookiesViewHandler::SendChildren(CookieTreeNode* parent) { |
children); |
ListValue args; |
- args.Append(parent == cookies_tree_model_->GetRoot() ? |
+ args.Append(parent == GetTreeModel()->GetRoot() ? |
Value::CreateNullValue() : |
Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent))); |
args.Append(children); |
- web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); |
+ web_ui()->CallJavascriptFunction(GetCallback(loadChildren), args); |
+} |
+ |
+void CookiesViewHandler::SetViewContext(const base::ListValue* args) { |
+ bool app_context = false; |
+ if (args->GetBoolean(0, &app_context)) |
+ app_context_ = app_context; |
+} |
+ |
+const std::string CookiesViewHandler::GetCallback( |
+ CookiesViewCallback callback) { |
Bernhard Bauer
2012/06/26 21:03:55
Could you implement this by constructing the full
|
+ switch (callback) { |
+ case onTreeItemAdded: |
+ if (app_context_) |
+ return "AppCookiesView.onTreeItemAdded"; |
+ return "CookiesView.onTreeItemAdded"; |
+ case onTreeItemRemoved: |
+ if (app_context_) |
+ return "AppCookiesView.onTreeItemRemoved"; |
+ return "CookiesView.onTreeItemRemoved"; |
+ case loadChildren: |
+ if (app_context_) |
+ return "AppCookiesView.loadChildren"; |
+ return "CookiesView.loadChildren"; |
+ default: |
+ NOTREACHED(); |
+ return ""; |
+ } |
+} |
+ |
+CookiesTreeModel* CookiesViewHandler::GetTreeModel() { |
+ CookiesTreeModel* model; |
+ if (app_context_) |
+ model = app_cookies_tree_model_.get(); |
+ else |
+ model = cookies_tree_model_.get(); |
+ |
+ DCHECK(model); |
+ return model; |
} |
} // namespace options2 |