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