| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/location_bar_view.h" | 5 #include "chrome/browser/views/location_bar_view.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 | 1420 |
| 1421 LocationBarView::PageActionImageView::PageActionImageView( | 1421 LocationBarView::PageActionImageView::PageActionImageView( |
| 1422 LocationBarView* owner, | 1422 LocationBarView* owner, |
| 1423 Profile* profile, | 1423 Profile* profile, |
| 1424 ExtensionAction* page_action, | 1424 ExtensionAction* page_action, |
| 1425 const BubblePositioner* bubble_positioner) | 1425 const BubblePositioner* bubble_positioner) |
| 1426 : LocationBarImageView(bubble_positioner), | 1426 : LocationBarImageView(bubble_positioner), |
| 1427 owner_(owner), | 1427 owner_(owner), |
| 1428 profile_(profile), | 1428 profile_(profile), |
| 1429 page_action_(page_action), | 1429 page_action_(page_action), |
| 1430 tracker_(NULL), | 1430 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
| 1431 current_tab_id_(-1), | 1431 current_tab_id_(-1), |
| 1432 preview_enabled_(false), | 1432 preview_enabled_(false), |
| 1433 popup_(NULL) { | 1433 popup_(NULL) { |
| 1434 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 1434 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
| 1435 page_action->extension_id(), false); | 1435 page_action->extension_id(), false); |
| 1436 DCHECK(extension); | 1436 DCHECK(extension); |
| 1437 | 1437 |
| 1438 // Load all the icons declared in the manifest. This is the contents of the | 1438 // Load all the icons declared in the manifest. This is the contents of the |
| 1439 // icons array, plus the default_icon property, if any. | 1439 // icons array, plus the default_icon property, if any. |
| 1440 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1440 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
| 1441 if (!page_action_->default_icon_path().empty()) | 1441 if (!page_action_->default_icon_path().empty()) |
| 1442 icon_paths.push_back(page_action_->default_icon_path()); | 1442 icon_paths.push_back(page_action_->default_icon_path()); |
| 1443 | 1443 |
| 1444 tracker_ = new ImageLoadingTracker(this, icon_paths.size()); | |
| 1445 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 1444 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
| 1446 iter != icon_paths.end(); ++iter) { | 1445 iter != icon_paths.end(); ++iter) { |
| 1447 tracker_->PostLoadImageTask( | 1446 tracker_.LoadImage(extension->GetResource(*iter), |
| 1448 extension->GetResource(*iter), | 1447 gfx::Size(Extension::kPageActionIconMaxSize, |
| 1449 gfx::Size(Extension::kPageActionIconMaxSize, | 1448 Extension::kPageActionIconMaxSize)); |
| 1450 Extension::kPageActionIconMaxSize)); | |
| 1451 } | 1449 } |
| 1452 } | 1450 } |
| 1453 | 1451 |
| 1454 LocationBarView::PageActionImageView::~PageActionImageView() { | 1452 LocationBarView::PageActionImageView::~PageActionImageView() { |
| 1455 if (tracker_) | |
| 1456 tracker_->StopTrackingImageLoad(); | |
| 1457 | |
| 1458 if (popup_) | 1453 if (popup_) |
| 1459 HidePopup(); | 1454 HidePopup(); |
| 1460 } | 1455 } |
| 1461 | 1456 |
| 1462 void LocationBarView::PageActionImageView::ExecuteAction(int button, | 1457 void LocationBarView::PageActionImageView::ExecuteAction(int button, |
| 1463 bool inspect_with_devtools) { | 1458 bool inspect_with_devtools) { |
| 1464 if (current_tab_id_ < 0) { | 1459 if (current_tab_id_ < 0) { |
| 1465 NOTREACHED() << "No current tab."; | 1460 NOTREACHED() << "No current tab."; |
| 1466 return; | 1461 return; |
| 1467 } | 1462 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 return; | 1549 return; |
| 1555 } | 1550 } |
| 1556 | 1551 |
| 1557 ExecuteAction(button, false); // inspect_with_devtools | 1552 ExecuteAction(button, false); // inspect_with_devtools |
| 1558 } | 1553 } |
| 1559 | 1554 |
| 1560 void LocationBarView::PageActionImageView::ShowInfoBubble() { | 1555 void LocationBarView::PageActionImageView::ShowInfoBubble() { |
| 1561 ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT)); | 1556 ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT)); |
| 1562 } | 1557 } |
| 1563 | 1558 |
| 1564 void LocationBarView::PageActionImageView::OnImageLoaded(SkBitmap* image, | 1559 void LocationBarView::PageActionImageView::OnImageLoaded( |
| 1565 size_t index) { | 1560 SkBitmap* image, ExtensionResource resource, int index) { |
| 1566 // We loaded icons()->size() icons, plus one extra if the page action had | 1561 // We loaded icons()->size() icons, plus one extra if the page action had |
| 1567 // a default icon. | 1562 // a default icon. |
| 1568 size_t total_icons = page_action_->icon_paths()->size(); | 1563 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
| 1569 if (!page_action_->default_icon_path().empty()) | 1564 if (!page_action_->default_icon_path().empty()) |
| 1570 total_icons++; | 1565 total_icons++; |
| 1571 DCHECK(index < total_icons); | 1566 DCHECK(index < total_icons); |
| 1572 | 1567 |
| 1573 // Map the index of the loaded image back to its name. If we ever get an | 1568 // Map the index of the loaded image back to its name. If we ever get an |
| 1574 // index greater than the number of icons, it must be the default icon. | 1569 // index greater than the number of icons, it must be the default icon. |
| 1575 if (image) { | 1570 if (image) { |
| 1576 if (index < page_action_->icon_paths()->size()) | 1571 if (index < static_cast<int>(page_action_->icon_paths()->size())) |
| 1577 page_action_icons_[page_action_->icon_paths()->at(index)] = *image; | 1572 page_action_icons_[page_action_->icon_paths()->at(index)] = *image; |
| 1578 else | 1573 else |
| 1579 page_action_icons_[page_action_->default_icon_path()] = *image; | 1574 page_action_icons_[page_action_->default_icon_path()] = *image; |
| 1580 } | 1575 } |
| 1581 | 1576 |
| 1582 // If we are done, release the tracker. | |
| 1583 if (index == total_icons - 1) | |
| 1584 tracker_ = NULL; | |
| 1585 | |
| 1586 owner_->UpdatePageActions(); | 1577 owner_->UpdatePageActions(); |
| 1587 } | 1578 } |
| 1588 | 1579 |
| 1589 void LocationBarView::PageActionImageView::UpdateVisibility( | 1580 void LocationBarView::PageActionImageView::UpdateVisibility( |
| 1590 TabContents* contents, const GURL& url) { | 1581 TabContents* contents, const GURL& url) { |
| 1591 // Save this off so we can pass it back to the extension when the action gets | 1582 // Save this off so we can pass it back to the extension when the action gets |
| 1592 // executed. See PageActionImageView::OnMousePressed. | 1583 // executed. See PageActionImageView::OnMousePressed. |
| 1593 current_tab_id_ = ExtensionTabUtil::GetTabId(contents); | 1584 current_tab_id_ = ExtensionTabUtil::GetTabId(contents); |
| 1594 current_url_ = url; | 1585 current_url_ = url; |
| 1595 | 1586 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton, | 1730 page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton, |
| 1740 false); // inspect_with_devtools | 1731 false); // inspect_with_devtools |
| 1741 return; | 1732 return; |
| 1742 } | 1733 } |
| 1743 ++current; | 1734 ++current; |
| 1744 } | 1735 } |
| 1745 } | 1736 } |
| 1746 | 1737 |
| 1747 NOTREACHED(); | 1738 NOTREACHED(); |
| 1748 } | 1739 } |
| OLD | NEW |