OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tab_contents/render_view_host_manager.h" | 5 #include "chrome/browser/tab_contents/render_view_host_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/dom_ui/dom_ui.h" | 9 #include "chrome/browser/dom_ui/dom_ui.h" |
10 #include "chrome/browser/dom_ui/dom_ui_factory.h" | 10 #include "chrome/browser/dom_ui/dom_ui_factory.h" |
11 #include "chrome/browser/renderer_host/render_view_host.h" | 11 #include "chrome/browser/renderer_host/render_view_host.h" |
12 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 12 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host_factory.h" |
13 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 14 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
14 #include "chrome/browser/tab_contents/navigation_controller.h" | 15 #include "chrome/browser/tab_contents/navigation_controller.h" |
15 #include "chrome/browser/tab_contents/navigation_entry.h" | 16 #include "chrome/browser/tab_contents/navigation_entry.h" |
16 #include "chrome/browser/tab_contents/site_instance.h" | 17 #include "chrome/browser/tab_contents/site_instance.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
19 #include "chrome/common/notification_type.h" | 20 #include "chrome/common/notification_type.h" |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class WaitableEvent; | 23 class WaitableEvent; |
23 } | 24 } |
24 | 25 |
25 RenderViewHostManager::RenderViewHostManager( | 26 RenderViewHostManager::RenderViewHostManager( |
26 RenderViewHostFactory* render_view_factory, | |
27 RenderViewHostDelegate* render_view_delegate, | 27 RenderViewHostDelegate* render_view_delegate, |
28 Delegate* delegate) | 28 Delegate* delegate) |
29 : delegate_(delegate), | 29 : delegate_(delegate), |
30 cross_navigation_pending_(false), | 30 cross_navigation_pending_(false), |
31 render_view_factory_(render_view_factory), | |
32 render_view_delegate_(render_view_delegate), | 31 render_view_delegate_(render_view_delegate), |
33 render_view_host_(NULL), | 32 render_view_host_(NULL), |
34 pending_render_view_host_(NULL), | 33 pending_render_view_host_(NULL), |
35 interstitial_page_(NULL) { | 34 interstitial_page_(NULL) { |
36 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, | 35 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, |
37 NotificationService::AllSources()); | 36 NotificationService::AllSources()); |
38 } | 37 } |
39 | 38 |
40 RenderViewHostManager::~RenderViewHostManager() { | 39 RenderViewHostManager::~RenderViewHostManager() { |
41 // Shutdown should have been called which should have cleaned these up. | 40 // Shutdown should have been called which should have cleaned these up. |
42 DCHECK(!render_view_host_); | 41 DCHECK(!render_view_host_); |
43 DCHECK(!pending_render_view_host_); | 42 DCHECK(!pending_render_view_host_); |
44 } | 43 } |
45 | 44 |
46 void RenderViewHostManager::Init(Profile* profile, | 45 void RenderViewHostManager::Init(Profile* profile, |
47 SiteInstance* site_instance, | 46 SiteInstance* site_instance, |
48 int routing_id, | 47 int routing_id, |
49 base::WaitableEvent* modal_dialog_event) { | 48 base::WaitableEvent* modal_dialog_event) { |
50 // Create a RenderViewHost, once we have an instance. It is important to | 49 // Create a RenderViewHost, once we have an instance. It is important to |
51 // immediately give this SiteInstance to a RenderViewHost so that it is | 50 // immediately give this SiteInstance to a RenderViewHost so that it is |
52 // ref counted. | 51 // ref counted. |
53 if (!site_instance) | 52 if (!site_instance) |
54 site_instance = SiteInstance::CreateSiteInstance(profile); | 53 site_instance = SiteInstance::CreateSiteInstance(profile); |
55 render_view_host_ = CreateRenderViewHost( | 54 render_view_host_ = RenderViewHostFactory::Create( |
56 site_instance, routing_id, modal_dialog_event); | 55 site_instance, render_view_delegate_, routing_id, modal_dialog_event); |
57 } | 56 } |
58 | 57 |
59 void RenderViewHostManager::Shutdown() { | 58 void RenderViewHostManager::Shutdown() { |
60 if (pending_render_view_host_) | 59 if (pending_render_view_host_) |
61 CancelPending(); | 60 CancelPending(); |
62 | 61 |
63 // We should always have a main RenderViewHost. | 62 // We should always have a main RenderViewHost. |
64 RenderViewHost* render_view_host = render_view_host_; | 63 RenderViewHost* render_view_host = render_view_host_; |
65 render_view_host_ = NULL; | 64 render_view_host_ = NULL; |
66 render_view_host->Shutdown(); | 65 render_view_host->Shutdown(); |
(...skipping 325 matching lines...) Loading... |
392 bool RenderViewHostManager::CreatePendingRenderView(SiteInstance* instance) { | 391 bool RenderViewHostManager::CreatePendingRenderView(SiteInstance* instance) { |
393 NavigationEntry* curr_entry = | 392 NavigationEntry* curr_entry = |
394 delegate_->GetControllerForRenderManager()->GetLastCommittedEntry(); | 393 delegate_->GetControllerForRenderManager()->GetLastCommittedEntry(); |
395 if (curr_entry && curr_entry->tab_type() == TAB_CONTENTS_WEB) { | 394 if (curr_entry && curr_entry->tab_type() == TAB_CONTENTS_WEB) { |
396 DCHECK(!curr_entry->content_state().empty()); | 395 DCHECK(!curr_entry->content_state().empty()); |
397 | 396 |
398 // TODO(creis): Should send a message to the RenderView to let it know | 397 // TODO(creis): Should send a message to the RenderView to let it know |
399 // we're about to switch away, so that it sends an UpdateState message. | 398 // we're about to switch away, so that it sends an UpdateState message. |
400 } | 399 } |
401 | 400 |
402 pending_render_view_host_ = | 401 pending_render_view_host_ = RenderViewHostFactory::Create( |
403 CreateRenderViewHost(instance, MSG_ROUTING_NONE, NULL); | 402 instance, render_view_delegate_, MSG_ROUTING_NONE, NULL); |
404 | 403 |
405 bool success = delegate_->CreateRenderViewForRenderManager( | 404 bool success = delegate_->CreateRenderViewForRenderManager( |
406 pending_render_view_host_); | 405 pending_render_view_host_); |
407 if (success) { | 406 if (success) { |
408 // Don't show the view until we get a DidNavigate from it. | 407 // Don't show the view until we get a DidNavigate from it. |
409 pending_render_view_host_->view()->Hide(); | 408 pending_render_view_host_->view()->Hide(); |
410 } else { | 409 } else { |
411 CancelPending(); | 410 CancelPending(); |
412 } | 411 } |
413 return success; | 412 return success; |
414 } | 413 } |
415 | 414 |
416 RenderViewHost* RenderViewHostManager::CreateRenderViewHost( | |
417 SiteInstance* instance, | |
418 int routing_id, | |
419 base::WaitableEvent* modal_dialog_event) { | |
420 if (render_view_factory_) { | |
421 return render_view_factory_->CreateRenderViewHost( | |
422 instance, render_view_delegate_, routing_id, modal_dialog_event); | |
423 } else { | |
424 return new RenderViewHost(instance, render_view_delegate_, routing_id, | |
425 modal_dialog_event); | |
426 } | |
427 } | |
428 | |
429 void RenderViewHostManager::CommitPending() { | 415 void RenderViewHostManager::CommitPending() { |
430 // First commit the DOM UI, if any. | 416 // First commit the DOM UI, if any. |
431 dom_ui_.swap(pending_dom_ui_); | 417 dom_ui_.swap(pending_dom_ui_); |
432 pending_dom_ui_.reset(); | 418 pending_dom_ui_.reset(); |
433 | 419 |
434 // It's possible for the pending_render_view_host_ to be NULL when we aren't | 420 // It's possible for the pending_render_view_host_ to be NULL when we aren't |
435 // crossing process boundaries. If so, we just needed to handle the DOM UI | 421 // crossing process boundaries. If so, we just needed to handle the DOM UI |
436 // committing above and we're done. | 422 // committing above and we're done. |
437 if (!pending_render_view_host_) | 423 if (!pending_render_view_host_) |
438 return; | 424 return; |
(...skipping 133 matching lines...) Loading... |
572 | 558 |
573 pending_dom_ui_.reset(); | 559 pending_dom_ui_.reset(); |
574 } | 560 } |
575 | 561 |
576 void RenderViewHostManager::CrossSiteNavigationCanceled() { | 562 void RenderViewHostManager::CrossSiteNavigationCanceled() { |
577 DCHECK(cross_navigation_pending_); | 563 DCHECK(cross_navigation_pending_); |
578 cross_navigation_pending_ = false; | 564 cross_navigation_pending_ = false; |
579 if (pending_render_view_host_) | 565 if (pending_render_view_host_) |
580 CancelPending(); | 566 CancelPending(); |
581 } | 567 } |
OLD | NEW |