| 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/views/location_bar/page_action_image_view.h" | 5 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" | 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
| 10 #include "chrome/browser/extensions/extension_browser_event_router.h" | 10 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 11 #include "chrome/browser/extensions/extension_context_menu_model.h" | 11 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_tab_helper.h" | 13 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 14 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 15 #include "chrome/browser/extensions/location_bar_controller.h" | 15 #include "chrome/browser/extensions/location_bar_controller.h" |
| 16 #include "chrome/browser/platform_util.h" | 16 #include "chrome/browser/platform_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 22 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 24 #include "chrome/common/extensions/extension_action.h" | 25 #include "chrome/common/extensions/extension_action.h" |
| 25 #include "chrome/common/extensions/extension_manifest_constants.h" | 26 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 26 #include "chrome/common/extensions/extension_resource.h" | 27 #include "chrome/common/extensions/extension_resource.h" |
| 27 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
| 28 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 29 #include "ui/base/accessibility/accessible_view_state.h" | 30 #include "ui/base/accessibility/accessible_view_state.h" |
| 30 #include "ui/views/controls/menu/menu_item_view.h" | 31 #include "ui/views/controls/menu/menu_item_view.h" |
| 31 #include "ui/views/controls/menu/menu_model_adapter.h" | 32 #include "ui/views/controls/menu/menu_model_adapter.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return; | 99 return; |
| 99 | 100 |
| 100 LocationBarController* controller = | 101 LocationBarController* controller = |
| 101 tab_contents->extension_tab_helper()->location_bar_controller(); | 102 tab_contents->extension_tab_helper()->location_bar_controller(); |
| 102 | 103 |
| 103 // 1 is left click. | 104 // 1 is left click. |
| 104 switch (controller->OnClicked(page_action_->extension_id(), 1)) { | 105 switch (controller->OnClicked(page_action_->extension_id(), 1)) { |
| 105 case LocationBarController::ACTION_NONE: | 106 case LocationBarController::ACTION_NONE: |
| 106 break; | 107 break; |
| 107 | 108 |
| 108 case LocationBarController::ACTION_SHOW_POPUP: { | 109 case LocationBarController::ACTION_SHOW_POPUP: |
| 109 bool popup_showing = popup_ != NULL; | 110 ShowPopupWithURL(page_action_->GetPopupUrl(current_tab_id_)); |
| 110 | |
| 111 // Always hide the current popup. Only one popup at a time. | |
| 112 HidePopup(); | |
| 113 | |
| 114 // If we were already showing, then treat this click as a dismiss. | |
| 115 if (popup_showing) | |
| 116 return; | |
| 117 | |
| 118 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? | |
| 119 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | |
| 120 | |
| 121 popup_ = ExtensionPopup::ShowPopup( | |
| 122 page_action_->GetPopupUrl(current_tab_id_), | |
| 123 browser_, | |
| 124 this, | |
| 125 arrow_location); | |
| 126 popup_->GetWidget()->AddObserver(this); | |
| 127 break; | 111 break; |
| 128 } | |
| 129 | 112 |
| 130 case LocationBarController::ACTION_SHOW_CONTEXT_MENU: | 113 case LocationBarController::ACTION_SHOW_CONTEXT_MENU: |
| 131 // We are never passing OnClicked a right-click button, so assume that | 114 // We are never passing OnClicked a right-click button, so assume that |
| 132 // we're never going to be asked to show a context menu. | 115 // we're never going to be asked to show a context menu. |
| 133 // TODO(kalman): if this changes, update this class to pass the real | 116 // TODO(kalman): if this changes, update this class to pass the real |
| 134 // mouse button through to the LocationBarController. | 117 // mouse button through to the LocationBarController. |
| 135 NOTREACHED(); | 118 NOTREACHED(); |
| 136 break; | 119 break; |
| 120 |
| 121 case LocationBarController::ACTION_SHOW_SCRIPT_POPUP: |
| 122 ShowPopupWithURL(ExtensionInfoUI::GetURL(page_action_->extension_id())); |
| 123 break; |
| 137 } | 124 } |
| 138 } | 125 } |
| 139 | 126 |
| 140 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) { | 127 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 141 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 128 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 142 state->name = UTF8ToUTF16(tooltip_); | 129 state->name = UTF8ToUTF16(tooltip_); |
| 143 } | 130 } |
| 144 | 131 |
| 145 bool PageActionImageView::OnMousePressed(const views::MouseEvent& event) { | 132 bool PageActionImageView::OnMousePressed(const views::MouseEvent& event) { |
| 146 // We want to show the bubble on mouse release; that is the standard behavior | 133 // We want to show the bubble on mouse release; that is the standard behavior |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 void PageActionImageView::Observe(int type, | 276 void PageActionImageView::Observe(int type, |
| 290 const content::NotificationSource& source, | 277 const content::NotificationSource& source, |
| 291 const content::NotificationDetails& details) { | 278 const content::NotificationDetails& details) { |
| 292 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); | 279 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNLOADED, type); |
| 293 const Extension* unloaded_extension = | 280 const Extension* unloaded_extension = |
| 294 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 281 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
| 295 if (page_action_ == unloaded_extension ->page_action()) | 282 if (page_action_ == unloaded_extension ->page_action()) |
| 296 owner_->UpdatePageActions(); | 283 owner_->UpdatePageActions(); |
| 297 } | 284 } |
| 298 | 285 |
| 286 void PageActionImageView::ShowPopupWithURL(const GURL& popup_url) { |
| 287 bool popup_showing = popup_ != NULL; |
| 288 |
| 289 // Always hide the current popup. Only one popup at a time. |
| 290 HidePopup(); |
| 291 |
| 292 // If we were already showing, then treat this click as a dismiss. |
| 293 if (popup_showing) |
| 294 return; |
| 295 |
| 296 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? |
| 297 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
| 298 |
| 299 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); |
| 300 popup_->GetWidget()->AddObserver(this); |
| 301 } |
| 302 |
| 299 void PageActionImageView::HidePopup() { | 303 void PageActionImageView::HidePopup() { |
| 300 if (popup_) | 304 if (popup_) |
| 301 popup_->GetWidget()->Close(); | 305 popup_->GetWidget()->Close(); |
| 302 } | 306 } |
| OLD | NEW |