| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ | 6 #define CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #import <Cocoa/Cocoa.h> | 11 #import <Cocoa/Cocoa.h> |
| 12 | 12 |
| 13 #include "app/gfx/native_widget_types.h" | 13 #include "app/gfx/native_widget_types.h" |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "chrome/browser/dom_ui/html_dialog_ui.h" | 16 #include "chrome/browser/dom_ui/html_dialog_ui.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 17 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 | 19 |
| 20 class Browser; | 20 class Browser; |
| 21 | 21 |
| 22 // Thin bridge that routes notifications to | 22 // Thin bridge that routes notifications to |
| 23 // HtmlDialogWindowController's member variables. | 23 // HtmlDialogWindowController's member variables. |
| 24 // |
| 25 // TODO(akalin): This doesn't need to be in the .h file; move it to the |
| 26 // .mm file. |
| 24 class HtmlDialogWindowDelegateBridge : public HtmlDialogUIDelegate, | 27 class HtmlDialogWindowDelegateBridge : public HtmlDialogUIDelegate, |
| 25 public TabContentsDelegate { | 28 public TabContentsDelegate { |
| 26 public: | 29 public: |
| 27 // All parameters must be non-NULL/non-nil. | 30 // All parameters must be non-NULL/non-nil. |
| 28 HtmlDialogWindowDelegateBridge(HtmlDialogUIDelegate* delegate, | 31 HtmlDialogWindowDelegateBridge(NSWindowController* controller, |
| 29 NSWindowController* controller, | 32 HtmlDialogUIDelegate* delegate, |
| 30 NSWindow* window, | |
| 31 Browser* browser); | 33 Browser* browser); |
| 32 | 34 |
| 33 virtual ~HtmlDialogWindowDelegateBridge(); | 35 virtual ~HtmlDialogWindowDelegateBridge(); |
| 34 | 36 |
| 35 // Called when the window is directly closed, e.g. from the close | 37 // Called when the window is directly closed, e.g. from the close |
| 36 // button or from an accelerator. | 38 // button or from an accelerator. |
| 37 void WindowControllerClosed(); | 39 void WindowControllerClosed(); |
| 38 | 40 |
| 39 // HtmlDialogUIDelegate declarations. | 41 // HtmlDialogUIDelegate declarations. |
| 40 virtual bool IsDialogModal() const; | 42 virtual bool IsDialogModal() const; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 virtual void ActivateContents(TabContents* contents); | 63 virtual void ActivateContents(TabContents* contents); |
| 62 virtual void LoadingStateChanged(TabContents* source); | 64 virtual void LoadingStateChanged(TabContents* source); |
| 63 virtual void CloseContents(TabContents* source); | 65 virtual void CloseContents(TabContents* source); |
| 64 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); | 66 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); |
| 65 virtual bool IsPopup(TabContents* source); | 67 virtual bool IsPopup(TabContents* source); |
| 66 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); | 68 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); |
| 67 virtual void URLStarredChanged(TabContents* source, bool starred); | 69 virtual void URLStarredChanged(TabContents* source, bool starred); |
| 68 virtual void UpdateTargetURL(TabContents* source, const GURL& url); | 70 virtual void UpdateTargetURL(TabContents* source, const GURL& url); |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 HtmlDialogUIDelegate* delegate_; // weak | |
| 72 NSWindowController* controller_; // weak | 73 NSWindowController* controller_; // weak |
| 73 NSWindow* window_; // weak | 74 HtmlDialogUIDelegate* delegate_; // weak, owned by controller_ |
| 74 Browser* browser_; // weak | 75 Browser* browser_; // weak, owned by controller_ |
| 75 | 76 |
| 76 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out | 77 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out |
| 77 // afterwards so that no other HtmlDialogUIDelegate calls are sent | 78 // afterwards so that no other HtmlDialogUIDelegate calls are sent |
| 78 // to it. Returns whether or not the OnDialogClosed() was actually | 79 // to it. Returns whether or not the OnDialogClosed() was actually |
| 79 // called on the delegate. | 80 // called on the delegate. |
| 80 bool DelegateOnDialogClosed(const std::string& json_retval); | 81 bool DelegateOnDialogClosed(const std::string& json_retval); |
| 81 | 82 |
| 82 DISALLOW_COPY_AND_ASSIGN(HtmlDialogWindowDelegateBridge); | 83 DISALLOW_COPY_AND_ASSIGN(HtmlDialogWindowDelegateBridge); |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 // This controller manages a dialog box with properties and HTML content taken | 86 // This controller manages a dialog box with properties and HTML content taken |
| 86 // from a HTMLDialogUIDelegate object. | 87 // from a HTMLDialogUIDelegate object. |
| 87 @interface HtmlDialogWindowController : NSWindowController { | 88 @interface HtmlDialogWindowController : NSWindowController { |
| 88 @private | 89 @private |
| 89 Browser* browser_; // weak | 90 // An HTML dialog can exist separately from a window in OS X, so this |
| 91 // controller needs its own browser. |
| 92 scoped_ptr<Browser> browser_; |
| 90 // Order here is important, as tab_contents_ may send messages to | 93 // Order here is important, as tab_contents_ may send messages to |
| 91 // delegate_ when it gets destroyed. | 94 // delegate_ when it gets destroyed. |
| 92 scoped_ptr<HtmlDialogWindowDelegateBridge> delegate_; | 95 scoped_ptr<HtmlDialogWindowDelegateBridge> delegate_; |
| 93 scoped_ptr<TabContents> tab_contents_; | 96 scoped_ptr<TabContents> tabContents_; |
| 94 } | 97 } |
| 95 | 98 |
| 96 // Creates and shows an HtmlDialogWindowController with the given | 99 // Creates and shows an HtmlDialogWindowController with the given |
| 97 // delegate, parent window, and browser, none of which may be NULL. | 100 // delegate, parent window, and profile, none of which may be NULL. |
| 98 // The window is automatically destroyed when it is closed. | 101 // The window is automatically destroyed when it is closed. |
| 102 // |
| 103 // TODO(akalin): Handle a NULL parentWindow as HTML dialogs may be launched |
| 104 // without any browser windows being present (on OS X). |
| 99 + (void)showHtmlDialog:(HtmlDialogUIDelegate*)delegate | 105 + (void)showHtmlDialog:(HtmlDialogUIDelegate*)delegate |
| 100 parentWindow:(gfx::NativeWindow)parent_window | 106 profile:(Profile*)profile |
| 101 browser:(Browser*)browser; | 107 parentWindow:(gfx::NativeWindow)parent_window; |
| 102 | 108 |
| 103 @end | 109 @end |
| 104 | 110 |
| 105 @interface HtmlDialogWindowController (TestingAPI) | 111 @interface HtmlDialogWindowController (TestingAPI) |
| 106 | 112 |
| 107 // This is the designated initializer. However, this is exposed only | 113 // This is the designated initializer. However, this is exposed only |
| 108 // for testing; use showHtmlDialog instead. | 114 // for testing; use showHtmlDialog instead. |
| 109 - (id)initWithDelegate:(HtmlDialogUIDelegate*)delegate | 115 - (id)initWithDelegate:(HtmlDialogUIDelegate*)delegate |
| 110 parentWindow:(gfx::NativeWindow)parent_window | 116 profile:(Profile*)profile |
| 111 browser:(Browser*)browser; | 117 parentWindow:(gfx::NativeWindow)parentWindow; |
| 112 | 118 |
| 113 // Loads the HTML content from the delegate; this is not a lightweight | 119 // Loads the HTML content from the delegate; this is not a lightweight |
| 114 // process which is why it is not part of the constructor. Must be | 120 // process which is why it is not part of the constructor. Must be |
| 115 // called before showWindow. | 121 // called before showWindow. |
| 116 - (void)loadDialogContents; | 122 - (void)loadDialogContents; |
| 117 | 123 |
| 118 @end | 124 @end |
| 119 | 125 |
| 120 #endif // CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ | 126 #endif // CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ |
| 121 | 127 |
| OLD | NEW |