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/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/base_window.h" | 10 #include "chrome/browser/ui/base_window.h" |
11 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" | 11 #include "chrome/browser/ui/views/extensions/extension_dialog_observer.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "content/public/browser/notification_details.h" | 13 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
20 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 | 22 |
23 #if defined(USE_ASH) | 23 #if defined(USE_ASH) |
24 #include "ash/shell.h" | 24 #include "ash/shell.h" |
25 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
26 #endif | 26 #endif |
27 | 27 |
28 using content::WebContents; | 28 using content::WebContents; |
29 | 29 |
30 ExtensionDialog::ExtensionDialog(ExtensionHost* host, | 30 ExtensionDialog::ExtensionDialog(extensions::ExtensionHost* host, |
31 ExtensionDialogObserver* observer) | 31 ExtensionDialogObserver* observer) |
32 : window_(NULL), | 32 : window_(NULL), |
33 extension_host_(host), | 33 extension_host_(host), |
34 observer_(observer) { | 34 observer_(observer) { |
35 AddRef(); // Balanced in DeleteDelegate(); | 35 AddRef(); // Balanced in DeleteDelegate(); |
36 | 36 |
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
38 content::Source<Profile>(host->profile())); | 38 content::Source<Profile>(host->profile())); |
39 // Listen for the containing view calling window.close(); | 39 // Listen for the containing view calling window.close(); |
40 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 40 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
41 content::Source<Profile>(host->profile())); | 41 content::Source<Profile>(host->profile())); |
42 // Listen for a crash or other termination of the extension process. | 42 // Listen for a crash or other termination of the extension process. |
43 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 43 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
44 content::Source<Profile>(host->profile())); | 44 content::Source<Profile>(host->profile())); |
45 } | 45 } |
46 | 46 |
47 ExtensionDialog::~ExtensionDialog() { | 47 ExtensionDialog::~ExtensionDialog() { |
48 } | 48 } |
49 | 49 |
50 // static | 50 // static |
51 ExtensionDialog* ExtensionDialog::Show( | 51 ExtensionDialog* ExtensionDialog::Show( |
52 const GURL& url, | 52 const GURL& url, |
53 BaseWindow* base_window, | 53 BaseWindow* base_window, |
54 Profile* profile, | 54 Profile* profile, |
55 WebContents* web_contents, | 55 WebContents* web_contents, |
56 int width, | 56 int width, |
57 int height, | 57 int height, |
58 const string16& title, | 58 const string16& title, |
59 ExtensionDialogObserver* observer) { | 59 ExtensionDialogObserver* observer) { |
60 ExtensionHost* host = CreateExtensionHost(url, profile); | 60 extensions::ExtensionHost* host = CreateExtensionHost(url, profile); |
61 if (!host) | 61 if (!host) |
62 return NULL; | 62 return NULL; |
63 host->SetAssociatedWebContents(web_contents); | 63 host->SetAssociatedWebContents(web_contents); |
64 | 64 |
65 return ExtensionDialog::ShowInternal(url, base_window, host, width, height, | 65 return ExtensionDialog::ShowInternal(url, base_window, host, width, height, |
66 false, title, observer); | 66 false, title, observer); |
67 } | 67 } |
68 | 68 |
69 #if defined(USE_AURA) | 69 #if defined(USE_AURA) |
70 // static | 70 // static |
71 ExtensionDialog* ExtensionDialog::ShowFullscreen( | 71 ExtensionDialog* ExtensionDialog::ShowFullscreen( |
72 const GURL& url, | 72 const GURL& url, |
73 Profile* profile, | 73 Profile* profile, |
74 const string16& title, | 74 const string16& title, |
75 ExtensionDialogObserver* observer) { | 75 ExtensionDialogObserver* observer) { |
76 ExtensionHost* host = CreateExtensionHost(url, profile); | 76 extensions::ExtensionHost* host = CreateExtensionHost(url, profile); |
77 if (!host) | 77 if (!host) |
78 return NULL; | 78 return NULL; |
79 | 79 |
80 return ExtensionDialog::ShowInternal(url, NULL, host, 0, 0, | 80 return ExtensionDialog::ShowInternal(url, NULL, host, 0, 0, |
81 true, title, observer); | 81 true, title, observer); |
82 } | 82 } |
83 #endif | 83 #endif |
84 | 84 |
85 // static | 85 // static |
86 ExtensionDialog* ExtensionDialog::ShowInternal(const GURL& url, | 86 ExtensionDialog* ExtensionDialog::ShowInternal( |
| 87 const GURL& url, |
87 BaseWindow* base_window, | 88 BaseWindow* base_window, |
88 ExtensionHost* host, | 89 extensions::ExtensionHost* host, |
89 int width, | 90 int width, |
90 int height, | 91 int height, |
91 bool fullscreen, | 92 bool fullscreen, |
92 const string16& title, | 93 const string16& title, |
93 ExtensionDialogObserver* observer) { | 94 ExtensionDialogObserver* observer) { |
94 CHECK(fullscreen || base_window); | 95 CHECK(fullscreen || base_window); |
95 ExtensionDialog* dialog = new ExtensionDialog(host, observer); | 96 ExtensionDialog* dialog = new ExtensionDialog(host, observer); |
96 dialog->set_title(title); | 97 dialog->set_title(title); |
97 | 98 |
98 if (fullscreen) | 99 if (fullscreen) |
99 dialog->InitWindowFullscreen(); | 100 dialog->InitWindowFullscreen(); |
100 else | 101 else |
101 dialog->InitWindow(base_window, width, height); | 102 dialog->InitWindow(base_window, width, height); |
102 | 103 |
103 // Show a white background while the extension loads. This is prettier than | 104 // Show a white background while the extension loads. This is prettier than |
104 // flashing a black unfilled window frame. | 105 // flashing a black unfilled window frame. |
105 host->view()->set_background( | 106 host->view()->set_background( |
106 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); | 107 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); |
107 host->view()->SetVisible(true); | 108 host->view()->SetVisible(true); |
108 | 109 |
109 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. | 110 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. |
110 host->host_contents()->Focus(); | 111 host->host_contents()->Focus(); |
111 return dialog; | 112 return dialog; |
112 } | 113 } |
113 | 114 |
114 // static | 115 // static |
115 ExtensionHost* ExtensionDialog::CreateExtensionHost(const GURL& url, | 116 extensions::ExtensionHost* ExtensionDialog::CreateExtensionHost( |
116 Profile* profile) { | 117 const GURL& url, |
| 118 Profile* profile) { |
117 DCHECK(profile); | 119 DCHECK(profile); |
118 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); | 120 ExtensionProcessManager* manager = profile->GetExtensionProcessManager(); |
119 | 121 |
120 DCHECK(manager); | 122 DCHECK(manager); |
121 if (!manager) | 123 if (!manager) |
122 return NULL; | 124 return NULL; |
123 return manager->CreateDialogHost(url); | 125 return manager->CreateDialogHost(url); |
124 } | 126 } |
125 | 127 |
126 #if defined(USE_ASH) | 128 #if defined(USE_ASH) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 void ExtensionDialog::Observe(int type, | 258 void ExtensionDialog::Observe(int type, |
257 const content::NotificationSource& source, | 259 const content::NotificationSource& source, |
258 const content::NotificationDetails& details) { | 260 const content::NotificationDetails& details) { |
259 switch (type) { | 261 switch (type) { |
260 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: | 262 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: |
261 // Avoid potential overdraw by removing the temporary background after | 263 // Avoid potential overdraw by removing the temporary background after |
262 // the extension finishes loading. | 264 // the extension finishes loading. |
263 extension_host_->view()->set_background(NULL); | 265 extension_host_->view()->set_background(NULL); |
264 // The render view is created during the LoadURL(), so we should | 266 // The render view is created during the LoadURL(), so we should |
265 // set the focus to the view if nobody else takes the focus. | 267 // set the focus to the view if nobody else takes the focus. |
266 if (content::Details<ExtensionHost>(host()) == details) | 268 if (content::Details<extensions::ExtensionHost>(host()) == details) |
267 MaybeFocusRenderView(); | 269 MaybeFocusRenderView(); |
268 break; | 270 break; |
269 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: | 271 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: |
270 // If we aren't the host of the popup, then disregard the notification. | 272 // If we aren't the host of the popup, then disregard the notification. |
271 if (content::Details<ExtensionHost>(host()) != details) | 273 if (content::Details<extensions::ExtensionHost>(host()) != details) |
272 return; | 274 return; |
273 Close(); | 275 Close(); |
274 break; | 276 break; |
275 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: | 277 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
276 if (content::Details<ExtensionHost>(host()) != details) | 278 if (content::Details<extensions::ExtensionHost>(host()) != details) |
277 return; | 279 return; |
278 if (observer_) | 280 if (observer_) |
279 observer_->ExtensionTerminated(this); | 281 observer_->ExtensionTerminated(this); |
280 break; | 282 break; |
281 default: | 283 default: |
282 NOTREACHED() << L"Received unexpected notification"; | 284 NOTREACHED() << L"Received unexpected notification"; |
283 break; | 285 break; |
284 } | 286 } |
285 } | 287 } |
OLD | NEW |