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); | |
kmadhusu
2011/10/14 00:21:09
Define const int variables for all magic numbers.
Lei Zhang
2011/10/14 20:31:27
But this is the constant. I renamed |min_size| to
| |
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); | |
kmadhusu
2011/10/14 00:21:09
nit: remove 2 spaces.
Lei Zhang
2011/10/14 20:31:27
Done.
| |
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; | |
233 if (preview_tab->render_view_host()->process() == rph) { | |
234 closed_preview_tabs.push_back(preview_tab); | |
235 } | |
145 TabContentsWrapper* initiator_tab = iter->second; | 236 TabContentsWrapper* initiator_tab = iter->second; |
146 if (initiator_tab && | 237 if (initiator_tab && initiator_tab->render_view_host()->process() == rph) { |
147 initiator_tab->render_view_host()->process() == rph) { | 238 closed_preview_tabs.push_back(initiator_tab); |
kmadhusu
2011/10/14 00:21:09
closed_preview_tabs => closed_initiator_tabs
Lei Zhang
2011/10/14 20:31:27
Done.
| |
148 TabContentsWrapper* preview_tab = iter->first; | |
149 PrintPreviewUI* print_preview_ui = | |
150 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
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]); | |
kmadhusu
2011/10/14 00:21:09
(repeating our conversation): I am not sure whethe
Lei Zhang
2011/10/14 20:31:27
I changed the if on line 237 to an else if.
| |
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 } | |
208 } | 295 } |
209 | 296 NOTREACHED(); |
210 // New |preview_tab| is created. Don't update/erase map entry. | 297 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 } | 298 } |
227 | 299 |
228 RemoveObservers(tab); | 300 // Initiator tab navigated. |
229 ResetPreviewTabOverrideTitle(preview_tab); | 301 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 } | 302 } |
247 | 303 |
248 // static | 304 // static |
249 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { | 305 bool PrintPreviewTabController::IsPrintPreviewTab(TabContentsWrapper* tab) { |
250 return IsPrintPreviewURL(tab->tab_contents()->GetURL()); | 306 return IsPrintPreviewURL(tab->tab_contents()->GetURL()); |
251 } | 307 } |
252 | 308 |
253 // static | 309 // static |
254 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { | 310 bool PrintPreviewTabController::IsPrintPreviewURL(const GURL& url) { |
255 return (url.SchemeIs(chrome::kChromeUIScheme) && | 311 return (url.SchemeIs(chrome::kChromeUIScheme) && |
256 url.host() == chrome::kChromeUIPrintHost); | 312 url.host() == chrome::kChromeUIPrintHost); |
257 } | 313 } |
258 | 314 |
259 void PrintPreviewTabController::EraseInitiatorTabInfo( | 315 void PrintPreviewTabController::EraseInitiatorTabInfo( |
260 TabContentsWrapper* preview_tab) { | 316 TabContentsWrapper* preview_tab) { |
261 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | 317 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
262 if (it == preview_tab_map_.end()) | 318 if (it == preview_tab_map_.end()) |
263 return; | 319 return; |
264 | 320 |
265 RemoveObservers(it->second); | 321 RemoveObservers(it->second); |
266 preview_tab_map_[preview_tab] = NULL; | 322 preview_tab_map_[preview_tab] = NULL; |
267 ResetPreviewTabOverrideTitle(preview_tab); | |
268 } | 323 } |
269 | 324 |
270 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( | 325 TabContentsWrapper* PrintPreviewTabController::GetInitiatorTab( |
271 TabContentsWrapper* preview_tab) { | 326 TabContentsWrapper* preview_tab) { |
272 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); | 327 PrintPreviewTabMap::iterator it = preview_tab_map_.find(preview_tab); |
273 if (it != preview_tab_map_.end()) | 328 if (it != preview_tab_map_.end()) |
274 return preview_tab_map_[preview_tab]; | 329 return preview_tab_map_[preview_tab]; |
275 return NULL; | 330 return NULL; |
276 } | 331 } |
277 | 332 |
278 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( | 333 TabContentsWrapper* PrintPreviewTabController::CreatePrintPreviewTab( |
279 TabContentsWrapper* initiator_tab) { | 334 TabContentsWrapper* initiator_tab) { |
280 Browser* current_browser = BrowserList::FindBrowserWithID( | 335 Browser* current_browser = BrowserList::FindBrowserWithID( |
281 initiator_tab->restore_tab_helper()->window_id().id()); | 336 initiator_tab->restore_tab_helper()->window_id().id()); |
282 if (!current_browser) { | 337 if (!current_browser) { |
283 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { | 338 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { |
284 Profile* profile = Profile::FromBrowserContext( | 339 Profile* profile = Profile::FromBrowserContext( |
285 initiator_tab->tab_contents()->browser_context()); | 340 initiator_tab->tab_contents()->browser_context()); |
286 current_browser = Browser::CreateForType(Browser::TYPE_POPUP, profile); | 341 current_browser = Browser::CreateForType(Browser::TYPE_POPUP, profile); |
287 if (!current_browser) { | 342 if (!current_browser) { |
288 NOTREACHED() << "Failed to create popup browser window"; | 343 NOTREACHED() << "Failed to create popup browser window"; |
289 return NULL; | 344 return NULL; |
290 } | 345 } |
291 } else { | 346 } else { |
292 return NULL; | 347 return NULL; |
293 } | 348 } |
294 } | 349 } |
295 | 350 |
296 // Add a new tab next to initiator tab. | 351 HtmlDialogUIDelegate* delegate = new PrintPreviewTabDelegate(initiator_tab); |
297 browser::NavigateParams params(current_browser, | 352 ConstrainedHtmlUIDelegate* html_delegate = |
298 GURL(chrome::kChromeUIPrintURL), | 353 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(current_browser->profile(), |
299 content::PAGE_TRANSITION_LINK); | 354 delegate, |
300 params.disposition = NEW_FOREGROUND_TAB; | 355 initiator_tab); |
301 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) | 356 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); | 357 EnableInternalPDFPluginForTab(preview_tab); |
314 static_cast<RenderViewHostDelegate*>(preview_tab->tab_contents())->Activate(); | |
315 | 358 |
316 // Add an entry to the map. | 359 // Add an entry to the map. |
317 preview_tab_map_[preview_tab] = initiator_tab; | 360 preview_tab_map_[preview_tab] = initiator_tab; |
318 waiting_for_new_preview_page_ = true; | 361 waiting_for_new_preview_page_ = true; |
319 | 362 |
320 AddObservers(initiator_tab); | 363 AddObservers(initiator_tab); |
321 AddObservers(preview_tab); | 364 AddObservers(preview_tab); |
322 | 365 |
323 return preview_tab; | 366 return preview_tab; |
324 } | 367 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // notification has already been added. | 407 // notification has already been added. |
365 RenderProcessHost* rph = tab->render_view_host()->process(); | 408 RenderProcessHost* rph = tab->render_view_host()->process(); |
366 if (registrar_.IsRegistered(this, | 409 if (registrar_.IsRegistered(this, |
367 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 410 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
368 Source<RenderProcessHost>(rph))) { | 411 Source<RenderProcessHost>(rph))) { |
369 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 412 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
370 Source<RenderProcessHost>(rph)); | 413 Source<RenderProcessHost>(rph)); |
371 } | 414 } |
372 } | 415 } |
373 | 416 |
417 void PrintPreviewTabController::RemoveInitiatorTab( | |
418 TabContentsWrapper* initiator_tab) { | |
419 TabContentsWrapper* preview_tab = GetPrintPreviewForTab(initiator_tab); | |
420 // Update the map entry first, so when the print preview tab gets destroyed | |
421 // and reaches RemovePreviewTab(), it does not attempt to also remove the | |
422 // initiator tab's observers. | |
423 preview_tab_map_[preview_tab] = NULL; | |
kmadhusu
2011/10/14 00:21:09
better to add a DCHECK to validate the preview_tab
Lei Zhang
2011/10/14 20:31:27
Done.
| |
424 RemoveObservers(initiator_tab); | |
425 | |
426 initiator_tab->print_view_manager()->PrintPreviewDone(); | |
427 | |
428 // Initiator tab is closed. Close the print preview tab too. | |
429 PrintPreviewUI* print_preview_ui = | |
430 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
431 if (print_preview_ui) | |
432 print_preview_ui->OnInitiatorTabClosed(); | |
433 } | |
434 | |
435 void PrintPreviewTabController::RemovePreviewTab( | |
436 TabContentsWrapper* preview_tab) { | |
437 // Remove the initiator tab's observers before erasing the mapping. | |
438 TabContentsWrapper* initiator_tab = GetInitiatorTab(preview_tab); | |
439 if (initiator_tab) { | |
440 initiator_tab->print_view_manager()->PrintPreviewDone(); | |
441 RemoveObservers(initiator_tab); | |
442 } | |
443 | |
444 // Print preview TabContents is destroyed. Notify |PrintPreviewUI| to abort | |
445 // the initiator tab preview request. | |
446 PrintPreviewUI* print_preview_ui = | |
447 static_cast<PrintPreviewUI*>(preview_tab->web_ui()); | |
448 if (print_preview_ui) | |
449 print_preview_ui->OnTabDestroyed(); | |
450 | |
451 preview_tab_map_.erase(preview_tab); | |
452 RemoveObservers(preview_tab); | |
453 } | |
454 | |
374 } // namespace printing | 455 } // namespace printing |
OLD | NEW |