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/workers_ui.h" | 5 #include "chrome/browser/ui/webui/workers_ui.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 worker_data->SetString(kUrlField, i->url().spec()); | 94 worker_data->SetString(kUrlField, i->url().spec()); |
95 worker_data->SetString(kNameField, i->name()); | 95 worker_data->SetString(kNameField, i->name()); |
96 worker_data->SetInteger(kPidField, worker->pid()); | 96 worker_data->SetInteger(kPidField, worker->pid()); |
97 workers_list.Append(worker_data); | 97 workers_list.Append(worker_data); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 std::string json_string; | 101 std::string json_string; |
102 base::JSONWriter::Write(&workers_list, false, &json_string); | 102 base::JSONWriter::Write(&workers_list, false, &json_string); |
103 | 103 |
104 scoped_refptr<RefCountedBytes> json_bytes(new RefCountedBytes()); | 104 SendResponse(request_id, base::RefCountedString::TakeString(&json_string)); |
105 json_bytes->data.resize(json_string.size()); | |
106 std::copy(json_string.begin(), json_string.end(), json_bytes->data.begin()); | |
107 | |
108 SendResponse(request_id, json_bytes); | |
109 } | 105 } |
110 | 106 |
111 class WorkersDOMHandler : public WebUIMessageHandler { | 107 class WorkersDOMHandler : public WebUIMessageHandler { |
112 public: | 108 public: |
113 WorkersDOMHandler() {} | 109 WorkersDOMHandler() {} |
114 virtual ~WorkersDOMHandler() {} | 110 virtual ~WorkersDOMHandler() {} |
115 | 111 |
116 private: | 112 private: |
117 // WebUIMessageHandler implementation. | 113 // WebUIMessageHandler implementation. |
118 virtual void RegisterMessages(); | 114 virtual void RegisterMessages(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 WorkersUI::WorkersUI(TabContents* contents) : ChromeWebUI(contents) { | 150 WorkersUI::WorkersUI(TabContents* contents) : ChromeWebUI(contents) { |
155 WorkersDOMHandler* handler = new WorkersDOMHandler(); | 151 WorkersDOMHandler* handler = new WorkersDOMHandler(); |
156 AddMessageHandler(handler); | 152 AddMessageHandler(handler); |
157 handler->Attach(this); | 153 handler->Attach(this); |
158 | 154 |
159 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource(); | 155 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource(); |
160 | 156 |
161 // Set up the chrome://workers/ source. | 157 // Set up the chrome://workers/ source. |
162 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 158 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
163 } | 159 } |
OLD | NEW |