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 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
30 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_ui.h" | 32 #include "content/public/browser/web_ui.h" |
33 #include "content/public/browser/web_ui_data_source.h" | 33 #include "content/public/browser/web_ui_data_source.h" |
34 #include "content/public/common/child_process_host.h" | 34 #include "content/public/common/child_process_host.h" |
35 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
36 | 36 |
37 using base::DictionaryValue; | 37 using base::DictionaryValue; |
38 using base::FundamentalValue; | |
39 using base::ListValue; | 38 using base::ListValue; |
40 using base::StringValue; | 39 using base::StringValue; |
41 using base::Value; | 40 using base::Value; |
42 using base::WeakPtr; | 41 using base::WeakPtr; |
43 | 42 |
44 namespace content { | 43 namespace content { |
45 | 44 |
46 namespace { | 45 namespace { |
47 | 46 |
48 using GetRegistrationsCallback = | 47 using GetRegistrationsCallback = |
49 base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>&, | 48 base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>&, |
50 const std::vector<ServiceWorkerVersionInfo>&, | 49 const std::vector<ServiceWorkerVersionInfo>&, |
51 const std::vector<ServiceWorkerRegistrationInfo>&)>; | 50 const std::vector<ServiceWorkerRegistrationInfo>&)>; |
52 | 51 |
53 void OperationCompleteCallback(WeakPtr<ServiceWorkerInternalsUI> internals, | 52 void OperationCompleteCallback(WeakPtr<ServiceWorkerInternalsUI> internals, |
54 int callback_id, | 53 int callback_id, |
55 ServiceWorkerStatusCode status) { | 54 ServiceWorkerStatusCode status) { |
56 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 55 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
57 BrowserThread::PostTask( | 56 BrowserThread::PostTask( |
58 BrowserThread::UI, | 57 BrowserThread::UI, |
59 FROM_HERE, | 58 FROM_HERE, |
60 base::Bind(OperationCompleteCallback, internals, callback_id, status)); | 59 base::Bind(OperationCompleteCallback, internals, callback_id, status)); |
61 return; | 60 return; |
62 } | 61 } |
63 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
64 if (internals) { | 63 if (internals) { |
65 internals->web_ui()->CallJavascriptFunctionUnsafe( | 64 internals->web_ui()->CallJavascriptFunctionUnsafe( |
66 "serviceworker.onOperationComplete", | 65 "serviceworker.onOperationComplete", Value(static_cast<int>(status)), |
67 FundamentalValue(static_cast<int>(status)), | 66 Value(callback_id)); |
68 FundamentalValue(callback_id)); | |
69 } | 67 } |
70 } | 68 } |
71 | 69 |
72 void CallServiceWorkerVersionMethodWithVersionID( | 70 void CallServiceWorkerVersionMethodWithVersionID( |
73 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, | 71 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, |
74 scoped_refptr<ServiceWorkerContextWrapper> context, | 72 scoped_refptr<ServiceWorkerContextWrapper> context, |
75 int64_t version_id, | 73 int64_t version_id, |
76 const ServiceWorkerInternalsUI::StatusCallback& callback) { | 74 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
77 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 75 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
78 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 const std::vector<ServiceWorkerVersionInfo>& live_versions, | 254 const std::vector<ServiceWorkerVersionInfo>& live_versions, |
257 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { | 255 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { |
258 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 256 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
259 if (!internals) | 257 if (!internals) |
260 return; | 258 return; |
261 | 259 |
262 std::vector<std::unique_ptr<const Value>> args; | 260 std::vector<std::unique_ptr<const Value>> args; |
263 args.push_back(GetRegistrationListValue(live_registrations)); | 261 args.push_back(GetRegistrationListValue(live_registrations)); |
264 args.push_back(GetVersionListValue(live_versions)); | 262 args.push_back(GetVersionListValue(live_versions)); |
265 args.push_back(GetRegistrationListValue(stored_registrations)); | 263 args.push_back(GetRegistrationListValue(stored_registrations)); |
266 args.push_back(base::MakeUnique<FundamentalValue>(partition_id)); | 264 args.push_back(base::MakeUnique<Value>(partition_id)); |
267 args.push_back(base::MakeUnique<StringValue>(context_path.value())); | 265 args.push_back(base::MakeUnique<StringValue>(context_path.value())); |
268 internals->web_ui()->CallJavascriptFunctionUnsafe( | 266 internals->web_ui()->CallJavascriptFunctionUnsafe( |
269 "serviceworker.onPartitionData", ConvertToRawPtrVector(args)); | 267 "serviceworker.onPartitionData", ConvertToRawPtrVector(args)); |
270 } | 268 } |
271 | 269 |
272 } // namespace | 270 } // namespace |
273 | 271 |
274 class ServiceWorkerInternalsUI::PartitionObserver | 272 class ServiceWorkerInternalsUI::PartitionObserver |
275 : public ServiceWorkerContextObserver { | 273 : public ServiceWorkerContextObserver { |
276 public: | 274 public: |
277 PartitionObserver(int partition_id, WebUI* web_ui) | 275 PartitionObserver(int partition_id, WebUI* web_ui) |
278 : partition_id_(partition_id), web_ui_(web_ui) {} | 276 : partition_id_(partition_id), web_ui_(web_ui) {} |
279 ~PartitionObserver() override {} | 277 ~PartitionObserver() override {} |
280 // ServiceWorkerContextObserver overrides: | 278 // ServiceWorkerContextObserver overrides: |
281 void OnRunningStateChanged(int64_t version_id, | 279 void OnRunningStateChanged(int64_t version_id, |
282 EmbeddedWorkerStatus) override { | 280 EmbeddedWorkerStatus) override { |
283 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
284 web_ui_->CallJavascriptFunctionUnsafe( | 282 web_ui_->CallJavascriptFunctionUnsafe( |
285 "serviceworker.onRunningStateChanged", FundamentalValue(partition_id_), | 283 "serviceworker.onRunningStateChanged", Value(partition_id_), |
286 StringValue(base::Int64ToString(version_id))); | 284 StringValue(base::Int64ToString(version_id))); |
287 } | 285 } |
288 void OnVersionStateChanged(int64_t version_id, | 286 void OnVersionStateChanged(int64_t version_id, |
289 ServiceWorkerVersion::Status) override { | 287 ServiceWorkerVersion::Status) override { |
290 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 288 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
291 web_ui_->CallJavascriptFunctionUnsafe( | 289 web_ui_->CallJavascriptFunctionUnsafe( |
292 "serviceworker.onVersionStateChanged", FundamentalValue(partition_id_), | 290 "serviceworker.onVersionStateChanged", Value(partition_id_), |
293 StringValue(base::Int64ToString(version_id))); | 291 StringValue(base::Int64ToString(version_id))); |
294 } | 292 } |
295 void OnErrorReported(int64_t version_id, | 293 void OnErrorReported(int64_t version_id, |
296 int process_id, | 294 int process_id, |
297 int thread_id, | 295 int thread_id, |
298 const ErrorInfo& info) override { | 296 const ErrorInfo& info) override { |
299 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 297 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
300 std::vector<std::unique_ptr<const Value>> args; | 298 std::vector<std::unique_ptr<const Value>> args; |
301 args.push_back(base::MakeUnique<FundamentalValue>(partition_id_)); | 299 args.push_back(base::MakeUnique<Value>(partition_id_)); |
302 args.push_back( | 300 args.push_back( |
303 base::MakeUnique<StringValue>(base::Int64ToString(version_id))); | 301 base::MakeUnique<StringValue>(base::Int64ToString(version_id))); |
304 args.push_back(base::MakeUnique<FundamentalValue>(process_id)); | 302 args.push_back(base::MakeUnique<Value>(process_id)); |
305 args.push_back(base::MakeUnique<FundamentalValue>(thread_id)); | 303 args.push_back(base::MakeUnique<Value>(thread_id)); |
306 auto value = base::MakeUnique<DictionaryValue>(); | 304 auto value = base::MakeUnique<DictionaryValue>(); |
307 value->SetString("message", info.error_message); | 305 value->SetString("message", info.error_message); |
308 value->SetInteger("lineNumber", info.line_number); | 306 value->SetInteger("lineNumber", info.line_number); |
309 value->SetInteger("columnNumber", info.column_number); | 307 value->SetInteger("columnNumber", info.column_number); |
310 value->SetString("sourceURL", info.source_url.spec()); | 308 value->SetString("sourceURL", info.source_url.spec()); |
311 args.push_back(std::move(value)); | 309 args.push_back(std::move(value)); |
312 web_ui_->CallJavascriptFunctionUnsafe("serviceworker.onErrorReported", | 310 web_ui_->CallJavascriptFunctionUnsafe("serviceworker.onErrorReported", |
313 ConvertToRawPtrVector(args)); | 311 ConvertToRawPtrVector(args)); |
314 } | 312 } |
315 void OnReportConsoleMessage(int64_t version_id, | 313 void OnReportConsoleMessage(int64_t version_id, |
316 int process_id, | 314 int process_id, |
317 int thread_id, | 315 int thread_id, |
318 const ConsoleMessage& message) override { | 316 const ConsoleMessage& message) override { |
319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 317 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
320 std::vector<std::unique_ptr<const Value>> args; | 318 std::vector<std::unique_ptr<const Value>> args; |
321 args.push_back(base::MakeUnique<FundamentalValue>(partition_id_)); | 319 args.push_back(base::MakeUnique<Value>(partition_id_)); |
322 args.push_back( | 320 args.push_back( |
323 base::MakeUnique<StringValue>(base::Int64ToString(version_id))); | 321 base::MakeUnique<StringValue>(base::Int64ToString(version_id))); |
324 args.push_back(base::MakeUnique<FundamentalValue>(process_id)); | 322 args.push_back(base::MakeUnique<Value>(process_id)); |
325 args.push_back(base::MakeUnique<FundamentalValue>(thread_id)); | 323 args.push_back(base::MakeUnique<Value>(thread_id)); |
326 auto value = base::MakeUnique<DictionaryValue>(); | 324 auto value = base::MakeUnique<DictionaryValue>(); |
327 value->SetInteger("sourceIdentifier", message.source_identifier); | 325 value->SetInteger("sourceIdentifier", message.source_identifier); |
328 value->SetInteger("message_level", message.message_level); | 326 value->SetInteger("message_level", message.message_level); |
329 value->SetString("message", message.message); | 327 value->SetString("message", message.message); |
330 value->SetInteger("lineNumber", message.line_number); | 328 value->SetInteger("lineNumber", message.line_number); |
331 value->SetString("sourceURL", message.source_url.spec()); | 329 value->SetString("sourceURL", message.source_url.spec()); |
332 args.push_back(std::move(value)); | 330 args.push_back(std::move(value)); |
333 web_ui_->CallJavascriptFunctionUnsafe( | 331 web_ui_->CallJavascriptFunctionUnsafe( |
334 "serviceworker.onConsoleMessageReported", ConvertToRawPtrVector(args)); | 332 "serviceworker.onConsoleMessageReported", ConvertToRawPtrVector(args)); |
335 } | 333 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 613 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
616 return; | 614 return; |
617 } | 615 } |
618 | 616 |
619 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here | 617 // ServiceWorkerContextWrapper::UnregisterServiceWorker doesn't work here |
620 // because that reduces a status code to boolean. | 618 // because that reduces a status code to boolean. |
621 context->context()->UnregisterServiceWorker(scope, callback); | 619 context->context()->UnregisterServiceWorker(scope, callback); |
622 } | 620 } |
623 | 621 |
624 } // namespace content | 622 } // namespace content |
OLD | NEW |