Chromium Code Reviews| Index: chrome/browser/ui/views/extensions/extension_dialog.cc |
| diff --git a/chrome/browser/ui/views/extensions/extension_dialog.cc b/chrome/browser/ui/views/extensions/extension_dialog.cc |
| index 35f8220d5a3fb72795b2a3e89e8bfaffb9dfeec7..c1137511108c797b36b38745331ad404e89fb93c 100644 |
| --- a/chrome/browser/ui/views/extensions/extension_dialog.cc |
| +++ b/chrome/browser/ui/views/extensions/extension_dialog.cc |
| @@ -7,6 +7,7 @@ |
| #include "chrome/browser/extensions/extension_host.h" |
| #include "chrome/browser/extensions/extension_process_manager.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
|
xiyuan
2012/02/27 18:26:30
nit: ProfileManager seems not used. Do we need thi
rkc
2012/02/27 22:24:43
Done.
|
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/dialog_style.h" |
| @@ -23,8 +24,8 @@ |
| #include "ui/views/widget/widget.h" |
| #if defined(USE_AURA) |
| +#include "ash/shell.h" |
| #include "ui/aura/root_window.h" |
| -#include "ui/aura/window.h" |
| #endif |
| using content::WebContents; |
| @@ -58,19 +59,27 @@ ExtensionDialog* ExtensionDialog::Show( |
| int height, |
| const string16& title, |
| ExtensionDialogObserver* observer) { |
| - return ExtensionDialog::ShowInternal(url, browser, web_contents, width, |
| - height, false, title, observer); |
| + ExtensionHost* host = CreateExtensionHost(url, browser, NULL); |
| + if (!host) |
| + return NULL; |
| + host->set_associated_web_contents(web_contents); |
| + |
| + return ExtensionDialog::ShowInternal(url, browser, host, width, height, |
| + false, title, observer); |
| } |
| #if defined(USE_AURA) |
| // static |
| ExtensionDialog* ExtensionDialog::ShowFullscreen( |
| const GURL& url, |
| - Browser* browser, |
| - WebContents* web_contents, |
| + Profile* profile, |
| const string16& title, |
| ExtensionDialogObserver* observer) { |
| - return ExtensionDialog::ShowInternal(url, browser, web_contents, 0, 0, |
| + ExtensionHost* host = CreateExtensionHost(url, NULL, profile); |
| + if (!host) |
| + return NULL; |
| + |
| + return ExtensionDialog::ShowInternal(url, NULL, host, 0, 0, |
| true, title, observer); |
| } |
| #endif |
| @@ -78,22 +87,18 @@ ExtensionDialog* ExtensionDialog::ShowFullscreen( |
| // static |
| ExtensionDialog* ExtensionDialog::ShowInternal(const GURL& url, |
| Browser* browser, |
| - content::WebContents* web_contents, |
| + ExtensionHost* host, |
| int width, |
| int height, |
| bool fullscreen, |
| const string16& title, |
| ExtensionDialogObserver* observer) { |
| - CHECK(browser); |
| - ExtensionHost* host = CreateExtensionHost(url, browser); |
| - if (!host) |
| - return NULL; |
| - host->set_associated_web_contents(web_contents); |
| - |
| + CHECK(fullscreen || browser); |
| ExtensionDialog* dialog = new ExtensionDialog(host, observer); |
| dialog->set_title(title); |
| + |
| if (fullscreen) |
| - dialog->InitWindowFullscreen(browser); |
| + dialog->InitWindowFullscreen(); |
| else |
| dialog->InitWindow(browser, width, height); |
| @@ -110,28 +115,36 @@ ExtensionDialog* ExtensionDialog::ShowInternal(const GURL& url, |
| // static |
| ExtensionHost* ExtensionDialog::CreateExtensionHost(const GURL& url, |
| - Browser* browser) { |
| - ExtensionProcessManager* manager = |
| - browser->profile()->GetExtensionProcessManager(); |
| + Browser* browser, |
| + Profile* profile) { |
| + // Prefer picking the extension manager from the profile if given. |
| + ExtensionProcessManager* manager = NULL; |
| + if (profile) |
| + manager = profile->GetExtensionProcessManager(); |
| + else |
| + manager = browser->profile()->GetExtensionProcessManager(); |
| + |
| DCHECK(manager); |
| if (!manager) |
| return NULL; |
| - return manager->CreateDialogHost(url, browser); |
| + if (browser) |
| + return manager->CreateDialogHost(url, browser); |
| + else |
| + return manager->CreatePopupHost(url, NULL); |
| } |
| #if defined(USE_AURA) |
| -void ExtensionDialog::InitWindowFullscreen(Browser* browser) { |
| - gfx::NativeWindow parent = browser->window()->GetNativeHandle(); |
| - |
| +void ExtensionDialog::InitWindowFullscreen() { |
| + aura::RootWindow* root_window = ash::Shell::GetRootWindow(); |
| // Create the window as a child of the root window. |
| window_ = browser::CreateFramelessViewsWindow( |
| - parent->GetRootWindow(), this); |
| + root_window, this); |
| // Make sure we're always on top by putting ourselves at the top |
| // of the z-order of the child windows of the root window. |
| - parent->GetRootWindow()->StackChildAtTop(window_->GetNativeWindow()); |
| + root_window->StackChildAtTop(window_->GetNativeWindow()); |
|
sky
2012/02/27 15:52:43
Use the views API for this sort of stuff:
window_-
rkc
2012/02/27 22:24:43
Done.
|
| - int width = parent->GetRootWindow()->GetHostSize().width(); |
| - int height = parent->GetRootWindow()->GetHostSize().height(); |
| + int width = root_window->GetHostSize().width(); |
|
sky
2012/02/27 15:52:43
gfx::Screen::GetMonitorWorkAreaNearestWindow
rkc
2012/02/27 22:24:43
Done.
|
| + int height = root_window->GetHostSize().height(); |
| window_->SetBounds(gfx::Rect(0, 0, width, height)); |
| window_->Show(); |
| @@ -139,7 +152,7 @@ void ExtensionDialog::InitWindowFullscreen(Browser* browser) { |
| window_->Activate(); |
| } |
| #else |
| -void ExtensionDialog::InitWindowFullscreen(Browser* browser) { |
| +void ExtensionDialog::InitWindowFullscreen() { |
| NOTIMPLEMENTED(); |
| } |
| #endif |