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

Side by Side Diff: chrome/browser/tab_contents/test_tab_contents.cc

Issue 6537015: Start moving core pieces of Chrome multi-process code to src\content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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
« no previous file with comments | « chrome/browser/tab_contents/test_tab_contents.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/tab_contents/test_tab_contents.h"
6
7 #include <utility>
8
9 #include "chrome/browser/browser_url_handler.h"
10 #include "chrome/browser/renderer_host/mock_render_process_host.h"
11 #include "chrome/browser/renderer_host/render_view_host.h"
12 #include "chrome/browser/renderer_host/site_instance.h"
13 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
14 #include "chrome/browser/tab_contents/infobar_delegate.h"
15 #include "chrome/common/notification_details.h"
16 #include "chrome/common/notification_source.h"
17 #include "chrome/common/page_transition_types.h"
18
19 TestTabContents::TestTabContents(Profile* profile, SiteInstance* instance)
20 : TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL),
21 transition_cross_site(false) {
22 // Listen for infobar events so we can call InfoBarClosed() on the infobar
23 // delegates and give them an opportunity to delete themselves. (Since we
24 // have no InfobarContainer in TestTabContents, InfoBarClosed() is not called
25 // most likely leading to the infobar delegates being leaked.)
26 Source<TabContents> source(this);
27 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
28 source);
29 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
30 source);
31 }
32
33 void TestTabContents::Observe(NotificationType type,
34 const NotificationSource& source,
35 const NotificationDetails& details) {
36 // TabContents does not handle TAB_CONTENTS_INFOBAR_* so we don't pass it
37 // these notifications.
38 switch (type.value) {
39 case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED:
40 Details<InfoBarDelegate>(details).ptr()->InfoBarClosed();
41 break;
42 case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED:
43 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr()->
44 first->InfoBarClosed();
45 break;
46 default:
47 TabContents::Observe(type, source, details);
48 break;
49 }
50 }
51
52 TestRenderViewHost* TestTabContents::pending_rvh() const {
53 return static_cast<TestRenderViewHost*>(
54 render_manager_.pending_render_view_host_);
55 }
56
57 bool TestTabContents::CreateRenderViewForRenderManager(
58 RenderViewHost* render_view_host) {
59 // This will go to a TestRenderViewHost.
60 render_view_host->CreateRenderView(string16());
61 return true;
62 }
63
64 TabContents* TestTabContents::Clone() {
65 TabContents* tc = new TestTabContents(
66 profile(), SiteInstance::CreateSiteInstance(profile()));
67 tc->controller().CopyStateFrom(controller_);
68 return tc;
69 }
70
71 void TestTabContents::NavigateAndCommit(const GURL& url) {
72 controller().LoadURL(url, GURL(), PageTransition::LINK);
73 GURL loaded_url(url);
74 bool reverse_on_redirect = false;
75 BrowserURLHandler::RewriteURLIfNecessary(
76 &loaded_url, profile(), &reverse_on_redirect);
77
78 // LoadURL created a navigation entry, now simulate the RenderView sending
79 // a notification that it actually navigated.
80 CommitPendingNavigation();
81 }
82
83 void TestTabContents::CommitPendingNavigation() {
84 // If we are doing a cross-site navigation, this simulates the current RVH
85 // notifying that it has unloaded so the pending RVH is resumed and can
86 // navigate.
87 ProceedWithCrossSiteNavigation();
88 TestRenderViewHost* rvh = pending_rvh();
89 if (!rvh)
90 rvh = static_cast<TestRenderViewHost*>(render_manager_.current_host());
91
92 const NavigationEntry* entry = controller().pending_entry();
93 DCHECK(entry);
94 int page_id = entry->page_id();
95 if (page_id == -1) {
96 // It's a new navigation, assign a never-seen page id to it.
97 page_id =
98 static_cast<MockRenderProcessHost*>(rvh->process())->max_page_id() + 1;
99 }
100 rvh->SendNavigate(page_id, entry->url());
101 }
102
103 void TestTabContents::ProceedWithCrossSiteNavigation() {
104 if (!pending_rvh())
105 return;
106 render_manager_.ShouldClosePage(true, true);
107 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/test_tab_contents.h ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698