OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_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/property_bag.h" | 9 #include "base/property_bag.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #import "chrome/browser/ui/browser_dialogs.h" | 13 #import "chrome/browser/ui/browser_dialogs.h" |
14 #import "chrome/browser/ui/cocoa/browser_command_executor.h" | 14 #import "chrome/browser/ui/cocoa/browser_command_executor.h" |
15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 15 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
16 #include "chrome/browser/ui/dialog_style.h" | 16 #include "chrome/browser/ui/dialog_style.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/browser/ui/webui/html_dialog_controller.h" | 18 #include "chrome/browser/ui/webui/web_dialog_controller.h" |
19 #include "chrome/browser/ui/webui/html_dialog_tab_contents_delegate.h" | 19 #include "chrome/browser/ui/webui/web_dialog_web_contents_delegate.h" |
20 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 20 #include "chrome/browser/ui/webui/web_dialog_ui.h" |
21 #include "content/public/browser/native_web_keyboard_event.h" | 21 #include "content/public/browser/native_web_keyboard_event.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_ui_message_handler.h" | 23 #include "content/public/browser/web_ui_message_handler.h" |
24 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
25 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
26 | 26 |
27 using content::WebContents; | 27 using content::WebContents; |
28 using content::WebUIMessageHandler; | 28 using content::WebUIMessageHandler; |
29 | 29 |
30 // Thin bridge that routes notifications to | 30 // Thin bridge that routes notifications to |
31 // HtmlDialogWindowController's member variables. | 31 // WebDialogWindowController's member variables. |
32 class HtmlDialogWindowDelegateBridge : public HtmlDialogUIDelegate, | 32 class WebDialogWindowDelegateBridge |
33 public HtmlDialogTabContentsDelegate { | 33 : public WebDialogDelegate, |
| 34 public WebDialogWebContentsDelegate { |
34 public: | 35 public: |
35 // All parameters must be non-NULL/non-nil. | 36 // All parameters must be non-NULL/non-nil. |
36 HtmlDialogWindowDelegateBridge(HtmlDialogWindowController* controller, | 37 WebDialogWindowDelegateBridge(WebDialogWindowController* controller, |
37 Profile* profile, | 38 Profile* profile, |
38 Browser* browser, | 39 Browser* browser, |
39 HtmlDialogUIDelegate* delegate); | 40 WebDialogDelegate* delegate); |
40 | 41 |
41 virtual ~HtmlDialogWindowDelegateBridge(); | 42 virtual ~WebDialogWindowDelegateBridge(); |
42 | 43 |
43 // Called when the window is directly closed, e.g. from the close | 44 // Called when the window is directly closed, e.g. from the close |
44 // button or from an accelerator. | 45 // button or from an accelerator. |
45 void WindowControllerClosed(); | 46 void WindowControllerClosed(); |
46 | 47 |
47 // HtmlDialogUIDelegate declarations. | 48 // WebDialogDelegate declarations. |
48 virtual ui::ModalType GetDialogModalType() const OVERRIDE; | 49 virtual ui::ModalType GetDialogModalType() const OVERRIDE; |
49 virtual string16 GetDialogTitle() const OVERRIDE; | 50 virtual string16 GetDialogTitle() const OVERRIDE; |
50 virtual GURL GetDialogContentURL() const OVERRIDE; | 51 virtual GURL GetDialogContentURL() const OVERRIDE; |
51 virtual void GetWebUIMessageHandlers( | 52 virtual void GetWebUIMessageHandlers( |
52 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; | 53 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE; |
53 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; | 54 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; |
54 virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE; | 55 virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE; |
55 virtual std::string GetDialogArgs() const OVERRIDE; | 56 virtual std::string GetDialogArgs() const OVERRIDE; |
56 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | 57 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
57 virtual void OnCloseContents(WebContents* source, | 58 virtual void OnCloseContents(WebContents* source, |
58 bool* out_close_dialog) OVERRIDE; | 59 bool* out_close_dialog) OVERRIDE; |
59 virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; } | 60 virtual bool ShouldShowDialogTitle() const OVERRIDE { return true; } |
60 | 61 |
61 // HtmlDialogTabContentsDelegate declarations. | 62 // WebDialogWebContentsDelegate declarations. |
62 virtual void MoveContents(WebContents* source, const gfx::Rect& pos); | 63 virtual void MoveContents(WebContents* source, const gfx::Rect& pos); |
63 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); | 64 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event); |
64 virtual void CloseContents(WebContents* source) OVERRIDE; | 65 virtual void CloseContents(WebContents* source) OVERRIDE; |
65 virtual content::WebContents* OpenURLFromTab( | 66 virtual content::WebContents* OpenURLFromTab( |
66 content::WebContents* source, | 67 content::WebContents* source, |
67 const content::OpenURLParams& params) OVERRIDE; | 68 const content::OpenURLParams& params) OVERRIDE; |
68 virtual void AddNewContents(content::WebContents* source, | 69 virtual void AddNewContents(content::WebContents* source, |
69 content::WebContents* new_contents, | 70 content::WebContents* new_contents, |
70 WindowOpenDisposition disposition, | 71 WindowOpenDisposition disposition, |
71 const gfx::Rect& initial_pos, | 72 const gfx::Rect& initial_pos, |
72 bool user_gesture) OVERRIDE; | 73 bool user_gesture) OVERRIDE; |
73 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | 74 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; |
74 | 75 |
75 private: | 76 private: |
76 HtmlDialogWindowController* controller_; // weak | 77 WebDialogWindowController* controller_; // weak |
77 HtmlDialogUIDelegate* delegate_; // weak, owned by controller_ | 78 WebDialogDelegate* delegate_; // weak, owned by controller_ |
78 HtmlDialogController* dialog_controller_; | 79 WebDialogController* dialog_controller_; |
79 | 80 |
80 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out | 81 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out afterwards |
81 // afterwards so that no other HtmlDialogUIDelegate calls are sent | 82 // so that no other WebDialogDelegate calls are sent to it. Returns whether or |
82 // to it. Returns whether or not the OnDialogClosed() was actually | 83 // not the OnDialogClosed() was actually called on the delegate. |
83 // called on the delegate. | |
84 bool DelegateOnDialogClosed(const std::string& json_retval); | 84 bool DelegateOnDialogClosed(const std::string& json_retval); |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(HtmlDialogWindowDelegateBridge); | 86 DISALLOW_COPY_AND_ASSIGN(WebDialogWindowDelegateBridge); |
87 }; | 87 }; |
88 | 88 |
89 // ChromeEventProcessingWindow expects its controller to implement the | 89 // ChromeEventProcessingWindow expects its controller to implement the |
90 // BrowserCommandExecutor protocol. | 90 // BrowserCommandExecutor protocol. |
91 @interface HtmlDialogWindowController (InternalAPI) <BrowserCommandExecutor> | 91 @interface WebDialogWindowController (InternalAPI) <BrowserCommandExecutor> |
92 | 92 |
93 // BrowserCommandExecutor methods. | 93 // BrowserCommandExecutor methods. |
94 - (void)executeCommand:(int)command; | 94 - (void)executeCommand:(int)command; |
95 | 95 |
96 @end | 96 @end |
97 | 97 |
98 namespace browser { | 98 namespace browser { |
99 | 99 |
100 gfx::NativeWindow ShowHtmlDialog(gfx::NativeWindow parent, | 100 gfx::NativeWindow ShowWebDialog(gfx::NativeWindow parent, |
101 Profile* profile, | 101 Profile* profile, |
102 Browser* browser, | 102 Browser* browser, |
103 HtmlDialogUIDelegate* delegate, | 103 WebDialogDelegate* delegate, |
104 DialogStyle style) { | 104 DialogStyle style) { |
105 return [HtmlDialogWindowController showHtmlDialog:delegate | 105 return [WebDialogWindowController showWebDialog:delegate |
106 profile:profile | 106 profile:profile |
107 browser:browser]; | 107 browser:browser]; |
108 } | 108 } |
109 | 109 |
110 void CloseHtmlDialog(gfx::NativeWindow window) { | 110 void CloseWDialog(gfx::NativeWindow window) { |
111 [window performClose:nil]; | 111 [window performClose:nil]; |
112 } | 112 } |
113 | 113 |
114 } // namespace html_dialog_window_controller | 114 } // namespace web_dialog_window_controller |
115 | 115 |
116 HtmlDialogWindowDelegateBridge::HtmlDialogWindowDelegateBridge( | 116 WebDialogWindowDelegateBridge::WebDialogWindowDelegateBridge( |
117 HtmlDialogWindowController* controller, | 117 WebDialogWindowController* controller, |
118 Profile* profile, | 118 Profile* profile, |
119 Browser* browser, | 119 Browser* browser, |
120 HtmlDialogUIDelegate* delegate) | 120 WebDialogDelegate* delegate) |
121 : HtmlDialogTabContentsDelegate(profile), | 121 : WebDialogWebContentsDelegate(profile), |
122 controller_(controller), | 122 controller_(controller), |
123 delegate_(delegate), | 123 delegate_(delegate), |
124 dialog_controller_(new HtmlDialogController(this, profile, browser)) { | 124 dialog_controller_(new WebDialogController(this, profile, browser)) { |
125 DCHECK(controller_); | 125 DCHECK(controller_); |
126 DCHECK(delegate_); | 126 DCHECK(delegate_); |
127 } | 127 } |
128 | 128 |
129 HtmlDialogWindowDelegateBridge::~HtmlDialogWindowDelegateBridge() {} | 129 WebDialogWindowDelegateBridge::~WebDialogWindowDelegateBridge() {} |
130 | 130 |
131 void HtmlDialogWindowDelegateBridge::WindowControllerClosed() { | 131 void WebDialogWindowDelegateBridge::WindowControllerClosed() { |
132 Detach(); | 132 Detach(); |
133 delete dialog_controller_; | 133 delete dialog_controller_; |
134 controller_ = nil; | 134 controller_ = nil; |
135 DelegateOnDialogClosed(""); | 135 DelegateOnDialogClosed(""); |
136 } | 136 } |
137 | 137 |
138 bool HtmlDialogWindowDelegateBridge::DelegateOnDialogClosed( | 138 bool WebDialogWindowDelegateBridge::DelegateOnDialogClosed( |
139 const std::string& json_retval) { | 139 const std::string& json_retval) { |
140 if (delegate_) { | 140 if (delegate_) { |
141 HtmlDialogUIDelegate* real_delegate = delegate_; | 141 WebDialogDelegate* real_delegate = delegate_; |
142 delegate_ = NULL; | 142 delegate_ = NULL; |
143 real_delegate->OnDialogClosed(json_retval); | 143 real_delegate->OnDialogClosed(json_retval); |
144 return true; | 144 return true; |
145 } | 145 } |
146 return false; | 146 return false; |
147 } | 147 } |
148 | 148 |
149 // HtmlDialogUIDelegate definitions. | 149 // WebDialogDelegate definitions. |
150 | 150 |
151 // All of these functions check for NULL first since delegate_ is set | 151 // All of these functions check for NULL first since delegate_ is set |
152 // to NULL when the window is closed. | 152 // to NULL when the window is closed. |
153 | 153 |
154 ui::ModalType HtmlDialogWindowDelegateBridge::GetDialogModalType() const { | 154 ui::ModalType WebDialogWindowDelegateBridge::GetDialogModalType() const { |
155 // TODO(akalin): Support modal dialog boxes. | 155 // TODO(akalin): Support modal dialog boxes. |
156 if (delegate_ && delegate_->GetDialogModalType() != ui::MODAL_TYPE_NONE) { | 156 if (delegate_ && delegate_->GetDialogModalType() != ui::MODAL_TYPE_NONE) { |
157 LOG(WARNING) << "Modal HTML dialogs are not supported yet"; | 157 LOG(WARNING) << "Modal Web dialogs are not supported yet"; |
158 } | 158 } |
159 return ui::MODAL_TYPE_NONE; | 159 return ui::MODAL_TYPE_NONE; |
160 } | 160 } |
161 | 161 |
162 string16 HtmlDialogWindowDelegateBridge::GetDialogTitle() const { | 162 string16 WebDialogWindowDelegateBridge::GetDialogTitle() const { |
163 return delegate_ ? delegate_->GetDialogTitle() : string16(); | 163 return delegate_ ? delegate_->GetDialogTitle() : string16(); |
164 } | 164 } |
165 | 165 |
166 GURL HtmlDialogWindowDelegateBridge::GetDialogContentURL() const { | 166 GURL WebDialogWindowDelegateBridge::GetDialogContentURL() const { |
167 return delegate_ ? delegate_->GetDialogContentURL() : GURL(); | 167 return delegate_ ? delegate_->GetDialogContentURL() : GURL(); |
168 } | 168 } |
169 | 169 |
170 void HtmlDialogWindowDelegateBridge::GetWebUIMessageHandlers( | 170 void WebDialogWindowDelegateBridge::GetWebUIMessageHandlers( |
171 std::vector<WebUIMessageHandler*>* handlers) const { | 171 std::vector<WebUIMessageHandler*>* handlers) const { |
172 if (delegate_) { | 172 if (delegate_) { |
173 delegate_->GetWebUIMessageHandlers(handlers); | 173 delegate_->GetWebUIMessageHandlers(handlers); |
174 } else { | 174 } else { |
175 // TODO(akalin): Add this clause in the windows version. Also | 175 // TODO(akalin): Add this clause in the windows version. Also |
176 // make sure that everything expects handlers to be non-NULL and | 176 // make sure that everything expects handlers to be non-NULL and |
177 // document it. | 177 // document it. |
178 handlers->clear(); | 178 handlers->clear(); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void HtmlDialogWindowDelegateBridge::GetDialogSize(gfx::Size* size) const { | 182 void WebDialogWindowDelegateBridge::GetDialogSize(gfx::Size* size) const { |
183 if (delegate_) | 183 if (delegate_) |
184 delegate_->GetDialogSize(size); | 184 delegate_->GetDialogSize(size); |
185 else | 185 else |
186 *size = gfx::Size(); | 186 *size = gfx::Size(); |
187 } | 187 } |
188 | 188 |
189 void HtmlDialogWindowDelegateBridge::GetMinimumDialogSize( | 189 void WebDialogWindowDelegateBridge::GetMinimumDialogSize( |
190 gfx::Size* size) const { | 190 gfx::Size* size) const { |
191 if (delegate_) | 191 if (delegate_) |
192 delegate_->GetMinimumDialogSize(size); | 192 delegate_->GetMinimumDialogSize(size); |
193 else | 193 else |
194 *size = gfx::Size(); | 194 *size = gfx::Size(); |
195 } | 195 } |
196 | 196 |
197 std::string HtmlDialogWindowDelegateBridge::GetDialogArgs() const { | 197 std::string WebDialogWindowDelegateBridge::GetDialogArgs() const { |
198 return delegate_ ? delegate_->GetDialogArgs() : ""; | 198 return delegate_ ? delegate_->GetDialogArgs() : ""; |
199 } | 199 } |
200 | 200 |
201 void HtmlDialogWindowDelegateBridge::OnDialogClosed( | 201 void WebDialogWindowDelegateBridge::OnDialogClosed( |
202 const std::string& json_retval) { | 202 const std::string& json_retval) { |
203 Detach(); | 203 Detach(); |
204 // [controller_ close] should be called at most once, too. | 204 // [controller_ close] should be called at most once, too. |
205 if (DelegateOnDialogClosed(json_retval)) { | 205 if (DelegateOnDialogClosed(json_retval)) { |
206 [controller_ close]; | 206 [controller_ close]; |
207 } | 207 } |
208 controller_ = nil; | 208 controller_ = nil; |
209 } | 209 } |
210 | 210 |
211 void HtmlDialogWindowDelegateBridge::OnCloseContents(WebContents* source, | 211 void WebDialogWindowDelegateBridge::OnCloseContents(WebContents* source, |
212 bool* out_close_dialog) { | 212 bool* out_close_dialog) { |
213 if (out_close_dialog) | 213 if (out_close_dialog) |
214 *out_close_dialog = true; | 214 *out_close_dialog = true; |
215 } | 215 } |
216 | 216 |
217 void HtmlDialogWindowDelegateBridge::CloseContents(WebContents* source) { | 217 void WebDialogWindowDelegateBridge::CloseContents(WebContents* source) { |
218 bool close_dialog = false; | 218 bool close_dialog = false; |
219 OnCloseContents(source, &close_dialog); | 219 OnCloseContents(source, &close_dialog); |
220 if (close_dialog) | 220 if (close_dialog) |
221 OnDialogClosed(std::string()); | 221 OnDialogClosed(std::string()); |
222 } | 222 } |
223 | 223 |
224 content::WebContents* HtmlDialogWindowDelegateBridge::OpenURLFromTab( | 224 content::WebContents* WebDialogWindowDelegateBridge::OpenURLFromTab( |
225 content::WebContents* source, | 225 content::WebContents* source, |
226 const content::OpenURLParams& params) { | 226 const content::OpenURLParams& params) { |
227 content::WebContents* new_contents = NULL; | 227 content::WebContents* new_contents = NULL; |
228 if (delegate_ && | 228 if (delegate_ && |
229 delegate_->HandleOpenURLFromTab(source, params, &new_contents)) { | 229 delegate_->HandleOpenURLFromTab(source, params, &new_contents)) { |
230 return new_contents; | 230 return new_contents; |
231 } | 231 } |
232 return HtmlDialogTabContentsDelegate::OpenURLFromTab(source, params); | 232 return WebDialogWebContentsDelegate::OpenURLFromTab(source, params); |
233 } | 233 } |
234 | 234 |
235 void HtmlDialogWindowDelegateBridge::AddNewContents( | 235 void WebDialogWindowDelegateBridge::AddNewContents( |
236 content::WebContents* source, | 236 content::WebContents* source, |
237 content::WebContents* new_contents, | 237 content::WebContents* new_contents, |
238 WindowOpenDisposition disposition, | 238 WindowOpenDisposition disposition, |
239 const gfx::Rect& initial_pos, | 239 const gfx::Rect& initial_pos, |
240 bool user_gesture) { | 240 bool user_gesture) { |
241 if (delegate_ && delegate_->HandleAddNewContents( | 241 if (delegate_ && delegate_->HandleAddNewContents( |
242 source, new_contents, disposition, initial_pos, user_gesture)) { | 242 source, new_contents, disposition, initial_pos, user_gesture)) { |
243 return; | 243 return; |
244 } | 244 } |
245 HtmlDialogTabContentsDelegate::AddNewContents( | 245 WebDialogWebContentsDelegate::AddNewContents( |
246 source, new_contents, disposition, initial_pos, user_gesture); | 246 source, new_contents, disposition, initial_pos, user_gesture); |
247 } | 247 } |
248 | 248 |
249 void HtmlDialogWindowDelegateBridge::LoadingStateChanged( | 249 void WebDialogWindowDelegateBridge::LoadingStateChanged( |
250 content::WebContents* source) { | 250 content::WebContents* source) { |
251 if (delegate_) | 251 if (delegate_) |
252 delegate_->OnLoadingStateChanged(source); | 252 delegate_->OnLoadingStateChanged(source); |
253 } | 253 } |
254 | 254 |
255 void HtmlDialogWindowDelegateBridge::MoveContents(WebContents* source, | 255 void WebDialogWindowDelegateBridge::MoveContents(WebContents* source, |
256 const gfx::Rect& pos) { | 256 const gfx::Rect& pos) { |
257 // TODO(akalin): Actually set the window bounds. | 257 // TODO(akalin): Actually set the window bounds. |
258 } | 258 } |
259 | 259 |
260 // A simplified version of BrowserWindowCocoa::HandleKeyboardEvent(). | 260 // A simplified version of BrowserWindowCocoa::HandleKeyboardEvent(). |
261 // We don't handle global keyboard shortcuts here, but that's fine since | 261 // We don't handle global keyboard shortcuts here, but that's fine since |
262 // they're all browser-specific. (This may change in the future.) | 262 // they're all browser-specific. (This may change in the future.) |
263 void HtmlDialogWindowDelegateBridge::HandleKeyboardEvent( | 263 void WebDialogWindowDelegateBridge::HandleKeyboardEvent( |
264 const NativeWebKeyboardEvent& event) { | 264 const NativeWebKeyboardEvent& event) { |
265 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) | 265 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) |
266 return; | 266 return; |
267 | 267 |
268 // Close ourselves if the user hits Esc or Command-. . The normal | 268 // Close ourselves if the user hits Esc or Command-. . The normal |
269 // way to do this is to implement (void)cancel:(int)sender, but | 269 // way to do this is to implement (void)cancel:(int)sender, but |
270 // since we handle keyboard events ourselves we can't do that. | 270 // since we handle keyboard events ourselves we can't do that. |
271 // | 271 // |
272 // According to experiments, hitting Esc works regardless of the | 272 // According to experiments, hitting Esc works regardless of the |
273 // presence of other modifiers (as long as it's not an app-level | 273 // presence of other modifiers (as long as it's not an app-level |
274 // shortcut, e.g. Commmand-Esc for Front Row) but no other modifiers | 274 // shortcut, e.g. Commmand-Esc for Front Row) but no other modifiers |
275 // can be present for Command-. to work. | 275 // can be present for Command-. to work. |
276 // | 276 // |
277 // TODO(thakis): It would be nice to get cancel: to work somehow. | 277 // TODO(thakis): It would be nice to get cancel: to work somehow. |
278 // Bug: http://code.google.com/p/chromium/issues/detail?id=32828 . | 278 // Bug: http://code.google.com/p/chromium/issues/detail?id=32828 . |
279 if (event.type == NativeWebKeyboardEvent::RawKeyDown && | 279 if (event.type == NativeWebKeyboardEvent::RawKeyDown && |
280 ((event.windowsKeyCode == ui::VKEY_ESCAPE) || | 280 ((event.windowsKeyCode == ui::VKEY_ESCAPE) || |
281 (event.windowsKeyCode == ui::VKEY_OEM_PERIOD && | 281 (event.windowsKeyCode == ui::VKEY_OEM_PERIOD && |
282 event.modifiers == NativeWebKeyboardEvent::MetaKey))) { | 282 event.modifiers == NativeWebKeyboardEvent::MetaKey))) { |
283 [controller_ close]; | 283 [controller_ close]; |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 ChromeEventProcessingWindow* event_window = | 287 ChromeEventProcessingWindow* event_window = |
288 static_cast<ChromeEventProcessingWindow*>([controller_ window]); | 288 static_cast<ChromeEventProcessingWindow*>([controller_ window]); |
289 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); | 289 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); |
290 [event_window redispatchKeyEvent:event.os_event]; | 290 [event_window redispatchKeyEvent:event.os_event]; |
291 } | 291 } |
292 | 292 |
293 @implementation HtmlDialogWindowController (InternalAPI) | 293 @implementation WebDialogWindowController (InternalAPI) |
294 | 294 |
295 // This gets called whenever a chrome-specific keyboard shortcut is performed | 295 // This gets called whenever a chrome-specific keyboard shortcut is performed |
296 // in the HTML dialog window. We simply swallow all those events. | 296 // in the Web dialog window. We simply swallow all those events. |
297 - (void)executeCommand:(int)command {} | 297 - (void)executeCommand:(int)command {} |
298 | 298 |
299 @end | 299 @end |
300 | 300 |
301 @implementation HtmlDialogWindowController | 301 @implementation WebDialogWindowController |
302 | 302 |
303 // NOTE(akalin): We'll probably have to add the parentWindow parameter back | 303 // NOTE(akalin): We'll probably have to add the parentWindow parameter back |
304 // in once we implement modal dialogs. | 304 // in once we implement modal dialogs. |
305 | 305 |
306 + (NSWindow*)showHtmlDialog:(HtmlDialogUIDelegate*)delegate | 306 + (NSWindow*)showWebDialog:(WebDialogDelegate*)delegate |
307 profile:(Profile*)profile | 307 profile:(Profile*)profile |
308 browser:(Browser*)browser { | 308 browser:(Browser*)browser { |
309 HtmlDialogWindowController* htmlDialogWindowController = | 309 WebDialogWindowController* webDialogWindowController = |
310 [[HtmlDialogWindowController alloc] initWithDelegate:delegate | 310 [[WebDialogWindowController alloc] initWithDelegate:delegate |
311 profile:profile | 311 profile:profile |
312 browser:browser]; | 312 browser:browser]; |
313 [htmlDialogWindowController loadDialogContents]; | 313 [webDialogWindowController loadDialogContents]; |
314 [htmlDialogWindowController showWindow:nil]; | 314 [webDialogWindowController showWindow:nil]; |
315 return [htmlDialogWindowController window]; | 315 return [webDialogWindowController window]; |
316 } | 316 } |
317 | 317 |
318 - (id)initWithDelegate:(HtmlDialogUIDelegate*)delegate | 318 - (id)initWithDelegate:(WebDialogDelegate*)delegate |
319 profile:(Profile*)profile | 319 profile:(Profile*)profile |
320 browser:(Browser*)browser { | 320 browser:(Browser*)browser { |
321 DCHECK(delegate); | 321 DCHECK(delegate); |
322 DCHECK(profile); | 322 DCHECK(profile); |
323 | 323 |
324 gfx::Size dialogSize; | 324 gfx::Size dialogSize; |
325 delegate->GetDialogSize(&dialogSize); | 325 delegate->GetDialogSize(&dialogSize); |
326 NSRect dialogRect = NSMakeRect(0, 0, dialogSize.width(), dialogSize.height()); | 326 NSRect dialogRect = NSMakeRect(0, 0, dialogSize.width(), dialogSize.height()); |
327 NSUInteger style = NSTitledWindowMask | NSClosableWindowMask | | 327 NSUInteger style = NSTitledWindowMask | NSClosableWindowMask | |
328 NSResizableWindowMask; | 328 NSResizableWindowMask; |
329 scoped_nsobject<ChromeEventProcessingWindow> window( | 329 scoped_nsobject<ChromeEventProcessingWindow> window( |
330 [[ChromeEventProcessingWindow alloc] | 330 [[ChromeEventProcessingWindow alloc] |
331 initWithContentRect:dialogRect | 331 initWithContentRect:dialogRect |
332 styleMask:style | 332 styleMask:style |
333 backing:NSBackingStoreBuffered | 333 backing:NSBackingStoreBuffered |
334 defer:YES]); | 334 defer:YES]); |
335 if (!window.get()) { | 335 if (!window.get()) { |
336 return nil; | 336 return nil; |
337 } | 337 } |
338 self = [super initWithWindow:window]; | 338 self = [super initWithWindow:window]; |
339 if (!self) { | 339 if (!self) { |
340 return nil; | 340 return nil; |
341 } | 341 } |
342 [window setWindowController:self]; | 342 [window setWindowController:self]; |
343 [window setDelegate:self]; | 343 [window setDelegate:self]; |
344 [window setTitle:base::SysUTF16ToNSString(delegate->GetDialogTitle())]; | 344 [window setTitle:base::SysUTF16ToNSString(delegate->GetDialogTitle())]; |
345 [window setMinSize:dialogRect.size]; | 345 [window setMinSize:dialogRect.size]; |
346 [window center]; | 346 [window center]; |
347 delegate_.reset( | 347 delegate_.reset( |
348 new HtmlDialogWindowDelegateBridge(self, profile, browser, delegate)); | 348 new WebDialogWindowDelegateBridge(self, profile, browser, delegate)); |
349 return self; | 349 return self; |
350 } | 350 } |
351 | 351 |
352 - (void)loadDialogContents { | 352 - (void)loadDialogContents { |
353 contentsWrapper_.reset(new TabContentsWrapper(WebContents::Create( | 353 contentsWrapper_.reset(new TabContentsWrapper(WebContents::Create( |
354 delegate_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); | 354 delegate_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL))); |
355 [[self window] | 355 [[self window] |
356 setContentView:contentsWrapper_->web_contents()->GetNativeView()]; | 356 setContentView:contentsWrapper_->web_contents()->GetNativeView()]; |
357 contentsWrapper_->web_contents()->SetDelegate(delegate_.get()); | 357 contentsWrapper_->web_contents()->SetDelegate(delegate_.get()); |
358 | 358 |
359 // This must be done before loading the page; see the comments in | 359 // This must be done before loading the page; see the comments in |
360 // HtmlDialogUI. | 360 // WebDialogUI. |
361 HtmlDialogUI::GetPropertyAccessor().SetProperty( | 361 WebDialogUI::GetPropertyAccessor().SetProperty( |
362 contentsWrapper_->web_contents()->GetPropertyBag(), delegate_.get()); | 362 contentsWrapper_->web_contents()->GetPropertyBag(), delegate_.get()); |
363 | 363 |
364 contentsWrapper_->web_contents()->GetController().LoadURL( | 364 contentsWrapper_->web_contents()->GetController().LoadURL( |
365 delegate_->GetDialogContentURL(), | 365 delegate_->GetDialogContentURL(), |
366 content::Referrer(), | 366 content::Referrer(), |
367 content::PAGE_TRANSITION_START_PAGE, | 367 content::PAGE_TRANSITION_START_PAGE, |
368 std::string()); | 368 std::string()); |
369 | 369 |
370 // TODO(akalin): add accelerator for ESC to close the dialog box. | 370 // TODO(akalin): add accelerator for ESC to close the dialog box. |
371 // | 371 // |
372 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender | 372 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender |
373 // to do the above doesn't work. | 373 // to do the above doesn't work. |
374 } | 374 } |
375 | 375 |
376 - (void)windowWillClose:(NSNotification*)notification { | 376 - (void)windowWillClose:(NSNotification*)notification { |
377 delegate_->WindowControllerClosed(); | 377 delegate_->WindowControllerClosed(); |
378 [self autorelease]; | 378 [self autorelease]; |
379 } | 379 } |
380 | 380 |
381 @end | 381 @end |
OLD | NEW |