Chromium Code Reviews| 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/task_manager/task_manager_resource_providers.h" | 5 #include "chrome/browser/task_manager/task_manager_resource_providers.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/browser/prerender/prerender_manager.h" | 31 #include "chrome/browser/prerender/prerender_manager.h" |
| 32 #include "chrome/browser/prerender/prerender_manager_factory.h" | 32 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/profiles/profile_info_cache.h" | 34 #include "chrome/browser/profiles/profile_info_cache.h" |
| 35 #include "chrome/browser/profiles/profile_manager.h" | 35 #include "chrome/browser/profiles/profile_manager.h" |
| 36 #include "chrome/browser/tab_contents/background_contents.h" | 36 #include "chrome/browser/tab_contents/background_contents.h" |
| 37 #include "chrome/browser/tab_contents/tab_util.h" | 37 #include "chrome/browser/tab_contents/tab_util.h" |
| 38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_instant_controller.h" | 39 #include "chrome/browser/ui/browser_instant_controller.h" |
| 40 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 41 #include "chrome/browser/ui/panels/panel.h" | |
| 42 #include "chrome/browser/ui/panels/panel_manager.h" | |
| 41 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 43 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 42 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 44 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 43 #include "chrome/browser/view_type_utils.h" | 45 #include "chrome/browser/view_type_utils.h" |
| 44 #include "chrome/common/chrome_notification_types.h" | 46 #include "chrome/common/chrome_notification_types.h" |
| 45 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 46 #include "chrome/common/extensions/extension.h" | 48 #include "chrome/common/extensions/extension.h" |
| 47 #include "chrome/common/render_messages.h" | 49 #include "chrome/common/render_messages.h" |
| 48 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
| 49 #include "content/public/browser/browser_child_process_host_iterator.h" | 51 #include "content/public/browser/browser_child_process_host_iterator.h" |
| 50 #include "content/public/browser/browser_thread.h" | 52 #include "content/public/browser/browser_thread.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 else | 326 else |
| 325 return cache.GetNameOfProfileAtIndex(index); | 327 return cache.GetNameOfProfileAtIndex(index); |
| 326 } | 328 } |
| 327 | 329 |
| 328 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { | 330 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { |
| 329 if (IsPrerendering()) | 331 if (IsPrerendering()) |
| 330 return *prerender_icon_; | 332 return *prerender_icon_; |
| 331 return tab_contents_->favicon_tab_helper()->GetFavicon(); | 333 return tab_contents_->favicon_tab_helper()->GetFavicon(); |
| 332 } | 334 } |
| 333 | 335 |
| 334 TabContents* TaskManagerTabContentsResource::GetTabContents() const { | 336 WebContents* TaskManagerTabContentsResource::GetWebContents() const { |
| 335 return tab_contents_; | 337 return tab_contents_->web_contents(); |
| 336 } | 338 } |
| 337 | 339 |
| 338 const Extension* TaskManagerTabContentsResource::GetExtension() const { | 340 const Extension* TaskManagerTabContentsResource::GetExtension() const { |
| 339 if (HostsExtension()) { | 341 if (HostsExtension()) { |
| 340 ExtensionService* extension_service = | 342 ExtensionService* extension_service = |
| 341 tab_contents_->profile()->GetExtensionService(); | 343 tab_contents_->profile()->GetExtensionService(); |
| 342 return extension_service->extensions()->GetByID( | 344 return extension_service->extensions()->GetByID( |
| 343 tab_contents_->web_contents()->GetURL().host()); | 345 tab_contents_->web_contents()->GetURL().host()); |
| 344 } | 346 } |
| 345 | 347 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 case chrome::NOTIFICATION_INSTANT_COMMITTED: | 519 case chrome::NOTIFICATION_INSTANT_COMMITTED: |
| 518 Update(tab_contents); | 520 Update(tab_contents); |
| 519 break; | 521 break; |
| 520 default: | 522 default: |
| 521 NOTREACHED() << "Unexpected notification."; | 523 NOTREACHED() << "Unexpected notification."; |
| 522 return; | 524 return; |
| 523 } | 525 } |
| 524 } | 526 } |
| 525 | 527 |
| 526 //////////////////////////////////////////////////////////////////////////////// | 528 //////////////////////////////////////////////////////////////////////////////// |
| 529 // TaskManagerPanelResource class | |
| 530 //////////////////////////////////////////////////////////////////////////////// | |
| 531 | |
| 532 TaskManagerPanelResource::TaskManagerPanelResource(Panel* panel) | |
| 533 : TaskManagerRendererResource( | |
| 534 panel->GetWebContents()->GetRenderProcessHost()->GetHandle(), | |
| 535 panel->GetWebContents()->GetRenderViewHost()), | |
| 536 panel_(panel) { | |
| 537 message_prefix_id_ = GetMessagePrefixID( | |
| 538 GetExtension()->is_app(), true, panel->profile()->IsOffTheRecord(), | |
| 539 false, false); | |
| 540 } | |
| 541 | |
| 542 TaskManagerPanelResource::~TaskManagerPanelResource() { | |
| 543 } | |
| 544 | |
| 545 TaskManager::Resource::Type TaskManagerPanelResource::GetType() const { | |
| 546 return EXTENSION; | |
| 547 } | |
| 548 | |
| 549 string16 TaskManagerPanelResource::GetTitle() const { | |
| 550 string16 title = panel_->GetWindowTitle(); | |
| 551 // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix | |
| 552 // we need to explicitly set the title to be LTR format if there is no | |
| 553 // strong RTL charater in it. Otherwise, if the task manager prefix is an | |
| 554 // RTL word, the concatenated result might be wrong. For example, | |
| 555 // a page whose title is "Yahoo! Mail: The best web-based Email!", without | |
| 556 // setting it explicitly as LTR format, the concatenated result will be | |
| 557 // "!Yahoo! Mail: The best web-based Email :PPA", in which the capital | |
| 558 // letters "PPA" stands for the Hebrew word for "app". | |
| 559 base::i18n::AdjustStringForLocaleDirection(&title); | |
| 560 | |
| 561 return l10n_util::GetStringFUTF16(message_prefix_id_, title); | |
| 562 } | |
| 563 | |
| 564 string16 TaskManagerPanelResource::GetProfileName() const { | |
|
Dmitry Titov
2012/07/18 22:52:15
this seems mostly duplicate the TaskManagerTabCont
| |
| 565 ProfileInfoCache& cache = | |
| 566 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 567 Profile* profile = panel_->profile()->GetOriginalProfile(); | |
| 568 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
| 569 if (index == std::string::npos) | |
| 570 return string16(); | |
| 571 else | |
| 572 return cache.GetNameOfProfileAtIndex(index); | |
| 573 } | |
| 574 | |
| 575 gfx::ImageSkia TaskManagerPanelResource::GetIcon() const { | |
| 576 return panel_->GetCurrentPageIcon(); | |
| 577 } | |
| 578 | |
| 579 WebContents* TaskManagerPanelResource::GetWebContents() const { | |
| 580 return panel_->GetWebContents(); | |
| 581 } | |
| 582 | |
| 583 const Extension* TaskManagerPanelResource::GetExtension() const { | |
| 584 ExtensionService* extension_service = | |
| 585 panel_->profile()->GetExtensionService(); | |
| 586 return extension_service->extensions()->GetByID(panel_->extension_id()); | |
| 587 } | |
| 588 | |
| 589 //////////////////////////////////////////////////////////////////////////////// | |
| 590 // TaskManagerPanelResourceProvider class | |
| 591 //////////////////////////////////////////////////////////////////////////////// | |
| 592 | |
| 593 TaskManagerPanelResourceProvider::TaskManagerPanelResourceProvider( | |
| 594 TaskManager* task_manager) | |
| 595 : updating_(false), | |
| 596 task_manager_(task_manager) { | |
| 597 } | |
| 598 | |
| 599 TaskManagerPanelResourceProvider::~TaskManagerPanelResourceProvider() { | |
| 600 } | |
| 601 | |
| 602 TaskManager::Resource* TaskManagerPanelResourceProvider::GetResource( | |
| 603 int origin_pid, | |
| 604 int render_process_host_id, | |
| 605 int routing_id) { | |
| 606 // If an origin PID was specified, the request is from a plugin, not the | |
| 607 // render view host process | |
| 608 if (origin_pid) | |
| 609 return NULL; | |
| 610 | |
| 611 for (std::map<Panel*, TaskManagerPanelResource*>::iterator i = | |
| 612 resources_.begin(); i != resources_.end(); ++i) { | |
| 613 WebContents* contents = i->first->GetWebContents(); | |
| 614 if (contents && | |
| 615 contents->GetRenderProcessHost()->GetID() == render_process_host_id && | |
| 616 contents->GetRenderViewHost()->GetRoutingID() == routing_id) { | |
| 617 return i->second; | |
| 618 } | |
| 619 } | |
| 620 | |
| 621 // Can happen if the panel went away while a network request was being | |
| 622 // performed. | |
| 623 return NULL; | |
| 624 } | |
| 625 | |
| 626 void TaskManagerPanelResourceProvider::StartUpdating() { | |
| 627 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 628 switches::kBrowserlessPanels)) | |
| 629 return; | |
| 630 | |
| 631 DCHECK(!updating_); | |
| 632 updating_ = true; | |
| 633 | |
| 634 // Add all the Panels. | |
| 635 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); | |
| 636 for (size_t i = 0; i < panels.size(); ++i) | |
| 637 Add(panels[i]); | |
| 638 | |
| 639 // Then we register for notifications to get new and remove closed panels. | |
| 640 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | |
| 641 content::NotificationService::AllSources()); | |
| 642 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | |
| 643 content::NotificationService::AllSources()); | |
| 644 } | |
| 645 | |
| 646 void TaskManagerPanelResourceProvider::StopUpdating() { | |
| 647 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 648 switches::kBrowserlessPanels)) | |
| 649 return; | |
| 650 | |
| 651 DCHECK(updating_); | |
| 652 updating_ = false; | |
| 653 | |
| 654 // Unregister for notifications about new/removed panels. | |
| 655 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, | |
| 656 content::NotificationService::AllSources()); | |
| 657 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | |
| 658 content::NotificationService::AllSources()); | |
| 659 | |
| 660 // Delete all the resources. | |
| 661 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); | |
| 662 resources_.clear(); | |
| 663 } | |
| 664 | |
| 665 void TaskManagerPanelResourceProvider::Add(Panel* panel) { | |
| 666 if (!updating_) | |
| 667 return; | |
| 668 | |
| 669 std::map<Panel*, TaskManagerPanelResource*>::const_iterator iter = | |
| 670 resources_.find(panel); | |
| 671 if (iter != resources_.end()) | |
| 672 return; | |
| 673 | |
| 674 TaskManagerPanelResource* resource = new TaskManagerPanelResource(panel); | |
| 675 resources_[panel] = resource; | |
| 676 task_manager_->AddResource(resource); | |
| 677 } | |
| 678 | |
| 679 void TaskManagerPanelResourceProvider::Remove(Panel* panel) { | |
| 680 if (!updating_) | |
| 681 return; | |
| 682 | |
| 683 std::map<Panel*, TaskManagerPanelResource*>::iterator iter = | |
| 684 resources_.find(panel); | |
| 685 if (iter == resources_.end()) | |
| 686 return; | |
| 687 | |
| 688 TaskManagerPanelResource* resource = iter->second; | |
| 689 task_manager_->RemoveResource(resource); | |
| 690 resources_.erase(iter); | |
| 691 delete resource; | |
| 692 } | |
| 693 | |
| 694 void TaskManagerPanelResourceProvider::Observe(int type, | |
| 695 const content::NotificationSource& source, | |
| 696 const content::NotificationDetails& details) { | |
| 697 Panel* panel = Panel::FromWebContents( | |
| 698 content::Source<WebContents>(source).ptr()); | |
| 699 if (!panel) | |
| 700 return; | |
| 701 | |
| 702 switch (type) { | |
| 703 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: | |
| 704 Add(panel); | |
| 705 break; | |
| 706 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | |
| 707 Remove(panel); | |
| 708 break; | |
| 709 default: | |
| 710 NOTREACHED() << "Unexpected notificiation."; | |
| 711 break; | |
| 712 } | |
| 713 } | |
| 714 | |
| 715 //////////////////////////////////////////////////////////////////////////////// | |
| 527 // TaskManagerBackgroundContentsResource class | 716 // TaskManagerBackgroundContentsResource class |
| 528 //////////////////////////////////////////////////////////////////////////////// | 717 //////////////////////////////////////////////////////////////////////////////// |
| 529 | 718 |
| 530 gfx::ImageSkia* TaskManagerBackgroundContentsResource::default_icon_ = NULL; | 719 gfx::ImageSkia* TaskManagerBackgroundContentsResource::default_icon_ = NULL; |
| 531 | 720 |
| 532 // TODO(atwilson): http://crbug.com/116893 | 721 // TODO(atwilson): http://crbug.com/116893 |
| 533 // HACK: if the process handle is invalid, we use the current process's handle. | 722 // HACK: if the process handle is invalid, we use the current process's handle. |
| 534 // This preserves old behavior but is incorrect, and should be fixed. | 723 // This preserves old behavior but is incorrect, and should be fixed. |
| 535 TaskManagerBackgroundContentsResource::TaskManagerBackgroundContentsResource( | 724 TaskManagerBackgroundContentsResource::TaskManagerBackgroundContentsResource( |
| 536 BackgroundContents* background_contents, | 725 BackgroundContents* background_contents, |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 } | 1499 } |
| 1311 } | 1500 } |
| 1312 | 1501 |
| 1313 bool TaskManagerExtensionProcessResourceProvider:: | 1502 bool TaskManagerExtensionProcessResourceProvider:: |
| 1314 IsHandledByThisProvider(content::RenderViewHost* render_view_host) { | 1503 IsHandledByThisProvider(content::RenderViewHost* render_view_host) { |
| 1315 // Don't add WebContents (those are handled by | 1504 // Don't add WebContents (those are handled by |
| 1316 // TaskManagerTabContentsResourceProvider) or background contents (handled | 1505 // TaskManagerTabContentsResourceProvider) or background contents (handled |
| 1317 // by TaskManagerBackgroundResourceProvider). | 1506 // by TaskManagerBackgroundResourceProvider). |
| 1318 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); | 1507 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| 1319 chrome::ViewType view_type = chrome::GetViewType(web_contents); | 1508 chrome::ViewType view_type = chrome::GetViewType(web_contents); |
| 1509 #if defined(USE_ASH) | |
| 1320 return (view_type != chrome::VIEW_TYPE_TAB_CONTENTS && | 1510 return (view_type != chrome::VIEW_TYPE_TAB_CONTENTS && |
| 1321 view_type != chrome::VIEW_TYPE_BACKGROUND_CONTENTS); | 1511 view_type != chrome::VIEW_TYPE_BACKGROUND_CONTENTS); |
| 1512 #else | |
| 1513 return (view_type != chrome::VIEW_TYPE_TAB_CONTENTS && | |
| 1514 view_type != chrome::VIEW_TYPE_BACKGROUND_CONTENTS && | |
| 1515 view_type != chrome::VIEW_TYPE_PANEL); | |
| 1516 #endif // USE_ASH | |
| 1322 } | 1517 } |
| 1323 | 1518 |
| 1324 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( | 1519 void TaskManagerExtensionProcessResourceProvider::AddToTaskManager( |
| 1325 content::RenderViewHost* render_view_host) { | 1520 content::RenderViewHost* render_view_host) { |
| 1326 if (!IsHandledByThisProvider(render_view_host)) | 1521 if (!IsHandledByThisProvider(render_view_host)) |
| 1327 return; | 1522 return; |
| 1328 | 1523 |
| 1329 TaskManagerExtensionProcessResource* resource = | 1524 TaskManagerExtensionProcessResource* resource = |
| 1330 new TaskManagerExtensionProcessResource(render_view_host); | 1525 new TaskManagerExtensionProcessResource(render_view_host); |
| 1331 DCHECK(resources_.find(render_view_host) == resources_.end()); | 1526 DCHECK(resources_.find(render_view_host) == resources_.end()); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1492 | 1687 |
| 1493 return &resource_; | 1688 return &resource_; |
| 1494 } | 1689 } |
| 1495 | 1690 |
| 1496 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1691 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { |
| 1497 task_manager_->AddResource(&resource_); | 1692 task_manager_->AddResource(&resource_); |
| 1498 } | 1693 } |
| 1499 | 1694 |
| 1500 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1695 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { |
| 1501 } | 1696 } |
| OLD | NEW |