| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/tab_contents_resource_provider.h" | 5 #include "chrome/browser/task_manager/tab_contents_resource_provider.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 11 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 12 #include "chrome/browser/prerender/prerender_manager.h" | 12 #include "chrome/browser/prerender/prerender_manager.h" |
| 13 #include "chrome/browser/prerender/prerender_manager_factory.h" | 13 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/search/instant_service.h" | |
| 17 #include "chrome/browser/search/instant_service_factory.h" | |
| 18 #include "chrome/browser/search/search.h" | 16 #include "chrome/browser/search/search.h" |
| 19 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
| 20 #include "chrome/browser/task_manager/renderer_resource.h" | 18 #include "chrome/browser/task_manager/renderer_resource.h" |
| 21 #include "chrome/browser/task_manager/resource_provider.h" | 19 #include "chrome/browser/task_manager/resource_provider.h" |
| 22 #include "chrome/browser/task_manager/task_manager.h" | 20 #include "chrome/browser/task_manager/task_manager.h" |
| 23 #include "chrome/browser/task_manager/task_manager_util.h" | 21 #include "chrome/browser/task_manager/task_manager_util.h" |
| 24 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/browser_iterator.h" | 24 #include "chrome/browser/ui/browser_iterator.h" |
| 27 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 virtual content::WebContents* GetWebContents() const OVERRIDE; | 80 virtual content::WebContents* GetWebContents() const OVERRIDE; |
| 83 virtual const extensions::Extension* GetExtension() const OVERRIDE; | 81 virtual const extensions::Extension* GetExtension() const OVERRIDE; |
| 84 | 82 |
| 85 private: | 83 private: |
| 86 // Returns true if contains content rendered by an extension. | 84 // Returns true if contains content rendered by an extension. |
| 87 bool HostsExtension() const; | 85 bool HostsExtension() const; |
| 88 | 86 |
| 89 static gfx::ImageSkia* prerender_icon_; | 87 static gfx::ImageSkia* prerender_icon_; |
| 90 content::WebContents* web_contents_; | 88 content::WebContents* web_contents_; |
| 91 Profile* profile_; | 89 Profile* profile_; |
| 92 bool is_instant_ntp_; | |
| 93 | 90 |
| 94 DISALLOW_COPY_AND_ASSIGN(TabContentsResource); | 91 DISALLOW_COPY_AND_ASSIGN(TabContentsResource); |
| 95 }; | 92 }; |
| 96 | 93 |
| 97 gfx::ImageSkia* TabContentsResource::prerender_icon_ = NULL; | 94 gfx::ImageSkia* TabContentsResource::prerender_icon_ = NULL; |
| 98 | 95 |
| 99 TabContentsResource::TabContentsResource( | 96 TabContentsResource::TabContentsResource( |
| 100 WebContents* web_contents) | 97 WebContents* web_contents) |
| 101 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(), | 98 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(), |
| 102 web_contents->GetRenderViewHost()), | 99 web_contents->GetRenderViewHost()), |
| 103 web_contents_(web_contents), | 100 web_contents_(web_contents), |
| 104 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 101 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 105 is_instant_ntp_(chrome::IsPreloadedInstantExtendedNTP(web_contents)) { | |
| 106 if (!prerender_icon_) { | 102 if (!prerender_icon_) { |
| 107 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 103 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 108 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); | 104 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); |
| 109 } | 105 } |
| 110 } | 106 } |
| 111 | 107 |
| 112 TabContentsResource::~TabContentsResource() { | 108 TabContentsResource::~TabContentsResource() { |
| 113 } | 109 } |
| 114 | 110 |
| 115 bool TabContentsResource::HostsExtension() const { | 111 bool TabContentsResource::HostsExtension() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 131 ExtensionService* extension_service = profile_->GetExtensionService(); | 127 ExtensionService* extension_service = profile_->GetExtensionService(); |
| 132 extensions::ProcessMap* process_map = extension_service->process_map(); | 128 extensions::ProcessMap* process_map = extension_service->process_map(); |
| 133 bool is_app = extension_service->IsInstalledApp(url) && | 129 bool is_app = extension_service->IsInstalledApp(url) && |
| 134 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID()); | 130 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID()); |
| 135 | 131 |
| 136 int message_id = util::GetMessagePrefixID( | 132 int message_id = util::GetMessagePrefixID( |
| 137 is_app, | 133 is_app, |
| 138 HostsExtension(), | 134 HostsExtension(), |
| 139 profile_->IsOffTheRecord(), | 135 profile_->IsOffTheRecord(), |
| 140 IsContentsPrerendering(web_contents_), | 136 IsContentsPrerendering(web_contents_), |
| 141 is_instant_ntp_, | |
| 142 false); // is_background | 137 false); // is_background |
| 143 return l10n_util::GetStringFUTF16(message_id, tab_title); | 138 return l10n_util::GetStringFUTF16(message_id, tab_title); |
| 144 } | 139 } |
| 145 | 140 |
| 146 base::string16 TabContentsResource::GetProfileName() const { | 141 base::string16 TabContentsResource::GetProfileName() const { |
| 147 return util::GetProfileNameFromInfoCache(profile_); | 142 return util::GetProfileNameFromInfoCache(profile_); |
| 148 } | 143 } |
| 149 | 144 |
| 150 gfx::ImageSkia TabContentsResource::GetIcon() const { | 145 gfx::ImageSkia TabContentsResource::GetIcon() const { |
| 151 if (IsContentsPrerendering(web_contents_)) | 146 if (IsContentsPrerendering(web_contents_)) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 prerender::PrerenderManager* prerender_manager = | 225 prerender::PrerenderManager* prerender_manager = |
| 231 prerender::PrerenderManagerFactory::GetForProfile(profiles[i]); | 226 prerender::PrerenderManagerFactory::GetForProfile(profiles[i]); |
| 232 if (prerender_manager) { | 227 if (prerender_manager) { |
| 233 const std::vector<content::WebContents*> contentses = | 228 const std::vector<content::WebContents*> contentses = |
| 234 prerender_manager->GetAllPrerenderingContents(); | 229 prerender_manager->GetAllPrerenderingContents(); |
| 235 for (size_t j = 0; j < contentses.size(); ++j) | 230 for (size_t j = 0; j < contentses.size(); ++j) |
| 236 Add(contentses[j]); | 231 Add(contentses[j]); |
| 237 } | 232 } |
| 238 } | 233 } |
| 239 | 234 |
| 240 // Add all the Instant Extended prerendered NTPs. | |
| 241 for (size_t i = 0; i < profiles.size(); ++i) { | |
| 242 const InstantService* instant_service = | |
| 243 InstantServiceFactory::GetForProfile(profiles[i]); | |
| 244 if (instant_service && instant_service->GetNTPContents()) | |
| 245 Add(instant_service->GetNTPContents()); | |
| 246 } | |
| 247 | |
| 248 #if defined(ENABLE_FULL_PRINTING) | 235 #if defined(ENABLE_FULL_PRINTING) |
| 249 // Add all the pages being background printed. | 236 // Add all the pages being background printed. |
| 250 printing::BackgroundPrintingManager* printing_manager = | 237 printing::BackgroundPrintingManager* printing_manager = |
| 251 g_browser_process->background_printing_manager(); | 238 g_browser_process->background_printing_manager(); |
| 252 std::set<content::WebContents*> printing_contents = | 239 std::set<content::WebContents*> printing_contents = |
| 253 printing_manager->CurrentContentSet(); | 240 printing_manager->CurrentContentSet(); |
| 254 for (std::set<content::WebContents*>::iterator i = | 241 for (std::set<content::WebContents*>::iterator i = |
| 255 printing_contents.begin(); | 242 printing_contents.begin(); |
| 256 i != printing_contents.end(); ++i) { | 243 i != printing_contents.end(); ++i) { |
| 257 Add(*i); | 244 Add(*i); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 280 |
| 294 void TabContentsResourceProvider::Add(WebContents* web_contents) { | 281 void TabContentsResourceProvider::Add(WebContents* web_contents) { |
| 295 if (!updating_) | 282 if (!updating_) |
| 296 return; | 283 return; |
| 297 | 284 |
| 298 // The contents that are tracked by this resource provider are those that | 285 // The contents that are tracked by this resource provider are those that |
| 299 // are tab contents (WebContents serving as a tab in a Browser), Instant | 286 // are tab contents (WebContents serving as a tab in a Browser), Instant |
| 300 // pages, prerender pages, and background printed pages. | 287 // pages, prerender pages, and background printed pages. |
| 301 if (!chrome::FindBrowserWithWebContents(web_contents) && | 288 if (!chrome::FindBrowserWithWebContents(web_contents) && |
| 302 !IsContentsPrerendering(web_contents) && | 289 !IsContentsPrerendering(web_contents) && |
| 303 !chrome::IsPreloadedInstantExtendedNTP(web_contents) && | |
| 304 !IsContentsBackgroundPrinted(web_contents) && | 290 !IsContentsBackgroundPrinted(web_contents) && |
| 305 !DevToolsWindow::IsDevToolsWindow(web_contents->GetRenderViewHost())) { | 291 !DevToolsWindow::IsDevToolsWindow(web_contents->GetRenderViewHost())) { |
| 306 return; | 292 return; |
| 307 } | 293 } |
| 308 | 294 |
| 309 // Don't add dead tabs or tabs that haven't yet connected. | 295 // Don't add dead tabs or tabs that haven't yet connected. |
| 310 if (!web_contents->GetRenderProcessHost()->GetHandle() || | 296 if (!web_contents->GetRenderProcessHost()->GetHandle() || |
| 311 !web_contents->WillNotifyDisconnection()) { | 297 !web_contents->WillNotifyDisconnection()) { |
| 312 return; | 298 return; |
| 313 } | 299 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: | 347 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
| 362 Remove(web_contents); | 348 Remove(web_contents); |
| 363 break; | 349 break; |
| 364 default: | 350 default: |
| 365 NOTREACHED() << "Unexpected notification."; | 351 NOTREACHED() << "Unexpected notification."; |
| 366 return; | 352 return; |
| 367 } | 353 } |
| 368 } | 354 } |
| 369 | 355 |
| 370 } // namespace task_manager | 356 } // namespace task_manager |
| OLD | NEW |