OLD | NEW |
---|---|
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 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.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 #import "chrome/browser/app_controller_mac.h" | 16 #import "chrome/browser/app_controller_mac.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/api/tabs/tabs_api.h" | 20 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
21 #include "chrome/browser/extensions/extension_action.h" | 21 #include "chrome/browser/extensions/extension_action.h" |
22 #include "chrome/browser/extensions/extension_service.h" | |
23 #include "chrome/browser/extensions/location_bar_controller.h" | 22 #include "chrome/browser/extensions/location_bar_controller.h" |
24 #include "chrome/browser/extensions/tab_helper.h" | 23 #include "chrome/browser/extensions/tab_helper.h" |
25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/search/instant_service.h" | 25 #include "chrome/browser/search/instant_service.h" |
27 #include "chrome/browser/search/instant_service_factory.h" | 26 #include "chrome/browser/search/instant_service_factory.h" |
28 #include "chrome/browser/search/search.h" | 27 #include "chrome/browser/search/search.h" |
29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
30 #include "chrome/browser/translate/chrome_translate_client.h" | 29 #include "chrome/browser/translate/chrome_translate_client.h" |
31 #include "chrome/browser/translate/translate_service.h" | 30 #include "chrome/browser/translate/translate_service.h" |
32 #include "chrome/browser/ui/browser_instant_controller.h" | 31 #include "chrome/browser/ui/browser_instant_controller.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 using content::WebContents; | 77 using content::WebContents; |
79 | 78 |
80 namespace { | 79 namespace { |
81 | 80 |
82 // Vertical space between the bottom edge of the location_bar and the first run | 81 // Vertical space between the bottom edge of the location_bar and the first run |
83 // bubble arrow point. | 82 // bubble arrow point. |
84 const static int kFirstRunBubbleYOffset = 1; | 83 const static int kFirstRunBubbleYOffset = 1; |
85 | 84 |
86 // Functor for moving BookmarkManagerPrivate page actions to the right via | 85 // Functor for moving BookmarkManagerPrivate page actions to the right via |
87 // stable_partition. | 86 // stable_partition. |
88 class IsPageActionViewRightAligned { | 87 bool PageActionHasBoomarkManagerPrivate(PageActionDecoration* decoration) { |
Avi (use Gerrit)
2014/10/30 23:21:26
Fix typo: "boomark"?
Devlin
2014/10/31 17:50:43
It was just in Halloween spirit! ;)
| |
89 public: | 88 return decoration->GetExtension()->permissions_data()->HasAPIPermission( |
90 explicit IsPageActionViewRightAligned(ExtensionService* extension_service) | 89 extensions::APIPermission::kBookmarkManagerPrivate); |
91 : extension_service_(extension_service) {} | 90 } |
92 | 91 |
93 bool operator()(PageActionDecoration* page_action_decoration) { | 92 } // namespace |
94 return extension_service_ | |
95 ->GetExtensionById( | |
96 page_action_decoration->page_action()->extension_id(), false) | |
97 ->permissions_data() | |
98 ->HasAPIPermission(extensions::APIPermission::kBookmarkManagerPrivate); | |
99 } | |
100 | |
101 private: | |
102 ExtensionService* extension_service_; | |
103 | |
104 // NOTE: Can't DISALLOW_COPY_AND_ASSIGN as we pass this object by value to | |
105 // std::stable_partition(). | |
106 }; | |
107 | |
108 } | |
109 | 93 |
110 // TODO(shess): This code is mostly copied from the gtk | 94 // TODO(shess): This code is mostly copied from the gtk |
111 // implementation. Make sure it's all appropriate and flesh it out. | 95 // implementation. Make sure it's all appropriate and flesh it out. |
112 | 96 |
113 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, | 97 LocationBarViewMac::LocationBarViewMac(AutocompleteTextField* field, |
114 CommandUpdater* command_updater, | 98 CommandUpdater* command_updater, |
115 Profile* profile, | 99 Profile* profile, |
116 Browser* browser) | 100 Browser* browser) |
117 : LocationBar(profile), | 101 : LocationBar(profile), |
118 OmniboxEditController(command_updater), | 102 OmniboxEditController(command_updater), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 214 |
231 void LocationBarViewMac::UpdateBookmarkStarVisibility() { | 215 void LocationBarViewMac::UpdateBookmarkStarVisibility() { |
232 star_decoration_->SetVisible(IsStarEnabled()); | 216 star_decoration_->SetVisible(IsStarEnabled()); |
233 } | 217 } |
234 | 218 |
235 bool LocationBarViewMac::ShowPageActionPopup( | 219 bool LocationBarViewMac::ShowPageActionPopup( |
236 const extensions::Extension* extension, bool grant_active_tab) { | 220 const extensions::Extension* extension, bool grant_active_tab) { |
237 for (ScopedVector<PageActionDecoration>::iterator iter = | 221 for (ScopedVector<PageActionDecoration>::iterator iter = |
238 page_action_decorations_.begin(); | 222 page_action_decorations_.begin(); |
239 iter != page_action_decorations_.end(); ++iter) { | 223 iter != page_action_decorations_.end(); ++iter) { |
240 if ((*iter)->page_action()->extension_id() == extension->id()) | 224 if ((*iter)->GetExtension() == extension) |
241 return (*iter)->ActivatePageAction(grant_active_tab); | 225 return (*iter)->ActivatePageAction(grant_active_tab); |
242 } | 226 } |
243 return false; | 227 return false; |
244 } | 228 } |
245 | 229 |
246 void LocationBarViewMac::UpdateOpenPDFInReaderPrompt() { | 230 void LocationBarViewMac::UpdateOpenPDFInReaderPrompt() { |
247 // Not implemented on Mac. | 231 // Not implemented on Mac. |
248 } | 232 } |
249 | 233 |
250 void LocationBarViewMac::UpdateGeneratedCreditCardView() { | 234 void LocationBarViewMac::UpdateGeneratedCreditCardView() { |
(...skipping 30 matching lines...) Expand all Loading... | |
281 int result = 0; | 265 int result = 0; |
282 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 266 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
283 if (page_action_decorations_[i]->IsVisible()) | 267 if (page_action_decorations_[i]->IsVisible()) |
284 ++result; | 268 ++result; |
285 } | 269 } |
286 return result; | 270 return result; |
287 } | 271 } |
288 | 272 |
289 ExtensionAction* LocationBarViewMac::GetPageAction(size_t index) { | 273 ExtensionAction* LocationBarViewMac::GetPageAction(size_t index) { |
290 if (index < page_action_decorations_.size()) | 274 if (index < page_action_decorations_.size()) |
291 return page_action_decorations_[index]->page_action(); | 275 return page_action_decorations_[index]->GetPageAction(); |
292 NOTREACHED(); | 276 NOTREACHED(); |
293 return NULL; | 277 return NULL; |
294 } | 278 } |
295 | 279 |
296 ExtensionAction* LocationBarViewMac::GetVisiblePageAction(size_t index) { | 280 ExtensionAction* LocationBarViewMac::GetVisiblePageAction(size_t index) { |
297 size_t current = 0; | 281 size_t current = 0; |
298 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 282 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
299 if (page_action_decorations_[i]->IsVisible()) { | 283 if (page_action_decorations_[i]->IsVisible()) { |
300 if (current == index) | 284 if (current == index) |
301 return page_action_decorations_[i]->page_action(); | 285 return page_action_decorations_[i]->GetPageAction(); |
302 | 286 |
303 ++current; | 287 ++current; |
304 } | 288 } |
305 } | 289 } |
306 | 290 |
307 NOTREACHED(); | 291 NOTREACHED(); |
308 return NULL; | 292 return NULL; |
309 } | 293 } |
310 | 294 |
311 void LocationBarViewMac::TestPageActionPressed(size_t index) { | 295 void LocationBarViewMac::TestPageActionPressed(size_t index) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 return; | 479 return; |
496 RefreshPageActionDecorations(); | 480 RefreshPageActionDecorations(); |
497 Layout(); | 481 Layout(); |
498 | 482 |
499 PageActionDecoration* decoration = GetPageActionDecoration(page_action); | 483 PageActionDecoration* decoration = GetPageActionDecoration(page_action); |
500 DCHECK(decoration); | 484 DCHECK(decoration); |
501 if (!decoration) | 485 if (!decoration) |
502 return; | 486 return; |
503 | 487 |
504 decoration->set_preview_enabled(preview_enabled); | 488 decoration->set_preview_enabled(preview_enabled); |
505 decoration->UpdateVisibility(contents, GetToolbarModel()->GetURL()); | 489 decoration->UpdateVisibility(contents); |
506 } | 490 } |
507 | 491 |
508 NSRect LocationBarViewMac::GetPageActionFrame(ExtensionAction* page_action) { | 492 NSRect LocationBarViewMac::GetPageActionFrame(ExtensionAction* page_action) { |
509 PageActionDecoration* decoration = GetPageActionDecoration(page_action); | 493 PageActionDecoration* decoration = GetPageActionDecoration(page_action); |
510 if (!decoration) | 494 if (!decoration) |
511 return NSZeroRect; | 495 return NSZeroRect; |
512 | 496 |
513 AutocompleteTextFieldCell* cell = [field_ cell]; | 497 AutocompleteTextFieldCell* cell = [field_ cell]; |
514 NSRect frame = [cell frameForDecoration:decoration inFrame:[field_ bounds]]; | 498 NSRect frame = [cell frameForDecoration:decoration inFrame:[field_ bounds]]; |
515 return frame; | 499 return frame; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 | 622 |
639 void LocationBarViewMac::PostNotification(NSString* notification) { | 623 void LocationBarViewMac::PostNotification(NSString* notification) { |
640 [[NSNotificationCenter defaultCenter] postNotificationName:notification | 624 [[NSNotificationCenter defaultCenter] postNotificationName:notification |
641 object:[NSValue valueWithPointer:this]]; | 625 object:[NSValue valueWithPointer:this]]; |
642 } | 626 } |
643 | 627 |
644 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( | 628 PageActionDecoration* LocationBarViewMac::GetPageActionDecoration( |
645 ExtensionAction* page_action) { | 629 ExtensionAction* page_action) { |
646 DCHECK(page_action); | 630 DCHECK(page_action); |
647 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 631 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
648 if (page_action_decorations_[i]->page_action() == page_action) | 632 if (page_action_decorations_[i]->GetPageAction() == page_action) |
649 return page_action_decorations_[i]; | 633 return page_action_decorations_[i]; |
650 } | 634 } |
651 // If |page_action| is the browser action of an extension, no element in | 635 // If |page_action| is the browser action of an extension, no element in |
652 // |page_action_decorations_| will match. | 636 // |page_action_decorations_| will match. |
653 NOTREACHED(); | 637 NOTREACHED(); |
654 return NULL; | 638 return NULL; |
655 } | 639 } |
656 | 640 |
657 | |
658 void LocationBarViewMac::DeletePageActionDecorations() { | 641 void LocationBarViewMac::DeletePageActionDecorations() { |
659 // TODO(shess): Deleting these decorations could result in the cell | 642 // TODO(shess): Deleting these decorations could result in the cell |
660 // refering to them before things are laid out again. Meanwhile, at | 643 // refering to them before things are laid out again. Meanwhile, at |
661 // least fail safe. | 644 // least fail safe. |
662 [[field_ cell] clearDecorations]; | 645 [[field_ cell] clearDecorations]; |
663 | 646 |
664 page_action_decorations_.clear(); | 647 page_action_decorations_.clear(); |
665 } | 648 } |
666 | 649 |
667 void LocationBarViewMac::OnEditBookmarksEnabledChanged() { | 650 void LocationBarViewMac::OnEditBookmarksEnabledChanged() { |
(...skipping 19 matching lines...) Expand all Loading... | |
687 | 670 |
688 if (new_page_actions != page_actions_) { | 671 if (new_page_actions != page_actions_) { |
689 page_actions_.swap(new_page_actions); | 672 page_actions_.swap(new_page_actions); |
690 DeletePageActionDecorations(); | 673 DeletePageActionDecorations(); |
691 for (size_t i = 0; i < page_actions_.size(); ++i) { | 674 for (size_t i = 0; i < page_actions_.size(); ++i) { |
692 page_action_decorations_.push_back( | 675 page_action_decorations_.push_back( |
693 new PageActionDecoration(this, browser_, page_actions_[i])); | 676 new PageActionDecoration(this, browser_, page_actions_[i])); |
694 } | 677 } |
695 | 678 |
696 // Move rightmost extensions to the start. | 679 // Move rightmost extensions to the start. |
697 std::stable_partition( | 680 std::stable_partition(page_action_decorations_.begin(), |
698 page_action_decorations_.begin(), | 681 page_action_decorations_.end(), |
699 page_action_decorations_.end(), | 682 PageActionHasBoomarkManagerPrivate); |
700 IsPageActionViewRightAligned( | |
701 extensions::ExtensionSystem::Get(profile())->extension_service())); | |
702 } | 683 } |
703 | 684 |
704 GURL url = GetToolbarModel()->GetURL(); | 685 GURL url = GetToolbarModel()->GetURL(); |
705 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { | 686 for (size_t i = 0; i < page_action_decorations_.size(); ++i) { |
706 page_action_decorations_[i]->UpdateVisibility( | 687 page_action_decorations_[i]->UpdateVisibility( |
707 GetToolbarModel()->input_in_progress() ? NULL : web_contents, url); | 688 GetToolbarModel()->input_in_progress() ? NULL : web_contents); |
708 } | 689 } |
709 } | 690 } |
710 | 691 |
711 bool LocationBarViewMac::RefreshContentSettingsDecorations() { | 692 bool LocationBarViewMac::RefreshContentSettingsDecorations() { |
712 const bool input_in_progress = GetToolbarModel()->input_in_progress(); | 693 const bool input_in_progress = GetToolbarModel()->input_in_progress(); |
713 WebContents* web_contents = input_in_progress ? | 694 WebContents* web_contents = input_in_progress ? |
714 NULL : browser_->tab_strip_model()->GetActiveWebContents(); | 695 NULL : browser_->tab_strip_model()->GetActiveWebContents(); |
715 bool icons_updated = false; | 696 bool icons_updated = false; |
716 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { | 697 for (size_t i = 0; i < content_setting_decorations_.size(); ++i) { |
717 icons_updated |= | 698 icons_updated |= |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 } | 745 } |
765 | 746 |
766 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { | 747 bool LocationBarViewMac::UpdateMicSearchDecorationVisibility() { |
767 bool is_visible = !GetToolbarModel()->input_in_progress() && | 748 bool is_visible = !GetToolbarModel()->input_in_progress() && |
768 browser_->search_model()->voice_search_supported(); | 749 browser_->search_model()->voice_search_supported(); |
769 if (mic_search_decoration_->IsVisible() == is_visible) | 750 if (mic_search_decoration_->IsVisible() == is_visible) |
770 return false; | 751 return false; |
771 mic_search_decoration_->SetVisible(is_visible); | 752 mic_search_decoration_->SetVisible(is_visible); |
772 return true; | 753 return true; |
773 } | 754 } |
OLD | NEW |