1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_
10 #include "base/strings/string16.h"
11 #include "ui/gfx/native_widget_types.h"
16 class EditSearchEngineControllerDelegate
{
18 // Invoked from the EditSearchEngineController when the user accepts the
19 // edits. NOTE: |template_url| is the value supplied to
20 // EditSearchEngineController's constructor, and may be NULL. A NULL value
21 // indicates a new TemplateURL should be created rather than modifying an
22 // existing TemplateURL.
23 virtual void OnEditedKeyword(TemplateURL
* template_url
,
24 const base::string16
& title
,
25 const base::string16
& keyword
,
26 const std::string
& url
) = 0;
29 virtual ~EditSearchEngineControllerDelegate() {}
32 // EditSearchEngineController provides the core platform independent logic
33 // for the Edit Search Engine dialog.
34 class EditSearchEngineController
{
36 // The |template_url| and/or |edit_keyword_delegate| may be NULL.
37 EditSearchEngineController(
38 TemplateURL
* template_url
,
39 EditSearchEngineControllerDelegate
* edit_keyword_delegate
,
41 ~EditSearchEngineController() {}
43 // Returns true if the value of |title_input| is a valid search engine name.
44 bool IsTitleValid(const base::string16
& title_input
) const;
46 // Returns true if the value of |url_input| represents a valid search engine
47 // URL. The URL is valid if it contains no search terms and is a valid
48 // url, or if it contains a search term and replacing that search term with a
49 // character results in a valid url.
50 bool IsURLValid(const std::string
& url_input
) const;
52 // Returns true if the value of |keyword_input| represents a valid keyword.
53 // The keyword is valid if it is non-empty and does not conflict with an
54 // existing entry. NOTE: this is just the keyword, not the title and url.
55 bool IsKeywordValid(const base::string16
& keyword_input
) const;
57 // Completes the add or edit of a search engine.
58 void AcceptAddOrEdit(const base::string16
& title_input
,
59 const base::string16
& keyword_input
,
60 const std::string
& url_input
);
62 // Deletes an unused TemplateURL, if its add was cancelled and it's not
63 // already owned by the TemplateURLService.
64 void CleanUpCancelledAdd();
67 const TemplateURL
* template_url() const { return template_url_
; }
68 Profile
* profile() const { return profile_
; }
71 // Fixes up and returns the URL the user has input. The returned URL is
72 // suitable for use by TemplateURL.
73 std::string
GetFixedUpURL(const std::string
& url_input
) const;
75 // The TemplateURL we're displaying information for. It may be NULL. If we
76 // have a keyword_editor_view, we assume that this TemplateURL is already in
77 // the TemplateURLService; if not, we assume it isn't.
78 TemplateURL
* template_url_
;
80 // We may have been created by this, in which case we will call back to it on
81 // success to add/modify the entry. May be NULL.
82 EditSearchEngineControllerDelegate
* edit_keyword_delegate_
;
84 // Profile whose TemplateURLService we're modifying.
87 DISALLOW_COPY_AND_ASSIGN(EditSearchEngineController
);
90 #endif // CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_