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

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: 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
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_controller_browsertest.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/timer.h" 10 #include "base/timer.h"
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 // LinkListener implementation. 922 // LinkListener implementation.
923 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 923 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
924 924
925 // WebIntentPicker implementation. 925 // WebIntentPicker implementation.
926 virtual void Close() OVERRIDE; 926 virtual void Close() OVERRIDE;
927 virtual void SetActionString(const string16& action) OVERRIDE; 927 virtual void SetActionString(const string16& action) OVERRIDE;
928 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; 928 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
929 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE; 929 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE;
930 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE; 930 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE;
931 virtual void OnPendingAsyncCompleted() OVERRIDE; 931 virtual void OnPendingAsyncCompleted() OVERRIDE;
932 virtual void InvalidateDelegate() OVERRIDE;
932 virtual void OnInlineDispositionWebContentsLoaded( 933 virtual void OnInlineDispositionWebContentsLoaded(
933 content::WebContents* web_contents) OVERRIDE; 934 content::WebContents* web_contents) OVERRIDE;
934 935
935 // WebIntentPickerModelObserver implementation. 936 // WebIntentPickerModelObserver implementation.
936 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE; 937 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE;
937 virtual void OnFaviconChanged(WebIntentPickerModel* model, 938 virtual void OnFaviconChanged(WebIntentPickerModel* model,
938 size_t index) OVERRIDE; 939 size_t index) OVERRIDE;
939 virtual void OnExtensionIconChanged(WebIntentPickerModel* model, 940 virtual void OnExtensionIconChanged(WebIntentPickerModel* model,
940 const std::string& extension_id) OVERRIDE; 941 const std::string& extension_id) OVERRIDE;
941 virtual void OnInlineDisposition(const string16& title, 942 virtual void OnInlineDisposition(const string16& title,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 else 1102 else
1102 UpdateContents(); 1103 UpdateContents();
1103 } 1104 }
1104 1105
1105 WebIntentPickerViews::~WebIntentPickerViews() { 1106 WebIntentPickerViews::~WebIntentPickerViews() {
1106 model_->set_observer(NULL); 1107 model_->set_observer(NULL);
1107 } 1108 }
1108 1109
1109 void WebIntentPickerViews::ButtonPressed(views::Button* sender, 1110 void WebIntentPickerViews::ButtonPressed(views::Button* sender,
1110 const ui::Event& event) { 1111 const ui::Event& event) {
1112 DCHECK(delegate_);
1111 delegate_->OnUserCancelledPickerDialog(); 1113 delegate_->OnUserCancelledPickerDialog();
1112 } 1114 }
1113 1115
1114 void WebIntentPickerViews::WindowClosing() { 1116 void WebIntentPickerViews::WindowClosing() {
1115 delegate_->OnClosing(); 1117 if (delegate_)
1118 delegate_->OnClosing();
1116 } 1119 }
1117 1120
1118 void WebIntentPickerViews::DeleteDelegate() { 1121 void WebIntentPickerViews::DeleteDelegate() {
1119 delete this; 1122 delete this;
1120 } 1123 }
1121 1124
1122 views::Widget* WebIntentPickerViews::GetWidget() { 1125 views::Widget* WebIntentPickerViews::GetWidget() {
1123 return contents_->GetWidget(); 1126 return contents_->GetWidget();
1124 } 1127 }
1125 1128
1126 const views::Widget* WebIntentPickerViews::GetWidget() const { 1129 const views::Widget* WebIntentPickerViews::GetWidget() const {
1127 return contents_->GetWidget(); 1130 return contents_->GetWidget();
1128 } 1131 }
1129 1132
1130 views::View* WebIntentPickerViews::GetContentsView() { 1133 views::View* WebIntentPickerViews::GetContentsView() {
1131 return contents_; 1134 return contents_;
1132 } 1135 }
1133 1136
1134 void WebIntentPickerViews::LinkClicked(views::Link* source, int event_flags) { 1137 void WebIntentPickerViews::LinkClicked(views::Link* source, int event_flags) {
1138 DCHECK(delegate_);
1135 if (source == more_suggestions_link_) { 1139 if (source == more_suggestions_link_) {
1136 delegate_->OnSuggestionsLinkClicked( 1140 delegate_->OnSuggestionsLinkClicked(
1137 chrome::DispositionFromEventFlags(event_flags)); 1141 chrome::DispositionFromEventFlags(event_flags));
1138 } else if (source == choose_another_service_link_) { 1142 } else if (source == choose_another_service_link_) {
1139 // Signal cancellation of inline disposition. 1143 // Signal cancellation of inline disposition.
1140 delegate_->OnChooseAnotherService(); 1144 delegate_->OnChooseAnotherService();
1141 ResetContents(); 1145 ResetContents();
1142 } else { 1146 } else {
1143 NOTREACHED(); 1147 NOTREACHED();
1144 } 1148 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 const gfx::Size& size) { 1180 const gfx::Size& size) {
1177 webview_->SetPreferredSize(size); 1181 webview_->SetPreferredSize(size);
1178 contents_->Layout(); 1182 contents_->Layout();
1179 SizeToContents(); 1183 SizeToContents();
1180 } 1184 }
1181 1185
1182 void WebIntentPickerViews::OnPendingAsyncCompleted() { 1186 void WebIntentPickerViews::OnPendingAsyncCompleted() {
1183 UpdateContents(); 1187 UpdateContents();
1184 } 1188 }
1185 1189
1190 void WebIntentPickerViews::InvalidateDelegate() {
1191 delegate_ = NULL;
1192 }
1193
1186 void WebIntentPickerViews::ShowNoServicesMessage() { 1194 void WebIntentPickerViews::ShowNoServicesMessage() {
1187 if (state_ == NO_SERVICES) 1195 if (state_ == NO_SERVICES)
1188 return; 1196 return;
1189 state_ = NO_SERVICES; 1197 state_ = NO_SERVICES;
1190 1198
1191 ClearContents(); 1199 ClearContents();
1192 views::GridLayout* layout = new views::GridLayout(contents_); 1200 views::GridLayout* layout = new views::GridLayout(contents_);
1193 layout->set_minimum_size(gfx::Size(WebIntentPicker::kWindowMinWidth, 0)); 1201 layout->set_minimum_size(gfx::Size(WebIntentPicker::kWindowMinWidth, 0));
1194 const int kContentBuiltinBottomPadding = 3; 1202 const int kContentBuiltinBottomPadding = 3;
1195 layout->SetInsets(ConstrainedWindowConstants::kCloseButtonPadding, 1203 layout->SetInsets(ConstrainedWindowConstants::kCloseButtonPadding,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 } 1368 }
1361 1369
1362 void WebIntentPickerViews::OnExtensionIconChanged( 1370 void WebIntentPickerViews::OnExtensionIconChanged(
1363 WebIntentPickerModel* model, 1371 WebIntentPickerModel* model,
1364 const std::string& extension_id) { 1372 const std::string& extension_id) {
1365 OnFaviconChanged(model, -1); 1373 OnFaviconChanged(model, -1);
1366 } 1374 }
1367 1375
1368 void WebIntentPickerViews::OnInlineDisposition( 1376 void WebIntentPickerViews::OnInlineDisposition(
1369 const string16&, const GURL& url) { 1377 const string16&, const GURL& url) {
1378 DCHECK(delegate_);
1370 if (!webview_) 1379 if (!webview_)
1371 webview_ = new views::WebView(tab_contents_->profile()); 1380 webview_ = new views::WebView(tab_contents_->profile());
1372 1381
1373 inline_web_contents_.reset(delegate_->CreateWebContentsForInlineDisposition( 1382 inline_web_contents_.reset(delegate_->CreateWebContentsForInlineDisposition(
1374 tab_contents_->profile(), url)); 1383 tab_contents_->profile(), url));
1384
1375 // Does not take ownership, so we keep a scoped_ptr 1385 // Does not take ownership, so we keep a scoped_ptr
1376 // for the WebContents locally. 1386 // for the WebContents locally.
1377 webview_->SetWebContents(inline_web_contents_.get()); 1387 webview_->SetWebContents(inline_web_contents_.get());
1378 Browser* browser = browser::FindBrowserWithWebContents( 1388 Browser* browser = browser::FindBrowserWithWebContents(
1379 tab_contents_->web_contents()); 1389 tab_contents_->web_contents());
1380 inline_disposition_delegate_.reset( 1390 inline_disposition_delegate_.reset(
1381 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(), 1391 new WebIntentInlineDispositionDelegate(this, inline_web_contents_.get(),
1382 browser)); 1392 browser));
1383 1393
1384 inline_web_contents_->GetController().LoadURL( 1394 inline_web_contents_->GetController().LoadURL(
1385 url, 1395 url,
1386 content::Referrer(), 1396 content::Referrer(),
1387 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1397 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
1388 std::string()); 1398 std::string());
1389 1399
1390 // Disable all buttons. 1400 // Disable all buttons.
1391 // TODO(groby): Add throbber for inline dispo - see http://crbug.com/142519. 1401 // TODO(groby): Add throbber for inline dispo - see http://crbug.com/142519.
1392 if (extensions_) 1402 if (extensions_)
1393 extensions_->SetEnabled(false); 1403 extensions_->SetEnabled(false);
1394 if (more_suggestions_link_) 1404 if (more_suggestions_link_)
1395 more_suggestions_link_->SetEnabled(false); 1405 more_suggestions_link_->SetEnabled(false);
1396 contents_->Layout(); 1406 contents_->Layout();
1397 } 1407 }
1398 1408
1399 void WebIntentPickerViews::OnExtensionInstallClicked( 1409 void WebIntentPickerViews::OnExtensionInstallClicked(
1400 const std::string& extension_id) { 1410 const std::string& extension_id) {
1411 DCHECK(delegate_);
1401 can_close_ = false; 1412 can_close_ = false;
1402 extensions_->StartThrobber(extension_id); 1413 extensions_->StartThrobber(extension_id);
1403 more_suggestions_link_->SetEnabled(false); 1414 more_suggestions_link_->SetEnabled(false);
1404 contents_->Layout(); 1415 contents_->Layout();
1405 delegate_->OnExtensionInstallRequested(extension_id); 1416 delegate_->OnExtensionInstallRequested(extension_id);
1406 } 1417 }
1407 1418
1408 void WebIntentPickerViews::OnExtensionLinkClicked( 1419 void WebIntentPickerViews::OnExtensionLinkClicked(
1409 const std::string& extension_id, 1420 const std::string& extension_id,
1410 WindowOpenDisposition disposition) { 1421 WindowOpenDisposition disposition) {
1422 DCHECK(delegate_);
1411 delegate_->OnExtensionLinkClicked(extension_id, disposition); 1423 delegate_->OnExtensionLinkClicked(extension_id, disposition);
1412 } 1424 }
1413 1425
1414 void WebIntentPickerViews::OnActionButtonClicked( 1426 void WebIntentPickerViews::OnActionButtonClicked(
1415 IntentRowView::ActionType type, size_t tag) { 1427 IntentRowView::ActionType type, size_t tag) {
1428 DCHECK(delegate_);
1416 DCHECK_EQ(IntentRowView::ACTION_INVOKE, type); 1429 DCHECK_EQ(IntentRowView::ACTION_INVOKE, type);
1417 const WebIntentPickerModel::InstalledService& service = 1430 const WebIntentPickerModel::InstalledService& service =
1418 model_->GetInstalledServiceAt(tag); 1431 model_->GetInstalledServiceAt(tag);
1419 delegate_->OnServiceChosen(service.url, service.disposition, 1432 delegate_->OnServiceChosen(service.url, service.disposition,
1420 WebIntentPickerDelegate::kEnableDefaults); 1433 WebIntentPickerDelegate::kEnableDefaults);
1421 } 1434 }
1422 1435
1423 void WebIntentPickerViews::UpdateContents() { 1436 void WebIntentPickerViews::UpdateContents() {
1424 if (model_ && model_->IsInlineDisposition()) 1437 if (model_ && model_->IsInlineDisposition())
1425 return; 1438 return;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 if (inline_service) 1597 if (inline_service)
1585 inline_service_icon_->SetImage(inline_service->favicon.ToImageSkia()); 1598 inline_service_icon_->SetImage(inline_service->favicon.ToImageSkia());
1586 } 1599 }
1587 1600
1588 void WebIntentPickerViews::RefreshExtensions() { 1601 void WebIntentPickerViews::RefreshExtensions() {
1589 DCHECK(extensions_); 1602 DCHECK(extensions_);
1590 extensions_->Update(); 1603 extensions_->Update();
1591 contents_->Layout(); 1604 contents_->Layout();
1592 SizeToContents(); 1605 SizeToContents();
1593 } 1606 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/intents/web_intent_picker_controller_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698