 Chromium Code Reviews
 Chromium Code Reviews Issue 5526002:
  Show extension tabs in task manager and correctly label apps.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 5526002:
  Show extension tabs in task manager and correctly label apps.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 7 #include "build/build_config.h" | 
| 8 | 8 | 
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" | 
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "grit/theme_resources.h" | 43 #include "grit/theme_resources.h" | 
| 44 | 44 | 
| 45 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) | 
| 46 #include "skia/ext/skia_utils_mac.h" | 46 #include "skia/ext/skia_utils_mac.h" | 
| 47 #endif | 47 #endif | 
| 48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) | 
| 49 #include "chrome/browser/app_icon_win.h" | 49 #include "chrome/browser/app_icon_win.h" | 
| 50 #include "gfx/icon_util.h" | 50 #include "gfx/icon_util.h" | 
| 51 #endif // defined(OS_WIN) | 51 #endif // defined(OS_WIN) | 
| 52 | 52 | 
| 53 namespace { | |
| 54 | |
| 55 // Returns the appropriate message prefix ID for tabs and extensions, | |
| 56 // reflecting whether they are apps or in incognito mode. | |
| 57 int GetMessagePrefixID(bool is_app, bool is_extension, | |
| 58 bool is_off_the_record) { | |
| 59 return is_app ? | |
| 60 (is_off_the_record ? | |
| 61 IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX : | |
| 62 IDS_TASK_MANAGER_APP_PREFIX) : | |
| 63 (is_extension ? | |
| 64 (is_off_the_record ? | |
| 65 IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX : | |
| 66 IDS_TASK_MANAGER_EXTENSION_PREFIX) : | |
| 67 IDS_TASK_MANAGER_TAB_PREFIX); | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 53 | 71 | 
| 54 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// | 
| 55 // TaskManagerRendererResource class | 73 // TaskManagerRendererResource class | 
| 56 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// | 
| 57 TaskManagerRendererResource::TaskManagerRendererResource( | 75 TaskManagerRendererResource::TaskManagerRendererResource( | 
| 58 base::ProcessHandle process, RenderViewHost* render_view_host) | 76 base::ProcessHandle process, RenderViewHost* render_view_host) | 
| 59 : process_(process), | 77 : process_(process), | 
| 60 render_view_host_(render_view_host), | 78 render_view_host_(render_view_host), | 
| 61 pending_stats_update_(false), | 79 pending_stats_update_(false), | 
| 62 v8_memory_allocated_(0), | 80 v8_memory_allocated_(0), | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 TabContents* tab_contents) | 142 TabContents* tab_contents) | 
| 125 : TaskManagerRendererResource( | 143 : TaskManagerRendererResource( | 
| 126 tab_contents->GetRenderProcessHost()->GetHandle(), | 144 tab_contents->GetRenderProcessHost()->GetHandle(), | 
| 127 tab_contents->render_view_host()), | 145 tab_contents->render_view_host()), | 
| 128 tab_contents_(tab_contents) { | 146 tab_contents_(tab_contents) { | 
| 129 } | 147 } | 
| 130 | 148 | 
| 131 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { | 149 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { | 
| 132 } | 150 } | 
| 133 | 151 | 
| 152 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { | |
| 153 if (tab_contents_->HostsExtension()) | |
| 
Erik does not do reviews
2010/12/03 17:04:56
in cases like this I usually prefer:
return tab_co
 
Charlie Reis
2010/12/03 23:02:16
Done.
 | |
| 154 return EXTENSION; | |
| 155 | |
| 156 return RENDERER; | |
| 157 } | |
| 158 | |
| 134 std::wstring TaskManagerTabContentsResource::GetTitle() const { | 159 std::wstring TaskManagerTabContentsResource::GetTitle() const { | 
| 135 // Fall back on the URL if there's no title. | 160 // Fall back on the URL if there's no title. | 
| 136 std::wstring tab_title(UTF16ToWideHack(tab_contents_->GetTitle())); | 161 std::wstring tab_title(UTF16ToWideHack(tab_contents_->GetTitle())); | 
| 137 if (tab_title.empty()) { | 162 if (tab_title.empty()) { | 
| 138 tab_title = UTF8ToWide(tab_contents_->GetURL().spec()); | 163 tab_title = UTF8ToWide(tab_contents_->GetURL().spec()); | 
| 139 // Force URL to be LTR. | 164 // Force URL to be LTR. | 
| 140 tab_title = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( | 165 tab_title = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( | 
| 141 WideToUTF16(tab_title))); | 166 WideToUTF16(tab_title))); | 
| 142 } else { | 167 } else { | 
| 143 // Since the tab_title will be concatenated with | 168 // Since the tab_title will be concatenated with | 
| 144 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to | 169 // IDS_TASK_MANAGER_TAB_PREFIX, we need to explicitly set the tab_title to | 
| 145 // be LTR format if there is no strong RTL charater in it. Otherwise, if | 170 // be LTR format if there is no strong RTL charater in it. Otherwise, if | 
| 146 // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result | 171 // IDS_TASK_MANAGER_TAB_PREFIX is an RTL word, the concatenated result | 
| 147 // might be wrong. For example, http://mail.yahoo.com, whose title is | 172 // might be wrong. For example, http://mail.yahoo.com, whose title is | 
| 148 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly | 173 // "Yahoo! Mail: The best web-based Email!", without setting it explicitly | 
| 149 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best | 174 // as LTR format, the concatenated result will be "!Yahoo! Mail: The best | 
| 150 // web-based Email :BAT", in which the capital letters "BAT" stands for | 175 // web-based Email :BAT", in which the capital letters "BAT" stands for | 
| 151 // the Hebrew word for "tab". | 176 // the Hebrew word for "tab". | 
| 152 base::i18n::AdjustStringForLocaleDirection(&tab_title); | 177 base::i18n::AdjustStringForLocaleDirection(&tab_title); | 
| 153 } | 178 } | 
| 154 | 179 | 
| 155 return l10n_util::GetStringF(IDS_TASK_MANAGER_TAB_PREFIX, tab_title); | 180 int message_id = GetMessagePrefixID(tab_contents_->IsInstalledApp(), | 
| 181 tab_contents_->HostsExtension(), | |
| 182 tab_contents_->profile()->IsOffTheRecord()); | |
| 183 return l10n_util::GetStringF(message_id, tab_title); | |
| 156 } | 184 } | 
| 157 | 185 | 
| 158 | |
| 159 SkBitmap TaskManagerTabContentsResource::GetIcon() const { | 186 SkBitmap TaskManagerTabContentsResource::GetIcon() const { | 
| 160 return tab_contents_->GetFavIcon(); | 187 return tab_contents_->GetFavIcon(); | 
| 161 } | 188 } | 
| 162 | 189 | 
| 163 TabContents* TaskManagerTabContentsResource::GetTabContents() const { | 190 TabContents* TaskManagerTabContentsResource::GetTabContents() const { | 
| 164 return static_cast<TabContents*>(tab_contents_); | 191 return static_cast<TabContents*>(tab_contents_); | 
| 165 } | 192 } | 
| 166 | 193 | 
| 194 const Extension* TaskManagerTabContentsResource::GetExtension() const { | |
| 195 if (tab_contents_->HostsExtension()) { | |
| 196 ExtensionsService* extensions_service = | |
| 197 tab_contents_->profile()->GetExtensionsService(); | |
| 198 return extensions_service->GetExtensionByURL(tab_contents_->GetURL()); | |
| 199 } | |
| 200 | |
| 201 return NULL; | |
| 202 } | |
| 203 | |
| 167 //////////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////////// | 
| 168 // TaskManagerTabContentsResourceProvider class | 205 // TaskManagerTabContentsResourceProvider class | 
| 169 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// | 
| 170 | 207 | 
| 171 TaskManagerTabContentsResourceProvider:: | 208 TaskManagerTabContentsResourceProvider:: | 
| 172 TaskManagerTabContentsResourceProvider(TaskManager* task_manager) | 209 TaskManagerTabContentsResourceProvider(TaskManager* task_manager) | 
| 173 : updating_(false), | 210 : updating_(false), | 
| 174 task_manager_(task_manager) { | 211 task_manager_(task_manager) { | 
| 175 } | 212 } | 
| 176 | 213 | 
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 new TaskManagerTabContentsResource(tab_contents); | 297 new TaskManagerTabContentsResource(tab_contents); | 
| 261 resources_[tab_contents] = resource; | 298 resources_[tab_contents] = resource; | 
| 262 task_manager_->AddResource(resource); | 299 task_manager_->AddResource(resource); | 
| 263 } | 300 } | 
| 264 | 301 | 
| 265 void TaskManagerTabContentsResourceProvider::Add(TabContents* tab_contents) { | 302 void TaskManagerTabContentsResourceProvider::Add(TabContents* tab_contents) { | 
| 266 if (!updating_) | 303 if (!updating_) | 
| 267 return; | 304 return; | 
| 268 | 305 | 
| 269 // Don't add dead tabs or tabs that haven't yet connected. | 306 // Don't add dead tabs or tabs that haven't yet connected. | 
| 270 // Also ignore tabs which display extension content. We collapse | |
| 271 // all of these into one extension row. | |
| 272 if (!tab_contents->GetRenderProcessHost()->GetHandle() || | 307 if (!tab_contents->GetRenderProcessHost()->GetHandle() || | 
| 273 !tab_contents->notify_disconnection() || | 308 !tab_contents->notify_disconnection()) { | 
| 274 tab_contents->HostsExtension()) { | |
| 275 return; | 309 return; | 
| 276 } | 310 } | 
| 277 | 311 | 
| 278 std::map<TabContents*, TaskManagerTabContentsResource*>::const_iterator | 312 std::map<TabContents*, TaskManagerTabContentsResource*>::const_iterator | 
| 279 iter = resources_.find(tab_contents); | 313 iter = resources_.find(tab_contents); | 
| 280 if (iter != resources_.end()) { | 314 if (iter != resources_.end()) { | 
| 281 // The case may happen that we have added a TabContents as part of the | 315 // The case may happen that we have added a TabContents as part of the | 
| 282 // iteration performed during StartUpdating() call but the notification that | 316 // iteration performed during StartUpdating() call but the notification that | 
| 283 // it has connected was not fired yet. So when the notification happens, we | 317 // it has connected was not fired yet. So when the notification happens, we | 
| 284 // already know about this tab and just ignore it. | 318 // already know about this tab and just ignore it. | 
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 : extension_host_(extension_host) { | 853 : extension_host_(extension_host) { | 
| 820 if (!default_icon_) { | 854 if (!default_icon_) { | 
| 821 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 855 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 
| 822 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 856 default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); | 
| 823 } | 857 } | 
| 824 process_handle_ = extension_host_->render_process_host()->GetHandle(); | 858 process_handle_ = extension_host_->render_process_host()->GetHandle(); | 
| 825 pid_ = base::GetProcId(process_handle_); | 859 pid_ = base::GetProcId(process_handle_); | 
| 826 std::wstring extension_name(UTF8ToWide(GetExtension()->name())); | 860 std::wstring extension_name(UTF8ToWide(GetExtension()->name())); | 
| 827 DCHECK(!extension_name.empty()); | 861 DCHECK(!extension_name.empty()); | 
| 828 | 862 | 
| 829 int message_id = | 863 int message_id = GetMessagePrefixID(GetExtension()->is_app(), true, | 
| 830 GetExtension()->is_app() ? | 864 extension_host_->profile()->IsOffTheRecord()); | 
| 831 (extension_host_->profile()->IsOffTheRecord() ? | |
| 832 IDS_TASK_MANAGER_APP_INCOGNITO_PREFIX : | |
| 833 IDS_TASK_MANAGER_APP_PREFIX) : | |
| 834 (extension_host_->profile()->IsOffTheRecord() ? | |
| 835 IDS_TASK_MANAGER_EXTENSION_INCOGNITO_PREFIX : | |
| 836 IDS_TASK_MANAGER_EXTENSION_PREFIX); | |
| 837 title_ = l10n_util::GetStringF(message_id, extension_name); | 865 title_ = l10n_util::GetStringF(message_id, extension_name); | 
| 838 } | 866 } | 
| 839 | 867 | 
| 840 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { | 868 TaskManagerExtensionProcessResource::~TaskManagerExtensionProcessResource() { | 
| 841 } | 869 } | 
| 842 | 870 | 
| 843 std::wstring TaskManagerExtensionProcessResource::GetTitle() const { | 871 std::wstring TaskManagerExtensionProcessResource::GetTitle() const { | 
| 844 return title_; | 872 return title_; | 
| 845 } | 873 } | 
| 846 | 874 | 
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1227 | 1255 | 
| 1228 return &resource_; | 1256 return &resource_; | 
| 1229 } | 1257 } | 
| 1230 | 1258 | 
| 1231 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 1259 void TaskManagerBrowserProcessResourceProvider::StartUpdating() { | 
| 1232 task_manager_->AddResource(&resource_); | 1260 task_manager_->AddResource(&resource_); | 
| 1233 } | 1261 } | 
| 1234 | 1262 | 
| 1235 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 1263 void TaskManagerBrowserProcessResourceProvider::StopUpdating() { | 
| 1236 } | 1264 } | 
| OLD | NEW |