OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/task_manager_handler.h" | 5 #include "chrome/browser/ui/webui/task_manager_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/task_manager/task_manager.h" | 14 #include "chrome/browser/task_manager/task_manager.h" |
15 #include "chrome/browser/ui/webui/web_ui_util.h" | 15 #include "chrome/browser/ui/webui/web_ui_util.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/renderer_host/render_view_host_delegate.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
| 21 #include "content/public/browser/web_contents.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "webkit/glue/webpreferences.h" | 23 #include "webkit/glue/webpreferences.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 static Value* CreateColumnValue(const TaskManagerModel* tm, | 27 static Value* CreateColumnValue(const TaskManagerModel* tm, |
27 const std::string column_name, | 28 const std::string column_name, |
28 const int i) { | 29 const int i) { |
29 if (column_name == "uniqueId") | 30 if (column_name == "uniqueId") |
30 return Value::CreateIntegerValue(tm->GetResourceUniqueId(i)); | 31 return Value::CreateIntegerValue(tm->GetResourceUniqueId(i)); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 model_->AddObserver(this); | 396 model_->AddObserver(this); |
396 model_->StartUpdating(); | 397 model_->StartUpdating(); |
397 | 398 |
398 content::NotificationService::current()->Notify( | 399 content::NotificationService::current()->Notify( |
399 chrome::NOTIFICATION_TASK_MANAGER_WINDOW_READY, | 400 chrome::NOTIFICATION_TASK_MANAGER_WINDOW_READY, |
400 content::Source<TaskManagerModel>(model_), | 401 content::Source<TaskManagerModel>(model_), |
401 content::NotificationService::NoDetails()); | 402 content::NotificationService::NoDetails()); |
402 } | 403 } |
403 | 404 |
404 void TaskManagerHandler::OpenAboutMemory(const ListValue* indexes) { | 405 void TaskManagerHandler::OpenAboutMemory(const ListValue* indexes) { |
405 RenderViewHost* rvh = web_ui()->tab_contents()->GetRenderViewHost(); | 406 RenderViewHost* rvh = web_ui()->web_contents()->GetRenderViewHost(); |
406 if (rvh && rvh->delegate()) { | 407 if (rvh && rvh->delegate()) { |
407 WebPreferences webkit_prefs = rvh->delegate()->GetWebkitPrefs(); | 408 WebPreferences webkit_prefs = rvh->delegate()->GetWebkitPrefs(); |
408 webkit_prefs.allow_scripts_to_close_windows = true; | 409 webkit_prefs.allow_scripts_to_close_windows = true; |
409 rvh->UpdateWebkitPreferences(webkit_prefs); | 410 rvh->UpdateWebkitPreferences(webkit_prefs); |
410 } else { | 411 } else { |
411 DCHECK(false); | 412 DCHECK(false); |
412 } | 413 } |
413 | 414 |
414 task_manager_->OpenAboutMemory(); | 415 task_manager_->OpenAboutMemory(); |
415 } | 416 } |
416 | 417 |
417 // TaskManagerHandler, private: ----------------------------------------------- | 418 // TaskManagerHandler, private: ----------------------------------------------- |
418 | 419 |
419 bool TaskManagerHandler::is_alive() { | 420 bool TaskManagerHandler::is_alive() { |
420 return web_ui()->tab_contents()->GetRenderViewHost() != NULL; | 421 return web_ui()->web_contents()->GetRenderViewHost() != NULL; |
421 } | 422 } |
422 | 423 |
423 void TaskManagerHandler::UpdateResourceGroupTable(int start, int length) { | 424 void TaskManagerHandler::UpdateResourceGroupTable(int start, int length) { |
424 if (resource_to_group_table_.size() < static_cast<size_t>(start)) { | 425 if (resource_to_group_table_.size() < static_cast<size_t>(start)) { |
425 length += start - resource_to_group_table_.size(); | 426 length += start - resource_to_group_table_.size(); |
426 start = resource_to_group_table_.size(); | 427 start = resource_to_group_table_.size(); |
427 } | 428 } |
428 | 429 |
429 // Makes room to fill group_index at first since inserting vector is too slow. | 430 // Makes room to fill group_index at first since inserting vector is too slow. |
430 std::vector<int>::iterator it = resource_to_group_table_.begin() + start; | 431 std::vector<int>::iterator it = resource_to_group_table_.begin() + start; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 } | 466 } |
466 } | 467 } |
467 | 468 |
468 void TaskManagerHandler::OnGroupRemoved(const int group_start, | 469 void TaskManagerHandler::OnGroupRemoved(const int group_start, |
469 const int group_length) { | 470 const int group_length) { |
470 base::FundamentalValue start_value(group_start); | 471 base::FundamentalValue start_value(group_start); |
471 base::FundamentalValue length_value(group_length); | 472 base::FundamentalValue length_value(group_length); |
472 if (is_enabled_ && is_alive()) | 473 if (is_enabled_ && is_alive()) |
473 web_ui()->CallJavascriptFunction("taskRemoved", start_value, length_value); | 474 web_ui()->CallJavascriptFunction("taskRemoved", start_value, length_value); |
474 } | 475 } |
OLD | NEW |