| 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     Profile* profile, | 1420     Profile* profile, | 
| 1421     ExtensionAction* page_action, | 1421     ExtensionAction* page_action, | 
| 1422     const BubblePositioner* bubble_positioner) | 1422     const BubblePositioner* bubble_positioner) | 
| 1423     : LocationBarImageView(bubble_positioner), | 1423     : LocationBarImageView(bubble_positioner), | 
| 1424       owner_(owner), | 1424       owner_(owner), | 
| 1425       profile_(profile), | 1425       profile_(profile), | 
| 1426       page_action_(page_action), | 1426       page_action_(page_action), | 
| 1427       tracker_(NULL), | 1427       tracker_(NULL), | 
| 1428       current_tab_id_(-1), | 1428       current_tab_id_(-1), | 
| 1429       preview_enabled_(false), | 1429       preview_enabled_(false), | 
| 1430       popup_(NULL), | 1430       popup_(NULL) { | 
| 1431       ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |  | 
| 1432   Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 1431   Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 
| 1433       page_action->extension_id(), false); | 1432       page_action->extension_id(), false); | 
| 1434   DCHECK(extension); | 1433   DCHECK(extension); | 
| 1435 | 1434 | 
| 1436   // Load all the icons declared in the manifest. This is the contents of the | 1435   // Load all the icons declared in the manifest. This is the contents of the | 
| 1437   // icons array, plus the default_icon property, if any. | 1436   // icons array, plus the default_icon property, if any. | 
| 1438   std::vector<std::string> icon_paths(*page_action->icon_paths()); | 1437   std::vector<std::string> icon_paths(*page_action->icon_paths()); | 
| 1439   if (!page_action_->default_icon_path().empty()) | 1438   if (!page_action_->default_icon_path().empty()) | 
| 1440     icon_paths.push_back(page_action_->default_icon_path()); | 1439     icon_paths.push_back(page_action_->default_icon_path()); | 
| 1441 | 1440 | 
| 1442   tracker_ = new ImageLoadingTracker(this, icon_paths.size()); | 1441   tracker_ = new ImageLoadingTracker(this, icon_paths.size()); | 
| 1443   for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 1442   for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 
| 1444        iter != icon_paths.end(); ++iter) { | 1443        iter != icon_paths.end(); ++iter) { | 
| 1445     tracker_->PostLoadImageTask( | 1444     tracker_->PostLoadImageTask( | 
| 1446         extension->GetResource(*iter), | 1445         extension->GetResource(*iter), | 
| 1447         gfx::Size(Extension::kPageActionIconMaxSize, | 1446         gfx::Size(Extension::kPageActionIconMaxSize, | 
| 1448                   Extension::kPageActionIconMaxSize)); | 1447                   Extension::kPageActionIconMaxSize)); | 
| 1449   } | 1448   } | 
| 1450 |  | 
| 1451   registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |  | 
| 1452                  Source<Profile>(profile_)); |  | 
| 1453 } | 1449 } | 
| 1454 | 1450 | 
| 1455 LocationBarView::PageActionImageView::~PageActionImageView() { | 1451 LocationBarView::PageActionImageView::~PageActionImageView() { | 
| 1456   if (tracker_) | 1452   if (tracker_) | 
| 1457     tracker_->StopTrackingImageLoad(); | 1453     tracker_->StopTrackingImageLoad(); | 
| 1458 | 1454 | 
| 1459   if (popup_) | 1455   if (popup_) | 
| 1460     HidePopup(); | 1456     HidePopup(); | 
| 1461 } | 1457 } | 
| 1462 | 1458 | 
| 1463 void LocationBarView::PageActionImageView::ExecuteAction(int button) { | 1459 void LocationBarView::PageActionImageView::ExecuteAction(int button, | 
|  | 1460     bool inspect_with_devtools) { | 
| 1464   if (current_tab_id_ < 0) { | 1461   if (current_tab_id_ < 0) { | 
| 1465     NOTREACHED() << "No current tab."; | 1462     NOTREACHED() << "No current tab."; | 
| 1466     return; | 1463     return; | 
| 1467   } | 1464   } | 
| 1468 | 1465 | 
| 1469   if (page_action_->HasPopup(current_tab_id_)) { | 1466   if (page_action_->HasPopup(current_tab_id_)) { | 
| 1470     // In tests, GetLastActive could return NULL, so we need to have | 1467     // In tests, GetLastActive could return NULL, so we need to have | 
| 1471     // a fallback. | 1468     // a fallback. | 
| 1472     // TODO(erikkay): Find a better way to get the Browser that this | 1469     // TODO(erikkay): Find a better way to get the Browser that this | 
| 1473     // button is in. | 1470     // button is in. | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 1493     rect.set_y(origin.y()); | 1490     rect.set_y(origin.y()); | 
| 1494 | 1491 | 
| 1495     popup_ = ExtensionPopup::Show( | 1492     popup_ = ExtensionPopup::Show( | 
| 1496         page_action_->GetPopupUrl(current_tab_id_), | 1493         page_action_->GetPopupUrl(current_tab_id_), | 
| 1497         browser, | 1494         browser, | 
| 1498         browser->profile(), | 1495         browser->profile(), | 
| 1499         browser->window()->GetNativeHandle(), | 1496         browser->window()->GetNativeHandle(), | 
| 1500         rect, | 1497         rect, | 
| 1501         BubbleBorder::TOP_RIGHT, | 1498         BubbleBorder::TOP_RIGHT, | 
| 1502         true,  // Activate the popup window. | 1499         true,  // Activate the popup window. | 
| 1503         ExtensionPopup::BUBBLE_CHROME); | 1500         inspect_with_devtools, | 
| 1504     popup_->set_delegate(this); | 1501         ExtensionPopup::BUBBLE_CHROME, | 
|  | 1502         this);  // ExtensionPopup::Observer | 
| 1505   } else { | 1503   } else { | 
| 1506     ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 1504     ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 
| 1507         profile_, page_action_->extension_id(), page_action_->id(), | 1505         profile_, page_action_->extension_id(), page_action_->id(), | 
| 1508         current_tab_id_, current_url_.spec(), button); | 1506         current_tab_id_, current_url_.spec(), button); | 
| 1509   } | 1507   } | 
| 1510 } | 1508 } | 
| 1511 | 1509 | 
| 1512 void LocationBarView::PageActionImageView::OnMouseMoved( | 1510 void LocationBarView::PageActionImageView::OnMouseMoved( | 
| 1513     const views::MouseEvent& event) { | 1511     const views::MouseEvent& event) { | 
| 1514   // PageActionImageView uses normal tooltips rather than the info bubble, | 1512   // PageActionImageView uses normal tooltips rather than the info bubble, | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 1540     ConvertPointToScreen(this, &point); | 1538     ConvertPointToScreen(this, &point); | 
| 1541 | 1539 | 
| 1542     // Make the menu appear below the button. | 1540     // Make the menu appear below the button. | 
| 1543     point.Offset(0, height()); | 1541     point.Offset(0, height()); | 
| 1544 | 1542 | 
| 1545     Extension* extension = profile_->GetExtensionsService()->GetExtensionById( | 1543     Extension* extension = profile_->GetExtensionsService()->GetExtensionById( | 
| 1546         page_action()->extension_id(), false); | 1544         page_action()->extension_id(), false); | 
| 1547 | 1545 | 
| 1548     if (!context_menu_.get()) | 1546     if (!context_menu_.get()) | 
| 1549       context_menu_.reset(new ExtensionActionContextMenu()); | 1547       context_menu_.reset(new ExtensionActionContextMenu()); | 
| 1550     context_menu_->Run(extension, point); | 1548     context_menu_->Run(extension, | 
|  | 1549                        extension->page_action(), | 
|  | 1550                        this,  // ExtensionActionContextMenuModel::Delegate | 
|  | 1551                        profile_->GetPrefs(), | 
|  | 1552                        point); | 
| 1551     return; | 1553     return; | 
| 1552   } | 1554   } | 
| 1553 | 1555 | 
| 1554   ExecuteAction(button); | 1556   ExecuteAction(button, false);  // inspect_with_devtools | 
| 1555 } | 1557 } | 
| 1556 | 1558 | 
| 1557 void LocationBarView::PageActionImageView::ShowInfoBubble() { | 1559 void LocationBarView::PageActionImageView::ShowInfoBubble() { | 
| 1558   ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT)); | 1560   ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT)); | 
| 1559 } | 1561 } | 
| 1560 | 1562 | 
| 1561 void LocationBarView::PageActionImageView::OnImageLoaded(SkBitmap* image, | 1563 void LocationBarView::PageActionImageView::OnImageLoaded(SkBitmap* image, | 
| 1562                                                          size_t index) { | 1564                                                          size_t index) { | 
| 1563   // We loaded icons()->size() icons, plus one extra if the page action had | 1565   // We loaded icons()->size() icons, plus one extra if the page action had | 
| 1564   // a default icon. | 1566   // a default icon. | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1622           icon = iter->second; | 1624           icon = iter->second; | 
| 1623       } | 1625       } | 
| 1624     } | 1626     } | 
| 1625 | 1627 | 
| 1626     if (!icon.isNull()) | 1628     if (!icon.isNull()) | 
| 1627       SetImage(&icon); | 1629       SetImage(&icon); | 
| 1628   } | 1630   } | 
| 1629   SetVisible(visible); | 1631   SetVisible(visible); | 
| 1630 } | 1632 } | 
| 1631 | 1633 | 
| 1632 void LocationBarView::PageActionImageView::BubbleBrowserWindowClosing( | 1634 void LocationBarView::PageActionImageView::ShowPopupForDevToolsWindow( | 
| 1633     BrowserBubble* bubble) { | 1635     Extension* extension, ExtensionAction* extension_action) { | 
| 1634   HidePopup(); | 1636   ExecuteAction(1,  // left-click | 
|  | 1637                 true);  // inspect_with_devtools | 
| 1635 } | 1638 } | 
| 1636 | 1639 | 
| 1637 void LocationBarView::PageActionImageView::BubbleLostFocus( | 1640 void LocationBarView::PageActionImageView::ExtensionPopupClosed( | 
| 1638     BrowserBubble* bubble, bool lost_focus_to_child) { | 1641     ExtensionPopup* popup) { | 
| 1639   // Don't close when we are losing focus to a child window, this is the case | 1642   DCHECK_EQ(popup_, popup); | 
| 1640   // for select popups and alert for example. | 1643   // ExtensionPopup is ref-counted, so we don't need to delete it. | 
| 1641   if (!popup_ || lost_focus_to_child) | 1644   popup_ = NULL; | 
| 1642     return; |  | 
| 1643 |  | 
| 1644   MessageLoop::current()->PostTask(FROM_HERE, |  | 
| 1645       method_factory_.NewRunnableMethod( |  | 
| 1646           &LocationBarView::PageActionImageView::HidePopup)); |  | 
| 1647 } | 1645 } | 
| 1648 | 1646 | 
| 1649 void LocationBarView::PageActionImageView::HidePopup() { | 1647 void LocationBarView::PageActionImageView::HidePopup() { | 
| 1650   if (!popup_) | 1648   if (popup_) | 
| 1651     return; | 1649     popup_->Close(); | 
| 1652 |  | 
| 1653   // This sometimes gets called via a timer (See BubbleLostFocus), so clear |  | 
| 1654   // the method factory. in case one is pending. |  | 
| 1655   method_factory_.RevokeAll(); |  | 
| 1656 |  | 
| 1657   // Save the popup in a local since destroying it calls BubbleLostFocus, |  | 
| 1658   // which will try to call HidePopup() again. |  | 
| 1659   ExtensionPopup* closing_popup = popup_; |  | 
| 1660   popup_ = NULL; |  | 
| 1661 |  | 
| 1662   closing_popup->DetachFromBrowser(); |  | 
| 1663   delete closing_popup; |  | 
| 1664 } |  | 
| 1665 |  | 
| 1666 void LocationBarView::PageActionImageView::Observe( |  | 
| 1667     NotificationType type, |  | 
| 1668     const NotificationSource& source, |  | 
| 1669     const NotificationDetails& details) { |  | 
| 1670   switch (type.value) { |  | 
| 1671     case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: |  | 
| 1672       // If we aren't the host of the popup, then disregard the notification. |  | 
| 1673       if (!popup_ || Details<ExtensionHost>(popup_->host()) != details) |  | 
| 1674         return; |  | 
| 1675 |  | 
| 1676       HidePopup(); |  | 
| 1677       break; |  | 
| 1678     default: |  | 
| 1679       NOTREACHED() << "Unexpected notification"; |  | 
| 1680       break; |  | 
| 1681   } |  | 
| 1682 } | 1650 } | 
| 1683 | 1651 | 
| 1684 //////////////////////////////////////////////////////////////////////////////// | 1652 //////////////////////////////////////////////////////////////////////////////// | 
| 1685 // LocationBarView, LocationBar implementation: | 1653 // LocationBarView, LocationBar implementation: | 
| 1686 | 1654 | 
| 1687 void LocationBarView::ShowFirstRunBubble(bool use_OEM_bubble) { | 1655 void LocationBarView::ShowFirstRunBubble(bool use_OEM_bubble) { | 
| 1688   // We wait 30 milliseconds to open. It allows less flicker. | 1656   // We wait 30 milliseconds to open. It allows less flicker. | 
| 1689   Task* task = first_run_bubble_.NewRunnableMethod( | 1657   Task* task = first_run_bubble_.NewRunnableMethod( | 
| 1690       &LocationBarView::ShowFirstRunBubbleInternal, use_OEM_bubble); | 1658       &LocationBarView::ShowFirstRunBubbleInternal, use_OEM_bubble); | 
| 1691   MessageLoop::current()->PostDelayedTask(FROM_HERE, task, 30); | 1659   MessageLoop::current()->PostDelayedTask(FROM_HERE, task, 30); | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1760   NOTREACHED(); | 1728   NOTREACHED(); | 
| 1761   return NULL; | 1729   return NULL; | 
| 1762 } | 1730 } | 
| 1763 | 1731 | 
| 1764 void LocationBarView::TestPageActionPressed(size_t index) { | 1732 void LocationBarView::TestPageActionPressed(size_t index) { | 
| 1765   size_t current = 0; | 1733   size_t current = 0; | 
| 1766   for (size_t i = 0; i < page_action_views_.size(); ++i) { | 1734   for (size_t i = 0; i < page_action_views_.size(); ++i) { | 
| 1767     if (page_action_views_[i]->IsVisible()) { | 1735     if (page_action_views_[i]->IsVisible()) { | 
| 1768       if (current == index) { | 1736       if (current == index) { | 
| 1769         const int kLeftMouseButton = 1; | 1737         const int kLeftMouseButton = 1; | 
| 1770         page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton); | 1738         page_action_views_[i]->image_view()->ExecuteAction(kLeftMouseButton, | 
|  | 1739             false);  // inspect_with_devtools | 
| 1771         return; | 1740         return; | 
| 1772       } | 1741       } | 
| 1773       ++current; | 1742       ++current; | 
| 1774     } | 1743     } | 
| 1775   } | 1744   } | 
| 1776 | 1745 | 
| 1777   NOTREACHED(); | 1746   NOTREACHED(); | 
| 1778 } | 1747 } | 
| OLD | NEW | 
|---|