OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/test_tab_contents.h" | 5 #include "chrome/browser/tab_contents/test_tab_contents.h" |
6 | 6 |
7 #include "chrome/browser/browser_url_handler.h" | 7 #include "chrome/browser/browser_url_handler.h" |
8 #include "chrome/browser/renderer_host/mock_render_process_host.h" | 8 #include "chrome/browser/renderer_host/mock_render_process_host.h" |
9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
10 #include "chrome/browser/renderer_host/site_instance.h" | 10 #include "chrome/browser/renderer_host/site_instance.h" |
11 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 11 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
12 #include "chrome/browser/tab_contents/infobar_delegate.h" | 12 #include "chrome/browser/tab_contents/infobar_delegate.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 | 14 |
15 TestTabContents::TestTabContents(Profile* profile, SiteInstance* instance) | 15 TestTabContents::TestTabContents(Profile* profile, SiteInstance* instance) |
16 : TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL), | 16 : TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL), |
17 transition_cross_site(false) { | 17 transition_cross_site(false) { |
18 // Listen for infobar events so we can call InfoBarClosed() on the infobar | |
19 // delegates and give them an opportunity to delete themselves. (Since we | |
20 // have no InfobarContainer in TestTabContents, InfoBarClosed() is not called | |
21 // most likely leading to the infobar delegates being leaked.) | |
22 Source<TabContents> source(this); | |
23 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | |
24 source); | |
25 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, | |
26 source); | |
27 } | |
28 | |
29 void TestTabContents::Observe(NotificationType type, | |
30 const NotificationSource& source, | |
31 const NotificationDetails& details) { | |
32 // TabContents does not handle TAB_CONTENTS_INFOBAR_* so we don't pass it | |
33 // these notifications. | |
34 switch (type.value) { | |
35 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED: | |
36 Details<InfoBarDelegate>(details).ptr()->InfoBarClosed(); | |
37 break; | |
38 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED: | |
39 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr()-> | |
40 first->InfoBarClosed(); | |
41 break; | |
42 default: | |
43 TabContents::Observe(type, source, details); | |
44 break; | |
45 } | |
46 } | 18 } |
47 | 19 |
48 TestRenderViewHost* TestTabContents::pending_rvh() const { | 20 TestRenderViewHost* TestTabContents::pending_rvh() const { |
49 return static_cast<TestRenderViewHost*>( | 21 return static_cast<TestRenderViewHost*>( |
50 render_manager_.pending_render_view_host_); | 22 render_manager_.pending_render_view_host_); |
51 } | 23 } |
52 | 24 |
53 bool TestTabContents::CreateRenderViewForRenderManager( | 25 bool TestTabContents::CreateRenderViewForRenderManager( |
54 RenderViewHost* render_view_host) { | 26 RenderViewHost* render_view_host) { |
55 // This will go to a TestRenderViewHost. | 27 // This will go to a TestRenderViewHost. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 static_cast<MockRenderProcessHost*>(rvh->process())->max_page_id() + 1; | 66 static_cast<MockRenderProcessHost*>(rvh->process())->max_page_id() + 1; |
95 } | 67 } |
96 rvh->SendNavigate(page_id, entry->url()); | 68 rvh->SendNavigate(page_id, entry->url()); |
97 } | 69 } |
98 | 70 |
99 void TestTabContents::ProceedWithCrossSiteNavigation() { | 71 void TestTabContents::ProceedWithCrossSiteNavigation() { |
100 if (!pending_rvh()) | 72 if (!pending_rvh()) |
101 return; | 73 return; |
102 render_manager_.ShouldClosePage(true, true); | 74 render_manager_.ShouldClosePage(true, true); |
103 } | 75 } |
OLD | NEW |