| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 void OperationCompleteCallback(WeakPtr<ServiceWorkerInternalsUI> internals, | 40 void OperationCompleteCallback(WeakPtr<ServiceWorkerInternalsUI> internals, |
| 41 int callback_id, | 41 int callback_id, |
| 42 ServiceWorkerStatusCode status) { | 42 ServiceWorkerStatusCode status) { |
| 43 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 43 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 44 BrowserThread::PostTask( | 44 BrowserThread::PostTask( |
| 45 BrowserThread::UI, | 45 BrowserThread::UI, |
| 46 FROM_HERE, | 46 FROM_HERE, |
| 47 base::Bind(OperationCompleteCallback, internals, callback_id, status)); | 47 base::Bind(OperationCompleteCallback, internals, callback_id, status)); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 51 if (internals) { | 51 if (internals) { |
| 52 internals->web_ui()->CallJavascriptFunction( | 52 internals->web_ui()->CallJavascriptFunction( |
| 53 "serviceworker.onOperationComplete", | 53 "serviceworker.onOperationComplete", |
| 54 FundamentalValue(static_cast<int>(status)), | 54 FundamentalValue(static_cast<int>(status)), |
| 55 FundamentalValue(callback_id)); | 55 FundamentalValue(callback_id)); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CallServiceWorkerVersionMethodWithVersionID( | 59 void CallServiceWorkerVersionMethodWithVersionID( |
| 60 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, | 60 ServiceWorkerInternalsUI::ServiceWorkerVersionMethod method, |
| 61 scoped_refptr<ServiceWorkerContextWrapper> context, | 61 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 62 int64 version_id, | 62 int64 version_id, |
| 63 const ServiceWorkerInternalsUI::StatusCallback& callback) { | 63 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
| 64 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 64 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 65 BrowserThread::PostTask( | 65 BrowserThread::PostTask( |
| 66 BrowserThread::IO, | 66 BrowserThread::IO, |
| 67 FROM_HERE, | 67 FROM_HERE, |
| 68 base::Bind(CallServiceWorkerVersionMethodWithVersionID, | 68 base::Bind(CallServiceWorkerVersionMethodWithVersionID, |
| 69 method, | 69 method, |
| 70 context, | 70 context, |
| 71 version_id, | 71 version_id, |
| 72 callback)); | 72 callback)); |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 76 scoped_refptr<ServiceWorkerVersion> version = | 76 scoped_refptr<ServiceWorkerVersion> version = |
| 77 context->context()->GetLiveVersion(version_id); | 77 context->context()->GetLiveVersion(version_id); |
| 78 if (!version.get()) { | 78 if (!version.get()) { |
| 79 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 79 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 (*version.get().*method)(callback); | 82 (*version.get().*method)(callback); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void DispatchPushEventWithVersionID( | 85 void DispatchPushEventWithVersionID( |
| 86 scoped_refptr<ServiceWorkerContextWrapper> context, | 86 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 87 int64 version_id, | 87 int64 version_id, |
| 88 const ServiceWorkerInternalsUI::StatusCallback& callback) { | 88 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
| 89 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 89 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 90 BrowserThread::PostTask( | 90 BrowserThread::PostTask( |
| 91 BrowserThread::IO, | 91 BrowserThread::IO, |
| 92 FROM_HERE, | 92 FROM_HERE, |
| 93 base::Bind(DispatchPushEventWithVersionID, | 93 base::Bind(DispatchPushEventWithVersionID, |
| 94 context, | 94 context, |
| 95 version_id, | 95 version_id, |
| 96 callback)); | 96 callback)); |
| 97 return; | 97 return; |
| 98 } | 98 } |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 100 scoped_refptr<ServiceWorkerVersion> version = | 100 scoped_refptr<ServiceWorkerVersion> version = |
| 101 context->context()->GetLiveVersion(version_id); | 101 context->context()->GetLiveVersion(version_id); |
| 102 if (!version.get()) { | 102 if (!version.get()) { |
| 103 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 103 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 std::string data = "Test push message from ServiceWorkerInternals."; | 106 std::string data = "Test push message from ServiceWorkerInternals."; |
| 107 version->DispatchPushEvent(callback, data); | 107 version->DispatchPushEvent(callback, data); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void UnregisterWithScope( | 110 void UnregisterWithScope( |
| 111 scoped_refptr<ServiceWorkerContextWrapper> context, | 111 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 112 const GURL& scope, | 112 const GURL& scope, |
| 113 const ServiceWorkerInternalsUI::StatusCallback& callback) { | 113 const ServiceWorkerInternalsUI::StatusCallback& callback) { |
| 114 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 114 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 115 BrowserThread::PostTask( | 115 BrowserThread::PostTask( |
| 116 BrowserThread::IO, | 116 BrowserThread::IO, |
| 117 FROM_HERE, | 117 FROM_HERE, |
| 118 base::Bind(UnregisterWithScope, context, scope, callback)); | 118 base::Bind(UnregisterWithScope, context, scope, callback)); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 121 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 122 context->context()->UnregisterServiceWorker(scope, callback); | 122 context->context()->UnregisterServiceWorker(scope, callback); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void WorkerStarted(const scoped_refptr<ServiceWorkerRegistration>& registration, | 125 void WorkerStarted(const scoped_refptr<ServiceWorkerRegistration>& registration, |
| 126 const ServiceWorkerInternalsUI::StatusCallback& callback, | 126 const ServiceWorkerInternalsUI::StatusCallback& callback, |
| 127 ServiceWorkerStatusCode status) { | 127 ServiceWorkerStatusCode status) { |
| 128 callback.Run(status); | 128 callback.Run(status); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void StartActiveWorker( | 131 void StartActiveWorker( |
| 132 const ServiceWorkerInternalsUI::StatusCallback& callback, | 132 const ServiceWorkerInternalsUI::StatusCallback& callback, |
| 133 ServiceWorkerStatusCode status, | 133 ServiceWorkerStatusCode status, |
| 134 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 134 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 135 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 136 if (status == SERVICE_WORKER_OK) { | 136 if (status == SERVICE_WORKER_OK) { |
| 137 // Pass the reference of |registration| to WorkerStarted callback to prevent | 137 // Pass the reference of |registration| to WorkerStarted callback to prevent |
| 138 // it from being deleted while starting the worker. If the refcount of | 138 // it from being deleted while starting the worker. If the refcount of |
| 139 // |registration| is 1, it will be deleted after WorkerStarted is called. | 139 // |registration| is 1, it will be deleted after WorkerStarted is called. |
| 140 registration->active_version()->StartWorker( | 140 registration->active_version()->StartWorker( |
| 141 base::Bind(WorkerStarted, registration, callback)); | 141 base::Bind(WorkerStarted, registration, callback)); |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 144 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void FindRegistrationForPattern( | 147 void FindRegistrationForPattern( |
| 148 scoped_refptr<ServiceWorkerContextWrapper> context, | 148 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 149 const GURL& scope, | 149 const GURL& scope, |
| 150 const ServiceWorkerStorage::FindRegistrationCallback callback) { | 150 const ServiceWorkerStorage::FindRegistrationCallback callback) { |
| 151 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 151 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 152 BrowserThread::PostTask( | 152 BrowserThread::PostTask( |
| 153 BrowserThread::IO, | 153 BrowserThread::IO, |
| 154 FROM_HERE, | 154 FROM_HERE, |
| 155 base::Bind(FindRegistrationForPattern, context, scope, callback)); | 155 base::Bind(FindRegistrationForPattern, context, scope, callback)); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 158 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 159 context->context()->storage()->FindRegistrationForPattern(scope, callback); | 159 context->context()->storage()->FindRegistrationForPattern(scope, callback); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, | 162 void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, |
| 163 DictionaryValue* info) { | 163 DictionaryValue* info) { |
| 164 switch (version.running_status) { | 164 switch (version.running_status) { |
| 165 case ServiceWorkerVersion::STOPPED: | 165 case ServiceWorkerVersion::STOPPED: |
| 166 info->SetString("running_status", "STOPPED"); | 166 info->SetString("running_status", "STOPPED"); |
| 167 break; | 167 break; |
| 168 case ServiceWorkerVersion::STARTING: | 168 case ServiceWorkerVersion::STARTING: |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 UpdateVersionInfo(*it, info); | 246 UpdateVersionInfo(*it, info); |
| 247 result->Append(info); | 247 result->Append(info); |
| 248 } | 248 } |
| 249 return result; | 249 return result; |
| 250 } | 250 } |
| 251 | 251 |
| 252 void GetRegistrationsOnIOThread( | 252 void GetRegistrationsOnIOThread( |
| 253 scoped_refptr<ServiceWorkerContextWrapper> context, | 253 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 254 base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>&)> | 254 base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>&)> |
| 255 callback) { | 255 callback) { |
| 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 256 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 257 context->context()->storage()->GetAllRegistrations(callback); | 257 context->context()->storage()->GetAllRegistrations(callback); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void OnStoredRegistrations( | 260 void OnStoredRegistrations( |
| 261 scoped_refptr<ServiceWorkerContextWrapper> context, | 261 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 262 base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>&, | 262 base::Callback<void(const std::vector<ServiceWorkerRegistrationInfo>&, |
| 263 const std::vector<ServiceWorkerVersionInfo>&, | 263 const std::vector<ServiceWorkerVersionInfo>&, |
| 264 const std::vector<ServiceWorkerRegistrationInfo>&)> | 264 const std::vector<ServiceWorkerRegistrationInfo>&)> |
| 265 callback, | 265 callback, |
| 266 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { | 266 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { |
| 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 267 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 268 BrowserThread::PostTask( | 268 BrowserThread::PostTask( |
| 269 BrowserThread::UI, | 269 BrowserThread::UI, |
| 270 FROM_HERE, | 270 FROM_HERE, |
| 271 base::Bind(callback, | 271 base::Bind(callback, |
| 272 context->context()->GetAllLiveRegistrationInfo(), | 272 context->context()->GetAllLiveRegistrationInfo(), |
| 273 context->context()->GetAllLiveVersionInfo(), | 273 context->context()->GetAllLiveVersionInfo(), |
| 274 stored_registrations)); | 274 stored_registrations)); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void OnAllRegistrations( | 277 void OnAllRegistrations( |
| 278 WeakPtr<ServiceWorkerInternalsUI> internals, | 278 WeakPtr<ServiceWorkerInternalsUI> internals, |
| 279 int partition_id, | 279 int partition_id, |
| 280 const base::FilePath& context_path, | 280 const base::FilePath& context_path, |
| 281 const std::vector<ServiceWorkerRegistrationInfo>& live_registrations, | 281 const std::vector<ServiceWorkerRegistrationInfo>& live_registrations, |
| 282 const std::vector<ServiceWorkerVersionInfo>& live_versions, | 282 const std::vector<ServiceWorkerVersionInfo>& live_versions, |
| 283 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { | 283 const std::vector<ServiceWorkerRegistrationInfo>& stored_registrations) { |
| 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 284 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 285 if (!internals) | 285 if (!internals) |
| 286 return; | 286 return; |
| 287 | 287 |
| 288 ScopedVector<const Value> args; | 288 ScopedVector<const Value> args; |
| 289 args.push_back(GetRegistrationListValue(live_registrations)); | 289 args.push_back(GetRegistrationListValue(live_registrations)); |
| 290 args.push_back(GetVersionListValue(live_versions)); | 290 args.push_back(GetVersionListValue(live_versions)); |
| 291 args.push_back(GetRegistrationListValue(stored_registrations)); | 291 args.push_back(GetRegistrationListValue(stored_registrations)); |
| 292 args.push_back(new FundamentalValue(partition_id)); | 292 args.push_back(new FundamentalValue(partition_id)); |
| 293 args.push_back(new StringValue(context_path.value())); | 293 args.push_back(new StringValue(context_path.value())); |
| 294 internals->web_ui()->CallJavascriptFunction("serviceworker.onPartitionData", | 294 internals->web_ui()->CallJavascriptFunction("serviceworker.onPartitionData", |
| 295 args.get()); | 295 args.get()); |
| 296 } | 296 } |
| 297 | 297 |
| 298 } // namespace | 298 } // namespace |
| 299 | 299 |
| 300 class ServiceWorkerInternalsUI::PartitionObserver | 300 class ServiceWorkerInternalsUI::PartitionObserver |
| 301 : public ServiceWorkerContextObserver { | 301 : public ServiceWorkerContextObserver { |
| 302 public: | 302 public: |
| 303 PartitionObserver(int partition_id, WebUI* web_ui) | 303 PartitionObserver(int partition_id, WebUI* web_ui) |
| 304 : partition_id_(partition_id), web_ui_(web_ui) {} | 304 : partition_id_(partition_id), web_ui_(web_ui) {} |
| 305 ~PartitionObserver() override {} | 305 ~PartitionObserver() override {} |
| 306 // ServiceWorkerContextObserver overrides: | 306 // ServiceWorkerContextObserver overrides: |
| 307 void OnRunningStateChanged(int64 version_id) override { | 307 void OnRunningStateChanged(int64 version_id) override { |
| 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 308 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 309 web_ui_->CallJavascriptFunction( | 309 web_ui_->CallJavascriptFunction( |
| 310 "serviceworker.onRunningStateChanged", FundamentalValue(partition_id_), | 310 "serviceworker.onRunningStateChanged", FundamentalValue(partition_id_), |
| 311 StringValue(base::Int64ToString(version_id))); | 311 StringValue(base::Int64ToString(version_id))); |
| 312 } | 312 } |
| 313 void OnVersionStateChanged(int64 version_id) override { | 313 void OnVersionStateChanged(int64 version_id) override { |
| 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 314 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 315 web_ui_->CallJavascriptFunction( | 315 web_ui_->CallJavascriptFunction( |
| 316 "serviceworker.onVersionStateChanged", | 316 "serviceworker.onVersionStateChanged", |
| 317 FundamentalValue(partition_id_), | 317 FundamentalValue(partition_id_), |
| 318 StringValue(base::Int64ToString(version_id))); | 318 StringValue(base::Int64ToString(version_id))); |
| 319 } | 319 } |
| 320 void OnErrorReported(int64 version_id, | 320 void OnErrorReported(int64 version_id, |
| 321 int process_id, | 321 int process_id, |
| 322 int thread_id, | 322 int thread_id, |
| 323 const ErrorInfo& info) override { | 323 const ErrorInfo& info) override { |
| 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 324 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 325 ScopedVector<const Value> args; | 325 ScopedVector<const Value> args; |
| 326 args.push_back(new FundamentalValue(partition_id_)); | 326 args.push_back(new FundamentalValue(partition_id_)); |
| 327 args.push_back(new StringValue(base::Int64ToString(version_id))); | 327 args.push_back(new StringValue(base::Int64ToString(version_id))); |
| 328 args.push_back(new FundamentalValue(process_id)); | 328 args.push_back(new FundamentalValue(process_id)); |
| 329 args.push_back(new FundamentalValue(thread_id)); | 329 args.push_back(new FundamentalValue(thread_id)); |
| 330 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 330 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 331 value->SetString("message", info.error_message); | 331 value->SetString("message", info.error_message); |
| 332 value->SetInteger("lineNumber", info.line_number); | 332 value->SetInteger("lineNumber", info.line_number); |
| 333 value->SetInteger("columnNumber", info.column_number); | 333 value->SetInteger("columnNumber", info.column_number); |
| 334 value->SetString("sourceURL", info.source_url.spec()); | 334 value->SetString("sourceURL", info.source_url.spec()); |
| 335 args.push_back(value.release()); | 335 args.push_back(value.release()); |
| 336 web_ui_->CallJavascriptFunction("serviceworker.onErrorReported", | 336 web_ui_->CallJavascriptFunction("serviceworker.onErrorReported", |
| 337 args.get()); | 337 args.get()); |
| 338 } | 338 } |
| 339 void OnReportConsoleMessage(int64 version_id, | 339 void OnReportConsoleMessage(int64 version_id, |
| 340 int process_id, | 340 int process_id, |
| 341 int thread_id, | 341 int thread_id, |
| 342 const ConsoleMessage& message) override { | 342 const ConsoleMessage& message) override { |
| 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 343 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 344 ScopedVector<const Value> args; | 344 ScopedVector<const Value> args; |
| 345 args.push_back(new FundamentalValue(partition_id_)); | 345 args.push_back(new FundamentalValue(partition_id_)); |
| 346 args.push_back(new StringValue(base::Int64ToString(version_id))); | 346 args.push_back(new StringValue(base::Int64ToString(version_id))); |
| 347 args.push_back(new FundamentalValue(process_id)); | 347 args.push_back(new FundamentalValue(process_id)); |
| 348 args.push_back(new FundamentalValue(thread_id)); | 348 args.push_back(new FundamentalValue(thread_id)); |
| 349 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 349 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 350 value->SetInteger("sourceIdentifier", message.source_identifier); | 350 value->SetInteger("sourceIdentifier", message.source_identifier); |
| 351 value->SetInteger("message_level", message.message_level); | 351 value->SetInteger("message_level", message.message_level); |
| 352 value->SetString("message", message.message); | 352 value->SetString("message", message.message); |
| 353 value->SetInteger("lineNumber", message.line_number); | 353 value->SetInteger("lineNumber", message.line_number); |
| 354 value->SetString("sourceURL", message.source_url.spec()); | 354 value->SetString("sourceURL", message.source_url.spec()); |
| 355 args.push_back(value.release()); | 355 args.push_back(value.release()); |
| 356 web_ui_->CallJavascriptFunction("serviceworker.onConsoleMessageReported", | 356 web_ui_->CallJavascriptFunction("serviceworker.onConsoleMessageReported", |
| 357 args.get()); | 357 args.get()); |
| 358 } | 358 } |
| 359 void OnRegistrationStored(int64 registration_id, | 359 void OnRegistrationStored(int64 registration_id, |
| 360 const GURL& pattern) override { | 360 const GURL& pattern) override { |
| 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 361 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 362 web_ui_->CallJavascriptFunction("serviceworker.onRegistrationStored", | 362 web_ui_->CallJavascriptFunction("serviceworker.onRegistrationStored", |
| 363 StringValue(pattern.spec())); | 363 StringValue(pattern.spec())); |
| 364 } | 364 } |
| 365 void OnRegistrationDeleted(int64 registration_id, | 365 void OnRegistrationDeleted(int64 registration_id, |
| 366 const GURL& pattern) override { | 366 const GURL& pattern) override { |
| 367 web_ui_->CallJavascriptFunction("serviceworker.onRegistrationDeleted", | 367 web_ui_->CallJavascriptFunction("serviceworker.onRegistrationDeleted", |
| 368 StringValue(pattern.spec())); | 368 StringValue(pattern.spec())); |
| 369 } | 369 } |
| 370 int partition_id() const { return partition_id_; } | 370 int partition_id() const { return partition_id_; } |
| 371 | 371 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 bool option_boolean; | 453 bool option_boolean; |
| 454 if (!args->GetString(0, &option_name) || option_name != "debug_on_start" || | 454 if (!args->GetString(0, &option_name) || option_name != "debug_on_start" || |
| 455 !args->GetBoolean(1, &option_boolean)) { | 455 !args->GetBoolean(1, &option_boolean)) { |
| 456 return; | 456 return; |
| 457 } | 457 } |
| 458 ServiceWorkerDevToolsManager::GetInstance() | 458 ServiceWorkerDevToolsManager::GetInstance() |
| 459 ->set_debug_service_worker_on_start(option_boolean); | 459 ->set_debug_service_worker_on_start(option_boolean); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) { | 462 void ServiceWorkerInternalsUI::GetAllRegistrations(const ListValue* args) { |
| 463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 463 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 464 BrowserContext* browser_context = | 464 BrowserContext* browser_context = |
| 465 web_ui()->GetWebContents()->GetBrowserContext(); | 465 web_ui()->GetWebContents()->GetBrowserContext(); |
| 466 // Safe to use base::Unretained(this) because | 466 // Safe to use base::Unretained(this) because |
| 467 // ForEachStoragePartition is synchronous. | 467 // ForEachStoragePartition is synchronous. |
| 468 BrowserContext::StoragePartitionCallback add_context_cb = | 468 BrowserContext::StoragePartitionCallback add_context_cb = |
| 469 base::Bind(&ServiceWorkerInternalsUI::AddContextFromStoragePartition, | 469 base::Bind(&ServiceWorkerInternalsUI::AddContextFromStoragePartition, |
| 470 base::Unretained(this)); | 470 base::Unretained(this)); |
| 471 BrowserContext::ForEachStoragePartition(browser_context, add_context_cb); | 471 BrowserContext::ForEachStoragePartition(browser_context, add_context_cb); |
| 472 } | 472 } |
| 473 | 473 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 if (!result_partition) | 541 if (!result_partition) |
| 542 return false; | 542 return false; |
| 543 *context = static_cast<ServiceWorkerContextWrapper*>( | 543 *context = static_cast<ServiceWorkerContextWrapper*>( |
| 544 result_partition->GetServiceWorkerContext()); | 544 result_partition->GetServiceWorkerContext()); |
| 545 return true; | 545 return true; |
| 546 } | 546 } |
| 547 | 547 |
| 548 void ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod( | 548 void ServiceWorkerInternalsUI::CallServiceWorkerVersionMethod( |
| 549 ServiceWorkerVersionMethod method, | 549 ServiceWorkerVersionMethod method, |
| 550 const ListValue* args) { | 550 const ListValue* args) { |
| 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 551 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 552 int callback_id; | 552 int callback_id; |
| 553 const DictionaryValue* cmd_args = NULL; | 553 const DictionaryValue* cmd_args = NULL; |
| 554 int partition_id; | 554 int partition_id; |
| 555 scoped_refptr<ServiceWorkerContextWrapper> context; | 555 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 556 std::string version_id_string; | 556 std::string version_id_string; |
| 557 int64 version_id = 0; | 557 int64 version_id = 0; |
| 558 if (!args->GetInteger(0, &callback_id) || | 558 if (!args->GetInteger(0, &callback_id) || |
| 559 !args->GetDictionary(1, &cmd_args) || | 559 !args->GetDictionary(1, &cmd_args) || |
| 560 !cmd_args->GetInteger("partition_id", &partition_id) || | 560 !cmd_args->GetInteger("partition_id", &partition_id) || |
| 561 !GetServiceWorkerContext(partition_id, &context) || | 561 !GetServiceWorkerContext(partition_id, &context) || |
| 562 !cmd_args->GetString("version_id", &version_id_string) || | 562 !cmd_args->GetString("version_id", &version_id_string) || |
| 563 !base::StringToInt64(version_id_string, &version_id)) { | 563 !base::StringToInt64(version_id_string, &version_id)) { |
| 564 return; | 564 return; |
| 565 } | 565 } |
| 566 | 566 |
| 567 base::Callback<void(ServiceWorkerStatusCode)> callback = | 567 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 568 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 568 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 569 CallServiceWorkerVersionMethodWithVersionID( | 569 CallServiceWorkerVersionMethodWithVersionID( |
| 570 method, context, version_id, callback); | 570 method, context, version_id, callback); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void ServiceWorkerInternalsUI::DispatchPushEvent( | 573 void ServiceWorkerInternalsUI::DispatchPushEvent( |
| 574 const ListValue* args) { | 574 const ListValue* args) { |
| 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 575 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 576 int callback_id; | 576 int callback_id; |
| 577 int partition_id; | 577 int partition_id; |
| 578 int64 version_id = 0; | 578 int64 version_id = 0; |
| 579 std::string version_id_string; | 579 std::string version_id_string; |
| 580 const DictionaryValue* cmd_args = NULL; | 580 const DictionaryValue* cmd_args = NULL; |
| 581 scoped_refptr<ServiceWorkerContextWrapper> context; | 581 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 582 if (!args->GetInteger(0, &callback_id) || | 582 if (!args->GetInteger(0, &callback_id) || |
| 583 !args->GetDictionary(1, &cmd_args) || | 583 !args->GetDictionary(1, &cmd_args) || |
| 584 !cmd_args->GetInteger("partition_id", &partition_id) || | 584 !cmd_args->GetInteger("partition_id", &partition_id) || |
| 585 !GetServiceWorkerContext(partition_id, &context) || | 585 !GetServiceWorkerContext(partition_id, &context) || |
| 586 !cmd_args->GetString("version_id", &version_id_string) || | 586 !cmd_args->GetString("version_id", &version_id_string) || |
| 587 !base::StringToInt64(version_id_string, &version_id)) { | 587 !base::StringToInt64(version_id_string, &version_id)) { |
| 588 return; | 588 return; |
| 589 } | 589 } |
| 590 | 590 |
| 591 base::Callback<void(ServiceWorkerStatusCode)> callback = | 591 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 592 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 592 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 593 DispatchPushEventWithVersionID(context, version_id, callback); | 593 DispatchPushEventWithVersionID(context, version_id, callback); |
| 594 } | 594 } |
| 595 | 595 |
| 596 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { | 596 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { |
| 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 597 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 598 int callback_id; | 598 int callback_id; |
| 599 const DictionaryValue* cmd_args = NULL; | 599 const DictionaryValue* cmd_args = NULL; |
| 600 int process_id = 0; | 600 int process_id = 0; |
| 601 int devtools_agent_route_id = 0; | 601 int devtools_agent_route_id = 0; |
| 602 if (!args->GetInteger(0, &callback_id) || | 602 if (!args->GetInteger(0, &callback_id) || |
| 603 !args->GetDictionary(1, &cmd_args) || | 603 !args->GetDictionary(1, &cmd_args) || |
| 604 !cmd_args->GetInteger("process_id", &process_id) || | 604 !cmd_args->GetInteger("process_id", &process_id) || |
| 605 !cmd_args->GetInteger("devtools_agent_route_id", | 605 !cmd_args->GetInteger("devtools_agent_route_id", |
| 606 &devtools_agent_route_id)) { | 606 &devtools_agent_route_id)) { |
| 607 return; | 607 return; |
| 608 } | 608 } |
| 609 base::Callback<void(ServiceWorkerStatusCode)> callback = | 609 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 610 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 610 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 611 scoped_refptr<DevToolsAgentHostImpl> agent_host( | 611 scoped_refptr<DevToolsAgentHostImpl> agent_host( |
| 612 ServiceWorkerDevToolsManager::GetInstance() | 612 ServiceWorkerDevToolsManager::GetInstance() |
| 613 ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id)); | 613 ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id)); |
| 614 if (!agent_host.get()) { | 614 if (!agent_host.get()) { |
| 615 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); | 615 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 616 return; | 616 return; |
| 617 } | 617 } |
| 618 agent_host->Inspect(web_ui()->GetWebContents()->GetBrowserContext()); | 618 agent_host->Inspect(web_ui()->GetWebContents()->GetBrowserContext()); |
| 619 callback.Run(SERVICE_WORKER_OK); | 619 callback.Run(SERVICE_WORKER_OK); |
| 620 } | 620 } |
| 621 | 621 |
| 622 void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { | 622 void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { |
| 623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 623 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 624 int callback_id; | 624 int callback_id; |
| 625 int partition_id; | 625 int partition_id; |
| 626 std::string scope_string; | 626 std::string scope_string; |
| 627 const DictionaryValue* cmd_args = NULL; | 627 const DictionaryValue* cmd_args = NULL; |
| 628 scoped_refptr<ServiceWorkerContextWrapper> context; | 628 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 629 if (!args->GetInteger(0, &callback_id) || | 629 if (!args->GetInteger(0, &callback_id) || |
| 630 !args->GetDictionary(1, &cmd_args) || | 630 !args->GetDictionary(1, &cmd_args) || |
| 631 !cmd_args->GetInteger("partition_id", &partition_id) || | 631 !cmd_args->GetInteger("partition_id", &partition_id) || |
| 632 !GetServiceWorkerContext(partition_id, &context) || | 632 !GetServiceWorkerContext(partition_id, &context) || |
| 633 !cmd_args->GetString("scope", &scope_string)) { | 633 !cmd_args->GetString("scope", &scope_string)) { |
| 634 return; | 634 return; |
| 635 } | 635 } |
| 636 | 636 |
| 637 base::Callback<void(ServiceWorkerStatusCode)> callback = | 637 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 638 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 638 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 639 UnregisterWithScope(context, GURL(scope_string), callback); | 639 UnregisterWithScope(context, GURL(scope_string), callback); |
| 640 } | 640 } |
| 641 | 641 |
| 642 void ServiceWorkerInternalsUI::StartWorker(const ListValue* args) { | 642 void ServiceWorkerInternalsUI::StartWorker(const ListValue* args) { |
| 643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 643 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 644 int callback_id; | 644 int callback_id; |
| 645 int partition_id; | 645 int partition_id; |
| 646 std::string scope_string; | 646 std::string scope_string; |
| 647 const DictionaryValue* cmd_args = NULL; | 647 const DictionaryValue* cmd_args = NULL; |
| 648 scoped_refptr<ServiceWorkerContextWrapper> context; | 648 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 649 if (!args->GetInteger(0, &callback_id) || | 649 if (!args->GetInteger(0, &callback_id) || |
| 650 !args->GetDictionary(1, &cmd_args) || | 650 !args->GetDictionary(1, &cmd_args) || |
| 651 !cmd_args->GetInteger("partition_id", &partition_id) || | 651 !cmd_args->GetInteger("partition_id", &partition_id) || |
| 652 !GetServiceWorkerContext(partition_id, &context) || | 652 !GetServiceWorkerContext(partition_id, &context) || |
| 653 !cmd_args->GetString("scope", &scope_string)) { | 653 !cmd_args->GetString("scope", &scope_string)) { |
| 654 return; | 654 return; |
| 655 } | 655 } |
| 656 | 656 |
| 657 base::Callback<void(ServiceWorkerStatusCode)> callback = | 657 base::Callback<void(ServiceWorkerStatusCode)> callback = |
| 658 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); | 658 base::Bind(OperationCompleteCallback, AsWeakPtr(), callback_id); |
| 659 FindRegistrationForPattern( | 659 FindRegistrationForPattern( |
| 660 context, GURL(scope_string), base::Bind(StartActiveWorker, callback)); | 660 context, GURL(scope_string), base::Bind(StartActiveWorker, callback)); |
| 661 } | 661 } |
| 662 | 662 |
| 663 } // namespace content | 663 } // namespace content |
| OLD | NEW |