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

Side by Side Diff: chrome/browser/ui/views/constrained_html_delegate_views.cc

Issue 8220026: Add new methods to create constrained windows for print preview and release the internal TabConte... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
OLDNEW
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/ui/webui/constrained_html_ui.h" 5 #include "chrome/browser/ui/webui/constrained_html_ui.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h" 10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" 11 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h"
12 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" 12 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h"
13 #include "chrome/browser/ui/webui/html_dialog_ui.h" 13 #include "chrome/browser/ui/webui/html_dialog_ui.h"
14 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
15 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
16 #include "views/view.h" 16 #include "views/view.h"
17 #include "views/widget/widget_delegate.h" 17 #include "views/widget/widget_delegate.h"
18 18
19 class ConstrainedHtmlDelegateViews : public TabContentsContainer, 19 class ConstrainedHtmlDelegateViews : public TabContentsContainer,
20 public ConstrainedHtmlUIDelegate, 20 public ConstrainedHtmlUIDelegate,
21 public views::WidgetDelegate, 21 public views::WidgetDelegate,
22 public HtmlDialogTabContentsDelegate { 22 public HtmlDialogTabContentsDelegate {
23 public: 23 public:
24 ConstrainedHtmlDelegateViews(Profile* profile, 24 ConstrainedHtmlDelegateViews(Profile* profile,
25 HtmlDialogUIDelegate* delegate); 25 HtmlDialogUIDelegate* delegate);
26 ~ConstrainedHtmlDelegateViews(); 26 ~ConstrainedHtmlDelegateViews();
27 27
28 TabContentsWrapper* tab() {
29 return html_tab_contents_.get();
30 }
31
28 // ConstrainedHtmlUIDelegate interface. 32 // ConstrainedHtmlUIDelegate interface.
29 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE; 33 virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE;
30 virtual void OnDialogCloseFromWebUI() OVERRIDE; 34 virtual void OnDialogCloseFromWebUI() OVERRIDE;
35 virtual void ReleaseTabContentsOnDialogClose() OVERRIDE;
31 36
32 // views::WidgetDelegate interface. 37 // views::WidgetDelegate interface.
33 virtual bool CanResize() const OVERRIDE { return true; } 38 virtual bool CanResize() const OVERRIDE { return true; }
34 virtual views::View* GetContentsView() OVERRIDE { 39 virtual views::View* GetContentsView() OVERRIDE {
35 return this; 40 return this;
36 } 41 }
37 virtual void WindowClosing() OVERRIDE { 42 virtual void WindowClosing() OVERRIDE {
38 if (!closed_via_webui_) 43 if (!closed_via_webui_)
39 html_delegate_->OnDialogClosed(""); 44 html_delegate_->OnDialogClosed("");
40 } 45 }
(...skipping 16 matching lines...) Expand all
57 gfx::Size size; 62 gfx::Size size;
58 html_delegate_->GetDialogSize(&size); 63 html_delegate_->GetDialogSize(&size);
59 return size; 64 return size;
60 } 65 }
61 66
62 virtual void ViewHierarchyChanged(bool is_add, 67 virtual void ViewHierarchyChanged(bool is_add,
63 views::View* parent, 68 views::View* parent,
64 views::View* child) OVERRIDE { 69 views::View* child) OVERRIDE {
65 TabContentsContainer::ViewHierarchyChanged(is_add, parent, child); 70 TabContentsContainer::ViewHierarchyChanged(is_add, parent, child);
66 if (is_add && child == this) { 71 if (is_add && child == this) {
67 ChangeTabContents(&html_tab_contents_); 72 ChangeTabContents(html_tab_contents_->tab_contents());
68 } 73 }
69 } 74 }
70 75
71 void set_window(ConstrainedWindow* window) { 76 void set_window(ConstrainedWindow* window) {
72 window_ = window; 77 window_ = window;
73 } 78 }
74 79
75 private: 80 private:
76 TabContents html_tab_contents_; 81 scoped_ptr<TabContentsWrapper> html_tab_contents_;
77 82
78 HtmlDialogUIDelegate* html_delegate_; 83 HtmlDialogUIDelegate* html_delegate_;
79 84
80 // The constrained window that owns |this|. Saved so we can close it later. 85 // The constrained window that owns |this|. Saved so we can close it later.
81 ConstrainedWindow* window_; 86 ConstrainedWindow* window_;
82 87
83 // Was the dialog closed from WebUI (in which case |html_delegate_|'s 88 // Was the dialog closed from WebUI (in which case |html_delegate_|'s
84 // OnDialogClosed() method has already been called)? 89 // OnDialogClosed() method has already been called)?
85 bool closed_via_webui_; 90 bool closed_via_webui_;
91
92 // If true, release |tab_| on close instead of destroying it.
93 bool release_tab_on_close_;
86 }; 94 };
87 95
88 ConstrainedHtmlDelegateViews::ConstrainedHtmlDelegateViews( 96 ConstrainedHtmlDelegateViews::ConstrainedHtmlDelegateViews(
89 Profile* profile, 97 Profile* profile,
90 HtmlDialogUIDelegate* delegate) 98 HtmlDialogUIDelegate* delegate)
91 : HtmlDialogTabContentsDelegate(profile), 99 : HtmlDialogTabContentsDelegate(profile),
92 html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL),
93 html_delegate_(delegate), 100 html_delegate_(delegate),
94 window_(NULL), 101 window_(NULL),
95 closed_via_webui_(false) { 102 closed_via_webui_(false),
103 release_tab_on_close_(false) {
96 CHECK(delegate); 104 CHECK(delegate);
97 html_tab_contents_.set_delegate(this); 105 TabContents* tab_contents =
106 new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL);
107 html_tab_contents_.reset(new TabContentsWrapper(tab_contents));
108 tab_contents->set_delegate(this);
98 109
99 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it. 110 // Set |this| as a property so the ConstrainedHtmlUI can retrieve it.
100 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty( 111 ConstrainedHtmlUI::GetPropertyAccessor().SetProperty(
101 html_tab_contents_.property_bag(), this); 112 html_tab_contents_->tab_contents()->property_bag(), this);
102 html_tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(), 113 tab_contents->controller().LoadURL(delegate->GetDialogContentURL(),
103 GURL(), 114 GURL(),
104 PageTransition::START_PAGE, 115 PageTransition::START_PAGE,
105 std::string()); 116 std::string());
106 } 117 }
107 118
108 ConstrainedHtmlDelegateViews::~ConstrainedHtmlDelegateViews() { 119 ConstrainedHtmlDelegateViews::~ConstrainedHtmlDelegateViews() {
120 if (release_tab_on_close_)
121 ignore_result(html_tab_contents_.release());
109 } 122 }
110 123
111 HtmlDialogUIDelegate* ConstrainedHtmlDelegateViews::GetHtmlDialogUIDelegate() { 124 HtmlDialogUIDelegate* ConstrainedHtmlDelegateViews::GetHtmlDialogUIDelegate() {
112 return html_delegate_; 125 return html_delegate_;
113 } 126 }
114 127
115 void ConstrainedHtmlDelegateViews::OnDialogCloseFromWebUI() { 128 void ConstrainedHtmlDelegateViews::OnDialogCloseFromWebUI() {
116 closed_via_webui_ = true; 129 closed_via_webui_ = true;
117 window_->CloseConstrainedWindow(); 130 window_->CloseConstrainedWindow();
118 } 131 }
119 132
133 void ConstrainedHtmlDelegateViews::ReleaseTabContentsOnDialogClose() {
134 release_tab_on_close_ = true;
135 }
136
120 // static 137 // static
121 ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog( 138 ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
122 Profile* profile, 139 Profile* profile,
123 HtmlDialogUIDelegate* delegate, 140 HtmlDialogUIDelegate* delegate,
124 TabContentsWrapper* container) { 141 TabContentsWrapper* container) {
125 #if defined(USE_AURA) 142 #if defined(USE_AURA)
126 // TODO(saintlou): Another atrocious hack until we get PureView version. 143 // TODO(saintlou): Another atrocious hack until we get PureView version.
127 return NULL; 144 return NULL;
128 #else 145 #else
129 ConstrainedHtmlDelegateViews* constrained_delegate = 146 ConstrainedHtmlDelegateViews* constrained_delegate =
130 new ConstrainedHtmlDelegateViews(profile, delegate); 147 new ConstrainedHtmlDelegateViews(profile, delegate);
131 ConstrainedWindow* constrained_window = 148 ConstrainedWindow* constrained_window =
132 new ConstrainedWindowViews(container, constrained_delegate); 149 new ConstrainedWindowViews(container, constrained_delegate);
133 constrained_delegate->set_window(constrained_window); 150 constrained_delegate->set_window(constrained_window);
134 return constrained_window; 151 return constrained_window;
135 #endif 152 #endif
136 } 153 }
154 TabContentsWrapper* ConstrainedHtmlUI::CreateConstrainedPrintPreviewHtmlUI(
155 Profile* profile,
156 HtmlDialogUIDelegate* delegate,
157 TabContentsWrapper* container) {
158 #if defined(USE_AURA)
159 // TODO(saintlou): Another atrocious hack until we get PureView version.
160 return NULL;
161 #else
162 ConstrainedHtmlDelegateViews* constrained_delegate =
163 new ConstrainedHtmlDelegateViews(profile, delegate);
164 ConstrainedWindow* constrained_window =
165 new ConstrainedWindowViews(container, constrained_delegate);
166 constrained_delegate->set_window(constrained_window);
167 return constrained_delegate->tab();
168 #endif
169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698