Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: chrome/browser/task_manager/tab_contents_resource_provider.cc

Issue 18223002: InstantExtended: Remove overlay control code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Call renamed method. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/favicon/favicon_tab_helper.h" 9 #include "chrome/browser/favicon/favicon_tab_helper.h"
10 #include "chrome/browser/prerender/prerender_manager.h" 10 #include "chrome/browser/prerender/prerender_manager.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 namespace task_manager { 58 namespace task_manager {
59 59
60 // Tracks a single tab contents, prerendered page, Instant page, or background 60 // Tracks a single tab contents, prerendered page, Instant page, or background
61 // printing page. 61 // printing page.
62 class TabContentsResource : public RendererResource { 62 class TabContentsResource : public RendererResource {
63 public: 63 public:
64 explicit TabContentsResource(content::WebContents* web_contents); 64 explicit TabContentsResource(content::WebContents* web_contents);
65 virtual ~TabContentsResource(); 65 virtual ~TabContentsResource();
66 66
67 // Called when the underlying web_contents has been committed and is no
68 // longer an Instant overlay.
69 void InstantCommitted();
70
71 // Resource methods: 67 // Resource methods:
72 virtual Type GetType() const OVERRIDE; 68 virtual Type GetType() const OVERRIDE;
73 virtual string16 GetTitle() const OVERRIDE; 69 virtual string16 GetTitle() const OVERRIDE;
74 virtual string16 GetProfileName() const OVERRIDE; 70 virtual string16 GetProfileName() const OVERRIDE;
75 virtual gfx::ImageSkia GetIcon() const OVERRIDE; 71 virtual gfx::ImageSkia GetIcon() const OVERRIDE;
76 virtual content::WebContents* GetWebContents() const OVERRIDE; 72 virtual content::WebContents* GetWebContents() const OVERRIDE;
77 virtual const extensions::Extension* GetExtension() const OVERRIDE; 73 virtual const extensions::Extension* GetExtension() const OVERRIDE;
78 74
79 private: 75 private:
80 // Returns true if contains content rendered by an extension. 76 // Returns true if contains content rendered by an extension.
81 bool HostsExtension() const; 77 bool HostsExtension() const;
82 78
83 static gfx::ImageSkia* prerender_icon_; 79 static gfx::ImageSkia* prerender_icon_;
84 content::WebContents* web_contents_; 80 content::WebContents* web_contents_;
85 Profile* profile_; 81 Profile* profile_;
86 bool is_instant_overlay_; 82 bool is_instant_ntp_;
87 83
88 DISALLOW_COPY_AND_ASSIGN(TabContentsResource); 84 DISALLOW_COPY_AND_ASSIGN(TabContentsResource);
89 }; 85 };
90 86
91 gfx::ImageSkia* TabContentsResource::prerender_icon_ = NULL; 87 gfx::ImageSkia* TabContentsResource::prerender_icon_ = NULL;
92 88
93 TabContentsResource::TabContentsResource( 89 TabContentsResource::TabContentsResource(
94 WebContents* web_contents) 90 WebContents* web_contents)
95 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(), 91 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(),
96 web_contents->GetRenderViewHost()), 92 web_contents->GetRenderViewHost()),
97 web_contents_(web_contents), 93 web_contents_(web_contents),
98 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 94 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
99 is_instant_overlay_(chrome::IsInstantOverlay(web_contents) || 95 is_instant_ntp_(chrome::IsPreloadedInstantExtendedNTP(web_contents)) {
100 chrome::IsPreloadedInstantExtendedNTP(web_contents)) {
101 if (!prerender_icon_) { 96 if (!prerender_icon_) {
102 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 97 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
103 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); 98 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER);
104 } 99 }
105 } 100 }
106 101
107 TabContentsResource::~TabContentsResource() { 102 TabContentsResource::~TabContentsResource() {
108 } 103 }
109 104
110 void TabContentsResource::InstantCommitted() {
111 DCHECK(is_instant_overlay_);
112 is_instant_overlay_ = false;
113 }
114
115 bool TabContentsResource::HostsExtension() const { 105 bool TabContentsResource::HostsExtension() const {
116 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme); 106 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme);
117 } 107 }
118 108
119 Resource::Type TabContentsResource::GetType() const { 109 Resource::Type TabContentsResource::GetType() const {
120 return HostsExtension() ? EXTENSION : RENDERER; 110 return HostsExtension() ? EXTENSION : RENDERER;
121 } 111 }
122 112
123 string16 TabContentsResource::GetTitle() const { 113 string16 TabContentsResource::GetTitle() const {
124 // Fall back on the URL if there's no title. 114 // Fall back on the URL if there's no title.
125 GURL url = web_contents_->GetURL(); 115 GURL url = web_contents_->GetURL();
126 string16 tab_title = util::GetTitleFromWebContents(web_contents_); 116 string16 tab_title = util::GetTitleFromWebContents(web_contents_);
127 117
128 // Only classify as an app if the URL is an app and the tab is hosting an 118 // Only classify as an app if the URL is an app and the tab is hosting an
129 // extension process. (It's possible to be showing the URL from before it 119 // extension process. (It's possible to be showing the URL from before it
130 // was installed as an app.) 120 // was installed as an app.)
131 ExtensionService* extension_service = profile_->GetExtensionService(); 121 ExtensionService* extension_service = profile_->GetExtensionService();
132 extensions::ProcessMap* process_map = extension_service->process_map(); 122 extensions::ProcessMap* process_map = extension_service->process_map();
133 bool is_app = extension_service->IsInstalledApp(url) && 123 bool is_app = extension_service->IsInstalledApp(url) &&
134 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID()); 124 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID());
135 125
136 int message_id = util::GetMessagePrefixID( 126 int message_id = util::GetMessagePrefixID(
137 is_app, 127 is_app,
138 HostsExtension(), 128 HostsExtension(),
139 profile_->IsOffTheRecord(), 129 profile_->IsOffTheRecord(),
140 IsContentsPrerendering(web_contents_), 130 IsContentsPrerendering(web_contents_),
141 is_instant_overlay_, 131 is_instant_ntp_,
142 false); // is_background 132 false); // is_background
143 return l10n_util::GetStringFUTF16(message_id, tab_title); 133 return l10n_util::GetStringFUTF16(message_id, tab_title);
144 } 134 }
145 135
146 string16 TabContentsResource::GetProfileName() const { 136 string16 TabContentsResource::GetProfileName() const {
147 return util::GetProfileNameFromInfoCache(profile_); 137 return util::GetProfileNameFromInfoCache(profile_);
148 } 138 }
149 139
150 gfx::ImageSkia TabContentsResource::GetIcon() const { 140 gfx::ImageSkia TabContentsResource::GetIcon() const {
151 if (IsContentsPrerendering(web_contents_)) 141 if (IsContentsPrerendering(web_contents_))
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // are tab contents (WebContents serving as a tab in a Browser), Instant 203 // are tab contents (WebContents serving as a tab in a Browser), Instant
214 // pages, prerender pages, and background printed pages. 204 // pages, prerender pages, and background printed pages.
215 205
216 // Add all the existing WebContentses. 206 // Add all the existing WebContentses.
217 for (TabContentsIterator iterator; !iterator.done(); iterator.Next()) 207 for (TabContentsIterator iterator; !iterator.done(); iterator.Next())
218 Add(*iterator); 208 Add(*iterator);
219 209
220 // Add all the Instant pages. 210 // Add all the Instant pages.
221 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 211 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
222 if (it->instant_controller()) { 212 if (it->instant_controller()) {
223 if (it->instant_controller()->instant()->GetOverlayContents())
224 Add(it->instant_controller()->instant()->GetOverlayContents());
225 if (it->instant_controller()->instant()->GetNTPContents()) 213 if (it->instant_controller()->instant()->GetNTPContents())
226 Add(it->instant_controller()->instant()->GetNTPContents()); 214 Add(it->instant_controller()->instant()->GetNTPContents());
227 } 215 }
228 } 216 }
229 217
230 // Add all the prerender pages. 218 // Add all the prerender pages.
231 std::vector<Profile*> profiles( 219 std::vector<Profile*> profiles(
232 g_browser_process->profile_manager()->GetLoadedProfiles()); 220 g_browser_process->profile_manager()->GetLoadedProfiles());
233 for (size_t i = 0; i < profiles.size(); ++i) { 221 for (size_t i = 0; i < profiles.size(); ++i) {
234 prerender::PrerenderManager* prerender_manager = 222 prerender::PrerenderManager* prerender_manager =
(...skipping 15 matching lines...) Expand all
250 Add(*i); 238 Add(*i);
251 } 239 }
252 240
253 // Then we register for notifications to get new web contents. 241 // Then we register for notifications to get new web contents.
254 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 242 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
255 content::NotificationService::AllBrowserContextsAndSources()); 243 content::NotificationService::AllBrowserContextsAndSources());
256 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 244 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
257 content::NotificationService::AllBrowserContextsAndSources()); 245 content::NotificationService::AllBrowserContextsAndSources());
258 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 246 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
259 content::NotificationService::AllBrowserContextsAndSources()); 247 content::NotificationService::AllBrowserContextsAndSources());
260 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
261 content::NotificationService::AllBrowserContextsAndSources());
262 } 248 }
263 249
264 void TabContentsResourceProvider::StopUpdating() { 250 void TabContentsResourceProvider::StopUpdating() {
265 DCHECK(updating_); 251 DCHECK(updating_);
266 updating_ = false; 252 updating_ = false;
267 253
268 // Then we unregister for notifications to get new web contents. 254 // Then we unregister for notifications to get new web contents.
269 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 255 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
270 content::NotificationService::AllBrowserContextsAndSources()); 256 content::NotificationService::AllBrowserContextsAndSources());
271 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 257 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
272 content::NotificationService::AllBrowserContextsAndSources()); 258 content::NotificationService::AllBrowserContextsAndSources());
273 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 259 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
274 content::NotificationService::AllBrowserContextsAndSources()); 260 content::NotificationService::AllBrowserContextsAndSources());
275 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
276 content::NotificationService::AllBrowserContextsAndSources());
277 261
278 // Delete all the resources. 262 // Delete all the resources.
279 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); 263 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
280 264
281 resources_.clear(); 265 resources_.clear();
282 } 266 }
283 267
284 void TabContentsResourceProvider::AddToTaskManager(WebContents* web_contents) { 268 void TabContentsResourceProvider::AddToTaskManager(WebContents* web_contents) {
285 TabContentsResource* resource = new TabContentsResource(web_contents); 269 TabContentsResource* resource = new TabContentsResource(web_contents);
286 resources_[web_contents] = resource; 270 resources_[web_contents] = resource;
287 task_manager_->AddResource(resource); 271 task_manager_->AddResource(resource);
288 } 272 }
289 273
290 void TabContentsResourceProvider::Add(WebContents* web_contents) { 274 void TabContentsResourceProvider::Add(WebContents* web_contents) {
291 if (!updating_) 275 if (!updating_)
292 return; 276 return;
293 277
294 // The contents that are tracked by this resource provider are those that 278 // The contents that are tracked by this resource provider are those that
295 // are tab contents (WebContents serving as a tab in a Browser), Instant 279 // are tab contents (WebContents serving as a tab in a Browser), Instant
296 // pages, prerender pages, and background printed pages. 280 // pages, prerender pages, and background printed pages.
297 if (!chrome::FindBrowserWithWebContents(web_contents) && 281 if (!chrome::FindBrowserWithWebContents(web_contents) &&
298 !IsContentsPrerendering(web_contents) && 282 !IsContentsPrerendering(web_contents) &&
299 !chrome::IsInstantOverlay(web_contents) &&
300 !chrome::IsPreloadedInstantExtendedNTP(web_contents) && 283 !chrome::IsPreloadedInstantExtendedNTP(web_contents) &&
301 !IsContentsBackgroundPrinted(web_contents)) { 284 !IsContentsBackgroundPrinted(web_contents)) {
302 return; 285 return;
303 } 286 }
304 287
305 // Don't add dead tabs or tabs that haven't yet connected. 288 // Don't add dead tabs or tabs that haven't yet connected.
306 if (!web_contents->GetRenderProcessHost()->GetHandle() || 289 if (!web_contents->GetRenderProcessHost()->GetHandle() ||
307 !web_contents->WillNotifyDisconnection()) { 290 !web_contents->WillNotifyDisconnection()) {
308 return; 291 return;
309 } 292 }
(...skipping 23 matching lines...) Expand all
333 316
334 // Remove the resource from the Task Manager. 317 // Remove the resource from the Task Manager.
335 TabContentsResource* resource = iter->second; 318 TabContentsResource* resource = iter->second;
336 task_manager_->RemoveResource(resource); 319 task_manager_->RemoveResource(resource);
337 // And from the provider. 320 // And from the provider.
338 resources_.erase(iter); 321 resources_.erase(iter);
339 // Finally, delete the resource. 322 // Finally, delete the resource.
340 delete resource; 323 delete resource;
341 } 324 }
342 325
343 void TabContentsResourceProvider::InstantCommitted(WebContents* web_contents) {
344 if (!updating_)
345 return;
346 std::map<WebContents*, TabContentsResource*>::iterator
347 iter = resources_.find(web_contents);
348 DCHECK(iter != resources_.end());
349 if (iter != resources_.end())
350 iter->second->InstantCommitted();
351 }
352
353 void TabContentsResourceProvider::Observe( 326 void TabContentsResourceProvider::Observe(
354 int type, 327 int type,
355 const content::NotificationSource& source, 328 const content::NotificationSource& source,
356 const content::NotificationDetails& details) { 329 const content::NotificationDetails& details) {
357 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 330 WebContents* web_contents = content::Source<WebContents>(source).ptr();
358 331
359 switch (type) { 332 switch (type) {
360 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: 333 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
361 Add(web_contents); 334 Add(web_contents);
362 break; 335 break;
363 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: 336 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED:
364 Remove(web_contents); 337 Remove(web_contents);
365 Add(web_contents); 338 Add(web_contents);
366 break; 339 break;
367 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: 340 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED:
368 Remove(web_contents); 341 Remove(web_contents);
369 break; 342 break;
370 case chrome::NOTIFICATION_INSTANT_COMMITTED:
371 InstantCommitted(web_contents);
372 break;
373 default: 343 default:
374 NOTREACHED() << "Unexpected notification."; 344 NOTREACHED() << "Unexpected notification.";
375 return; 345 return;
376 } 346 }
377 } 347 }
378 348
379 } // namespace task_manager 349 } // namespace task_manager
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/tab_contents_resource_provider.h ('k') | chrome/browser/ui/browser_instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698