OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/processes/processes_api.h" | 5 #include "chrome/browser/extensions/api/processes/processes_api.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 continue; | 118 continue; |
119 if (!widgets[i]->IsRenderView()) | 119 if (!widgets[i]->IsRenderView()) |
120 continue; | 120 continue; |
121 | 121 |
122 content::RenderViewHost* host = content::RenderViewHost::From(widgets[i]); | 122 content::RenderViewHost* host = content::RenderViewHost::From(widgets[i]); |
123 content::WebContents* contents = | 123 content::WebContents* contents = |
124 content::WebContents::FromRenderViewHost(host); | 124 content::WebContents::FromRenderViewHost(host); |
125 if (contents) { | 125 if (contents) { |
126 tab_id = ExtensionTabUtil::GetTabId(contents); | 126 tab_id = ExtensionTabUtil::GetTabId(contents); |
127 if (tab_id != -1) | 127 if (tab_id != -1) |
128 tabs_list->Append(Value::CreateIntegerValue(tab_id)); | 128 tabs_list->Append(new base::FundamentalValue(tab_id)); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 return tabs_list; | 132 return tabs_list; |
133 } | 133 } |
134 | 134 |
135 // This function creates a Process object to be returned to the extensions | 135 // This function creates a Process object to be returned to the extensions |
136 // using these APIs. For memory details, which are not added by this function, | 136 // using these APIs. For memory details, which are not added by this function, |
137 // the callers need to use AddMemoryDetails. | 137 // the callers need to use AddMemoryDetails. |
138 base::DictionaryValue* CreateProcessFromModel(int process_id, | 138 base::DictionaryValue* CreateProcessFromModel(int process_id, |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // termination status, therefore we will rely on notifications and not on | 394 // termination status, therefore we will rely on notifications and not on |
395 // the Task Manager data. We do use the rest of this method for non-renderer | 395 // the Task Manager data. We do use the rest of this method for non-renderer |
396 // processes. | 396 // processes. |
397 if (model_->GetResourceType(start) == task_manager::Resource::RENDERER) | 397 if (model_->GetResourceType(start) == task_manager::Resource::RENDERER) |
398 return; | 398 return; |
399 | 399 |
400 // The callback function parameters. | 400 // The callback function parameters. |
401 scoped_ptr<base::ListValue> args(new base::ListValue()); | 401 scoped_ptr<base::ListValue> args(new base::ListValue()); |
402 | 402 |
403 // First arg: The id of the process that was closed. | 403 // First arg: The id of the process that was closed. |
404 args->Append(Value::CreateIntegerValue( | 404 args->Append(new base::FundamentalValue( |
405 model_->GetUniqueChildProcessId(start))); | 405 model_->GetUniqueChildProcessId(start))); |
406 | 406 |
407 // Second arg: The exit type for the process. | 407 // Second arg: The exit type for the process. |
408 args->Append(Value::CreateIntegerValue(0)); | 408 args->Append(new base::FundamentalValue(0)); |
409 | 409 |
410 // Third arg: The exit code for the process. | 410 // Third arg: The exit code for the process. |
411 args->Append(Value::CreateIntegerValue(0)); | 411 args->Append(new base::FundamentalValue(0)); |
412 | 412 |
413 DispatchEvent(keys::kOnExited, args.Pass()); | 413 DispatchEvent(keys::kOnExited, args.Pass()); |
414 #endif // defined(ENABLE_TASK_MANAGER) | 414 #endif // defined(ENABLE_TASK_MANAGER) |
415 } | 415 } |
416 | 416 |
417 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) { | 417 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) { |
418 #if defined(ENABLE_TASK_MANAGER) | 418 #if defined(ENABLE_TASK_MANAGER) |
419 std::string event(keys::kOnUnresponsive); | 419 std::string event(keys::kOnUnresponsive); |
420 if (!HasEventListeners(event)) | 420 if (!HasEventListeners(event)) |
421 return; | 421 return; |
(...skipping 23 matching lines...) Expand all Loading... |
445 } | 445 } |
446 | 446 |
447 void ProcessesEventRouter::ProcessClosedEvent( | 447 void ProcessesEventRouter::ProcessClosedEvent( |
448 content::RenderProcessHost* rph, | 448 content::RenderProcessHost* rph, |
449 content::RenderProcessHost::RendererClosedDetails* details) { | 449 content::RenderProcessHost::RendererClosedDetails* details) { |
450 #if defined(ENABLE_TASK_MANAGER) | 450 #if defined(ENABLE_TASK_MANAGER) |
451 // The callback function parameters. | 451 // The callback function parameters. |
452 scoped_ptr<base::ListValue> args(new base::ListValue()); | 452 scoped_ptr<base::ListValue> args(new base::ListValue()); |
453 | 453 |
454 // First arg: The id of the process that was closed. | 454 // First arg: The id of the process that was closed. |
455 args->Append(Value::CreateIntegerValue(rph->GetID())); | 455 args->Append(new base::FundamentalValue(rph->GetID())); |
456 | 456 |
457 // Second arg: The exit type for the process. | 457 // Second arg: The exit type for the process. |
458 args->Append(Value::CreateIntegerValue(details->status)); | 458 args->Append(new base::FundamentalValue(details->status)); |
459 | 459 |
460 // Third arg: The exit code for the process. | 460 // Third arg: The exit code for the process. |
461 args->Append(Value::CreateIntegerValue(details->exit_code)); | 461 args->Append(new base::FundamentalValue(details->exit_code)); |
462 | 462 |
463 DispatchEvent(keys::kOnExited, args.Pass()); | 463 DispatchEvent(keys::kOnExited, args.Pass()); |
464 #endif // defined(ENABLE_TASK_MANAGER) | 464 #endif // defined(ENABLE_TASK_MANAGER) |
465 } | 465 } |
466 | 466 |
467 void ProcessesEventRouter::DispatchEvent( | 467 void ProcessesEventRouter::DispatchEvent( |
468 const char* event_name, | 468 const char* event_name, |
469 scoped_ptr<base::ListValue> event_args) { | 469 scoped_ptr<base::ListValue> event_args) { |
470 if (extensions::ExtensionSystem::Get(profile_)->event_router()) { | 470 if (extensions::ExtensionSystem::Get(profile_)->event_router()) { |
471 scoped_ptr<extensions::Event> event(new extensions::Event( | 471 scoped_ptr<extensions::Event> event(new extensions::Event( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 } | 578 } |
579 | 579 |
580 void GetProcessIdForTabFunction::GetProcessIdForTab() { | 580 void GetProcessIdForTabFunction::GetProcessIdForTab() { |
581 content::WebContents* contents = NULL; | 581 content::WebContents* contents = NULL; |
582 int tab_index = -1; | 582 int tab_index = -1; |
583 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), | 583 if (!ExtensionTabUtil::GetTabById(tab_id_, profile(), include_incognito(), |
584 NULL, NULL, &contents, &tab_index)) { | 584 NULL, NULL, &contents, &tab_index)) { |
585 error_ = ErrorUtils::FormatErrorMessage( | 585 error_ = ErrorUtils::FormatErrorMessage( |
586 extensions::tabs_constants::kTabNotFoundError, | 586 extensions::tabs_constants::kTabNotFoundError, |
587 base::IntToString(tab_id_)); | 587 base::IntToString(tab_id_)); |
588 SetResult(Value::CreateIntegerValue(-1)); | 588 SetResult(new base::FundamentalValue(-1)); |
589 SendResponse(false); | 589 SendResponse(false); |
590 } else { | 590 } else { |
591 int process_id = contents->GetRenderProcessHost()->GetID(); | 591 int process_id = contents->GetRenderProcessHost()->GetID(); |
592 SetResult(Value::CreateIntegerValue(process_id)); | 592 SetResult(new base::FundamentalValue(process_id)); |
593 SendResponse(true); | 593 SendResponse(true); |
594 } | 594 } |
595 | 595 |
596 // Balance the AddRef in the RunImpl. | 596 // Balance the AddRef in the RunImpl. |
597 Release(); | 597 Release(); |
598 } | 598 } |
599 | 599 |
600 TerminateFunction::TerminateFunction() : process_id_(-1) { | 600 TerminateFunction::TerminateFunction() : process_id_(-1) { |
601 } | 601 } |
602 | 602 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 break; | 657 break; |
658 } | 658 } |
659 } | 659 } |
660 } | 660 } |
661 | 661 |
662 if (!found) { | 662 if (!found) { |
663 error_ = ErrorUtils::FormatErrorMessage(errors::kProcessNotFound, | 663 error_ = ErrorUtils::FormatErrorMessage(errors::kProcessNotFound, |
664 base::IntToString(process_id_)); | 664 base::IntToString(process_id_)); |
665 SendResponse(false); | 665 SendResponse(false); |
666 } else { | 666 } else { |
667 SetResult(Value::CreateBooleanValue(killed)); | 667 SetResult(new base::FundamentalValue(killed)); |
668 SendResponse(true); | 668 SendResponse(true); |
669 } | 669 } |
670 | 670 |
671 // Balance the AddRef in the RunImpl. | 671 // Balance the AddRef in the RunImpl. |
672 Release(); | 672 Release(); |
673 } | 673 } |
674 | 674 |
675 GetProcessInfoFunction::GetProcessInfoFunction() | 675 GetProcessInfoFunction::GetProcessInfoFunction() |
676 #if defined(ENABLE_TASK_MANAGER) | 676 #if defined(ENABLE_TASK_MANAGER) |
677 : memory_(false) | 677 : memory_(false) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 771 |
772 SetResult(processes); | 772 SetResult(processes); |
773 SendResponse(true); | 773 SendResponse(true); |
774 | 774 |
775 // Balance the AddRef in the RunImpl. | 775 // Balance the AddRef in the RunImpl. |
776 Release(); | 776 Release(); |
777 #endif // defined(ENABLE_TASK_MANAGER) | 777 #endif // defined(ENABLE_TASK_MANAGER) |
778 } | 778 } |
779 | 779 |
780 } // namespace extensions | 780 } // namespace extensions |
OLD | NEW |