| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/devtools/protocol/service_worker_handler.h" | 5 #include "content/browser/devtools/protocol/service_worker_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER) { | 101 SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER) { |
| 102 scoped_refptr<DevToolsAgentHost> agent_host( | 102 scoped_refptr<DevToolsAgentHost> agent_host( |
| 103 DevToolsAgentHost::GetForWorker(client.second.process_id, | 103 DevToolsAgentHost::GetForWorker(client.second.process_id, |
| 104 client.second.route_id)); | 104 client.second.route_id)); |
| 105 if (agent_host) | 105 if (agent_host) |
| 106 clients.push_back(agent_host->GetId()); | 106 clients.push_back(agent_host->GetId()); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 scoped_refptr<ServiceWorkerVersion> version( | 109 scoped_refptr<ServiceWorkerVersion> version( |
| 110 ServiceWorkerVersion::Create() | 110 ServiceWorkerVersion::Create() |
| 111 ->set_version_id(base::Int64ToString(version_info.version_id)) | 111 ->set_version_id(version_info.version_uuid) |
| 112 ->set_registration_id( | 112 ->set_registration_id( |
| 113 base::Int64ToString(version_info.registration_id)) | 113 base::Int64ToString(version_info.registration_id)) |
| 114 ->set_script_url(version_info.script_url.spec()) | 114 ->set_script_url(version_info.script_url.spec()) |
| 115 ->set_running_status( | 115 ->set_running_status( |
| 116 GetVersionRunningStatusString(version_info.running_status)) | 116 GetVersionRunningStatusString(version_info.running_status)) |
| 117 ->set_status(GetVersionStatusString(version_info.status)) | 117 ->set_status(GetVersionStatusString(version_info.status)) |
| 118 ->set_script_last_modified( | 118 ->set_script_last_modified( |
| 119 version_info.script_last_modified.ToDoubleT()) | 119 version_info.script_last_modified.ToDoubleT()) |
| 120 ->set_script_response_time( | 120 ->set_script_response_time( |
| 121 version_info.script_response_time.ToDoubleT()) | 121 version_info.script_response_time.ToDoubleT()) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 return result; | 172 return result; |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) { | 175 bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) { |
| 176 urls->insert(tree_node->current_url()); | 176 urls->insert(tree_node->current_url()); |
| 177 return false; | 177 return false; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void StopServiceWorkerOnIO(scoped_refptr<ServiceWorkerContextWrapper> context, | 180 void StopServiceWorkerOnIO(scoped_refptr<ServiceWorkerContextWrapper> context, |
| 181 int64 version_id) { | 181 std::string version_uuid) { |
| 182 if (content::ServiceWorkerVersion* version = | 182 if (content::ServiceWorkerVersion* version = |
| 183 context->GetLiveVersion(version_id)) { | 183 context->GetLiveVersion(version_uuid)) { |
| 184 version->StopWorker(base::Bind(&StatusNoOp)); | 184 version->StopWorker(base::Bind(&StatusNoOp)); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 void GetDevToolsRouteInfoOnIO( | 188 void GetDevToolsRouteInfoOnIO( |
| 189 scoped_refptr<ServiceWorkerContextWrapper> context, | 189 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 190 int64 version_id, | 190 std::string version_uuid, |
| 191 const base::Callback<void(int, int)>& callback) { | 191 const base::Callback<void(int, int)>& callback) { |
| 192 if (content::ServiceWorkerVersion* version = | 192 if (content::ServiceWorkerVersion* version = |
| 193 context->GetLiveVersion(version_id)) { | 193 context->GetLiveVersion(version_uuid)) { |
| 194 BrowserThread::PostTask( | 194 BrowserThread::PostTask( |
| 195 BrowserThread::UI, FROM_HERE, | 195 BrowserThread::UI, FROM_HERE, |
| 196 base::Bind( | 196 base::Bind( |
| 197 callback, version->embedded_worker()->process_id(), | 197 callback, version->embedded_worker()->process_id(), |
| 198 version->embedded_worker()->worker_devtools_agent_route_id())); | 198 version->embedded_worker()->worker_devtools_agent_route_id())); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 Response CreateContextErrorResponse() { | 202 Response CreateContextErrorResponse() { |
| 203 return Response::InternalError("Could not connect to the context"); | 203 return Response::InternalError("Could not connect to the context"); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 Response ServiceWorkerHandler::StartWorker(const std::string& scope_url) { | 361 Response ServiceWorkerHandler::StartWorker(const std::string& scope_url) { |
| 362 if (!enabled_) | 362 if (!enabled_) |
| 363 return Response::OK(); | 363 return Response::OK(); |
| 364 if (!context_) | 364 if (!context_) |
| 365 return CreateContextErrorResponse(); | 365 return CreateContextErrorResponse(); |
| 366 context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp)); | 366 context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp)); |
| 367 return Response::OK(); | 367 return Response::OK(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 Response ServiceWorkerHandler::StopWorker(const std::string& version_id) { | 370 Response ServiceWorkerHandler::StopWorker(const std::string& version_uuid) { |
| 371 if (!enabled_) | 371 if (!enabled_) |
| 372 return Response::OK(); | 372 return Response::OK(); |
| 373 if (!context_) | 373 if (!context_) |
| 374 return CreateContextErrorResponse(); | 374 return CreateContextErrorResponse(); |
| 375 int64 id = 0; | 375 std::string id(version_uuid); |
| 376 if (!base::StringToInt64(version_id, &id)) | 376 if (id.empty()) |
| 377 return CreateInvalidVersionIdErrorResponse(); | 377 return CreateInvalidVersionIdErrorResponse(); |
| 378 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 378 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 379 base::Bind(&StopServiceWorkerOnIO, context_, id)); | 379 base::Bind(&StopServiceWorkerOnIO, context_, id)); |
| 380 return Response::OK(); | 380 return Response::OK(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 Response ServiceWorkerHandler::UpdateRegistration( | 383 Response ServiceWorkerHandler::UpdateRegistration( |
| 384 const std::string& scope_url) { | 384 const std::string& scope_url) { |
| 385 if (!enabled_) | 385 if (!enabled_) |
| 386 return Response::OK(); | 386 return Response::OK(); |
| 387 if (!context_) | 387 if (!context_) |
| 388 return CreateContextErrorResponse(); | 388 return CreateContextErrorResponse(); |
| 389 context_->UpdateRegistration(GURL(scope_url)); | 389 context_->UpdateRegistration(GURL(scope_url)); |
| 390 return Response::OK(); | 390 return Response::OK(); |
| 391 } | 391 } |
| 392 | 392 |
| 393 Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) { | 393 Response ServiceWorkerHandler::InspectWorker(const std::string& version_uuid) { |
| 394 if (!enabled_) | 394 if (!enabled_) |
| 395 return Response::OK(); | 395 return Response::OK(); |
| 396 if (!context_) | 396 if (!context_) |
| 397 return CreateContextErrorResponse(); | 397 return CreateContextErrorResponse(); |
| 398 | 398 |
| 399 int64 id = 0; | 399 std::string id(version_uuid); |
| 400 if (!base::StringToInt64(version_id, &id)) | 400 if (id.empty()) |
| 401 return CreateInvalidVersionIdErrorResponse(); | 401 return CreateInvalidVersionIdErrorResponse(); |
| 402 BrowserThread::PostTask( | 402 BrowserThread::PostTask( |
| 403 BrowserThread::IO, FROM_HERE, | 403 BrowserThread::IO, FROM_HERE, |
| 404 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, | 404 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, |
| 405 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, | 405 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, |
| 406 weak_factory_.GetWeakPtr()))); | 406 weak_factory_.GetWeakPtr()))); |
| 407 return Response::OK(); | 407 return Response::OK(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 Response ServiceWorkerHandler::SkipWaiting(const std::string& version_id) { | 410 Response ServiceWorkerHandler::SkipWaiting(const std::string& version_uuid) { |
| 411 if (!enabled_) | 411 if (!enabled_) |
| 412 return Response::OK(); | 412 return Response::OK(); |
| 413 if (!context_) | 413 if (!context_) |
| 414 return CreateContextErrorResponse(); | 414 return CreateContextErrorResponse(); |
| 415 | 415 |
| 416 int64 id = 0; | 416 std::string id(version_uuid); |
| 417 if (!base::StringToInt64(version_id, &id)) | 417 if (id.empty()) |
| 418 return CreateInvalidVersionIdErrorResponse(); | 418 return CreateInvalidVersionIdErrorResponse(); |
| 419 context_->SimulateSkipWaiting(id); | 419 context_->SimulateSkipWaiting(id); |
| 420 return Response::OK(); | 420 return Response::OK(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { | 423 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { |
| 424 ServiceWorkerDevToolsManager::GetInstance() | 424 ServiceWorkerDevToolsManager::GetInstance() |
| 425 ->set_debug_service_worker_on_start(debug_on_start); | 425 ->set_debug_service_worker_on_start(debug_on_start); |
| 426 return Response::OK(); | 426 return Response::OK(); |
| 427 } | 427 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 std::vector<scoped_refptr<ServiceWorkerVersion>> version_values; | 495 std::vector<scoped_refptr<ServiceWorkerVersion>> version_values; |
| 496 for (const auto& version : versions) { | 496 for (const auto& version : versions) { |
| 497 version_values.push_back(CreateVersionDictionaryValue(version)); | 497 version_values.push_back(CreateVersionDictionaryValue(version)); |
| 498 } | 498 } |
| 499 client_->WorkerVersionUpdated( | 499 client_->WorkerVersionUpdated( |
| 500 WorkerVersionUpdatedParams::Create()->set_versions(version_values)); | 500 WorkerVersionUpdatedParams::Create()->set_versions(version_values)); |
| 501 } | 501 } |
| 502 | 502 |
| 503 void ServiceWorkerHandler::OnErrorReported( | 503 void ServiceWorkerHandler::OnErrorReported( |
| 504 int64 registration_id, | 504 int64 registration_id, |
| 505 int64 version_id, | 505 std::string version_uuid, |
| 506 const ServiceWorkerContextObserver::ErrorInfo& info) { | 506 const ServiceWorkerContextObserver::ErrorInfo& info) { |
| 507 client_->WorkerErrorReported( | 507 client_->WorkerErrorReported( |
| 508 WorkerErrorReportedParams::Create()->set_error_message( | 508 WorkerErrorReportedParams::Create()->set_error_message( |
| 509 ServiceWorkerErrorMessage::Create() | 509 ServiceWorkerErrorMessage::Create() |
| 510 ->set_error_message(base::UTF16ToUTF8(info.error_message)) | 510 ->set_error_message(base::UTF16ToUTF8(info.error_message)) |
| 511 ->set_registration_id(base::Int64ToString(registration_id)) | 511 ->set_registration_id(base::Int64ToString(registration_id)) |
| 512 ->set_version_id(base::Int64ToString(version_id)) | 512 ->set_version_id(version_uuid) |
| 513 ->set_source_url(info.source_url.spec()) | 513 ->set_source_url(info.source_url.spec()) |
| 514 ->set_line_number(info.line_number) | 514 ->set_line_number(info.line_number) |
| 515 ->set_column_number(info.column_number))); | 515 ->set_column_number(info.column_number))); |
| 516 } | 516 } |
| 517 | 517 |
| 518 void ServiceWorkerHandler::DispatchProtocolMessage( | 518 void ServiceWorkerHandler::DispatchProtocolMessage( |
| 519 DevToolsAgentHost* host, | 519 DevToolsAgentHost* host, |
| 520 const std::string& message) { | 520 const std::string& message) { |
| 521 | 521 |
| 522 auto it = attached_hosts_.find(host->GetId()); | 522 auto it = attached_hosts_.find(host->GetId()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 return; | 588 return; |
| 589 host->DetachClient(); | 589 host->DetachClient(); |
| 590 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 590 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 591 set_worker_id(host->GetId())); | 591 set_worker_id(host->GetId())); |
| 592 attached_hosts_.erase(it); | 592 attached_hosts_.erase(it); |
| 593 } | 593 } |
| 594 | 594 |
| 595 } // namespace service_worker | 595 } // namespace service_worker |
| 596 } // namespace devtools | 596 } // namespace devtools |
| 597 } // namespace content | 597 } // namespace content |
| OLD | NEW |