15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PrefRegistrySimple; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TemplateURL; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TemplateURLService; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TemplateURLTableModel; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class KeywordEditorController { 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit KeywordEditorController(Profile* profile); 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~KeywordEditorController(); 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static void RegisterPrefs(PrefRegistrySimple* registry); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the user succesfully fills out the add keyword dialog. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Propagates the change to the TemplateURLService and updates the table 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // model. Returns the index of the added URL. 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int AddTemplateURL(const base::string16& title, 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& keyword, 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& url); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the user modifies a TemplateURL. Updates the 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TemplateURLService and table model appropriately. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ModifyTemplateURL(TemplateURL* template_url, 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& title, 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& keyword, 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& url); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return true if the given |url| can be edited. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanEdit(const TemplateURL* url) const; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return true if the given |url| can be made the default. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanMakeDefault(const TemplateURL* url) const; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return true if the given |url| can be removed. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanRemove(const TemplateURL* url) const; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove the TemplateURL at the specified index in the TableModel. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveTemplateURL(int index); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make the TemplateURL at the specified index (into the TableModel) the 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // default search provider. Return the new index, or -1 if nothing was done. 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int MakeDefaultTemplateURL(int index); 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return true if the |url_model_| data is loaded. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool loaded() const; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return the TemplateURL corresponding to the |index| in the model. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TemplateURL* GetTemplateURL(int index); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TemplateURLTableModel* table_model() { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return table_model_.get(); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TemplateURLService* url_model() const; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The profile. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Model for the TableView. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<TemplateURLTableModel> table_model_; 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(KeywordEditorController); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_ 80