| 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 |
| (...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 G_CALLBACK(OnRealizeThunk), this); | 1810 G_CALLBACK(OnRealizeThunk), this); |
| 1811 | 1811 |
| 1812 image_.Own(gtk_image_new()); | 1812 image_.Own(gtk_image_new()); |
| 1813 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1813 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
| 1814 | 1814 |
| 1815 const Extension* extension = owner->browser()->profile()-> | 1815 const Extension* extension = owner->browser()->profile()-> |
| 1816 GetExtensionService()->GetExtensionById(page_action->extension_id(), | 1816 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
| 1817 false); | 1817 false); |
| 1818 DCHECK(extension); | 1818 DCHECK(extension); |
| 1819 | 1819 |
| 1820 // Load all the icons declared in the manifest. This is the contents of the | 1820 std::string path = page_action_->default_icon_path(); |
| 1821 // icons array, plus the default_icon property, if any. | 1821 if (!path.empty()) { |
| 1822 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1822 tracker_.LoadImage(extension, extension->GetResource(path), |
| 1823 if (!page_action_->default_icon_path().empty()) | |
| 1824 icon_paths.push_back(page_action_->default_icon_path()); | |
| 1825 | |
| 1826 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | |
| 1827 iter != icon_paths.end(); ++iter) { | |
| 1828 tracker_.LoadImage(extension, extension->GetResource(*iter), | |
| 1829 gfx::Size(Extension::kPageActionIconMaxSize, | 1823 gfx::Size(Extension::kPageActionIconMaxSize, |
| 1830 Extension::kPageActionIconMaxSize), | 1824 Extension::kPageActionIconMaxSize), |
| 1831 ImageLoadingTracker::DONT_CACHE); | 1825 ImageLoadingTracker::DONT_CACHE); |
| 1832 } | 1826 } |
| 1833 | 1827 |
| 1834 // We set the owner last of all so that we can determine whether we are in | 1828 // We set the owner last of all so that we can determine whether we are in |
| 1835 // the process of initializing this class or not. | 1829 // the process of initializing this class or not. |
| 1836 owner_ = owner; | 1830 owner_ = owner; |
| 1837 } | 1831 } |
| 1838 | 1832 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1881 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1875 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 1882 content::Source<ExtensionAction>(page_action_), | 1876 content::Source<ExtensionAction>(page_action_), |
| 1883 content::Details<WebContents>(contents)); | 1877 content::Details<WebContents>(contents)); |
| 1884 } | 1878 } |
| 1885 } | 1879 } |
| 1886 | 1880 |
| 1887 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1881 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
| 1888 const gfx::Image& image, | 1882 const gfx::Image& image, |
| 1889 const std::string& extension_id, | 1883 const std::string& extension_id, |
| 1890 int index) { | 1884 int index) { |
| 1891 // We loaded icons()->size() icons, plus one extra if the page action had | 1885 page_action_->CacheIcon(image); |
| 1892 // a default icon. | |
| 1893 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | |
| 1894 if (!page_action_->default_icon_path().empty()) | |
| 1895 total_icons++; | |
| 1896 DCHECK(index < total_icons); | |
| 1897 | |
| 1898 // Map the index of the loaded image back to its name. If we ever get an | |
| 1899 // index greater than the number of icons, it must be the default icon. | |
| 1900 if (index < static_cast<int>(page_action_->icon_paths()->size())) | |
| 1901 page_action_->CacheIcon(page_action_->icon_paths()->at(index), image); | |
| 1902 else | |
| 1903 page_action_->CacheIcon(page_action_->default_icon_path(), image); | |
| 1904 | 1886 |
| 1905 // If we have no owner, that means this class is still being constructed. | 1887 // If we have no owner, that means this class is still being constructed. |
| 1906 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; | 1888 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; |
| 1907 if (tab_contents) | 1889 if (tab_contents) |
| 1908 UpdateVisibility(tab_contents->web_contents(), current_url_); | 1890 UpdateVisibility(tab_contents->web_contents(), current_url_); |
| 1909 } | 1891 } |
| 1910 | 1892 |
| 1911 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { | 1893 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { |
| 1912 GdkEventButton event = {}; | 1894 GdkEventButton event = {}; |
| 1913 event.button = 1; | 1895 event.button = 1; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2115 } | 2097 } |
| 2116 | 2098 |
| 2117 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 2099 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
| 2118 ExtensionAction* action) { | 2100 ExtensionAction* action) { |
| 2119 ExtensionPopupGtk::Show( | 2101 ExtensionPopupGtk::Show( |
| 2120 action->GetPopupUrl(current_tab_id_), | 2102 action->GetPopupUrl(current_tab_id_), |
| 2121 owner_->browser_, | 2103 owner_->browser_, |
| 2122 event_box_.get(), | 2104 event_box_.get(), |
| 2123 ExtensionPopupGtk::SHOW_AND_INSPECT); | 2105 ExtensionPopupGtk::SHOW_AND_INSPECT); |
| 2124 } | 2106 } |
| OLD | NEW |