| 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/views/extensions/extension_dialog.h" | 5 #include "chrome/browser/ui/views/extensions/extension_dialog.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/base_window.h" | 11 #include "chrome/browser/ui/base_window.h" |
| 12 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" | 12 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/render_widget_host_view.h" | 17 #include "content/public/browser/render_widget_host_view.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 22 #include "ui/views/background.h" | 22 #include "ui/views/background.h" |
| 23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 | 24 |
| 25 #if defined(USE_ASH) | |
| 26 #include "ash/shell.h" | |
| 27 #include "ui/aura/root_window.h" | |
| 28 #endif | |
| 29 | |
| 30 using content::WebContents; | 25 using content::WebContents; |
| 31 | 26 |
| 32 ExtensionDialog::ExtensionDialog(extensions::ExtensionHost* host, | 27 ExtensionDialog::ExtensionDialog(extensions::ExtensionHost* host, |
| 33 ExtensionDialogObserver* observer) | 28 ExtensionDialogObserver* observer) |
| 34 : window_(NULL), | 29 : window_(NULL), |
| 35 extension_host_(host), | 30 extension_host_(host), |
| 36 observer_(observer) { | 31 observer_(observer) { |
| 37 AddRef(); // Balanced in DeleteDelegate(); | 32 AddRef(); // Balanced in DeleteDelegate(); |
| 38 | 33 |
| 39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 34 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 WebContents* web_contents, | 52 WebContents* web_contents, |
| 58 int width, | 53 int width, |
| 59 int height, | 54 int height, |
| 60 const string16& title, | 55 const string16& title, |
| 61 ExtensionDialogObserver* observer) { | 56 ExtensionDialogObserver* observer) { |
| 62 extensions::ExtensionHost* host = CreateExtensionHost(url, profile); | 57 extensions::ExtensionHost* host = CreateExtensionHost(url, profile); |
| 63 if (!host) | 58 if (!host) |
| 64 return NULL; | 59 return NULL; |
| 65 host->SetAssociatedWebContents(web_contents); | 60 host->SetAssociatedWebContents(web_contents); |
| 66 | 61 |
| 67 return ExtensionDialog::ShowInternal(url, base_window, host, width, height, | 62 CHECK(base_window); |
| 68 false, title, observer); | |
| 69 } | |
| 70 | |
| 71 #if defined(USE_AURA) | |
| 72 // static | |
| 73 ExtensionDialog* ExtensionDialog::ShowFullscreen( | |
| 74 const GURL& url, | |
| 75 Profile* profile, | |
| 76 const string16& title, | |
| 77 ExtensionDialogObserver* observer) { | |
| 78 extensions::ExtensionHost* host = CreateExtensionHost(url, profile); | |
| 79 if (!host) | |
| 80 return NULL; | |
| 81 | |
| 82 return ExtensionDialog::ShowInternal(url, NULL, host, 0, 0, | |
| 83 true, title, observer); | |
| 84 } | |
| 85 #endif | |
| 86 | |
| 87 // static | |
| 88 ExtensionDialog* ExtensionDialog::ShowInternal( | |
| 89 const GURL& url, | |
| 90 BaseWindow* base_window, | |
| 91 extensions::ExtensionHost* host, | |
| 92 int width, | |
| 93 int height, | |
| 94 bool fullscreen, | |
| 95 const string16& title, | |
| 96 ExtensionDialogObserver* observer) { | |
| 97 CHECK(fullscreen || base_window); | |
| 98 ExtensionDialog* dialog = new ExtensionDialog(host, observer); | 63 ExtensionDialog* dialog = new ExtensionDialog(host, observer); |
| 99 dialog->set_title(title); | 64 dialog->set_title(title); |
| 100 | 65 dialog->InitWindow(base_window, width, height); |
| 101 if (fullscreen) | |
| 102 dialog->InitWindowFullscreen(); | |
| 103 else | |
| 104 dialog->InitWindow(base_window, width, height); | |
| 105 | 66 |
| 106 // Show a white background while the extension loads. This is prettier than | 67 // Show a white background while the extension loads. This is prettier than |
| 107 // flashing a black unfilled window frame. | 68 // flashing a black unfilled window frame. |
| 108 host->view()->set_background( | 69 host->view()->set_background( |
| 109 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); | 70 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); |
| 110 host->view()->SetVisible(true); | 71 host->view()->SetVisible(true); |
| 111 | 72 |
| 112 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. | 73 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. |
| 113 host->host_contents()->GetView()->Focus(); | 74 host->host_contents()->GetView()->Focus(); |
| 114 return dialog; | 75 return dialog; |
| 115 } | 76 } |
| 116 | 77 |
| 117 // static | 78 // static |
| 118 extensions::ExtensionHost* ExtensionDialog::CreateExtensionHost( | 79 extensions::ExtensionHost* ExtensionDialog::CreateExtensionHost( |
| 119 const GURL& url, | 80 const GURL& url, |
| 120 Profile* profile) { | 81 Profile* profile) { |
| 121 DCHECK(profile); | 82 DCHECK(profile); |
| 122 ExtensionProcessManager* manager = | 83 ExtensionProcessManager* manager = |
| 123 extensions::ExtensionSystem::Get(profile)->process_manager(); | 84 extensions::ExtensionSystem::Get(profile)->process_manager(); |
| 124 | 85 |
| 125 DCHECK(manager); | 86 DCHECK(manager); |
| 126 if (!manager) | 87 if (!manager) |
| 127 return NULL; | 88 return NULL; |
| 128 return manager->CreateDialogHost(url); | 89 return manager->CreateDialogHost(url); |
| 129 } | 90 } |
| 130 | 91 |
| 131 #if defined(USE_ASH) | |
| 132 void ExtensionDialog::InitWindowFullscreen() { | |
| 133 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); | |
| 134 gfx::Rect screen_rect = | |
| 135 ash::Shell::GetScreen()->GetDisplayNearestWindow(root_window).bounds(); | |
| 136 | |
| 137 // We want to be the fullscreen topmost child of the root window. | |
| 138 window_ = new views::Widget; | |
| 139 views::Widget::InitParams params( | |
| 140 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 141 params.delegate = this; | |
| 142 params.parent = root_window; | |
| 143 window_->Init(params); | |
| 144 window_->StackAtTop(); | |
| 145 window_->SetBounds(screen_rect); | |
| 146 window_->Show(); | |
| 147 | |
| 148 // TODO(jamescook): Remove redundant call to Activate()? | |
| 149 window_->Activate(); | |
| 150 } | |
| 151 #else | |
| 152 void ExtensionDialog::InitWindowFullscreen() { | |
| 153 NOTIMPLEMENTED(); | |
| 154 } | |
| 155 #endif | |
| 156 | |
| 157 | |
| 158 void ExtensionDialog::InitWindow(BaseWindow* base_window, | 92 void ExtensionDialog::InitWindow(BaseWindow* base_window, |
| 159 int width, | 93 int width, |
| 160 int height) { | 94 int height) { |
| 161 gfx::NativeWindow parent = base_window->GetNativeWindow(); | 95 gfx::NativeWindow parent = base_window->GetNativeWindow(); |
| 162 window_ = views::Widget::CreateWindowWithParent(this, parent); | 96 window_ = views::DialogDelegate::CreateDialogWidget(this, NULL, parent); |
| 163 | 97 |
| 164 // Center the window over the browser. | 98 // Center the window over the browser. |
| 165 gfx::Point center = base_window->GetBounds().CenterPoint(); | 99 gfx::Point center = base_window->GetBounds().CenterPoint(); |
| 166 int x = center.x() - width / 2; | 100 int x = center.x() - width / 2; |
| 167 int y = center.y() - height / 2; | 101 int y = center.y() - height / 2; |
| 168 // Ensure the top left and top right of the window are on screen, with | 102 // Ensure the top left and top right of the window are on screen, with |
| 169 // priority given to the top left. | 103 // priority given to the top left. |
| 170 gfx::Rect screen_rect = gfx::Screen::GetScreenFor(parent)-> | 104 gfx::Rect screen_rect = gfx::Screen::GetScreenFor(parent)-> |
| 171 GetDisplayNearestPoint(center).bounds(); | 105 GetDisplayNearestPoint(center).bounds(); |
| 172 gfx::Rect bounds_rect = gfx::Rect(x, y, width, height); | 106 gfx::Rect bounds_rect = gfx::Rect(x, y, width, height); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 138 |
| 205 // TODO(oshima): Views + aura doesn't seem to update the views focus | 139 // TODO(oshima): Views + aura doesn't seem to update the views focus |
| 206 // manager when an aura window gets focus. This is a workaround for | 140 // manager when an aura window gets focus. This is a workaround for |
| 207 // this issue. Fix it this and remove this workaround. | 141 // this issue. Fix it this and remove this workaround. |
| 208 // See bug.com/127222. | 142 // See bug.com/127222. |
| 209 focus_manager->SetFocusedView(GetContentsView()); | 143 focus_manager->SetFocusedView(GetContentsView()); |
| 210 view->Focus(); | 144 view->Focus(); |
| 211 } | 145 } |
| 212 | 146 |
| 213 ///////////////////////////////////////////////////////////////////////////// | 147 ///////////////////////////////////////////////////////////////////////////// |
| 214 // views::WidgetDelegate overrides. | 148 // views::DialogDelegate overrides. |
| 149 |
| 150 int ExtensionDialog::GetDialogButtons() const { |
| 151 // The only user, SelectFileDialogExtension, provides its own buttons. |
| 152 return ui::DIALOG_BUTTON_NONE; |
| 153 } |
| 215 | 154 |
| 216 bool ExtensionDialog::CanResize() const { | 155 bool ExtensionDialog::CanResize() const { |
| 217 // Can resize only if minimum contents size set. | 156 // Can resize only if minimum contents size set. |
| 218 return extension_host_->view()->GetPreferredSize() != gfx::Size(); | 157 return extension_host_->view()->GetPreferredSize() != gfx::Size(); |
| 219 } | 158 } |
| 220 | 159 |
| 221 void ExtensionDialog::SetMinimumContentsSize(int width, int height) { | 160 void ExtensionDialog::SetMinimumContentsSize(int width, int height) { |
| 222 extension_host_->view()->SetPreferredSize(gfx::Size(width, height)); | 161 extension_host_->view()->SetPreferredSize(gfx::Size(width, height)); |
| 223 } | 162 } |
| 224 | 163 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (content::Details<extensions::ExtensionHost>(host()) != details) | 221 if (content::Details<extensions::ExtensionHost>(host()) != details) |
| 283 return; | 222 return; |
| 284 if (observer_) | 223 if (observer_) |
| 285 observer_->ExtensionTerminated(this); | 224 observer_->ExtensionTerminated(this); |
| 286 break; | 225 break; |
| 287 default: | 226 default: |
| 288 NOTREACHED() << L"Received unexpected notification"; | 227 NOTREACHED() << L"Received unexpected notification"; |
| 289 break; | 228 break; |
| 290 } | 229 } |
| 291 } | 230 } |
| OLD | NEW |