OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/printing/print_preview_tab_controller.h" | 5 #include "chrome/browser/printing/print_preview_tab_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 } // namespace | 192 } // namespace |
193 | 193 |
194 namespace printing { | 194 namespace printing { |
195 | 195 |
196 PrintPreviewTabController::PrintPreviewTabController() | 196 PrintPreviewTabController::PrintPreviewTabController() |
197 : waiting_for_new_preview_page_(false), | 197 : waiting_for_new_preview_page_(false), |
198 is_creating_print_preview_tab_(false) { | 198 is_creating_print_preview_tab_(false) { |
199 } | 199 } |
200 | 200 |
201 PrintPreviewTabController::~PrintPreviewTabController() {} | |
202 | |
203 // static | 201 // static |
204 PrintPreviewTabController* PrintPreviewTabController::GetInstance() { | 202 PrintPreviewTabController* PrintPreviewTabController::GetInstance() { |
205 if (!g_browser_process) | 203 if (!g_browser_process) |
206 return NULL; | 204 return NULL; |
207 return g_browser_process->print_preview_tab_controller(); | 205 return g_browser_process->print_preview_tab_controller(); |
208 } | 206 } |
209 | 207 |
210 // static | 208 // static |
211 void PrintPreviewTabController::PrintPreview(TabContentsWrapper* tab) { | 209 void PrintPreviewTabController::PrintPreview(TabContentsWrapper* tab) { |
212 if (tab->web_contents()->ShowingInterstitialPage()) | 210 if (tab->web_contents()->ShowingInterstitialPage()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 for (it = preview_tab_map_.begin(); it != preview_tab_map_.end(); ++it) { | 242 for (it = preview_tab_map_.begin(); it != preview_tab_map_.end(); ++it) { |
245 // If |tab| is an initiator tab. | 243 // If |tab| is an initiator tab. |
246 if (tab == it->second) { | 244 if (tab == it->second) { |
247 // Return the associated preview tab. | 245 // Return the associated preview tab. |
248 return it->first; | 246 return it->first; |
249 } | 247 } |
250 } | 248 } |
251 return NULL; | 249 return NULL; |
252 } | 250 } |
253 | 251 |
| 252 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( |
| 253 TabContentsWrapper* preview_tab) { |
| 254 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
| 255 if (it != preview_tab_map_.end()) |
| 256 return preview_tab_map_[preview_tab]; |
| 257 return NULL; |
| 258 } |
| 259 |
254 void PrintPreviewTabController::Observe( | 260 void PrintPreviewTabController::Observe( |
255 int type, | 261 int type, |
256 const content::NotificationSource& source, | 262 const content::NotificationSource& source, |
257 const content::NotificationDetails& details) { | 263 const content::NotificationDetails& details) { |
258 switch (type) { | 264 switch (type) { |
259 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 265 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
260 OnRendererProcessClosed( | 266 OnRendererProcessClosed( |
261 content::Source<content::RenderProcessHost>(source).ptr()); | 267 content::Source<content::RenderProcessHost>(source).ptr()); |
262 break; | 268 break; |
263 } | 269 } |
(...skipping 15 matching lines...) Expand all Loading... |
279 OnNavEntryCommitted(wrapper, load_details); | 285 OnNavEntryCommitted(wrapper, load_details); |
280 break; | 286 break; |
281 } | 287 } |
282 default: { | 288 default: { |
283 NOTREACHED(); | 289 NOTREACHED(); |
284 break; | 290 break; |
285 } | 291 } |
286 } | 292 } |
287 } | 293 } |
288 | 294 |
| 295 // static |
| 296 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { |
| 297 return IsPrintPreviewURL(tab->web_contents()->GetURL()); |
| 298 } |
| 299 |
| 300 // static |
| 301 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { |
| 302 return (url.SchemeIs(chrome::kChromeUIScheme) && |
| 303 url.host() == chrome::kChromeUIPrintHost); |
| 304 } |
| 305 |
| 306 void PrintPreviewTabController::EraseInitiatorTabInfo( |
| 307 TabContentsWrapper* preview_tab) { |
| 308 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
| 309 if (it == preview_tab_map_.end()) |
| 310 return; |
| 311 |
| 312 RemoveObservers(it->second); |
| 313 preview_tab_map_[preview_tab] = NULL; |
| 314 } |
| 315 |
| 316 bool PrintPreviewTabController::is_creating_print_preview_tab() const { |
| 317 return is_creating_print_preview_tab_; |
| 318 } |
| 319 |
| 320 PrintPreviewTabController::~PrintPreviewTabController() {} |
| 321 |
289 void PrintPreviewTabController::OnRendererProcessClosed( | 322 void PrintPreviewTabController::OnRendererProcessClosed( |
290 content::RenderProcessHost* rph) { | 323 content::RenderProcessHost* rph) { |
291 // Store tabs in a vector and deal with them after iterating through | 324 // Store tabs in a vector and deal with them after iterating through |
292 // |preview_tab_map_| because RemoveFooTab() can change |preview_tab_map_|. | 325 // |preview_tab_map_| because RemoveFooTab() can change |preview_tab_map_|. |
293 std::vector<TabContentsWrapper*> closed_initiator_tabs; | 326 std::vector<TabContentsWrapper*> closed_initiator_tabs; |
294 std::vector<TabContentsWrapper*> closed_preview_tabs; | 327 std::vector<TabContentsWrapper*> closed_preview_tabs; |
295 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); | 328 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); |
296 iter != preview_tab_map_.end(); ++iter) { | 329 iter != preview_tab_map_.end(); ++iter) { |
297 TabContentsWrapper* preview_tab = iter->first; | 330 TabContentsWrapper* preview_tab = iter->first; |
298 TabContentsWrapper* initiator_tab = iter->second; | 331 TabContentsWrapper* initiator_tab = iter->second; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 397 } |
365 } | 398 } |
366 NOTREACHED(); | 399 NOTREACHED(); |
367 return; | 400 return; |
368 } | 401 } |
369 | 402 |
370 // Initiator tab navigated. | 403 // Initiator tab navigated. |
371 RemoveInitiatorTab(tab, true); | 404 RemoveInitiatorTab(tab, true); |
372 } | 405 } |
373 | 406 |
374 // static | |
375 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { | |
376 return IsPrintPreviewURL(tab->web_contents()->GetURL()); | |
377 } | |
378 | |
379 // static | |
380 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { | |
381 return (url.SchemeIs(chrome::kChromeUIScheme) && | |
382 url.host() == chrome::kChromeUIPrintHost); | |
383 } | |
384 | |
385 void PrintPreviewTabController::EraseInitiatorTabInfo( | |
386 TabContentsWrapper* preview_tab) { | |
387 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | |
388 if (it == preview_tab_map_.end()) | |
389 return; | |
390 | |
391 RemoveObservers(it->second); | |
392 preview_tab_map_[preview_tab] = NULL; | |
393 } | |
394 | |
395 bool PrintPreviewTabController::is_creating_print_preview_tab() const { | |
396 return is_creating_print_preview_tab_; | |
397 } | |
398 | |
399 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( | |
400 TabContentsWrapper* preview_tab) { | |
401 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | |
402 if (it != preview_tab_map_.end()) | |
403 return preview_tab_map_[preview_tab]; | |
404 return NULL; | |
405 } | |
406 | |
407 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( | 407 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( |
408 TabContentsWrapper* initiator_tab) { | 408 TabContentsWrapper* initiator_tab) { |
409 AutoReset<bool> auto_reset(&is_creating_print_preview_tab_, true); | 409 AutoReset<bool> auto_reset(&is_creating_print_preview_tab_, true); |
410 WebContents* web_contents = initiator_tab->web_contents(); | 410 WebContents* web_contents = initiator_tab->web_contents(); |
411 Browser* current_browser = | 411 Browser* current_browser = |
412 BrowserList::FindBrowserWithWebContents(web_contents); | 412 BrowserList::FindBrowserWithWebContents(web_contents); |
413 if (!current_browser) { | 413 if (!current_browser) { |
414 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { | 414 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { |
415 Profile* profile = | 415 Profile* profile = |
416 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 416 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 539 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
540 preview_tab->web_contents()->GetWebUI()->GetController()); | 540 preview_tab->web_contents()->GetWebUI()->GetController()); |
541 if (print_preview_ui) | 541 if (print_preview_ui) |
542 print_preview_ui->OnTabDestroyed(); | 542 print_preview_ui->OnTabDestroyed(); |
543 | 543 |
544 preview_tab_map_.erase(preview_tab); | 544 preview_tab_map_.erase(preview_tab); |
545 RemoveObservers(preview_tab); | 545 RemoveObservers(preview_tab); |
546 } | 546 } |
547 | 547 |
548 } // namespace printing | 548 } // namespace printing |
OLD | NEW |