| 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/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/action_box_controller.h" |
| 27 #include "chrome/browser/extensions/api/commands/command_service.h" | 28 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 28 #include "chrome/browser/extensions/api/commands/command_service_factory.h" | 29 #include "chrome/browser/extensions/api/commands/command_service_factory.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_helper.h" |
| 32 #include "chrome/browser/extensions/extension_tab_util.h" | 33 #include "chrome/browser/extensions/extension_tab_util.h" |
| 33 #include "chrome/browser/favicon/favicon_tab_helper.h" | 34 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 34 #include "chrome/browser/instant/instant_controller.h" | 35 #include "chrome/browser/instant/instant_controller.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/search_engines/template_url.h" | 37 #include "chrome/browser/search_engines/template_url.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // |security_info_label_|. | 354 // |security_info_label_|. |
| 354 g_signal_connect(hbox_.get(), "size-allocate", | 355 g_signal_connect(hbox_.get(), "size-allocate", |
| 355 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 356 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
| 356 | 357 |
| 357 registrar_.Add(this, | 358 registrar_.Add(this, |
| 358 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 359 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 359 content::Source<ThemeService>(theme_service_)); | 360 content::Source<ThemeService>(theme_service_)); |
| 360 registrar_.Add(this, | 361 registrar_.Add(this, |
| 361 chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED, | 362 chrome::NOTIFICATION_EXTENSION_ACTION_BOX_UPDATED, |
| 362 content::Source<Profile>(browser()->profile())); | 363 content::Source<Profile>(browser()->profile())); |
| 363 | |
| 364 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, | 364 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, |
| 365 profile->GetPrefs(), this); | 365 profile->GetPrefs(), this); |
| 366 | 366 |
| 367 theme_service_->InitThemesFor(this); | 367 theme_service_->InitThemesFor(this); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void LocationBarViewGtk::BuildSiteTypeArea() { | 370 void LocationBarViewGtk::BuildSiteTypeArea() { |
| 371 location_icon_image_ = gtk_image_new(); | 371 location_icon_image_ = gtk_image_new(); |
| 372 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); | 372 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); |
| 373 | 373 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 442 } |
| 443 | 443 |
| 444 WebContents* LocationBarViewGtk::GetWebContents() const { | 444 WebContents* LocationBarViewGtk::GetWebContents() const { |
| 445 return browser_->GetSelectedWebContents(); | 445 return browser_->GetSelectedWebContents(); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void LocationBarViewGtk::SetPreviewEnabledPageAction( | 448 void LocationBarViewGtk::SetPreviewEnabledPageAction( |
| 449 ExtensionAction *page_action, | 449 ExtensionAction *page_action, |
| 450 bool preview_enabled) { | 450 bool preview_enabled) { |
| 451 DCHECK(page_action); | 451 DCHECK(page_action); |
| 452 if (preview_enabled && preview_enabled_actions_.insert(page_action).second) | 452 UpdatePageActions(); |
| 453 UpdatePageActions(); | 453 for (ScopedVector<PageActionViewGtk>::iterator iter = |
| 454 if (!preview_enabled && preview_enabled_actions_.erase(page_action) > 0) | 454 page_action_views_.begin(); iter != page_action_views_.end(); |
| 455 UpdatePageActions(); | 455 ++iter) { |
| 456 if ((*iter)->page_action() == page_action) { |
| 457 (*iter)->set_preview_enabled(preview_enabled); |
| 458 UpdatePageActions(); |
| 459 return; |
| 460 } |
| 461 } |
| 456 } | 462 } |
| 457 | 463 |
| 458 GtkWidget* LocationBarViewGtk::GetPageActionWidget( | 464 GtkWidget* LocationBarViewGtk::GetPageActionWidget( |
| 459 ExtensionAction *page_action) { | 465 ExtensionAction *page_action) { |
| 460 DCHECK(page_action); | 466 DCHECK(page_action); |
| 461 for (ScopedVector<PageActionViewGtk>::iterator iter = | 467 for (ScopedVector<PageActionViewGtk>::iterator iter = |
| 462 page_action_views_.begin(); | 468 page_action_views_.begin(); |
| 463 iter != page_action_views_.end(); | 469 iter != page_action_views_.end(); |
| 464 ++iter) { | 470 ++iter) { |
| 465 if ((*iter)->page_action() == page_action) | 471 if ((*iter)->page_action() == page_action) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 void LocationBarViewGtk::UpdatePageActions() { | 692 void LocationBarViewGtk::UpdatePageActions() { |
| 687 std::vector<ExtensionAction*> page_actions; | 693 std::vector<ExtensionAction*> page_actions; |
| 688 | 694 |
| 689 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); | 695 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); |
| 690 if (tab_contents) { | 696 if (tab_contents) { |
| 691 ActionBoxController* controller = | 697 ActionBoxController* controller = |
| 692 tab_contents->extension_tab_helper()->action_box_controller(); | 698 tab_contents->extension_tab_helper()->action_box_controller(); |
| 693 page_actions.swap(*controller->GetCurrentActions()); | 699 page_actions.swap(*controller->GetCurrentActions()); |
| 694 } | 700 } |
| 695 | 701 |
| 696 // Add page actions for any extensions which have "preview enabled" and not | |
| 697 // already visible. | |
| 698 ActionBoxController::AddMissingActions( | |
| 699 preview_enabled_actions_, &page_actions); | |
| 700 | |
| 701 // Initialize on the first call, or re-inialize if more extensions have been | 702 // Initialize on the first call, or re-inialize if more extensions have been |
| 702 // loaded or added after startup. | 703 // loaded or added after startup. |
| 703 if (page_actions.size() != page_action_views_.size()) { | 704 if (page_actions.size() != page_action_views_.size()) { |
| 704 page_action_views_.reset(); // Delete the old views (if any). | 705 page_action_views_.reset(); // Delete the old views (if any). |
| 705 | 706 |
| 706 for (size_t i = 0; i < page_actions.size(); ++i) { | 707 for (size_t i = 0; i < page_actions.size(); ++i) { |
| 707 page_action_views_.push_back( | 708 page_action_views_.push_back( |
| 708 new PageActionViewGtk(this, page_actions[i])); | 709 new PageActionViewGtk(this, page_actions[i])); |
| 709 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), | 710 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), |
| 710 page_action_views_[i]->widget(), FALSE, FALSE, 0); | 711 page_action_views_[i]->widget(), FALSE, FALSE, 0); |
| 711 } | 712 } |
| 712 content::NotificationService::current()->Notify( | 713 content::NotificationService::current()->Notify( |
| 713 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 714 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
| 714 content::Source<LocationBar>(this), | 715 content::Source<LocationBar>(this), |
| 715 content::NotificationService::NoDetails()); | 716 content::NotificationService::NoDetails()); |
| 716 } | 717 } |
| 717 | 718 |
| 718 WebContents* contents = GetWebContents(); | 719 WebContents* contents = GetWebContents(); |
| 719 if (!page_action_views_.empty() && contents) { | 720 if (!page_action_views_.empty() && contents) { |
| 720 GURL url = browser()->GetSelectedWebContents()->GetURL(); | 721 GURL url = browser()->GetSelectedWebContents()->GetURL(); |
| 721 | 722 |
| 722 for (size_t i = 0; i < page_action_views_.size(); i++) { | 723 for (size_t i = 0; i < page_action_views_.size(); i++) { |
| 723 page_action_views_[i]->Update( | 724 page_action_views_[i]->UpdateVisibility( |
| 724 toolbar_model_->input_in_progress() ? NULL : contents, url); | 725 toolbar_model_->input_in_progress() ? NULL : contents, url); |
| 725 } | 726 } |
| 726 } | 727 } |
| 727 | 728 |
| 728 // If there are no visible page actions, hide the hbox too, so that it does | 729 // If there are no visible page actions, hide the hbox too, so that it does |
| 729 // not affect the padding in the location bar. | 730 // not affect the padding in the location bar. |
| 730 gtk_widget_set_visible(page_action_hbox_.get(), | 731 gtk_widget_set_visible(page_action_hbox_.get(), |
| 731 PageActionVisibleCount() && !ShouldOnlyShowLocation()); | 732 PageActionVisibleCount() && !ShouldOnlyShowLocation()); |
| 732 } | 733 } |
| 733 | 734 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { | 777 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { |
| 777 if (index >= page_action_views_.size()) { | 778 if (index >= page_action_views_.size()) { |
| 778 NOTREACHED(); | 779 NOTREACHED(); |
| 779 return NULL; | 780 return NULL; |
| 780 } | 781 } |
| 781 | 782 |
| 782 return page_action_views_[index]->page_action(); | 783 return page_action_views_[index]->page_action(); |
| 783 } | 784 } |
| 784 | 785 |
| 785 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { | 786 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { |
| 786 return page_action_views_[index]->page_action(); | 787 size_t visible_index = 0; |
| 788 for (size_t i = 0; i < page_action_views_.size(); ++i) { |
| 789 if (page_action_views_[i]->IsVisible()) { |
| 790 if (index == visible_index++) |
| 791 return page_action_views_[i]->page_action(); |
| 792 } |
| 793 } |
| 794 |
| 795 NOTREACHED(); |
| 796 return NULL; |
| 787 } | 797 } |
| 788 | 798 |
| 789 void LocationBarViewGtk::TestPageActionPressed(size_t index) { | 799 void LocationBarViewGtk::TestPageActionPressed(size_t index) { |
| 790 if (index >= page_action_views_.size()) { | 800 if (index >= page_action_views_.size()) { |
| 791 NOTREACHED(); | 801 NOTREACHED(); |
| 792 return; | 802 return; |
| 793 } | 803 } |
| 794 | 804 |
| 795 page_action_views_[index]->TestActivatePageAction(); | 805 page_action_views_[index]->TestActivatePageAction(); |
| 796 } | 806 } |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 | 1511 |
| 1502 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1512 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
| 1503 LocationBarViewGtk* owner, | 1513 LocationBarViewGtk* owner, |
| 1504 ExtensionAction* page_action) | 1514 ExtensionAction* page_action) |
| 1505 : owner_(NULL), | 1515 : owner_(NULL), |
| 1506 page_action_(page_action), | 1516 page_action_(page_action), |
| 1507 last_icon_pixbuf_(NULL), | 1517 last_icon_pixbuf_(NULL), |
| 1508 tracker_(this), | 1518 tracker_(this), |
| 1509 current_tab_id_(-1), | 1519 current_tab_id_(-1), |
| 1510 window_(NULL), | 1520 window_(NULL), |
| 1511 accel_group_(NULL) { | 1521 accel_group_(NULL), |
| 1522 preview_enabled_(false) { |
| 1512 event_box_.Own(gtk_event_box_new()); | 1523 event_box_.Own(gtk_event_box_new()); |
| 1513 gtk_widget_set_size_request(event_box_.get(), | 1524 gtk_widget_set_size_request(event_box_.get(), |
| 1514 Extension::kPageActionIconMaxSize, | 1525 Extension::kPageActionIconMaxSize, |
| 1515 Extension::kPageActionIconMaxSize); | 1526 Extension::kPageActionIconMaxSize); |
| 1516 | 1527 |
| 1517 // Make the event box not visible so it does not paint a background. | 1528 // Make the event box not visible so it does not paint a background. |
| 1518 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1529 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
| 1519 g_signal_connect(event_box_.get(), "button-press-event", | 1530 g_signal_connect(event_box_.get(), "button-press-event", |
| 1520 G_CALLBACK(&OnButtonPressedThunk), this); | 1531 G_CALLBACK(&OnButtonPressedThunk), this); |
| 1521 g_signal_connect_after(event_box_.get(), "expose-event", | 1532 g_signal_connect_after(event_box_.get(), "expose-event", |
| 1522 G_CALLBACK(OnExposeEventThunk), this); | 1533 G_CALLBACK(OnExposeEventThunk), this); |
| 1523 g_signal_connect(event_box_.get(), "realize", | 1534 g_signal_connect(event_box_.get(), "realize", |
| 1524 G_CALLBACK(OnRealizeThunk), this); | 1535 G_CALLBACK(OnRealizeThunk), this); |
| 1525 | 1536 |
| 1526 image_.Own(gtk_image_new()); | 1537 image_.Own(gtk_image_new()); |
| 1527 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1538 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
| 1528 gtk_widget_show_all(event_box_.get()); | |
| 1529 | 1539 |
| 1530 const Extension* extension = owner->browser()->profile()-> | 1540 const Extension* extension = owner->browser()->profile()-> |
| 1531 GetExtensionService()->GetExtensionById(page_action->extension_id(), | 1541 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
| 1532 false); | 1542 false); |
| 1533 DCHECK(extension); | 1543 DCHECK(extension); |
| 1534 | 1544 |
| 1535 // Load all the icons declared in the manifest. This is the contents of the | 1545 // Load all the icons declared in the manifest. This is the contents of the |
| 1536 // icons array, plus the default_icon property, if any. | 1546 // icons array, plus the default_icon property, if any. |
| 1537 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1547 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
| 1538 if (!page_action_->default_icon_path().empty()) | 1548 if (!page_action_->default_icon_path().empty()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1557 image_.Destroy(); | 1567 image_.Destroy(); |
| 1558 event_box_.Destroy(); | 1568 event_box_.Destroy(); |
| 1559 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); | 1569 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); |
| 1560 ++iter) { | 1570 ++iter) { |
| 1561 g_object_unref(iter->second); | 1571 g_object_unref(iter->second); |
| 1562 } | 1572 } |
| 1563 if (last_icon_pixbuf_) | 1573 if (last_icon_pixbuf_) |
| 1564 g_object_unref(last_icon_pixbuf_); | 1574 g_object_unref(last_icon_pixbuf_); |
| 1565 } | 1575 } |
| 1566 | 1576 |
| 1567 void LocationBarViewGtk::PageActionViewGtk::Update( | 1577 bool LocationBarViewGtk::PageActionViewGtk::IsVisible() { |
| 1578 return gtk_widget_get_visible(widget()); |
| 1579 } |
| 1580 |
| 1581 void LocationBarViewGtk::PageActionViewGtk::UpdateVisibility( |
| 1568 WebContents* contents, const GURL& url) { | 1582 WebContents* contents, const GURL& url) { |
| 1569 // Save this off so we can pass it back to the extension when the action gets | 1583 // Save this off so we can pass it back to the extension when the action gets |
| 1570 // executed. See PageActionImageView::OnMousePressed. | 1584 // executed. See PageActionImageView::OnMousePressed. |
| 1571 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1; | 1585 current_tab_id_ = contents ? ExtensionTabUtil::GetTabId(contents) : -1; |
| 1572 current_url_ = url; | 1586 current_url_ = url; |
| 1573 | 1587 |
| 1574 // Set the tooltip. | 1588 bool visible = contents && |
| 1575 gtk_widget_set_tooltip_text(event_box_.get(), | 1589 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); |
| 1576 page_action_->GetTitle(current_tab_id_).c_str()); | 1590 if (visible) { |
| 1591 // Set the tooltip. |
| 1592 gtk_widget_set_tooltip_text(event_box_.get(), |
| 1593 page_action_->GetTitle(current_tab_id_).c_str()); |
| 1577 | 1594 |
| 1578 // Set the image. | 1595 // Set the image. |
| 1579 // It can come from three places. In descending order of priority: | 1596 // It can come from three places. In descending order of priority: |
| 1580 // - The developer can set it dynamically by path or bitmap. It will be in | 1597 // - The developer can set it dynamically by path or bitmap. It will be in |
| 1581 // page_action_->GetIcon(). | 1598 // page_action_->GetIcon(). |
| 1582 // - The developer can set it dyanmically by index. It will be in | 1599 // - The developer can set it dyanmically by index. It will be in |
| 1583 // page_action_->GetIconIndex(). | 1600 // page_action_->GetIconIndex(). |
| 1584 // - It can be set in the manifest by path. It will be in page_action_-> | 1601 // - It can be set in the manifest by path. It will be in page_action_-> |
| 1585 // default_icon_path(). | 1602 // default_icon_path(). |
| 1586 | 1603 |
| 1587 // First look for a dynamically set bitmap. | 1604 // First look for a dynamically set bitmap. |
| 1588 SkBitmap icon = page_action_->GetIcon(current_tab_id_); | 1605 SkBitmap icon = page_action_->GetIcon(current_tab_id_); |
| 1589 GdkPixbuf* pixbuf = NULL; | 1606 GdkPixbuf* pixbuf = NULL; |
| 1590 | 1607 if (!icon.isNull()) { |
| 1591 if (!icon.isNull()) { | 1608 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { |
| 1592 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { | 1609 if (last_icon_pixbuf_) |
| 1593 if (last_icon_pixbuf_) | 1610 g_object_unref(last_icon_pixbuf_); |
| 1594 g_object_unref(last_icon_pixbuf_); | 1611 last_icon_skbitmap_ = icon; |
| 1595 last_icon_skbitmap_ = icon; | 1612 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(icon); |
| 1596 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(icon); | 1613 } |
| 1614 DCHECK(last_icon_pixbuf_); |
| 1615 pixbuf = last_icon_pixbuf_; |
| 1616 } else { |
| 1617 // Otherwise look for a dynamically set index, or fall back to the |
| 1618 // default path. |
| 1619 int icon_index = page_action_->GetIconIndex(current_tab_id_); |
| 1620 std::string icon_path = (icon_index < 0) ? |
| 1621 page_action_->default_icon_path() : |
| 1622 page_action_->icon_paths()->at(icon_index); |
| 1623 if (!icon_path.empty()) { |
| 1624 PixbufMap::iterator iter = pixbufs_.find(icon_path); |
| 1625 if (iter != pixbufs_.end()) |
| 1626 pixbuf = iter->second; |
| 1627 } |
| 1597 } | 1628 } |
| 1598 DCHECK(last_icon_pixbuf_); | 1629 // The pixbuf might not be loaded yet. |
| 1599 pixbuf = last_icon_pixbuf_; | 1630 if (pixbuf) |
| 1600 } else { | 1631 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
| 1601 // Otherwise look for a dynamically set index, or fall back to the | |
| 1602 // default path. | |
| 1603 int icon_index = page_action_->GetIconIndex(current_tab_id_); | |
| 1604 std::string icon_path = icon_index < 0 ? | |
| 1605 page_action_->default_icon_path() : | |
| 1606 page_action_->icon_paths()->at(icon_index); | |
| 1607 if (!icon_path.empty()) { | |
| 1608 PixbufMap::iterator iter = pixbufs_.find(icon_path); | |
| 1609 if (iter != pixbufs_.end()) | |
| 1610 pixbuf = iter->second; | |
| 1611 } | |
| 1612 } | 1632 } |
| 1613 | 1633 |
| 1614 // The pixbuf might not be loaded yet. | 1634 bool old_visible = IsVisible(); |
| 1615 if (pixbuf) | 1635 if (visible) |
| 1616 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1636 gtk_widget_show_all(event_box_.get()); |
| 1637 else |
| 1638 gtk_widget_hide_all(event_box_.get()); |
| 1639 |
| 1640 if (visible != old_visible) { |
| 1641 content::NotificationService::current()->Notify( |
| 1642 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 1643 content::Source<ExtensionAction>(page_action_), |
| 1644 content::Details<WebContents>(contents)); |
| 1645 } |
| 1617 } | 1646 } |
| 1618 | 1647 |
| 1619 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1648 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
| 1620 const gfx::Image& image, | 1649 const gfx::Image& image, |
| 1621 const std::string& extension_id, | 1650 const std::string& extension_id, |
| 1622 int index) { | 1651 int index) { |
| 1623 // We loaded icons()->size() icons, plus one extra if the page action had | 1652 // We loaded icons()->size() icons, plus one extra if the page action had |
| 1624 // a default icon. | 1653 // a default icon. |
| 1625 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 1654 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
| 1626 if (!page_action_->default_icon_path().empty()) | 1655 if (!page_action_->default_icon_path().empty()) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 GdkModifierType modifier, | 1825 GdkModifierType modifier, |
| 1797 void* user_data) { | 1826 void* user_data) { |
| 1798 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); | 1827 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); |
| 1799 if (!gtk_widget_get_visible(view->widget())) | 1828 if (!gtk_widget_get_visible(view->widget())) |
| 1800 return FALSE; | 1829 return FALSE; |
| 1801 | 1830 |
| 1802 GdkEventButton event = {}; | 1831 GdkEventButton event = {}; |
| 1803 event.button = 1; | 1832 event.button = 1; |
| 1804 return view->OnButtonPressed(view->widget(), &event); | 1833 return view->OnButtonPressed(view->widget(), &event); |
| 1805 } | 1834 } |
| OLD | NEW |