| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 ServiceWorkerStatusCode status) { | 51 ServiceWorkerStatusCode status) { |
| 52 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 52 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 53 BrowserThread::PostTask( | 53 BrowserThread::PostTask( |
| 54 BrowserThread::UI, | 54 BrowserThread::UI, |
| 55 FROM_HERE, | 55 FROM_HERE, |
| 56 base::Bind(OperationCompleteCallback, internals, callback_id, status)); | 56 base::Bind(OperationCompleteCallback, internals, callback_id, status)); |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 60 if (internals) { | 60 if (internals) { |
| 61 internals->web_ui()->CallJavascriptFunction( | 61 internals->web_ui()->CallJavascriptFunctionUnsafe( |
| 62 "serviceworker.onOperationComplete", | 62 "serviceworker.onOperationComplete", |
| 63 FundamentalValue(static_cast<int>(status)), | 63 FundamentalValue(static_cast<int>(status)), |
| 64 FundamentalValue(callback_id)); | 64 FundamentalValue(callback_id)); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 void CallServiceWorkerVersionMethodWithVersionID( | 68 void CallServiceWorkerVersionMethodWithVersionID( |
| 69 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, | 69 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, |
| 70 scoped_refptr<ServiceWorkerContextWrapper> context, | 70 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 71 int64_t version_id, | 71 int64_t version_id, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 233 if (!internals) | 233 if (!internals) |
| 234 return; | 234 return; |
| 235 | 235 |
| 236 ScopedVector<const Value> args; | 236 ScopedVector<const Value> args; |
| 237 args.push_back(GetRegistrationListValue(live_registrations)); | 237 args.push_back(GetRegistrationListValue(live_registrations)); |
| 238 args.push_back(GetVersionListValue(live_versions)); | 238 args.push_back(GetVersionListValue(live_versions)); |
| 239 args.push_back(GetRegistrationListValue(stored_registrations)); | 239 args.push_back(GetRegistrationListValue(stored_registrations)); |
| 240 args.push_back(new FundamentalValue(partition_id)); | 240 args.push_back(new FundamentalValue(partition_id)); |
| 241 args.push_back(new StringValue(context_path.value())); | 241 args.push_back(new StringValue(context_path.value())); |
| 242 internals->web_ui()->CallJavascriptFunction("serviceworker.onPartitionData", | 242 internals->web_ui()->CallJavascriptFunctionUnsafe( |
| 243 args.get()); | 243 "serviceworker.onPartitionData", args.get()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace | 246 } // namespace |
| 247 | 247 |
| 248 class ServiceWorkerInternalsUI::PartitionObserver | 248 class ServiceWorkerInternalsUI::PartitionObserver |
| 249 : public ServiceWorkerContextObserver { | 249 : public ServiceWorkerContextObserver { |
| 250 public: | 250 public: |
| 251 PartitionObserver(int partition_id, WebUI* web_ui) | 251 PartitionObserver(int partition_id, WebUI* web_ui) |
| 252 : partition_id_(partition_id), web_ui_(web_ui) {} | 252 : partition_id_(partition_id), web_ui_(web_ui) {} |
| 253 ~PartitionObserver() override {} | 253 ~PartitionObserver() override {} |
| 254 // ServiceWorkerContextObserver overrides: | 254 // ServiceWorkerContextObserver overrides: |
| 255 void OnRunningStateChanged(int64_t version_id, | 255 void OnRunningStateChanged(int64_t version_id, |
| 256 ServiceWorkerVersion::RunningStatus) override { | 256 ServiceWorkerVersion::RunningStatus) override { |
| 257 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 257 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 258 web_ui_->CallJavascriptFunction( | 258 web_ui_->CallJavascriptFunctionUnsafe( |
| 259 "serviceworker.onRunningStateChanged", FundamentalValue(partition_id_), | 259 "serviceworker.onRunningStateChanged", FundamentalValue(partition_id_), |
| 260 StringValue(base::Int64ToString(version_id))); | 260 StringValue(base::Int64ToString(version_id))); |
| 261 } | 261 } |
| 262 void OnVersionStateChanged(int64_t version_id, | 262 void OnVersionStateChanged(int64_t version_id, |
| 263 ServiceWorkerVersion::Status) override { | 263 ServiceWorkerVersion::Status) override { |
| 264 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 264 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 265 web_ui_->CallJavascriptFunction( | 265 web_ui_->CallJavascriptFunctionUnsafe( |
| 266 "serviceworker.onVersionStateChanged", | 266 "serviceworker.onVersionStateChanged", FundamentalValue(partition_id_), |
| 267 FundamentalValue(partition_id_), | |
| 268 StringValue(base::Int64ToString(version_id))); | 267 StringValue(base::Int64ToString(version_id))); |
| 269 } | 268 } |
| 270 void OnErrorReported(int64_t version_id, | 269 void OnErrorReported(int64_t version_id, |
| 271 int process_id, | 270 int process_id, |
| 272 int thread_id, | 271 int thread_id, |
| 273 const ErrorInfo& info) override { | 272 const ErrorInfo& info) override { |
| 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 275 ScopedVector<const Value> args; | 274 ScopedVector<const Value> args; |
| 276 args.push_back(new FundamentalValue(partition_id_)); | 275 args.push_back(new FundamentalValue(partition_id_)); |
| 277 args.push_back(new StringValue(base::Int64ToString(version_id))); | 276 args.push_back(new StringValue(base::Int64ToString(version_id))); |
| 278 args.push_back(new FundamentalValue(process_id)); | 277 args.push_back(new FundamentalValue(process_id)); |
| 279 args.push_back(new FundamentalValue(thread_id)); | 278 args.push_back(new FundamentalValue(thread_id)); |
| 280 std::unique_ptr<DictionaryValue> value(new DictionaryValue()); | 279 std::unique_ptr<DictionaryValue> value(new DictionaryValue()); |
| 281 value->SetString("message", info.error_message); | 280 value->SetString("message", info.error_message); |
| 282 value->SetInteger("lineNumber", info.line_number); | 281 value->SetInteger("lineNumber", info.line_number); |
| 283 value->SetInteger("columnNumber", info.column_number); | 282 value->SetInteger("columnNumber", info.column_number); |
| 284 value->SetString("sourceURL", info.source_url.spec()); | 283 value->SetString("sourceURL", info.source_url.spec()); |
| 285 args.push_back(value.release()); | 284 args.push_back(value.release()); |
| 286 web_ui_->CallJavascriptFunction("serviceworker.onErrorReported", | 285 web_ui_->CallJavascriptFunctionUnsafe("serviceworker.onErrorReported", |
| 287 args.get()); | 286 args.get()); |
| 288 } | 287 } |
| 289 void OnReportConsoleMessage(int64_t version_id, | 288 void OnReportConsoleMessage(int64_t version_id, |
| 290 int process_id, | 289 int process_id, |
| 291 int thread_id, | 290 int thread_id, |
| 292 const ConsoleMessage& message) override { | 291 const ConsoleMessage& message) override { |
| 293 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 294 ScopedVector<const Value> args; | 293 ScopedVector<const Value> args; |
| 295 args.push_back(new FundamentalValue(partition_id_)); | 294 args.push_back(new FundamentalValue(partition_id_)); |
| 296 args.push_back(new StringValue(base::Int64ToString(version_id))); | 295 args.push_back(new StringValue(base::Int64ToString(version_id))); |
| 297 args.push_back(new FundamentalValue(process_id)); | 296 args.push_back(new FundamentalValue(process_id)); |
| 298 args.push_back(new FundamentalValue(thread_id)); | 297 args.push_back(new FundamentalValue(thread_id)); |
| 299 std::unique_ptr<DictionaryValue> value(new DictionaryValue()); | 298 std::unique_ptr<DictionaryValue> value(new DictionaryValue()); |
| 300 value->SetInteger("sourceIdentifier", message.source_identifier); | 299 value->SetInteger("sourceIdentifier", message.source_identifier); |
| 301 value->SetInteger("message_level", message.message_level); | 300 value->SetInteger("message_level", message.message_level); |
| 302 value->SetString("message", message.message); | 301 value->SetString("message", message.message); |
| 303 value->SetInteger("lineNumber", message.line_number); | 302 value->SetInteger("lineNumber", message.line_number); |
| 304 value->SetString("sourceURL", message.source_url.spec()); | 303 value->SetString("sourceURL", message.source_url.spec()); |
| 305 args.push_back(value.release()); | 304 args.push_back(value.release()); |
| 306 web_ui_->CallJavascriptFunction("serviceworker.onConsoleMessageReported", | 305 web_ui_->CallJavascriptFunctionUnsafe( |
| 307 args.get()); | 306 "serviceworker.onConsoleMessageReported", args.get()); |
| 308 } | 307 } |
| 309 void OnRegistrationStored(int64_t registration_id, | 308 void OnRegistrationStored(int64_t registration_id, |
| 310 const GURL& pattern) override { | 309 const GURL& pattern) override { |
| 311 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 310 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 312 web_ui_->CallJavascriptFunction("serviceworker.onRegistrationStored", | 311 web_ui_->CallJavascriptFunctionUnsafe("serviceworker.onRegistrationStored", |
| 313 StringValue(pattern.spec())); | 312 StringValue(pattern.spec())); |
| 314 } | 313 } |
| 315 void OnRegistrationDeleted(int64_t registration_id, | 314 void OnRegistrationDeleted(int64_t registration_id, |
| 316 const GURL& pattern) override { | 315 const GURL& pattern) override { |
| 317 web_ui_->CallJavascriptFunction("serviceworker.onRegistrationDeleted", | 316 web_ui_->CallJavascriptFunctionUnsafe("serviceworker.onRegistrationDeleted", |
| 318 StringValue(pattern.spec())); | 317 StringValue(pattern.spec())); |
| 319 } | 318 } |
| 320 int partition_id() const { return partition_id_; } | 319 int partition_id() const { return partition_id_; } |
| 321 | 320 |
| 322 private: | 321 private: |
| 323 const int partition_id_; | 322 const int partition_id_; |
| 324 WebUI* const web_ui_; | 323 WebUI* const web_ui_; |
| 325 }; | 324 }; |
| 326 | 325 |
| 327 ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) | 326 ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) |
| 328 : WebUIController(web_ui), next_partition_id_(0) { | 327 : WebUIController(web_ui), next_partition_id_(0) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 base::Bind(&ServiceWorkerInternalsUI::RemoveObserverFromStoragePartition, | 378 base::Bind(&ServiceWorkerInternalsUI::RemoveObserverFromStoragePartition, |
| 380 base::Unretained(this)); | 379 base::Unretained(this)); |
| 381 BrowserContext::ForEachStoragePartition(browser_context, remove_observer_cb); | 380 BrowserContext::ForEachStoragePartition(browser_context, remove_observer_cb); |
| 382 } | 381 } |
| 383 | 382 |
| 384 void ServiceWorkerInternalsUI::GetOptions(const ListValue* args) { | 383 void ServiceWorkerInternalsUI::GetOptions(const ListValue* args) { |
| 385 DictionaryValue options; | 384 DictionaryValue options; |
| 386 options.SetBoolean("debug_on_start", | 385 options.SetBoolean("debug_on_start", |
| 387 ServiceWorkerDevToolsManager::GetInstance() | 386 ServiceWorkerDevToolsManager::GetInstance() |
| 388 ->debug_service_worker_on_start()); | 387 ->debug_service_worker_on_start()); |
| 389 web_ui()->CallJavascriptFunction("serviceworker.onOptions", options); | 388 web_ui()->CallJavascriptFunctionUnsafe("serviceworker.onOptions", options); |
| 390 } | 389 } |
| 391 | 390 |
| 392 void ServiceWorkerInternalsUI::SetOption(const ListValue* args) { | 391 void ServiceWorkerInternalsUI::SetOption(const ListValue* args) { |
| 393 std::string option_name; | 392 std::string option_name; |
| 394 bool option_boolean; | 393 bool option_boolean; |
| 395 if (!args->GetString(0, &option_name) || option_name != "debug_on_start" || | 394 if (!args->GetString(0, &option_name) || option_name != "debug_on_start" || |
| 396 !args->GetBoolean(1, &option_boolean)) { | 395 !args->GetBoolean(1, &option_boolean)) { |
| 397 return; | 396 return; |
| 398 } | 397 } |
| 399 ServiceWorkerDevToolsManager::GetInstance() | 398 ServiceWorkerDevToolsManager::GetInstance() |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 586 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 588 return; | 587 return; |
| 589 } | 588 } |
| 590 | 589 |
| 591 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here | 590 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here |
| 592 // because that reduces a status code to boolean. | 591 // because that reduces a status code to boolean. |
| 593 context->context()->UnregisterServiceWorker(scope, callback); | 592 context->context()->UnregisterServiceWorker(scope, callback); |
| 594 } | 593 } |
| 595 | 594 |
| 596 } // namespace content | 595 } // namespace content |
| OLD | NEW |