| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/background_resource_provider.h" | 5 #include "chrome/browser/task_manager/background_resource_provider.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/background/background_contents_service.h" | 10 #include "chrome/browser/background/background_contents_service.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 BackgroundContentsResource::~BackgroundContentsResource() { | 94 BackgroundContentsResource::~BackgroundContentsResource() { |
| 95 } | 95 } |
| 96 | 96 |
| 97 base::string16 BackgroundContentsResource::GetTitle() const { | 97 base::string16 BackgroundContentsResource::GetTitle() const { |
| 98 base::string16 title = application_name_; | 98 base::string16 title = application_name_; |
| 99 | 99 |
| 100 if (title.empty()) { | 100 if (title.empty()) { |
| 101 // No title (can't locate the parent app for some reason) so just display | 101 // No title (can't locate the parent app for some reason) so just display |
| 102 // the URL (properly forced to be LTR). | 102 // the URL (properly forced to be LTR). |
| 103 title = base::i18n::GetDisplayStringInLTRDirectionality( | 103 title = base::i18n::GetDisplayStringInLTRDirectionality( |
| 104 UTF8ToUTF16(background_contents_->GetURL().spec())); | 104 base::UTF8ToUTF16(background_contents_->GetURL().spec())); |
| 105 } | 105 } |
| 106 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_BACKGROUND_PREFIX, title); | 106 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_BACKGROUND_PREFIX, title); |
| 107 } | 107 } |
| 108 | 108 |
| 109 base::string16 BackgroundContentsResource::GetProfileName() const { | 109 base::string16 BackgroundContentsResource::GetProfileName() const { |
| 110 return base::string16(); | 110 return base::string16(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 gfx::ImageSkia BackgroundContentsResource::GetIcon() const { | 113 gfx::ImageSkia BackgroundContentsResource::GetIcon() const { |
| 114 return *default_icon_; | 114 return *default_icon_; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 background_contents_service->GetBackgroundContents(); | 174 background_contents_service->GetBackgroundContents(); |
| 175 ExtensionService* extension_service = profiles[i]->GetExtensionService(); | 175 ExtensionService* extension_service = profiles[i]->GetExtensionService(); |
| 176 for (std::vector<BackgroundContents*>::iterator iterator = contents.begin(); | 176 for (std::vector<BackgroundContents*>::iterator iterator = contents.begin(); |
| 177 iterator != contents.end(); ++iterator) { | 177 iterator != contents.end(); ++iterator) { |
| 178 base::string16 application_name; | 178 base::string16 application_name; |
| 179 // Lookup the name from the parent extension. | 179 // Lookup the name from the parent extension. |
| 180 if (extension_service) { | 180 if (extension_service) { |
| 181 const base::string16& application_id = | 181 const base::string16& application_id = |
| 182 background_contents_service->GetParentApplicationId(*iterator); | 182 background_contents_service->GetParentApplicationId(*iterator); |
| 183 const Extension* extension = extension_service->GetExtensionById( | 183 const Extension* extension = extension_service->GetExtensionById( |
| 184 UTF16ToUTF8(application_id), false); | 184 base::UTF16ToUTF8(application_id), false); |
| 185 if (extension) | 185 if (extension) |
| 186 application_name = UTF8ToUTF16(extension->name()); | 186 application_name = base::UTF8ToUTF16(extension->name()); |
| 187 } | 187 } |
| 188 Add(*iterator, application_name); | 188 Add(*iterator, application_name); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Then we register for notifications to get new BackgroundContents. | 192 // Then we register for notifications to get new BackgroundContents. |
| 193 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, | 193 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, |
| 194 content::NotificationService::AllBrowserContextsAndSources()); | 194 content::NotificationService::AllBrowserContextsAndSources()); |
| 195 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | 195 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 196 content::NotificationService::AllBrowserContextsAndSources()); | 196 content::NotificationService::AllBrowserContextsAndSources()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED: { | 270 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED: { |
| 271 // Get the name from the parent application. If no parent application is | 271 // Get the name from the parent application. If no parent application is |
| 272 // found, just pass an empty string - BackgroundContentsResource::GetTitle | 272 // found, just pass an empty string - BackgroundContentsResource::GetTitle |
| 273 // will display the URL instead in this case. This should never happen | 273 // will display the URL instead in this case. This should never happen |
| 274 // except in rare cases when an extension is being unloaded or chrome is | 274 // except in rare cases when an extension is being unloaded or chrome is |
| 275 // exiting while the task manager is displayed. | 275 // exiting while the task manager is displayed. |
| 276 base::string16 application_name; | 276 base::string16 application_name; |
| 277 ExtensionService* service = | 277 ExtensionService* service = |
| 278 content::Source<Profile>(source)->GetExtensionService(); | 278 content::Source<Profile>(source)->GetExtensionService(); |
| 279 if (service) { | 279 if (service) { |
| 280 std::string application_id = UTF16ToUTF8( | 280 std::string application_id = base::UTF16ToUTF8( |
| 281 content::Details<BackgroundContentsOpenedDetails>(details)-> | 281 content::Details<BackgroundContentsOpenedDetails>(details)-> |
| 282 application_id); | 282 application_id); |
| 283 const Extension* extension = | 283 const Extension* extension = |
| 284 service->GetExtensionById(application_id, false); | 284 service->GetExtensionById(application_id, false); |
| 285 // Extension can be NULL when running unit tests. | 285 // Extension can be NULL when running unit tests. |
| 286 if (extension) | 286 if (extension) |
| 287 application_name = UTF8ToUTF16(extension->name()); | 287 application_name = base::UTF8ToUTF16(extension->name()); |
| 288 } | 288 } |
| 289 Add(content::Details<BackgroundContentsOpenedDetails>(details)->contents, | 289 Add(content::Details<BackgroundContentsOpenedDetails>(details)->contents, |
| 290 application_name); | 290 application_name); |
| 291 // Opening a new BackgroundContents needs to force the display to refresh | 291 // Opening a new BackgroundContents needs to force the display to refresh |
| 292 // (applications may now be considered "background" that weren't before). | 292 // (applications may now be considered "background" that weren't before). |
| 293 task_manager_->ModelChanged(); | 293 task_manager_->ModelChanged(); |
| 294 break; | 294 break; |
| 295 } | 295 } |
| 296 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: { | 296 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: { |
| 297 BackgroundContents* contents = | 297 BackgroundContents* contents = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 325 } | 325 } |
| 326 break; | 326 break; |
| 327 } | 327 } |
| 328 default: | 328 default: |
| 329 NOTREACHED() << "Unexpected notification."; | 329 NOTREACHED() << "Unexpected notification."; |
| 330 return; | 330 return; |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace task_manager | 334 } // namespace task_manager |
| OLD | NEW |