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

Side by Side Diff: chrome/browser/ui/views/web_intent_picker_views.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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 views::View* child = host->child_at(i); 368 views::View* child = host->child_at(i);
369 if (!child->visible()) 369 if (!child->visible())
370 continue; 370 continue;
371 gfx::Size size(child->GetPreferredSize()); 371 gfx::Size size(child->GetPreferredSize());
372 gfx::Rect child_bounds(x, y, size.width(), child_area.height()); 372 gfx::Rect child_bounds(x, y, size.width(), child_area.height());
373 if (i == host->child_count() - 1) { 373 if (i == host->child_count() - 1) {
374 // Last child (the install button) should be right aligned. 374 // Last child (the install button) should be right aligned.
375 child_bounds.set_x(std::max(child_area.width() - size.width(), x)); 375 child_bounds.set_x(std::max(child_area.width() - size.width(), x));
376 } else if (i == 1) { 376 } else if (i == 1) {
377 // Label is considered fixed width, to align ratings widget. 377 // Label is considered fixed width, to align ratings widget.
378 DCHECK_LE(size.width(), WebIntentPicker::kTitleLinkMaxWidth);
379 x += WebIntentPicker::kTitleLinkMaxWidth + 378 x += WebIntentPicker::kTitleLinkMaxWidth +
380 views::kRelatedControlHorizontalSpacing; 379 views::kRelatedControlHorizontalSpacing;
381 } else { 380 } else {
382 x += size.width() + views::kRelatedControlHorizontalSpacing; 381 x += size.width() + views::kRelatedControlHorizontalSpacing;
383 } 382 }
384 // Clamp child view bounds to |child_area|. 383 // Clamp child view bounds to |child_area|.
385 child->SetBoundsRect(child_bounds.Intersect(child_area)); 384 child->SetBoundsRect(child_bounds.Intersect(child_area));
386 } 385 }
387 } 386 }
388 387
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 // LinkListener implementation. 786 // LinkListener implementation.
788 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 787 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
789 788
790 // WebIntentPicker implementation. 789 // WebIntentPicker implementation.
791 virtual void Close() OVERRIDE; 790 virtual void Close() OVERRIDE;
792 virtual void SetActionString(const string16& action) OVERRIDE; 791 virtual void SetActionString(const string16& action) OVERRIDE;
793 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; 792 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
794 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE; 793 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE;
795 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE; 794 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE;
796 virtual void OnPendingAsyncCompleted() OVERRIDE; 795 virtual void OnPendingAsyncCompleted() OVERRIDE;
796 virtual void InvalidateDelegate() OVERRIDE;
797 virtual void OnInlineDispositionWebContentsLoaded( 797 virtual void OnInlineDispositionWebContentsLoaded(
798 content::WebContents* web_contents) OVERRIDE; 798 content::WebContents* web_contents) OVERRIDE;
799 799
800 // WebIntentPickerModelObserver implementation. 800 // WebIntentPickerModelObserver implementation.
801 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE; 801 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE;
802 virtual void OnFaviconChanged(WebIntentPickerModel* model, 802 virtual void OnFaviconChanged(WebIntentPickerModel* model,
803 size_t index) OVERRIDE; 803 size_t index) OVERRIDE;
804 virtual void OnExtensionIconChanged(WebIntentPickerModel* model, 804 virtual void OnExtensionIconChanged(WebIntentPickerModel* model,
805 const std::string& extension_id) OVERRIDE; 805 const std::string& extension_id) OVERRIDE;
806 virtual void OnInlineDisposition(const string16& title, 806 virtual void OnInlineDisposition(const string16& title,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 else 950 else
951 UpdateContents(); 951 UpdateContents();
952 } 952 }
953 953
954 WebIntentPickerViews::~WebIntentPickerViews() { 954 WebIntentPickerViews::~WebIntentPickerViews() {
955 model_->set_observer(NULL); 955 model_->set_observer(NULL);
956 } 956 }
957 957
958 void WebIntentPickerViews::ButtonPressed(views::Button* sender, 958 void WebIntentPickerViews::ButtonPressed(views::Button* sender,
959 const ui::Event& event) { 959 const ui::Event& event) {
960 DCHECK(delegate_);
960 delegate_->OnUserCancelledPickerDialog(); 961 delegate_->OnUserCancelledPickerDialog();
961 } 962 }
962 963
963 void WebIntentPickerViews::WindowClosing() { 964 void WebIntentPickerViews::WindowClosing() {
964 delegate_->OnClosing(); 965 if (delegate_)
966 delegate_->OnClosing();
965 } 967 }
966 968
967 void WebIntentPickerViews::DeleteDelegate() { 969 void WebIntentPickerViews::DeleteDelegate() {
968 delete this; 970 delete this;
969 } 971 }
970 972
971 views::Widget* WebIntentPickerViews::GetWidget() { 973 views::Widget* WebIntentPickerViews::GetWidget() {
972 return contents_->GetWidget(); 974 return contents_->GetWidget();
973 } 975 }
974 976
975 const views::Widget* WebIntentPickerViews::GetWidget() const { 977 const views::Widget* WebIntentPickerViews::GetWidget() const {
976 return contents_->GetWidget(); 978 return contents_->GetWidget();
977 } 979 }
978 980
979 views::View* WebIntentPickerViews::GetContentsView() { 981 views::View* WebIntentPickerViews::GetContentsView() {
980 return contents_; 982 return contents_;
981 } 983 }
982 984
983 int WebIntentPickerViews::GetDialogButtons() const { 985 int WebIntentPickerViews::GetDialogButtons() const {
984 return ui::DIALOG_BUTTON_NONE; 986 return ui::DIALOG_BUTTON_NONE;
985 } 987 }
986 988
987 bool WebIntentPickerViews::Cancel() { 989 bool WebIntentPickerViews::Cancel() {
988 return can_close_; 990 return can_close_;
989 } 991 }
990 992
991 void WebIntentPickerViews::LinkClicked(views::Link* source, int event_flags) { 993 void WebIntentPickerViews::LinkClicked(views::Link* source, int event_flags) {
994 DCHECK(delegate_);
992 if (source == more_suggestions_link_) { 995 if (source == more_suggestions_link_) {
993 delegate_->OnSuggestionsLinkClicked( 996 delegate_->OnSuggestionsLinkClicked(
994 chrome::DispositionFromEventFlags(event_flags)); 997 chrome::DispositionFromEventFlags(event_flags));
995 } else if (source == choose_another_service_link_) { 998 } else if (source == choose_another_service_link_) {
996 // Signal cancellation of inline disposition. 999 // Signal cancellation of inline disposition.
997 delegate_->OnChooseAnotherService(); 1000 delegate_->OnChooseAnotherService();
998 ResetContents(); 1001 ResetContents();
999 } else { 1002 } else {
1000 NOTREACHED(); 1003 NOTREACHED();
1001 } 1004 }
(...skipping 30 matching lines...) Expand all
1032 const gfx::Size& size) { 1035 const gfx::Size& size) {
1033 webview_->SetPreferredSize(size); 1036 webview_->SetPreferredSize(size);
1034 contents_->Layout(); 1037 contents_->Layout();
1035 SizeToContents(); 1038 SizeToContents();
1036 } 1039 }
1037 1040
1038 void WebIntentPickerViews::OnPendingAsyncCompleted() { 1041 void WebIntentPickerViews::OnPendingAsyncCompleted() {
1039 UpdateContents(); 1042 UpdateContents();
1040 } 1043 }
1041 1044
1045 void WebIntentPickerViews::InvalidateDelegate() {
1046 delegate_ = NULL;
1047 }
1048
1042 void WebIntentPickerViews::ShowNoServicesMessage() { 1049 void WebIntentPickerViews::ShowNoServicesMessage() {
1043 ClearContents(); 1050 ClearContents();
1044 1051
1045 views::GridLayout* grid_layout = new views::GridLayout(contents_); 1052 views::GridLayout* grid_layout = new views::GridLayout(contents_);
1046 contents_->SetLayoutManager(grid_layout); 1053 contents_->SetLayoutManager(grid_layout);
1047 1054
1048 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder, 1055 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder,
1049 kContentAreaBorder, kContentAreaBorder); 1056 kContentAreaBorder, kContentAreaBorder);
1050 views::ColumnSet* main_cs = grid_layout->AddColumnSet(0); 1057 views::ColumnSet* main_cs = grid_layout->AddColumnSet(0);
1051 main_cs->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, 1058 main_cs->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 const std::string& extension_id) { 1177 const std::string& extension_id) {
1171 if (extensions_) 1178 if (extensions_)
1172 extensions_->Update(); 1179 extensions_->Update();
1173 1180
1174 contents_->Layout(); 1181 contents_->Layout();
1175 SizeToContents(); 1182 SizeToContents();
1176 } 1183 }
1177 1184
1178 void WebIntentPickerViews::OnInlineDisposition( 1185 void WebIntentPickerViews::OnInlineDisposition(
1179 const string16&, const GURL& url) { 1186 const string16&, const GURL& url) {
1187 DCHECK(delegate_);
1180 if (!webview_) 1188 if (!webview_)
1181 webview_ = new views::WebView(tab_contents_->profile()); 1189 webview_ = new views::WebView(tab_contents_->profile());
1182 1190
1183 inline_web_contents_.reset(delegate_->CreateWebContentsForInlineDisposition( 1191 inline_web_contents_.reset(delegate_->CreateWebContentsForInlineDisposition(
1184 tab_contents_->profile(), url)); 1192 tab_contents_->profile(), url));
1193
1185 // Does not take ownership, so we keep a scoped_ptr 1194 // Does not take ownership, so we keep a scoped_ptr
1186 // for the WebContents locally. 1195 // for the WebContents locally.
1187 webview_->SetWebContents(inline_web_contents_.get()); 1196 webview_->SetWebContents(inline_web_contents_.get());
1188 Browser* browser = browser::FindBrowserWithWebContents( 1197 Browser* browser = browser::FindBrowserWithWebContents(
1189 tab_contents_->web_contents()); 1198 tab_contents_->web_contents());
1190 inline_disposition_delegate_.reset( 1199 inline_disposition_delegate_.reset(
1191 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(), 1200 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(),
1192 browser)); 1201 browser));
1193 1202
1194 inline_web_contents_->GetController().LoadURL( 1203 inline_web_contents_->GetController().LoadURL(
1195 url, 1204 url,
1196 content::Referrer(), 1205 content::Referrer(),
1197 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1206 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
1198 std::string()); 1207 std::string());
1199 1208
1200 // Disable all buttons. 1209 // Disable all buttons.
1201 // TODO(groby): Add throbber for inline dispo - see http://crbug.com/142519. 1210 // TODO(groby): Add throbber for inline dispo - see http://crbug.com/142519.
1202 if (extensions_) 1211 if (extensions_)
1203 extensions_->SetEnabled(false); 1212 extensions_->SetEnabled(false);
1204 if (more_suggestions_link_) 1213 if (more_suggestions_link_)
1205 more_suggestions_link_->SetEnabled(false); 1214 more_suggestions_link_->SetEnabled(false);
1206 contents_->Layout(); 1215 contents_->Layout();
1207 } 1216 }
1208 1217
1209 void WebIntentPickerViews::OnExtensionInstallClicked( 1218 void WebIntentPickerViews::OnExtensionInstallClicked(
1210 const std::string& extension_id) { 1219 const std::string& extension_id) {
1220 DCHECK(delegate_);
1211 can_close_ = false; 1221 can_close_ = false;
1212 extensions_->StartThrobber(extension_id); 1222 extensions_->StartThrobber(extension_id);
1213 more_suggestions_link_->SetEnabled(false); 1223 more_suggestions_link_->SetEnabled(false);
1214 contents_->Layout(); 1224 contents_->Layout();
1215 delegate_->OnExtensionInstallRequested(extension_id); 1225 delegate_->OnExtensionInstallRequested(extension_id);
1216 } 1226 }
1217 1227
1218 void WebIntentPickerViews::OnExtensionLinkClicked( 1228 void WebIntentPickerViews::OnExtensionLinkClicked(
1219 const std::string& extension_id, 1229 const std::string& extension_id,
1220 WindowOpenDisposition disposition) { 1230 WindowOpenDisposition disposition) {
1231 DCHECK(delegate_);
1221 delegate_->OnExtensionLinkClicked(extension_id, disposition); 1232 delegate_->OnExtensionLinkClicked(extension_id, disposition);
1222 } 1233 }
1223 1234
1224 void WebIntentPickerViews::OnActionButtonClicked( 1235 void WebIntentPickerViews::OnActionButtonClicked(
1225 IntentRowView::ActionType type, size_t tag) { 1236 IntentRowView::ActionType type, size_t tag) {
1237 DCHECK(delegate_);
1226 DCHECK_EQ(IntentRowView::ACTION_INVOKE, type); 1238 DCHECK_EQ(IntentRowView::ACTION_INVOKE, type);
1227 const WebIntentPickerModel::InstalledService& service = 1239 const WebIntentPickerModel::InstalledService& service =
1228 model_->GetInstalledServiceAt(tag); 1240 model_->GetInstalledServiceAt(tag);
1229 delegate_->OnServiceChosen(service.url, service.disposition, 1241 delegate_->OnServiceChosen(service.url, service.disposition,
1230 WebIntentPickerDelegate::kEnableDefaults); 1242 WebIntentPickerDelegate::kEnableDefaults);
1231 } 1243 }
1232 1244
1233 void WebIntentPickerViews::UpdateContents() { 1245 void WebIntentPickerViews::UpdateContents() {
1234 if (model_ && model_->IsInlineDisposition()) 1246 if (model_ && model_->IsInlineDisposition())
1235 return; 1247 return;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 // we do not set our weak pointers to NULL, then they will continue to point 1389 // we do not set our weak pointers to NULL, then they will continue to point
1378 // to where the deleted objects used to be, i.e. unitialized memory. This 1390 // to where the deleted objects used to be, i.e. unitialized memory. This
1379 // would cause hard-to-explain crashes. 1391 // would cause hard-to-explain crashes.
1380 contents_->RemoveAllChildViews(true); 1392 contents_->RemoveAllChildViews(true);
1381 action_label_ = NULL; 1393 action_label_ = NULL;
1382 suggestions_label_ = NULL; 1394 suggestions_label_ = NULL;
1383 extensions_ = NULL; 1395 extensions_ = NULL;
1384 more_suggestions_link_ = NULL; 1396 more_suggestions_link_ = NULL;
1385 choose_another_service_link_ = NULL; 1397 choose_another_service_link_ = NULL;
1386 } 1398 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698