OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_internals_ui.h" | 5 #include "content/browser/service_worker/service_worker_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "content/browser/devtools/devtools_manager_impl.h" |
| 15 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
14 #include "content/browser/service_worker/service_worker_context_observer.h" | 16 #include "content/browser/service_worker/service_worker_context_observer.h" |
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
16 #include "content/browser/service_worker/service_worker_registration.h" | 18 #include "content/browser/service_worker/service_worker_registration.h" |
17 #include "content/browser/service_worker/service_worker_version.h" | 19 #include "content/browser/service_worker/service_worker_version.h" |
18 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
21 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
23 #include "content/public/browser/web_ui_data_source.h" | 25 #include "content/public/browser/web_ui_data_source.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 base::Bind(&ServiceWorkerInternalsUI::StopWorker, | 195 base::Bind(&ServiceWorkerInternalsUI::StopWorker, |
194 base::Unretained(this))); | 196 base::Unretained(this))); |
195 web_ui->RegisterMessageCallback( | 197 web_ui->RegisterMessageCallback( |
196 "unregister", | 198 "unregister", |
197 base::Bind(&ServiceWorkerInternalsUI::Unregister, | 199 base::Bind(&ServiceWorkerInternalsUI::Unregister, |
198 base::Unretained(this))); | 200 base::Unretained(this))); |
199 web_ui->RegisterMessageCallback( | 201 web_ui->RegisterMessageCallback( |
200 "sync", | 202 "sync", |
201 base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, | 203 base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, |
202 base::Unretained(this))); | 204 base::Unretained(this))); |
| 205 web_ui->RegisterMessageCallback( |
| 206 "inspect", |
| 207 base::Bind(&ServiceWorkerInternalsUI::InspectWorker, |
| 208 base::Unretained(this))); |
203 } | 209 } |
204 | 210 |
205 ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() { | 211 ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() { |
206 BrowserContext* browser_context = | 212 BrowserContext* browser_context = |
207 web_ui()->GetWebContents()->GetBrowserContext(); | 213 web_ui()->GetWebContents()->GetBrowserContext(); |
208 // Safe to use base::Unretained(this) because | 214 // Safe to use base::Unretained(this) because |
209 // ForEachStoragePartition is synchronous. | 215 // ForEachStoragePartition is synchronous. |
210 BrowserContext::StoragePartitionCallback remove_observer_cb = | 216 BrowserContext::StoragePartitionCallback remove_observer_cb = |
211 base::Bind(&ServiceWorkerInternalsUI::RemoveObserverFromStoragePartition, | 217 base::Bind(&ServiceWorkerInternalsUI::RemoveObserverFromStoragePartition, |
212 base::Unretained(this)); | 218 base::Unretained(this)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 BrowserThread::PostTask( | 327 BrowserThread::PostTask( |
322 BrowserThread::IO, | 328 BrowserThread::IO, |
323 FROM_HERE, | 329 FROM_HERE, |
324 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: | 330 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
325 DispatchSyncEventToWorkerOnIOThread, | 331 DispatchSyncEventToWorkerOnIOThread, |
326 new OperationProxy(AsWeakPtr(), args_copy.Pass()), | 332 new OperationProxy(AsWeakPtr(), args_copy.Pass()), |
327 context, | 333 context, |
328 scope)); | 334 scope)); |
329 } | 335 } |
330 | 336 |
| 337 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { |
| 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 339 base::FilePath partition_path; |
| 340 GURL scope; |
| 341 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 342 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) |
| 343 return; |
| 344 scoped_refptr<DevToolsAgentHost> agent_host( |
| 345 EmbeddedWorkerDevToolsManager::GetInstance() |
| 346 ->GetDevToolsAgentHostForServiceWorker(partition_path, scope)); |
| 347 if (agent_host) { |
| 348 DevToolsManagerImpl::GetInstance()->Inspect( |
| 349 web_ui()->GetWebContents()->GetBrowserContext(), agent_host.get()); |
| 350 } |
| 351 scoped_ptr<ListValue> args_copy(args->DeepCopy()); |
| 352 args_copy->Insert(0, new FundamentalValue(0)); |
| 353 web_ui()->CallJavascriptFunction( |
| 354 "serviceworker.onOperationComplete", |
| 355 std::vector<const Value*>(args_copy->begin(), args_copy->end())); |
| 356 } |
| 357 |
331 void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { | 358 void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { |
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
333 base::FilePath partition_path; | 360 base::FilePath partition_path; |
334 GURL scope; | 361 GURL scope; |
335 scoped_refptr<ServiceWorkerContextWrapper> context; | 362 scoped_refptr<ServiceWorkerContextWrapper> context; |
336 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) | 363 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) |
337 return; | 364 return; |
338 | 365 |
339 scoped_ptr<ListValue> args_copy(args->DeepCopy()); | 366 scoped_ptr<ListValue> args_copy(args->DeepCopy()); |
340 BrowserThread::PostTask( | 367 BrowserThread::PostTask( |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 ServiceWorkerVersion::ACTIVE) { | 622 ServiceWorkerVersion::ACTIVE) { |
596 registration->active_version()->DispatchSyncEvent(base::Bind( | 623 registration->active_version()->DispatchSyncEvent(base::Bind( |
597 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); | 624 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); |
598 return; | 625 return; |
599 } | 626 } |
600 | 627 |
601 OperationComplete(SERVICE_WORKER_ERROR_FAILED); | 628 OperationComplete(SERVICE_WORKER_ERROR_FAILED); |
602 } | 629 } |
603 | 630 |
604 } // namespace content | 631 } // namespace content |
OLD | NEW |