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

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

Issue 10214001: WebDialogs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud_unittest.cc ('k') | chrome/browser/ui/browser.h » ('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_tab_controller.h" 5 #include "chrome/browser/printing/print_preview_tab_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/command_line.h" 12 #include "base/command_line.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_plugin_service_filter.h" 15 #include "chrome/browser/chrome_plugin_service_filter.h"
16 #include "chrome/browser/printing/print_view_manager.h" 16 #include "chrome/browser/printing/print_view_manager.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/tabs/tab_strip_model.h" 18 #include "chrome/browser/tabs/tab_strip_model.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 20 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #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" 24 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
25 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h"
26 #include "chrome/browser/ui/webui/html_dialog_ui.h"
27 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 25 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
26 #include "chrome/browser/ui/webui/web_dialog_web_contents_delegate.h"
27 #include "chrome/browser/ui/webui/web_dialog_ui.h"
28 #include "chrome/common/chrome_content_client.h" 28 #include "chrome/common/chrome_content_client.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
31 #include "content/public/browser/navigation_controller.h" 31 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/navigation_details.h" 32 #include "content/public/browser/navigation_details.h"
33 #include "content/public/browser/navigation_entry.h" 33 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
35 #include "content/public/browser/notification_source.h" 35 #include "content/public/browser/notification_source.h"
36 #include "content/public/browser/notification_types.h" 36 #include "content/public/browser/notification_types.h"
37 #include "content/public/browser/render_process_host.h" 37 #include "content/public/browser/render_process_host.h"
(...skipping 10 matching lines...) Expand all
48 48
49 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) { 49 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) {
50 // Always enable the internal PDF plugin for the print preview page. 50 // Always enable the internal PDF plugin for the print preview page.
51 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( 51 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab(
52 preview_tab->web_contents()->GetRenderProcessHost()->GetID(), 52 preview_tab->web_contents()->GetRenderProcessHost()->GetID(),
53 preview_tab->web_contents()->GetRenderViewHost()->GetRoutingID(), 53 preview_tab->web_contents()->GetRenderViewHost()->GetRoutingID(),
54 GURL(), 54 GURL(),
55 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName)); 55 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
56 } 56 }
57 57
58 // HtmlDialogUIDelegate that specifies what the print preview dialog will look 58 // WebDialogDelegate that specifies what the print preview dialog
59 // like. 59 // will look like.
60 class PrintPreviewTabDelegate : public HtmlDialogUIDelegate { 60 class PrintPreviewTabDelegate : public WebDialogDelegate {
61 public: 61 public:
62 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab); 62 explicit PrintPreviewTabDelegate(TabContentsWrapper* initiator_tab);
63 virtual ~PrintPreviewTabDelegate(); 63 virtual ~PrintPreviewTabDelegate();
64 64
65 // Overridden from WebDialogDelegate:
65 virtual ui::ModalType GetDialogModalType() const OVERRIDE; 66 virtual ui::ModalType GetDialogModalType() const OVERRIDE;
66 virtual string16 GetDialogTitle() const OVERRIDE; 67 virtual string16 GetDialogTitle() const OVERRIDE;
67 virtual GURL GetDialogContentURL() const OVERRIDE; 68 virtual GURL GetDialogContentURL() const OVERRIDE;
68 virtual void GetWebUIMessageHandlers( 69 virtual void GetWebUIMessageHandlers(
69 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; 70 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
70 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; 71 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
71 virtual std::string GetDialogArgs() const OVERRIDE; 72 virtual std::string GetDialogArgs() const OVERRIDE;
72 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; 73 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
73 virtual void OnCloseContents(WebContents* source, 74 virtual void OnCloseContents(WebContents* source,
74 bool* out_close_dialog) OVERRIDE; 75 bool* out_close_dialog) OVERRIDE;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 142 }
142 143
143 bool PrintPreviewTabDelegate::ShouldShowDialogTitle() const { 144 bool PrintPreviewTabDelegate::ShouldShowDialogTitle() const {
144 // Not used, returning dummy value. 145 // Not used, returning dummy value.
145 NOTREACHED(); 146 NOTREACHED();
146 return false; 147 return false;
147 } 148 }
148 149
149 // WebContentsDelegate that forwards shortcut keys in the print preview 150 // WebContentsDelegate that forwards shortcut keys in the print preview
150 // renderer to the browser. 151 // renderer to the browser.
151 class PrintPreviewWebContentDelegate : public HtmlDialogTabContentsDelegate { 152 class PrintPreviewWebContentDelegate : public WebDialogWebContentsDelegate {
152 public: 153 public:
153 PrintPreviewWebContentDelegate(Profile* profile, 154 PrintPreviewWebContentDelegate(Profile* profile,
154 TabContentsWrapper* initiator_tab); 155 TabContentsWrapper* initiator_tab);
155 virtual ~PrintPreviewWebContentDelegate(); 156 virtual ~PrintPreviewWebContentDelegate();
156 157
157 virtual bool CanReloadContents(WebContents* source) const OVERRIDE; 158 virtual bool CanReloadContents(WebContents* source) const OVERRIDE;
158 virtual void HandleKeyboardEvent( 159 virtual void HandleKeyboardEvent(
159 const NativeWebKeyboardEvent& event) OVERRIDE; 160 const NativeWebKeyboardEvent& event) OVERRIDE;
160 161
161 private: 162 private:
162 TabContentsWrapper* tab_; 163 TabContentsWrapper* tab_;
163 164
164 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate); 165 DISALLOW_COPY_AND_ASSIGN(PrintPreviewWebContentDelegate);
165 }; 166 };
166 167
167 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate( 168 PrintPreviewWebContentDelegate::PrintPreviewWebContentDelegate(
168 Profile* profile, 169 Profile* profile,
169 TabContentsWrapper* initiator_tab) 170 TabContentsWrapper* initiator_tab)
170 : HtmlDialogTabContentsDelegate(profile), 171 : WebDialogWebContentsDelegate(profile),
171 tab_(initiator_tab) {} 172 tab_(initiator_tab) {}
172 173
173 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {} 174 PrintPreviewWebContentDelegate::~PrintPreviewWebContentDelegate() {}
174 175
175 bool PrintPreviewWebContentDelegate::CanReloadContents( 176 bool PrintPreviewWebContentDelegate::CanReloadContents(
176 WebContents* source) const { 177 WebContents* source) const {
177 return false; 178 return false;
178 } 179 }
179 180
180 void PrintPreviewWebContentDelegate::HandleKeyboardEvent( 181 void PrintPreviewWebContentDelegate::HandleKeyboardEvent(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 Browser::CreateParams(Browser::TYPE_POPUP, profile)); 419 Browser::CreateParams(Browser::TYPE_POPUP, profile));
419 if (!current_browser) { 420 if (!current_browser) {
420 NOTREACHED() << "Failed to create popup browser window"; 421 NOTREACHED() << "Failed to create popup browser window";
421 return NULL; 422 return NULL;
422 } 423 }
423 } else { 424 } else {
424 return NULL; 425 return NULL;
425 } 426 }
426 } 427 }
427 428
428 // |html_dialog_ui_delegate| deletes itself in 429 // |web_dialog_ui_delegate| deletes itself in
429 // PrintPreviewTabDelegate::OnDialogClosed(). 430 // PrintPreviewTabDelegate::OnDialogClosed().
430 HtmlDialogUIDelegate* html_dialog_ui_delegate = 431 WebDialogDelegate* web_dialog_delegate =
431 new PrintPreviewTabDelegate(initiator_tab); 432 new PrintPreviewTabDelegate(initiator_tab);
432 // |html_tab_content_delegate|'s owner is |constrained_html_ui_delegate|. 433 // |web_tab_content_delegate|'s owner is |constrained_web_ui_delegate|.
433 PrintPreviewWebContentDelegate* html_tab_content_delegate = 434 PrintPreviewWebContentDelegate* pp_wcd =
434 new PrintPreviewWebContentDelegate(current_browser->profile(), 435 new PrintPreviewWebContentDelegate(current_browser->profile(),
435 initiator_tab); 436 initiator_tab);
436 ConstrainedHtmlUIDelegate* constrained_html_ui_delegate = 437 ConstrainedWebDialogDelegate* constrained_delegate =
437 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(current_browser->profile(), 438 ConstrainedWebDialogUI::CreateConstrainedWebDialog(
438 html_dialog_ui_delegate, 439 current_browser->profile(),
439 html_tab_content_delegate, 440 web_dialog_delegate,
440 initiator_tab); 441 pp_wcd,
441 TabContentsWrapper* preview_tab = constrained_html_ui_delegate->tab(); 442 initiator_tab);
443 TabContentsWrapper* preview_tab = constrained_delegate->tab();
442 EnableInternalPDFPluginForTab(preview_tab); 444 EnableInternalPDFPluginForTab(preview_tab);
443 445
444 // Add an entry to the map. 446 // Add an entry to the map.
445 preview_tab_map_[preview_tab] = initiator_tab; 447 preview_tab_map_[preview_tab] = initiator_tab;
446 waiting_for_new_preview_page_ = true; 448 waiting_for_new_preview_page_ = true;
447 449
448 AddObservers(initiator_tab); 450 AddObservers(initiator_tab);
449 AddObservers(preview_tab); 451 AddObservers(preview_tab);
450 452
451 return preview_tab; 453 return preview_tab;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( 541 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(
540 preview_tab->web_contents()->GetWebUI()->GetController()); 542 preview_tab->web_contents()->GetWebUI()->GetController());
541 if (print_preview_ui) 543 if (print_preview_ui)
542 print_preview_ui->OnTabDestroyed(); 544 print_preview_ui->OnTabDestroyed();
543 545
544 preview_tab_map_.erase(preview_tab); 546 preview_tab_map_.erase(preview_tab);
545 RemoveObservers(preview_tab); 547 RemoveObservers(preview_tab);
546 } 548 }
547 549
548 } // namespace printing 550 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud_unittest.cc ('k') | chrome/browser/ui/browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698