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

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: rebase, fix tests. 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 288 }
289 289
290 void WebIntentPickerGtk::OnExtensionIconChanged( 290 void WebIntentPickerGtk::OnExtensionIconChanged(
291 WebIntentPickerModel* model, 291 WebIntentPickerModel* model,
292 const std::string& extension_id) { 292 const std::string& extension_id) {
293 UpdateSuggestedExtensions(); 293 UpdateSuggestedExtensions();
294 } 294 }
295 295
296 void WebIntentPickerGtk::OnInlineDisposition(const string16&, 296 void WebIntentPickerGtk::OnInlineDisposition(const string16&,
297 const GURL& url) { 297 const GURL& url) {
298 DCHECK(delegate_);
298 content::WebContents* web_contents = 299 content::WebContents* web_contents =
299 delegate_->CreateWebContentsForInlineDisposition( 300 delegate_->CreateWebContentsForInlineDisposition(
300 tab_contents_->profile(), url); 301 tab_contents_->profile(), url);
301 inline_disposition_tab_contents_.reset( 302 inline_disposition_tab_contents_.reset(
302 TabContents::Factory::CreateTabContents(web_contents)); 303 TabContents::Factory::CreateTabContents(web_contents));
303 Browser* browser = browser::FindBrowserWithWebContents( 304 Browser* browser = browser::FindBrowserWithWebContents(
304 tab_contents_->web_contents()); 305 tab_contents_->web_contents());
305 inline_disposition_delegate_.reset( 306 inline_disposition_delegate_.reset(
306 new WebIntentInlineDispositionDelegate(this, web_contents, browser)); 307 new WebIntentInlineDispositionDelegate(this, web_contents, browser));
307 308
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 gtk_misc_set_alignment(GTK_MISC(no_service_label), 0, 0); 414 gtk_misc_set_alignment(GTK_MISC(no_service_label), 0, 0);
414 // Set the label width to the size of |sub_contents|, which we don't have 415 // Set the label width to the size of |sub_contents|, which we don't have
415 // access to yet, by calculating the main content width minus borders. 416 // access to yet, by calculating the main content width minus borders.
416 gtk_util::SetLabelWidth(no_service_label, 417 gtk_util::SetLabelWidth(no_service_label,
417 kWindowMinWidth - 2 * ui::kContentAreaBorder); 418 kWindowMinWidth - 2 * ui::kContentAreaBorder);
418 gtk_box_pack_start(GTK_BOX(hbox), no_service_label, TRUE, TRUE, 0); 419 gtk_box_pack_start(GTK_BOX(hbox), no_service_label, TRUE, TRUE, 0);
419 420
420 gtk_widget_show_all(contents_); 421 gtk_widget_show_all(contents_);
421 } 422 }
422 423
424 void WebIntentPickerGtk::InvalidateDelegate() {
425 delegate_ = NULL;
426 }
427
423 GtkWidget* WebIntentPickerGtk::GetWidgetRoot() { 428 GtkWidget* WebIntentPickerGtk::GetWidgetRoot() {
424 return contents_; 429 return contents_;
425 } 430 }
426 431
427 GtkWidget* WebIntentPickerGtk::GetFocusWidget() { 432 GtkWidget* WebIntentPickerGtk::GetFocusWidget() {
428 return contents_; 433 return contents_;
429 } 434 }
430 435
431 void WebIntentPickerGtk::DeleteDelegate() { 436 void WebIntentPickerGtk::DeleteDelegate() {
432 // The delegate is deleted when the contents widget is destroyed. See 437 // The delegate is deleted when the contents widget is destroyed. See
433 // OnDestroy. 438 // OnDestroy.
434 delegate_->OnClosing(); 439 if (delegate_)
440 delegate_->OnClosing();
435 } 441 }
436 442
437 bool WebIntentPickerGtk::GetBackgroundColor(GdkColor* color) { 443 bool WebIntentPickerGtk::GetBackgroundColor(GdkColor* color) {
438 if (tab_contents_container_.get()) { 444 if (tab_contents_container_.get()) {
439 *color = ui::kGdkWhite; 445 *color = ui::kGdkWhite;
440 return true; 446 return true;
441 } 447 }
442 448
443 return false; 449 return false;
444 } 450 }
(...skipping 19 matching lines...) Expand all
464 470
465 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) { 471 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) {
466 // Destroy this object when the contents widget is destroyed. It can't be 472 // Destroy this object when the contents widget is destroyed. It can't be
467 // "delete this" because this function happens in a callback. 473 // "delete this" because this function happens in a callback.
468 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 474 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
469 model_->set_observer(NULL); 475 model_->set_observer(NULL);
470 window_ = NULL; 476 window_ = NULL;
471 } 477 }
472 478
473 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) { 479 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) {
480 DCHECK(delegate_);
474 delegate_->OnUserCancelledPickerDialog(); 481 delegate_->OnUserCancelledPickerDialog();
475 } 482 }
476 483
477 void WebIntentPickerGtk::OnExtensionLinkClick(GtkWidget* link) { 484 void WebIntentPickerGtk::OnExtensionLinkClick(GtkWidget* link) {
485 DCHECK(delegate_);
478 size_t index = GetExtensionWidgetRow(link); 486 size_t index = GetExtensionWidgetRow(link);
479 const WebIntentPickerModel::SuggestedExtension& extension = 487 const WebIntentPickerModel::SuggestedExtension& extension =
480 model_->GetSuggestedExtensionAt(index); 488 model_->GetSuggestedExtensionAt(index);
481 delegate_->OnExtensionLinkClicked(extension.id, 489 delegate_->OnExtensionLinkClicked(extension.id,
482 event_utils::DispositionForCurrentButtonPressEvent()); 490 event_utils::DispositionForCurrentButtonPressEvent());
483 } 491 }
484 492
485 void WebIntentPickerGtk::OnExtensionInstallButtonClick(GtkWidget* button) { 493 void WebIntentPickerGtk::OnExtensionInstallButtonClick(GtkWidget* button) {
494 DCHECK(delegate_);
486 size_t index = GetExtensionWidgetRow(button); 495 size_t index = GetExtensionWidgetRow(button);
487 const WebIntentPickerModel::SuggestedExtension& extension = 496 const WebIntentPickerModel::SuggestedExtension& extension =
488 model_->GetSuggestedExtensionAt(index); 497 model_->GetSuggestedExtensionAt(index);
489 498
490 delegate_->OnExtensionInstallRequested(extension.id); 499 delegate_->OnExtensionInstallRequested(extension.id);
491 SetWidgetsEnabled(false); 500 SetWidgetsEnabled(false);
492 501
493 // Re-enable the clicked extension row. 502 // Re-enable the clicked extension row.
494 GList* vbox_list = 503 GList* vbox_list =
495 gtk_container_get_children(GTK_CONTAINER(extensions_vbox_)); 504 gtk_container_get_children(GTK_CONTAINER(extensions_vbox_));
(...skipping 10 matching lines...) Expand all
506 g_list_free(hbox_list); 515 g_list_free(hbox_list);
507 g_list_free(vbox_list); 516 g_list_free(vbox_list);
508 517
509 // Show the throbber with the same size as the install button. 518 // Show the throbber with the same size as the install button.
510 GtkWidget* throbber = AddThrobberToExtensionAt(index); 519 GtkWidget* throbber = AddThrobberToExtensionAt(index);
511 gtk_widget_set_size_request(throbber, allocation.width, allocation.height); 520 gtk_widget_set_size_request(throbber, allocation.width, allocation.height);
512 gtk_widget_show_all(throbber); 521 gtk_widget_show_all(throbber);
513 } 522 }
514 523
515 void WebIntentPickerGtk::OnMoreSuggestionsLinkClick(GtkWidget* link) { 524 void WebIntentPickerGtk::OnMoreSuggestionsLinkClick(GtkWidget* link) {
516 // TODO(binji): This should link to a CWS search, based on the current 525 DCHECK(delegate_);
517 // action/type pair.
518 delegate_->OnSuggestionsLinkClicked( 526 delegate_->OnSuggestionsLinkClicked(
519 event_utils::DispositionForCurrentButtonPressEvent()); 527 event_utils::DispositionForCurrentButtonPressEvent());
520 } 528 }
521 529
522 void WebIntentPickerGtk::OnChooseAnotherServiceClick(GtkWidget* link) { 530 void WebIntentPickerGtk::OnChooseAnotherServiceClick(GtkWidget* link) {
531 DCHECK(delegate_);
523 delegate_->OnChooseAnotherService(); 532 delegate_->OnChooseAnotherService();
524 ResetContents(); 533 ResetContents();
525 } 534 }
526 535
527 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { 536 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) {
537 DCHECK(delegate_);
528 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_)); 538 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_));
529 gint index = g_list_index(button_list, button); 539 gint index = g_list_index(button_list, button);
530 DCHECK(index != -1); 540 DCHECK(index != -1);
531 g_list_free(button_list); 541 g_list_free(button_list);
532 542
533 const WebIntentPickerModel::InstalledService& installed_service = 543 const WebIntentPickerModel::InstalledService& installed_service =
534 model_->GetInstalledServiceAt(index); 544 model_->GetInstalledServiceAt(index);
535 545
536 delegate_->OnServiceChosen(installed_service.url, 546 delegate_->OnServiceChosen(installed_service.url,
537 installed_service.disposition, 547 installed_service.disposition,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 return alignment; 843 return alignment;
834 } 844 }
835 845
836 void WebIntentPickerGtk::RemoveThrobber() { 846 void WebIntentPickerGtk::RemoveThrobber() {
837 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget()); 847 GtkWidget* alignment = gtk_widget_get_parent(throbber_->widget());
838 DCHECK(alignment); 848 DCHECK(alignment);
839 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget()); 849 gtk_container_remove(GTK_CONTAINER(alignment), throbber_->widget());
840 gtk_widget_destroy(alignment); 850 gtk_widget_destroy(alignment);
841 throbber_->Stop(); 851 throbber_->Stop();
842 } 852 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698