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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 254393004: LocationBarView should consistently NULL-check GetWebContents(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | « no previous file | 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 "chrome/browser/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #include "chrome/browser/ui/views/first_run_bubble.h" 101 #include "chrome/browser/ui/views/first_run_bubble.h"
102 #endif 102 #endif
103 103
104 using content::WebContents; 104 using content::WebContents;
105 using views::View; 105 using views::View;
106 106
107 namespace { 107 namespace {
108 108
109 #if !defined(OS_CHROMEOS) 109 #if !defined(OS_CHROMEOS)
110 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { 110 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) {
111 WebContents* contents = delegate->GetWebContents(); 111 WebContents* web_contents = delegate->GetWebContents();
112 return contents ? chrome::FindBrowserWithWebContents(contents) : NULL; 112 return web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL;
113 } 113 }
114 #endif 114 #endif
115 115
116 // Given a containing |height| and a |base_font_list|, shrinks the font size 116 // Given a containing |height| and a |base_font_list|, shrinks the font size
117 // until the font list will fit within |height| while having its cap height 117 // until the font list will fit within |height| while having its cap height
118 // vertically centered. Returns the correctly-sized font list. 118 // vertically centered. Returns the correctly-sized font list.
119 // 119 //
120 // The expected layout: 120 // The expected layout:
121 // +--------+-----------------------------------------------+------------+ 121 // +--------+-----------------------------------------------+------------+
122 // | | y offset | space | 122 // | | y offset | space |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 513 }
514 } 514 }
515 515
516 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 516 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
517 DCHECK(zoom_view_); 517 DCHECK(zoom_view_);
518 if (RefreshZoomView()) { 518 if (RefreshZoomView()) {
519 Layout(); 519 Layout();
520 SchedulePaint(); 520 SchedulePaint();
521 } 521 }
522 522
523 if (can_show_bubble && zoom_view_->visible() && delegate_->GetWebContents()) 523 WebContents* web_contents = GetWebContents();
524 ZoomBubbleView::ShowBubble(delegate_->GetWebContents(), true); 524 if (can_show_bubble && zoom_view_->visible() && web_contents)
525 ZoomBubbleView::ShowBubble(web_contents, true);
525 } 526 }
526 527
527 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, 528 void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action,
528 bool preview_enabled) { 529 bool preview_enabled) {
529 if (is_popup_mode_) 530 if (is_popup_mode_)
530 return; 531 return;
531 532
532 DCHECK(page_action); 533 DCHECK(page_action);
533 WebContents* contents = delegate_->GetWebContents(); 534 WebContents* web_contents = GetWebContents();
534 535
535 RefreshPageActionViews(); 536 RefreshPageActionViews();
536 PageActionWithBadgeView* page_action_view = 537 PageActionWithBadgeView* page_action_view =
537 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); 538 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action));
538 DCHECK(page_action_view); 539 DCHECK(page_action_view);
539 if (!page_action_view) 540 if (!page_action_view)
540 return; 541 return;
541 542
542 page_action_view->image_view()->set_preview_enabled(preview_enabled); 543 page_action_view->image_view()->set_preview_enabled(preview_enabled);
543 page_action_view->UpdateVisibility(contents, GetToolbarModel()->GetURL()); 544 page_action_view->UpdateVisibility(web_contents, GetToolbarModel()->GetURL());
544 Layout(); 545 Layout();
545 SchedulePaint(); 546 SchedulePaint();
546 } 547 }
547 548
548 PageActionWithBadgeView* LocationBarView::GetPageActionView( 549 PageActionWithBadgeView* LocationBarView::GetPageActionView(
549 ExtensionAction* page_action) { 550 ExtensionAction* page_action) {
550 DCHECK(page_action); 551 DCHECK(page_action);
551 for (PageActionViews::const_iterator i(page_action_views_.begin()); 552 for (PageActionViews::const_iterator i(page_action_views_.begin());
552 i != page_action_views_.end(); ++i) { 553 i != page_action_views_.end(); ++i) {
553 if ((*i)->image_view()->page_action() == page_action) 554 if ((*i)->image_view()->page_action() == page_action)
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 const int kEditLeadingInternalSpace = base::i18n::IsRTL() ? 1 : 0; 755 const int kEditLeadingInternalSpace = base::i18n::IsRTL() ? 1 : 0;
755 LocationBarLayout leading_decorations( 756 LocationBarLayout leading_decorations(
756 LocationBarLayout::LEFT_EDGE, item_padding - kEditLeadingInternalSpace); 757 LocationBarLayout::LEFT_EDGE, item_padding - kEditLeadingInternalSpace);
757 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, 758 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE,
758 item_padding); 759 item_padding);
759 760
760 // Show and position the animated host label used in the show and hide URL 761 // Show and position the animated host label used in the show and hide URL
761 // animations. 762 // animations.
762 if (show_url_animation_->is_animating() || 763 if (show_url_animation_->is_animating() ||
763 hide_url_animation_->is_animating()) { 764 hide_url_animation_->is_animating()) {
764 const GURL url = GetWebContents()->GetURL(); 765 WebContents* web_contents = GetWebContents();
766 const GURL url = web_contents ? web_contents->GetURL() : GURL();
765 const base::string16 host = 767 const base::string16 host =
766 OriginChip::LabelFromURLForProfile(url, profile()); 768 OriginChip::LabelFromURLForProfile(url, profile());
767 animated_host_label_->SetText(host); 769 animated_host_label_->SetText(host);
768 770
769 const base::string16 formatted_url = GetToolbarModel()->GetFormattedURL(); 771 const base::string16 formatted_url = GetToolbarModel()->GetFormattedURL();
770 772
771 // Split the formatted URL on the host name in order to determine the size 773 // Split the formatted URL on the host name in order to determine the size
772 // of the text leading up to it. 774 // of the text leading up to it.
773 std::vector<base::string16> substrings; 775 std::vector<base::string16> substrings;
774 base::SplitStringUsingSubstr(formatted_url, host, &substrings); 776 base::SplitStringUsingSubstr(formatted_url, host, &substrings);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 // Remember the previous visibility of the page actions so that we can 1119 // Remember the previous visibility of the page actions so that we can
1118 // notify when this changes. 1120 // notify when this changes.
1119 std::map<ExtensionAction*, bool> old_visibility; 1121 std::map<ExtensionAction*, bool> old_visibility;
1120 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1122 for (PageActionViews::const_iterator i(page_action_views_.begin());
1121 i != page_action_views_.end(); ++i) { 1123 i != page_action_views_.end(); ++i) {
1122 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); 1124 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible();
1123 } 1125 }
1124 1126
1125 PageActions new_page_actions; 1127 PageActions new_page_actions;
1126 1128
1127 WebContents* contents = delegate_->GetWebContents(); 1129 WebContents* web_contents = GetWebContents();
1128 if (contents) { 1130 if (web_contents) {
1129 extensions::TabHelper* extensions_tab_helper = 1131 extensions::TabHelper* extensions_tab_helper =
1130 extensions::TabHelper::FromWebContents(contents); 1132 extensions::TabHelper::FromWebContents(web_contents);
1131 extensions::LocationBarController* controller = 1133 extensions::LocationBarController* controller =
1132 extensions_tab_helper->location_bar_controller(); 1134 extensions_tab_helper->location_bar_controller();
1133 new_page_actions = controller->GetCurrentActions(); 1135 new_page_actions = controller->GetCurrentActions();
1134 } 1136 }
1135 1137
1136 // On startup we sometimes haven't loaded any extensions. This makes sure 1138 // On startup we sometimes haven't loaded any extensions. This makes sure
1137 // we catch up when the extensions (and any page actions) load. 1139 // we catch up when the extensions (and any page actions) load.
1138 if (page_actions_ != new_page_actions) { 1140 if (page_actions_ != new_page_actions) {
1139 changed = true; 1141 changed = true;
1140 1142
(...skipping 22 matching lines...) Expand all
1163 DCHECK(right_anchor); 1165 DCHECK(right_anchor);
1164 1166
1165 // |page_action_views_| are ordered right-to-left. Add them as children in 1167 // |page_action_views_| are ordered right-to-left. Add them as children in
1166 // reverse order so the logical order and visual order match for 1168 // reverse order so the logical order and visual order match for
1167 // accessibility purposes. 1169 // accessibility purposes.
1168 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); 1170 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin();
1169 i != page_action_views_.rend(); ++i) 1171 i != page_action_views_.rend(); ++i)
1170 AddChildViewAt(*i, GetIndexOf(right_anchor)); 1172 AddChildViewAt(*i, GetIndexOf(right_anchor));
1171 } 1173 }
1172 1174
1173 if (!page_action_views_.empty() && contents) { 1175 if (!page_action_views_.empty() && web_contents) {
1174 Browser* browser = chrome::FindBrowserWithWebContents(contents); 1176 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
1175 GURL url = browser->tab_strip_model()->GetActiveWebContents()->GetURL(); 1177 GURL url = browser->tab_strip_model()->GetActiveWebContents()->GetURL();
1176 1178
1177 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1179 for (PageActionViews::const_iterator i(page_action_views_.begin());
1178 i != page_action_views_.end(); ++i) { 1180 i != page_action_views_.end(); ++i) {
1179 (*i)->UpdateVisibility( 1181 (*i)->UpdateVisibility(
1180 GetToolbarModel()->input_in_progress() ? NULL : contents, url); 1182 GetToolbarModel()->input_in_progress() ? NULL : web_contents, url);
1181 1183
1182 // Check if the visibility of the action changed and notify if it did. 1184 // Check if the visibility of the action changed and notify if it did.
1183 ExtensionAction* action = (*i)->image_view()->page_action(); 1185 ExtensionAction* action = (*i)->image_view()->page_action();
1184 if (old_visibility.find(action) == old_visibility.end() || 1186 if (old_visibility.find(action) == old_visibility.end() ||
1185 old_visibility[action] != (*i)->visible()) { 1187 old_visibility[action] != (*i)->visible()) {
1186 changed = true; 1188 changed = true;
1187 content::NotificationService::current()->Notify( 1189 content::NotificationService::current()->Notify(
1188 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 1190 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
1189 content::Source<ExtensionAction>(action), 1191 content::Source<ExtensionAction>(action),
1190 content::Details<WebContents>(contents)); 1192 content::Details<WebContents>(web_contents));
1191 } 1193 }
1192 } 1194 }
1193 } 1195 }
1194 return changed; 1196 return changed;
1195 } 1197 }
1196 1198
1197 bool LocationBarView::RefreshZoomView() { 1199 bool LocationBarView::RefreshZoomView() {
1198 DCHECK(zoom_view_); 1200 DCHECK(zoom_view_);
1199 WebContents* web_contents = GetWebContents(); 1201 WebContents* web_contents = GetWebContents();
1200 if (!web_contents) 1202 if (!web_contents)
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 1675
1674 //////////////////////////////////////////////////////////////////////////////// 1676 ////////////////////////////////////////////////////////////////////////////////
1675 // LocationBarView, private content::NotificationObserver implementation: 1677 // LocationBarView, private content::NotificationObserver implementation:
1676 1678
1677 void LocationBarView::Observe(int type, 1679 void LocationBarView::Observe(int type,
1678 const content::NotificationSource& source, 1680 const content::NotificationSource& source,
1679 const content::NotificationDetails& details) { 1681 const content::NotificationDetails& details) {
1680 switch (type) { 1682 switch (type) {
1681 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: { 1683 case chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED: {
1682 // Only update if the updated action box was for the active tab contents. 1684 // Only update if the updated action box was for the active tab contents.
1683 WebContents* target_tab = content::Details<WebContents>(details).ptr(); 1685 if (content::Details<WebContents>(details).ptr() == GetWebContents())
1684 if (target_tab == GetWebContents())
1685 UpdatePageActions(); 1686 UpdatePageActions();
1686 break; 1687 break;
1687 } 1688 }
1688 1689
1689 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: 1690 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
1690 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: 1691 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED:
1691 Update(NULL); 1692 Update(NULL);
1692 break; 1693 break;
1693 1694
1694 default: 1695 default:
1695 NOTREACHED() << "Unexpected notification."; 1696 NOTREACHED() << "Unexpected notification.";
1696 } 1697 }
1697 } 1698 }
1698 1699
1699 //////////////////////////////////////////////////////////////////////////////// 1700 ////////////////////////////////////////////////////////////////////////////////
1700 // LocationBarView, private SearchModelObserver implementation: 1701 // LocationBarView, private SearchModelObserver implementation:
1701 1702
1702 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1703 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1703 const SearchModel::State& new_state) { 1704 const SearchModel::State& new_state) {
1704 const bool visible = !GetToolbarModel()->input_in_progress() && 1705 const bool visible = !GetToolbarModel()->input_in_progress() &&
1705 new_state.voice_search_supported; 1706 new_state.voice_search_supported;
1706 if (mic_search_view_->visible() != visible) { 1707 if (mic_search_view_->visible() != visible) {
1707 mic_search_view_->SetVisible(visible); 1708 mic_search_view_->SetVisible(visible);
1708 Layout(); 1709 Layout();
1709 } 1710 }
1710 } 1711 }
1711 1712
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698