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/web_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/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "chrome/browser/ui/browser_dialogs.h" | 10 #import "chrome/browser/ui/browser_dialogs.h" |
11 #import "chrome/browser/ui/cocoa/browser_command_executor.h" | 11 #import "chrome/browser/ui/cocoa/browser_command_executor.h" |
12 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 12 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
14 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 14 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
15 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_ui_message_handler.h" | 17 #include "content/public/browser/web_ui_message_handler.h" |
18 #include "ui/base/keycodes/keyboard_codes.h" | 18 #include "ui/base/keycodes/keyboard_codes.h" |
19 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
20 #include "ui/web_dialogs/web_dialog_delegate.h" | 20 #include "ui/web_dialogs/web_dialog_delegate.h" |
21 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" | 21 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
22 | 22 |
23 using content::NativeWebKeyboardEvent; | 23 using content::NativeWebKeyboardEvent; |
24 using content::WebContents; | 24 using content::WebContents; |
25 using content::WebUIMessageHandler; | 25 using content::WebUIMessageHandler; |
26 using ui::WebDialogDelegate; | 26 using ui::WebDialogDelegate; |
27 using ui::WebDialogUI; | 27 using ui::WebDialogUI; |
28 using ui::WebDialogWebContentsDelegate; | 28 using ui::WebDialogWebContentsDelegate; |
29 | 29 |
| 30 // TODO(avi): Kill this when TabContents goes away. |
| 31 class WebDialogWindowControllerTabContentsCreator { |
| 32 public: |
| 33 static TabContents* CreateTabContents(content::WebContents* contents) { |
| 34 return TabContents::Factory::CreateTabContents(contents); |
| 35 } |
| 36 }; |
| 37 |
30 // Thin bridge that routes notifications to | 38 // Thin bridge that routes notifications to |
31 // WebDialogWindowController's member variables. | 39 // WebDialogWindowController's member variables. |
32 class WebDialogWindowDelegateBridge | 40 class WebDialogWindowDelegateBridge |
33 : public WebDialogDelegate, | 41 : public WebDialogDelegate, |
34 public WebDialogWebContentsDelegate { | 42 public WebDialogWebContentsDelegate { |
35 public: | 43 public: |
36 // All parameters must be non-NULL/non-nil. | 44 // All parameters must be non-NULL/non-nil. |
37 WebDialogWindowDelegateBridge(WebDialogWindowController* controller, | 45 WebDialogWindowDelegateBridge(WebDialogWindowController* controller, |
38 content::BrowserContext* context, | 46 content::BrowserContext* context, |
39 WebDialogDelegate* delegate); | 47 WebDialogDelegate* delegate); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 [window setDelegate:self]; | 338 [window setDelegate:self]; |
331 [window setTitle:base::SysUTF16ToNSString(delegate->GetDialogTitle())]; | 339 [window setTitle:base::SysUTF16ToNSString(delegate->GetDialogTitle())]; |
332 [window setMinSize:dialogRect.size]; | 340 [window setMinSize:dialogRect.size]; |
333 [window center]; | 341 [window center]; |
334 delegate_.reset( | 342 delegate_.reset( |
335 new WebDialogWindowDelegateBridge(self, context, delegate)); | 343 new WebDialogWindowDelegateBridge(self, context, delegate)); |
336 return self; | 344 return self; |
337 } | 345 } |
338 | 346 |
339 - (void)loadDialogContents { | 347 - (void)loadDialogContents { |
340 tabContents_.reset(new TabContents(WebContents::Create( | 348 tabContents_.reset( |
341 delegate_->browser_context(), NULL, MSG_ROUTING_NONE, NULL))); | 349 WebDialogWindowControllerTabContentsCreator::CreateTabContents( |
| 350 WebContents::Create( |
| 351 delegate_->browser_context(), NULL, MSG_ROUTING_NONE, NULL))); |
342 [[self window] | 352 [[self window] |
343 setContentView:tabContents_->web_contents()->GetNativeView()]; | 353 setContentView:tabContents_->web_contents()->GetNativeView()]; |
344 tabContents_->web_contents()->SetDelegate(delegate_.get()); | 354 tabContents_->web_contents()->SetDelegate(delegate_.get()); |
345 | 355 |
346 // This must be done before loading the page; see the comments in | 356 // This must be done before loading the page; see the comments in |
347 // WebDialogUI. | 357 // WebDialogUI. |
348 WebDialogUI::SetDelegate(tabContents_->web_contents(), delegate_.get()); | 358 WebDialogUI::SetDelegate(tabContents_->web_contents(), delegate_.get()); |
349 | 359 |
350 tabContents_->web_contents()->GetController().LoadURL( | 360 tabContents_->web_contents()->GetController().LoadURL( |
351 delegate_->GetDialogContentURL(), | 361 delegate_->GetDialogContentURL(), |
352 content::Referrer(), | 362 content::Referrer(), |
353 content::PAGE_TRANSITION_START_PAGE, | 363 content::PAGE_TRANSITION_START_PAGE, |
354 std::string()); | 364 std::string()); |
355 | 365 |
356 // TODO(akalin): add accelerator for ESC to close the dialog box. | 366 // TODO(akalin): add accelerator for ESC to close the dialog box. |
357 // | 367 // |
358 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender | 368 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender |
359 // to do the above doesn't work. | 369 // to do the above doesn't work. |
360 } | 370 } |
361 | 371 |
362 - (void)windowWillClose:(NSNotification*)notification { | 372 - (void)windowWillClose:(NSNotification*)notification { |
363 delegate_->WindowControllerClosed(); | 373 delegate_->WindowControllerClosed(); |
364 [self autorelease]; | 374 [self autorelease]; |
365 } | 375 } |
366 | 376 |
367 @end | 377 @end |
OLD | NEW |