| 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/location_bar_view_mac.h" | 5 #import "chrome/browser/cocoa/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 611 |
| 612 // PageActionImageView---------------------------------------------------------- | 612 // PageActionImageView---------------------------------------------------------- |
| 613 | 613 |
| 614 LocationBarViewMac::PageActionImageView::PageActionImageView( | 614 LocationBarViewMac::PageActionImageView::PageActionImageView( |
| 615 LocationBarViewMac* owner, | 615 LocationBarViewMac* owner, |
| 616 Profile* profile, | 616 Profile* profile, |
| 617 ExtensionAction* page_action) | 617 ExtensionAction* page_action) |
| 618 : owner_(owner), | 618 : owner_(owner), |
| 619 profile_(profile), | 619 profile_(profile), |
| 620 page_action_(page_action), | 620 page_action_(page_action), |
| 621 tracker_(this), |
| 621 current_tab_id_(-1), | 622 current_tab_id_(-1), |
| 622 preview_enabled_(false) { | 623 preview_enabled_(false) { |
| 623 Extension* extension = profile->GetExtensionsService()->GetExtensionById( | 624 Extension* extension = profile->GetExtensionsService()->GetExtensionById( |
| 624 page_action->extension_id(), false); | 625 page_action->extension_id(), false); |
| 625 DCHECK(extension); | 626 DCHECK(extension); |
| 626 | 627 |
| 627 // Load all the icons declared in the manifest. This is the contents of the | 628 // Load all the icons declared in the manifest. This is the contents of the |
| 628 // icons array, plus the default_icon property, if any. | 629 // icons array, plus the default_icon property, if any. |
| 629 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 630 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
| 630 if (!page_action_->default_icon_path().empty()) | 631 if (!page_action_->default_icon_path().empty()) |
| 631 icon_paths.push_back(page_action_->default_icon_path()); | 632 icon_paths.push_back(page_action_->default_icon_path()); |
| 632 | 633 |
| 633 tracker_ = new ImageLoadingTracker(this, icon_paths.size()); | |
| 634 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 634 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
| 635 iter != icon_paths.end(); ++iter) { | 635 iter != icon_paths.end(); ++iter) { |
| 636 tracker_->PostLoadImageTask(extension->GetResource(*iter), | 636 tracker_.LoadImage(extension->GetResource(*iter), |
| 637 gfx::Size(Extension::kPageActionIconMaxSize, | 637 gfx::Size(Extension::kPageActionIconMaxSize, |
| 638 Extension::kPageActionIconMaxSize)); | 638 Extension::kPageActionIconMaxSize)); |
| 639 } | 639 } |
| 640 | 640 |
| 641 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 641 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 642 Source<Profile>(profile_)); | 642 Source<Profile>(profile_)); |
| 643 } | 643 } |
| 644 | 644 |
| 645 LocationBarViewMac::PageActionImageView::~PageActionImageView() { | 645 LocationBarViewMac::PageActionImageView::~PageActionImageView() { |
| 646 if (tracker_) | |
| 647 tracker_->StopTrackingImageLoad(); | |
| 648 } | 646 } |
| 649 | 647 |
| 650 NSSize LocationBarViewMac::PageActionImageView::GetPreferredImageSize() { | 648 NSSize LocationBarViewMac::PageActionImageView::GetPreferredImageSize() { |
| 651 NSImage* image = GetImage(); | 649 NSImage* image = GetImage(); |
| 652 if (image) { | 650 if (image) { |
| 653 return [image size]; | 651 return [image size]; |
| 654 } else { | 652 } else { |
| 655 return NSMakeSize(Extension::kPageActionIconMaxSize, | 653 return NSMakeSize(Extension::kPageActionIconMaxSize, |
| 656 Extension::kPageActionIconMaxSize); | 654 Extension::kPageActionIconMaxSize); |
| 657 } | 655 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 682 anchoredAt:arrowPoint | 680 anchoredAt:arrowPoint |
| 683 arrowLocation:kTopRight]; | 681 arrowLocation:kTopRight]; |
| 684 } else { | 682 } else { |
| 685 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( | 683 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
| 686 profile_, page_action_->extension_id(), page_action_->id(), | 684 profile_, page_action_->extension_id(), page_action_->id(), |
| 687 current_tab_id_, current_url_.spec(), | 685 current_tab_id_, current_url_.spec(), |
| 688 1); | 686 1); |
| 689 } | 687 } |
| 690 } | 688 } |
| 691 | 689 |
| 692 void LocationBarViewMac::PageActionImageView::OnImageLoaded(SkBitmap* image, | 690 void LocationBarViewMac::PageActionImageView::OnImageLoaded( |
| 693 size_t index) { | 691 SkBitmap* image, ExtensionResource resource, int index) { |
| 694 // We loaded icons()->size() icons, plus one extra if the Page Action had | 692 // We loaded icons()->size() icons, plus one extra if the Page Action had |
| 695 // a default icon. | 693 // a default icon. |
| 696 int total_icons = page_action_->icon_paths()->size(); | 694 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
| 697 if (!page_action_->default_icon_path().empty()) | 695 if (!page_action_->default_icon_path().empty()) |
| 698 total_icons++; | 696 total_icons++; |
| 699 DCHECK(static_cast<int>(index) < total_icons); | 697 DCHECK(index < total_icons); |
| 700 | 698 |
| 701 // Map the index of the loaded image back to its name. If we ever get an | 699 // Map the index of the loaded image back to its name. If we ever get an |
| 702 // index greater than the number of icons, it must be the default icon. | 700 // index greater than the number of icons, it must be the default icon. |
| 703 if (image) { | 701 if (image) { |
| 704 if (index < page_action_->icon_paths()->size()) | 702 if (index < static_cast<int>(page_action_->icon_paths()->size())) |
| 705 page_action_icons_[page_action_->icon_paths()->at(index)] = *image; | 703 page_action_icons_[page_action_->icon_paths()->at(index)] = *image; |
| 706 else | 704 else |
| 707 page_action_icons_[page_action_->default_icon_path()] = *image; | 705 page_action_icons_[page_action_->default_icon_path()] = *image; |
| 708 } | 706 } |
| 709 | 707 |
| 710 // If we are done, release the tracker. | |
| 711 if (static_cast<int>(index) == (total_icons - 1)) | |
| 712 tracker_ = NULL; | |
| 713 | |
| 714 owner_->UpdatePageActions(); | 708 owner_->UpdatePageActions(); |
| 715 | 709 |
| 716 if (preview_enabled_) | 710 if (preview_enabled_) |
| 717 [owner_->GetAutocompleteTextField() display]; | 711 [owner_->GetAutocompleteTextField() display]; |
| 718 } | 712 } |
| 719 | 713 |
| 720 void LocationBarViewMac::PageActionImageView::UpdateVisibility( | 714 void LocationBarViewMac::PageActionImageView::UpdateVisibility( |
| 721 TabContents* contents, const GURL& url) { | 715 TabContents* contents, const GURL& url) { |
| 722 // Save this off so we can pass it back to the extension when the action gets | 716 // Save this off so we can pass it back to the extension when the action gets |
| 723 // executed. See PageActionImageView::OnMousePressed. | 717 // executed. See PageActionImageView::OnMousePressed. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 951 ++result; | 945 ++result; |
| 952 } | 946 } |
| 953 return result; | 947 return result; |
| 954 } | 948 } |
| 955 | 949 |
| 956 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, | 950 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, |
| 957 size_t index) { | 951 size_t index) { |
| 958 ViewAt(index)->OnMousePressed(iconFrame); | 952 ViewAt(index)->OnMousePressed(iconFrame); |
| 959 } | 953 } |
| 960 | 954 |
| OLD | NEW |