| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
| 10 #include "grit/ui_resources.h" |
| 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/image/image.h" |
| 13 |
| 14 WebIntentPickerModel::WebIntentPickerModel() |
| 15 : observer_(NULL), |
| 16 inline_disposition_index_(std::string::npos) { |
| 17 } |
| 18 |
| 19 WebIntentPickerModel::~WebIntentPickerModel() { |
| 20 DestroyItems(); |
| 21 } |
| 22 |
| 23 void WebIntentPickerModel::AddItem(const string16& title, |
| 24 const GURL& url, |
| 25 Disposition disposition) { |
| 26 items_.push_back(new Item(title, url, disposition)); |
| 27 if (observer_) |
| 28 observer_->OnModelChanged(this); |
| 29 } |
| 30 |
| 31 void WebIntentPickerModel::RemoveItemAt(size_t index) { |
| 32 DCHECK(index < items_.size()); |
| 33 std::vector<Item*>::iterator iter = items_.begin() + index; |
| 34 delete *iter; |
| 35 items_.erase(iter); |
| 36 if (observer_) |
| 37 observer_->OnModelChanged(this); |
| 38 } |
| 39 |
| 40 void WebIntentPickerModel::Clear() { |
| 41 DestroyItems(); |
| 42 inline_disposition_index_ = std::string::npos; |
| 43 if (observer_) |
| 44 observer_->OnModelChanged(this); |
| 45 } |
| 46 |
| 47 const WebIntentPickerModel::Item& WebIntentPickerModel::GetItemAt( |
| 48 size_t index) const { |
| 49 DCHECK(index < items_.size()); |
| 50 return *items_[index]; |
| 51 } |
| 52 |
| 53 size_t WebIntentPickerModel::GetItemCount() const { |
| 54 return items_.size(); |
| 55 } |
| 56 |
| 57 void WebIntentPickerModel::UpdateFaviconAt(size_t index, |
| 58 const gfx::Image& image) { |
| 59 DCHECK(index < items_.size()); |
| 60 items_[index]->favicon = image; |
| 61 if (observer_) |
| 62 observer_->OnFaviconChanged(this, index); |
| 63 } |
| 64 |
| 65 void WebIntentPickerModel::SetInlineDisposition(size_t index) { |
| 66 DCHECK(index < items_.size()); |
| 67 inline_disposition_index_ = index; |
| 68 if (observer_) |
| 69 observer_->OnInlineDisposition(this); |
| 70 } |
| 71 |
| 72 bool WebIntentPickerModel::IsInlineDisposition() const { |
| 73 return inline_disposition_index_ != std::string::npos; |
| 74 } |
| 75 |
| 76 void WebIntentPickerModel::DestroyItems() { |
| 77 STLDeleteElements(&items_); |
| 78 } |
| 79 |
| 80 WebIntentPickerModel::Item::Item(const string16& title, |
| 81 const GURL& url, |
| 82 Disposition disposition) |
| 83 : title(title), |
| 84 url(url), |
| 85 favicon(ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 86 IDR_DEFAULT_FAVICON)), |
| 87 disposition(disposition) { |
| 88 } |
| 89 |
| 90 WebIntentPickerModel::Item::~Item() { |
| 91 } |
| OLD | NEW |