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

Side by Side Diff: chrome/browser/ui/gtk/web_intent_picker_gtk.cc

Issue 11141037: Disable delegation to picker controller once it is deleted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK on accessor. Created 8 years, 2 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/gtk/web_intent_picker_gtk.h" 5 #include "chrome/browser/ui/gtk/web_intent_picker_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 281
282 void WebIntentPickerGtk::OnExtensionIconChanged( 282 void WebIntentPickerGtk::OnExtensionIconChanged(
283 WebIntentPickerModel* model, 283 WebIntentPickerModel* model,
284 const std::string& extension_id) { 284 const std::string& extension_id) {
285 UpdateSuggestedExtensions(); 285 UpdateSuggestedExtensions();
286 } 286 }
287 287
288 void WebIntentPickerGtk::OnInlineDisposition(const string16& title, 288 void WebIntentPickerGtk::OnInlineDisposition(const string16& title,
289 const GURL& url) { 289 const GURL& url) {
290 DCHECK(delegate_);
290 content::WebContents* web_contents = 291 content::WebContents* web_contents =
291 delegate_->CreateWebContentsForInlineDisposition( 292 delegate_->CreateWebContentsForInlineDisposition(
292 tab_contents_->profile(), url); 293 tab_contents_->profile(), url);
293 inline_disposition_tab_contents_.reset( 294 inline_disposition_tab_contents_.reset(
294 TabContents::Factory::CreateTabContents(web_contents)); 295 TabContents::Factory::CreateTabContents(web_contents));
295 Browser* browser = browser::FindBrowserWithWebContents( 296 Browser* browser = browser::FindBrowserWithWebContents(
296 tab_contents_->web_contents()); 297 tab_contents_->web_contents());
297 inline_disposition_delegate_.reset( 298 inline_disposition_delegate_.reset(
298 new WebIntentInlineDispositionDelegate(this, web_contents, browser)); 299 new WebIntentInlineDispositionDelegate(this, web_contents, browser));
299 300
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 gtk_misc_set_alignment(GTK_MISC(no_service_label), 0, 0); 408 gtk_misc_set_alignment(GTK_MISC(no_service_label), 0, 0);
408 // Set the label width to the size of |sub_contents|, which we don't have 409 // Set the label width to the size of |sub_contents|, which we don't have
409 // access to yet, by calculating the main content width minus borders. 410 // access to yet, by calculating the main content width minus borders.
410 gtk_util::SetLabelWidth(no_service_label, 411 gtk_util::SetLabelWidth(no_service_label,
411 kWindowMinWidth - 2 * ui::kContentAreaBorder); 412 kWindowMinWidth - 2 * ui::kContentAreaBorder);
412 gtk_box_pack_start(GTK_BOX(hbox), no_service_label, TRUE, TRUE, 0); 413 gtk_box_pack_start(GTK_BOX(hbox), no_service_label, TRUE, TRUE, 0);
413 414
414 gtk_widget_show_all(contents_); 415 gtk_widget_show_all(contents_);
415 } 416 }
416 417
418 void WebIntentPickerGtk::InvalidateDelegate() {
419 delegate_ = NULL;
420 }
421
417 GtkWidget* WebIntentPickerGtk::GetWidgetRoot() { 422 GtkWidget* WebIntentPickerGtk::GetWidgetRoot() {
418 return contents_; 423 return contents_;
419 } 424 }
420 425
421 GtkWidget* WebIntentPickerGtk::GetFocusWidget() { 426 GtkWidget* WebIntentPickerGtk::GetFocusWidget() {
422 return contents_; 427 return contents_;
423 } 428 }
424 429
425 void WebIntentPickerGtk::DeleteDelegate() { 430 void WebIntentPickerGtk::DeleteDelegate() {
426 // The delegate is deleted when the contents widget is destroyed. See 431 // The delegate is deleted when the contents widget is destroyed. See
427 // OnDestroy. 432 // OnDestroy.
428 delegate_->OnClosing(); 433 if (delegate_)
434 delegate_->OnClosing();
429 } 435 }
430 436
431 bool WebIntentPickerGtk::ShouldHaveBorderPadding() const { 437 bool WebIntentPickerGtk::ShouldHaveBorderPadding() const {
432 return false; 438 return false;
433 } 439 }
434 440
435 void WebIntentPickerGtk::Observe(int type, 441 void WebIntentPickerGtk::Observe(int type,
436 const content::NotificationSource& source, 442 const content::NotificationSource& source,
437 const content::NotificationDetails& details) { 443 const content::NotificationDetails& details) {
438 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); 444 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED);
(...skipping 10 matching lines...) Expand all
449 455
450 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) { 456 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) {
451 // Destroy this object when the contents widget is destroyed. It can't be 457 // Destroy this object when the contents widget is destroyed. It can't be
452 // "delete this" because this function happens in a callback. 458 // "delete this" because this function happens in a callback.
453 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 459 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
454 model_->set_observer(NULL); 460 model_->set_observer(NULL);
455 window_ = NULL; 461 window_ = NULL;
456 } 462 }
457 463
458 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) { 464 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) {
465 DCHECK(delegate_);
459 delegate_->OnUserCancelledPickerDialog(); 466 delegate_->OnUserCancelledPickerDialog();
460 } 467 }
461 468
462 void WebIntentPickerGtk::OnExtensionLinkClick(GtkWidget* link) { 469 void WebIntentPickerGtk::OnExtensionLinkClick(GtkWidget* link) {
470 DCHECK(delegate_);
463 size_t index = GetExtensionWidgetRow(link); 471 size_t index = GetExtensionWidgetRow(link);
464 const WebIntentPickerModel::SuggestedExtension& extension = 472 const WebIntentPickerModel::SuggestedExtension& extension =
465 model_->GetSuggestedExtensionAt(index); 473 model_->GetSuggestedExtensionAt(index);
466 delegate_->OnExtensionLinkClicked(extension.id, 474 delegate_->OnExtensionLinkClicked(extension.id,
467 event_utils::DispositionForCurrentButtonPressEvent()); 475 event_utils::DispositionForCurrentButtonPressEvent());
468 } 476 }
469 477
470 void WebIntentPickerGtk::OnExtensionInstallButtonClick(GtkWidget* button) { 478 void WebIntentPickerGtk::OnExtensionInstallButtonClick(GtkWidget* button) {
479 DCHECK(delegate_);
471 size_t index = GetExtensionWidgetRow(button); 480 size_t index = GetExtensionWidgetRow(button);
472 const WebIntentPickerModel::SuggestedExtension& extension = 481 const WebIntentPickerModel::SuggestedExtension& extension =
473 model_->GetSuggestedExtensionAt(index); 482 model_->GetSuggestedExtensionAt(index);
474 483
475 delegate_->OnExtensionInstallRequested(extension.id); 484 delegate_->OnExtensionInstallRequested(extension.id);
476 SetWidgetsEnabled(false); 485 SetWidgetsEnabled(false);
477 486
478 // Re-enable the clicked extension row. 487 // Re-enable the clicked extension row.
479 GList* vbox_list = 488 GList* vbox_list =
480 gtk_container_get_children(GTK_CONTAINER(extensions_vbox_)); 489 gtk_container_get_children(GTK_CONTAINER(extensions_vbox_));
(...skipping 10 matching lines...) Expand all
491 g_list_free(hbox_list); 500 g_list_free(hbox_list);
492 g_list_free(vbox_list); 501 g_list_free(vbox_list);
493 502
494 // Show the throbber with the same size as the install button. 503 // Show the throbber with the same size as the install button.
495 GtkWidget* throbber = AddThrobberToExtensionAt(index); 504 GtkWidget* throbber = AddThrobberToExtensionAt(index);
496 gtk_widget_set_size_request(throbber, allocation.width, allocation.height); 505 gtk_widget_set_size_request(throbber, allocation.width, allocation.height);
497 gtk_widget_show_all(throbber); 506 gtk_widget_show_all(throbber);
498 } 507 }
499 508
500 void WebIntentPickerGtk::OnMoreSuggestionsLinkClick(GtkWidget* link) { 509 void WebIntentPickerGtk::OnMoreSuggestionsLinkClick(GtkWidget* link) {
501 // TODO(binji): This should link to a CWS search, based on the current 510 DCHECK(delegate_);
502 // action/type pair.
503 delegate_->OnSuggestionsLinkClicked( 511 delegate_->OnSuggestionsLinkClicked(
504 event_utils::DispositionForCurrentButtonPressEvent()); 512 event_utils::DispositionForCurrentButtonPressEvent());
505 } 513 }
506 514
507 void WebIntentPickerGtk::OnChooseAnotherServiceClick(GtkWidget* link) { 515 void WebIntentPickerGtk::OnChooseAnotherServiceClick(GtkWidget* link) {
516 DCHECK(delegate_);
508 delegate_->OnChooseAnotherService(); 517 delegate_->OnChooseAnotherService();
509 ResetContents(); 518 ResetContents();
510 } 519 }
511 520
512 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { 521 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) {
522 DCHECK(delegate_);
513 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_)); 523 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_));
514 gint index = g_list_index(button_list, button); 524 gint index = g_list_index(button_list, button);
515 DCHECK(index != -1); 525 DCHECK(index != -1);
516 g_list_free(button_list); 526 g_list_free(button_list);
517 527
518 const WebIntentPickerModel::InstalledService& installed_service = 528 const WebIntentPickerModel::InstalledService& installed_service =
519 model_->GetInstalledServiceAt(index); 529 model_->GetInstalledServiceAt(index);
520 530
521 delegate_->OnServiceChosen(installed_service.url, 531 delegate_->OnServiceChosen(installed_service.url,
522 installed_service.disposition, 532 installed_service.disposition,
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 return alignment; 826 return alignment;
817 } 827 }
818 828
819 void WebIntentPickerGtk::RemoveThrobber() { 829 void WebIntentPickerGtk::RemoveThrobber() {
820 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget()); 830 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget());
821 DCHECK(alignment); 831 DCHECK(alignment);
822 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget()); 832 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget());
823 gtk_widget_destroy(alignment); 833 gtk_widget_destroy(alignment);
824 throbber_->Stop(); 834 throbber_->Stop();
825 } 835 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698