| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); | 153 views::MenuModelAdapter menu_model_adapter(context_menu_model.get()); |
| 154 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); | 154 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu())); |
| 155 gfx::Point screen_loc; | 155 gfx::Point screen_loc; |
| 156 views::View::ConvertPointToScreen(this, &screen_loc); | 156 views::View::ConvertPointToScreen(this, &screen_loc); |
| 157 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 157 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
| 158 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 158 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
| 159 views::MenuRunner::MENU_DELETED) | 159 views::MenuRunner::MENU_DELETED) |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void PageActionImageView::OnImageLoaded( | 163 void PageActionImageView::OnImageLoaded(const gfx::Image* image, |
| 164 SkBitmap* image, const ExtensionResource& resource, int index) { | 164 const std::string& extension_id, |
| 165 int index) { |
| 165 // We loaded icons()->size() icons, plus one extra if the page action had | 166 // We loaded icons()->size() icons, plus one extra if the page action had |
| 166 // a default icon. | 167 // a default icon. |
| 167 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 168 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
| 168 if (!page_action_->default_icon_path().empty()) | 169 if (!page_action_->default_icon_path().empty()) |
| 169 total_icons++; | 170 total_icons++; |
| 170 DCHECK(index < total_icons); | 171 DCHECK(index < total_icons); |
| 171 | 172 |
| 172 // Map the index of the loaded image back to its name. If we ever get an | 173 // Map the index of the loaded image back to its name. If we ever get an |
| 173 // index greater than the number of icons, it must be the default icon. | 174 // index greater than the number of icons, it must be the default icon. |
| 174 if (image) { | 175 if (image) { |
| 176 const SkBitmap* bitmap = image->ToSkBitmap(); |
| 175 if (index < static_cast<int>(page_action_->icon_paths()->size())) | 177 if (index < static_cast<int>(page_action_->icon_paths()->size())) |
| 176 page_action_icons_[page_action_->icon_paths()->at(index)] = *image; | 178 page_action_icons_[page_action_->icon_paths()->at(index)] = *bitmap; |
| 177 else | 179 else |
| 178 page_action_icons_[page_action_->default_icon_path()] = *image; | 180 page_action_icons_[page_action_->default_icon_path()] = *bitmap; |
| 179 } | 181 } |
| 180 | 182 |
| 181 // During object construction (before the parent has been set) we are already | 183 // During object construction (before the parent has been set) we are already |
| 182 // in a UpdatePageActions call, so we don't need to start another one (and | 184 // in a UpdatePageActions call, so we don't need to start another one (and |
| 183 // doing so causes crash described in http://crbug.com/57333). | 185 // doing so causes crash described in http://crbug.com/57333). |
| 184 if (parent()) | 186 if (parent()) |
| 185 owner_->UpdatePageActions(); | 187 owner_->UpdatePageActions(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void PageActionImageView::UpdateVisibility(WebContents* contents, | 190 void PageActionImageView::UpdateVisibility(WebContents* contents, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const Extension* unloaded_extension = | 250 const Extension* unloaded_extension = |
| 249 content::Details<UnloadedExtensionInfo>(details)->extension; | 251 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 250 if (page_action_ == unloaded_extension ->page_action()) | 252 if (page_action_ == unloaded_extension ->page_action()) |
| 251 owner_->UpdatePageActions(); | 253 owner_->UpdatePageActions(); |
| 252 } | 254 } |
| 253 | 255 |
| 254 void PageActionImageView::HidePopup() { | 256 void PageActionImageView::HidePopup() { |
| 255 if (popup_) | 257 if (popup_) |
| 256 popup_->GetWidget()->Close(); | 258 popup_->GetWidget()->Close(); |
| 257 } | 259 } |
| OLD | NEW |