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