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
92
93
94
95
96
97
98
99
|
// Copyright (c) 2009 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_SEARCH_ENGINES_EDIT_KEYWORD_CONTROLLER_BASE_H_
#define CHROME_BROWSER_SEARCH_ENGINES_EDIT_KEYWORD_CONTROLLER_BASE_H_
#include <string>
#include "base/gfx/native_widget_types.h"
class Profile;
class TemplateURL;
// EditKeywordControllerBase provides the platform independent logic and
// interface for implementing a dialog for editing keyword searches.
class EditKeywordControllerBase {
public:
class Delegate {
public:
virtual ~Delegate() {}
// Invoked from the EditKeywordController when the user accepts the edits.
// NOTE: |template_url| is the value supplied to EditKeywordController's
// constructor, and may be null. A null value indicates a new TemplateURL
// should be created rather than modifying an existing TemplateURL.
virtual void OnEditedKeyword(const TemplateURL* template_url,
const std::wstring& title,
const std::wstring& keyword,
const std::wstring& url) = 0;
};
// Create and show the platform's implementation of the dialog.
static void Create(gfx::NativeWindow parent_window,
const TemplateURL* template_url,
Delegate* delegate,
Profile* profile);
// The |template_url| and/or |edit_keyword_delegate| may be NULL.
EditKeywordControllerBase(const TemplateURL* template_url,
Delegate* edit_keyword_delegate,
Profile* profile);
virtual ~EditKeywordControllerBase() {}
protected:
// Interface to platform specific view
virtual std::wstring GetURLInput() const = 0;
virtual std::wstring GetKeywordInput() const = 0;
virtual std::wstring GetTitleInput() const = 0;
// Check if content of Title entry is valid.
bool IsTitleValid() const;
// Returns true if the currently input URL is valid. The URL is valid if it
// contains no search terms and is a valid url, or if it contains a search
// term and replacing that search term with a character results in a valid
// url.
bool IsURLValid() const;
// Fixes up and returns the URL the user has input. The returned URL is
// suitable for use by TemplateURL.
std::wstring GetURL() const;
// Returns whether the currently entered keyword is valid. The keyword is
// valid if it is non-empty and does not conflict with an existing entry.
// NOTE: this is just the keyword, not the title and url.
bool IsKeywordValid() const;
// Deletes an unused TemplateURL, if its add was cancelled and it's not
// already owned by the TemplateURLModel.
void AcceptAddOrEdit();
// Deletes an unused TemplateURL, if its add was cancelled and it's not
// already owned by the TemplateURLModel.
void CleanUpCancelledAdd();
const TemplateURL* template_url() const {
return template_url_;
}
const Profile* profile() const {
return profile_;
}
private:
// The TemplateURL we're displaying information for. It may be NULL. If we
// have a keyword_editor_view, we assume that this TemplateURL is already in
// the TemplateURLModel; if not, we assume it isn't.
const TemplateURL* template_url_;
// We may have been created by this, in which case we will call back to it on
// success to add/modify the entry. May be NULL.
Delegate* edit_keyword_delegate_;
// Profile whose TemplateURLModel we're modifying.
Profile* profile_;
};
#endif // CHROME_BROWSER_SEARCH_ENGINES_EDIT_KEYWORD_CONTROLLER_BASE_H_
|