| 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h" | 7 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h" |
| 8 | 8 |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" | 10 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 PageActionDecoration::PageActionDecoration( | 31 PageActionDecoration::PageActionDecoration( |
| 32 LocationBarViewMac* owner, | 32 LocationBarViewMac* owner, |
| 33 Profile* profile, | 33 Profile* profile, |
| 34 ExtensionAction* page_action) | 34 ExtensionAction* page_action) |
| 35 : owner_(owner), | 35 : owner_(owner), |
| 36 profile_(profile), | 36 profile_(profile), |
| 37 page_action_(page_action), | 37 page_action_(page_action), |
| 38 tracker_(this), | 38 tracker_(this), |
| 39 current_tab_id_(-1), | 39 current_tab_id_(-1), |
| 40 preview_enabled_(false) { | 40 preview_enabled_(false) { |
| 41 DCHECK(profile); |
| 41 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 42 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
| 42 page_action->extension_id(), false); | 43 page_action->extension_id(), false); |
| 43 DCHECK(extension); | 44 DCHECK(extension); |
| 44 | 45 |
| 45 // Load all the icons declared in the manifest. This is the contents of the | 46 // Load all the icons declared in the manifest. This is the contents of the |
| 46 // icons array, plus the default_icon property, if any. | 47 // icons array, plus the default_icon property, if any. |
| 47 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 48 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
| 48 if (!page_action_->default_icon_path().empty()) | 49 if (!page_action_->default_icon_path().empty()) |
| 49 icon_paths.push_back(page_action_->default_icon_path()); | 50 icon_paths.push_back(page_action_->default_icon_path()); |
| 50 | 51 |
| 51 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 52 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
| 52 iter != icon_paths.end(); ++iter) { | 53 iter != icon_paths.end(); ++iter) { |
| 53 tracker_.LoadImage(extension, extension->GetResource(*iter), | 54 tracker_.LoadImage(extension, extension->GetResource(*iter), |
| 54 gfx::Size(Extension::kPageActionIconMaxSize, | 55 gfx::Size(Extension::kPageActionIconMaxSize, |
| 55 Extension::kPageActionIconMaxSize), | 56 Extension::kPageActionIconMaxSize), |
| 56 ImageLoadingTracker::DONT_CACHE); | 57 ImageLoadingTracker::DONT_CACHE); |
| 57 } | 58 } |
| 58 | 59 |
| 59 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 60 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 60 Source<Profile>(profile_)); | 61 Source<Profile>(profile_)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 PageActionDecoration::~PageActionDecoration() { | 64 PageActionDecoration::~PageActionDecoration() {} |
| 64 } | |
| 65 | 65 |
| 66 // Always |kPageActionIconMaxSize| wide. |ImageDecoration| draws the | 66 // Always |kPageActionIconMaxSize| wide. |ImageDecoration| draws the |
| 67 // image centered. | 67 // image centered. |
| 68 CGFloat PageActionDecoration::GetWidthForSpace(CGFloat width) { | 68 CGFloat PageActionDecoration::GetWidthForSpace(CGFloat width) { |
| 69 return Extension::kPageActionIconMaxSize; | 69 return Extension::kPageActionIconMaxSize; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Either notify listeners or show a popup depending on the Page | 72 // Either notify listeners or show a popup depending on the Page |
| 73 // Action. | 73 // Action. |
| 74 bool PageActionDecoration::OnMousePressed(NSRect frame) { | 74 bool PageActionDecoration::OnMousePressed(NSRect frame) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if (!profile_) | 212 if (!profile_) |
| 213 return nil; | 213 return nil; |
| 214 ExtensionsService* service = profile_->GetExtensionsService(); | 214 ExtensionsService* service = profile_->GetExtensionsService(); |
| 215 if (!service) | 215 if (!service) |
| 216 return nil; | 216 return nil; |
| 217 Extension* extension = service->GetExtensionById( | 217 Extension* extension = service->GetExtensionById( |
| 218 page_action_->extension_id(), false); | 218 page_action_->extension_id(), false); |
| 219 DCHECK(extension); | 219 DCHECK(extension); |
| 220 if (!extension) | 220 if (!extension) |
| 221 return nil; | 221 return nil; |
| 222 return [[[ExtensionActionContextMenu alloc] | 222 menu_.reset([[ExtensionActionContextMenu alloc] |
| 223 initWithExtension:extension | 223 initWithExtension:extension |
| 224 profile:profile_ | 224 profile:profile_ |
| 225 extensionAction:page_action_] autorelease]; | 225 extensionAction:page_action_]); |
| 226 |
| 227 return menu_.get(); |
| 226 } | 228 } |
| 227 | 229 |
| 228 void PageActionDecoration::Observe( | 230 void PageActionDecoration::Observe( |
| 229 NotificationType type, | 231 NotificationType type, |
| 230 const NotificationSource& source, | 232 const NotificationSource& source, |
| 231 const NotificationDetails& details) { | 233 const NotificationDetails& details) { |
| 232 switch (type.value) { | 234 switch (type.value) { |
| 233 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: { | 235 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: { |
| 234 ExtensionPopupController* popup = [ExtensionPopupController popup]; | 236 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
| 235 if (popup && ![popup isClosing]) | 237 if (popup && ![popup isClosing]) |
| 236 [popup close]; | 238 [popup close]; |
| 237 | 239 |
| 238 break; | 240 break; |
| 239 } | 241 } |
| 240 default: | 242 default: |
| 241 NOTREACHED() << "Unexpected notification"; | 243 NOTREACHED() << "Unexpected notification"; |
| 242 break; | 244 break; |
| 243 } | 245 } |
| 244 } | 246 } |
| OLD | NEW |