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

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller.cc

Issue 8520011: Print Preview: Make print preview tab modal. (try 2) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: disable tests in touch_ui, fix failing test Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
8 #include <memory>
9 #include <string>
7 #include <vector> 10 #include <vector>
8 11
12 #include "base/auto_reset.h"
9 #include "base/command_line.h" 13 #include "base/command_line.h"
10 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_plugin_service_filter.h" 16 #include "chrome/browser/chrome_plugin_service_filter.h"
13 #include "chrome/browser/printing/print_view_manager.h" 17 #include "chrome/browser/printing/print_view_manager.h"
14 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/restore_tab_helper.h" 19 #include "chrome/browser/sessions/restore_tab_helper.h"
16 #include "chrome/browser/tabs/tab_strip_model.h" 20 #include "chrome/browser/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/browser_navigator.h" 23 #include "chrome/browser/ui/browser_navigator.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "chrome/browser/ui/webui/constrained_html_ui.h"
26 #include "chrome/browser/ui/webui/html_dialog_ui.h"
21 #include "chrome/browser/ui/webui/print_preview_ui.h" 27 #include "chrome/browser/ui/webui/print_preview_ui.h"
22 #include "chrome/common/chrome_content_client.h" 28 #include "chrome/common/chrome_content_client.h"
23 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
25 #include "content/browser/renderer_host/render_view_host.h" 31 #include "content/browser/renderer_host/render_view_host.h"
26 #include "content/browser/tab_contents/navigation_details.h" 32 #include "content/browser/tab_contents/navigation_details.h"
27 #include "content/browser/tab_contents/tab_contents.h" 33 #include "content/browser/tab_contents/tab_contents.h"
28 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
29 #include "content/public/browser/notification_source.h" 35 #include "content/public/browser/notification_source.h"
30 #include "content/public/browser/notification_types.h" 36 #include "content/public/browser/notification_types.h"
31 #include "webkit/plugins/webplugininfo.h" 37 #include "webkit/plugins/webplugininfo.h"
32 38
33 namespace { 39 namespace {
34 40
35 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { 41 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) {
36 // Always enable the internal PDF plugin for the print preview page. 42 // Always enable the internal PDF plugin for the print preview page.
37 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( 43 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab(
38 preview_tab->render_view_host()->process()->id(), 44 preview_tab->render_view_host()->process()->id(),
39 preview_tab->render_view_host()->routing_id(), 45 preview_tab->render_view_host()->routing_id(),
40 GURL(), 46 GURL(),
41 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); 47 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
42 } 48 }
43 49
44 void ResetPreviewTabOverrideTitle(TabContentsWrapper* preview_tab) { 50 class PrintPreviewTabDelegate : public HtmlDialogUIDelegate {
45 preview_tab->print_view_manager()->ResetTitleOverride(); 51 public:
52 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab);
53 virtual ~PrintPreviewTabDelegate();
54
55 virtual bool IsDialogModal() const OVERRIDE;
56 virtual string16 GetDialogTitle() const OVERRIDE;
57 virtual GURL GetDialogContentURL() const OVERRIDE;
58 virtual void GetWebUIMessageHandlers(
59 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
60 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
61 virtual std::string GetDialogArgs() const OVERRIDE;
62 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
63 virtual void OnCloseContents(TabContents* source,
64 bool* out_close_dialog) OVERRIDE;
65 virtual bool ShouldShowDialogTitle() const OVERRIDE;
66
67 private:
68 gfx::Size size_;
69
70 DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabDelegate);
71 };
72
73 PrintPreviewTabDelegate::PrintPreviewTabDelegate(
74 TabContentsWrapper* initiator_tab) {
75 const gfx::Size kMinDialogSize(800, 480);
76 const int kBorder = 50;
77 gfx::Rect rect;
78 initiator_tab->tab_contents()->GetContainerBounds(&rect);
79 size_.set_width(std::max(rect.width(), kMinDialogSize.width()) - kBorder);
80 size_.set_height(std::max(rect.height(), kMinDialogSize.height()) - kBorder);
81 }
82
83 PrintPreviewTabDelegate::~PrintPreviewTabDelegate() {
84 }
85
86 bool PrintPreviewTabDelegate::IsDialogModal() const {
87 // Not used, returning dummy value.
88 NOTREACHED();
89 return true;
90 }
91
92 string16 PrintPreviewTabDelegate::GetDialogTitle() const {
93 // Only used on Windows? UI folks prefer no title.
94 return string16();
95 }
96
97 GURL PrintPreviewTabDelegate::GetDialogContentURL() const {
98 return GURL(chrome::kChromeUIPrintURL);
99 }
100
101 void PrintPreviewTabDelegate::GetWebUIMessageHandlers(
102 std::vector<WebUIMessageHandler*>* /* handlers */) const {
103 // PrintPreviewUI adds its own message handlers.
104 }
105
106 void PrintPreviewTabDelegate::GetDialogSize(gfx::Size* size) const {
107 *size = size_;
108 }
109
110 std::string PrintPreviewTabDelegate::GetDialogArgs() const {
111 return std::string();
112 }
113
114 void PrintPreviewTabDelegate::OnDialogClosed(
115 const std::string& /* json_retval */) {
116 delete this;
117 }
118
119 void PrintPreviewTabDelegate::OnCloseContents(TabContents* /* source */,
120 bool* /* out_close_dialog */) {
121 // Not used, returning dummy value.
122 NOTREACHED();
123 }
124
125 bool PrintPreviewTabDelegate::ShouldShowDialogTitle() const {
126 // Not used, returning dummy value.
127 NOTREACHED();
128 return false;
46 } 129 }
47 130
48 } // namespace 131 } // namespace
49 132
50 namespace printing { 133 namespace printing {
51 134
52 PrintPreviewTabController::PrintPreviewTabController() 135 PrintPreviewTabController::PrintPreviewTabController()
53 : waiting_for_new_preview_page_(false) { 136 : waiting_for_new_preview_page_(false),
137 is_creating_print_preview_tab_(false) {
54 } 138 }
55 139
56 PrintPreviewTabController::~PrintPreviewTabController() {} 140 PrintPreviewTabController::~PrintPreviewTabController() {}
57 141
58 // static 142 // static
59 PrintPreviewTabController* PrintPreviewTabController::GetInstance() { 143 PrintPreviewTabController* PrintPreviewTabController::GetInstance() {
60 if (!g_browser_process) 144 if (!g_browser_process)
61 return NULL; 145 return NULL;
62 return g_browser_process->print_preview_tab_controller(); 146 return g_browser_process->print_preview_tab_controller();
63 } 147 }
(...skipping 11 matching lines...) Expand all
75 159
76 TabContentsWrapper* PrintPreviewTabController::GetOrCreatePreviewTab( 160 TabContentsWrapper* PrintPreviewTabController::GetOrCreatePreviewTab(
77 TabContentsWrapper* initiator_tab) { 161 TabContentsWrapper* initiator_tab) {
78 DCHECK(initiator_tab); 162 DCHECK(initiator_tab);
79 163
80 // Get the print preview tab for |initiator_tab|. 164 // Get the print preview tab for |initiator_tab|.
81 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); 165 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab);
82 if (!preview_tab) 166 if (!preview_tab)
83 return CreatePrintPreviewTab(initiator_tab); 167 return CreatePrintPreviewTab(initiator_tab);
84 168
85 // Show current preview tab. 169 // Show the initiator tab holding the existing preview tab.
86 static_cast<RenderViewHostDelegate*>(preview_tab->tab_contents())->Activate(); 170 static_cast<RenderViewHostDelegate*>(
171 initiator_tab->tab_contents())->Activate();
87 return preview_tab; 172 return preview_tab;
88 } 173 }
89 174
90 TabContentsWrapper* PrintPreviewTabController::GetPrintPreviewForTab( 175 TabContentsWrapper* PrintPreviewTabController::GetPrintPreviewForTab(
91 TabContentsWrapper* tab) const { 176 TabContentsWrapper* tab) const {
92 // |preview_tab_map_| is keyed by the preview tab, so if find() succeeds, then 177 // |preview_tab_map_| is keyed by the preview tab, so if find() succeeds, then
93 // |tab| is the preview tab. 178 // |tab| is the preview tab.
94 PrintPreviewTabMap::const_iterator it = preview_tab_map_.find(tab); 179 PrintPreviewTabMap::const_iterator it = preview_tab_map_.find(tab);
95 if (it != preview_tab_map_.end()) 180 if (it != preview_tab_map_.end())
96 return tab; 181 return tab;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 219 }
135 default: { 220 default: {
136 NOTREACHED(); 221 NOTREACHED();
137 break; 222 break;
138 } 223 }
139 } 224 }
140 } 225 }
141 226
142 void PrintPreviewTabController::OnRendererProcessClosed( 227 void PrintPreviewTabController::OnRendererProcessClosed(
143 RenderProcessHost* rph) { 228 RenderProcessHost* rph) {
229 // Store tabs in a vector and deal with them after iterating through
230 // |preview_tab_map_| because RemoveFooTab() can change |preview_tab_map_|.
231 std::vector<TabContentsWrapper*> closed_initiator_tabs;
232 std::vector<TabContentsWrapper*> closed_preview_tabs;
144 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin(); 233 for (PrintPreviewTabMap::iterator iter = preview_tab_map_.begin();
145 iter != preview_tab_map_.end(); ++iter) { 234 iter != preview_tab_map_.end(); ++iter) {
235 TabContentsWrapper* preview_tab = iter->first;
146 TabContentsWrapper* initiator_tab = iter->second; 236 TabContentsWrapper* initiator_tab = iter->second;
147 if (initiator_tab && 237 if (preview_tab->render_view_host()->process() == rph) {
148 initiator_tab->render_view_host()->process() == rph) { 238 closed_preview_tabs.push_back(preview_tab);
149 TabContentsWrapper* preview_tab = iter->first; 239 } else if (initiator_tab &&
150 PrintPreviewUI* print_preview_ui = 240 initiator_tab->render_view_host()->process() == rph) {
151 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); 241 closed_initiator_tabs.push_back(initiator_tab);
152 print_preview_ui->OnInitiatorTabCrashed();
153 } 242 }
154 } 243 }
244
245 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) {
246 RemovePreviewTab(closed_preview_tabs[i]);
247 PrintPreviewUI* print_preview_ui =
248 static_cast<PrintPreviewUI*>(closed_preview_tabs[i]->web_ui());
249 if (print_preview_ui)
250 print_preview_ui->OnPrintPreviewTabClosed();
251 }
252
253 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i)
254 RemoveInitiatorTab(closed_initiator_tabs[i]);
155 } 255 }
156 256
157 void PrintPreviewTabController::OnTabContentsDestroyed( 257 void PrintPreviewTabController::OnTabContentsDestroyed(
158 TabContentsWrapper* tab) { 258 TabContentsWrapper* tab) {
159 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); 259 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab);
160 if (!preview_tab) 260 if (!preview_tab) {
261 NOTREACHED();
161 return; 262 return;
162
163 if (tab == preview_tab) {
164 // Remove the initiator tab's observers before erasing the mapping.
165 TabContentsWrapper* initiator_tab = GetInitiatorTab(tab);
166 if (initiator_tab)
167 RemoveObservers(initiator_tab);
168
169 // Print preview tab contents are destroyed. Notify |PrintPreviewUI| to
170 // abort the initiator tab preview request.
171 if (IsPrintPreviewTab(tab) && tab->web_ui()) {
172 PrintPreviewUI* print_preview_ui =
173 static_cast<PrintPreviewUI*>(tab->web_ui());
174 print_preview_ui->OnTabDestroyed();
175 }
176
177 // Erase the map entry.
178 preview_tab_map_.erase(tab);
179 } else {
180 // Initiator tab is closed. Disable the controls in preview tab.
181 if (preview_tab->web_ui()) {
182 PrintPreviewUI* print_preview_ui =
183 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
184 print_preview_ui->OnInitiatorTabClosed();
185 }
186
187 // |tab| is an initiator tab, update the map entry and remove observers.
188 preview_tab_map_[preview_tab] = NULL;
189 } 263 }
190 264
191 ResetPreviewTabOverrideTitle(preview_tab); 265 if (tab == preview_tab)
192 RemoveObservers(tab); 266 RemovePreviewTab(tab);
267 else
268 RemoveInitiatorTab(tab);
193 } 269 }
194 270
195 void PrintPreviewTabController::OnNavEntryCommitted( 271 void PrintPreviewTabController::OnNavEntryCommitted(
196 TabContentsWrapper* tab, content::LoadCommittedDetails* details) { 272 TabContentsWrapper* tab, content::LoadCommittedDetails* details) {
197 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); 273 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab);
274 if (!preview_tab) {
275 NOTREACHED();
276 return;
277 }
198 bool source_tab_is_preview_tab = (tab == preview_tab); 278 bool source_tab_is_preview_tab = (tab == preview_tab);
199 if (details) {
200 content::PageTransition transition_type = details->entry->transition_type();
201 content::NavigationType nav_type = details->type;
202 279
203 // Don't update/erase the map entry if the page has not changed. 280 if (source_tab_is_preview_tab) {
204 if (transition_type == content::PAGE_TRANSITION_RELOAD || 281 // Preview tab navigated.
205 nav_type == content::NAVIGATION_TYPE_SAME_PAGE) { 282 if (details) {
206 if (source_tab_is_preview_tab) 283 content::PageTransition transition_type =
284 details->entry->transition_type();
285 content::NavigationType nav_type = details->type;
286
287 // New |preview_tab| is created. Don't update/erase map entry.
288 if (waiting_for_new_preview_page_ &&
289 transition_type == content::PAGE_TRANSITION_START_PAGE &&
290 nav_type == content::NAVIGATION_TYPE_NEW_PAGE) {
291 waiting_for_new_preview_page_ = false;
207 SetInitiatorTabURLAndTitle(preview_tab); 292 SetInitiatorTabURLAndTitle(preview_tab);
208 return; 293
294 // Disabling the delegate will prevent all future navigation.
295 tab->tab_contents()->set_delegate(NULL);
296 return;
297 }
298
299 // Cloud print sign-in causes a reload.
300 if (!waiting_for_new_preview_page_ &&
301 transition_type == content::PAGE_TRANSITION_RELOAD &&
302 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE &&
303 IsPrintPreviewURL(details->previous_url)) {
304 return;
305 }
209 } 306 }
210 307 NOTREACHED();
211 // New |preview_tab| is created. Don't update/erase map entry. 308 return;
212 if (waiting_for_new_preview_page_ &&
213 transition_type == content::PAGE_TRANSITION_LINK &&
214 nav_type == content::NAVIGATION_TYPE_NEW_PAGE &&
215 source_tab_is_preview_tab) {
216 waiting_for_new_preview_page_ = false;
217 SetInitiatorTabURLAndTitle(preview_tab);
218 return;
219 }
220
221 // User navigated to a preview tab using forward/back button.
222 if (source_tab_is_preview_tab &&
223 transition_type == content::PAGE_TRANSITION_FORWARD_BACK &&
224 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE) {
225 return;
226 }
227 } 309 }
228 310
229 RemoveObservers(tab); 311 // Initiator tab navigated.
230 ResetPreviewTabOverrideTitle(preview_tab); 312 RemoveInitiatorTab(tab);
231 if (source_tab_is_preview_tab) {
232 // Remove the initiator tab's observers before erasing the mapping.
233 TabContentsWrapper* initiator_tab = GetInitiatorTab(tab);
234 if (initiator_tab)
235 RemoveObservers(initiator_tab);
236 preview_tab_map_.erase(tab);
237 } else {
238 preview_tab_map_[preview_tab] = NULL;
239
240 // Initiator tab is closed. Disable the controls in preview tab.
241 if (preview_tab->web_ui()) {
242 PrintPreviewUI* print_preview_ui =
243 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
244 print_preview_ui->OnInitiatorTabClosed();
245 }
246 }
247 } 313 }
248 314
249 // static 315 // static
250 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { 316 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) {
251 return IsPrintPreviewURL(tab->tab_contents()->GetURL()); 317 return IsPrintPreviewURL(tab->tab_contents()->GetURL());
252 } 318 }
253 319
254 // static 320 // static
255 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { 321 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) {
256 return (url.SchemeIs(chrome::kChromeUIScheme) && 322 return (url.SchemeIs(chrome::kChromeUIScheme) &&
257 url.host() == chrome::kChromeUIPrintHost); 323 url.host() == chrome::kChromeUIPrintHost);
258 } 324 }
259 325
260 void PrintPreviewTabController::EraseInitiatorTabInfo( 326 void PrintPreviewTabController::EraseInitiatorTabInfo(
261 TabContentsWrapper* preview_tab) { 327 TabContentsWrapper* preview_tab) {
262 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); 328 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab);
263 if (it == preview_tab_map_.end()) 329 if (it == preview_tab_map_.end())
264 return; 330 return;
265 331
266 RemoveObservers(it->second); 332 RemoveObservers(it->second);
267 preview_tab_map_[preview_tab] = NULL; 333 preview_tab_map_[preview_tab] = NULL;
268 ResetPreviewTabOverrideTitle(preview_tab); 334 }
335
336 bool PrintPreviewTabController::is_creating_print_preview_tab() const {
337 return is_creating_print_preview_tab_;
269 } 338 }
270 339
271 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( 340 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab(
272 TabContentsWrapper* preview_tab) { 341 TabContentsWrapper* preview_tab) {
273 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); 342 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab);
274 if (it != preview_tab_map_.end()) 343 if (it != preview_tab_map_.end())
275 return preview_tab_map_[preview_tab]; 344 return preview_tab_map_[preview_tab];
276 return NULL; 345 return NULL;
277 } 346 }
278 347
279 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( 348 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab(
280 TabContentsWrapper* initiator_tab) { 349 TabContentsWrapper* initiator_tab) {
350 AutoReset<bool> auto_reset(&is_creating_print_preview_tab_, true);
281 Browser* current_browser = BrowserList::FindBrowserWithID( 351 Browser* current_browser = BrowserList::FindBrowserWithID(
282 initiator_tab->restore_tab_helper()->window_id().id()); 352 initiator_tab->restore_tab_helper()->window_id().id());
283 if (!current_browser) { 353 if (!current_browser) {
284 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { 354 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) {
285 Profile* profile = Profile::FromBrowserContext( 355 Profile* profile = Profile::FromBrowserContext(
286 initiator_tab->tab_contents()->browser_context()); 356 initiator_tab->tab_contents()->browser_context());
287 current_browser = Browser::CreateForType(Browser::TYPE_POPUP, profile); 357 current_browser = Browser::CreateForType(Browser::TYPE_POPUP, profile);
288 if (!current_browser) { 358 if (!current_browser) {
289 NOTREACHED() << "Failed to create popup browser window"; 359 NOTREACHED() << "Failed to create popup browser window";
290 return NULL; 360 return NULL;
291 } 361 }
292 } else { 362 } else {
293 return NULL; 363 return NULL;
294 } 364 }
295 } 365 }
296 366
297 // Add a new tab next to initiator tab. 367 HtmlDialogUIDelegate* delegate = new PrintPreviewTabDelegate(initiator_tab);
298 browser::NavigateParams params(current_browser, 368 ConstrainedHtmlUIDelegate* html_delegate =
299 GURL(chrome::kChromeUIPrintURL), 369 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(current_browser->profile(),
300 content::PAGE_TRANSITION_LINK); 370 delegate,
301 params.disposition = NEW_FOREGROUND_TAB; 371 initiator_tab);
302 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) 372 TabContentsWrapper* preview_tab = html_delegate->tab();
303 params.disposition = NEW_POPUP;
304
305 // For normal tabs, set the position as immediately to the right,
306 // otherwise let the tab strip decide.
307 if (current_browser->is_type_tabbed()) {
308 params.tabstrip_index = current_browser->tabstrip_model()->
309 GetIndexOfTabContents(initiator_tab) + 1;
310 }
311
312 browser::Navigate(&params);
313 TabContentsWrapper* preview_tab = params.target_contents;
314 EnableInternalPDFPluginForTab(preview_tab); 373 EnableInternalPDFPluginForTab(preview_tab);
315 static_cast<RenderViewHostDelegate*>(preview_tab->tab_contents())->Activate();
316 374
317 // Add an entry to the map. 375 // Add an entry to the map.
318 preview_tab_map_[preview_tab] = initiator_tab; 376 preview_tab_map_[preview_tab] = initiator_tab;
319 waiting_for_new_preview_page_ = true; 377 waiting_for_new_preview_page_ = true;
320 378
321 AddObservers(initiator_tab); 379 AddObservers(initiator_tab);
322 AddObservers(preview_tab); 380 AddObservers(preview_tab);
323 381
324 return preview_tab; 382 return preview_tab;
325 } 383 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // notification has already been added. 425 // notification has already been added.
368 RenderProcessHost* rph = tab->render_view_host()->process(); 426 RenderProcessHost* rph = tab->render_view_host()->process();
369 if (registrar_.IsRegistered(this, 427 if (registrar_.IsRegistered(this,
370 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 428 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
371 content::Source<RenderProcessHost>(rph))) { 429 content::Source<RenderProcessHost>(rph))) {
372 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 430 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
373 content::Source<RenderProcessHost>(rph)); 431 content::Source<RenderProcessHost>(rph));
374 } 432 }
375 } 433 }
376 434
435 void PrintPreviewTabController::RemoveInitiatorTab(
436 TabContentsWrapper* initiator_tab) {
437 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab);
438 DCHECK(preview_tab);
439 // Update the map entry first, so when the print preview tab gets destroyed
440 // and reaches RemovePreviewTab(), it does not attempt to also remove the
441 // initiator tab's observers.
442 preview_tab_map_[preview_tab] = NULL;
443 RemoveObservers(initiator_tab);
444
445 // Initiator tab is closed. Close the print preview tab too.
446 PrintPreviewUI* print_preview_ui =
447 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
448 if (print_preview_ui)
449 print_preview_ui->OnInitiatorTabClosed();
450 }
451
452 void PrintPreviewTabController::RemovePreviewTab(
453 TabContentsWrapper* preview_tab) {
454 // Remove the initiator tab's observers before erasing the mapping.
455 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab);
456 if (initiator_tab)
457 RemoveObservers(initiator_tab);
458
459 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort
460 // the initiator tab preview request.
461 PrintPreviewUI* print_preview_ui =
462 static_cast<PrintPreviewUI*>(preview_tab->web_ui());
463 if (print_preview_ui)
464 print_preview_ui->OnTabDestroyed();
465
466 preview_tab_map_.erase(preview_tab);
467 RemoveObservers(preview_tab);
468 }
469
377 } // namespace printing 470 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698