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/api/extension_action/extension_action_api.h" |
10 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void ExtensionActionViewController::ExecuteActionByUser() { | 65 void ExtensionActionViewController::ExecuteActionByUser() { |
66 ExecuteAction(ExtensionPopup::SHOW, true); | 66 ExecuteAction(ExtensionPopup::SHOW, true); |
67 } | 67 } |
68 | 68 |
69 bool ExtensionActionViewController::ExecuteAction( | 69 bool ExtensionActionViewController::ExecuteAction( |
70 ExtensionPopup::ShowAction show_action, bool grant_tab_permissions) { | 70 ExtensionPopup::ShowAction show_action, bool grant_tab_permissions) { |
71 if (extensions::ExtensionActionAPI::Get(browser_->profile())-> | 71 if (extensions::ExtensionActionAPI::Get(browser_->profile())-> |
72 ExecuteExtensionAction(extension_, browser_, grant_tab_permissions) == | 72 ExecuteExtensionAction(extension_, browser_, grant_tab_permissions) == |
73 ExtensionAction::ACTION_SHOW_POPUP) { | 73 ExtensionAction::ACTION_SHOW_POPUP) { |
74 GURL popup_url = extension_action_->GetPopupUrl(GetCurrentTabId()); | 74 GURL popup_url = extension_action_->GetPopupUrl(GetCurrentTabId()); |
75 if (delegate_->GetPreferredPopupViewController()->ShowPopupWithUrl( | 75 return delegate_->GetPreferredPopupViewController()->ShowPopupWithUrl( |
76 show_action, popup_url)) { | 76 show_action, popup_url, grant_tab_permissions); |
77 delegate_->OnPopupShown(grant_tab_permissions); | |
78 return true; | |
79 } | |
80 } | 77 } |
81 return false; | 78 return false; |
82 } | 79 } |
83 | 80 |
84 void ExtensionActionViewController::HidePopup() { | 81 void ExtensionActionViewController::HidePopup() { |
85 if (popup_) | 82 if (popup_) |
86 CleanupPopup(true); | 83 CleanupPopup(true); |
87 } | 84 } |
88 | 85 |
89 gfx::Image ExtensionActionViewController::GetIcon(int tab_id) { | 86 gfx::Image ExtensionActionViewController::GetIcon(int tab_id) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 234 |
238 // If another extension action wants to show its context menu, allow it to. | 235 // If another extension action wants to show its context menu, allow it to. |
239 if (!followup_context_menu_task_.is_null()) { | 236 if (!followup_context_menu_task_.is_null()) { |
240 base::Closure task = followup_context_menu_task_; | 237 base::Closure task = followup_context_menu_task_; |
241 followup_context_menu_task_ = base::Closure(); | 238 followup_context_menu_task_ = base::Closure(); |
242 task.Run(); | 239 task.Run(); |
243 } | 240 } |
244 } | 241 } |
245 | 242 |
246 bool ExtensionActionViewController::ShowPopupWithUrl( | 243 bool ExtensionActionViewController::ShowPopupWithUrl( |
247 ExtensionPopup::ShowAction show_action, const GURL& popup_url) { | 244 ExtensionPopup::ShowAction show_action, |
| 245 const GURL& popup_url, |
| 246 bool grant_tab_permissions) { |
248 // If we're already showing the popup for this browser action, just hide it | 247 // If we're already showing the popup for this browser action, just hide it |
249 // and return. | 248 // and return. |
250 bool already_showing = popup_ != NULL; | 249 bool already_showing = popup_ != NULL; |
251 | 250 |
252 // Always hide the current popup, even if it's not the same. | 251 // Always hide the current popup, even if it's not the same. |
253 // Only one popup should be visible at a time. | 252 // Only one popup should be visible at a time. |
254 delegate_->HideActivePopup(); | 253 delegate_->HideActivePopup(); |
255 | 254 |
256 // Similarly, don't allow a context menu and a popup to be showing | 255 // Similarly, don't allow a context menu and a popup to be showing |
257 // simultaneously. | 256 // simultaneously. |
258 CloseActiveMenuIfNeeded(); | 257 CloseActiveMenuIfNeeded(); |
259 | 258 |
260 if (already_showing) | 259 if (already_showing) |
261 return false; | 260 return false; |
262 | 261 |
263 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? | 262 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? |
264 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 263 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
265 | 264 |
266 views::View* reference_view = delegate_->GetReferenceViewForPopup(); | 265 views::View* reference_view = delegate_->GetReferenceViewForPopup(); |
267 | 266 |
268 popup_ = ExtensionPopup::ShowPopup( | 267 popup_ = ExtensionPopup::ShowPopup( |
269 popup_url, browser_, reference_view, arrow, show_action); | 268 popup_url, browser_, reference_view, arrow, show_action); |
270 popup_->GetWidget()->AddObserver(this); | 269 popup_->GetWidget()->AddObserver(this); |
271 | 270 |
| 271 delegate_->OnPopupShown(grant_tab_permissions); |
| 272 |
272 return true; | 273 return true; |
273 } | 274 } |
274 | 275 |
275 bool ExtensionActionViewController::GetExtensionCommand( | 276 bool ExtensionActionViewController::GetExtensionCommand( |
276 extensions::Command* command) { | 277 extensions::Command* command) { |
277 DCHECK(command); | 278 DCHECK(command); |
278 CommandService* command_service = CommandService::Get(browser_->profile()); | 279 CommandService* command_service = CommandService::Get(browser_->profile()); |
279 if (extension_action_->action_type() == ActionInfo::TYPE_PAGE) { | 280 if (extension_action_->action_type() == ActionInfo::TYPE_PAGE) { |
280 return command_service->GetPageActionCommand( | 281 return command_service->GetPageActionCommand( |
281 extension_->id(), CommandService::ACTIVE_ONLY, command, NULL); | 282 extension_->id(), CommandService::ACTIVE_ONLY, command, NULL); |
(...skipping 24 matching lines...) Expand all Loading... |
306 } | 307 } |
307 | 308 |
308 void ExtensionActionViewController::CleanupPopup(bool close_widget) { | 309 void ExtensionActionViewController::CleanupPopup(bool close_widget) { |
309 DCHECK(popup_); | 310 DCHECK(popup_); |
310 delegate_->CleanupPopup(); | 311 delegate_->CleanupPopup(); |
311 popup_->GetWidget()->RemoveObserver(this); | 312 popup_->GetWidget()->RemoveObserver(this); |
312 if (close_widget) | 313 if (close_widget) |
313 popup_->GetWidget()->Close(); | 314 popup_->GetWidget()->Close(); |
314 popup_ = NULL; | 315 popup_ = NULL; |
315 } | 316 } |
OLD | NEW |