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

Side by Side Diff: chrome/browser/ui/webui/options/intents_settings_handler.cc

Issue 7624012: First pass on intents options UI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add comments, fix CSS, etc. Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "chrome/browser/ui/webui/options/intents_settings_handler.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "base/values.h"
9 #include "chrome/browser/browsing_data_appcache_helper.h"
10 #include "chrome/browser/browsing_data_database_helper.h"
11 #include "chrome/browser/browsing_data_file_system_helper.h"
12 #include "chrome/browser/browsing_data_indexed_db_helper.h"
13 #include "chrome/browser/browsing_data_local_storage_helper.h"
14 #include "chrome/browser/intents/web_intents_registry.h"
15 #include "chrome/browser/intents/web_intents_registry_factory.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/webdata/web_data_service.h"
18 #include "content/browser/webui/web_ui.h"
19 #include "grit/generated_resources.h"
20 #include "net/url_request/url_request_context_getter.h"
21 #include "ui/base/l10n/l10n_util.h"
22
23 IntentsSettingsHandler::IntentsSettingsHandler() : batch_update_(false) {
24 }
25
26 IntentsSettingsHandler::~IntentsSettingsHandler() {
27 }
28
29 void IntentsSettingsHandler::GetLocalizedValues(
30 DictionaryValue* localized_strings) {
31 DCHECK(localized_strings);
32
33 static OptionsStringResource resources[] = {
34 { "intentsTabLabel", IDS_INTENTS_TAB_LABEL },
35 { "intentsAllow", IDS_INTENTS_ALLOW_RADIO },
36 { "intentsBlock", IDS_INTENTS_BLOCK_RADIO },
37 { "intentsDomain", IDS_INTENTS_DOMAIN_COLUMN_HEADER },
38 { "intentsServiceData", IDS_INTENTS_SERVICE_DATA_COLUMN_HEADER },
39 { "manageIntents", IDS_INTENTS_MANAGE_BUTTON },
40 { "removeIntent", IDS_INTENTS_REMOVE_INTENT_BUTTON },
41 };
42
43 RegisterStrings(localized_strings, resources, arraysize(resources));
44 RegisterTitle(localized_strings, "intentsViewPage",
45 IDS_INTENTS_MANAGER_WINDOW_TITLE);
46 }
47
48 void IntentsSettingsHandler::RegisterMessages() {
49 web_ui_->RegisterMessageCallback("removeIntent",
50 NewCallback(this, &IntentsSettingsHandler::RemoveIntent));
51 web_ui_->RegisterMessageCallback("loadIntents",
52 NewCallback(this, &IntentsSettingsHandler::LoadChildren));
53 }
54
55 void IntentsSettingsHandler::TreeNodesAdded(ui::TreeModel* model,
56 ui::TreeModelNode* parent,
57 int start,
58 int count) {
59 SendChildren(intents_tree_model_->GetRoot());
60 }
61
62 void IntentsSettingsHandler::TreeNodesRemoved(ui::TreeModel* model,
63 ui::TreeModelNode* parent,
64 int start,
65 int count) {
66 SendChildren(intents_tree_model_->GetRoot());
67 }
68
69 void IntentsSettingsHandler::TreeModelBeginBatch(IntentsModel* model) {
70 DCHECK(!batch_update_); // There should be no nested batch begin.
71 batch_update_ = true;
72 }
73
74 void IntentsSettingsHandler::TreeModelEndBatch(IntentsModel* model) {
75 DCHECK(batch_update_);
76 batch_update_ = false;
77
78 SendChildren(intents_tree_model_->GetRoot());
79 }
80
81 void IntentsSettingsHandler::EnsureIntentsModelCreated() {
82 if (intents_tree_model_.get()) return;
83
84 Profile* profile = Profile::FromWebUI(web_ui_);
85 web_data_service_ = profile->GetWebDataService(Profile::EXPLICIT_ACCESS);
86 web_intents_registry_ = WebIntentsRegistryFactory::GetForProfile(profile);
87 web_intents_registry_->Initialize(web_data_service_.get());
88 intents_tree_model_.reset(new IntentsModel(web_intents_registry_));
89 intents_tree_model_->AddIntentsTreeObserver(this);
90 }
91
92 void IntentsSettingsHandler::RemoveIntent(const base::ListValue* args) {
93 std::string node_path;
94 if (!args->GetString(0, &node_path)) {
95 return;
96 }
97
98 EnsureIntentsModelCreated();
99
100 IntentsTreeNode* node = intents_tree_model_->GetTreeNode(node_path);
101 if (node->Type() == IntentsTreeNode::TYPE_ORIGIN) {
102 RemoveOrigin(node);
103 } else if (node->Type() == IntentsTreeNode::TYPE_SERVICE) {
104 ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(node);
105 RemoveService(snode);
106 }
107 }
108
109 void IntentsSettingsHandler::RemoveOrigin(IntentsTreeNode* node) {
110 // TODO(gbillock): This is a known batch update. Worth optimizing?
111 while (node->child_count() > 0) {
112 IntentsTreeNode* cnode = node->GetChild(0);
113 CHECK(cnode->Type() == IntentsTreeNode::TYPE_SERVICE);
114 ServiceTreeNode* snode = static_cast<ServiceTreeNode*>(cnode);
115 RemoveService(snode);
116 }
117 delete intents_tree_model_->Remove(node->parent(), node);
118 }
119
120 void IntentsSettingsHandler::RemoveService(ServiceTreeNode* snode) {
121 WebIntentData provider;
122 provider.service_url = GURL(snode->ServiceUrl());
123 provider.action = snode->Action();
124 string16 stype;
125 if (snode->Types().GetString(0, &stype)) {
126 provider.type = stype; // Really need to iterate here.
127 }
128 provider.title = snode->ServiceName();
129 LOG(INFO) << "Removing service " << snode->ServiceName()
130 << " " << snode->ServiceUrl();
131 web_intents_registry_->UnregisterIntentProvider(provider);
132 delete intents_tree_model_->Remove(snode->parent(), snode);
133 }
134
135 void IntentsSettingsHandler::LoadChildren(const base::ListValue* args) {
136 EnsureIntentsModelCreated();
137
138 std::string node_path;
139 if (!args->GetString(0, &node_path)) {
140 SendChildren(intents_tree_model_->GetRoot());
141 return;
142 }
143
144 IntentsTreeNode* node = intents_tree_model_->GetTreeNode(node_path);
145 SendChildren(node);
146 }
147
148 void IntentsSettingsHandler::SendChildren(IntentsTreeNode* parent) {
149 // Early bailout during batch updates. We'll get one after the batch concludes
150 // with batch_update_ set false.
151 if (batch_update_) return;
152
153 ListValue* children = new ListValue;
154 intents_tree_model_->GetChildNodeList(parent, 0, parent->child_count(),
155 children);
156
157 ListValue args;
158 args.Append(parent == intents_tree_model_->GetRoot() ?
159 Value::CreateNullValue() :
160 Value::CreateStringValue(intents_tree_model_->GetTreeNodeId(parent)));
161 args.Append(children);
162
163 web_ui_->CallJavascriptFunction("IntentsView.loadChildren", args);
164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698