| 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/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/browser/extensions/extension_process_manager.h" | 9 #include "chrome/browser/extensions/extension_host_factory.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/views/constrained_window_views.h" | 11 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 13 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" | 12 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
| 14 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
| 18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
| 20 #include "ui/base/base_window.h" | 19 #include "ui/base/base_window.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 const GURL& url, | 48 const GURL& url, |
| 50 ui::BaseWindow* base_window, | 49 ui::BaseWindow* base_window, |
| 51 Profile* profile, | 50 Profile* profile, |
| 52 WebContents* web_contents, | 51 WebContents* web_contents, |
| 53 int width, | 52 int width, |
| 54 int height, | 53 int height, |
| 55 int min_width, | 54 int min_width, |
| 56 int min_height, | 55 int min_height, |
| 57 const string16& title, | 56 const string16& title, |
| 58 ExtensionDialogObserver* observer) { | 57 ExtensionDialogObserver* observer) { |
| 59 extensions::ExtensionHost* host = CreateExtensionHost(url, profile); | 58 extensions::ExtensionHost* host = |
| 59 extensions::ExtensionHostFactory::CreateDialogHost(url, profile); |
| 60 if (!host) | 60 if (!host) |
| 61 return NULL; | 61 return NULL; |
| 62 // Preferred size must be set before views::Widget::CreateWindowWithParent | 62 // Preferred size must be set before views::Widget::CreateWindowWithParent |
| 63 // is called because CreateWindowWithParent refers the result of CanResize(). | 63 // is called because CreateWindowWithParent refers the result of CanResize(). |
| 64 host->view()->SetPreferredSize(gfx::Size(min_width, min_height)); | 64 host->view()->SetPreferredSize(gfx::Size(min_width, min_height)); |
| 65 host->SetAssociatedWebContents(web_contents); | 65 host->SetAssociatedWebContents(web_contents); |
| 66 | 66 |
| 67 CHECK(base_window); | 67 CHECK(base_window); |
| 68 ExtensionDialog* dialog = new ExtensionDialog(host, observer); | 68 ExtensionDialog* dialog = new ExtensionDialog(host, observer); |
| 69 dialog->set_title(title); | 69 dialog->set_title(title); |
| 70 dialog->InitWindow(base_window, width, height); | 70 dialog->InitWindow(base_window, width, height); |
| 71 | 71 |
| 72 // Show a white background while the extension loads. This is prettier than | 72 // Show a white background while the extension loads. This is prettier than |
| 73 // flashing a black unfilled window frame. | 73 // flashing a black unfilled window frame. |
| 74 host->view()->set_background( | 74 host->view()->set_background( |
| 75 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); | 75 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); |
| 76 host->view()->SetVisible(true); | 76 host->view()->SetVisible(true); |
| 77 | 77 |
| 78 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. | 78 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. |
| 79 host->host_contents()->GetView()->Focus(); | 79 host->host_contents()->GetView()->Focus(); |
| 80 return dialog; | 80 return dialog; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // static | |
| 84 extensions::ExtensionHost* ExtensionDialog::CreateExtensionHost( | |
| 85 const GURL& url, | |
| 86 Profile* profile) { | |
| 87 DCHECK(profile); | |
| 88 ExtensionProcessManager* manager = | |
| 89 extensions::ExtensionSystem::Get(profile)->process_manager(); | |
| 90 | |
| 91 DCHECK(manager); | |
| 92 if (!manager) | |
| 93 return NULL; | |
| 94 return manager->CreateDialogHost(url); | |
| 95 } | |
| 96 | |
| 97 void ExtensionDialog::InitWindow(ui::BaseWindow* base_window, | 83 void ExtensionDialog::InitWindow(ui::BaseWindow* base_window, |
| 98 int width, | 84 int width, |
| 99 int height) { | 85 int height) { |
| 100 gfx::NativeWindow parent = base_window->GetNativeWindow(); | 86 gfx::NativeWindow parent = base_window->GetNativeWindow(); |
| 101 views::Widget* window = CreateBrowserModalDialogViews(this, parent); | 87 views::Widget* window = CreateBrowserModalDialogViews(this, parent); |
| 102 | 88 |
| 103 // Center the window over the browser. | 89 // Center the window over the browser. |
| 104 gfx::Point center = base_window->GetBounds().CenterPoint(); | 90 gfx::Point center = base_window->GetBounds().CenterPoint(); |
| 105 int x = center.x() - width / 2; | 91 int x = center.x() - width / 2; |
| 106 int y = center.y() - height / 2; | 92 int y = center.y() - height / 2; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (content::Details<extensions::ExtensionHost>(host()) != details) | 203 if (content::Details<extensions::ExtensionHost>(host()) != details) |
| 218 return; | 204 return; |
| 219 if (observer_) | 205 if (observer_) |
| 220 observer_->ExtensionTerminated(this); | 206 observer_->ExtensionTerminated(this); |
| 221 break; | 207 break; |
| 222 default: | 208 default: |
| 223 NOTREACHED() << L"Received unexpected notification"; | 209 NOTREACHED() << L"Received unexpected notification"; |
| 224 break; | 210 break; |
| 225 } | 211 } |
| 226 } | 212 } |
| OLD | NEW |