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

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

Issue 10392142: Revert 137630 - Broke ASAN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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_helper.h"
32 #include "chrome/browser/extensions/extension_tab_util.h" 32 #include "chrome/browser/extensions/extension_tab_util.h"
33 #include "chrome/browser/favicon/favicon_tab_helper.h" 33 #include "chrome/browser/favicon/favicon_tab_helper.h"
34 #include "chrome/browser/instant/instant_controller.h" 34 #include "chrome/browser/instant/instant_controller.h"
35 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/search_engines/template_url.h" 36 #include "chrome/browser/search_engines/template_url.h"
37 #include "chrome/browser/search_engines/template_url_service.h" 37 #include "chrome/browser/search_engines/template_url_service.h"
38 #include "chrome/browser/search_engines/template_url_service_factory.h" 38 #include "chrome/browser/search_engines/template_url_service_factory.h"
39 #include "chrome/browser/ui/browser.h" 39 #include "chrome/browser/ui/browser.h"
40 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" 40 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
41 #include "chrome/browser/ui/browser_list.h" 41 #include "chrome/browser/ui/browser_list.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s 350 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s
351 // size-allocate so we can do proper resizing and eliding on 351 // size-allocate so we can do proper resizing and eliding on
352 // |security_info_label_|. 352 // |security_info_label_|.
353 g_signal_connect(hbox_.get(), "size-allocate", 353 g_signal_connect(hbox_.get(), "size-allocate",
354 G_CALLBACK(&OnHboxSizeAllocateThunk), this); 354 G_CALLBACK(&OnHboxSizeAllocateThunk), this);
355 355
356 registrar_.Add(this, 356 registrar_.Add(this,
357 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 357 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
358 content::Source<ThemeService>(theme_service_)); 358 content::Source<ThemeService>(theme_service_));
359 registrar_.Add(this,
360 chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED,
361 content::Source<Profile>(browser()->profile()));
362
363 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, 359 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled,
364 profile->GetPrefs(), this); 360 profile->GetPrefs(), this);
365 361
366 theme_service_->InitThemesFor(this); 362 theme_service_->InitThemesFor(this);
367 } 363 }
368 364
369 void LocationBarViewGtk::BuildSiteTypeArea() { 365 void LocationBarViewGtk::BuildSiteTypeArea() {
370 location_icon_image_ = gtk_image_new(); 366 location_icon_image_ = gtk_image_new();
371 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); 367 gtk_widget_set_name(location_icon_image_, "chrome-location-icon");
372 368
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 437 }
442 438
443 WebContents* LocationBarViewGtk::GetWebContents() const { 439 WebContents* LocationBarViewGtk::GetWebContents() const {
444 return browser_->GetSelectedWebContents(); 440 return browser_->GetSelectedWebContents();
445 } 441 }
446 442
447 void LocationBarViewGtk::SetPreviewEnabledPageAction( 443 void LocationBarViewGtk::SetPreviewEnabledPageAction(
448 ExtensionAction *page_action, 444 ExtensionAction *page_action,
449 bool preview_enabled) { 445 bool preview_enabled) {
450 DCHECK(page_action); 446 DCHECK(page_action);
451 if (preview_enabled && preview_enabled_actions_.insert(page_action).second) 447 UpdatePageActions();
452 UpdatePageActions(); 448 for (ScopedVector<PageActionViewGtk>::iterator iter =
453 if (!preview_enabled && preview_enabled_actions_.erase(page_action) > 0) 449 page_action_views_.begin(); iter != page_action_views_.end();
454 UpdatePageActions(); 450 ++iter) {
451 if ((*iter)->page_action() == page_action) {
452 (*iter)->set_preview_enabled(preview_enabled);
453 UpdatePageActions();
454 return;
455 }
456 }
455 } 457 }
456 458
457 GtkWidget* LocationBarViewGtk::GetPageActionWidget( 459 GtkWidget* LocationBarViewGtk::GetPageActionWidget(
458 ExtensionAction *page_action) { 460 ExtensionAction *page_action) {
459 DCHECK(page_action); 461 DCHECK(page_action);
460 for (ScopedVector<PageActionViewGtk>::iterator iter = 462 for (ScopedVector<PageActionViewGtk>::iterator iter =
461 page_action_views_.begin(); 463 page_action_views_.begin();
462 iter != page_action_views_.end(); 464 iter != page_action_views_.end();
463 ++iter) { 465 ++iter) {
464 if ((*iter)->page_action() == page_action) 466 if ((*iter)->page_action() == page_action)
(...skipping 211 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 689
688 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); 690 TabContentsWrapper* tab_contents = GetTabContentsWrapper();
689 if (tab_contents) { 691 if (tab_contents) {
690 ActionBoxController* controller = 692 page_actions.swap(
691 tab_contents->extension_tab_helper()->action_box_controller(); 693 *tab_contents->extension_action_box_controller()->GetAllBadgeData());
692 page_actions.swap(*controller->GetCurrentActions());
693 } 694 }
694 695
695 // Add page actions for any extensions which have "preview enabled" and not
696 // already visible.
697 ActionBoxController::AddMissingActions(
698 preview_enabled_actions_, &page_actions);
699
700 // 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
701 // loaded or added after startup. 697 // loaded or added after startup.
702 if (page_actions.size() != page_action_views_.size()) { 698 if (page_actions.size() != page_action_views_.size()) {
703 page_action_views_.reset(); // Delete the old views (if any). 699 page_action_views_.reset(); // Delete the old views (if any).
704 700
705 for (size_t i = 0; i < page_actions.size(); ++i) { 701 for (size_t i = 0; i < page_actions.size(); ++i) {
706 page_action_views_.push_back( 702 page_action_views_.push_back(
707 new PageActionViewGtk(this, page_actions[i])); 703 new PageActionViewGtk(this, page_actions[i].action));
708 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), 704 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()),
709 page_action_views_[i]->widget(), FALSE, FALSE, 0); 705 page_action_views_[i]->widget(), FALSE, FALSE, 0);
710 } 706 }
711 content::NotificationService::current()->Notify( 707 content::NotificationService::current()->Notify(
712 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 708 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
713 content::Source<LocationBar>(this), 709 content::Source<LocationBar>(this),
714 content::NotificationService::NoDetails()); 710 content::NotificationService::NoDetails());
715 } 711 }
716 712
717 WebContents* contents = GetWebContents(); 713 WebContents* contents = GetWebContents();
718 if (!page_action_views_.empty() && contents) { 714 if (!page_action_views_.empty() && contents) {
719 GURL url = browser()->GetSelectedWebContents()->GetURL(); 715 GURL url = browser()->GetSelectedWebContents()->GetURL();
720 716
721 for (size_t i = 0; i < page_action_views_.size(); i++) { 717 for (size_t i = 0; i < page_action_views_.size(); i++) {
722 page_action_views_[i]->Update( 718 page_action_views_[i]->UpdateVisibility(
723 toolbar_model_->input_in_progress() ? NULL : contents, url); 719 toolbar_model_->input_in_progress() ? NULL : contents, url);
724 } 720 }
725 } 721 }
726 722
727 // If there are no visible page actions, hide the hbox too, so that it does 723 // If there are no visible page actions, hide the hbox too, so that it does
728 // not affect the padding in the location bar. 724 // not affect the padding in the location bar.
729 gtk_widget_set_visible(page_action_hbox_.get(), 725 gtk_widget_set_visible(page_action_hbox_.get(),
730 PageActionVisibleCount() && !ShouldOnlyShowLocation()); 726 PageActionVisibleCount() && !ShouldOnlyShowLocation());
731 } 727 }
732 728
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { 771 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) {
776 if (index >= page_action_views_.size()) { 772 if (index >= page_action_views_.size()) {
777 NOTREACHED(); 773 NOTREACHED();
778 return NULL; 774 return NULL;
779 } 775 }
780 776
781 return page_action_views_[index]->page_action(); 777 return page_action_views_[index]->page_action();
782 } 778 }
783 779
784 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { 780 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) {
785 return page_action_views_[index]->page_action(); 781 size_t visible_index = 0;
782 for (size_t i = 0; i < page_action_views_.size(); ++i) {
783 if (page_action_views_[i]->IsVisible()) {
784 if (index == visible_index++)
785 return page_action_views_[i]->page_action();
786 }
787 }
788
789 NOTREACHED();
790 return NULL;
786 } 791 }
787 792
788 void LocationBarViewGtk::TestPageActionPressed(size_t index) { 793 void LocationBarViewGtk::TestPageActionPressed(size_t index) {
789 if (index >= page_action_views_.size()) { 794 if (index >= page_action_views_.size()) {
790 NOTREACHED(); 795 NOTREACHED();
791 return; 796 return;
792 } 797 }
793 798
794 page_action_views_[index]->TestActivatePageAction(); 799 page_action_views_[index]->TestActivatePageAction();
795 } 800 }
796 801
797 void LocationBarViewGtk::Observe(int type, 802 void LocationBarViewGtk::Observe(int type,
798 const content::NotificationSource& source, 803 const content::NotificationSource& source,
799 const content::NotificationDetails& details) { 804 const content::NotificationDetails& details) {
800 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 805 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
801 UpdateStarIcon(); 806 UpdateStarIcon();
802 UpdateChromeToMobileIcon(); 807 UpdateChromeToMobileIcon();
803 return; 808 return;
804 } 809 }
805 810
806 if (type == chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED) {
807 // Only update if the updated action box was for the active tab contents.
808 TabContentsWrapper* target_tab =
809 content::Details<TabContentsWrapper>(details).ptr();
810 if (target_tab == GetTabContentsWrapper())
811 UpdatePageActions();
812 return;
813 }
814
815 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); 811 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED);
816 812
817 if (theme_service_->UsingNativeTheme()) { 813 if (theme_service_->UsingNativeTheme()) {
818 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); 814 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL);
819 815
820 GdkColor border_color = theme_service_->GetGdkColor( 816 GdkColor border_color = theme_service_->GetGdkColor(
821 ThemeService::COLOR_FRAME); 817 ThemeService::COLOR_FRAME);
822 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); 818 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color);
823 819
824 gtk_util::UndoForceFontSize(security_info_label_); 820 gtk_util::UndoForceFontSize(security_info_label_);
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 1496
1501 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( 1497 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
1502 LocationBarViewGtk* owner, 1498 LocationBarViewGtk* owner,
1503 ExtensionAction* page_action) 1499 ExtensionAction* page_action)
1504 : owner_(NULL), 1500 : owner_(NULL),
1505 page_action_(page_action), 1501 page_action_(page_action),
1506 last_icon_pixbuf_(NULL), 1502 last_icon_pixbuf_(NULL),
1507 tracker_(this), 1503 tracker_(this),
1508 current_tab_id_(-1), 1504 current_tab_id_(-1),
1509 window_(NULL), 1505 window_(NULL),
1510 accel_group_(NULL) { 1506 accel_group_(NULL),
1507 preview_enabled_(false) {
1511 event_box_.Own(gtk_event_box_new()); 1508 event_box_.Own(gtk_event_box_new());
1512 gtk_widget_set_size_request(event_box_.get(), 1509 gtk_widget_set_size_request(event_box_.get(),
1513 Extension::kPageActionIconMaxSize, 1510 Extension::kPageActionIconMaxSize,
1514 Extension::kPageActionIconMaxSize); 1511 Extension::kPageActionIconMaxSize);
1515 1512
1516 // Make the event box not visible so it does not paint a background. 1513 // Make the event box not visible so it does not paint a background.
1517 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); 1514 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
1518 g_signal_connect(event_box_.get(), "button-press-event", 1515 g_signal_connect(event_box_.get(), "button-press-event",
1519 G_CALLBACK(&OnButtonPressedThunk), this); 1516 G_CALLBACK(&OnButtonPressedThunk), this);
1520 g_signal_connect_after(event_box_.get(), "expose-event", 1517 g_signal_connect_after(event_box_.get(), "expose-event",
1521 G_CALLBACK(OnExposeEventThunk), this); 1518 G_CALLBACK(OnExposeEventThunk), this);
1522 g_signal_connect(event_box_.get(), "realize", 1519 g_signal_connect(event_box_.get(), "realize",
1523 G_CALLBACK(OnRealizeThunk), this); 1520 G_CALLBACK(OnRealizeThunk), this);
1524 1521
1525 image_.Own(gtk_image_new()); 1522 image_.Own(gtk_image_new());
1526 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); 1523 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get());
1527 gtk_widget_show_all(event_box_.get());
1528 1524
1529 const Extension* extension = owner->browser()->profile()-> 1525 const Extension* extension = owner->browser()->profile()->
1530 GetExtensionService()->GetExtensionById(page_action->extension_id(), 1526 GetExtensionService()->GetExtensionById(page_action->extension_id(),
1531 false); 1527 false);
1532 DCHECK(extension); 1528 DCHECK(extension);
1533 1529
1534 // Load all the icons declared in the manifest. This is the contents of the 1530 // Load all the icons declared in the manifest. This is the contents of the
1535 // icons array, plus the default_icon property, if any. 1531 // icons array, plus the default_icon property, if any.
1536 std::vector<std::string> icon_paths(*page_action->icon_paths()); 1532 std::vector<std::string> icon_paths(*page_action->icon_paths());
1537 if (!page_action_->default_icon_path().empty()) 1533 if (!page_action_->default_icon_path().empty())
(...skipping 18 matching lines...) Expand all
1556 image_.Destroy(); 1552 image_.Destroy();
1557 event_box_.Destroy(); 1553 event_box_.Destroy();
1558 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); 1554 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end();
1559 ++iter) { 1555 ++iter) {
1560 g_object_unref(iter->second); 1556 g_object_unref(iter->second);
1561 } 1557 }
1562 if (last_icon_pixbuf_) 1558 if (last_icon_pixbuf_)
1563 g_object_unref(last_icon_pixbuf_); 1559 g_object_unref(last_icon_pixbuf_);
1564 } 1560 }
1565 1561
1566 void LocationBarViewGtk::PageActionViewGtk::Update( 1562 bool LocationBarViewGtk::PageActionViewGtk::IsVisible() {
1563 return gtk_widget_get_visible(widget());
1564 }
1565
1566 void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility(
1567 WebContents* contents, const GURL& url) { 1567 WebContents* contents, const GURL& url) {
1568 // Save this off so we can pass it back to the extension when the action gets 1568 // Save this off so we can pass it back to the extension when the action gets
1569 // executed. See PageActionImageView::OnMousePressed. 1569 // executed. See PageActionImageView::OnMousePressed.
1570 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1; 1570 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1;
1571 current_url_ = url; 1571 current_url_ = url;
1572 1572
1573 // Set the tooltip. 1573 bool visible = contents &&
1574 gtk_widget_set_tooltip_text(event_box_.get(), 1574 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_));
1575 page_action_->GetTitle(current_tab_id_).c_str()); 1575 if (visible) {
1576 // Set the tooltip.
1577 gtk_widget_set_tooltip_text(event_box_.get(),
1578 page_action_->GetTitle(current_tab_id_).c_str());
1576 1579
1577 // Set the image. 1580 // Set the image.
1578 // It can come from three places. In descending order of priority: 1581 // It can come from three places. In descending order of priority:
1579 // - The developer can set it dynamically by path or bitmap. It will be in 1582 // - The developer can set it dynamically by path or bitmap. It will be in
1580 // page_action_->GetIcon(). 1583 // page_action_->GetIcon().
1581 // - The developer can set it dyanmically by index. It will be in 1584 // - The developer can set it dyanmically by index. It will be in
1582 // page_action_->GetIconIndex(). 1585 // page_action_->GetIconIndex().
1583 // - It can be set in the manifest by path. It will be in page_action_-> 1586 // - It can be set in the manifest by path. It will be in page_action_->
1584 // default_icon_path(). 1587 // default_icon_path().
1585 1588
1586 // First look for a dynamically set bitmap. 1589 // First look for a dynamically set bitmap.
1587 SkBitmap icon = page_action_->GetIcon(current_tab_id_); 1590 SkBitmap icon = page_action_->GetIcon(current_tab_id_);
1588 GdkPixbuf* pixbuf = NULL; 1591 GdkPixbuf* pixbuf = NULL;
1589 1592 if (!icon.isNull()) {
1590 if (!icon.isNull()) { 1593 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) {
1591 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { 1594 if (last_icon_pixbuf_)
1592 if (last_icon_pixbuf_) 1595 g_object_unref(last_icon_pixbuf_);
1593 g_object_unref(last_icon_pixbuf_); 1596 last_icon_skbitmap_ = icon;
1594 last_icon_skbitmap_ = icon; 1597 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&icon);
1595 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&icon); 1598 }
1599 DCHECK(last_icon_pixbuf_);
1600 pixbuf = last_icon_pixbuf_;
1601 } else {
1602 // Otherwise look for a dynamically set index, or fall back to the
1603 // default path.
1604 int icon_index = page_action_->GetIconIndex(current_tab_id_);
1605 std::string icon_path = (icon_index < 0) ?
1606 page_action_->default_icon_path() :
1607 page_action_->icon_paths()->at(icon_index);
1608 if (!icon_path.empty()) {
1609 PixbufMap::iterator iter = pixbufs_.find(icon_path);
1610 if (iter != pixbufs_.end())
1611 pixbuf = iter->second;
1612 }
1596 } 1613 }
1597 DCHECK(last_icon_pixbuf_); 1614 // The pixbuf might not be loaded yet.
1598 pixbuf = last_icon_pixbuf_; 1615 if (pixbuf)
1599 } else { 1616 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf);
1600 // Otherwise look for a dynamically set index, or fall back to the
1601 // default path.
1602 int icon_index = page_action_->GetIconIndex(current_tab_id_);
1603 std::string icon_path = icon_index < 0 ?
1604 page_action_->default_icon_path() :
1605 page_action_->icon_paths()->at(icon_index);
1606 if (!icon_path.empty()) {
1607 PixbufMap::iterator iter = pixbufs_.find(icon_path);
1608 if (iter != pixbufs_.end())
1609 pixbuf = iter->second;
1610 }
1611 } 1617 }
1612 1618
1613 // The pixbuf might not be loaded yet. 1619 bool old_visible = IsVisible();
1614 if (pixbuf) 1620 if (visible)
1615 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); 1621 gtk_widget_show_all(event_box_.get());
1622 else
1623 gtk_widget_hide_all(event_box_.get());
1624
1625 if (visible != old_visible) {
1626 content::NotificationService::current()->Notify(
1627 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
1628 content::Source<ExtensionAction>(page_action_),
1629 content::Details<WebContents>(contents));
1630 }
1616 } 1631 }
1617 1632
1618 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( 1633 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded(
1619 const gfx::Image& image, 1634 const gfx::Image& image,
1620 const std::string& extension_id, 1635 const std::string& extension_id,
1621 int index) { 1636 int index) {
1622 // We loaded icons()->size() icons, plus one extra if the page action had 1637 // We loaded icons()->size() icons, plus one extra if the page action had
1623 // a default icon. 1638 // a default icon.
1624 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); 1639 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
1625 if (!page_action_->default_icon_path().empty()) 1640 if (!page_action_->default_icon_path().empty())
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 owner_->browser()->profile()->GetExtensionService(); 1741 owner_->browser()->profile()->GetExtensionService();
1727 if (!extension_service) 1742 if (!extension_service)
1728 return TRUE; 1743 return TRUE;
1729 1744
1730 const Extension* extension = 1745 const Extension* extension =
1731 extension_service->extensions()->GetByID(page_action()->extension_id()); 1746 extension_service->extensions()->GetByID(page_action()->extension_id());
1732 if (!extension) 1747 if (!extension)
1733 return TRUE; 1748 return TRUE;
1734 1749
1735 ActionBoxController* controller = 1750 ActionBoxController* controller =
1736 tab_contents->extension_tab_helper()->action_box_controller(); 1751 tab_contents->extension_action_box_controller();
1737 1752
1738 switch (controller->OnClicked(extension->id(), event->button)) { 1753 switch (controller->OnClicked(extension->id(), event->button)) {
1739 case ActionBoxController::ACTION_NONE: 1754 case ActionBoxController::ACTION_NONE:
1740 break; 1755 break;
1741 1756
1742 case ActionBoxController::ACTION_SHOW_POPUP: 1757 case ActionBoxController::ACTION_SHOW_POPUP:
1743 ExtensionPopupGtk::Show( 1758 ExtensionPopupGtk::Show(
1744 page_action_->GetPopupUrl(current_tab_id_), 1759 page_action_->GetPopupUrl(current_tab_id_),
1745 owner_->browser_, 1760 owner_->browser_,
1746 event_box_.get()); 1761 event_box_.get());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 GdkModifierType modifier, 1808 GdkModifierType modifier,
1794 void* user_data) { 1809 void* user_data) {
1795 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); 1810 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data);
1796 if (!gtk_widget_get_visible(view->widget())) 1811 if (!gtk_widget_get_visible(view->widget()))
1797 return FALSE; 1812 return FALSE;
1798 1813
1799 GdkEventButton event = {}; 1814 GdkEventButton event = {};
1800 event.button = 1; 1815 event.button = 1;
1801 return view->OnButtonPressed(view->widget(), &event); 1816 return view->OnButtonPressed(view->widget(), &event);
1802 } 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