| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // might be wrong. For example, http://mail.yahoo.com, whose title is | 140 // might be wrong. For example, http://mail.yahoo.com, whose title is |
| 141 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly | 141 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly |
| 142 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best | 142 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best |
| 143 // web-based Email :BAT", in which the capital letters "BAT" stands for | 143 // web-based Email :BAT", in which the capital letters "BAT" stands for |
| 144 // the Hebrew word for "tab". | 144 // the Hebrew word for "tab". |
| 145 base::i18n::AdjustStringForLocaleDirection(&title); | 145 base::i18n::AdjustStringForLocaleDirection(&title); |
| 146 } | 146 } |
| 147 return title; | 147 return title; |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Only classify as an app if the URL is an app and the tab is hosting an |
| 151 // extension process. (It's possible to be showing the URL from before it |
| 152 // was installed as an app.) Return Extension::TYPE_UNKNOWN if the web_contents |
| 153 // is not for an extension, not for an app, or the process is not hosting an |
| 154 // extension. |
| 155 Extension::Type GetAppExtensionType(WebContents* web_contents) { |
| 156 ExtensionService* extension_service = Profile::FromBrowserContext( |
| 157 web_contents->GetBrowserContext())->GetExtensionService(); |
| 158 const Extension* extension = |
| 159 extension_service->GetInstalledApp(web_contents->GetURL()); |
| 160 |
| 161 if (!extension || !extension->is_app()) |
| 162 return Extension::TYPE_UNKNOWN; |
| 163 |
| 164 const extensions::ProcessMap* process_map = extension_service->process_map(); |
| 165 if (!process_map->Contains(web_contents->GetRenderProcessHost()->GetID())) |
| 166 return Extension::TYPE_UNKNOWN; |
| 167 |
| 168 return extension->GetType(); |
| 169 } |
| 170 |
| 150 } // namespace | 171 } // namespace |
| 151 | 172 |
| 152 //////////////////////////////////////////////////////////////////////////////// | 173 //////////////////////////////////////////////////////////////////////////////// |
| 153 // TaskManagerRendererResource class | 174 // TaskManagerRendererResource class |
| 154 //////////////////////////////////////////////////////////////////////////////// | 175 //////////////////////////////////////////////////////////////////////////////// |
| 155 TaskManagerRendererResource::TaskManagerRendererResource( | 176 TaskManagerRendererResource::TaskManagerRendererResource( |
| 156 base::ProcessHandle process, content::RenderViewHost* render_view_host) | 177 base::ProcessHandle process, content::RenderViewHost* render_view_host) |
| 157 : process_(process), | 178 : process_(process), |
| 158 render_view_host_(render_view_host), | 179 render_view_host_(render_view_host), |
| 159 pending_stats_update_(false), | 180 pending_stats_update_(false), |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { | 338 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { |
| 318 return HostsExtension() ? EXTENSION : RENDERER; | 339 return HostsExtension() ? EXTENSION : RENDERER; |
| 319 } | 340 } |
| 320 | 341 |
| 321 string16 TaskManagerTabContentsResource::GetTitle() const { | 342 string16 TaskManagerTabContentsResource::GetTitle() const { |
| 322 // Fall back on the URL if there's no title. | 343 // Fall back on the URL if there's no title. |
| 323 WebContents* contents = tab_contents_->web_contents(); | 344 WebContents* contents = tab_contents_->web_contents(); |
| 324 GURL url = contents->GetURL(); | 345 GURL url = contents->GetURL(); |
| 325 string16 tab_title = GetTitleFromWebContents(contents); | 346 string16 tab_title = GetTitleFromWebContents(contents); |
| 326 | 347 |
| 327 // Only classify as an app if the URL is an app and the tab is hosting an | |
| 328 // extension process. (It's possible to be showing the URL from before it | |
| 329 // was installed as an app.) | |
| 330 ExtensionService* extension_service = | |
| 331 tab_contents_->profile()->GetExtensionService(); | |
| 332 extensions::ProcessMap* process_map = extension_service->process_map(); | |
| 333 bool is_app = extension_service->IsInstalledApp(url) && | |
| 334 process_map->Contains(contents->GetRenderProcessHost()->GetID()); | |
| 335 | |
| 336 int message_id = GetMessagePrefixID( | 348 int message_id = GetMessagePrefixID( |
| 337 is_app, | 349 GetAppExtensionType(contents) != Extension::TYPE_UNKNOWN, |
| 338 HostsExtension(), | 350 HostsExtension(), |
| 339 tab_contents_->profile()->IsOffTheRecord(), | 351 tab_contents_->profile()->IsOffTheRecord(), |
| 340 IsPrerendering(), | 352 IsPrerendering(), |
| 341 is_instant_preview_, | 353 is_instant_preview_, |
| 342 false); | 354 false); |
| 343 return l10n_util::GetStringFUTF16(message_id, tab_title); | 355 return l10n_util::GetStringFUTF16(message_id, tab_title); |
| 344 } | 356 } |
| 345 | 357 |
| 346 string16 TaskManagerTabContentsResource::GetProfileName() const { | 358 string16 TaskManagerTabContentsResource::GetProfileName() const { |
| 347 return GetProfileNameFromInfoCache(tab_contents_->profile()); | 359 return GetProfileNameFromInfoCache(tab_contents_->profile()); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator | 517 std::map<TabContents*, TaskManagerTabContentsResource*>::iterator |
| 506 iter = resources_.find(tab_contents); | 518 iter = resources_.find(tab_contents); |
| 507 DCHECK(iter != resources_.end()); | 519 DCHECK(iter != resources_.end()); |
| 508 if (iter != resources_.end()) | 520 if (iter != resources_.end()) |
| 509 iter->second->InstantCommitted(); | 521 iter->second->InstantCommitted(); |
| 510 } | 522 } |
| 511 | 523 |
| 512 void TaskManagerTabContentsResourceProvider::Observe(int type, | 524 void TaskManagerTabContentsResourceProvider::Observe(int type, |
| 513 const content::NotificationSource& source, | 525 const content::NotificationSource& source, |
| 514 const content::NotificationDetails& details) { | 526 const content::NotificationDetails& details) { |
| 515 TabContents* tab_contents; | 527 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
| 516 tab_contents = TabContents::FromWebContents( | 528 TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
| 517 content::Source<WebContents>(source).ptr()); | |
| 518 // A background page does not have a TabContents. | 529 // A background page does not have a TabContents. |
| 519 if (!tab_contents) | 530 if (!tab_contents) |
| 520 return; | 531 return; |
| 532 |
| 533 // Platform Apps' contents are tracked using the RenderViewHost associated |
| 534 // with the extension in the TaskManagerExtensionProcessResourceProvider. |
| 535 if (GetAppExtensionType(web_contents) == Extension::TYPE_PLATFORM_APP) |
| 536 return; |
| 537 |
| 521 switch (type) { | 538 switch (type) { |
| 522 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: | 539 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: |
| 523 Add(tab_contents); | 540 Add(tab_contents); |
| 524 break; | 541 break; |
| 525 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: | 542 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: |
| 526 Remove(tab_contents); | 543 Remove(tab_contents); |
| 527 Add(tab_contents); | 544 Add(tab_contents); |
| 528 break; | 545 break; |
| 529 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | 546 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
| 530 Remove(tab_contents); | 547 Remove(tab_contents); |
| (...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1868 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: | 1885 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: |
| 1869 Add(web_contents->GetRenderViewHost()); | 1886 Add(web_contents->GetRenderViewHost()); |
| 1870 break; | 1887 break; |
| 1871 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | 1888 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
| 1872 Remove(web_contents->GetRenderViewHost()); | 1889 Remove(web_contents->GetRenderViewHost()); |
| 1873 break; | 1890 break; |
| 1874 default: | 1891 default: |
| 1875 NOTREACHED() << "Unexpected notification."; | 1892 NOTREACHED() << "Unexpected notification."; |
| 1876 } | 1893 } |
| 1877 } | 1894 } |
| OLD | NEW |