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

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

Issue 538203002: Fix a crash on WebViewFocusHelper destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build; cleanup. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/constrained_web_dialog_delegate_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 16 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
17 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 17 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
18 #include "chrome/browser/printing/print_view_manager.h" 18 #include "chrome/browser/printing/print_view_manager.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
23 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/host_desktop.h" 23 #include "chrome/browser/ui/host_desktop.h"
25 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" 24 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
26 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 25 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
27 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 26 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
28 #include "chrome/common/chrome_content_client.h" 27 #include "chrome/common/chrome_content_client.h"
29 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
31 #include "components/web_modal/web_contents_modal_dialog_host.h" 30 #include "components/web_modal/web_contents_modal_dialog_host.h"
32 #include "content/public/browser/navigation_controller.h" 31 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_details.h" 32 #include "content/public/browser/navigation_details.h"
34 #include "content/public/browser/navigation_entry.h" 33 #include "content/public/browser/navigation_entry.h"
35 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
36 #include "content/public/browser/notification_source.h" 35 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/plugin_service.h" 36 #include "content/public/browser/plugin_service.h"
38 #include "content/public/browser/render_frame_host.h" 37 #include "content/public/browser/render_frame_host.h"
39 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
40 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
41 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
42 #include "content/public/browser/web_contents_delegate.h" 41 #include "content/public/browser/web_contents_delegate.h"
43 #include "content/public/common/webplugininfo.h" 42 #include "content/public/common/webplugininfo.h"
44 #include "ui/web_dialogs/web_dialog_delegate.h" 43 #include "ui/web_dialogs/web_dialog_delegate.h"
45 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h"
46 44
47 using content::NativeWebKeyboardEvent;
48 using content::NavigationController; 45 using content::NavigationController;
49 using content::WebContents; 46 using content::WebContents;
50 using content::WebUIMessageHandler; 47 using content::WebUIMessageHandler;
51 using ui::WebDialogDelegate;
52 using ui::WebDialogWebContentsDelegate;
53 48
54 namespace { 49 namespace {
55 50
56 void EnableInternalPDFPluginForContents(WebContents* preview_dialog) { 51 void EnableInternalPDFPluginForContents(WebContents* preview_dialog) {
57 // Always enable the internal PDF plugin for the print preview page. 52 // Always enable the internal PDF plugin for the print preview page.
58 base::FilePath pdf_plugin_path; 53 base::FilePath pdf_plugin_path;
59 if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_plugin_path)) 54 if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_plugin_path))
60 return; 55 return;
61 56
62 content::WebPluginInfo pdf_plugin; 57 content::WebPluginInfo pdf_plugin;
63 if (!content::PluginService::GetInstance()->GetPluginInfoByPath( 58 if (!content::PluginService::GetInstance()->GetPluginInfoByPath(
64 pdf_plugin_path, &pdf_plugin)) 59 pdf_plugin_path, &pdf_plugin))
65 return; 60 return;
66 61
67 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame( 62 ChromePluginServiceFilter::GetInstance()->OverridePluginForFrame(
68 preview_dialog->GetRenderProcessHost()->GetID(), 63 preview_dialog->GetRenderProcessHost()->GetID(),
69 preview_dialog->GetMainFrame()->GetRoutingID(), 64 preview_dialog->GetMainFrame()->GetRoutingID(),
70 GURL(), pdf_plugin); 65 GURL(), pdf_plugin);
71 } 66 }
72 67
73 // WebDialogDelegate that specifies what the print preview dialog 68 // A ui::WebDialogDelegate that specifies the print preview dialog appearance.
74 // will look like. 69 class PrintPreviewDialogDelegate : public ui::WebDialogDelegate {
75 class PrintPreviewDialogDelegate : public WebDialogDelegate {
76 public: 70 public:
77 explicit PrintPreviewDialogDelegate(WebContents* initiator); 71 explicit PrintPreviewDialogDelegate(WebContents* initiator);
78 virtual ~PrintPreviewDialogDelegate(); 72 virtual ~PrintPreviewDialogDelegate();
79 73
80 virtual ui::ModalType GetDialogModalType() const OVERRIDE; 74 virtual ui::ModalType GetDialogModalType() const OVERRIDE;
81 virtual base::string16 GetDialogTitle() const OVERRIDE; 75 virtual base::string16 GetDialogTitle() const OVERRIDE;
82 virtual GURL GetDialogContentURL() const OVERRIDE; 76 virtual GURL GetDialogContentURL() const OVERRIDE;
83 virtual void GetWebUIMessageHandlers( 77 virtual void GetWebUIMessageHandlers(
84 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; 78 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
85 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; 79 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 void PrintPreviewDialogDelegate::OnCloseContents(WebContents* /* source */, 154 void PrintPreviewDialogDelegate::OnCloseContents(WebContents* /* source */,
161 bool* out_close_dialog) { 155 bool* out_close_dialog) {
162 if (out_close_dialog) 156 if (out_close_dialog)
163 *out_close_dialog = true; 157 *out_close_dialog = true;
164 } 158 }
165 159
166 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const { 160 bool PrintPreviewDialogDelegate::ShouldShowDialogTitle() const {
167 return false; 161 return false;
168 } 162 }
169 163
170 // WebContentsDelegate that forwards shortcut keys in the print preview
171 // renderer to the browser.
172 class PrintPreviewWebContentDelegate : public WebDialogWebContentsDelegate {
173 public:
174 PrintPreviewWebContentDelegate(Profile* profile, WebContents* initiator);
175 virtual ~PrintPreviewWebContentDelegate();
176
177 // Overridden from WebDialogWebContentsDelegate:
178 virtual void HandleKeyboardEvent(
179 WebContents* source,
180 const NativeWebKeyboardEvent& event) OVERRIDE;
181
182 private:
183 WebContents* initiator_;
184
185 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate);
186 };
187
188 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate(
189 Profile* profile,
190 WebContents* initiator)
191 : WebDialogWebContentsDelegate(profile, new ChromeWebContentsHandler),
192 initiator_(initiator) {}
193
194 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {}
195
196 void PrintPreviewWebContentDelegate::HandleKeyboardEvent(
197 WebContents* source,
198 const NativeWebKeyboardEvent& event) {
199 // Disabled on Mac due to http://crbug.com/112173
200 #if !defined(OS_MACOSX)
201 Browser* current_browser = chrome::FindBrowserWithWebContents(initiator_);
202 if (!current_browser)
203 return;
204 current_browser->window()->HandleKeyboardEvent(event);
205 #endif
206 }
207
208 } // namespace 164 } // namespace
209 165
210 namespace printing { 166 namespace printing {
211 167
212 PrintPreviewDialogController::PrintPreviewDialogController() 168 PrintPreviewDialogController::PrintPreviewDialogController()
213 : waiting_for_new_preview_page_(false), 169 : waiting_for_new_preview_page_(false),
214 is_creating_print_preview_dialog_(false) { 170 is_creating_print_preview_dialog_(false) {
215 } 171 }
216 172
217 // static 173 // static
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 NOTREACHED(); 361 NOTREACHED();
406 return; 362 return;
407 } 363 }
408 364
409 RemoveInitiator(contents); 365 RemoveInitiator(contents);
410 } 366 }
411 367
412 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( 368 WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog(
413 WebContents* initiator) { 369 WebContents* initiator) {
414 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true); 370 base::AutoReset<bool> auto_reset(&is_creating_print_preview_dialog_, true);
415 Profile* profile =
416 Profile::FromBrowserContext(initiator->GetBrowserContext());
417 371
418 // |web_dialog_ui_delegate| deletes itself in 372 // The dialog delegates are deleted when the dialog is closed.
419 // PrintPreviewDialogDelegate::OnDialogClosed(). 373 ConstrainedWebDialogDelegate* web_dialog_delegate =
420 WebDialogDelegate* web_dialog_delegate = 374 CreateConstrainedWebDialog(initiator->GetBrowserContext(),
421 new PrintPreviewDialogDelegate(initiator); 375 new PrintPreviewDialogDelegate(initiator),
422 // |web_dialog_delegate|'s owner is |constrained_delegate|.
423 PrintPreviewWebContentDelegate* pp_wcd =
424 new PrintPreviewWebContentDelegate(profile, initiator);
425 ConstrainedWebDialogDelegate* constrained_delegate =
426 CreateConstrainedWebDialog(profile,
427 web_dialog_delegate,
428 pp_wcd,
429 initiator); 376 initiator);
430 WebContents* preview_dialog = constrained_delegate->GetWebContents(); 377
378 WebContents* preview_dialog = web_dialog_delegate->GetWebContents();
431 EnableInternalPDFPluginForContents(preview_dialog); 379 EnableInternalPDFPluginForContents(preview_dialog);
432 PrintViewManager::CreateForWebContents(preview_dialog); 380 PrintViewManager::CreateForWebContents(preview_dialog);
433 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 381 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
434 preview_dialog); 382 preview_dialog);
435 383
436 // Add an entry to the map. 384 // Add an entry to the map.
437 preview_dialog_map_[preview_dialog] = initiator; 385 preview_dialog_map_[preview_dialog] = initiator;
438 waiting_for_new_preview_page_ = true; 386 waiting_for_new_preview_page_ = true;
439 387
440 AddObservers(initiator); 388 AddObservers(initiator);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 static_cast<PrintPreviewUI*>(web_ui->GetController()); 473 static_cast<PrintPreviewUI*>(web_ui->GetController());
526 if (print_preview_ui) 474 if (print_preview_ui)
527 print_preview_ui->OnPrintPreviewDialogDestroyed(); 475 print_preview_ui->OnPrintPreviewDialogDestroyed();
528 } 476 }
529 477
530 preview_dialog_map_.erase(preview_dialog); 478 preview_dialog_map_.erase(preview_dialog);
531 RemoveObservers(preview_dialog); 479 RemoveObservers(preview_dialog);
532 } 480 }
533 481
534 } // namespace printing 482 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/constrained_web_dialog_delegate_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698