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