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

Unified Diff: chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm

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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm
===================================================================
--- chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm (revision 104824)
+++ chrome/browser/ui/cocoa/constrained_html_delegate_mac.mm (working copy)
@@ -23,8 +23,15 @@
public:
ConstrainedHtmlDelegateMac(Profile* profile,
HtmlDialogUIDelegate* delegate);
- ~ConstrainedHtmlDelegateMac() {}
+ ~ConstrainedHtmlDelegateMac() {
+ if (release_tab_on_close_)
+ ignore_result(tab_.release());
+ }
+ TabContentsWrapper* tab() {
+ return tab_.get();
+ }
+
// ConstrainedWindowMacDelegateCustomSheet -----------------------------------
virtual void DeleteDelegate() OVERRIDE {
// From ConstrainedWindowMacDelegate: "you MUST close the sheet belonging to
@@ -39,6 +46,7 @@
// ConstrainedHtmlDelegate ---------------------------------------------------
virtual HtmlDialogUIDelegate* GetHtmlDialogUIDelegate() OVERRIDE;
virtual void OnDialogCloseFromWebUI() OVERRIDE;
+ virtual void ReleaseTabContentsOnDialogClose() OVERRIDE;
// HtmlDialogTabContentsDelegate ---------------------------------------------
virtual void HandleKeyboardEvent(
@@ -49,7 +57,8 @@
}
private:
- TabContents tab_contents_; // Holds the HTML to be displayed in the sheet.
+ // Holds the HTML to be displayed in the sheet.
+ scoped_ptr<TabContentsWrapper> tab_;
HtmlDialogUIDelegate* html_delegate_; // weak.
// The constrained window that owns |this|. Saved here because it needs to be
@@ -60,6 +69,9 @@
// OnDialogClosed() method has already been called)?
bool closed_via_webui_;
+ // If true, release |tab_| on close instead of destroying it.
+ bool release_tab_on_close_;
+
DISALLOW_COPY_AND_ASSIGN(ConstrainedHtmlDelegateMac);
};
@@ -80,18 +92,21 @@
Profile* profile,
HtmlDialogUIDelegate* delegate)
: HtmlDialogTabContentsDelegate(profile),
- tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL),
html_delegate_(delegate),
constrained_window_(NULL),
- closed_via_webui_(false) {
- tab_contents_.set_delegate(this);
+ closed_via_webui_(false),
+ release_tab_on_close_(false) {
+ TabContents* tab_contents =
+ new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL, NULL);
+ tab_.reset(new TabContentsWrapper(tab_contents));
+ tab_contents->set_delegate(this);
// Set |this| as a property on the tab contents so that the ConstrainedHtmlUI
// can get a reference to |this|.
ConstrainedHtmlUI::GetPropertyAccessor().SetProperty(
- tab_contents_.property_bag(), this);
+ tab_contents->property_bag(), this);
- tab_contents_.controller().LoadURL(delegate->GetDialogContentURL(),
+ tab_contents->controller().LoadURL(delegate->GetDialogContentURL(),
GURL(), PageTransition::START_PAGE,
std::string());
@@ -109,7 +124,7 @@
backing:NSBackingStoreBuffered
defer:YES]);
- [window.get() setContentView:tab_contents_.GetNativeView()];
+ [window.get() setContentView:tab_contents->GetNativeView()];
// Set the custom sheet to point to the new window.
ConstrainedWindowMacDelegateCustomSheet::init(
@@ -130,6 +145,10 @@
constrained_window_->CloseConstrainedWindow();
}
+void ConstrainedHtmlDelegateMac::ReleaseTabContentsOnDialogClose() {
+ release_tab_on_close_ = true;
+}
+
// static
ConstrainedWindow* ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
Profile* profile,
@@ -145,6 +164,21 @@
return constrained_window;
}
+// static
+TabContentsWrapper* ConstrainedHtmlUI::CreateConstrainedPrintPreviewHtmlUI(
+ Profile* profile,
+ HtmlDialogUIDelegate* delegate,
+ TabContentsWrapper* wrapper) {
+ // Deleted when ConstrainedHtmlDelegateMac::DeleteDelegate() runs.
+ ConstrainedHtmlDelegateMac* constrained_delegate =
+ new ConstrainedHtmlDelegateMac(profile, delegate);
+ // Deleted when ConstrainedHtmlDelegateMac::OnDialogCloseFromWebUI() runs.
+ ConstrainedWindow* constrained_window =
+ new ConstrainedWindowMac(wrapper, constrained_delegate);
+ constrained_delegate->set_window(constrained_window);
+ return constrained_delegate->tab();
+}
+
@implementation ConstrainedHtmlDialogSheetCocoa
- (id)initWithConstrainedHtmlDelegateMac:

Powered by Google App Engine
This is Rietveld 408576698