Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(672)

Side by Side Diff: chrome/browser/ui/views/extensions/extension_dialog.cc

Issue 10913243: extensions: Add ExtensionView interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: virtual dtor for cocoa and gtk ports Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 13 matching lines...) Expand all
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(extensions::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 view_(static_cast<ExtensionViewViews*>(host->GetExtensionView())),
34 observer_(observer) { 35 observer_(observer) {
35 AddRef(); // Balanced in DeleteDelegate(); 36 AddRef(); // Balanced in DeleteDelegate();
36 37
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 38 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
38 content::Source<Profile>(host->profile())); 39 content::Source<Profile>(host->profile()));
39 // Listen for the containing view calling window.close(); 40 // Listen for the containing view calling window.close();
40 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 41 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
41 content::Source<Profile>(host->profile())); 42 content::Source<Profile>(host->profile()));
42 // Listen for a crash or other termination of the extension process. 43 // Listen for a crash or other termination of the extension process.
43 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 44 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 ExtensionDialog* dialog = new ExtensionDialog(host, observer); 97 ExtensionDialog* dialog = new ExtensionDialog(host, observer);
97 dialog->set_title(title); 98 dialog->set_title(title);
98 99
99 if (fullscreen) 100 if (fullscreen)
100 dialog->InitWindowFullscreen(); 101 dialog->InitWindowFullscreen();
101 else 102 else
102 dialog->InitWindow(base_window, width, height); 103 dialog->InitWindow(base_window, width, height);
103 104
104 // Show a white background while the extension loads. This is prettier than 105 // Show a white background while the extension loads. This is prettier than
105 // flashing a black unfilled window frame. 106 // flashing a black unfilled window frame.
106 host->view()->set_background( 107 view_->set_background(
107 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF)); 108 views::Background::CreateSolidBackground(0xFF, 0xFF, 0xFF));
108 host->view()->SetVisible(true); 109 view_->SetVisible(true);
109 110
110 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts. 111 // Ensure the DOM JavaScript can respond immediately to keyboard shortcuts.
111 host->host_contents()->Focus(); 112 host->host_contents()->Focus();
112 return dialog; 113 return dialog;
113 } 114 }
114 115
115 // static 116 // static
116 extensions::ExtensionHost* ExtensionDialog::CreateExtensionHost( 117 extensions::ExtensionHost* ExtensionDialog::CreateExtensionHost(
117 const GURL& url, 118 const GURL& url,
118 Profile* profile) { 119 Profile* profile) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // See bug.com/127222. 205 // See bug.com/127222.
205 focus_manager->SetFocusedView(GetContentsView()); 206 focus_manager->SetFocusedView(GetContentsView());
206 view->Focus(); 207 view->Focus();
207 } 208 }
208 209
209 ///////////////////////////////////////////////////////////////////////////// 210 /////////////////////////////////////////////////////////////////////////////
210 // views::WidgetDelegate overrides. 211 // views::WidgetDelegate overrides.
211 212
212 bool ExtensionDialog::CanResize() const { 213 bool ExtensionDialog::CanResize() const {
213 // Can resize only if minimum contents size set. 214 // Can resize only if minimum contents size set.
214 return extension_host_->view()->GetPreferredSize() != gfx::Size(); 215 return view_->GetPreferredSize() != gfx::Size();
215 } 216 }
216 217
217 void ExtensionDialog::SetMinimumContentsSize(int width, int height) { 218 void ExtensionDialog::SetMinimumContentsSize(int width, int height) {
218 extension_host_->view()->SetPreferredSize(gfx::Size(width, height)); 219 view_->SetPreferredSize(gfx::Size(width, height));
219 } 220 }
220 221
221 ui::ModalType ExtensionDialog::GetModalType() const { 222 ui::ModalType ExtensionDialog::GetModalType() const {
222 return ui::MODAL_TYPE_WINDOW; 223 return ui::MODAL_TYPE_WINDOW;
223 } 224 }
224 225
225 bool ExtensionDialog::ShouldShowWindowTitle() const { 226 bool ExtensionDialog::ShouldShowWindowTitle() const {
226 return !window_title_.empty(); 227 return !window_title_.empty();
227 } 228 }
228 229
229 string16 ExtensionDialog::GetWindowTitle() const { 230 string16 ExtensionDialog::GetWindowTitle() const {
230 return window_title_; 231 return window_title_;
231 } 232 }
232 233
233 void ExtensionDialog::WindowClosing() { 234 void ExtensionDialog::WindowClosing() {
234 if (observer_) 235 if (observer_)
235 observer_->ExtensionDialogClosing(this); 236 observer_->ExtensionDialogClosing(this);
236 } 237 }
237 238
238 void ExtensionDialog::DeleteDelegate() { 239 void ExtensionDialog::DeleteDelegate() {
239 // The window has finished closing. Allow ourself to be deleted. 240 // The window has finished closing. Allow ourself to be deleted.
240 Release(); 241 Release();
241 } 242 }
242 243
243 views::Widget* ExtensionDialog::GetWidget() { 244 views::Widget* ExtensionDialog::GetWidget() {
244 return extension_host_->view()->GetWidget(); 245 return view_->GetWidget();
245 } 246 }
246 247
247 const views::Widget* ExtensionDialog::GetWidget() const { 248 const views::Widget* ExtensionDialog::GetWidget() const {
248 return extension_host_->view()->GetWidget(); 249 return view_->GetWidget();
249 } 250 }
250 251
251 views::View* ExtensionDialog::GetContentsView() { 252 views::View* ExtensionDialog::GetContentsView() {
252 return extension_host_->view(); 253 return view_;
253 } 254 }
254 255
255 ///////////////////////////////////////////////////////////////////////////// 256 /////////////////////////////////////////////////////////////////////////////
256 // content::NotificationObserver overrides. 257 // content::NotificationObserver overrides.
257 258
258 void ExtensionDialog::Observe(int type, 259 void ExtensionDialog::Observe(int type,
259 const content::NotificationSource& source, 260 const content::NotificationSource& source,
260 const content::NotificationDetails& details) { 261 const content::NotificationDetails& details) {
261 switch (type) { 262 switch (type) {
262 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: 263 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING:
263 // Avoid potential overdraw by removing the temporary background after 264 // Avoid potential overdraw by removing the temporary background after
264 // the extension finishes loading. 265 // the extension finishes loading.
265 extension_host_->view()->set_background(NULL); 266 view_->set_background(NULL);
266 // The render view is created during the LoadURL(), so we should 267 // The render view is created during the LoadURL(), so we should
267 // set the focus to the view if nobody else takes the focus. 268 // set the focus to the view if nobody else takes the focus.
268 if (content::Details<extensions::ExtensionHost>(host()) == details) 269 if (content::Details<extensions::ExtensionHost>(host()) == details)
269 MaybeFocusRenderView(); 270 MaybeFocusRenderView();
270 break; 271 break;
271 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE: 272 case chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
272 // If we aren't the host of the popup, then disregard the notification. 273 // If we aren't the host of the popup, then disregard the notification.
273 if (content::Details<extensions::ExtensionHost>(host()) != details) 274 if (content::Details<extensions::ExtensionHost>(host()) != details)
274 return; 275 return;
275 Close(); 276 Close();
276 break; 277 break;
277 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: 278 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED:
278 if (content::Details<extensions::ExtensionHost>(host()) != details) 279 if (content::Details<extensions::ExtensionHost>(host()) != details)
279 return; 280 return;
280 if (observer_) 281 if (observer_)
281 observer_->ExtensionTerminated(this); 282 observer_->ExtensionTerminated(this);
282 break; 283 break;
283 default: 284 default:
284 NOTREACHED() << L"Received unexpected notification"; 285 NOTREACHED() << L"Received unexpected notification";
285 break; 286 break;
286 } 287 }
287 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698