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