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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/debugger/devtools_window.h" | 14 #include "chrome/browser/debugger/devtools_window.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 16 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "content/browser/webui/web_ui.h" |
| 20 #include "content/browser/worker_host/worker_process_host.h" |
19 #include "content/public/browser/devtools_agent_host_registry.h" | 21 #include "content/public/browser/devtools_agent_host_registry.h" |
20 #include "content/browser/worker_host/worker_process_host.h" | |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/worker_service.h" | 24 #include "content/public/browser/worker_service.h" |
24 #include "content/public/browser/worker_service_observer.h" | 25 #include "content/public/browser/worker_service_observer.h" |
25 #include "content/public/browser/web_ui_message_handler.h" | 26 #include "content/public/browser/web_ui_message_handler.h" |
26 #include "content/public/common/process_type.h" | 27 #include "content/public/common/process_type.h" |
27 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
28 #include "grit/workers_resources.h" | 29 #include "grit/workers_resources.h" |
29 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
30 | 31 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 worker_data->SetInteger(kWorkerRouteIdField, worker_route_id); | 227 worker_data->SetInteger(kWorkerRouteIdField, worker_route_id); |
227 | 228 |
228 BrowserThread::PostTask( | 229 BrowserThread::PostTask( |
229 BrowserThread::UI, FROM_HERE, | 230 BrowserThread::UI, FROM_HERE, |
230 base::Bind(&WorkerCreationDestructionListener::NotifyWorkerDestroyed, | 231 base::Bind(&WorkerCreationDestructionListener::NotifyWorkerDestroyed, |
231 this, base::Owned(worker_data))); | 232 this, base::Owned(worker_data))); |
232 } | 233 } |
233 virtual void WorkerContextStarted(WorkerProcessHost*, int) OVERRIDE {} | 234 virtual void WorkerContextStarted(WorkerProcessHost*, int) OVERRIDE {} |
234 | 235 |
235 void NotifyWorkerCreated(DictionaryValue* worker_data) { | 236 void NotifyWorkerCreated(DictionaryValue* worker_data) { |
236 if (workers_ui_) | 237 if (!workers_ui_) { |
237 workers_ui_->CallJavascriptFunction("workerCreated", *worker_data); | 238 workers_ui_->web_ui()->CallJavascriptFunction( |
| 239 "workerCreated", *worker_data); |
| 240 } |
238 } | 241 } |
239 | 242 |
240 void NotifyWorkerDestroyed(DictionaryValue* worker_data) { | 243 void NotifyWorkerDestroyed(DictionaryValue* worker_data) { |
241 if (workers_ui_) | 244 if (workers_ui_) { |
242 workers_ui_->CallJavascriptFunction("workerDestroyed", *worker_data); | 245 workers_ui_->web_ui()->CallJavascriptFunction( |
| 246 "workerDestroyed", *worker_data); |
| 247 } |
243 } | 248 } |
244 | 249 |
245 void RegisterObserver() { | 250 void RegisterObserver() { |
246 WorkerService::GetInstance()->AddObserver(this); | 251 WorkerService::GetInstance()->AddObserver(this); |
247 } | 252 } |
248 void UnregisterObserver() { | 253 void UnregisterObserver() { |
249 WorkerService::GetInstance()->RemoveObserver(this); | 254 WorkerService::GetInstance()->RemoveObserver(this); |
250 } | 255 } |
251 | 256 |
252 WorkersUI* workers_ui_; | 257 WorkersUI* workers_ui_; |
253 }; | 258 }; |
254 | 259 |
255 WorkersUI::WorkersUI(WebContents* contents) | 260 WorkersUI::WorkersUI(WebUI* web_ui) |
256 : WebUI(contents, this), | 261 : WebUIController(web_ui), |
257 observer_(new WorkerCreationDestructionListener(this)){ | 262 observer_(new WorkerCreationDestructionListener(this)){ |
258 AddMessageHandler(new WorkersDOMHandler()); | 263 web_ui->AddMessageHandler(new WorkersDOMHandler()); |
259 | 264 |
260 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource(); | 265 WorkersUIHTMLSource* html_source = new WorkersUIHTMLSource(); |
261 | 266 |
262 // Set up the chrome://workers/ source. | 267 // Set up the chrome://workers/ source. |
263 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 268 Profile* profile = Profile::FromBrowserContext( |
| 269 web_ui->web_contents()->GetBrowserContext()); |
264 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 270 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
265 } | 271 } |
266 | 272 |
267 WorkersUI::~WorkersUI() { | 273 WorkersUI::~WorkersUI() { |
268 observer_->WorkersUIDestroyed(); | 274 observer_->WorkersUIDestroyed(); |
269 observer_ = NULL; | 275 observer_ = NULL; |
270 } | 276 } |
OLD | NEW |