| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/components_ui.h" | 5 #include "chrome/browser/ui/webui/components_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual void RegisterMessages() OVERRIDE; | 69 virtual void RegisterMessages() OVERRIDE; |
| 70 | 70 |
| 71 // Callback for the "requestComponentsData" message. | 71 // Callback for the "requestComponentsData" message. |
| 72 void HandleRequestComponentsData(const base::ListValue* args); | 72 void HandleRequestComponentsData(const base::ListValue* args); |
| 73 | 73 |
| 74 // Callback for the "checkUpdate" message. | 74 // Callback for the "checkUpdate" message. |
| 75 void HandleCheckUpdate(const base::ListValue* args); | 75 void HandleCheckUpdate(const base::ListValue* args); |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 void LoadComponents(); | 78 void LoadComponents(); |
| 79 void ComponentsDOMHandler::HandleRequestComponentStatus( |
| 80 const base::ListValue* args); |
| 79 | 81 |
| 80 content::NotificationRegistrar registrar_; | 82 content::NotificationRegistrar registrar_; |
| 81 | 83 |
| 82 DISALLOW_COPY_AND_ASSIGN(ComponentsDOMHandler); | 84 DISALLOW_COPY_AND_ASSIGN(ComponentsDOMHandler); |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 ComponentsDOMHandler::ComponentsDOMHandler() { | 87 ComponentsDOMHandler::ComponentsDOMHandler() { |
| 86 } | 88 } |
| 87 | 89 |
| 88 void ComponentsDOMHandler::RegisterMessages() { | 90 void ComponentsDOMHandler::RegisterMessages() { |
| 89 web_ui()->RegisterMessageCallback("requestComponentsData", | 91 web_ui()->RegisterMessageCallback("requestComponentsData", |
| 90 base::Bind(&ComponentsDOMHandler::HandleRequestComponentsData, | 92 base::Bind(&ComponentsDOMHandler::HandleRequestComponentsData, |
| 91 base::Unretained(this))); | 93 base::Unretained(this))); |
| 92 | 94 |
| 93 web_ui()->RegisterMessageCallback("checkUpdate", | 95 web_ui()->RegisterMessageCallback("checkUpdate", |
| 94 base::Bind(&ComponentsDOMHandler::HandleCheckUpdate, | 96 base::Bind(&ComponentsDOMHandler::HandleCheckUpdate, |
| 95 base::Unretained(this))); | 97 base::Unretained(this))); |
| 98 |
| 99 web_ui()->RegisterMessageCallback("requestComponentStatus", |
| 100 base::Bind(&ComponentsDOMHandler::HandleRequestComponentStatus, |
| 101 base::Unretained(this))); |
| 96 } | 102 } |
| 97 | 103 |
| 98 void ComponentsDOMHandler::HandleRequestComponentsData( | 104 void ComponentsDOMHandler::HandleRequestComponentsData( |
| 99 const base::ListValue* args) { | 105 const base::ListValue* args) { |
| 100 LoadComponents(); | 106 LoadComponents(); |
| 101 } | 107 } |
| 102 | 108 |
| 103 // This function is called when user presses button from html UI. | 109 // This function is called when user presses button from html UI. |
| 104 // TODO(shrikant): We need to make this button available based on current | 110 // TODO(shrikant): We need to make this button available based on current |
| 105 // state e.g. If component state is currently updating then we need to disable | 111 // state e.g. If component state is currently updating then we need to disable |
| 106 // button. (https://code.google.com/p/chromium/issues/detail?id=272540) | 112 // button. (https://code.google.com/p/chromium/issues/detail?id=272540) |
| 107 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { | 113 void ComponentsDOMHandler::HandleCheckUpdate(const base::ListValue* args) { |
| 108 if (args->GetSize() != 1) { | 114 if (args->GetSize() != 1) { |
| 109 NOTREACHED(); | 115 NOTREACHED(); |
| 110 return; | 116 return; |
| 111 } | 117 } |
| 112 | 118 |
| 113 std::string component_id; | 119 std::string component_id; |
| 114 if (!args->GetString(0, &component_id)) { | 120 if (!args->GetString(0, &component_id)) { |
| 115 NOTREACHED(); | 121 NOTREACHED(); |
| 116 return; | 122 return; |
| 117 } | 123 } |
| 118 | 124 |
| 119 ComponentsUI::OnDemandUpdate(component_id); | 125 ComponentsUI::OnDemandUpdate(component_id); |
| 120 } | 126 } |
| 121 | 127 |
| 128 void ComponentsDOMHandler::HandleRequestComponentStatus( |
| 129 const base::ListValue* args) { |
| 130 if (args->GetSize() != 1) { |
| 131 NOTREACHED(); |
| 132 return; |
| 133 } |
| 134 |
| 135 std::string component_id; |
| 136 if (!args->GetString(0, &component_id)) { |
| 137 NOTREACHED(); |
| 138 return; |
| 139 } |
| 140 |
| 141 component_updater::ComponentUpdateService* cus = |
| 142 g_browser_process->component_updater(); |
| 143 component_updater::ComponentUpdateService::Status status = |
| 144 cus->GetComponentStatus(component_id); |
| 145 |
| 146 std::string string_status; |
| 147 if (status == component_updater::ComponentUpdateService::kInProgress) |
| 148 string_status = "in-progress"; |
| 149 else if (status == component_updater::ComponentUpdateService::kOk) |
| 150 string_status = "ok"; |
| 151 else |
| 152 string_status = "error"; |
| 153 |
| 154 web_ui()->CallJavascriptFunction("returnComponentStatus", |
| 155 base::StringValue(component_id), |
| 156 base::StringValue(string_status)); |
| 157 } |
| 158 |
| 122 void ComponentsDOMHandler::LoadComponents() { | 159 void ComponentsDOMHandler::LoadComponents() { |
| 123 component_updater::ComponentUpdateService* cus = | 160 component_updater::ComponentUpdateService* cus = |
| 124 g_browser_process->component_updater(); | 161 g_browser_process->component_updater(); |
| 125 std::vector<component_updater::CrxComponentInfo> components; | 162 std::vector<component_updater::CrxComponentInfo> components; |
| 126 cus->GetComponents(&components); | 163 cus->GetComponents(&components); |
| 127 | 164 |
| 128 // Construct DictionaryValues to return to UI. | 165 // Construct DictionaryValues to return to UI. |
| 129 base::ListValue* component_list = new base::ListValue(); | 166 base::ListValue* component_list = new base::ListValue(); |
| 130 for (size_t j = 0; j < components.size(); ++j) { | 167 for (size_t j = 0; j < components.size(); ++j) { |
| 131 const component_updater::CrxComponentInfo& component = components[j]; | 168 const component_updater::CrxComponentInfo& component = components[j]; |
| 132 | 169 |
| 133 base::DictionaryValue* component_entry = new base::DictionaryValue(); | 170 base::DictionaryValue* component_entry = new base::DictionaryValue(); |
| 134 component_entry->SetString("id", component.id); | 171 component_entry->SetString("id", component.id); |
| 135 component_entry->SetString("name", component.name); | 172 component_entry->SetString("name", component.name); |
| 136 component_entry->SetString("version", component.version); | 173 component_entry->SetString("version", component.version); |
| 174 switch (component.status) { |
| 175 case component_updater::ComponentUpdateService::kInProgress: |
| 176 component_entry->SetString("status", "in-progress"); |
| 177 break; |
| 178 case component_updater::ComponentUpdateService::kOk: |
| 179 component_entry->SetString("status", "ok"); |
| 180 break; |
| 181 case component_updater::ComponentUpdateService::kError: |
| 182 component_entry->SetString("status", "error"); |
| 183 break; |
| 184 } |
| 137 | 185 |
| 138 component_list->Append(component_entry); | 186 component_list->Append(component_entry); |
| 139 } | 187 } |
| 140 | 188 |
| 141 base::DictionaryValue results; | 189 base::DictionaryValue results; |
| 142 results.Set("components", component_list); | 190 results.Set("components", component_list); |
| 143 web_ui()->CallJavascriptFunction("returnComponentsData", results); | 191 web_ui()->CallJavascriptFunction("returnComponentsData", results); |
| 144 } | 192 } |
| 145 | 193 |
| 146 } // namespace | 194 } // namespace |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 g_browser_process->component_updater(); | 213 g_browser_process->component_updater(); |
| 166 cus->OnDemandUpdate(component_id); | 214 cus->OnDemandUpdate(component_id); |
| 167 } | 215 } |
| 168 | 216 |
| 169 // static | 217 // static |
| 170 base::RefCountedMemory* ComponentsUI::GetFaviconResourceBytes( | 218 base::RefCountedMemory* ComponentsUI::GetFaviconResourceBytes( |
| 171 ui::ScaleFactor scale_factor) { | 219 ui::ScaleFactor scale_factor) { |
| 172 return ResourceBundle::GetSharedInstance(). | 220 return ResourceBundle::GetSharedInstance(). |
| 173 LoadDataResourceBytesForScale(IDR_PLUGINS_FAVICON, scale_factor); | 221 LoadDataResourceBytesForScale(IDR_PLUGINS_FAVICON, scale_factor); |
| 174 } | 222 } |
| OLD | NEW |