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