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 min_size(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(), min_size.width()) - kBorder); | |
79 size_.set_height(std::max(rect.height(), min_size.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 } |
vandebo (ex-Chrome)
2011/10/14 07:14:05
nit: } else if
Lei Zhang
2011/10/14 20:31:27
Done.
| |
149 PrintPreviewUI* print_preview_ui = | 237 else if (initiator_tab && |
150 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | 238 initiator_tab->render_view_host()->process() == rph) { |
151 print_preview_ui->OnInitiatorTabCrashed(); | 239 closed_preview_tabs.push_back(initiator_tab); |
152 } | 240 } |
153 } | 241 } |
242 | |
243 for (size_t i = 0; i < closed_preview_tabs.size(); ++i) { | |
244 RemovePreviewTab(closed_preview_tabs[i]); | |
245 PrintPreviewUI* print_preview_ui = | |
246 static_cast<PrintPreviewUI*>(closed_preview_tabs[i]->web_ui()); | |
247 if (print_preview_ui) | |
248 print_preview_ui->OnPrintPreviewTabCrashed(); | |
249 } | |
250 | |
251 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) | |
252 RemoveInitiatorTab(closed_initiator_tabs[i]); | |
154 } | 253 } |
155 | 254 |
156 void PrintPreviewTabController::OnTabContentsDestroyed( | 255 void PrintPreviewTabController::OnTabContentsDestroyed( |
157 TabContentsWrapper* tab) { | 256 TabContentsWrapper* tab) { |
158 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); | 257 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); |
159 if (!preview_tab) | 258 if (!preview_tab) { |
259 NOTREACHED(); | |
160 return; | 260 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 } | 261 } |
189 | 262 |
190 ResetPreviewTabOverrideTitle(preview_tab); | 263 if (tab == preview_tab) |
191 RemoveObservers(tab); | 264 RemovePreviewTab(tab); |
265 else | |
266 RemoveInitiatorTab(tab); | |
192 } | 267 } |
193 | 268 |
194 void PrintPreviewTabController::OnNavEntryCommitted( | 269 void PrintPreviewTabController::OnNavEntryCommitted( |
195 TabContentsWrapper* tab, content::LoadCommittedDetails* details) { | 270 TabContentsWrapper* tab, content::LoadCommittedDetails* details) { |
196 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); | 271 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(tab); |
272 if (!preview_tab) { | |
273 NOTREACHED(); | |
274 return; | |
275 } | |
197 bool source_tab_is_preview_tab = (tab == preview_tab); | 276 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 | 277 |
202 // Don't update/erase the map entry if the page has not changed. | 278 if (source_tab_is_preview_tab) { |
203 if (transition_type == content::PAGE_TRANSITION_RELOAD || | 279 // Preview tab navigated. |
204 nav_type == NavigationType::SAME_PAGE) { | 280 if (details) { |
205 if (source_tab_is_preview_tab) | 281 content::PageTransition transition_type = |
282 details->entry->transition_type(); | |
283 NavigationType::Type nav_type = details->type; | |
284 | |
285 // New |preview_tab| is created. Don't update/erase map entry. | |
286 if (waiting_for_new_preview_page_ && | |
287 transition_type == content::PAGE_TRANSITION_START_PAGE && | |
288 nav_type == NavigationType::NEW_PAGE) { | |
289 waiting_for_new_preview_page_ = false; | |
206 SetInitiatorTabURLAndTitle(preview_tab); | 290 SetInitiatorTabURLAndTitle(preview_tab); |
207 return; | 291 |
292 // Disabling the delegate will prevent all future navigation. | |
293 tab->tab_contents()->set_delegate(NULL); | |
294 return; | |
295 } | |
208 } | 296 } |
209 | 297 NOTREACHED(); |
210 // New |preview_tab| is created. Don't update/erase map entry. | 298 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 } | 299 } |
227 | 300 |
228 RemoveObservers(tab); | 301 // Initiator tab navigated. |
229 ResetPreviewTabOverrideTitle(preview_tab); | 302 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 } | 303 } |
247 | 304 |
248 // static | 305 // static |
249 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { | 306 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { |
250 return IsPrintPreviewURL(tab->tab_contents()->GetURL()); | 307 return IsPrintPreviewURL(tab->tab_contents()->GetURL()); |
251 } | 308 } |
252 | 309 |
253 // static | 310 // static |
254 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { | 311 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { |
255 return (url.SchemeIs(chrome::kChromeUIScheme) && | 312 return (url.SchemeIs(chrome::kChromeUIScheme) && |
256 url.host() == chrome::kChromeUIPrintHost); | 313 url.host() == chrome::kChromeUIPrintHost); |
257 } | 314 } |
258 | 315 |
259 void PrintPreviewTabController::EraseInitiatorTabInfo( | 316 void PrintPreviewTabController::EraseInitiatorTabInfo( |
260 TabContentsWrapper* preview_tab) { | 317 TabContentsWrapper* preview_tab) { |
261 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | 318 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
262 if (it == preview_tab_map_.end()) | 319 if (it == preview_tab_map_.end()) |
263 return; | 320 return; |
264 | 321 |
265 RemoveObservers(it->second); | 322 RemoveObservers(it->second); |
266 preview_tab_map_[preview_tab] = NULL; | 323 preview_tab_map_[preview_tab] = NULL; |
267 ResetPreviewTabOverrideTitle(preview_tab); | |
268 } | 324 } |
269 | 325 |
270 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( | 326 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( |
271 TabContentsWrapper* preview_tab) { | 327 TabContentsWrapper* preview_tab) { |
272 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | 328 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
273 if (it != preview_tab_map_.end()) | 329 if (it != preview_tab_map_.end()) |
274 return preview_tab_map_[preview_tab]; | 330 return preview_tab_map_[preview_tab]; |
275 return NULL; | 331 return NULL; |
276 } | 332 } |
277 | 333 |
278 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( | 334 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( |
279 TabContentsWrapper* initiator_tab) { | 335 TabContentsWrapper* initiator_tab) { |
280 Browser* current_browser = BrowserList::FindBrowserWithID( | 336 Browser* current_browser = BrowserList::FindBrowserWithID( |
281 initiator_tab->restore_tab_helper()->window_id().id()); | 337 initiator_tab->restore_tab_helper()->window_id().id()); |
282 if (!current_browser) { | 338 if (!current_browser) { |
283 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { | 339 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { |
284 Profile* profile = Profile::FromBrowserContext( | 340 Profile* profile = Profile::FromBrowserContext( |
285 initiator_tab->tab_contents()->browser_context()); | 341 initiator_tab->tab_contents()->browser_context()); |
286 current_browser = Browser::CreateForType(Browser::TYPE_POPUP, profile); | 342 current_browser = Browser::CreateForType(Browser::TYPE_POPUP, profile); |
287 if (!current_browser) { | 343 if (!current_browser) { |
288 NOTREACHED() << "Failed to create popup browser window"; | 344 NOTREACHED() << "Failed to create popup browser window"; |
289 return NULL; | 345 return NULL; |
290 } | 346 } |
291 } else { | 347 } else { |
292 return NULL; | 348 return NULL; |
293 } | 349 } |
294 } | 350 } |
295 | 351 |
296 // Add a new tab next to initiator tab. | 352 HtmlDialogUIDelegate* delegate = new PrintPreviewTabDelegate(initiator_tab); |
297 browser::NavigateParams params(current_browser, | 353 ConstrainedHtmlUIDelegate* html_delegate = |
298 GURL(chrome::kChromeUIPrintURL), | 354 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(current_browser->profile(), |
299 content::PAGE_TRANSITION_LINK); | 355 delegate, |
300 params.disposition = NEW_FOREGROUND_TAB; | 356 initiator_tab); |
301 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) | 357 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); | 358 EnableInternalPDFPluginForTab(preview_tab); |
314 static_cast<RenderViewHostDelegate*>(preview_tab->tab_contents())->Activate(); | |
315 | 359 |
316 // Add an entry to the map. | 360 // Add an entry to the map. |
317 preview_tab_map_[preview_tab] = initiator_tab; | 361 preview_tab_map_[preview_tab] = initiator_tab; |
318 waiting_for_new_preview_page_ = true; | 362 waiting_for_new_preview_page_ = true; |
319 | 363 |
320 AddObservers(initiator_tab); | 364 AddObservers(initiator_tab); |
321 AddObservers(preview_tab); | 365 AddObservers(preview_tab); |
322 | 366 |
323 return preview_tab; | 367 return preview_tab; |
324 } | 368 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // notification has already been added. | 408 // notification has already been added. |
365 RenderProcessHost* rph = tab->render_view_host()->process(); | 409 RenderProcessHost* rph = tab->render_view_host()->process(); |
366 if (registrar_.IsRegistered(this, | 410 if (registrar_.IsRegistered(this, |
367 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 411 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
368 Source<RenderProcessHost>(rph))) { | 412 Source<RenderProcessHost>(rph))) { |
369 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 413 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
370 Source<RenderProcessHost>(rph)); | 414 Source<RenderProcessHost>(rph)); |
371 } | 415 } |
372 } | 416 } |
373 | 417 |
418 void PrintPreviewTabController::RemoveInitiatorTab( | |
419 TabContentsWrapper* initiator_tab) { | |
420 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); | |
421 // Update the map entry first, so when the print preview tab gets destroyed | |
422 // and reaches RemovePreviewTab(), it does not attempt to also remove the | |
423 // initiator tab's observers. | |
424 preview_tab_map_[preview_tab] = NULL; | |
425 RemoveObservers(initiator_tab); | |
426 | |
427 initiator_tab->print_view_manager()->PrintPreviewDone(); | |
428 | |
429 // Initiator tab is closed. Close the print preview tab too. | |
430 PrintPreviewUI* print_preview_ui = | |
431 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
432 if (print_preview_ui) | |
433 print_preview_ui->OnInitiatorTabClosed(); | |
434 } | |
435 | |
436 void PrintPreviewTabController::RemovePreviewTab( | |
437 TabContentsWrapper* preview_tab) { | |
438 // Remove the initiator tab's observers before erasing the mapping. | |
439 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | |
440 if (initiator_tab) { | |
441 initiator_tab->print_view_manager()->PrintPreviewDone(); | |
442 RemoveObservers(initiator_tab); | |
443 } | |
444 | |
445 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort | |
446 // the initiator tab preview request. | |
447 PrintPreviewUI* print_preview_ui = | |
448 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
449 if (print_preview_ui) | |
450 print_preview_ui->OnTabDestroyed(); | |
451 | |
452 preview_tab_map_.erase(preview_tab); | |
453 RemoveObservers(preview_tab); | |
454 } | |
455 | |
374 } // namespace printing | 456 } // namespace printing |
OLD | NEW |