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