| OLD | NEW |
| 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 #import "chrome/browser/ui/cocoa/html_dialog_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/html_dialog_window_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 Profile* profile, | 28 Profile* profile, |
| 29 HtmlDialogUIDelegate* delegate); | 29 HtmlDialogUIDelegate* delegate); |
| 30 | 30 |
| 31 virtual ~HtmlDialogWindowDelegateBridge(); | 31 virtual ~HtmlDialogWindowDelegateBridge(); |
| 32 | 32 |
| 33 // Called when the window is directly closed, e.g. from the close | 33 // Called when the window is directly closed, e.g. from the close |
| 34 // button or from an accelerator. | 34 // button or from an accelerator. |
| 35 void WindowControllerClosed(); | 35 void WindowControllerClosed(); |
| 36 | 36 |
| 37 // HtmlDialogUIDelegate declarations. | 37 // HtmlDialogUIDelegate declarations. |
| 38 virtual bool IsDialogModal() const; | 38 virtual bool IsDialogModal() const OVERRIDE; |
| 39 virtual std::wstring GetDialogTitle() const; | 39 virtual string16 GetDialogTitle() const OVERRIDE; |
| 40 virtual GURL GetDialogContentURL() const; | 40 virtual GURL GetDialogContentURL() const OVERRIDE; |
| 41 virtual void GetWebUIMessageHandlers( | 41 virtual void GetWebUIMessageHandlers( |
| 42 std::vector<WebUIMessageHandler*>* handlers) const; | 42 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
| 43 virtual void GetDialogSize(gfx::Size* size) const; | 43 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; |
| 44 virtual std::string GetDialogArgs() const; | 44 virtual std::string GetDialogArgs() const OVERRIDE; |
| 45 virtual void OnDialogClosed(const std::string& json_retval); | 45 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
| 46 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) { } | 46 virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) |
| 47 virtual bool ShouldShowDialogTitle() const { return true; } | 47 OVERRIDE { } |
| 48 virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; } |
| 48 | 49 |
| 49 // HtmlDialogTabContentsDelegate declarations. | 50 // HtmlDialogTabContentsDelegate declarations. |
| 50 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); | 51 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); |
| 51 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); | 52 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 HtmlDialogWindowController* controller_; // weak | 55 HtmlDialogWindowController* controller_; // weak |
| 55 HtmlDialogUIDelegate* delegate_; // weak, owned by controller_ | 56 HtmlDialogUIDelegate* delegate_; // weak, owned by controller_ |
| 56 | 57 |
| 57 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out | 58 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // to NULL when the window is closed. | 117 // to NULL when the window is closed. |
| 117 | 118 |
| 118 bool HtmlDialogWindowDelegateBridge::IsDialogModal() const { | 119 bool HtmlDialogWindowDelegateBridge::IsDialogModal() const { |
| 119 // TODO(akalin): Support modal dialog boxes. | 120 // TODO(akalin): Support modal dialog boxes. |
| 120 if (delegate_ && delegate_->IsDialogModal()) { | 121 if (delegate_ && delegate_->IsDialogModal()) { |
| 121 LOG(WARNING) << "Modal HTML dialogs are not supported yet"; | 122 LOG(WARNING) << "Modal HTML dialogs are not supported yet"; |
| 122 } | 123 } |
| 123 return false; | 124 return false; |
| 124 } | 125 } |
| 125 | 126 |
| 126 std::wstring HtmlDialogWindowDelegateBridge::GetDialogTitle() const { | 127 string16 HtmlDialogWindowDelegateBridge::GetDialogTitle() const { |
| 127 return delegate_ ? delegate_->GetDialogTitle() : L""; | 128 return delegate_ ? delegate_->GetDialogTitle() : string16(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 GURL HtmlDialogWindowDelegateBridge::GetDialogContentURL() const { | 131 GURL HtmlDialogWindowDelegateBridge::GetDialogContentURL() const { |
| 131 return delegate_ ? delegate_->GetDialogContentURL() : GURL(); | 132 return delegate_ ? delegate_->GetDialogContentURL() : GURL(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void HtmlDialogWindowDelegateBridge::GetWebUIMessageHandlers( | 135 void HtmlDialogWindowDelegateBridge::GetWebUIMessageHandlers( |
| 135 std::vector<WebUIMessageHandler*>* handlers) const { | 136 std::vector<WebUIMessageHandler*>* handlers) const { |
| 136 if (delegate_) { | 137 if (delegate_) { |
| 137 delegate_->GetWebUIMessageHandlers(handlers); | 138 delegate_->GetWebUIMessageHandlers(handlers); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 defer:YES]); | 248 defer:YES]); |
| 248 if (!window.get()) { | 249 if (!window.get()) { |
| 249 return nil; | 250 return nil; |
| 250 } | 251 } |
| 251 self = [super initWithWindow:window]; | 252 self = [super initWithWindow:window]; |
| 252 if (!self) { | 253 if (!self) { |
| 253 return nil; | 254 return nil; |
| 254 } | 255 } |
| 255 [window setWindowController:self]; | 256 [window setWindowController:self]; |
| 256 [window setDelegate:self]; | 257 [window setDelegate:self]; |
| 257 [window setTitle:base::SysWideToNSString(delegate->GetDialogTitle())]; | 258 [window setTitle:base::SysUTF16ToNSString(delegate->GetDialogTitle())]; |
| 258 [window center]; | 259 [window center]; |
| 259 delegate_.reset(new HtmlDialogWindowDelegateBridge(self, profile, delegate)); | 260 delegate_.reset(new HtmlDialogWindowDelegateBridge(self, profile, delegate)); |
| 260 return self; | 261 return self; |
| 261 } | 262 } |
| 262 | 263 |
| 263 - (void)loadDialogContents { | 264 - (void)loadDialogContents { |
| 264 tabContents_.reset(new TabContents( | 265 tabContents_.reset(new TabContents( |
| 265 delegate_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL)); | 266 delegate_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL)); |
| 266 [[self window] setContentView:tabContents_->GetNativeView()]; | 267 [[self window] setContentView:tabContents_->GetNativeView()]; |
| 267 tabContents_->set_delegate(delegate_.get()); | 268 tabContents_->set_delegate(delegate_.get()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 279 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender | 280 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender |
| 280 // to do the above doesn't work. | 281 // to do the above doesn't work. |
| 281 } | 282 } |
| 282 | 283 |
| 283 - (void)windowWillClose:(NSNotification*)notification { | 284 - (void)windowWillClose:(NSNotification*)notification { |
| 284 delegate_->WindowControllerClosed(); | 285 delegate_->WindowControllerClosed(); |
| 285 [self autorelease]; | 286 [self autorelease]; |
| 286 } | 287 } |
| 287 | 288 |
| 288 @end | 289 @end |
| OLD | NEW |