OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/location_bar/page_action_image_view.h" | 5 #include "chrome/browser/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/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
9 #include "chrome/browser/extensions/extension_browser_event_router.h" | 9 #include "chrome/browser/extensions/extension_browser_event_router.h" |
10 #include "chrome/browser/extensions/extensions_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/views/frame/browser_view.h" | 12 #include "chrome/browser/views/frame/browser_view.h" |
13 #include "chrome/browser/views/location_bar/location_bar_view.h" | 13 #include "chrome/browser/views/location_bar/location_bar_view.h" |
14 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
15 #include "chrome/common/extensions/extension_action.h" | 15 #include "chrome/common/extensions/extension_action.h" |
16 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
17 #include "views/controls/menu/menu_2.h" | 17 #include "views/controls/menu/menu_2.h" |
18 | 18 |
19 PageActionImageView::PageActionImageView(LocationBarView* owner, | 19 PageActionImageView::PageActionImageView(LocationBarView* owner, |
20 Profile* profile, | 20 Profile* profile, |
21 ExtensionAction* page_action) | 21 ExtensionAction* page_action) |
22 : owner_(owner), | 22 : owner_(owner), |
23 profile_(profile), | 23 profile_(profile), |
24 page_action_(page_action), | 24 page_action_(page_action), |
25 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 25 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
26 current_tab_id_(-1), | 26 current_tab_id_(-1), |
27 preview_enabled_(false), | 27 preview_enabled_(false), |
28 popup_(NULL) { | 28 popup_(NULL) { |
29 const Extension* extension = profile->GetExtensionsService()-> | 29 const Extension* extension = profile->GetExtensionService()-> |
30 GetExtensionById(page_action->extension_id(), false); | 30 GetExtensionById(page_action->extension_id(), false); |
31 DCHECK(extension); | 31 DCHECK(extension); |
32 | 32 |
33 // Load all the icons declared in the manifest. This is the contents of the | 33 // Load all the icons declared in the manifest. This is the contents of the |
34 // icons array, plus the default_icon property, if any. | 34 // icons array, plus the default_icon property, if any. |
35 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 35 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
36 if (!page_action_->default_icon_path().empty()) | 36 if (!page_action_->default_icon_path().empty()) |
37 icon_paths.push_back(page_action_->default_icon_path()); | 37 icon_paths.push_back(page_action_->default_icon_path()); |
38 | 38 |
39 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 39 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (e.GetKeyCode() == app::VKEY_SPACE || | 139 if (e.GetKeyCode() == app::VKEY_SPACE || |
140 e.GetKeyCode() == app::VKEY_RETURN) { | 140 e.GetKeyCode() == app::VKEY_RETURN) { |
141 ExecuteAction(1, false); | 141 ExecuteAction(1, false); |
142 return true; | 142 return true; |
143 } | 143 } |
144 return false; | 144 return false; |
145 } | 145 } |
146 | 146 |
147 void PageActionImageView::ShowContextMenu(const gfx::Point& p, | 147 void PageActionImageView::ShowContextMenu(const gfx::Point& p, |
148 bool is_mouse_gesture) { | 148 bool is_mouse_gesture) { |
149 const Extension* extension = profile_->GetExtensionsService()-> | 149 const Extension* extension = profile_->GetExtensionService()-> |
150 GetExtensionById(page_action()->extension_id(), false); | 150 GetExtensionById(page_action()->extension_id(), false); |
151 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( | 151 Browser* browser = BrowserView::GetBrowserViewForNativeWindow( |
152 platform_util::GetTopLevel(GetWidget()->GetNativeView()))->browser(); | 152 platform_util::GetTopLevel(GetWidget()->GetNativeView()))->browser(); |
153 context_menu_contents_ = | 153 context_menu_contents_ = |
154 new ExtensionContextMenuModel(extension, browser, this); | 154 new ExtensionContextMenuModel(extension, browser, this); |
155 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 155 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
156 context_menu_menu_->RunContextMenuAt(p); | 156 context_menu_menu_->RunContextMenuAt(p); |
157 } | 157 } |
158 | 158 |
159 void PageActionImageView::OnImageLoaded( | 159 void PageActionImageView::OnImageLoaded( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) { | 234 void PageActionImageView::ExtensionPopupIsClosing(ExtensionPopup* popup) { |
235 DCHECK_EQ(popup_, popup); | 235 DCHECK_EQ(popup_, popup); |
236 // ExtensionPopup is ref-counted, so we don't need to delete it. | 236 // ExtensionPopup is ref-counted, so we don't need to delete it. |
237 popup_ = NULL; | 237 popup_ = NULL; |
238 } | 238 } |
239 | 239 |
240 void PageActionImageView::HidePopup() { | 240 void PageActionImageView::HidePopup() { |
241 if (popup_) | 241 if (popup_) |
242 popup_->Close(); | 242 popup_->Close(); |
243 } | 243 } |
OLD | NEW |