OLD | NEW |
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" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/command_updater.h" | 17 #include "chrome/browser/command_updater.h" |
18 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_action.h" |
21 #include "chrome/browser/extensions/location_bar_controller.h" | 21 #include "chrome/browser/extensions/location_bar_controller.h" |
22 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
23 #include "chrome/browser/favicon/favicon_tab_helper.h" | 23 #include "chrome/browser/favicon/favicon_tab_helper.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/search/instant_service.h" | 25 #include "chrome/browser/search/instant_service.h" |
26 #include "chrome/browser/search/instant_service_factory.h" | 26 #include "chrome/browser/search/instant_service_factory.h" |
27 #include "chrome/browser/search/search.h" | 27 #include "chrome/browser/search/search.h" |
28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
29 #include "chrome/browser/translate/chrome_translate_client.h" | 29 #include "chrome/browser/translate/chrome_translate_client.h" |
30 #include "chrome/browser/translate/translate_service.h" | 30 #include "chrome/browser/translate/translate_service.h" |
(...skipping 29 matching lines...) Expand all Loading... |
60 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 60 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
61 #include "chrome/browser/ui/zoom/zoom_controller.h" | 61 #include "chrome/browser/ui/zoom/zoom_controller.h" |
62 #include "chrome/common/chrome_switches.h" | 62 #include "chrome/common/chrome_switches.h" |
63 #include "chrome/common/pref_names.h" | 63 #include "chrome/common/pref_names.h" |
64 #include "components/search_engines/template_url.h" | 64 #include "components/search_engines/template_url.h" |
65 #include "components/search_engines/template_url_service.h" | 65 #include "components/search_engines/template_url_service.h" |
66 #include "components/translate/core/browser/language_state.h" | 66 #include "components/translate/core/browser/language_state.h" |
67 #include "content/public/browser/notification_service.h" | 67 #include "content/public/browser/notification_service.h" |
68 #include "content/public/browser/render_widget_host_view.h" | 68 #include "content/public/browser/render_widget_host_view.h" |
69 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
70 #include "extensions/browser/extension_system.h" | 70 #include "extensions/browser/extension_registry.h" |
71 #include "extensions/common/feature_switch.h" | 71 #include "extensions/common/feature_switch.h" |
72 #include "extensions/common/permissions/permissions_data.h" | 72 #include "extensions/common/permissions/permissions_data.h" |
73 #include "grit/component_scaled_resources.h" | 73 #include "grit/component_scaled_resources.h" |
74 #include "grit/generated_resources.h" | 74 #include "grit/generated_resources.h" |
75 #include "grit/theme_resources.h" | 75 #include "grit/theme_resources.h" |
76 #include "ui/accessibility/ax_view_state.h" | 76 #include "ui/accessibility/ax_view_state.h" |
77 #include "ui/base/dragdrop/drag_drop_types.h" | 77 #include "ui/base/dragdrop/drag_drop_types.h" |
78 #include "ui/base/l10n/l10n_util.h" | 78 #include "ui/base/l10n/l10n_util.h" |
79 #include "ui/base/resource/resource_bundle.h" | 79 #include "ui/base/resource/resource_bundle.h" |
80 #include "ui/base/theme_provider.h" | 80 #include "ui/base/theme_provider.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 int GetEditLeadingInternalSpace() { | 161 int GetEditLeadingInternalSpace() { |
162 // The textfield has 1 px of whitespace before the text in the RTL case only. | 162 // The textfield has 1 px of whitespace before the text in the RTL case only. |
163 return base::i18n::IsRTL() ? 1 : 0; | 163 return base::i18n::IsRTL() ? 1 : 0; |
164 } | 164 } |
165 | 165 |
166 // Functor for moving BookmarkManagerPrivate page actions to the right via | 166 // Functor for moving BookmarkManagerPrivate page actions to the right via |
167 // stable_partition. | 167 // stable_partition. |
168 class IsPageActionViewRightAligned { | 168 class IsPageActionViewRightAligned { |
169 public: | 169 public: |
170 explicit IsPageActionViewRightAligned(ExtensionService* extension_service) | 170 explicit IsPageActionViewRightAligned( |
171 : extension_service_(extension_service) {} | 171 extensions::ExtensionRegistry* extension_registry) |
| 172 : extension_registry_(extension_registry) {} |
172 | 173 |
173 bool operator()(PageActionWithBadgeView* page_action_view) { | 174 bool operator()(PageActionWithBadgeView* page_action_view) { |
174 return extension_service_ | 175 return extension_registry_->enabled_extensions().GetByID( |
175 ->GetExtensionById( | 176 page_action_view->image_view()->extension_action()->extension_id())-> |
176 page_action_view->image_view()->page_action()->extension_id(), | 177 permissions_data()-> |
177 false) | 178 HasAPIPermission(extensions::APIPermission::kBookmarkManagerPrivate); |
178 ->permissions_data() | |
179 ->HasAPIPermission(extensions::APIPermission::kBookmarkManagerPrivate); | |
180 } | 179 } |
181 | 180 |
182 private: | 181 private: |
183 ExtensionService* extension_service_; | 182 extensions::ExtensionRegistry* extension_registry_; |
184 | 183 |
185 // NOTE: Can't DISALLOW_COPY_AND_ASSIGN as we pass this object by value to | 184 // NOTE: Can't DISALLOW_COPY_AND_ASSIGN as we pass this object by value to |
186 // std::stable_partition(). | 185 // std::stable_partition(). |
187 }; | 186 }; |
188 | 187 |
189 } // namespace | 188 } // namespace |
190 | 189 |
191 | 190 |
192 // LocationBarView ----------------------------------------------------------- | 191 // LocationBarView ----------------------------------------------------------- |
193 | 192 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 WebContents* web_contents = GetWebContents(); | 501 WebContents* web_contents = GetWebContents(); |
503 | 502 |
504 RefreshPageActionViews(); | 503 RefreshPageActionViews(); |
505 PageActionWithBadgeView* page_action_view = | 504 PageActionWithBadgeView* page_action_view = |
506 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); | 505 static_cast<PageActionWithBadgeView*>(GetPageActionView(page_action)); |
507 DCHECK(page_action_view); | 506 DCHECK(page_action_view); |
508 if (!page_action_view) | 507 if (!page_action_view) |
509 return; | 508 return; |
510 | 509 |
511 page_action_view->image_view()->set_preview_enabled(preview_enabled); | 510 page_action_view->image_view()->set_preview_enabled(preview_enabled); |
512 page_action_view->UpdateVisibility(web_contents, GetToolbarModel()->GetURL()); | 511 page_action_view->UpdateVisibility(web_contents); |
513 Layout(); | 512 Layout(); |
514 SchedulePaint(); | 513 SchedulePaint(); |
515 } | 514 } |
516 | 515 |
517 PageActionWithBadgeView* LocationBarView::GetPageActionView( | 516 PageActionWithBadgeView* LocationBarView::GetPageActionView( |
518 ExtensionAction* page_action) { | 517 ExtensionAction* page_action) { |
519 DCHECK(page_action); | 518 DCHECK(page_action); |
520 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 519 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
521 i != page_action_views_.end(); ++i) { | 520 i != page_action_views_.end(); ++i) { |
522 if ((*i)->image_view()->page_action() == page_action) | 521 if ((*i)->image_view()->extension_action() == page_action) |
523 return *i; | 522 return *i; |
524 } | 523 } |
525 return NULL; | 524 return NULL; |
526 } | 525 } |
527 | 526 |
528 void LocationBarView::SetStarToggled(bool on) { | 527 void LocationBarView::SetStarToggled(bool on) { |
529 if (star_view_) | 528 if (star_view_) |
530 star_view_->SetToggled(on); | 529 star_view_->SetToggled(on); |
531 } | 530 } |
532 | 531 |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 if (is_popup_mode_) | 1143 if (is_popup_mode_) |
1145 return false; | 1144 return false; |
1146 | 1145 |
1147 bool changed = false; | 1146 bool changed = false; |
1148 | 1147 |
1149 // Remember the previous visibility of the page actions so that we can | 1148 // Remember the previous visibility of the page actions so that we can |
1150 // notify when this changes. | 1149 // notify when this changes. |
1151 std::map<ExtensionAction*, bool> old_visibility; | 1150 std::map<ExtensionAction*, bool> old_visibility; |
1152 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1151 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
1153 i != page_action_views_.end(); ++i) { | 1152 i != page_action_views_.end(); ++i) { |
1154 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); | 1153 old_visibility[(*i)->image_view()->extension_action()] = (*i)->visible(); |
1155 } | 1154 } |
1156 | 1155 |
1157 PageActions new_page_actions; | 1156 PageActions new_page_actions; |
1158 | 1157 |
1159 WebContents* web_contents = GetWebContents(); | 1158 WebContents* web_contents = GetWebContents(); |
1160 if (web_contents) { | 1159 if (web_contents) { |
1161 extensions::TabHelper* extensions_tab_helper = | 1160 extensions::TabHelper* extensions_tab_helper = |
1162 extensions::TabHelper::FromWebContents(web_contents); | 1161 extensions::TabHelper::FromWebContents(web_contents); |
1163 extensions::LocationBarController* controller = | 1162 extensions::LocationBarController* controller = |
1164 extensions_tab_helper->location_bar_controller(); | 1163 extensions_tab_helper->location_bar_controller(); |
(...skipping 15 matching lines...) Expand all Loading... |
1180 delegate_->CreatePageActionImageView(this, *i)); | 1179 delegate_->CreatePageActionImageView(this, *i)); |
1181 page_action_view->SetVisible(false); | 1180 page_action_view->SetVisible(false); |
1182 page_action_views_.push_back(page_action_view); | 1181 page_action_views_.push_back(page_action_view); |
1183 } | 1182 } |
1184 | 1183 |
1185 // Move rightmost extensions to the start. | 1184 // Move rightmost extensions to the start. |
1186 std::stable_partition( | 1185 std::stable_partition( |
1187 page_action_views_.begin(), | 1186 page_action_views_.begin(), |
1188 page_action_views_.end(), | 1187 page_action_views_.end(), |
1189 IsPageActionViewRightAligned( | 1188 IsPageActionViewRightAligned( |
1190 extensions::ExtensionSystem::Get(profile())->extension_service())); | 1189 extensions::ExtensionRegistry::Get(profile()))); |
1191 | 1190 |
1192 View* right_anchor = open_pdf_in_reader_view_; | 1191 View* right_anchor = open_pdf_in_reader_view_; |
1193 if (!right_anchor) | 1192 if (!right_anchor) |
1194 right_anchor = star_view_; | 1193 right_anchor = star_view_; |
1195 DCHECK(right_anchor); | 1194 DCHECK(right_anchor); |
1196 | 1195 |
1197 // |page_action_views_| are ordered right-to-left. Add them as children in | 1196 // |page_action_views_| are ordered right-to-left. Add them as children in |
1198 // reverse order so the logical order and visual order match for | 1197 // reverse order so the logical order and visual order match for |
1199 // accessibility purposes. | 1198 // accessibility purposes. |
1200 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); | 1199 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); |
1201 i != page_action_views_.rend(); ++i) | 1200 i != page_action_views_.rend(); ++i) |
1202 AddChildViewAt(*i, GetIndexOf(right_anchor)); | 1201 AddChildViewAt(*i, GetIndexOf(right_anchor)); |
1203 } | 1202 } |
1204 | 1203 |
1205 if (!page_action_views_.empty() && web_contents) { | 1204 if (!page_action_views_.empty() && web_contents) { |
1206 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
1207 GURL url = browser->tab_strip_model()->GetActiveWebContents()->GetURL(); | |
1208 | |
1209 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1205 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
1210 i != page_action_views_.end(); ++i) { | 1206 i != page_action_views_.end(); ++i) { |
1211 (*i)->UpdateVisibility( | 1207 (*i)->UpdateVisibility( |
1212 GetToolbarModel()->input_in_progress() ? NULL : web_contents, url); | 1208 GetToolbarModel()->input_in_progress() ? NULL : web_contents); |
1213 | 1209 |
1214 // Check if the visibility of the action changed and notify if it did. | 1210 // Check if the visibility of the action changed and notify if it did. |
1215 ExtensionAction* action = (*i)->image_view()->page_action(); | 1211 ExtensionAction* action = (*i)->image_view()->extension_action(); |
1216 if (old_visibility.find(action) == old_visibility.end() || | 1212 if (old_visibility.find(action) == old_visibility.end() || |
1217 old_visibility[action] != (*i)->visible()) { | 1213 old_visibility[action] != (*i)->visible()) { |
1218 changed = true; | 1214 changed = true; |
1219 content::NotificationService::current()->Notify( | 1215 content::NotificationService::current()->Notify( |
1220 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1216 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
1221 content::Source<ExtensionAction>(action), | 1217 content::Source<ExtensionAction>(action), |
1222 content::Details<WebContents>(web_contents)); | 1218 content::Details<WebContents>(web_contents)); |
1223 } | 1219 } |
1224 } | 1220 } |
1225 } | 1221 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 int result = 0; | 1443 int result = 0; |
1448 for (size_t i = 0; i < page_action_views_.size(); i++) { | 1444 for (size_t i = 0; i < page_action_views_.size(); i++) { |
1449 if (page_action_views_[i]->visible()) | 1445 if (page_action_views_[i]->visible()) |
1450 ++result; | 1446 ++result; |
1451 } | 1447 } |
1452 return result; | 1448 return result; |
1453 } | 1449 } |
1454 | 1450 |
1455 ExtensionAction* LocationBarView::GetPageAction(size_t index) { | 1451 ExtensionAction* LocationBarView::GetPageAction(size_t index) { |
1456 if (index < page_action_views_.size()) | 1452 if (index < page_action_views_.size()) |
1457 return page_action_views_[index]->image_view()->page_action(); | 1453 return page_action_views_[index]->image_view()->extension_action(); |
1458 | 1454 |
1459 NOTREACHED(); | 1455 NOTREACHED(); |
1460 return NULL; | 1456 return NULL; |
1461 } | 1457 } |
1462 | 1458 |
1463 ExtensionAction* LocationBarView::GetVisiblePageAction(size_t index) { | 1459 ExtensionAction* LocationBarView::GetVisiblePageAction(size_t index) { |
1464 size_t current = 0; | 1460 size_t current = 0; |
1465 for (size_t i = 0; i < page_action_views_.size(); ++i) { | 1461 for (size_t i = 0; i < page_action_views_.size(); ++i) { |
1466 if (page_action_views_[i]->visible()) { | 1462 if (page_action_views_[i]->visible()) { |
1467 if (current == index) | 1463 if (current == index) |
1468 return page_action_views_[i]->image_view()->page_action(); | 1464 return page_action_views_[i]->image_view()->extension_action(); |
1469 | 1465 |
1470 ++current; | 1466 ++current; |
1471 } | 1467 } |
1472 } | 1468 } |
1473 | 1469 |
1474 NOTREACHED(); | 1470 NOTREACHED(); |
1475 return NULL; | 1471 return NULL; |
1476 } | 1472 } |
1477 | 1473 |
1478 void LocationBarView::TestPageActionPressed(size_t index) { | 1474 void LocationBarView::TestPageActionPressed(size_t index) { |
1479 size_t current = 0; | 1475 size_t current = 0; |
1480 for (size_t i = 0; i < page_action_views_.size(); ++i) { | 1476 for (size_t i = 0; i < page_action_views_.size(); ++i) { |
1481 if (page_action_views_[i]->visible()) { | 1477 if (page_action_views_[i]->visible()) { |
1482 if (current == index) { | 1478 if (current == index) { |
1483 page_action_views_[i]->image_view()->ExecuteAction( | 1479 page_action_views_[i]->image_view()->view_controller()-> |
1484 ExtensionPopup::SHOW); | 1480 ExecuteAction(ExtensionPopup::SHOW, true); |
1485 return; | 1481 return; |
1486 } | 1482 } |
1487 ++current; | 1483 ++current; |
1488 } | 1484 } |
1489 } | 1485 } |
1490 | 1486 |
1491 NOTREACHED(); | 1487 NOTREACHED(); |
1492 } | 1488 } |
1493 | 1489 |
1494 bool LocationBarView::GetBookmarkStarVisibility() { | 1490 bool LocationBarView::GetBookmarkStarVisibility() { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 | 1760 |
1765 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1761 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1766 const SearchModel::State& new_state) { | 1762 const SearchModel::State& new_state) { |
1767 const bool visible = !GetToolbarModel()->input_in_progress() && | 1763 const bool visible = !GetToolbarModel()->input_in_progress() && |
1768 new_state.voice_search_supported; | 1764 new_state.voice_search_supported; |
1769 if (mic_search_view_->visible() != visible) { | 1765 if (mic_search_view_->visible() != visible) { |
1770 mic_search_view_->SetVisible(visible); | 1766 mic_search_view_->SetVisible(visible); |
1771 Layout(); | 1767 Layout(); |
1772 } | 1768 } |
1773 } | 1769 } |
OLD | NEW |