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

Unified Diff: chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.mm

Issue 128673002: [Mac] Hook up the "Remove" button in the collected cookies dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.mm
diff --git a/chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.mm b/chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.mm
new file mode 100644
index 0000000000000000000000000000000000000000..d563de8987151ee7090663704f2d07a21b223a80
--- /dev/null
+++ b/chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.mm
@@ -0,0 +1,101 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.h"
+
+CookiesTreeControllerBridge::CookiesTreeControllerBridge(
+ CookiesTreeModel* model)
+ : model_(model),
+ cocoa_model_([CocoaNodeFromTreeNode(model_->GetRoot()) retain]) {
+ model_->AddObserver(this);
+}
+
+CookiesTreeControllerBridge::~CookiesTreeControllerBridge() {
+ model_->RemoveObserver(this);
+}
+
+// Notification that nodes were added to the specified parent.
+void CookiesTreeControllerBridge::TreeNodesAdded(ui::TreeModel* model,
+ ui::TreeModelNode* parent,
+ int start,
+ int count) {
+ CocoaCookieTreeNode* cocoa_parent = FindCocoaNode(parent, nil);
+ NSMutableArray* cocoa_children = [cocoa_parent mutableChildren];
+
+ [cocoa_model_ willChangeValueForKey:@"children"];
+ CookieTreeNode* cookie_parent = static_cast<CookieTreeNode*>(parent);
+ for (int i = 0; i < count; ++i) {
+ CookieTreeNode* cookie_child = cookie_parent->GetChild(start + i);
+ CocoaCookieTreeNode* new_child = CocoaNodeFromTreeNode(cookie_child);
+ [cocoa_children addObject:new_child];
+ }
+ [cocoa_model_ didChangeValueForKey:@"children"];
+}
+
+// Notification that nodes were removed from the specified parent.
+void CookiesTreeControllerBridge::TreeNodesRemoved(ui::TreeModel* model,
+ ui::TreeModelNode* parent,
+ int start,
+ int count) {
+ CocoaCookieTreeNode* cocoa_parent = FindCocoaNode(parent, nil);
+ NSMutableArray* cocoa_children = [cocoa_parent mutableChildren];
+ [cocoa_model_ willChangeValueForKey:@"children"];
+ for (int i = start + count - 1; i >= start; --i) {
+ [cocoa_children removeObjectAtIndex:i];
+ }
+ [cocoa_model_ didChangeValueForKey:@"children"];
+}
+
+// Notification that the contents of a node has changed.
+void CookiesTreeControllerBridge::TreeNodeChanged(ui::TreeModel* model,
+ ui::TreeModelNode* node) {
+ [cocoa_model_ willChangeValueForKey:@"children"];
+ CocoaCookieTreeNode* changed_node = FindCocoaNode(node, nil);
+ [changed_node rebuild];
+ [cocoa_model_ didChangeValueForKey:@"children"];
+}
+
+CocoaCookieTreeNode* CookiesTreeControllerBridge::CocoaNodeFromTreeNode(
+ ui::TreeModelNode* node) {
+ CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node);
+ return [[[CocoaCookieTreeNode alloc] initWithNode:cookie_node] autorelease];
+}
+
+// Does breadth-first search on the tree to find |node|. This method is most
+// commonly used to find origin/folder nodes, which are at the first level off
+// the root (hence breadth-first search).
+CocoaCookieTreeNode* CookiesTreeControllerBridge::FindCocoaNode(
+ ui::TreeModelNode* target, CocoaCookieTreeNode* start) {
+ if (!start) {
+ start = cocoa_model_.get();
+ }
+ if ([start treeNode] == target) {
+ return start;
+ }
+
+ // Enqueue the root node of the search (sub-)tree.
+ std::queue<CocoaCookieTreeNode*> horizon;
+ horizon.push(start);
+
+ // Loop until we've looked at every node or we found the target.
+ while (!horizon.empty()) {
+ // Dequeue the item at the front.
+ CocoaCookieTreeNode* node = horizon.front();
+ horizon.pop();
+
+ // If this is the target node, report it up.
+ if ([node treeNode] == target)
+ return node;
+
+ // Add all child nodes to the queue for searching.
+ if (![node isLeaf]) {
+ NSArray* children = [node children];
+ for (CocoaCookieTreeNode* child in children) {
+ horizon.push(child);
+ }
+ }
+ }
+
+ return nil; // The node could not be found.
+}
« no previous file with comments | « chrome/browser/ui/cocoa/content_settings/cookies_tree_controller_bridge.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698