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_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | 9 |
11 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
12 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/stl_util.h" | |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 16 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
17 #include "chrome/browser/printing/print_view_manager.h" | 17 #include "chrome/browser/printing/print_view_manager.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_navigator.h" | 21 #include "chrome/browser/ui/browser_navigator.h" |
22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/host_desktop.h" | 23 #include "chrome/browser/ui/host_desktop.h" |
24 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 24 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
25 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 25 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
26 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 26 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
27 #include "chrome/common/chrome_content_client.h" | 27 #include "chrome/common/chrome_content_client.h" |
28 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
30 #include "components/web_modal/web_contents_modal_dialog_host.h" | 30 #include "components/web_modal/web_contents_modal_dialog_host.h" |
31 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
32 #include "content/public/browser/navigation_details.h" | 32 #include "content/public/browser/navigation_details.h" |
33 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/notification_details.h" | |
35 #include "content/public/browser/notification_source.h" | |
36 #include "content/public/browser/plugin_service.h" | 34 #include "content/public/browser/plugin_service.h" |
37 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
38 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
37 #include "content/public/browser/render_process_host_observer.h" | |
39 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
41 #include "content/public/browser/web_contents_delegate.h" | 40 #include "content/public/browser/web_contents_delegate.h" |
41 #include "content/public/browser/web_contents_observer.h" | |
42 #include "content/public/browser/web_contents_view.h" | 42 #include "content/public/browser/web_contents_view.h" |
43 #include "content/public/common/webplugininfo.h" | 43 #include "content/public/common/webplugininfo.h" |
44 #include "ui/web_dialogs/web_dialog_delegate.h" | 44 #include "ui/web_dialogs/web_dialog_delegate.h" |
45 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" | 45 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
46 | 46 |
47 using content::NativeWebKeyboardEvent; | 47 using content::NativeWebKeyboardEvent; |
48 using content::NavigationController; | 48 using content::NavigationController; |
49 using content::RenderProcessHost; | |
49 using content::WebContents; | 50 using content::WebContents; |
50 using content::WebUIMessageHandler; | 51 using content::WebUIMessageHandler; |
51 using ui::WebDialogDelegate; | 52 using ui::WebDialogDelegate; |
52 using ui::WebDialogWebContentsDelegate; | 53 using ui::WebDialogWebContentsDelegate; |
53 | 54 |
54 namespace { | 55 namespace { |
55 | 56 |
56 void EnableInternalPDFPluginForContents(WebContents* preview_dialog) { | 57 void EnableInternalPDFPluginForContents(WebContents* preview_dialog) { |
57 // Always enable the internal PDF plugin for the print preview page. | 58 // Always enable the internal PDF plugin for the print preview page. |
58 base::FilePath pdf_plugin_path; | 59 base::FilePath pdf_plugin_path; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 if (!current_browser) | 203 if (!current_browser) |
203 return; | 204 return; |
204 current_browser->window()->HandleKeyboardEvent(event); | 205 current_browser->window()->HandleKeyboardEvent(event); |
205 #endif | 206 #endif |
206 } | 207 } |
207 | 208 |
208 } // namespace | 209 } // namespace |
209 | 210 |
210 namespace printing { | 211 namespace printing { |
211 | 212 |
213 struct PrintPreviewDialogController::Operation { | |
214 class Observer : public content::WebContentsObserver, | |
215 public content::RenderProcessHostObserver { | |
216 public: | |
217 Observer(); | |
218 virtual ~Observer(); | |
219 | |
220 void StartObserving(PrintPreviewDialogController* owner, | |
221 WebContents* web_contents); | |
222 void StopObserving(); | |
223 | |
224 private: | |
225 // content::WebContentsObserver | |
226 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; | |
227 virtual void NavigationEntryCommitted( | |
228 const content::LoadCommittedDetails& load_details) OVERRIDE; | |
229 // content::RenderProcessHostObserver | |
230 virtual void RenderProcessExited(RenderProcessHost* host, | |
231 base::ProcessHandle handle, | |
232 base::TerminationStatus status, | |
233 int exit_code) OVERRIDE; | |
234 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) OVERRIDE; | |
235 | |
236 PrintPreviewDialogController* owner_; | |
237 RenderProcessHost* host_; | |
238 }; | |
239 | |
240 Operation(); | |
241 | |
242 WebContents* preview_dialog; | |
243 WebContents* initiator; | |
244 Observer preview_dialog_observer; | |
245 Observer initiator_observer; | |
246 | |
247 DISALLOW_COPY_AND_ASSIGN(Operation); | |
248 }; | |
249 | |
250 PrintPreviewDialogController::Operation::Operation() : preview_dialog(NULL), | |
251 initiator(NULL) { | |
252 } | |
253 | |
254 PrintPreviewDialogController::Operation::Observer::Observer() : owner_(NULL), | |
255 host_(NULL) { | |
256 } | |
257 | |
258 PrintPreviewDialogController::Operation::Observer::~Observer() { | |
259 StopObserving(); | |
260 } | |
261 | |
262 void PrintPreviewDialogController::Operation::Observer::StartObserving( | |
263 PrintPreviewDialogController* owner, | |
264 WebContents* web_contents) { | |
265 owner_ = owner; | |
266 Observe(web_contents); | |
267 host_ = web_contents->GetRenderProcessHost(); | |
268 host_->AddObserver(this); | |
269 } | |
270 | |
271 void PrintPreviewDialogController::Operation::Observer::StopObserving() { | |
272 Observe(NULL); | |
273 if (host_) { | |
274 host_->RemoveObserver(this); | |
275 host_ = NULL; | |
276 } | |
277 } | |
278 | |
279 void PrintPreviewDialogController::Operation::Observer::WebContentsDestroyed( | |
280 WebContents* web_contents) { | |
281 owner_->OnWebContentsDestroyed(web_contents); | |
282 } | |
283 | |
284 void | |
285 PrintPreviewDialogController::Operation::Observer::NavigationEntryCommitted( | |
286 const content::LoadCommittedDetails& load_details) { | |
287 owner_->OnNavigationEntryCommitted(web_contents(), &load_details); | |
288 } | |
289 | |
290 void PrintPreviewDialogController::Operation::Observer::RenderProcessExited( | |
291 RenderProcessHost* host, | |
292 base::ProcessHandle handle, | |
293 base::TerminationStatus status, | |
294 int exit_code) { | |
295 owner_->OnRenderProcessExited(host); | |
296 } | |
297 | |
298 void | |
299 PrintPreviewDialogController::Operation::Observer::RenderProcessHostDestroyed( | |
300 RenderProcessHost* host) { | |
301 host_ = NULL; | |
302 } | |
303 | |
212 PrintPreviewDialogController::PrintPreviewDialogController() | 304 PrintPreviewDialogController::PrintPreviewDialogController() |
213 : waiting_for_new_preview_page_(false), | 305 : waiting_for_new_preview_page_(false), |
214 is_creating_print_preview_dialog_(false) { | 306 is_creating_print_preview_dialog_(false) { |
215 } | 307 } |
216 | 308 |
217 // static | 309 // static |
218 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { | 310 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { |
219 if (!g_browser_process) | 311 if (!g_browser_process) |
220 return NULL; | 312 return NULL; |
221 return g_browser_process->print_preview_dialog_controller(); | 313 return g_browser_process->print_preview_dialog_controller(); |
(...skipping 20 matching lines...) Expand all Loading... | |
242 if (!preview_dialog) | 334 if (!preview_dialog) |
243 return CreatePrintPreviewDialog(initiator); | 335 return CreatePrintPreviewDialog(initiator); |
244 | 336 |
245 // Show the initiator holding the existing preview dialog. | 337 // Show the initiator holding the existing preview dialog. |
246 initiator->GetDelegate()->ActivateContents(initiator); | 338 initiator->GetDelegate()->ActivateContents(initiator); |
247 return preview_dialog; | 339 return preview_dialog; |
248 } | 340 } |
249 | 341 |
250 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( | 342 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( |
251 WebContents* contents) const { | 343 WebContents* contents) const { |
252 // |preview_dialog_map_| is keyed by the preview dialog, so if find() | 344 for (size_t i = 0; i < preview_operations_.size(); ++i) { |
253 // succeeds, then |contents| is the preview dialog. | 345 Operation* operation = preview_operations_[i]; |
254 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); | 346 if (operation->preview_dialog == contents || |
255 if (it != preview_dialog_map_.end()) | 347 operation->initiator == contents) { |
256 return contents; | 348 return operation->preview_dialog; |
257 | |
258 for (it = preview_dialog_map_.begin(); | |
259 it != preview_dialog_map_.end(); | |
260 ++it) { | |
261 // If |contents| is an initiator. | |
262 if (contents == it->second) { | |
263 // Return the associated preview dialog. | |
264 return it->first; | |
265 } | 349 } |
266 } | 350 } |
267 return NULL; | 351 return NULL; |
268 } | 352 } |
269 | 353 |
270 WebContents* PrintPreviewDialogController::GetInitiator( | 354 WebContents* PrintPreviewDialogController::GetInitiator( |
271 WebContents* preview_dialog) { | 355 WebContents* preview_dialog) { |
272 PrintPreviewDialogMap::iterator it = preview_dialog_map_.find(preview_dialog); | 356 for (size_t i = 0; i < preview_operations_.size(); ++i) { |
273 return (it != preview_dialog_map_.end()) ? it->second : NULL; | 357 Operation* operation = preview_operations_[i]; |
274 } | 358 if (operation->preview_dialog == preview_dialog) |
275 | 359 return operation->initiator; |
276 void PrintPreviewDialogController::Observe( | |
277 int type, | |
278 const content::NotificationSource& source, | |
279 const content::NotificationDetails& details) { | |
280 if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { | |
281 OnRendererProcessClosed( | |
282 content::Source<content::RenderProcessHost>(source).ptr()); | |
283 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | |
284 OnWebContentsDestroyed(content::Source<WebContents>(source).ptr()); | |
285 } else { | |
286 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | |
287 WebContents* contents = | |
288 content::Source<NavigationController>(source)->GetWebContents(); | |
289 OnNavEntryCommitted( | |
290 contents, | |
291 content::Details<content::LoadCommittedDetails>(details).ptr()); | |
292 } | 360 } |
361 return NULL; | |
293 } | 362 } |
294 | 363 |
295 // static | 364 // static |
296 bool PrintPreviewDialogController::IsPrintPreviewDialog(WebContents* contents) { | 365 bool PrintPreviewDialogController::IsPrintPreviewDialog(WebContents* contents) { |
297 return IsPrintPreviewURL(contents->GetURL()); | 366 return IsPrintPreviewURL(contents->GetURL()); |
298 } | 367 } |
299 | 368 |
300 // static | 369 // static |
301 bool PrintPreviewDialogController::IsPrintPreviewURL(const GURL& url) { | 370 bool PrintPreviewDialogController::IsPrintPreviewURL(const GURL& url) { |
302 return (url.SchemeIs(chrome::kChromeUIScheme) && | 371 return (url.SchemeIs(chrome::kChromeUIScheme) && |
303 url.host() == chrome::kChromeUIPrintHost); | 372 url.host() == chrome::kChromeUIPrintHost); |
304 } | 373 } |
305 | 374 |
306 void PrintPreviewDialogController::EraseInitiatorInfo( | 375 void PrintPreviewDialogController::EraseInitiatorInfo( |
307 WebContents* preview_dialog) { | 376 WebContents* preview_dialog) { |
308 PrintPreviewDialogMap::iterator it = preview_dialog_map_.find(preview_dialog); | 377 for (size_t i = 0; i < preview_operations_.size(); ++i) { |
309 if (it == preview_dialog_map_.end()) | 378 Operation* operation = preview_operations_[i]; |
310 return; | 379 if (operation->preview_dialog == preview_dialog) { |
311 | 380 operation->initiator_observer.StopObserving(); |
312 RemoveObservers(it->second); | 381 operation->initiator = NULL; |
313 preview_dialog_map_[preview_dialog] = NULL; | 382 return; |
383 } | |
384 } | |
314 } | 385 } |
315 | 386 |
316 PrintPreviewDialogController::~PrintPreviewDialogController() {} | 387 PrintPreviewDialogController::~PrintPreviewDialogController() { |
388 DCHECK_EQ(0U, preview_operations_.size()); | |
389 // Paranoia. | |
390 STLDeleteElements(&preview_operations_); | |
Lei Zhang
2014/01/06 20:29:22
Isn't this handling a DCHECK failure, which is som
Avi (use Gerrit)
2014/01/06 21:34:05
True. Removed.
| |
391 } | |
317 | 392 |
318 void PrintPreviewDialogController::OnRendererProcessClosed( | 393 void PrintPreviewDialogController::OnRenderProcessExited( |
319 content::RenderProcessHost* rph) { | 394 RenderProcessHost* rph) { |
320 // Store contents in a vector and deal with them after iterating through | 395 // Store contents in a vector and deal with them after iterating through |
321 // |preview_dialog_map_| because RemoveFoo() can change |preview_dialog_map_|. | 396 // |preview_operations_| because RemoveFoo() can change |preview_operations_|. |
322 std::vector<WebContents*> closed_initiators; | 397 std::vector<WebContents*> closed_initiators; |
323 std::vector<WebContents*> closed_preview_dialogs; | 398 std::vector<WebContents*> closed_preview_dialogs; |
324 for (PrintPreviewDialogMap::iterator iter = preview_dialog_map_.begin(); | 399 for (size_t i = 0; i < preview_operations_.size(); ++i) { |
325 iter != preview_dialog_map_.end(); ++iter) { | 400 Operation* operation = preview_operations_[i]; |
326 WebContents* preview_dialog = iter->first; | 401 WebContents* preview_dialog = operation->preview_dialog; |
327 WebContents* initiator = iter->second; | 402 WebContents* initiator = operation->initiator; |
328 if (preview_dialog->GetRenderProcessHost() == rph) { | 403 if (preview_dialog->GetRenderProcessHost() == rph) { |
329 closed_preview_dialogs.push_back(preview_dialog); | 404 closed_preview_dialogs.push_back(preview_dialog); |
330 } else if (initiator && | 405 } else if (initiator && |
331 initiator->GetRenderProcessHost() == rph) { | 406 initiator->GetRenderProcessHost() == rph) { |
332 closed_initiators.push_back(initiator); | 407 closed_initiators.push_back(initiator); |
333 } | 408 } |
334 } | 409 } |
335 | 410 |
336 for (size_t i = 0; i < closed_preview_dialogs.size(); ++i) { | 411 for (size_t i = 0; i < closed_preview_dialogs.size(); ++i) { |
337 RemovePreviewDialog(closed_preview_dialogs[i]); | 412 RemovePreviewDialog(closed_preview_dialogs[i]); |
(...skipping 14 matching lines...) Expand all Loading... | |
352 NOTREACHED(); | 427 NOTREACHED(); |
353 return; | 428 return; |
354 } | 429 } |
355 | 430 |
356 if (contents == preview_dialog) | 431 if (contents == preview_dialog) |
357 RemovePreviewDialog(contents); | 432 RemovePreviewDialog(contents); |
358 else | 433 else |
359 RemoveInitiator(contents); | 434 RemoveInitiator(contents); |
360 } | 435 } |
361 | 436 |
362 void PrintPreviewDialogController::OnNavEntryCommitted( | 437 void PrintPreviewDialogController::OnNavigationEntryCommitted( |
363 WebContents* contents, content::LoadCommittedDetails* details) { | 438 WebContents* contents, const content::LoadCommittedDetails* details) { |
364 WebContents* preview_dialog = GetPrintPreviewForContents(contents); | 439 WebContents* preview_dialog = GetPrintPreviewForContents(contents); |
365 if (!preview_dialog) { | 440 if (!preview_dialog) { |
366 NOTREACHED(); | 441 NOTREACHED(); |
367 return; | 442 return; |
368 } | 443 } |
369 | 444 |
370 if (contents == preview_dialog) { | 445 if (contents == preview_dialog) { |
371 // Preview dialog navigated. | 446 // Preview dialog navigated. |
372 if (details) { | 447 if (details) { |
373 content::PageTransition transition_type = | 448 content::PageTransition transition_type = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 new PrintPreviewWebContentDelegate(profile, initiator); | 488 new PrintPreviewWebContentDelegate(profile, initiator); |
414 ConstrainedWebDialogDelegate* constrained_delegate = | 489 ConstrainedWebDialogDelegate* constrained_delegate = |
415 CreateConstrainedWebDialog(profile, | 490 CreateConstrainedWebDialog(profile, |
416 web_dialog_delegate, | 491 web_dialog_delegate, |
417 pp_wcd, | 492 pp_wcd, |
418 initiator); | 493 initiator); |
419 WebContents* preview_dialog = constrained_delegate->GetWebContents(); | 494 WebContents* preview_dialog = constrained_delegate->GetWebContents(); |
420 EnableInternalPDFPluginForContents(preview_dialog); | 495 EnableInternalPDFPluginForContents(preview_dialog); |
421 PrintViewManager::CreateForWebContents(preview_dialog); | 496 PrintViewManager::CreateForWebContents(preview_dialog); |
422 | 497 |
423 // Add an entry to the map. | |
424 preview_dialog_map_[preview_dialog] = initiator; | |
425 waiting_for_new_preview_page_ = true; | 498 waiting_for_new_preview_page_ = true; |
426 | 499 |
427 AddObservers(initiator); | 500 // Add an entry to the map. |
428 AddObservers(preview_dialog); | 501 Operation* operation = new Operation; |
502 operation->preview_dialog = preview_dialog; | |
503 operation->initiator = initiator; | |
504 operation->preview_dialog_observer.StartObserving(this, preview_dialog); | |
505 operation->initiator_observer.StartObserving(this, initiator); | |
506 preview_operations_.push_back(operation); | |
429 | 507 |
430 return preview_dialog; | 508 return preview_dialog; |
431 } | 509 } |
432 | 510 |
433 void PrintPreviewDialogController::SaveInitiatorTitle( | 511 void PrintPreviewDialogController::SaveInitiatorTitle( |
434 WebContents* preview_dialog) { | 512 WebContents* preview_dialog) { |
435 WebContents* initiator = GetInitiator(preview_dialog); | 513 WebContents* initiator = GetInitiator(preview_dialog); |
436 if (initiator && preview_dialog->GetWebUI()) { | 514 if (initiator && preview_dialog->GetWebUI()) { |
437 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 515 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
438 preview_dialog->GetWebUI()->GetController()); | 516 preview_dialog->GetWebUI()->GetController()); |
439 print_preview_ui->SetInitiatorTitle( | 517 print_preview_ui->SetInitiatorTitle( |
440 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); | 518 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); |
441 } | 519 } |
442 } | 520 } |
443 | 521 |
444 void PrintPreviewDialogController::AddObservers(WebContents* contents) { | |
445 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
446 content::Source<WebContents>(contents)); | |
447 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
448 content::Source<NavigationController>(&contents->GetController())); | |
449 | |
450 // Multiple sites may share the same RenderProcessHost, so check if this | |
451 // notification has already been added. | |
452 content::Source<content::RenderProcessHost> rph_source( | |
453 contents->GetRenderProcessHost()); | |
454 if (!registrar_.IsRegistered(this, | |
455 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { | |
456 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
457 rph_source); | |
458 } | |
459 } | |
460 | |
461 void PrintPreviewDialogController::RemoveObservers(WebContents* contents) { | |
462 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
463 content::Source<WebContents>(contents)); | |
464 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
465 content::Source<NavigationController>(&contents->GetController())); | |
466 | |
467 // Multiple sites may share the same RenderProcessHost, so check if this | |
468 // notification has already been added. | |
469 content::Source<content::RenderProcessHost> rph_source( | |
470 contents->GetRenderProcessHost()); | |
471 if (registrar_.IsRegistered(this, | |
472 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { | |
473 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
474 rph_source); | |
475 } | |
476 } | |
477 | |
478 void PrintPreviewDialogController::RemoveInitiator( | 522 void PrintPreviewDialogController::RemoveInitiator( |
479 WebContents* initiator) { | 523 WebContents* initiator) { |
480 WebContents* preview_dialog = GetPrintPreviewForContents(initiator); | 524 WebContents* preview_dialog = GetPrintPreviewForContents(initiator); |
481 DCHECK(preview_dialog); | 525 DCHECK(preview_dialog); |
526 | |
482 // Update the map entry first, so when the print preview dialog gets destroyed | 527 // Update the map entry first, so when the print preview dialog gets destroyed |
483 // and reaches RemovePreviewDialog(), it does not attempt to also remove the | 528 // and reaches RemovePreviewDialog(), it does not attempt to also remove the |
484 // initiator's observers. | 529 // initiator's observers. |
485 preview_dialog_map_[preview_dialog] = NULL; | 530 EraseInitiatorInfo(preview_dialog); |
486 RemoveObservers(initiator); | |
487 | 531 |
488 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); | 532 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
489 | 533 |
490 // initiator is closed. Close the print preview dialog too. | 534 // initiator is closed. Close the print preview dialog too. |
491 PrintPreviewUI* print_preview_ui = | 535 PrintPreviewUI* print_preview_ui = |
492 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); | 536 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); |
493 if (print_preview_ui) | 537 if (print_preview_ui) |
494 print_preview_ui->OnInitiatorClosed(); | 538 print_preview_ui->OnInitiatorClosed(); |
495 } | 539 } |
496 | 540 |
497 void PrintPreviewDialogController::RemovePreviewDialog( | 541 void PrintPreviewDialogController::RemovePreviewDialog( |
498 WebContents* preview_dialog) { | 542 WebContents* preview_dialog) { |
499 // Remove the initiator's observers before erasing the mapping. | 543 for (size_t i = 0; i < preview_operations_.size(); ++i) { |
500 WebContents* initiator = GetInitiator(preview_dialog); | 544 Operation* operation = preview_operations_[i]; |
501 if (initiator) { | 545 if (operation->preview_dialog == preview_dialog) { |
502 RemoveObservers(initiator); | 546 // Remove the initiator's observers before erasing the mapping. |
503 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); | 547 if (operation->initiator) { |
548 operation->initiator_observer.StopObserving(); | |
549 PrintViewManager::FromWebContents(operation->initiator)-> | |
550 PrintPreviewDone(); | |
551 } | |
552 | |
553 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to | |
554 // abort the initiator preview request. | |
555 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | |
556 preview_dialog->GetWebUI()->GetController()); | |
557 if (print_preview_ui) | |
558 print_preview_ui->OnPrintPreviewDialogDestroyed(); | |
559 | |
560 preview_operations_.erase(preview_operations_.begin() + i); | |
561 delete operation; | |
562 | |
563 return; | |
564 } | |
504 } | 565 } |
505 | 566 NOTREACHED(); |
506 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort | |
507 // the initiator preview request. | |
508 PrintPreviewUI* print_preview_ui = | |
509 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); | |
510 if (print_preview_ui) | |
511 print_preview_ui->OnPrintPreviewDialogDestroyed(); | |
512 | |
513 preview_dialog_map_.erase(preview_dialog); | |
514 RemoveObservers(preview_dialog); | |
515 } | 567 } |
516 | 568 |
517 } // namespace printing | 569 } // namespace printing |
OLD | NEW |