| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/extension_action_view_controller.h" | 5 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.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/extension_action/extension_action_api.h" |
| 9 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
| 10 #include "chrome/browser/extensions/extension_toolbar_model.h" | |
| 11 #include "chrome/browser/extensions/location_bar_controller.h" | |
| 12 #include "chrome/browser/extensions/tab_helper.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sessions/session_tab_helper.h" | 12 #include "chrome/browser/sessions/session_tab_helper.h" |
| 15 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/extensions/accelerator_priority.h" | 14 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
| 17 #include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h" | 15 #include "chrome/browser/ui/views/extensions/extension_action_view_delegate.h" |
| 18 #include "chrome/common/extensions/api/extension_action/action_info.h" | 16 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 19 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/manifest_constants.h" | |
| 21 #include "ui/views/controls/menu/menu_controller.h" | 18 #include "ui/views/controls/menu/menu_controller.h" |
| 22 #include "ui/views/controls/menu/menu_runner.h" | 19 #include "ui/views/controls/menu/menu_runner.h" |
| 23 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 25 | 22 |
| 26 using extensions::ActionInfo; | 23 using extensions::ActionInfo; |
| 27 using extensions::CommandService; | 24 using extensions::CommandService; |
| 28 | 25 |
| 29 namespace { | 26 namespace { |
| 30 | 27 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void ExtensionActionViewController::InspectPopup() { | 61 void ExtensionActionViewController::InspectPopup() { |
| 65 ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT, true); | 62 ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT, true); |
| 66 } | 63 } |
| 67 | 64 |
| 68 void ExtensionActionViewController::ExecuteActionByUser() { | 65 void ExtensionActionViewController::ExecuteActionByUser() { |
| 69 ExecuteAction(ExtensionPopup::SHOW, true); | 66 ExecuteAction(ExtensionPopup::SHOW, true); |
| 70 } | 67 } |
| 71 | 68 |
| 72 bool ExtensionActionViewController::ExecuteAction( | 69 bool ExtensionActionViewController::ExecuteAction( |
| 73 ExtensionPopup::ShowAction show_action, bool grant_tab_permissions) { | 70 ExtensionPopup::ShowAction show_action, bool grant_tab_permissions) { |
| 74 GURL popup_url; | 71 if (extensions::ExtensionActionAPI::Get(browser_->profile())-> |
| 75 bool show_popup = false; | 72 ExecuteExtensionAction(extension_, browser_, grant_tab_permissions) == |
| 76 if (extension_action_->action_type() == ActionInfo::TYPE_BROWSER) { | 73 ExtensionAction::ACTION_SHOW_POPUP) { |
| 77 extensions::ExtensionToolbarModel* toolbar_model = | 74 GURL popup_url = extension_action_->GetPopupUrl(GetCurrentTabId()); |
| 78 extensions::ExtensionToolbarModel::Get(browser_->profile()); | 75 if (ShowPopupWithUrl(show_action, popup_url)) { |
| 79 show_popup = toolbar_model->ExecuteBrowserAction( | 76 delegate_->OnPopupShown(grant_tab_permissions); |
| 80 extension_, browser_, &popup_url, grant_tab_permissions) == | 77 return true; |
| 81 ExtensionAction::ACTION_SHOW_POPUP; | |
| 82 } else { // PageAction | |
| 83 content::WebContents* web_contents = delegate_->GetCurrentWebContents(); | |
| 84 if (!web_contents) | |
| 85 return false; | |
| 86 extensions::LocationBarController* controller = | |
| 87 extensions::TabHelper::FromWebContents(web_contents)-> | |
| 88 location_bar_controller(); | |
| 89 switch (controller->OnClicked(extension_action_)) { | |
| 90 case ExtensionAction::ACTION_NONE: | |
| 91 break; | |
| 92 case ExtensionAction::ACTION_SHOW_POPUP: | |
| 93 popup_url = extension_action_->GetPopupUrl(GetCurrentTabId()); | |
| 94 show_popup = true; | |
| 95 break; | |
| 96 } | 78 } |
| 97 } | 79 } |
| 98 | |
| 99 if (show_popup && ShowPopupWithUrl(show_action, popup_url)) { | |
| 100 delegate_->OnPopupShown(grant_tab_permissions); | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 return false; | 80 return false; |
| 105 } | 81 } |
| 106 | 82 |
| 107 void ExtensionActionViewController::HidePopup() { | 83 void ExtensionActionViewController::HidePopup() { |
| 108 if (popup_) | 84 if (popup_) |
| 109 CleanupPopup(true); | 85 CleanupPopup(true); |
| 110 } | 86 } |
| 111 | 87 |
| 112 gfx::Image ExtensionActionViewController::GetIcon(int tab_id) { | 88 gfx::Image ExtensionActionViewController::GetIcon(int tab_id) { |
| 113 return icon_factory_.GetIcon(tab_id); | 89 return icon_factory_.GetIcon(tab_id); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 305 } |
| 330 | 306 |
| 331 void ExtensionActionViewController::CleanupPopup(bool close_widget) { | 307 void ExtensionActionViewController::CleanupPopup(bool close_widget) { |
| 332 DCHECK(popup_); | 308 DCHECK(popup_); |
| 333 delegate_->CleanupPopup(); | 309 delegate_->CleanupPopup(); |
| 334 popup_->GetWidget()->RemoveObserver(this); | 310 popup_->GetWidget()->RemoveObserver(this); |
| 335 if (close_widget) | 311 if (close_widget) |
| 336 popup_->GetWidget()->Close(); | 312 popup_->GetWidget()->Close(); |
| 337 popup_ = NULL; | 313 popup_ = NULL; |
| 338 } | 314 } |
| OLD | NEW |