OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #import <Cocoa/Cocoa.h> |
| 12 |
| 13 #include "app/gfx/native_widget_types.h" |
| 14 #include "base/basictypes.h" |
| 15 #include "base/scoped_ptr.h" |
| 16 #include "chrome/browser/dom_ui/html_dialog_ui.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 18 #include "googleurl/src/gurl.h" |
| 19 |
| 20 class Browser; |
| 21 |
| 22 // Thin bridge that routes notifications to |
| 23 // HtmlDialogWindowController's member variables. |
| 24 class HtmlDialogWindowDelegateBridge : public HtmlDialogUIDelegate, |
| 25 public TabContentsDelegate { |
| 26 public: |
| 27 // All parameters must be non-NULL/non-nil. |
| 28 HtmlDialogWindowDelegateBridge(HtmlDialogUIDelegate* delegate, |
| 29 NSWindowController* controller, |
| 30 NSWindow* window, |
| 31 Browser* browser); |
| 32 |
| 33 virtual ~HtmlDialogWindowDelegateBridge(); |
| 34 |
| 35 // Called when the window is directly closed, e.g. from the close |
| 36 // button or from an accelerator. |
| 37 void WindowControllerClosed(); |
| 38 |
| 39 // HtmlDialogUIDelegate declarations. |
| 40 virtual bool IsDialogModal() const; |
| 41 virtual std::wstring GetDialogTitle() const; |
| 42 virtual GURL GetDialogContentURL() const; |
| 43 virtual void GetDOMMessageHandlers( |
| 44 std::vector<DOMMessageHandler*>* handlers) const; |
| 45 virtual void GetDialogSize(gfx::Size* size) const; |
| 46 virtual std::string GetDialogArgs() const; |
| 47 virtual void OnDialogClosed(const std::string& json_retval); |
| 48 |
| 49 // TabContentsDelegate declarations. |
| 50 virtual void OpenURLFromTab(TabContents* source, |
| 51 const GURL& url, const GURL& referrer, |
| 52 WindowOpenDisposition disposition, |
| 53 PageTransition::Type transition); |
| 54 virtual void NavigationStateChanged(const TabContents* source, |
| 55 unsigned changed_flags); |
| 56 virtual void AddNewContents(TabContents* source, |
| 57 TabContents* new_contents, |
| 58 WindowOpenDisposition disposition, |
| 59 const gfx::Rect& initial_pos, |
| 60 bool user_gesture); |
| 61 virtual void ActivateContents(TabContents* contents); |
| 62 virtual void LoadingStateChanged(TabContents* source); |
| 63 virtual void CloseContents(TabContents* source); |
| 64 virtual void MoveContents(TabContents* source, const gfx::Rect& pos); |
| 65 virtual bool IsPopup(TabContents* source); |
| 66 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); |
| 67 virtual void URLStarredChanged(TabContents* source, bool starred); |
| 68 virtual void UpdateTargetURL(TabContents* source, const GURL& url); |
| 69 |
| 70 private: |
| 71 HtmlDialogUIDelegate* delegate_; // weak |
| 72 NSWindowController* controller_; // weak |
| 73 NSWindow* window_; // weak |
| 74 Browser* browser_; // weak |
| 75 |
| 76 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out |
| 77 // afterwards so that no other HtmlDialogUIDelegate calls are sent |
| 78 // to it. Returns whether or not the OnDialogClosed() was actually |
| 79 // called on the delegate. |
| 80 bool DelegateOnDialogClosed(const std::string& json_retval); |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(HtmlDialogWindowDelegateBridge); |
| 83 }; |
| 84 |
| 85 // This controller manages a dialog box with properties and HTML content taken |
| 86 // from a HTMLDialogUIDelegate object. |
| 87 @interface HtmlDialogWindowController : NSWindowController { |
| 88 @private |
| 89 Browser* browser_; // weak |
| 90 // Order here is important, as tab_contents_ may send messages to |
| 91 // delegate_ when it gets destroyed. |
| 92 scoped_ptr<HtmlDialogWindowDelegateBridge> delegate_; |
| 93 scoped_ptr<TabContents> tab_contents_; |
| 94 } |
| 95 |
| 96 // Creates and shows an HtmlDialogWindowController with the given |
| 97 // delegate, parent window, and browser, none of which may be NULL. |
| 98 // The window is automatically destroyed when it is closed. |
| 99 + (void)showHtmlDialog:(HtmlDialogUIDelegate*)delegate |
| 100 parentWindow:(gfx::NativeWindow)parent_window |
| 101 browser:(Browser*)browser; |
| 102 |
| 103 @end |
| 104 |
| 105 @interface HtmlDialogWindowController (TestingAPI) |
| 106 |
| 107 // This is the designated initializer. However, this is exposed only |
| 108 // for testing; use showHtmlDialog instead. |
| 109 - (id)initWithDelegate:(HtmlDialogUIDelegate*)delegate |
| 110 parentWindow:(gfx::NativeWindow)parent_window |
| 111 browser:(Browser*)browser; |
| 112 |
| 113 // 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 |
| 115 // called before showWindow. |
| 116 - (void)loadDialogContents; |
| 117 |
| 118 @end |
| 119 |
| 120 #endif // CHROME_BROWSER_COCOA_HTML_DIALOG_WINDOW_CONTROLLER_H_ |
| 121 |
OLD | NEW |