| 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/extension_browser_event_router.h" | 8 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
| 11 #include "chrome/browser/platform_util.h" | 11 #include "chrome/browser/platform_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_action.h" | 18 #include "chrome/common/extensions/extension_action.h" |
| 19 #include "chrome/common/extensions/extension_resource.h" | 19 #include "chrome/common/extensions/extension_resource.h" |
| 20 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "ui/base/accessibility/accessible_view_state.h" | 22 #include "ui/base/accessibility/accessible_view_state.h" |
| 23 #include "ui/views/controls/menu/menu_item_view.h" | 23 #include "ui/views/controls/menu/menu_item_view.h" |
| 24 #include "ui/views/controls/menu/menu_model_adapter.h" | 24 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 25 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
| 26 | 26 |
| 27 using content::WebContents; | 27 using content::WebContents; |
| 28 | 28 |
| 29 PageActionImageView::PageActionImageView(LocationBarView* owner, | 29 PageActionImageView::PageActionImageView(LocationBarView* owner, |
| 30 ExtensionAction* page_action, | 30 ExtensionAction* page_action) |
| 31 Browser* browser) | |
| 32 : owner_(owner), | 31 : owner_(owner), |
| 33 page_action_(page_action), | 32 page_action_(page_action), |
| 34 browser_(browser), | |
| 35 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 33 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
| 36 current_tab_id_(-1), | 34 current_tab_id_(-1), |
| 37 preview_enabled_(false), | 35 preview_enabled_(false), |
| 38 popup_(NULL) { | 36 popup_(NULL) { |
| 39 const Extension* extension = owner_->profile()->GetExtensionService()-> | 37 const Extension* extension = owner_->browser()->profile()-> |
| 40 GetExtensionById(page_action->extension_id(), false); | 38 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
| 39 false); |
| 41 DCHECK(extension); | 40 DCHECK(extension); |
| 42 | 41 |
| 43 // Load all the icons declared in the manifest. This is the contents of the | 42 // Load all the icons declared in the manifest. This is the contents of the |
| 44 // icons array, plus the default_icon property, if any. | 43 // icons array, plus the default_icon property, if any. |
| 45 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 44 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
| 46 if (!page_action_->default_icon_path().empty()) | 45 if (!page_action_->default_icon_path().empty()) |
| 47 icon_paths.push_back(page_action_->default_icon_path()); | 46 icon_paths.push_back(page_action_->default_icon_path()); |
| 48 | 47 |
| 49 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 48 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
| 50 iter != icon_paths.end(); ++iter) { | 49 iter != icon_paths.end(); ++iter) { |
| 51 tracker_.LoadImage(extension, extension->GetResource(*iter), | 50 tracker_.LoadImage(extension, extension->GetResource(*iter), |
| 52 gfx::Size(Extension::kPageActionIconMaxSize, | 51 gfx::Size(Extension::kPageActionIconMaxSize, |
| 53 Extension::kPageActionIconMaxSize), | 52 Extension::kPageActionIconMaxSize), |
| 54 ImageLoadingTracker::DONT_CACHE); | 53 ImageLoadingTracker::DONT_CACHE); |
| 55 } | 54 } |
| 56 | 55 |
| 57 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 56 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 58 content::Source<Profile>( | 57 content::Source<Profile>( |
| 59 owner_->profile()->GetOriginalProfile())); | 58 owner_->browser()->profile()->GetOriginalProfile())); |
| 60 | 59 |
| 61 set_accessibility_focusable(true); | 60 set_accessibility_focusable(true); |
| 62 | 61 |
| 63 // Iterate through all the keybindings and see if one is assigned to the | 62 // Iterate through all the keybindings and see if one is assigned to the |
| 64 // pageAction. | 63 // pageAction. |
| 65 const std::vector<Extension::ExtensionKeybinding>& commands = | 64 const std::vector<Extension::ExtensionKeybinding>& commands = |
| 66 extension->keybindings(); | 65 extension->keybindings(); |
| 67 for (size_t i = 0; i < commands.size(); ++i) { | 66 for (size_t i = 0; i < commands.size(); ++i) { |
| 68 if (commands[i].command_name() == | 67 if (commands[i].command_name() == |
| 69 extension_manifest_values::kPageActionKeybindingEvent) { | 68 extension_manifest_values::kPageActionKeybindingEvent) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 99 | 98 |
| 100 // If we were already showing, then treat this click as a dismiss. | 99 // If we were already showing, then treat this click as a dismiss. |
| 101 if (popup_showing) | 100 if (popup_showing) |
| 102 return; | 101 return; |
| 103 | 102 |
| 104 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? | 103 views::BubbleBorder::ArrowLocation arrow_location = base::i18n::IsRTL() ? |
| 105 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 104 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
| 106 | 105 |
| 107 popup_ = ExtensionPopup::ShowPopup( | 106 popup_ = ExtensionPopup::ShowPopup( |
| 108 page_action_->GetPopupUrl(current_tab_id_), | 107 page_action_->GetPopupUrl(current_tab_id_), |
| 109 browser_, | 108 owner_->browser(), |
| 110 this, | 109 this, |
| 111 arrow_location, | 110 arrow_location, |
| 112 inspect_with_devtools); | 111 inspect_with_devtools); |
| 113 popup_->GetWidget()->AddObserver(this); | 112 popup_->GetWidget()->AddObserver(this); |
| 114 } else { | 113 } else { |
| 115 Profile* profile = owner_->profile(); | 114 Profile* profile = owner_->browser()->profile(); |
| 116 ExtensionService* service = profile->GetExtensionService(); | 115 ExtensionService* service = profile->GetExtensionService(); |
| 117 service->browser_event_router()->PageActionExecuted( | 116 service->browser_event_router()->PageActionExecuted( |
| 118 profile, page_action_->extension_id(), page_action_->id(), | 117 profile, page_action_->extension_id(), page_action_->id(), |
| 119 current_tab_id_, current_url_.spec(), button); | 118 current_tab_id_, current_url_.spec(), button); |
| 120 } | 119 } |
| 121 } | 120 } |
| 122 | 121 |
| 123 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) { | 122 void PageActionImageView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 124 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 123 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 125 state->name = UTF8ToUTF16(tooltip_); | 124 state->name = UTF8ToUTF16(tooltip_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 153 if (event.key_code() == ui::VKEY_SPACE || | 152 if (event.key_code() == ui::VKEY_SPACE || |
| 154 event.key_code() == ui::VKEY_RETURN) { | 153 event.key_code() == ui::VKEY_RETURN) { |
| 155 ExecuteAction(1, false); | 154 ExecuteAction(1, false); |
| 156 return true; | 155 return true; |
| 157 } | 156 } |
| 158 return false; | 157 return false; |
| 159 } | 158 } |
| 160 | 159 |
| 161 void PageActionImageView::ShowContextMenu(const gfx::Point& p, | 160 void PageActionImageView::ShowContextMenu(const gfx::Point& p, |
| 162 bool is_mouse_gesture) { | 161 bool is_mouse_gesture) { |
| 163 const Extension* extension = owner_->profile()->GetExtensionService()-> | 162 const Extension* extension = owner_->browser()->profile()-> |
| 164 GetExtensionById(page_action()->extension_id(), false); | 163 GetExtensionService()->GetExtensionById(page_action()->extension_id(), |
| 164 false); |
| 165 if (!extension->ShowConfigureContextMenus()) | 165 if (!extension->ShowConfigureContextMenus()) |
| 166 return; | 166 return; |
| 167 | 167 |
| 168 scoped_refptr<ExtensionContextMenuModel> context_menu_model( | 168 scoped_refptr<ExtensionContextMenuModel> context_menu_model( |
| 169 new ExtensionContextMenuModel(extension, browser_, this)); | 169 new ExtensionContextMenuModel(extension, owner_->browser(), this)); |
| 170 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); | 170 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); |
| 171 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); | 171 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); |
| 172 gfx::Point screen_loc; | 172 gfx::Point screen_loc; |
| 173 views::View::ConvertPointToScreen(this, &screen_loc); | 173 views::View::ConvertPointToScreen(this, &screen_loc); |
| 174 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 174 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 175 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 175 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 176 views::MenuRunner::MENU_DELETED) | 176 views::MenuRunner::MENU_DELETED) |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 const Extension* unloaded_extension = | 281 const Extension* unloaded_extension = |
| 282 content::Details<UnloadedExtensionInfo>(details)->extension; | 282 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 283 if (page_action_ == unloaded_extension ->page_action()) | 283 if (page_action_ == unloaded_extension ->page_action()) |
| 284 owner_->UpdatePageActions(); | 284 owner_->UpdatePageActions(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 void PageActionImageView::HidePopup() { | 287 void PageActionImageView::HidePopup() { |
| 288 if (popup_) | 288 if (popup_) |
| 289 popup_->GetWidget()->Close(); | 289 popup_->GetWidget()->Close(); |
| 290 } | 290 } |
| OLD | NEW |