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