blob: f5fddd18305a62ab84f0a98f7a8060abe4338353 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (c) 2011 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.
#ifndef CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_ADAPTER_H_
#define CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_ADAPTER_H_
#pragma once
#include "base/compiler_specific.h"
#include "chrome/browser/cookies_tree_model.h"
namespace base {
class ListValue;
class Value;
}
namespace content {
class WebUI;
}
// CookiesTreeModelAdapter binds a CookiesTreeModel with a JS tree. It observes
// tree model changes and forwards them to JS tree. It also provides a
// a callback for JS tree to load children of a specific node.
class CookiesTreeModelAdapter : public CookiesTreeModel::Observer {
public:
CookiesTreeModelAdapter();
virtual ~CookiesTreeModelAdapter();
// Initializes with given WebUI.
void Init(content::WebUI* web_ui);
// Sets up the bindings between js tree and |model|.
// Note that this class does not take ownership of the model.
void Bind(const std::string& tree_id, CookiesTreeModel* model);
private:
// CookiesTreeModel::Observer implementation.
virtual void TreeNodesAdded(ui::TreeModel* model,
ui::TreeModelNode* parent,
int start,
int count) OVERRIDE;
virtual void TreeNodesRemoved(ui::TreeModel* model,
ui::TreeModelNode* parent,
int start,
int count) OVERRIDE;
virtual void TreeNodeChanged(ui::TreeModel* model,
ui::TreeModelNode* node) OVERRIDE {}
virtual void TreeModelBeginBatch(CookiesTreeModel* model) OVERRIDE;
virtual void TreeModelEndBatch(CookiesTreeModel* model) OVERRIDE;
// JS callback that gets the tree node using the tree path info in |args| and
// call SendChildren to pass back children nodes data to WebUI.
void RequestChildren(const base::ListValue* args);
// Get children nodes data and pass it to 'CookiesTree.loadChildren' to
// update the WebUI.
void SendChildren(CookieTreeNode* parent);
// Helper function to get a Value* representing id of |node|.
// Caller needs to free the returned Value.
base::Value* GetTreeNodeId(CookieTreeNode* node);
// Hosting WebUI of the js tree.
content::WebUI* web_ui_;
// Id of JS tree that is managed by this handler.
std::string tree_id_;
// The Cookies Tree model. Note that we are not owning the model.
CookiesTreeModel* model_;
// Flag to indicate whether there is a batch update in progress.
bool batch_update_;
DISALLOW_COPY_AND_ASSIGN(CookiesTreeModelAdapter);
};
#endif // CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_ADAPTER_H_
|