OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_dialog_controller.h" | 5 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( | 67 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( |
68 preview_dialog->GetRenderProcessHost()->GetID(), | 68 preview_dialog->GetRenderProcessHost()->GetID(), |
69 preview_dialog->GetRenderViewHost()->GetRoutingID(), | 69 preview_dialog->GetRenderViewHost()->GetRoutingID(), |
70 GURL(), pdf_plugin); | 70 GURL(), pdf_plugin); |
71 } | 71 } |
72 | 72 |
73 // WebDialogDelegate that specifies what the print preview dialog | 73 // WebDialogDelegate that specifies what the print preview dialog |
74 // will look like. | 74 // will look like. |
75 class PrintPreviewDialogDelegate : public WebDialogDelegate { | 75 class PrintPreviewDialogDelegate : public WebDialogDelegate { |
76 public: | 76 public: |
77 explicit PrintPreviewDialogDelegate(WebContents* initiator_tab); | 77 explicit PrintPreviewDialogDelegate(WebContents* initiator); |
78 virtual ~PrintPreviewDialogDelegate(); | 78 virtual ~PrintPreviewDialogDelegate(); |
79 | 79 |
80 virtual ui::ModalType GetDialogModalType() const OVERRIDE; | 80 virtual ui::ModalType GetDialogModalType() const OVERRIDE; |
81 virtual string16 GetDialogTitle() const OVERRIDE; | 81 virtual string16 GetDialogTitle() const OVERRIDE; |
82 virtual GURL GetDialogContentURL() const OVERRIDE; | 82 virtual GURL GetDialogContentURL() const OVERRIDE; |
83 virtual void GetWebUIMessageHandlers( | 83 virtual void GetWebUIMessageHandlers( |
84 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; | 84 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
85 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; | 85 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; |
86 virtual std::string GetDialogArgs() const OVERRIDE; | 86 virtual std::string GetDialogArgs() const OVERRIDE; |
87 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | 87 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
88 virtual void OnCloseContents(WebContents* source, | 88 virtual void OnCloseContents(WebContents* source, |
89 bool* out_close_dialog) OVERRIDE; | 89 bool* out_close_dialog) OVERRIDE; |
90 virtual bool ShouldShowDialogTitle() const OVERRIDE; | 90 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
91 | 91 |
92 private: | 92 private: |
93 WebContents* initiator_tab_; | 93 WebContents* initiator_; |
94 | 94 |
95 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDelegate); | 95 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDelegate); |
96 }; | 96 }; |
97 | 97 |
98 PrintPreviewDialogDelegate::PrintPreviewDialogDelegate( | 98 PrintPreviewDialogDelegate::PrintPreviewDialogDelegate( |
99 WebContents* initiator_tab) { | 99 WebContents* initiator) { |
100 initiator_tab_ = initiator_tab; | 100 initiator_ = initiator; |
Lei Zhang
2013/06/29 00:24:18
Just put this in the initializer list? I don't kno
Mike Wittman
2013/07/01 17:16:12
Done.
| |
101 } | 101 } |
102 | 102 |
103 PrintPreviewDialogDelegate::~PrintPreviewDialogDelegate() { | 103 PrintPreviewDialogDelegate::~PrintPreviewDialogDelegate() { |
104 } | 104 } |
105 | 105 |
106 ui::ModalType PrintPreviewDialogDelegate::GetDialogModalType() const { | 106 ui::ModalType PrintPreviewDialogDelegate::GetDialogModalType() const { |
107 // Not used, returning dummy value. | 107 // Not used, returning dummy value. |
108 NOTREACHED(); | 108 NOTREACHED(); |
109 return ui::MODAL_TYPE_WINDOW; | 109 return ui::MODAL_TYPE_WINDOW; |
110 } | 110 } |
(...skipping 11 matching lines...) Expand all Loading... | |
122 std::vector<WebUIMessageHandler*>* /* handlers */) const { | 122 std::vector<WebUIMessageHandler*>* /* handlers */) const { |
123 // PrintPreviewUI adds its own message handlers. | 123 // PrintPreviewUI adds its own message handlers. |
124 } | 124 } |
125 | 125 |
126 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { | 126 void PrintPreviewDialogDelegate::GetDialogSize(gfx::Size* size) const { |
127 DCHECK(size); | 127 DCHECK(size); |
128 const gfx::Size kMinDialogSize(800, 480); | 128 const gfx::Size kMinDialogSize(800, 480); |
129 const int kBorder = 25; | 129 const int kBorder = 25; |
130 const int kConstrainedWindowOverlap = 3; | 130 const int kConstrainedWindowOverlap = 3; |
131 gfx::Rect rect; | 131 gfx::Rect rect; |
132 initiator_tab_->GetView()->GetContainerBounds(&rect); | 132 initiator_->GetView()->GetContainerBounds(&rect); |
133 size->set_width(std::max(rect.width(), kMinDialogSize.width()) - 2 * kBorder); | 133 size->set_width(std::max(rect.width(), kMinDialogSize.width()) - 2 * kBorder); |
134 size->set_height(std::max(rect.height(), kMinDialogSize.height()) - kBorder + | 134 size->set_height(std::max(rect.height(), kMinDialogSize.height()) - kBorder + |
135 kConstrainedWindowOverlap); | 135 kConstrainedWindowOverlap); |
136 | 136 |
137 #if defined(OS_MACOSX) | 137 #if defined(OS_MACOSX) |
138 // Limit the maximum size on MacOS X. | 138 // Limit the maximum size on MacOS X. |
139 // http://crbug.com/105815 | 139 // http://crbug.com/105815 |
140 const gfx::Size kMaxDialogSize(1000, 660); | 140 const gfx::Size kMaxDialogSize(1000, 660); |
141 size->set_width(std::min(size->width(), kMaxDialogSize.width())); | 141 size->set_width(std::min(size->width(), kMaxDialogSize.width())); |
142 size->set_height(std::min(size->height(), kMaxDialogSize.height())); | 142 size->set_height(std::min(size->height(), kMaxDialogSize.height())); |
(...skipping 15 matching lines...) Expand all Loading... | |
158 } | 158 } |
159 | 159 |
160 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { | 160 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { |
161 return false; | 161 return false; |
162 } | 162 } |
163 | 163 |
164 // WebContentsDelegate that forwards shortcut keys in the print preview | 164 // WebContentsDelegate that forwards shortcut keys in the print preview |
165 // renderer to the browser. | 165 // renderer to the browser. |
166 class PrintPreviewWebContentDelegate : public WebDialogWebContentsDelegate { | 166 class PrintPreviewWebContentDelegate : public WebDialogWebContentsDelegate { |
167 public: | 167 public: |
168 PrintPreviewWebContentDelegate(Profile* profile, WebContents* initiator_tab); | 168 PrintPreviewWebContentDelegate(Profile* profile, WebContents* initiator); |
169 virtual ~PrintPreviewWebContentDelegate(); | 169 virtual ~PrintPreviewWebContentDelegate(); |
170 | 170 |
171 // Overridden from WebDialogWebContentsDelegate: | 171 // Overridden from WebDialogWebContentsDelegate: |
172 virtual void HandleKeyboardEvent( | 172 virtual void HandleKeyboardEvent( |
173 WebContents* source, | 173 WebContents* source, |
174 const NativeWebKeyboardEvent& event) OVERRIDE; | 174 const NativeWebKeyboardEvent& event) OVERRIDE; |
175 | 175 |
176 private: | 176 private: |
177 WebContents* tab_; | 177 WebContents* tab_; |
178 | 178 |
179 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate); | 179 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate); |
180 }; | 180 }; |
181 | 181 |
182 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate( | 182 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate( |
183 Profile* profile, | 183 Profile* profile, |
184 WebContents* initiator_tab) | 184 WebContents* initiator) |
185 : WebDialogWebContentsDelegate(profile, new ChromeWebContentsHandler), | 185 : WebDialogWebContentsDelegate(profile, new ChromeWebContentsHandler), |
186 tab_(initiator_tab) {} | 186 tab_(initiator) {} |
187 | 187 |
188 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {} | 188 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {} |
189 | 189 |
190 void PrintPreviewWebContentDelegate::HandleKeyboardEvent( | 190 void PrintPreviewWebContentDelegate::HandleKeyboardEvent( |
191 WebContents* source, | 191 WebContents* source, |
192 const NativeWebKeyboardEvent& event) { | 192 const NativeWebKeyboardEvent& event) { |
193 // Disabled on Mac due to http://crbug.com/112173 | 193 // Disabled on Mac due to http://crbug.com/112173 |
194 #if !defined(OS_MACOSX) | 194 #if !defined(OS_MACOSX) |
195 Browser* current_browser = chrome::FindBrowserWithWebContents(tab_); | 195 Browser* current_browser = chrome::FindBrowserWithWebContents(tab_); |
196 if (!current_browser) | 196 if (!current_browser) |
(...skipping 12 matching lines...) Expand all Loading... | |
209 } | 209 } |
210 | 210 |
211 // static | 211 // static |
212 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { | 212 PrintPreviewDialogController* PrintPreviewDialogController::GetInstance() { |
213 if (!g_browser_process) | 213 if (!g_browser_process) |
214 return NULL; | 214 return NULL; |
215 return g_browser_process->print_preview_dialog_controller(); | 215 return g_browser_process->print_preview_dialog_controller(); |
216 } | 216 } |
217 | 217 |
218 // static | 218 // static |
219 void PrintPreviewDialogController::PrintPreview(WebContents* initiator_tab) { | 219 void PrintPreviewDialogController::PrintPreview(WebContents* initiator) { |
220 if (initiator_tab->ShowingInterstitialPage()) | 220 if (initiator->ShowingInterstitialPage()) |
221 return; | 221 return; |
222 | 222 |
223 PrintPreviewDialogController* dialog_controller = GetInstance(); | 223 PrintPreviewDialogController* dialog_controller = GetInstance(); |
224 if (!dialog_controller) | 224 if (!dialog_controller) |
225 return; | 225 return; |
226 if (!dialog_controller->GetOrCreatePreviewDialog(initiator_tab)) | 226 if (!dialog_controller->GetOrCreatePreviewDialog(initiator)) |
227 PrintViewManager::FromWebContents(initiator_tab)->PrintPreviewDone(); | 227 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
228 } | 228 } |
229 | 229 |
230 WebContents* PrintPreviewDialogController::GetOrCreatePreviewDialog( | 230 WebContents* PrintPreviewDialogController::GetOrCreatePreviewDialog( |
231 WebContents* initiator_tab) { | 231 WebContents* initiator) { |
232 DCHECK(initiator_tab); | 232 DCHECK(initiator); |
233 | 233 |
234 // Get the print preview dialog for |initiator_tab|. | 234 // Get the print preview dialog for |initiator|. |
235 WebContents* preview_dialog = GetPrintPreviewForContents(initiator_tab); | 235 WebContents* preview_dialog = GetPrintPreviewForContents(initiator); |
236 if (!preview_dialog) | 236 if (!preview_dialog) |
237 return CreatePrintPreviewDialog(initiator_tab); | 237 return CreatePrintPreviewDialog(initiator); |
238 | 238 |
239 // Show the initiator tab holding the existing preview dialog. | 239 // Show the initiator holding the existing preview dialog. |
240 initiator_tab->GetDelegate()->ActivateContents(initiator_tab); | 240 initiator->GetDelegate()->ActivateContents(initiator); |
241 return preview_dialog; | 241 return preview_dialog; |
242 } | 242 } |
243 | 243 |
244 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( | 244 WebContents* PrintPreviewDialogController::GetPrintPreviewForContents( |
245 WebContents* contents) const { | 245 WebContents* contents) const { |
246 // |preview_dialog_map_| is keyed by the preview dialog, so if find() | 246 // |preview_dialog_map_| is keyed by the preview dialog, so if find() |
247 // succeeds, then |contents| is the preview dialog. | 247 // succeeds, then |contents| is the preview dialog. |
248 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); | 248 PrintPreviewDialogMap::const_iterator it = preview_dialog_map_.find(contents); |
249 if (it != preview_dialog_map_.end()) | 249 if (it != preview_dialog_map_.end()) |
250 return contents; | 250 return contents; |
251 | 251 |
252 for (it = preview_dialog_map_.begin(); | 252 for (it = preview_dialog_map_.begin(); |
253 it != preview_dialog_map_.end(); | 253 it != preview_dialog_map_.end(); |
254 ++it) { | 254 ++it) { |
255 // If |contents| is an initiator tab. | 255 // If |contents| is an initiator. |
256 if (contents == it->second) { | 256 if (contents == it->second) { |
257 // Return the associated preview dialog. | 257 // Return the associated preview dialog. |
258 return it->first; | 258 return it->first; |
259 } | 259 } |
260 } | 260 } |
261 return NULL; | 261 return NULL; |
262 } | 262 } |
263 | 263 |
264 WebContents* PrintPreviewDialogController::GetInitiatorTab( | 264 WebContents* PrintPreviewDialogController::GetInitiator( |
265 WebContents* preview_dialog) { | 265 WebContents* preview_dialog) { |
266 PrintPreviewDialogMap::iterator it = preview_dialog_map_.find(preview_dialog); | 266 PrintPreviewDialogMap::iterator it = preview_dialog_map_.find(preview_dialog); |
267 return (it != preview_dialog_map_.end()) ? it->second : NULL; | 267 return (it != preview_dialog_map_.end()) ? it->second : NULL; |
268 } | 268 } |
269 | 269 |
270 void PrintPreviewDialogController::Observe( | 270 void PrintPreviewDialogController::Observe( |
271 int type, | 271 int type, |
272 const content::NotificationSource& source, | 272 const content::NotificationSource& source, |
273 const content::NotificationDetails& details) { | 273 const content::NotificationDetails& details) { |
274 if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { | 274 if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { |
(...skipping 15 matching lines...) Expand all Loading... | |
290 bool PrintPreviewDialogController::IsPrintPreviewDialog(WebContents* contents) { | 290 bool PrintPreviewDialogController::IsPrintPreviewDialog(WebContents* contents) { |
291 return IsPrintPreviewURL(contents->GetURL()); | 291 return IsPrintPreviewURL(contents->GetURL()); |
292 } | 292 } |
293 | 293 |
294 // static | 294 // static |
295 bool PrintPreviewDialogController::IsPrintPreviewURL(const GURL& url) { | 295 bool PrintPreviewDialogController::IsPrintPreviewURL(const GURL& url) { |
296 return (url.SchemeIs(chrome::kChromeUIScheme) && | 296 return (url.SchemeIs(chrome::kChromeUIScheme) && |
297 url.host() == chrome::kChromeUIPrintHost); | 297 url.host() == chrome::kChromeUIPrintHost); |
298 } | 298 } |
299 | 299 |
300 void PrintPreviewDialogController::EraseInitiatorTabInfo( | 300 void PrintPreviewDialogController::EraseInitiatorInfo( |
301 WebContents* preview_dialog) { | 301 WebContents* preview_dialog) { |
302 PrintPreviewDialogMap::iterator it = preview_dialog_map_.find(preview_dialog); | 302 PrintPreviewDialogMap::iterator it = preview_dialog_map_.find(preview_dialog); |
303 if (it == preview_dialog_map_.end()) | 303 if (it == preview_dialog_map_.end()) |
304 return; | 304 return; |
305 | 305 |
306 RemoveObservers(it->second); | 306 RemoveObservers(it->second, INITIATOR); |
307 preview_dialog_map_[preview_dialog] = NULL; | 307 preview_dialog_map_[preview_dialog] = NULL; |
308 } | 308 } |
309 | 309 |
310 PrintPreviewDialogController::~PrintPreviewDialogController() {} | 310 PrintPreviewDialogController::~PrintPreviewDialogController() {} |
311 | 311 |
312 void PrintPreviewDialogController::OnRendererProcessClosed( | 312 void PrintPreviewDialogController::OnRendererProcessClosed( |
313 content::RenderProcessHost* rph) { | 313 content::RenderProcessHost* rph) { |
314 // Store contents in a vector and deal with them after iterating through | 314 // Store contents in a vector and deal with them after iterating through |
315 // |preview_dialog_map_| because RemoveFoo() can change |preview_dialog_map_|. | 315 // |preview_dialog_map_| because RemoveFoo() can change |preview_dialog_map_|. |
316 std::vector<WebContents*> closed_initiator_tabs; | 316 std::vector<WebContents*> closed_initiators; |
317 std::vector<WebContents*> closed_preview_dialogs; | 317 std::vector<WebContents*> closed_preview_dialogs; |
318 for (PrintPreviewDialogMap::iterator iter = preview_dialog_map_.begin(); | 318 for (PrintPreviewDialogMap::iterator iter = preview_dialog_map_.begin(); |
319 iter != preview_dialog_map_.end(); ++iter) { | 319 iter != preview_dialog_map_.end(); ++iter) { |
320 WebContents* preview_dialog = iter->first; | 320 WebContents* preview_dialog = iter->first; |
321 WebContents* initiator_tab = iter->second; | 321 WebContents* initiator = iter->second; |
322 if (preview_dialog->GetRenderProcessHost() == rph) { | 322 if (preview_dialog->GetRenderProcessHost() == rph) { |
323 closed_preview_dialogs.push_back(preview_dialog); | 323 closed_preview_dialogs.push_back(preview_dialog); |
324 } else if (initiator_tab && | 324 } else if (initiator && |
325 initiator_tab->GetRenderProcessHost() == rph) { | 325 initiator->GetRenderProcessHost() == rph) { |
326 closed_initiator_tabs.push_back(initiator_tab); | 326 closed_initiators.push_back(initiator); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 for (size_t i = 0; i < closed_preview_dialogs.size(); ++i) { | 330 for (size_t i = 0; i < closed_preview_dialogs.size(); ++i) { |
331 RemovePreviewDialog(closed_preview_dialogs[i]); | 331 RemovePreviewDialog(closed_preview_dialogs[i]); |
332 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 332 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
333 closed_preview_dialogs[i]->GetWebUI()->GetController()); | 333 closed_preview_dialogs[i]->GetWebUI()->GetController()); |
334 if (print_preview_ui) | 334 if (print_preview_ui) |
335 print_preview_ui->OnPrintPreviewDialogClosed(); | 335 print_preview_ui->OnPrintPreviewDialogClosed(); |
336 } | 336 } |
337 | 337 |
338 for (size_t i = 0; i < closed_initiator_tabs.size(); ++i) | 338 for (size_t i = 0; i < closed_initiators.size(); ++i) |
339 RemoveInitiatorTab(closed_initiator_tabs[i]); | 339 RemoveInitiator(closed_initiators[i]); |
340 } | 340 } |
341 | 341 |
342 void PrintPreviewDialogController::OnWebContentsDestroyed( | 342 void PrintPreviewDialogController::OnWebContentsDestroyed( |
343 WebContents* contents) { | 343 WebContents* contents) { |
344 WebContents* preview_dialog = GetPrintPreviewForContents(contents); | 344 WebContents* preview_dialog = GetPrintPreviewForContents(contents); |
345 if (!preview_dialog) { | 345 if (!preview_dialog) { |
346 NOTREACHED(); | 346 NOTREACHED(); |
347 return; | 347 return; |
348 } | 348 } |
349 | 349 |
350 if (contents == preview_dialog) | 350 if (contents == preview_dialog) |
351 RemovePreviewDialog(contents); | 351 RemovePreviewDialog(contents); |
352 else | 352 else |
353 RemoveInitiatorTab(contents); | 353 RemoveInitiator(contents); |
354 } | 354 } |
355 | 355 |
356 void PrintPreviewDialogController::OnNavEntryCommitted( | 356 void PrintPreviewDialogController::OnNavEntryCommitted( |
357 WebContents* contents, content::LoadCommittedDetails* details) { | 357 WebContents* contents, content::LoadCommittedDetails* details) { |
358 WebContents* preview_dialog = GetPrintPreviewForContents(contents); | 358 WebContents* preview_dialog = GetPrintPreviewForContents(contents); |
359 if (!preview_dialog) { | 359 if (!preview_dialog) { |
360 NOTREACHED(); | 360 NOTREACHED(); |
361 return; | 361 return; |
362 } | 362 } |
363 | 363 |
364 if (contents == preview_dialog) { | 364 DCHECK_EQ(contents, preview_dialog); |
365 // Preview dialog navigated. | |
366 if (details) { | |
367 content::PageTransition transition_type = | |
368 details->entry->GetTransitionType(); | |
369 content::NavigationType nav_type = details->type; | |
370 | 365 |
371 // New |preview_dialog| is created. Don't update/erase map entry. | 366 // Preview dialog navigated. |
372 if (waiting_for_new_preview_page_ && | 367 if (details) { |
373 transition_type == content::PAGE_TRANSITION_AUTO_TOPLEVEL && | 368 content::PageTransition transition_type = |
374 nav_type == content::NAVIGATION_TYPE_NEW_PAGE) { | 369 details->entry->GetTransitionType(); |
375 waiting_for_new_preview_page_ = false; | 370 content::NavigationType nav_type = details->type; |
376 SaveInitiatorTabTitle(preview_dialog); | |
377 return; | |
378 } | |
379 | 371 |
380 // Cloud print sign-in causes a reload. | 372 // New |preview_dialog| is created. Don't update/erase map entry. |
381 if (!waiting_for_new_preview_page_ && | 373 if (waiting_for_new_preview_page_ && |
382 transition_type == content::PAGE_TRANSITION_RELOAD && | 374 transition_type == content::PAGE_TRANSITION_AUTO_TOPLEVEL && |
383 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && | 375 nav_type == content::NAVIGATION_TYPE_NEW_PAGE) { |
384 IsPrintPreviewURL(details->previous_url)) { | 376 waiting_for_new_preview_page_ = false; |
385 return; | 377 SaveInitiatorTitle(preview_dialog); |
386 } | 378 return; |
387 } | 379 } |
388 NOTREACHED(); | 380 |
389 return; | 381 // Cloud print sign-in causes a reload. |
382 if (!waiting_for_new_preview_page_ && | |
383 transition_type == content::PAGE_TRANSITION_RELOAD && | |
384 nav_type == content::NAVIGATION_TYPE_EXISTING_PAGE && | |
385 IsPrintPreviewURL(details->previous_url)) { | |
386 return; | |
387 } | |
390 } | 388 } |
391 | 389 |
392 RemoveInitiatorTab(contents); | 390 NOTREACHED(); |
393 } | 391 } |
394 | 392 |
395 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( | 393 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( |
396 WebContents* initiator_tab) { | 394 WebContents* initiator) { |
397 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); | 395 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); |
398 Profile* profile = | 396 Profile* profile = |
399 Profile::FromBrowserContext(initiator_tab->GetBrowserContext()); | 397 Profile::FromBrowserContext(initiator->GetBrowserContext()); |
400 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { | 398 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) { |
401 // Chrome Frame only ever runs on the native desktop, so it is safe to | 399 // Chrome Frame only ever runs on the native desktop, so it is safe to |
402 // create the popup on the native desktop. | 400 // create the popup on the native desktop. |
403 Browser* current_browser = new Browser( | 401 Browser* current_browser = new Browser( |
404 Browser::CreateParams(Browser::TYPE_POPUP, profile, | 402 Browser::CreateParams(Browser::TYPE_POPUP, profile, |
405 chrome::HOST_DESKTOP_TYPE_NATIVE)); | 403 chrome::HOST_DESKTOP_TYPE_NATIVE)); |
406 if (!current_browser) { | 404 if (!current_browser) { |
407 NOTREACHED() << "Failed to create popup browser window"; | 405 NOTREACHED() << "Failed to create popup browser window"; |
408 return NULL; | 406 return NULL; |
409 } | 407 } |
410 } | 408 } |
411 | 409 |
412 // |web_dialog_ui_delegate| deletes itself in | 410 // |web_dialog_ui_delegate| deletes itself in |
413 // PrintPreviewDialogDelegate::OnDialogClosed(). | 411 // PrintPreviewDialogDelegate::OnDialogClosed(). |
414 WebDialogDelegate* web_dialog_delegate = | 412 WebDialogDelegate* web_dialog_delegate = |
415 new PrintPreviewDialogDelegate(initiator_tab); | 413 new PrintPreviewDialogDelegate(initiator); |
416 // |web_dialog_delegate|'s owner is |constrained_delegate|. | 414 // |web_dialog_delegate|'s owner is |constrained_delegate|. |
417 PrintPreviewWebContentDelegate* pp_wcd = | 415 PrintPreviewWebContentDelegate* pp_wcd = |
418 new PrintPreviewWebContentDelegate(profile, initiator_tab); | 416 new PrintPreviewWebContentDelegate(profile, initiator); |
419 ConstrainedWebDialogDelegate* constrained_delegate = | 417 ConstrainedWebDialogDelegate* constrained_delegate = |
420 CreateConstrainedWebDialog(profile, | 418 CreateConstrainedWebDialog(profile, |
421 web_dialog_delegate, | 419 web_dialog_delegate, |
422 pp_wcd, | 420 pp_wcd, |
423 initiator_tab); | 421 initiator); |
424 WebContents* preview_dialog = constrained_delegate->GetWebContents(); | 422 WebContents* preview_dialog = constrained_delegate->GetWebContents(); |
425 EnableInternalPDFPluginForContents(preview_dialog); | 423 EnableInternalPDFPluginForContents(preview_dialog); |
426 PrintViewManager::CreateForWebContents(preview_dialog); | 424 PrintViewManager::CreateForWebContents(preview_dialog); |
427 | 425 |
428 // Add an entry to the map. | 426 // Add an entry to the map. |
429 preview_dialog_map_[preview_dialog] = initiator_tab; | 427 preview_dialog_map_[preview_dialog] = initiator; |
430 waiting_for_new_preview_page_ = true; | 428 waiting_for_new_preview_page_ = true; |
431 | 429 |
432 AddObservers(initiator_tab); | 430 AddObservers(initiator, INITIATOR); |
433 AddObservers(preview_dialog); | 431 AddObservers(preview_dialog, PREVIEW_DIALOG); |
434 | 432 |
435 return preview_dialog; | 433 return preview_dialog; |
436 } | 434 } |
437 | 435 |
438 void PrintPreviewDialogController::SaveInitiatorTabTitle( | 436 void PrintPreviewDialogController::SaveInitiatorTitle( |
439 WebContents* preview_dialog) { | 437 WebContents* preview_dialog) { |
440 WebContents* initiator_tab = GetInitiatorTab(preview_dialog); | 438 WebContents* initiator = GetInitiator(preview_dialog); |
441 if (initiator_tab && preview_dialog->GetWebUI()) { | 439 if (initiator && preview_dialog->GetWebUI()) { |
442 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 440 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
443 preview_dialog->GetWebUI()->GetController()); | 441 preview_dialog->GetWebUI()->GetController()); |
444 print_preview_ui->SetInitiatorTabTitle( | 442 print_preview_ui->SetInitiatorTitle( |
445 PrintViewManager::FromWebContents(initiator_tab)->RenderSourceName()); | 443 PrintViewManager::FromWebContents(initiator)->RenderSourceName()); |
446 } | 444 } |
447 } | 445 } |
448 | 446 |
449 void PrintPreviewDialogController::AddObservers(WebContents* contents) { | 447 void PrintPreviewDialogController::AddObservers(WebContents* contents, |
448 ContentsType contents_type) { | |
450 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 449 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
451 content::Source<WebContents>(contents)); | 450 content::Source<WebContents>(contents)); |
452 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 451 if (contents_type == PREVIEW_DIALOG) { |
453 content::Source<NavigationController>(&contents->GetController())); | 452 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
453 content::Source<NavigationController>(&contents->GetController())); | |
454 } | |
454 | 455 |
455 // Multiple sites may share the same RenderProcessHost, so check if this | 456 // Multiple sites may share the same RenderProcessHost, so check if this |
456 // notification has already been added. | 457 // notification has already been added. |
457 content::Source<content::RenderProcessHost> rph_source( | 458 content::Source<content::RenderProcessHost> rph_source( |
458 contents->GetRenderProcessHost()); | 459 contents->GetRenderProcessHost()); |
459 if (!registrar_.IsRegistered(this, | 460 if (!registrar_.IsRegistered(this, |
460 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { | 461 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { |
461 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 462 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
462 rph_source); | 463 rph_source); |
463 } | 464 } |
464 } | 465 } |
465 | 466 |
466 void PrintPreviewDialogController::RemoveObservers(WebContents* contents) { | 467 void PrintPreviewDialogController::RemoveObservers(WebContents* contents, |
468 ContentsType contents_type) { | |
467 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 469 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
468 content::Source<WebContents>(contents)); | 470 content::Source<WebContents>(contents)); |
469 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 471 if (contents_type == PREVIEW_DIALOG) { |
470 content::Source<NavigationController>(&contents->GetController())); | 472 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
473 content::Source<NavigationController>(&contents->GetController())); | |
474 } | |
471 | 475 |
472 // Multiple sites may share the same RenderProcessHost, so check if this | 476 // Multiple sites may share the same RenderProcessHost, so check if this |
473 // notification has already been added. | 477 // notification has already been added. |
474 content::Source<content::RenderProcessHost> rph_source( | 478 content::Source<content::RenderProcessHost> rph_source( |
475 contents->GetRenderProcessHost()); | 479 contents->GetRenderProcessHost()); |
476 if (registrar_.IsRegistered(this, | 480 if (registrar_.IsRegistered(this, |
477 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { | 481 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, rph_source)) { |
478 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 482 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
479 rph_source); | 483 rph_source); |
480 } | 484 } |
481 } | 485 } |
482 | 486 |
483 void PrintPreviewDialogController::RemoveInitiatorTab( | 487 void PrintPreviewDialogController::RemoveInitiator( |
484 WebContents* initiator_tab) { | 488 WebContents* initiator) { |
485 WebContents* preview_dialog = GetPrintPreviewForContents(initiator_tab); | 489 WebContents* preview_dialog = GetPrintPreviewForContents(initiator); |
486 DCHECK(preview_dialog); | 490 DCHECK(preview_dialog); |
487 // Update the map entry first, so when the print preview dialog gets destroyed | 491 // Update the map entry first, so when the print preview dialog gets destroyed |
488 // and reaches RemovePreviewDialog(), it does not attempt to also remove the | 492 // and reaches RemovePreviewDialog(), it does not attempt to also remove the |
489 // initiator tab's observers. | 493 // initiator's observers. |
490 preview_dialog_map_[preview_dialog] = NULL; | 494 preview_dialog_map_[preview_dialog] = NULL; |
491 RemoveObservers(initiator_tab); | 495 RemoveObservers(initiator, INITIATOR); |
492 | 496 |
493 PrintViewManager::FromWebContents(initiator_tab)->PrintPreviewDone(); | 497 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
494 | 498 |
495 // Initiator tab is closed. Close the print preview dialog too. | 499 // initiator is closed. Close the print preview dialog too. |
496 PrintPreviewUI* print_preview_ui = | 500 PrintPreviewUI* print_preview_ui = |
497 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); | 501 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); |
498 if (print_preview_ui) | 502 if (print_preview_ui) |
499 print_preview_ui->OnInitiatorTabClosed(); | 503 print_preview_ui->OnInitiatorClosed(); |
500 } | 504 } |
501 | 505 |
502 void PrintPreviewDialogController::RemovePreviewDialog( | 506 void PrintPreviewDialogController::RemovePreviewDialog( |
503 WebContents* preview_dialog) { | 507 WebContents* preview_dialog) { |
504 // Remove the initiator tab's observers before erasing the mapping. | 508 // Remove the initiator's observers before erasing the mapping. |
505 WebContents* initiator_tab = GetInitiatorTab(preview_dialog); | 509 WebContents* initiator = GetInitiator(preview_dialog); |
506 if (initiator_tab) { | 510 if (initiator) { |
507 RemoveObservers(initiator_tab); | 511 RemoveObservers(initiator, INITIATOR); |
508 PrintViewManager::FromWebContents(initiator_tab)->PrintPreviewDone(); | 512 PrintViewManager::FromWebContents(initiator)->PrintPreviewDone(); |
509 } | 513 } |
510 | 514 |
511 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort | 515 // Print preview WebContents is destroyed. Notify |PrintPreviewUI| to abort |
512 // the initiator tab preview request. | 516 // the initiator preview request. |
513 PrintPreviewUI* print_preview_ui = | 517 PrintPreviewUI* print_preview_ui = |
514 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); | 518 static_cast<PrintPreviewUI*>(preview_dialog->GetWebUI()->GetController()); |
515 if (print_preview_ui) | 519 if (print_preview_ui) |
516 print_preview_ui->OnPrintPreviewDialogDestroyed(); | 520 print_preview_ui->OnPrintPreviewDialogDestroyed(); |
517 | 521 |
518 preview_dialog_map_.erase(preview_dialog); | 522 preview_dialog_map_.erase(preview_dialog); |
519 RemoveObservers(preview_dialog); | 523 RemoveObservers(preview_dialog, PREVIEW_DIALOG); |
520 } | 524 } |
521 | 525 |
522 } // namespace printing | 526 } // namespace printing |
OLD | NEW |