| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/modal_html_dialog_delegate.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "chrome/browser/browser_list.h" | |
| 10 #include "content/browser/renderer_host/render_view_host.h" | |
| 11 #include "content/browser/tab_contents/tab_contents.h" | |
| 12 #include "content/common/notification_source.h" | |
| 13 #include "ui/gfx/size.h" | |
| 14 | |
| 15 ModalHtmlDialogDelegate::ModalHtmlDialogDelegate( | |
| 16 const GURL& url, int width, int height, const std::string& json_arguments, | |
| 17 IPC::Message* sync_result, TabContents* contents) | |
| 18 : contents_(contents), | |
| 19 sync_response_(sync_result) { | |
| 20 // Listen for when the TabContents or its renderer dies. | |
| 21 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, | |
| 22 Source<TabContents>(contents_)); | |
| 23 | |
| 24 // This information is needed to show the dialog HTML content. | |
| 25 params_.url = url; | |
| 26 params_.height = height; | |
| 27 params_.width = width; | |
| 28 params_.json_input = json_arguments; | |
| 29 } | |
| 30 | |
| 31 ModalHtmlDialogDelegate::~ModalHtmlDialogDelegate() { | |
| 32 } | |
| 33 | |
| 34 void ModalHtmlDialogDelegate::Observe(NotificationType type, | |
| 35 const NotificationSource& source, | |
| 36 const NotificationDetails& details) { | |
| 37 DCHECK(type == NotificationType::TAB_CONTENTS_DISCONNECTED); | |
| 38 DCHECK(Source<TabContents>(source).ptr() == contents_); | |
| 39 registrar_.RemoveAll(); | |
| 40 contents_ = NULL; | |
| 41 } | |
| 42 | |
| 43 bool ModalHtmlDialogDelegate::IsDialogModal() const { | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 std::wstring ModalHtmlDialogDelegate::GetDialogTitle() const { | |
| 48 return L"Gears"; | |
| 49 } | |
| 50 | |
| 51 GURL ModalHtmlDialogDelegate::GetDialogContentURL() const { | |
| 52 return params_.url; | |
| 53 } | |
| 54 | |
| 55 void ModalHtmlDialogDelegate::GetDialogSize(gfx::Size* size) const { | |
| 56 size->set_width(params_.width); | |
| 57 size->set_height(params_.height); | |
| 58 } | |
| 59 | |
| 60 std::string ModalHtmlDialogDelegate::GetDialogArgs() const { | |
| 61 return params_.json_input; | |
| 62 } | |
| 63 | |
| 64 void ModalHtmlDialogDelegate::OnDialogClosed(const std::string& json_retval) { | |
| 65 // Our TabContents may have died before this point. | |
| 66 if (contents_ && contents_->render_view_host()) { | |
| 67 contents_->render_view_host()->ModalHTMLDialogClosed(sync_response_, | |
| 68 json_retval); | |
| 69 } | |
| 70 | |
| 71 // We are done with this request, so delete us. | |
| 72 delete this; | |
| 73 } | |
| 74 | |
| 75 bool ModalHtmlDialogDelegate::ShouldShowDialogTitle() const { | |
| 76 return true; | |
| 77 } | |
| OLD | NEW |