| OLD | NEW |
| 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_COCOA_CUSTOM_HOME_PAGES_MODEL_H_ | 5 #ifndef CHROME_BROWSER_COCOA_CUSTOM_HOME_PAGES_MODEL_H_ |
| 6 #define CHROME_BROWSER_COCOA_CUSTOM_HOME_PAGES_MODEL_H_ | 6 #define CHROME_BROWSER_COCOA_CUSTOM_HOME_PAGES_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 #include "base/scoped_nsobject.h" | 12 #include "base/scoped_nsobject.h" |
| 13 #include "chrome/browser/history/history.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 | 15 |
| 15 class Profile; | 16 class Profile; |
| 16 | 17 |
| 17 // The model for the "custom home pages" table in preferences. Contains a list | 18 // The model for the "custom home pages" table in preferences. Contains a list |
| 18 // of CustomHomePageEntry objects. This is intended to be used with Cocoa | 19 // of CustomHomePageEntry objects. This is intended to be used with Cocoa |
| 19 // bindings. | 20 // bindings. |
| 20 // | 21 // |
| 21 // The supported binding is |customHomePages|, a to-many relationship which | 22 // The supported binding is |customHomePages|, a to-many relationship which |
| 22 // can be observed with an array controller. | 23 // can be observed with an array controller. |
| 23 | 24 |
| 24 @interface CustomHomePagesModel : NSObject { | 25 @interface CustomHomePagesModel : NSObject { |
| 25 @private | 26 @private |
| 26 scoped_nsobject<NSMutableArray> entries_; | 27 scoped_nsobject<NSMutableArray> entries_; |
| 27 Profile* profile_; // weak, used for loading favicons | 28 Profile* profile_; // weak, used for loading favicons |
| 28 } | 29 } |
| 29 | 30 |
| 30 // Initialize with |profile|, which must not be NULL. The profile is used for | 31 // Initialize with |profile|, which must not be NULL. The profile is used for |
| 31 // loading favicons for urls. | 32 // loading favicons for urls. |
| 32 - (id)initWithProfile:(Profile*)profile; | 33 - (id)initWithProfile:(Profile*)profile; |
| 33 | 34 |
| 34 // Get/set the urls the model currently contains as a group. Only one change | 35 // Get/set the urls the model currently contains as a group. Only one change |
| 35 // notification will be sent. | 36 // notification will be sent. |
| 36 - (std::vector<GURL>)URLs; | 37 - (std::vector<GURL>)URLs; |
| 37 - (void)setURLs:(const std::vector<GURL>&)urls; | 38 - (void)setURLs:(const std::vector<GURL>&)urls; |
| 38 | 39 |
| 40 // Reloads the URLs from their stored state. This will notify using KVO |
| 41 // |customHomePages|. |
| 42 - (void)reloadURLs; |
| 43 |
| 39 // Validates the set of URLs stored in the model. The user may have input bad | 44 // Validates the set of URLs stored in the model. The user may have input bad |
| 40 // data. This function removes invalid entries from the model, which will result | 45 // data. This function removes invalid entries from the model, which will result |
| 41 // in anyone observing being updated. | 46 // in anyone observing being updated. |
| 42 - (void)validateURLs; | 47 - (void)validateURLs; |
| 43 | 48 |
| 44 // For binding |customHomePages| to a mutable array controller. | 49 // For binding |customHomePages| to a mutable array controller. |
| 45 - (NSUInteger)countOfCustomHomePages; | 50 - (NSUInteger)countOfCustomHomePages; |
| 46 - (id)objectInCustomHomePagesAtIndex:(NSUInteger)index; | 51 - (id)objectInCustomHomePagesAtIndex:(NSUInteger)index; |
| 47 - (void)insertObject:(id)object inCustomHomePagesAtIndex:(NSUInteger)index; | 52 - (void)insertObject:(id)object inCustomHomePagesAtIndex:(NSUInteger)index; |
| 48 - (void)removeObjectFromCustomHomePagesAtIndex:(NSUInteger)index; | 53 - (void)removeObjectFromCustomHomePagesAtIndex:(NSUInteger)index; |
| 49 @end | 54 @end |
| 50 | 55 |
| 51 @interface CustomHomePagesModel(InternalOrTestingAPI) | 56 //////////////////////////////////////////////////////////////////////////////// |
| 57 |
| 58 // An entry representing a single item in the custom home page model. Stores |
| 59 // a url and a favicon. |
| 60 @interface CustomHomePageEntry : NSObject { |
| 61 @private |
| 62 scoped_nsobject<NSString> url_; |
| 63 scoped_nsobject<NSImage> icon_; |
| 64 |
| 65 // If non-zero, indicates we're loading the favicon for the page. |
| 66 HistoryService::Handle icon_handle_; |
| 67 } |
| 68 |
| 69 @property(nonatomic, copy) NSString* URL; |
| 70 @property(nonatomic, retain) NSImage* image; |
| 71 |
| 72 @end |
| 73 |
| 74 //////////////////////////////////////////////////////////////////////////////// |
| 75 |
| 76 @interface CustomHomePagesModel (InternalOrTestingAPI) |
| 52 | 77 |
| 53 // Clears the URL string at the specified index. This constitutes bad data. The | 78 // Clears the URL string at the specified index. This constitutes bad data. The |
| 54 // validator should scrub the entry from the list the next time it is run. | 79 // validator should scrub the entry from the list the next time it is run. |
| 55 - (void) setURLStringEmptyAt:(NSUInteger)index; | 80 - (void)setURLStringEmptyAt:(NSUInteger)index; |
| 56 | 81 |
| 57 @end | 82 @end |
| 58 | 83 |
| 59 // A notification that fires when the URL of one of the entries changes. | 84 // A notification that fires when the URL of one of the entries changes. |
| 60 // Prevents interested parties from having to observe all model objects in order | 85 // Prevents interested parties from having to observe all model objects in order |
| 61 // to persist changes to a single entry. Changes to the number of items in the | 86 // to persist changes to a single entry. Changes to the number of items in the |
| 62 // model can be observed by watching |customHomePages| via KVO so an additional | 87 // model can be observed by watching |customHomePages| via KVO so an additional |
| 63 // notification is not sent. | 88 // notification is not sent. |
| 64 extern NSString* const kHomepageEntryChangedNotification; | 89 extern NSString* const kHomepageEntryChangedNotification; |
| 65 | 90 |
| 66 #endif // CHROME_BROWSER_COCOA_CUSTOM_HOME_PAGES_MODEL_H_ | 91 #endif // CHROME_BROWSER_COCOA_CUSTOM_HOME_PAGES_MODEL_H_ |
| OLD | NEW |