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