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

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: 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
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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); 378 // DCHECK_LE(size.width(), WebIntentPicker::kTitleLinkMaxWidth);
Greg Billock 2012/10/15 22:29:33 erase this line?
groby-ooo-7-16 2012/10/16 01:13:10 Done.
379 x += WebIntentPicker::kTitleLinkMaxWidth + 379 x += WebIntentPicker::kTitleLinkMaxWidth +
380 views::kRelatedControlHorizontalSpacing; 380 views::kRelatedControlHorizontalSpacing;
381 } else { 381 } else {
382 x += size.width() + views::kRelatedControlHorizontalSpacing; 382 x += size.width() + views::kRelatedControlHorizontalSpacing;
383 } 383 }
384 // Clamp child view bounds to |child_area|. 384 // Clamp child view bounds to |child_area|.
385 child->SetBoundsRect(child_bounds.Intersect(child_area)); 385 child->SetBoundsRect(child_bounds.Intersect(child_area));
386 } 386 }
387 } 387 }
388 388
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 // LinkListener implementation. 787 // LinkListener implementation.
788 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 788 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
789 789
790 // WebIntentPicker implementation. 790 // WebIntentPicker implementation.
791 virtual void Close() OVERRIDE; 791 virtual void Close() OVERRIDE;
792 virtual void SetActionString(const string16& action) OVERRIDE; 792 virtual void SetActionString(const string16& action) OVERRIDE;
793 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; 793 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
794 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE; 794 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE;
795 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE; 795 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE;
796 virtual void OnPendingAsyncCompleted() OVERRIDE; 796 virtual void OnPendingAsyncCompleted() OVERRIDE;
797 virtual void InvalidateDelegate() OVERRIDE;
797 virtual void OnInlineDispositionWebContentsLoaded( 798 virtual void OnInlineDispositionWebContentsLoaded(
798 content::WebContents* web_contents) OVERRIDE; 799 content::WebContents* web_contents) OVERRIDE;
799 800
800 // WebIntentPickerModelObserver implementation. 801 // WebIntentPickerModelObserver implementation.
801 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE; 802 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE;
802 virtual void OnFaviconChanged(WebIntentPickerModel* model, 803 virtual void OnFaviconChanged(WebIntentPickerModel* model,
803 size_t index) OVERRIDE; 804 size_t index) OVERRIDE;
804 virtual void OnExtensionIconChanged(WebIntentPickerModel* model, 805 virtual void OnExtensionIconChanged(WebIntentPickerModel* model,
805 const std::string& extension_id) OVERRIDE; 806 const std::string& extension_id) OVERRIDE;
806 virtual void OnInlineDisposition(const string16& title, 807 virtual void OnInlineDisposition(const string16& title,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 948
948 UpdateContents(); 949 UpdateContents();
949 } 950 }
950 951
951 WebIntentPickerViews::~WebIntentPickerViews() { 952 WebIntentPickerViews::~WebIntentPickerViews() {
952 model_->set_observer(NULL); 953 model_->set_observer(NULL);
953 } 954 }
954 955
955 void WebIntentPickerViews::ButtonPressed(views::Button* sender, 956 void WebIntentPickerViews::ButtonPressed(views::Button* sender,
956 const ui::Event& event) { 957 const ui::Event& event) {
958 DCHECK(delegate_);
957 delegate_->OnUserCancelledPickerDialog(); 959 delegate_->OnUserCancelledPickerDialog();
958 } 960 }
959 961
960 void WebIntentPickerViews::WindowClosing() { 962 void WebIntentPickerViews::WindowClosing() {
961 delegate_->OnClosing(); 963 if (delegate_)
964 delegate_->OnClosing();
962 } 965 }
963 966
964 void WebIntentPickerViews::DeleteDelegate() { 967 void WebIntentPickerViews::DeleteDelegate() {
965 delete this; 968 delete this;
966 } 969 }
967 970
968 views::Widget* WebIntentPickerViews::GetWidget() { 971 views::Widget* WebIntentPickerViews::GetWidget() {
969 return contents_->GetWidget(); 972 return contents_->GetWidget();
970 } 973 }
971 974
972 const views::Widget* WebIntentPickerViews::GetWidget() const { 975 const views::Widget* WebIntentPickerViews::GetWidget() const {
973 return contents_->GetWidget(); 976 return contents_->GetWidget();
974 } 977 }
975 978
976 views::View* WebIntentPickerViews::GetContentsView() { 979 views::View* WebIntentPickerViews::GetContentsView() {
977 return contents_; 980 return contents_;
978 } 981 }
979 982
980 int WebIntentPickerViews::GetDialogButtons() const { 983 int WebIntentPickerViews::GetDialogButtons() const {
981 return ui::DIALOG_BUTTON_NONE; 984 return ui::DIALOG_BUTTON_NONE;
982 } 985 }
983 986
984 bool WebIntentPickerViews::Cancel() { 987 bool WebIntentPickerViews::Cancel() {
985 return can_close_; 988 return can_close_;
986 } 989 }
987 990
988 void WebIntentPickerViews::LinkClicked(views::Link* source, int event_flags) { 991 void WebIntentPickerViews::LinkClicked(views::Link* source, int event_flags) {
992 DCHECK(delegate_);
989 if (source == more_suggestions_link_) { 993 if (source == more_suggestions_link_) {
990 delegate_->OnSuggestionsLinkClicked( 994 delegate_->OnSuggestionsLinkClicked(
991 chrome::DispositionFromEventFlags(event_flags)); 995 chrome::DispositionFromEventFlags(event_flags));
992 } else if (source == choose_another_service_link_) { 996 } else if (source == choose_another_service_link_) {
993 // Signal cancellation of inline disposition. 997 // Signal cancellation of inline disposition.
994 delegate_->OnChooseAnotherService(); 998 delegate_->OnChooseAnotherService();
995 ResetContents(); 999 ResetContents();
996 } else { 1000 } else {
997 NOTREACHED(); 1001 NOTREACHED();
998 } 1002 }
(...skipping 30 matching lines...) Expand all
1029 const gfx::Size& size) { 1033 const gfx::Size& size) {
1030 webview_->SetPreferredSize(size); 1034 webview_->SetPreferredSize(size);
1031 contents_->Layout(); 1035 contents_->Layout();
1032 SizeToContents(); 1036 SizeToContents();
1033 } 1037 }
1034 1038
1035 void WebIntentPickerViews::OnPendingAsyncCompleted() { 1039 void WebIntentPickerViews::OnPendingAsyncCompleted() {
1036 UpdateContents(); 1040 UpdateContents();
1037 } 1041 }
1038 1042
1043 void WebIntentPickerViews::InvalidateDelegate() {
1044 delegate_ = NULL;
1045 }
1046
1039 void WebIntentPickerViews::ShowNoServicesMessage() { 1047 void WebIntentPickerViews::ShowNoServicesMessage() {
1040 ClearContents(); 1048 ClearContents();
1041 1049
1042 views::GridLayout* grid_layout = new views::GridLayout(contents_); 1050 views::GridLayout* grid_layout = new views::GridLayout(contents_);
1043 contents_->SetLayoutManager(grid_layout); 1051 contents_->SetLayoutManager(grid_layout);
1044 1052
1045 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder, 1053 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder,
1046 kContentAreaBorder, kContentAreaBorder); 1054 kContentAreaBorder, kContentAreaBorder);
1047 views::ColumnSet* main_cs = grid_layout->AddColumnSet(0); 1055 views::ColumnSet* main_cs = grid_layout->AddColumnSet(0);
1048 main_cs->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1, 1056 main_cs->AddColumn(GridLayout::FILL, GridLayout::LEADING, 1,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 const std::string& extension_id) { 1174 const std::string& extension_id) {
1167 if (extensions_) 1175 if (extensions_)
1168 extensions_->Update(); 1176 extensions_->Update();
1169 1177
1170 contents_->Layout(); 1178 contents_->Layout();
1171 SizeToContents(); 1179 SizeToContents();
1172 } 1180 }
1173 1181
1174 void WebIntentPickerViews::OnInlineDisposition( 1182 void WebIntentPickerViews::OnInlineDisposition(
1175 const string16&, const GURL& url) { 1183 const string16&, const GURL& url) {
1184 DCHECK(delegate_);
1176 if (!webview_) 1185 if (!webview_)
1177 webview_ = new views::WebView(tab_contents_->profile()); 1186 webview_ = new views::WebView(tab_contents_->profile());
1178 1187
1179 inline_web_contents_.reset(delegate_->CreateWebContentsForInlineDisposition( 1188 inline_web_contents_.reset(delegate_->CreateWebContentsForInlineDisposition(
1180 tab_contents_->profile(), url)); 1189 tab_contents_->profile(), url));
1190
1181 // Does not take ownership, so we keep a scoped_ptr 1191 // Does not take ownership, so we keep a scoped_ptr
1182 // for the WebContents locally. 1192 // for the WebContents locally.
1183 webview_->SetWebContents(inline_web_contents_.get()); 1193 webview_->SetWebContents(inline_web_contents_.get());
1184 Browser* browser = browser::FindBrowserWithWebContents( 1194 Browser* browser = browser::FindBrowserWithWebContents(
1185 tab_contents_->web_contents()); 1195 tab_contents_->web_contents());
1186 inline_disposition_delegate_.reset( 1196 inline_disposition_delegate_.reset(
1187 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(), 1197 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(),
1188 browser)); 1198 browser));
1189 1199
1190 inline_web_contents_->GetController().LoadURL( 1200 inline_web_contents_->GetController().LoadURL(
1191 url, 1201 url,
1192 content::Referrer(), 1202 content::Referrer(),
1193 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1203 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
1194 std::string()); 1204 std::string());
1195 1205
1196 // Disable all buttons. 1206 // Disable all buttons.
1197 // TODO(groby): Add throbber for inline dispo - see http://crbug.com/142519. 1207 // TODO(groby): Add throbber for inline dispo - see http://crbug.com/142519.
1198 extensions_->SetEnabled(false); 1208 extensions_->SetEnabled(false);
1199 more_suggestions_link_->SetEnabled(false); 1209 more_suggestions_link_->SetEnabled(false);
1200 contents_->Layout(); 1210 contents_->Layout();
1201 } 1211 }
1202 1212
1203 void WebIntentPickerViews::OnExtensionInstallClicked( 1213 void WebIntentPickerViews::OnExtensionInstallClicked(
1204 const std::string& extension_id) { 1214 const std::string& extension_id) {
1215 DCHECK(delegate_);
1205 can_close_ = false; 1216 can_close_ = false;
1206 extensions_->StartThrobber(extension_id); 1217 extensions_->StartThrobber(extension_id);
1207 more_suggestions_link_->SetEnabled(false); 1218 more_suggestions_link_->SetEnabled(false);
1208 contents_->Layout(); 1219 contents_->Layout();
1209 delegate_->OnExtensionInstallRequested(extension_id); 1220 delegate_->OnExtensionInstallRequested(extension_id);
1210 } 1221 }
1211 1222
1212 void WebIntentPickerViews::OnExtensionLinkClicked( 1223 void WebIntentPickerViews::OnExtensionLinkClicked(
1213 const std::string& extension_id, 1224 const std::string& extension_id,
1214 WindowOpenDisposition disposition) { 1225 WindowOpenDisposition disposition) {
1226 DCHECK(delegate_);
1215 delegate_->OnExtensionLinkClicked(extension_id, disposition); 1227 delegate_->OnExtensionLinkClicked(extension_id, disposition);
1216 } 1228 }
1217 1229
1218 void WebIntentPickerViews::OnActionButtonClicked( 1230 void WebIntentPickerViews::OnActionButtonClicked(
1219 IntentRowView::ActionType type, size_t tag) { 1231 IntentRowView::ActionType type, size_t tag) {
1232 DCHECK(delegate_);
1220 DCHECK_EQ(IntentRowView::ACTION_INVOKE, type); 1233 DCHECK_EQ(IntentRowView::ACTION_INVOKE, type);
1221 const WebIntentPickerModel::InstalledService& service = 1234 const WebIntentPickerModel::InstalledService& service =
1222 model_->GetInstalledServiceAt(tag); 1235 model_->GetInstalledServiceAt(tag);
1223 delegate_->OnServiceChosen(service.url, service.disposition, 1236 delegate_->OnServiceChosen(service.url, service.disposition,
1224 WebIntentPickerDelegate::kEnableDefaults); 1237 WebIntentPickerDelegate::kEnableDefaults);
1225 } 1238 }
1226 1239
1227 void WebIntentPickerViews::UpdateContents() { 1240 void WebIntentPickerViews::UpdateContents() {
1228 if (model_ && model_->IsWaitingForSuggestions()) { 1241 if (model_ && model_->IsWaitingForSuggestions()) {
1229 ClearContents(); 1242 ClearContents();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 // we do not set our weak pointers to NULL, then they will continue to point 1381 // we do not set our weak pointers to NULL, then they will continue to point
1369 // to where the deleted objects used to be, i.e. unitialized memory. This 1382 // to where the deleted objects used to be, i.e. unitialized memory. This
1370 // would cause hard-to-explain crashes. 1383 // would cause hard-to-explain crashes.
1371 contents_->RemoveAllChildViews(true); 1384 contents_->RemoveAllChildViews(true);
1372 action_label_ = NULL; 1385 action_label_ = NULL;
1373 suggestions_label_ = NULL; 1386 suggestions_label_ = NULL;
1374 extensions_ = NULL; 1387 extensions_ = NULL;
1375 more_suggestions_link_ = NULL; 1388 more_suggestions_link_ = NULL;
1376 choose_another_service_link_ = NULL; 1389 choose_another_service_link_ = NULL;
1377 } 1390 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698