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/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" | |
30 #include "chrome/browser/extensions/extension_browser_event_router.h" | 29 #include "chrome/browser/extensions/extension_browser_event_router.h" |
31 #include "chrome/browser/extensions/extension_service.h" | 30 #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 Loading... |
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 |
359 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, | 363 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, |
360 profile->GetPrefs(), this); | 364 profile->GetPrefs(), this); |
361 | 365 |
362 theme_service_->InitThemesFor(this); | 366 theme_service_->InitThemesFor(this); |
363 } | 367 } |
364 | 368 |
365 void LocationBarViewGtk::BuildSiteTypeArea() { | 369 void LocationBarViewGtk::BuildSiteTypeArea() { |
366 location_icon_image_ = gtk_image_new(); | 370 location_icon_image_ = gtk_image_new(); |
367 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); | 371 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); |
368 | 372 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 441 } |
438 | 442 |
439 WebContents* LocationBarViewGtk::GetWebContents() const { | 443 WebContents* LocationBarViewGtk::GetWebContents() const { |
440 return browser_->GetSelectedWebContents(); | 444 return browser_->GetSelectedWebContents(); |
441 } | 445 } |
442 | 446 |
443 void LocationBarViewGtk::SetPreviewEnabledPageAction( | 447 void LocationBarViewGtk::SetPreviewEnabledPageAction( |
444 ExtensionAction *page_action, | 448 ExtensionAction *page_action, |
445 bool preview_enabled) { | 449 bool preview_enabled) { |
446 DCHECK(page_action); | 450 DCHECK(page_action); |
447 UpdatePageActions(); | 451 if (preview_enabled && preview_enabled_actions_.insert(page_action).second) |
448 for (ScopedVector<PageActionViewGtk>::iterator iter = | 452 UpdatePageActions(); |
449 page_action_views_.begin(); iter != page_action_views_.end(); | 453 if (!preview_enabled && preview_enabled_actions_.erase(page_action) > 0) |
450 ++iter) { | 454 UpdatePageActions(); |
451 if ((*iter)->page_action() == page_action) { | |
452 (*iter)->set_preview_enabled(preview_enabled); | |
453 UpdatePageActions(); | |
454 return; | |
455 } | |
456 } | |
457 } | 455 } |
458 | 456 |
459 GtkWidget* LocationBarViewGtk::GetPageActionWidget( | 457 GtkWidget* LocationBarViewGtk::GetPageActionWidget( |
460 ExtensionAction *page_action) { | 458 ExtensionAction *page_action) { |
461 DCHECK(page_action); | 459 DCHECK(page_action); |
462 for (ScopedVector<PageActionViewGtk>::iterator iter = | 460 for (ScopedVector<PageActionViewGtk>::iterator iter = |
463 page_action_views_.begin(); | 461 page_action_views_.begin(); |
464 iter != page_action_views_.end(); | 462 iter != page_action_views_.end(); |
465 ++iter) { | 463 ++iter) { |
466 if ((*iter)->page_action() == page_action) | 464 if ((*iter)->page_action() == page_action) |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 toolbar_model_->input_in_progress() ? NULL : web_contents); | 676 toolbar_model_->input_in_progress() ? NULL : web_contents); |
679 any_visible = (*i)->IsVisible() || any_visible; | 677 any_visible = (*i)->IsVisible() || any_visible; |
680 } | 678 } |
681 | 679 |
682 // If there are no visible content things, hide the top level box so it | 680 // If there are no visible content things, hide the top level box so it |
683 // doesn't mess with padding. | 681 // doesn't mess with padding. |
684 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); | 682 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); |
685 } | 683 } |
686 | 684 |
687 void LocationBarViewGtk::UpdatePageActions() { | 685 void LocationBarViewGtk::UpdatePageActions() { |
688 ActionBoxController::DataList page_actions; | 686 std::vector<ExtensionAction*> page_actions; |
689 | 687 |
690 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); | 688 TabContentsWrapper* tab_contents = GetTabContentsWrapper(); |
691 if (tab_contents) { | 689 if (tab_contents) { |
692 page_actions.swap( | 690 ActionBoxController* controller = |
693 *tab_contents->extension_action_box_controller()->GetAllBadgeData()); | 691 tab_contents->extension_tab_helper()->action_box_controller(); |
| 692 page_actions.swap(*controller->GetCurrentActions()); |
694 } | 693 } |
695 | 694 |
| 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 |
696 // Initialize on the first call, or re-inialize if more extensions have been | 700 // Initialize on the first call, or re-inialize if more extensions have been |
697 // loaded or added after startup. | 701 // loaded or added after startup. |
698 if (page_actions.size() != page_action_views_.size()) { | 702 if (page_actions.size() != page_action_views_.size()) { |
699 page_action_views_.reset(); // Delete the old views (if any). | 703 page_action_views_.reset(); // Delete the old views (if any). |
700 | 704 |
701 for (size_t i = 0; i < page_actions.size(); ++i) { | 705 for (size_t i = 0; i < page_actions.size(); ++i) { |
702 page_action_views_.push_back( | 706 page_action_views_.push_back( |
703 new PageActionViewGtk(this, page_actions[i].action)); | 707 new PageActionViewGtk(this, page_actions[i])); |
704 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), | 708 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), |
705 page_action_views_[i]->widget(), FALSE, FALSE, 0); | 709 page_action_views_[i]->widget(), FALSE, FALSE, 0); |
706 } | 710 } |
707 content::NotificationService::current()->Notify( | 711 content::NotificationService::current()->Notify( |
708 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 712 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
709 content::Source<LocationBar>(this), | 713 content::Source<LocationBar>(this), |
710 content::NotificationService::NoDetails()); | 714 content::NotificationService::NoDetails()); |
711 } | 715 } |
712 | 716 |
713 WebContents* contents = GetWebContents(); | 717 WebContents* contents = GetWebContents(); |
714 if (!page_action_views_.empty() && contents) { | 718 if (!page_action_views_.empty() && contents) { |
715 GURL url = browser()->GetSelectedWebContents()->GetURL(); | 719 GURL url = browser()->GetSelectedWebContents()->GetURL(); |
716 | 720 |
717 for (size_t i = 0; i < page_action_views_.size(); i++) { | 721 for (size_t i = 0; i < page_action_views_.size(); i++) { |
718 page_action_views_[i]->UpdateVisibility( | 722 page_action_views_[i]->Update( |
719 toolbar_model_->input_in_progress() ? NULL : contents, url); | 723 toolbar_model_->input_in_progress() ? NULL : contents, url); |
720 } | 724 } |
721 } | 725 } |
722 | 726 |
723 // If there are no visible page actions, hide the hbox too, so that it does | 727 // If there are no visible page actions, hide the hbox too, so that it does |
724 // not affect the padding in the location bar. | 728 // not affect the padding in the location bar. |
725 gtk_widget_set_visible(page_action_hbox_.get(), | 729 gtk_widget_set_visible(page_action_hbox_.get(), |
726 PageActionVisibleCount() && !ShouldOnlyShowLocation()); | 730 PageActionVisibleCount() && !ShouldOnlyShowLocation()); |
727 } | 731 } |
728 | 732 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { | 775 ExtensionAction* LocationBarViewGtk::GetPageAction(size_t index) { |
772 if (index >= page_action_views_.size()) { | 776 if (index >= page_action_views_.size()) { |
773 NOTREACHED(); | 777 NOTREACHED(); |
774 return NULL; | 778 return NULL; |
775 } | 779 } |
776 | 780 |
777 return page_action_views_[index]->page_action(); | 781 return page_action_views_[index]->page_action(); |
778 } | 782 } |
779 | 783 |
780 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { | 784 ExtensionAction* LocationBarViewGtk::GetVisiblePageAction(size_t index) { |
781 size_t visible_index = 0; | 785 return page_action_views_[index]->page_action(); |
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; | |
791 } | 786 } |
792 | 787 |
793 void LocationBarViewGtk::TestPageActionPressed(size_t index) { | 788 void LocationBarViewGtk::TestPageActionPressed(size_t index) { |
794 if (index >= page_action_views_.size()) { | 789 if (index >= page_action_views_.size()) { |
795 NOTREACHED(); | 790 NOTREACHED(); |
796 return; | 791 return; |
797 } | 792 } |
798 | 793 |
799 page_action_views_[index]->TestActivatePageAction(); | 794 page_action_views_[index]->TestActivatePageAction(); |
800 } | 795 } |
801 | 796 |
802 void LocationBarViewGtk::Observe(int type, | 797 void LocationBarViewGtk::Observe(int type, |
803 const content::NotificationSource& source, | 798 const content::NotificationSource& source, |
804 const content::NotificationDetails& details) { | 799 const content::NotificationDetails& details) { |
805 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 800 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
806 UpdateStarIcon(); | 801 UpdateStarIcon(); |
807 UpdateChromeToMobileIcon(); | 802 UpdateChromeToMobileIcon(); |
808 return; | 803 return; |
809 } | 804 } |
810 | 805 |
| 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 |
811 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); | 815 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
812 | 816 |
813 if (theme_service_->UsingNativeTheme()) { | 817 if (theme_service_->UsingNativeTheme()) { |
814 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); | 818 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); |
815 | 819 |
816 GdkColor border_color = theme_service_->GetGdkColor( | 820 GdkColor border_color = theme_service_->GetGdkColor( |
817 ThemeService::COLOR_FRAME); | 821 ThemeService::COLOR_FRAME); |
818 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); | 822 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); |
819 | 823 |
820 gtk_util::UndoForceFontSize(security_info_label_); | 824 gtk_util::UndoForceFontSize(security_info_label_); |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 | 1500 |
1497 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1501 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
1498 LocationBarViewGtk* owner, | 1502 LocationBarViewGtk* owner, |
1499 ExtensionAction* page_action) | 1503 ExtensionAction* page_action) |
1500 : owner_(NULL), | 1504 : owner_(NULL), |
1501 page_action_(page_action), | 1505 page_action_(page_action), |
1502 last_icon_pixbuf_(NULL), | 1506 last_icon_pixbuf_(NULL), |
1503 tracker_(this), | 1507 tracker_(this), |
1504 current_tab_id_(-1), | 1508 current_tab_id_(-1), |
1505 window_(NULL), | 1509 window_(NULL), |
1506 accel_group_(NULL), | 1510 accel_group_(NULL) { |
1507 preview_enabled_(false) { | |
1508 event_box_.Own(gtk_event_box_new()); | 1511 event_box_.Own(gtk_event_box_new()); |
1509 gtk_widget_set_size_request(event_box_.get(), | 1512 gtk_widget_set_size_request(event_box_.get(), |
1510 Extension::kPageActionIconMaxSize, | 1513 Extension::kPageActionIconMaxSize, |
1511 Extension::kPageActionIconMaxSize); | 1514 Extension::kPageActionIconMaxSize); |
1512 | 1515 |
1513 // Make the event box not visible so it does not paint a background. | 1516 // Make the event box not visible so it does not paint a background. |
1514 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1517 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
1515 g_signal_connect(event_box_.get(), "button-press-event", | 1518 g_signal_connect(event_box_.get(), "button-press-event", |
1516 G_CALLBACK(&OnButtonPressedThunk), this); | 1519 G_CALLBACK(&OnButtonPressedThunk), this); |
1517 g_signal_connect_after(event_box_.get(), "expose-event", | 1520 g_signal_connect_after(event_box_.get(), "expose-event", |
1518 G_CALLBACK(OnExposeEventThunk), this); | 1521 G_CALLBACK(OnExposeEventThunk), this); |
1519 g_signal_connect(event_box_.get(), "realize", | 1522 g_signal_connect(event_box_.get(), "realize", |
1520 G_CALLBACK(OnRealizeThunk), this); | 1523 G_CALLBACK(OnRealizeThunk), this); |
1521 | 1524 |
1522 image_.Own(gtk_image_new()); | 1525 image_.Own(gtk_image_new()); |
1523 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1526 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
| 1527 gtk_widget_show_all(event_box_.get()); |
1524 | 1528 |
1525 const Extension* extension = owner->browser()->profile()-> | 1529 const Extension* extension = owner->browser()->profile()-> |
1526 GetExtensionService()->GetExtensionById(page_action->extension_id(), | 1530 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
1527 false); | 1531 false); |
1528 DCHECK(extension); | 1532 DCHECK(extension); |
1529 | 1533 |
1530 // Load all the icons declared in the manifest. This is the contents of the | 1534 // Load all the icons declared in the manifest. This is the contents of the |
1531 // icons array, plus the default_icon property, if any. | 1535 // icons array, plus the default_icon property, if any. |
1532 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1536 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
1533 if (!page_action_->default_icon_path().empty()) | 1537 if (!page_action_->default_icon_path().empty()) |
(...skipping 18 matching lines...) Expand all Loading... |
1552 image_.Destroy(); | 1556 image_.Destroy(); |
1553 event_box_.Destroy(); | 1557 event_box_.Destroy(); |
1554 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); | 1558 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); |
1555 ++iter) { | 1559 ++iter) { |
1556 g_object_unref(iter->second); | 1560 g_object_unref(iter->second); |
1557 } | 1561 } |
1558 if (last_icon_pixbuf_) | 1562 if (last_icon_pixbuf_) |
1559 g_object_unref(last_icon_pixbuf_); | 1563 g_object_unref(last_icon_pixbuf_); |
1560 } | 1564 } |
1561 | 1565 |
1562 bool LocationBarViewGtk::PageActionViewGtk::IsVisible() { | 1566 void LocationBarViewGtk::PageActionViewGtk::Update( |
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 bool visible = contents && | 1573 // Set the tooltip. |
1574 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); | 1574 gtk_widget_set_tooltip_text(event_box_.get(), |
1575 if (visible) { | 1575 page_action_->GetTitle(current_tab_id_).c_str()); |
1576 // Set the tooltip. | |
1577 gtk_widget_set_tooltip_text(event_box_.get(), | |
1578 page_action_->GetTitle(current_tab_id_).c_str()); | |
1579 | 1576 |
1580 // Set the image. | 1577 // Set the image. |
1581 // It can come from three places. In descending order of priority: | 1578 // It can come from three places. In descending order of priority: |
1582 // - The developer can set it dynamically by path or bitmap. It will be in | 1579 // - The developer can set it dynamically by path or bitmap. It will be in |
1583 // page_action_->GetIcon(). | 1580 // page_action_->GetIcon(). |
1584 // - The developer can set it dyanmically by index. It will be in | 1581 // - The developer can set it dyanmically by index. It will be in |
1585 // page_action_->GetIconIndex(). | 1582 // page_action_->GetIconIndex(). |
1586 // - It can be set in the manifest by path. It will be in page_action_-> | 1583 // - It can be set in the manifest by path. It will be in page_action_-> |
1587 // default_icon_path(). | 1584 // default_icon_path(). |
1588 | 1585 |
1589 // First look for a dynamically set bitmap. | 1586 // First look for a dynamically set bitmap. |
1590 SkBitmap icon = page_action_->GetIcon(current_tab_id_); | 1587 SkBitmap icon = page_action_->GetIcon(current_tab_id_); |
1591 GdkPixbuf* pixbuf = NULL; | 1588 GdkPixbuf* pixbuf = NULL; |
1592 if (!icon.isNull()) { | 1589 |
1593 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { | 1590 if (!icon.isNull()) { |
1594 if (last_icon_pixbuf_) | 1591 if (icon.pixelRef() != last_icon_skbitmap_.pixelRef()) { |
1595 g_object_unref(last_icon_pixbuf_); | 1592 if (last_icon_pixbuf_) |
1596 last_icon_skbitmap_ = icon; | 1593 g_object_unref(last_icon_pixbuf_); |
1597 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&icon); | 1594 last_icon_skbitmap_ = icon; |
1598 } | 1595 last_icon_pixbuf_ = gfx::GdkPixbufFromSkBitmap(&icon); |
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 } | |
1613 } | 1596 } |
1614 // The pixbuf might not be loaded yet. | 1597 DCHECK(last_icon_pixbuf_); |
1615 if (pixbuf) | 1598 pixbuf = last_icon_pixbuf_; |
1616 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1599 } else { |
| 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 } |
1617 } | 1611 } |
1618 | 1612 |
1619 bool old_visible = IsVisible(); | 1613 // The pixbuf might not be loaded yet. |
1620 if (visible) | 1614 if (pixbuf) |
1621 gtk_widget_show_all(event_box_.get()); | 1615 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
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 } | |
1631 } | 1616 } |
1632 | 1617 |
1633 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1618 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
1634 const gfx::Image& image, | 1619 const gfx::Image& image, |
1635 const std::string& extension_id, | 1620 const std::string& extension_id, |
1636 int index) { | 1621 int index) { |
1637 // We loaded icons()->size() icons, plus one extra if the page action had | 1622 // We loaded icons()->size() icons, plus one extra if the page action had |
1638 // a default icon. | 1623 // a default icon. |
1639 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 1624 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
1640 if (!page_action_->default_icon_path().empty()) | 1625 if (!page_action_->default_icon_path().empty()) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 owner_->browser()->profile()->GetExtensionService(); | 1726 owner_->browser()->profile()->GetExtensionService(); |
1742 if (!extension_service) | 1727 if (!extension_service) |
1743 return TRUE; | 1728 return TRUE; |
1744 | 1729 |
1745 const Extension* extension = | 1730 const Extension* extension = |
1746 extension_service->extensions()->GetByID(page_action()->extension_id()); | 1731 extension_service->extensions()->GetByID(page_action()->extension_id()); |
1747 if (!extension) | 1732 if (!extension) |
1748 return TRUE; | 1733 return TRUE; |
1749 | 1734 |
1750 ActionBoxController* controller = | 1735 ActionBoxController* controller = |
1751 tab_contents->extension_action_box_controller(); | 1736 tab_contents->extension_tab_helper()->action_box_controller(); |
1752 | 1737 |
1753 switch (controller->OnClicked(extension->id(), event->button)) { | 1738 switch (controller->OnClicked(extension->id(), event->button)) { |
1754 case ActionBoxController::ACTION_NONE: | 1739 case ActionBoxController::ACTION_NONE: |
1755 break; | 1740 break; |
1756 | 1741 |
1757 case ActionBoxController::ACTION_SHOW_POPUP: | 1742 case ActionBoxController::ACTION_SHOW_POPUP: |
1758 ExtensionPopupGtk::Show( | 1743 ExtensionPopupGtk::Show( |
1759 page_action_->GetPopupUrl(current_tab_id_), | 1744 page_action_->GetPopupUrl(current_tab_id_), |
1760 owner_->browser_, | 1745 owner_->browser_, |
1761 event_box_.get()); | 1746 event_box_.get()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1808 GdkModifierType modifier, | 1793 GdkModifierType modifier, |
1809 void* user_data) { | 1794 void* user_data) { |
1810 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); | 1795 PageActionViewGtk* view = static_cast<PageActionViewGtk*>(user_data); |
1811 if (!gtk_widget_get_visible(view->widget())) | 1796 if (!gtk_widget_get_visible(view->widget())) |
1812 return FALSE; | 1797 return FALSE; |
1813 | 1798 |
1814 GdkEventButton event = {}; | 1799 GdkEventButton event = {}; |
1815 event.button = 1; | 1800 event.button = 1; |
1816 return view->OnButtonPressed(view->widget(), &event); | 1801 return view->OnButtonPressed(view->widget(), &event); |
1817 } | 1802 } |
OLD | NEW |