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

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

Issue 10381105: Refactor UI "badge" (page action) logic into a BadgeController interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing NULL checks Created 8 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
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/gtk/location_bar_view_gtk.h" 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/app/chrome_command_ids.h" 18 #include "chrome/app/chrome_command_ids.h"
19 #include "chrome/browser/accessibility/accessibility_events.h" 19 #include "chrome/browser/accessibility/accessibility_events.h"
20 #include "chrome/browser/alternate_nav_url_fetcher.h" 20 #include "chrome/browser/alternate_nav_url_fetcher.h"
21 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 21 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
22 #include "chrome/browser/chrome_to_mobile_service.h" 22 #include "chrome/browser/chrome_to_mobile_service.h"
23 #include "chrome/browser/chrome_to_mobile_service_factory.h" 23 #include "chrome/browser/chrome_to_mobile_service_factory.h"
24 #include "chrome/browser/command_updater.h" 24 #include "chrome/browser/command_updater.h"
25 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 25 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
26 #include "chrome/browser/defaults.h" 26 #include "chrome/browser/defaults.h"
27 #include "chrome/browser/extensions/api/commands/extension_command_service.h" 27 #include "chrome/browser/extensions/api/commands/extension_command_service.h"
28 #include "chrome/browser/extensions/api/commands/extension_command_service_facto ry.h" 28 #include "chrome/browser/extensions/api/commands/extension_command_service_facto ry.h"
29 #include "chrome/browser/extensions/action_box_controller.h"
29 #include "chrome/browser/extensions/extension_browser_event_router.h" 30 #include "chrome/browser/extensions/extension_browser_event_router.h"
30 #include "chrome/browser/extensions/extension_service.h" 31 #include "chrome/browser/extensions/extension_service.h"
31 #include "chrome/browser/extensions/extension_tab_util.h" 32 #include "chrome/browser/extensions/extension_tab_util.h"
32 #include "chrome/browser/favicon/favicon_tab_helper.h" 33 #include "chrome/browser/favicon/favicon_tab_helper.h"
33 #include "chrome/browser/instant/instant_controller.h" 34 #include "chrome/browser/instant/instant_controller.h"
34 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/search_engines/template_url.h" 36 #include "chrome/browser/search_engines/template_url.h"
36 #include "chrome/browser/search_engines/template_url_service.h" 37 #include "chrome/browser/search_engines/template_url_service.h"
37 #include "chrome/browser/search_engines/template_url_service_factory.h" 38 #include "chrome/browser/search_engines/template_url_service_factory.h"
38 #include "chrome/browser/ui/browser.h" 39 #include "chrome/browser/ui/browser.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "ui/base/resource/resource_bundle.h" 76 #include "ui/base/resource/resource_bundle.h"
76 #include "ui/gfx/canvas_skia_paint.h" 77 #include "ui/gfx/canvas_skia_paint.h"
77 #include "ui/gfx/font.h" 78 #include "ui/gfx/font.h"
78 #include "ui/gfx/gtk_util.h" 79 #include "ui/gfx/gtk_util.h"
79 #include "ui/gfx/image/image.h" 80 #include "ui/gfx/image/image.h"
80 #include "webkit/glue/window_open_disposition.h" 81 #include "webkit/glue/window_open_disposition.h"
81 82
82 using content::NavigationEntry; 83 using content::NavigationEntry;
83 using content::OpenURLParams; 84 using content::OpenURLParams;
84 using content::WebContents; 85 using content::WebContents;
86 using extensions::ActionBoxController;
85 87
86 namespace { 88 namespace {
87 89
88 // We are positioned with a little bit of extra space that we don't use now. 90 // We are positioned with a little bit of extra space that we don't use now.
89 const int kTopMargin = 1; 91 const int kTopMargin = 1;
90 const int kBottomMargin = 1; 92 const int kBottomMargin = 1;
91 const int kLeftMargin = 1; 93 const int kLeftMargin = 1;
92 const int kRightMargin = 1; 94 const int kRightMargin = 1;
93 // We draw a border on the top and bottom (but not on left or right). 95 // We draw a border on the top and bottom (but not on left or right).
94 const int kBorderThickness = 1; 96 const int kBorderThickness = 1;
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 toolbar_model_->input_in_progress() ? NULL : web_contents); 678 toolbar_model_->input_in_progress() ? NULL : web_contents);
677 any_visible = (*i)->IsVisible() || any_visible; 679 any_visible = (*i)->IsVisible() || any_visible;
678 } 680 }
679 681
680 // If there are no visible content things, hide the top level box so it 682 // If there are no visible content things, hide the top level box so it
681 // doesn't mess with padding. 683 // doesn't mess with padding.
682 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); 684 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible);
683 } 685 }
684 686
685 void LocationBarViewGtk::UpdatePageActions() { 687 void LocationBarViewGtk::UpdatePageActions() {
686 std::vector<ExtensionAction*> page_actions; 688 ActionBoxController::DataList page_actions;
687 ExtensionService* service = browser_->profile()->GetExtensionService();
688 if (!service)
689 return;
690 689
691 // Find all the page actions. 690 TabContentsWrapper* tab_contents = GetTabContentsWrapper();
692 for (ExtensionSet::const_iterator it = service->extensions()->begin(); 691 if (tab_contents) {
693 it != service->extensions()->end(); ++it) { 692 page_actions.swap(
694 if ((*it)->page_action()) 693 *tab_contents->extension_action_box_controller()->GetAllBadgeData());
695 page_actions.push_back((*it)->page_action());
696 } 694 }
697 695
698 // Initialize on the first call, or re-inialize if more extensions have been 696 // Initialize on the first call, or re-inialize if more extensions have been
699 // loaded or added after startup. 697 // loaded or added after startup.
700 if (page_actions.size() != page_action_views_.size()) { 698 if (page_actions.size() != page_action_views_.size()) {
701 page_action_views_.reset(); // Delete the old views (if any). 699 page_action_views_.reset(); // Delete the old views (if any).
702 700
703 for (size_t i = 0; i < page_actions.size(); ++i) { 701 for (size_t i = 0; i < page_actions.size(); ++i) {
704 page_action_views_.push_back( 702 page_action_views_.push_back(
705 new PageActionViewGtk(this, page_actions[i])); 703 new PageActionViewGtk(this, page_actions[i].action));
706 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), 704 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()),
707 page_action_views_[i]->widget(), FALSE, FALSE, 0); 705 page_action_views_[i]->widget(), FALSE, FALSE, 0);
708 } 706 }
709 content::NotificationService::current()->Notify( 707 content::NotificationService::current()->Notify(
710 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 708 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
711 content::Source<LocationBar>(this), 709 content::Source<LocationBar>(this),
712 content::NotificationService::NoDetails()); 710 content::NotificationService::NoDetails());
713 } 711 }
714 712
715 WebContents* contents = GetWebContents(); 713 WebContents* contents = GetWebContents();
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 DCHECK_EQ(type, chrome::NOTIFICATION_WINDOW_CLOSED); 1672 DCHECK_EQ(type, chrome::NOTIFICATION_WINDOW_CLOSED);
1675 DisconnectPageActionAccelerator(); 1673 DisconnectPageActionAccelerator();
1676 } 1674 }
1677 1675
1678 void LocationBarViewGtk::EnabledStateChangedForCommand(int id, bool enabled) { 1676 void LocationBarViewGtk::EnabledStateChangedForCommand(int id, bool enabled) {
1679 DCHECK_EQ(id, IDC_CHROME_TO_MOBILE_PAGE); 1677 DCHECK_EQ(id, IDC_CHROME_TO_MOBILE_PAGE);
1680 if (enabled != gtk_widget_get_visible(chrome_to_mobile_view_.get())) 1678 if (enabled != gtk_widget_get_visible(chrome_to_mobile_view_.get()))
1681 UpdateChromeToMobileIcon(); 1679 UpdateChromeToMobileIcon();
1682 } 1680 }
1683 1681
1684 bool LocationBarViewGtk::PageActionViewGtk::ShowPopup() {
1685 if (!page_action_->HasPopup(current_tab_id_))
1686 return false;
1687
1688 ExtensionPopupGtk::Show(
1689 page_action_->GetPopupUrl(current_tab_id_),
1690 owner_->browser_,
1691 event_box_.get());
1692 return true;
1693 }
1694
1695 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() { 1682 void LocationBarViewGtk::PageActionViewGtk::ConnectPageActionAccelerator() {
1696 const ExtensionSet* extensions = owner_->browser()->profile()-> 1683 const ExtensionSet* extensions = owner_->browser()->profile()->
1697 GetExtensionService()->extensions(); 1684 GetExtensionService()->extensions();
1698 const Extension* extension = 1685 const Extension* extension =
1699 extensions->GetByID(page_action_->extension_id()); 1686 extensions->GetByID(page_action_->extension_id());
1700 window_ = owner_->browser()->window()->GetNativeHandle(); 1687 window_ = owner_->browser()->window()->GetNativeHandle();
1701 1688
1702 ExtensionCommandService* command_service = 1689 ExtensionCommandService* command_service =
1703 ExtensionCommandServiceFactory::GetForProfile( 1690 ExtensionCommandServiceFactory::GetForProfile(
1704 owner_->browser()->profile()); 1691 owner_->browser()->profile());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 gtk_window_remove_accel_group(window_, accel_group_); 1726 gtk_window_remove_accel_group(window_, accel_group_);
1740 g_object_unref(accel_group_); 1727 g_object_unref(accel_group_);
1741 accel_group_ = NULL; 1728 accel_group_ = NULL;
1742 keybinding_.reset(NULL); 1729 keybinding_.reset(NULL);
1743 } 1730 }
1744 } 1731 }
1745 1732
1746 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( 1733 gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed(
1747 GtkWidget* sender, 1734 GtkWidget* sender,
1748 GdkEventButton* event) { 1735 GdkEventButton* event) {
1749 Profile* profile = owner_->browser()->profile(); 1736 TabContentsWrapper* tab_contents = owner_->GetTabContentsWrapper();
1750 if (event->button != 3) { 1737 if (!tab_contents)
1751 if (!ShowPopup()) { 1738 return TRUE;
1752 ExtensionService* service = profile->GetExtensionService();
1753 service->browser_event_router()->PageActionExecuted(profile,
1754 page_action_->extension_id(), page_action_->id(), current_tab_id_,
1755 current_url_.spec(), event->button);
1756 }
1757 } else {
1758 const Extension* extension = profile->GetExtensionService()->
1759 GetExtensionById(page_action()->extension_id(), false);
1760 1739
1761 if (extension->ShowConfigureContextMenus()) { 1740 ExtensionService* extension_service =
1741 owner_->browser()->profile()->GetExtensionService();
1742 if (!extension_service)
1743 return TRUE;
1744
1745 const Extension* extension =
1746 extension_service->extensions()->GetByID(page_action()->extension_id());
1747 if (!extension)
1748 return TRUE;
1749
1750 ActionBoxController* controller =
1751 tab_contents->extension_action_box_controller();
1752
1753 switch (controller->OnClicked(extension->id(), event->button)) {
1754 case ActionBoxController::ACTION_NONE:
1755 break;
1756
1757 case ActionBoxController::ACTION_SHOW_POPUP:
1758 ExtensionPopupGtk::Show(
1759 page_action_->GetPopupUrl(current_tab_id_),
1760 owner_->browser_,
1761 event_box_.get());
1762 break;
1763
1764 case ActionBoxController::ACTION_SHOW_CONTEXT_MENU:
1762 context_menu_model_ = 1765 context_menu_model_ =
1763 new ExtensionContextMenuModel(extension, owner_->browser_); 1766 new ExtensionContextMenuModel(extension, owner_->browser_);
1764 context_menu_.reset( 1767 context_menu_.reset(
1765 new MenuGtk(NULL, context_menu_model_.get())); 1768 new MenuGtk(NULL, context_menu_model_.get()));
1766 context_menu_->PopupForWidget(sender, event->button, event->time); 1769 context_menu_->PopupForWidget(sender, event->button, event->time);
1767 } 1770 break;
1768 } 1771 }
1769 1772
1770 return TRUE; 1773 return TRUE;
1771 } 1774 }
1772 1775
1773 gboolean LocationBarViewGtk::PageActionViewGtk::OnExposeEvent( 1776 gboolean LocationBarViewGtk::PageActionViewGtk::OnExposeEvent(
1774 GtkWidget* widget, 1777 GtkWidget* widget,
1775 GdkEventExpose* event) { 1778 GdkEventExpose* event) {
1776 TRACE_EVENT0("ui::gtk", "LocationBarViewGtk::PageActionViewGtk::OnExpose"); 1779 TRACE_EVENT0("ui::gtk", "LocationBarViewGtk::PageActionViewGtk::OnExpose");
1777 WebContents* contents = owner_->GetWebContents(); 1780 WebContents* contents = owner_->GetWebContents();
(...skipping 27 matching lines...) Expand all
1805 GdkModifierType modifier, 1808 GdkModifierType modifier,
1806 void* user_data) { 1809 void* user_data) {
1807 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); 1810 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data);
1808 if (!gtk_widget_get_visible(view->widget())) 1811 if (!gtk_widget_get_visible(view->widget()))
1809 return FALSE; 1812 return FALSE;
1810 1813
1811 GdkEventButton event = {}; 1814 GdkEventButton event = {};
1812 event.button = 1; 1815 event.button = 1;
1813 return view->OnButtonPressed(view->widget(), &event); 1816 return view->OnButtonPressed(view->widget(), &event);
1814 } 1817 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/tab_contents/tab_contents_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698