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