| 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 #import "chrome/browser/cocoa/extensions/browser_action_button.h" | 5 #import "chrome/browser/cocoa/extensions/browser_action_button.h" |
| 6 | 6 |
| 7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/browser/cocoa/extensions/extension_action_context_menu.h" | 8 #include "chrome/browser/cocoa/extensions/extension_action_context_menu.h" |
| 9 #include "chrome/browser/extensions/image_loading_tracker.h" | 9 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const CGFloat kShadowOffset = 2.0; | 35 const CGFloat kShadowOffset = 2.0; |
| 36 } // anonymous namespace | 36 } // anonymous namespace |
| 37 | 37 |
| 38 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to | 38 // A helper class to bridge the asynchronous Skia bitmap loading mechanism to |
| 39 // the extension's button. | 39 // the extension's button. |
| 40 class ExtensionImageTrackerBridge : public NotificationObserver, | 40 class ExtensionImageTrackerBridge : public NotificationObserver, |
| 41 public ImageLoadingTracker::Observer { | 41 public ImageLoadingTracker::Observer { |
| 42 public: | 42 public: |
| 43 ExtensionImageTrackerBridge(BrowserActionButton* owner, Extension* extension) | 43 ExtensionImageTrackerBridge(BrowserActionButton* owner, Extension* extension) |
| 44 : owner_(owner), | 44 : owner_(owner), |
| 45 tracker_(NULL) { | 45 tracker_(this) { |
| 46 // The Browser Action API does not allow the default icon path to be | 46 // The Browser Action API does not allow the default icon path to be |
| 47 // changed at runtime, so we can load this now and cache it. | 47 // changed at runtime, so we can load this now and cache it. |
| 48 std::string path = extension->browser_action()->default_icon_path(); | 48 std::string path = extension->browser_action()->default_icon_path(); |
| 49 if (!path.empty()) { | 49 if (!path.empty()) { |
| 50 tracker_ = new ImageLoadingTracker(this, 1); | 50 tracker_.LoadImage(extension->GetResource(path), |
| 51 tracker_->PostLoadImageTask(extension->GetResource(path), | |
| 52 gfx::Size(Extension::kBrowserActionIconMaxSize, | 51 gfx::Size(Extension::kBrowserActionIconMaxSize, |
| 53 Extension::kBrowserActionIconMaxSize)); | 52 Extension::kBrowserActionIconMaxSize)); |
| 54 } | 53 } |
| 55 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, | 54 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, |
| 56 Source<ExtensionAction>(extension->browser_action())); | 55 Source<ExtensionAction>(extension->browser_action())); |
| 57 } | 56 } |
| 58 | 57 |
| 59 ~ExtensionImageTrackerBridge() { | 58 ~ExtensionImageTrackerBridge() { |
| 60 if (tracker_) | |
| 61 tracker_->StopTrackingImageLoad(); | |
| 62 } | 59 } |
| 63 | 60 |
| 64 // ImageLoadingTracker::Observer implementation. | 61 // ImageLoadingTracker::Observer implementation. |
| 65 void OnImageLoaded(SkBitmap* image, size_t index) { | 62 void OnImageLoaded(SkBitmap* image, ExtensionResource resource, int index) { |
| 66 if (image) | 63 if (image) |
| 67 [owner_ setDefaultIcon:gfx::SkBitmapToNSImage(*image)]; | 64 [owner_ setDefaultIcon:gfx::SkBitmapToNSImage(*image)]; |
| 68 tracker_ = NULL; | |
| 69 [owner_ updateState]; | 65 [owner_ updateState]; |
| 70 } | 66 } |
| 71 | 67 |
| 72 // Overridden from NotificationObserver. | 68 // Overridden from NotificationObserver. |
| 73 void Observe(NotificationType type, | 69 void Observe(NotificationType type, |
| 74 const NotificationSource& source, | 70 const NotificationSource& source, |
| 75 const NotificationDetails& details) { | 71 const NotificationDetails& details) { |
| 76 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) | 72 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) |
| 77 [owner_ updateState]; | 73 [owner_ updateState]; |
| 78 else | 74 else |
| 79 NOTREACHED(); | 75 NOTREACHED(); |
| 80 } | 76 } |
| 81 | 77 |
| 82 private: | 78 private: |
| 83 // Weak. Owns us. | 79 // Weak. Owns us. |
| 84 BrowserActionButton* owner_; | 80 BrowserActionButton* owner_; |
| 85 | 81 |
| 86 // Loads the button's icons for us on the file thread. Weak. | 82 // Loads the button's icons for us on the file thread. |
| 87 ImageLoadingTracker* tracker_; | 83 ImageLoadingTracker tracker_; |
| 88 | 84 |
| 89 // Used for registering to receive notifications and automatic clean up. | 85 // Used for registering to receive notifications and automatic clean up. |
| 90 NotificationRegistrar registrar_; | 86 NotificationRegistrar registrar_; |
| 91 | 87 |
| 92 DISALLOW_COPY_AND_ASSIGN(ExtensionImageTrackerBridge); | 88 DISALLOW_COPY_AND_ASSIGN(ExtensionImageTrackerBridge); |
| 93 }; | 89 }; |
| 94 | 90 |
| 95 @interface BrowserActionCell(Internals) | 91 @interface BrowserActionCell(Internals) |
| 96 - (void)setIconShadow; | 92 - (void)setIconShadow; |
| 97 - (void)drawBadgeWithinFrame:(NSRect)frame; | 93 - (void)drawBadgeWithinFrame:(NSRect)frame; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 243 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 248 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; | 244 cellFrame.origin.y += kBrowserActionBadgeOriginYOffset; |
| 249 [self drawBadgeWithinFrame:cellFrame]; | 245 [self drawBadgeWithinFrame:cellFrame]; |
| 250 [NSGraphicsContext restoreGraphicsState]; | 246 [NSGraphicsContext restoreGraphicsState]; |
| 251 } | 247 } |
| 252 | 248 |
| 253 @synthesize tabId = tabId_; | 249 @synthesize tabId = tabId_; |
| 254 @synthesize extensionAction = extensionAction_; | 250 @synthesize extensionAction = extensionAction_; |
| 255 | 251 |
| 256 @end | 252 @end |
| OLD | NEW |