| 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 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | 8 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 14 #include "components/web_modal/popup_manager.h" | |
| 15 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 | 17 |
| 19 using web_modal::WebContentsModalDialogManager; | 18 using web_modal::WebContentsModalDialogManager; |
| 20 using web_modal::NativeWebContentsModalDialog; | 19 using web_modal::NativeWebContentsModalDialog; |
| 21 | 20 |
| 22 ConstrainedWindowMac::ConstrainedWindowMac( | 21 ConstrainedWindowMac::ConstrainedWindowMac( |
| 23 ConstrainedWindowMacDelegate* delegate, | 22 ConstrainedWindowMacDelegate* delegate, |
| 24 content::WebContents* web_contents, | 23 content::WebContents* web_contents, |
| 25 id<ConstrainedWindowSheet> sheet) | 24 id<ConstrainedWindowSheet> sheet) |
| 26 : delegate_(delegate), | 25 : delegate_(delegate), |
| 27 web_contents_(NULL), | 26 web_contents_(NULL), |
| 28 sheet_([sheet retain]), | 27 sheet_([sheet retain]), |
| 29 shown_(false) { | 28 shown_(false) { |
| 30 DCHECK(web_contents); | 29 DCHECK(web_contents); |
| 31 extensions::WebViewGuest* web_view_guest = | 30 extensions::WebViewGuest* web_view_guest = |
| 32 extensions::WebViewGuest::FromWebContents(web_contents); | 31 extensions::WebViewGuest::FromWebContents(web_contents); |
| 33 // For embedded WebContents, use the embedder's WebContents for constrained | 32 // For embedded WebContents, use the embedder's WebContents for constrained |
| 34 // window. | 33 // window. |
| 35 web_contents_ = web_view_guest && web_view_guest->embedder_web_contents() ? | 34 web_contents_ = web_view_guest && web_view_guest->embedder_web_contents() ? |
| 36 web_view_guest->embedder_web_contents() : web_contents; | 35 web_view_guest->embedder_web_contents() : web_contents; |
| 37 DCHECK(sheet_.get()); | 36 DCHECK(sheet_.get()); |
| 38 web_modal::PopupManager* popup_manager = | 37 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 39 web_modal::PopupManager::FromWebContents(web_contents_); | 38 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 40 if (popup_manager) | 39 web_contents_modal_dialog_manager->ShowModalDialog(this); |
| 41 popup_manager->ShowModalDialog(this, web_contents_); | |
| 42 } | 40 } |
| 43 | 41 |
| 44 ConstrainedWindowMac::~ConstrainedWindowMac() { | 42 ConstrainedWindowMac::~ConstrainedWindowMac() { |
| 45 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 43 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 46 } | 44 } |
| 47 | 45 |
| 48 void ConstrainedWindowMac::ShowWebContentsModalDialog() { | 46 void ConstrainedWindowMac::ShowWebContentsModalDialog() { |
| 49 if (shown_) | 47 if (shown_) |
| 50 return; | 48 return; |
| 51 | 49 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 91 |
| 94 NSWindow* ConstrainedWindowMac::GetParentWindow() const { | 92 NSWindow* ConstrainedWindowMac::GetParentWindow() const { |
| 95 // Tab contents in a tabbed browser may not be inside a window. For this | 93 // Tab contents in a tabbed browser may not be inside a window. For this |
| 96 // reason use a browser window if possible. | 94 // reason use a browser window if possible. |
| 97 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 95 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 98 if (browser) | 96 if (browser) |
| 99 return browser->window()->GetNativeWindow(); | 97 return browser->window()->GetNativeWindow(); |
| 100 | 98 |
| 101 return web_contents_->GetTopLevelNativeWindow(); | 99 return web_contents_->GetTopLevelNativeWindow(); |
| 102 } | 100 } |
| OLD | NEW |