| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (content::ServiceWorkerVersion* version = | 163 if (content::ServiceWorkerVersion* version = |
| 164 context->GetLiveVersion(version_id)) { | 164 context->GetLiveVersion(version_id)) { |
| 165 BrowserThread::PostTask( | 165 BrowserThread::PostTask( |
| 166 BrowserThread::UI, FROM_HERE, | 166 BrowserThread::UI, FROM_HERE, |
| 167 base::Bind( | 167 base::Bind( |
| 168 callback, version->embedded_worker()->process_id(), | 168 callback, version->embedded_worker()->process_id(), |
| 169 version->embedded_worker()->worker_devtools_agent_route_id())); | 169 version->embedded_worker()->worker_devtools_agent_route_id())); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 Response CreateContextErrorResoponse() { | 173 Response CreateContextErrorResponse() { |
| 174 return Response::InternalError("Could not connect to the context"); | 174 return Response::InternalError("Could not connect to the context"); |
| 175 } | 175 } |
| 176 | 176 |
| 177 Response CreateInvalidVersionIdErrorResoponse() { | 177 Response CreateInvalidVersionIdErrorResponse() { |
| 178 return Response::InternalError("Invalid version ID"); | 178 return Response::InternalError("Invalid version ID"); |
| 179 } | 179 } |
| 180 | 180 |
| 181 } // namespace | 181 } // namespace |
| 182 | 182 |
| 183 ServiceWorkerHandler::ServiceWorkerHandler() | 183 ServiceWorkerHandler::ServiceWorkerHandler() |
| 184 : enabled_(false), weak_factory_(this) { | 184 : enabled_(false), weak_factory_(this) { |
| 185 } | 185 } |
| 186 | 186 |
| 187 ServiceWorkerHandler::~ServiceWorkerHandler() { | 187 ServiceWorkerHandler::~ServiceWorkerHandler() { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (it == attached_hosts_.end()) | 295 if (it == attached_hosts_.end()) |
| 296 return Response::InternalError("Not connected to the worker"); | 296 return Response::InternalError("Not connected to the worker"); |
| 297 it->second->UnregisterWorker(); | 297 it->second->UnregisterWorker(); |
| 298 return Response::OK(); | 298 return Response::OK(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 Response ServiceWorkerHandler::Unregister(const std::string& scope_url) { | 301 Response ServiceWorkerHandler::Unregister(const std::string& scope_url) { |
| 302 if (!enabled_) | 302 if (!enabled_) |
| 303 return Response::OK(); | 303 return Response::OK(); |
| 304 if (!context_) | 304 if (!context_) |
| 305 return CreateContextErrorResoponse(); | 305 return CreateContextErrorResponse(); |
| 306 context_->UnregisterServiceWorker(GURL(scope_url), base::Bind(&ResultNoOp)); | 306 context_->UnregisterServiceWorker(GURL(scope_url), base::Bind(&ResultNoOp)); |
| 307 return Response::OK(); | 307 return Response::OK(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 Response ServiceWorkerHandler::StartWorker(const std::string& scope_url) { | 310 Response ServiceWorkerHandler::StartWorker(const std::string& scope_url) { |
| 311 if (!enabled_) | 311 if (!enabled_) |
| 312 return Response::OK(); | 312 return Response::OK(); |
| 313 if (!context_) | 313 if (!context_) |
| 314 return CreateContextErrorResoponse(); | 314 return CreateContextErrorResponse(); |
| 315 context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp)); | 315 context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp)); |
| 316 return Response::OK(); | 316 return Response::OK(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 Response ServiceWorkerHandler::StopWorker(const std::string& version_id) { | 319 Response ServiceWorkerHandler::StopWorker(const std::string& version_id) { |
| 320 if (!enabled_) | 320 if (!enabled_) |
| 321 return Response::OK(); | 321 return Response::OK(); |
| 322 if (!context_) | 322 if (!context_) |
| 323 return CreateContextErrorResoponse(); | 323 return CreateContextErrorResponse(); |
| 324 int64 id = 0; | 324 int64 id = 0; |
| 325 if (!base::StringToInt64(version_id, &id)) | 325 if (!base::StringToInt64(version_id, &id)) |
| 326 return CreateInvalidVersionIdErrorResoponse(); | 326 return CreateInvalidVersionIdErrorResponse(); |
| 327 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 327 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 328 base::Bind(&StopServiceWorkerOnIO, context_, id)); | 328 base::Bind(&StopServiceWorkerOnIO, context_, id)); |
| 329 return Response::OK(); | 329 return Response::OK(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 Response ServiceWorkerHandler::UpdateRegistration( | 332 Response ServiceWorkerHandler::UpdateRegistration( |
| 333 const std::string& scope_url) { | 333 const std::string& scope_url) { |
| 334 if (!enabled_) | 334 if (!enabled_) |
| 335 return Response::OK(); | 335 return Response::OK(); |
| 336 if (!context_) | 336 if (!context_) |
| 337 return CreateContextErrorResoponse(); | 337 return CreateContextErrorResponse(); |
| 338 context_->UpdateRegistration(GURL(scope_url)); | 338 context_->UpdateRegistration(GURL(scope_url)); |
| 339 return Response::OK(); | 339 return Response::OK(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) { | 342 Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) { |
| 343 if (!enabled_) | 343 if (!enabled_) |
| 344 return Response::OK(); | 344 return Response::OK(); |
| 345 if (!context_) | 345 if (!context_) |
| 346 return CreateContextErrorResoponse(); | 346 return CreateContextErrorResponse(); |
| 347 | 347 |
| 348 int64 id = 0; | 348 int64 id = 0; |
| 349 if (!base::StringToInt64(version_id, &id)) | 349 if (!base::StringToInt64(version_id, &id)) |
| 350 return CreateInvalidVersionIdErrorResoponse(); | 350 return CreateInvalidVersionIdErrorResponse(); |
| 351 BrowserThread::PostTask( | 351 BrowserThread::PostTask( |
| 352 BrowserThread::IO, FROM_HERE, | 352 BrowserThread::IO, FROM_HERE, |
| 353 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, | 353 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, |
| 354 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, | 354 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, |
| 355 weak_factory_.GetWeakPtr()))); | 355 weak_factory_.GetWeakPtr()))); |
| 356 return Response::OK(); | 356 return Response::OK(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 Response ServiceWorkerHandler::SkipWaiting(const std::string& version_id) { |
| 360 if (!enabled_) |
| 361 return Response::OK(); |
| 362 if (!context_) |
| 363 return CreateContextErrorResponse(); |
| 364 |
| 365 int64 id = 0; |
| 366 if (!base::StringToInt64(version_id, &id)) |
| 367 return CreateInvalidVersionIdErrorResponse(); |
| 368 context_->SimulateSkipWaiting(id); |
| 369 return Response::OK(); |
| 370 } |
| 371 |
| 359 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { | 372 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { |
| 360 ServiceWorkerDevToolsManager::GetInstance() | 373 ServiceWorkerDevToolsManager::GetInstance() |
| 361 ->set_debug_service_worker_on_start(debug_on_start); | 374 ->set_debug_service_worker_on_start(debug_on_start); |
| 362 return Response::OK(); | 375 return Response::OK(); |
| 363 } | 376 } |
| 364 | 377 |
| 365 Response ServiceWorkerHandler::DeliverPushMessage( | 378 Response ServiceWorkerHandler::DeliverPushMessage( |
| 366 const std::string& origin, | 379 const std::string& origin, |
| 367 const std::string& registration_id, | 380 const std::string& registration_id, |
| 368 const std::string& data) { | 381 const std::string& data) { |
| 369 if (!enabled_) | 382 if (!enabled_) |
| 370 return Response::OK(); | 383 return Response::OK(); |
| 371 if (!render_frame_host_) | 384 if (!render_frame_host_) |
| 372 return CreateContextErrorResoponse(); | 385 return CreateContextErrorResponse(); |
| 373 int64 id = 0; | 386 int64 id = 0; |
| 374 if (!base::StringToInt64(registration_id, &id)) | 387 if (!base::StringToInt64(registration_id, &id)) |
| 375 return CreateInvalidVersionIdErrorResoponse(); | 388 return CreateInvalidVersionIdErrorResponse(); |
| 376 BrowserContext::DeliverPushMessage( | 389 BrowserContext::DeliverPushMessage( |
| 377 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, | 390 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, |
| 378 data, base::Bind(&PushDeliveryNoOp)); | 391 data, base::Bind(&PushDeliveryNoOp)); |
| 379 return Response::OK(); | 392 return Response::OK(); |
| 380 } | 393 } |
| 381 | 394 |
| 382 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, | 395 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, |
| 383 int devtools_agent_route_id) { | 396 int devtools_agent_route_id) { |
| 384 scoped_refptr<DevToolsAgentHostImpl> agent_host( | 397 scoped_refptr<DevToolsAgentHostImpl> agent_host( |
| 385 ServiceWorkerDevToolsManager::GetInstance() | 398 ServiceWorkerDevToolsManager::GetInstance() |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 return; | 508 return; |
| 496 host->DetachClient(); | 509 host->DetachClient(); |
| 497 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 510 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 498 set_worker_id(host->GetId())); | 511 set_worker_id(host->GetId())); |
| 499 attached_hosts_.erase(it); | 512 attached_hosts_.erase(it); |
| 500 } | 513 } |
| 501 | 514 |
| 502 } // namespace service_worker | 515 } // namespace service_worker |
| 503 } // namespace devtools | 516 } // namespace devtools |
| 504 } // namespace content | 517 } // namespace content |
| OLD | NEW |