diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 18:51:41 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 18:51:41 +0000 |
commit | 987d506a369f70966f4236917cdca7cde8e68e3d (patch) | |
tree | 321ebb2566969b9d996bd0f1ce5f395d6bc22628 /chrome/browser/views/select_file_dialog.cc | |
parent | 956d033ff82196efedc74533bff9749ee9b82141 (diff) | |
download | chromium_src-987d506a369f70966f4236917cdca7cde8e68e3d.zip chromium_src-987d506a369f70966f4236917cdca7cde8e68e3d.tar.gz chromium_src-987d506a369f70966f4236917cdca7cde8e68e3d.tar.bz2 |
Allow FileBrowse to change title of open/save dialog
Add a DOMMessageHandler to FileBrowse based SelectFileDialog that supports
a "setDialogTitle" call from javascript.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/554136
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37717 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/select_file_dialog.cc')
-rw-r--r-- | chrome/browser/views/select_file_dialog.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/chrome/browser/views/select_file_dialog.cc b/chrome/browser/views/select_file_dialog.cc index 2f5174e7b..6a439f5 100644 --- a/chrome/browser/views/select_file_dialog.cc +++ b/chrome/browser/views/select_file_dialog.cc @@ -16,8 +16,12 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/html_dialog_ui.h" #include "chrome/browser/shell_dialogs.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/views/html_dialog_view.h" #include "chrome/common/url_constants.h" #include "grit/generated_resources.h" +#include "views/window/non_client_view.h" +#include "views/window/window.h" namespace { @@ -105,6 +109,22 @@ class SelectFileDialogImpl : public SelectFileDialog { DISALLOW_COPY_AND_ASSIGN(FileBrowseDelegate); }; + class FileBrowseDelegateHandler : public DOMMessageHandler { + public: + explicit FileBrowseDelegateHandler(FileBrowseDelegate* delegate); + + // DOMMessageHandler implementation. + virtual void RegisterMessages(); + + // Callback for the "setDialogTitle" message. + void HandleSetDialogTitle(const Value* value); + + private: + FileBrowseDelegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(FileBrowseDelegateHandler); + }; + // Notification from FileBrowseDelegate when file browse UI is dismissed. void OnDialogClosed(FileBrowseDelegate* delegate, const std::string& json); @@ -291,6 +311,8 @@ GURL SelectFileDialogImpl::FileBrowseDelegate::GetDialogContentURL() const { void SelectFileDialogImpl::FileBrowseDelegate::GetDOMMessageHandlers( std::vector<DOMMessageHandler*>* handlers) const { + handlers->push_back(new FileBrowseDelegateHandler( + const_cast<FileBrowseDelegate*>(this))); return; } @@ -388,3 +410,35 @@ void SelectFileDialogImpl::FileBrowseDelegate::OnDialogClosed( delete this; return; } + +SelectFileDialogImpl::FileBrowseDelegateHandler::FileBrowseDelegateHandler( + FileBrowseDelegate* delegate) + : delegate_(delegate) { +} + +void SelectFileDialogImpl::FileBrowseDelegateHandler::RegisterMessages() { + dom_ui_->RegisterMessageCallback("setDialogTitle", + NewCallback(this, &FileBrowseDelegateHandler::HandleSetDialogTitle)); +} + +void SelectFileDialogImpl::FileBrowseDelegateHandler::HandleSetDialogTitle( + const Value* value) { + std::wstring new_title = ExtractStringValue(value); + if (new_title != delegate_->title_) { + delegate_->title_ = new_title; + + // Notify the containing view about the title change. + // The current HtmlDialogUIDelegate and HtmlDialogView does not support + // dynamic title change. We hijacked the mechanism between HTMLDialogUI + // and HtmlDialogView to get the HtmlDialgoView and forced it to update + // its title. + // TODO(xiyuan): Change this when the infrastructure is improved. + HtmlDialogUIDelegate** delegate = HtmlDialogUI::GetPropertyAccessor(). + GetProperty(dom_ui_->tab_contents()->property_bag()); + HtmlDialogView* containing_view = static_cast<HtmlDialogView*>(*delegate); + DCHECK(containing_view); + + containing_view->GetWindow()->UpdateWindowTitle(); + containing_view->GetWindow()->GetNonClientView()->SchedulePaint(); + } +} |