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

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

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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/browser.h ('k') | chrome/browser/ui/chrome_select_file_policy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 return false; 878 return false;
879 } 879 }
880 880
881 // static 881 // static
882 void Browser::JSOutOfMemoryHelper(WebContents* web_contents) { 882 void Browser::JSOutOfMemoryHelper(WebContents* web_contents) {
883 InfoBarService* infobar_service = 883 InfoBarService* infobar_service =
884 InfoBarService::FromWebContents(web_contents); 884 InfoBarService::FromWebContents(web_contents);
885 if (!infobar_service) 885 if (!infobar_service)
886 return; 886 return;
887 887
888 infobar_service->AddInfoBar(new SimpleAlertInfoBarDelegate( 888 SimpleAlertInfoBarDelegate::Create(
889 infobar_service, 889 infobar_service, NULL,
890 NULL, 890 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true);
891 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
892 true));
893 } 891 }
894 892
895 // static 893 // static
896 void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents, 894 void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents,
897 const std::string& protocol, 895 const std::string& protocol,
898 const GURL& url, 896 const GURL& url,
899 const string16& title, 897 const string16& title,
900 bool user_gesture, 898 bool user_gesture,
901 BrowserWindow* window) { 899 BrowserWindow* window) {
902 Profile* profile = 900 Profile* profile =
(...skipping 19 matching lines...) Expand all
922 return; 920 return;
923 } 921 }
924 922
925 // Make sure content-setting icon is turned off in case the page does 923 // Make sure content-setting icon is turned off in case the page does
926 // ungestured and gestured RPH calls. 924 // ungestured and gestured RPH calls.
927 if (window) { 925 if (window) {
928 tab_content_settings->ClearPendingProtocolHandler(); 926 tab_content_settings->ClearPendingProtocolHandler();
929 window->GetLocationBar()->UpdateContentSettingsIcons(); 927 window->GetLocationBar()->UpdateContentSettingsIcons();
930 } 928 }
931 929
932 content::RecordAction( 930 RegisterProtocolHandlerInfoBarDelegate::Create(
933 UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); 931 InfoBarService::FromWebContents(web_contents), registry, handler);
934 InfoBarService* infobar_service =
935 InfoBarService::FromWebContents(web_contents);
936
937 RegisterProtocolHandlerInfoBarDelegate* rph_delegate =
938 new RegisterProtocolHandlerInfoBarDelegate(infobar_service,
939 registry,
940 handler);
941
942 for (size_t i = 0; i < infobar_service->GetInfoBarCount(); i++) {
943 InfoBarDelegate* delegate = infobar_service->GetInfoBarDelegateAt(i);
944 RegisterProtocolHandlerInfoBarDelegate* cast_delegate =
945 delegate->AsRegisterProtocolHandlerInfoBarDelegate();
946 if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) {
947 infobar_service->ReplaceInfoBar(cast_delegate, rph_delegate);
948 rph_delegate = NULL;
949 break;
950 }
951 }
952
953 if (rph_delegate != NULL)
954 infobar_service->AddInfoBar(rph_delegate);
955 } 932 }
956 933
957 // static 934 // static
958 void Browser::FindReplyHelper(WebContents* web_contents, 935 void Browser::FindReplyHelper(WebContents* web_contents,
959 int request_id, 936 int request_id,
960 int number_of_matches, 937 int number_of_matches,
961 const gfx::Rect& selection_rect, 938 const gfx::Rect& selection_rect,
962 int active_match_ordinal, 939 int active_match_ordinal,
963 bool final_update) { 940 bool final_update) {
964 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents); 941 FindTabHelper* find_tab_helper = FindTabHelper::FromWebContents(web_contents);
965 if (!find_tab_helper) 942 if (!find_tab_helper)
966 return; 943 return;
967 944
968 find_tab_helper->HandleFindReply(request_id, 945 find_tab_helper->HandleFindReply(request_id,
969 number_of_matches, 946 number_of_matches,
970 selection_rect, 947 selection_rect,
971 active_match_ordinal, 948 active_match_ordinal,
972 final_update); 949 final_update);
973 } 950 }
974 951
975 // static
976 void Browser::RequestMediaAccessPermissionHelper(
977 content::WebContents* web_contents,
978 const content::MediaStreamRequest& request,
979 const content::MediaResponseCallback& callback) {
980 Profile* profile =
981 Profile::FromBrowserContext(web_contents->GetBrowserContext());
982
983 scoped_ptr<MediaStreamDevicesController>
984 controller(new MediaStreamDevicesController(profile,
985 request,
986 callback));
987 if (!controller->DismissInfoBarAndTakeActionOnSettings()) {
988 InfoBarService* infobar_service =
989 InfoBarService::FromWebContents(web_contents);
990 InfoBarDelegate* old_infobar = NULL;
991 for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) {
992 old_infobar = infobar_service->GetInfoBarDelegateAt(i)->
993 AsMediaStreamInfoBarDelegate();
994 if (old_infobar)
995 break;
996 }
997
998 InfoBarDelegate* infobar =
999 new MediaStreamInfoBarDelegate(infobar_service, controller.release());
1000 if (old_infobar)
1001 infobar_service->ReplaceInfoBar(old_infobar, infobar);
1002 else
1003 infobar_service->AddInfoBar(infobar);
1004 }
1005 }
1006
1007 void Browser::UpdateUIForNavigationInTab(WebContents* contents, 952 void Browser::UpdateUIForNavigationInTab(WebContents* contents,
1008 content::PageTransition transition, 953 content::PageTransition transition,
1009 bool user_initiated) { 954 bool user_initiated) {
1010 tab_strip_model_->TabNavigating(contents, transition); 955 tab_strip_model_->TabNavigating(contents, transition);
1011 956
1012 bool contents_is_selected = 957 bool contents_is_selected =
1013 contents == tab_strip_model_->GetActiveWebContents(); 958 contents == tab_strip_model_->GetActiveWebContents();
1014 if (user_initiated && contents_is_selected && window()->GetLocationBar()) { 959 if (user_initiated && contents_is_selected && window()->GetLocationBar()) {
1015 // Forcibly reset the location bar if the url is going to change in the 960 // Forcibly reset the location bar if the url is going to change in the
1016 // current tab, since otherwise it won't discard any ongoing user edits, 961 // current tab, since otherwise it won't discard any ongoing user edits,
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 return; 1544 return;
1600 1545
1601 chrome::ShowHungRendererDialog(source); 1546 chrome::ShowHungRendererDialog(source);
1602 } 1547 }
1603 1548
1604 void Browser::RendererResponsive(WebContents* source) { 1549 void Browser::RendererResponsive(WebContents* source) {
1605 chrome::HideHungRendererDialog(source); 1550 chrome::HideHungRendererDialog(source);
1606 } 1551 }
1607 1552
1608 void Browser::WorkerCrashed(WebContents* source) { 1553 void Browser::WorkerCrashed(WebContents* source) {
1609 InfoBarService* infobar_service = 1554 SimpleAlertInfoBarDelegate::Create(
1610 InfoBarService::FromWebContents(source); 1555 InfoBarService::FromWebContents(source), NULL,
1611 infobar_service->AddInfoBar(new SimpleAlertInfoBarDelegate( 1556 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true);
1612 infobar_service,
1613 NULL,
1614 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
1615 true));
1616 } 1557 }
1617 1558
1618 void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) { 1559 void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) {
1619 if (web_contents == tab_strip_model_->GetActiveWebContents()) 1560 if (web_contents == tab_strip_model_->GetActiveWebContents())
1620 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 1561 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
1621 } 1562 }
1622 1563
1623 void Browser::DidNavigateToPendingEntry(WebContents* web_contents) { 1564 void Browser::DidNavigateToPendingEntry(WebContents* web_contents) {
1624 if (web_contents == tab_strip_model_->GetActiveWebContents()) 1565 if (web_contents == tab_strip_model_->GetActiveWebContents())
1625 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 1566 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 const string16& title, 1626 const string16& title,
1686 bool user_gesture) { 1627 bool user_gesture) {
1687 RegisterProtocolHandlerHelper( 1628 RegisterProtocolHandlerHelper(
1688 web_contents, protocol, url, title, user_gesture, window()); 1629 web_contents, protocol, url, title, user_gesture, window());
1689 } 1630 }
1690 1631
1691 void Browser::RegisterIntentHandler( 1632 void Browser::RegisterIntentHandler(
1692 WebContents* web_contents, 1633 WebContents* web_contents,
1693 const webkit_glue::WebIntentServiceData& data, 1634 const webkit_glue::WebIntentServiceData& data,
1694 bool user_gesture) { 1635 bool user_gesture) {
1695 RegisterIntentHandlerHelper(web_contents, data, user_gesture); 1636 RegisterIntentHandlerInfoBarDelegate::Create(web_contents, data);
1696 } 1637 }
1697 1638
1698 void Browser::WebIntentDispatch( 1639 void Browser::WebIntentDispatch(
1699 WebContents* web_contents, 1640 WebContents* web_contents,
1700 content::WebIntentsDispatcher* intents_dispatcher) { 1641 content::WebIntentsDispatcher* intents_dispatcher) {
1701 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) { 1642 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) {
1702 web_intents::RecordIntentsDispatchDisabled(); 1643 web_intents::RecordIntentsDispatchDisabled();
1703 delete intents_dispatcher; 1644 delete intents_dispatcher;
1704 return; 1645 return;
1705 } 1646 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 } 1722 }
1782 1723
1783 void Browser::LostMouseLock() { 1724 void Browser::LostMouseLock() {
1784 fullscreen_controller_->LostMouseLock(); 1725 fullscreen_controller_->LostMouseLock();
1785 } 1726 }
1786 1727
1787 void Browser::RequestMediaAccessPermission( 1728 void Browser::RequestMediaAccessPermission(
1788 content::WebContents* web_contents, 1729 content::WebContents* web_contents,
1789 const content::MediaStreamRequest& request, 1730 const content::MediaStreamRequest& request,
1790 const content::MediaResponseCallback& callback) { 1731 const content::MediaResponseCallback& callback) {
1791 RequestMediaAccessPermissionHelper(web_contents, request, callback); 1732 MediaStreamInfoBarDelegate::Create(web_contents, request, callback);
1792 } 1733 }
1793 1734
1794 bool Browser::RequestPpapiBrokerPermission( 1735 bool Browser::RequestPpapiBrokerPermission(
1795 WebContents* web_contents, 1736 WebContents* web_contents,
1796 const GURL& url, 1737 const GURL& url,
1797 const FilePath& plugin_path, 1738 const FilePath& plugin_path,
1798 const base::Callback<void(bool)>& callback) { 1739 const base::Callback<void(bool)>& callback) {
1799 PepperBrokerInfoBarDelegate::Show(web_contents, url, plugin_path, callback); 1740 PepperBrokerInfoBarDelegate::Create(web_contents, url, plugin_path, callback);
1800 return true; 1741 return true;
1801 } 1742 }
1802 1743
1803 /////////////////////////////////////////////////////////////////////////////// 1744 ///////////////////////////////////////////////////////////////////////////////
1804 // Browser, CoreTabHelperDelegate implementation: 1745 // Browser, CoreTabHelperDelegate implementation:
1805 1746
1806 void Browser::SwapTabContents(content::WebContents* old_contents, 1747 void Browser::SwapTabContents(content::WebContents* old_contents,
1807 content::WebContents* new_contents) { 1748 content::WebContents* new_contents) {
1808 int index = tab_strip_model_->GetIndexOfWebContents(old_contents); 1749 int index = tab_strip_model_->GetIndexOfWebContents(old_contents);
1809 DCHECK_NE(TabStripModel::kNoTab, index); 1750 DCHECK_NE(TabStripModel::kNoTab, index);
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 if (contents && !allow_js_access) { 2379 if (contents && !allow_js_access) {
2439 contents->web_contents()->GetController().LoadURL( 2380 contents->web_contents()->GetController().LoadURL(
2440 target_url, 2381 target_url,
2441 content::Referrer(), 2382 content::Referrer(),
2442 content::PAGE_TRANSITION_LINK, 2383 content::PAGE_TRANSITION_LINK,
2443 std::string()); // No extra headers. 2384 std::string()); // No extra headers.
2444 } 2385 }
2445 2386
2446 return contents != NULL; 2387 return contents != NULL;
2447 } 2388 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/chrome_select_file_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698