| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 175 } |
| 176 return result; | 176 return result; |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) { | 179 bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) { |
| 180 urls->insert(tree_node->current_url()); | 180 urls->insert(tree_node->current_url()); |
| 181 return false; | 181 return false; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void StopServiceWorkerOnIO(scoped_refptr<ServiceWorkerContextWrapper> context, | 184 void StopServiceWorkerOnIO(scoped_refptr<ServiceWorkerContextWrapper> context, |
| 185 int64 version_id) { | 185 int64_t version_id) { |
| 186 if (content::ServiceWorkerVersion* version = | 186 if (content::ServiceWorkerVersion* version = |
| 187 context->GetLiveVersion(version_id)) { | 187 context->GetLiveVersion(version_id)) { |
| 188 version->StopWorker(base::Bind(&StatusNoOp)); | 188 version->StopWorker(base::Bind(&StatusNoOp)); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 void GetDevToolsRouteInfoOnIO( | 192 void GetDevToolsRouteInfoOnIO( |
| 193 scoped_refptr<ServiceWorkerContextWrapper> context, | 193 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 194 int64 version_id, | 194 int64_t version_id, |
| 195 const base::Callback<void(int, int)>& callback) { | 195 const base::Callback<void(int, int)>& callback) { |
| 196 if (content::ServiceWorkerVersion* version = | 196 if (content::ServiceWorkerVersion* version = |
| 197 context->GetLiveVersion(version_id)) { | 197 context->GetLiveVersion(version_id)) { |
| 198 BrowserThread::PostTask( | 198 BrowserThread::PostTask( |
| 199 BrowserThread::UI, FROM_HERE, | 199 BrowserThread::UI, FROM_HERE, |
| 200 base::Bind( | 200 base::Bind( |
| 201 callback, version->embedded_worker()->process_id(), | 201 callback, version->embedded_worker()->process_id(), |
| 202 version->embedded_worker()->worker_devtools_agent_route_id())); | 202 version->embedded_worker()->worker_devtools_agent_route_id())); |
| 203 } | 203 } |
| 204 } | 204 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 return CreateContextErrorResponse(); | 369 return CreateContextErrorResponse(); |
| 370 context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp)); | 370 context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp)); |
| 371 return Response::OK(); | 371 return Response::OK(); |
| 372 } | 372 } |
| 373 | 373 |
| 374 Response ServiceWorkerHandler::StopWorker(const std::string& version_id) { | 374 Response ServiceWorkerHandler::StopWorker(const std::string& version_id) { |
| 375 if (!enabled_) | 375 if (!enabled_) |
| 376 return Response::OK(); | 376 return Response::OK(); |
| 377 if (!context_) | 377 if (!context_) |
| 378 return CreateContextErrorResponse(); | 378 return CreateContextErrorResponse(); |
| 379 int64 id = 0; | 379 int64_t id = 0; |
| 380 if (!base::StringToInt64(version_id, &id)) | 380 if (!base::StringToInt64(version_id, &id)) |
| 381 return CreateInvalidVersionIdErrorResponse(); | 381 return CreateInvalidVersionIdErrorResponse(); |
| 382 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 382 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 383 base::Bind(&StopServiceWorkerOnIO, context_, id)); | 383 base::Bind(&StopServiceWorkerOnIO, context_, id)); |
| 384 return Response::OK(); | 384 return Response::OK(); |
| 385 } | 385 } |
| 386 | 386 |
| 387 Response ServiceWorkerHandler::UpdateRegistration( | 387 Response ServiceWorkerHandler::UpdateRegistration( |
| 388 const std::string& scope_url) { | 388 const std::string& scope_url) { |
| 389 if (!enabled_) | 389 if (!enabled_) |
| 390 return Response::OK(); | 390 return Response::OK(); |
| 391 if (!context_) | 391 if (!context_) |
| 392 return CreateContextErrorResponse(); | 392 return CreateContextErrorResponse(); |
| 393 context_->UpdateRegistration(GURL(scope_url)); | 393 context_->UpdateRegistration(GURL(scope_url)); |
| 394 return Response::OK(); | 394 return Response::OK(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) { | 397 Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) { |
| 398 if (!enabled_) | 398 if (!enabled_) |
| 399 return Response::OK(); | 399 return Response::OK(); |
| 400 if (!context_) | 400 if (!context_) |
| 401 return CreateContextErrorResponse(); | 401 return CreateContextErrorResponse(); |
| 402 | 402 |
| 403 int64 id = kInvalidServiceWorkerVersionId; | 403 int64_t id = kInvalidServiceWorkerVersionId; |
| 404 if (!base::StringToInt64(version_id, &id)) | 404 if (!base::StringToInt64(version_id, &id)) |
| 405 return CreateInvalidVersionIdErrorResponse(); | 405 return CreateInvalidVersionIdErrorResponse(); |
| 406 BrowserThread::PostTask( | 406 BrowserThread::PostTask( |
| 407 BrowserThread::IO, FROM_HERE, | 407 BrowserThread::IO, FROM_HERE, |
| 408 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, | 408 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, |
| 409 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, | 409 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, |
| 410 weak_factory_.GetWeakPtr()))); | 410 weak_factory_.GetWeakPtr()))); |
| 411 return Response::OK(); | 411 return Response::OK(); |
| 412 } | 412 } |
| 413 | 413 |
| 414 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { | 414 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { |
| 415 ServiceWorkerDevToolsManager::GetInstance() | 415 ServiceWorkerDevToolsManager::GetInstance() |
| 416 ->set_debug_service_worker_on_start(debug_on_start); | 416 ->set_debug_service_worker_on_start(debug_on_start); |
| 417 return Response::OK(); | 417 return Response::OK(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 Response ServiceWorkerHandler::SetForceUpdateOnPageLoad( | 420 Response ServiceWorkerHandler::SetForceUpdateOnPageLoad( |
| 421 const std::string& registration_id, | 421 const std::string& registration_id, |
| 422 bool force_update_on_page_load) { | 422 bool force_update_on_page_load) { |
| 423 if (!context_) | 423 if (!context_) |
| 424 return CreateContextErrorResponse(); | 424 return CreateContextErrorResponse(); |
| 425 int64 id = kInvalidServiceWorkerRegistrationId; | 425 int64_t id = kInvalidServiceWorkerRegistrationId; |
| 426 if (!base::StringToInt64(registration_id, &id)) | 426 if (!base::StringToInt64(registration_id, &id)) |
| 427 return CreateInvalidVersionIdErrorResponse(); | 427 return CreateInvalidVersionIdErrorResponse(); |
| 428 context_->SetForceUpdateOnPageLoad(id, force_update_on_page_load); | 428 context_->SetForceUpdateOnPageLoad(id, force_update_on_page_load); |
| 429 return Response::OK(); | 429 return Response::OK(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 Response ServiceWorkerHandler::DeliverPushMessage( | 432 Response ServiceWorkerHandler::DeliverPushMessage( |
| 433 const std::string& origin, | 433 const std::string& origin, |
| 434 const std::string& registration_id, | 434 const std::string& registration_id, |
| 435 const std::string& data) { | 435 const std::string& data) { |
| 436 if (!enabled_) | 436 if (!enabled_) |
| 437 return Response::OK(); | 437 return Response::OK(); |
| 438 if (!render_frame_host_) | 438 if (!render_frame_host_) |
| 439 return CreateContextErrorResponse(); | 439 return CreateContextErrorResponse(); |
| 440 int64 id = 0; | 440 int64_t id = 0; |
| 441 if (!base::StringToInt64(registration_id, &id)) | 441 if (!base::StringToInt64(registration_id, &id)) |
| 442 return CreateInvalidVersionIdErrorResponse(); | 442 return CreateInvalidVersionIdErrorResponse(); |
| 443 BrowserContext::DeliverPushMessage( | 443 BrowserContext::DeliverPushMessage( |
| 444 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, | 444 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, |
| 445 data, base::Bind(&PushDeliveryNoOp)); | 445 data, base::Bind(&PushDeliveryNoOp)); |
| 446 return Response::OK(); | 446 return Response::OK(); |
| 447 } | 447 } |
| 448 | 448 |
| 449 Response ServiceWorkerHandler::GetTargetInfo( | 449 Response ServiceWorkerHandler::GetTargetInfo( |
| 450 const std::string& target_id, | 450 const std::string& target_id, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 const std::vector<ServiceWorkerVersionInfo>& versions) { | 497 const std::vector<ServiceWorkerVersionInfo>& versions) { |
| 498 std::vector<scoped_refptr<ServiceWorkerVersion>> version_values; | 498 std::vector<scoped_refptr<ServiceWorkerVersion>> version_values; |
| 499 for (const auto& version : versions) { | 499 for (const auto& version : versions) { |
| 500 version_values.push_back(CreateVersionDictionaryValue(version)); | 500 version_values.push_back(CreateVersionDictionaryValue(version)); |
| 501 } | 501 } |
| 502 client_->WorkerVersionUpdated( | 502 client_->WorkerVersionUpdated( |
| 503 WorkerVersionUpdatedParams::Create()->set_versions(version_values)); | 503 WorkerVersionUpdatedParams::Create()->set_versions(version_values)); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void ServiceWorkerHandler::OnErrorReported( | 506 void ServiceWorkerHandler::OnErrorReported( |
| 507 int64 registration_id, | 507 int64_t registration_id, |
| 508 int64 version_id, | 508 int64_t version_id, |
| 509 const ServiceWorkerContextObserver::ErrorInfo& info) { | 509 const ServiceWorkerContextObserver::ErrorInfo& info) { |
| 510 client_->WorkerErrorReported( | 510 client_->WorkerErrorReported( |
| 511 WorkerErrorReportedParams::Create()->set_error_message( | 511 WorkerErrorReportedParams::Create()->set_error_message( |
| 512 ServiceWorkerErrorMessage::Create() | 512 ServiceWorkerErrorMessage::Create() |
| 513 ->set_error_message(base::UTF16ToUTF8(info.error_message)) | 513 ->set_error_message(base::UTF16ToUTF8(info.error_message)) |
| 514 ->set_registration_id(base::Int64ToString(registration_id)) | 514 ->set_registration_id(base::Int64ToString(registration_id)) |
| 515 ->set_version_id(base::Int64ToString(version_id)) | 515 ->set_version_id(base::Int64ToString(version_id)) |
| 516 ->set_source_url(info.source_url.spec()) | 516 ->set_source_url(info.source_url.spec()) |
| 517 ->set_line_number(info.line_number) | 517 ->set_line_number(info.line_number) |
| 518 ->set_column_number(info.column_number))); | 518 ->set_column_number(info.column_number))); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 return; | 593 return; |
| 594 host->DetachClient(); | 594 host->DetachClient(); |
| 595 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 595 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 596 set_worker_id(host->GetId())); | 596 set_worker_id(host->GetId())); |
| 597 attached_hosts_.erase(it); | 597 attached_hosts_.erase(it); |
| 598 } | 598 } |
| 599 | 599 |
| 600 } // namespace service_worker | 600 } // namespace service_worker |
| 601 } // namespace devtools | 601 } // namespace devtools |
| 602 } // namespace content | 602 } // namespace content |
| OLD | NEW |