Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 6291003: Revert 71485 - Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include "app/message_box_flags.h" 7 #include "app/message_box_flags.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/json/string_escape.h" 11 #include "base/json/string_escape.h"
(...skipping 2668 matching lines...) Expand 10 before | Expand all | Expand 10 after
2680 Browser* browser, 2680 Browser* browser,
2681 DictionaryValue* args, 2681 DictionaryValue* args,
2682 IPC::Message* reply_message) { 2682 IPC::Message* reply_message) {
2683 TemplateURLModel* url_model(profile_->GetTemplateURLModel()); 2683 TemplateURLModel* url_model(profile_->GetTemplateURLModel());
2684 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 2684 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
2685 ListValue* search_engines = new ListValue; 2685 ListValue* search_engines = new ListValue;
2686 std::vector<const TemplateURL*> template_urls = url_model->GetTemplateURLs(); 2686 std::vector<const TemplateURL*> template_urls = url_model->GetTemplateURLs();
2687 for (std::vector<const TemplateURL*>::const_iterator it = 2687 for (std::vector<const TemplateURL*>::const_iterator it =
2688 template_urls.begin(); it != template_urls.end(); ++it) { 2688 template_urls.begin(); it != template_urls.end(); ++it) {
2689 DictionaryValue* search_engine = new DictionaryValue; 2689 DictionaryValue* search_engine = new DictionaryValue;
2690 search_engine->SetString("short_name", UTF16ToUTF8((*it)->short_name())); 2690 search_engine->SetString("short_name", WideToUTF8((*it)->short_name()));
2691 search_engine->SetString("description", UTF16ToUTF8((*it)->description())); 2691 search_engine->SetString("description", WideToUTF8((*it)->description()));
2692 search_engine->SetString("keyword", UTF16ToUTF8((*it)->keyword())); 2692 search_engine->SetString("keyword", WideToUTF8((*it)->keyword()));
2693 search_engine->SetBoolean("in_default_list", (*it)->ShowInDefaultList()); 2693 search_engine->SetBoolean("in_default_list", (*it)->ShowInDefaultList());
2694 search_engine->SetBoolean("is_default", 2694 search_engine->SetBoolean("is_default",
2695 (*it) == url_model->GetDefaultSearchProvider()); 2695 (*it) == url_model->GetDefaultSearchProvider());
2696 search_engine->SetBoolean("is_valid", (*it)->url()->IsValid()); 2696 search_engine->SetBoolean("is_valid", (*it)->url()->IsValid());
2697 search_engine->SetBoolean("supports_replacement", 2697 search_engine->SetBoolean("supports_replacement",
2698 (*it)->url()->SupportsReplacement()); 2698 (*it)->url()->SupportsReplacement());
2699 search_engine->SetString("url", (*it)->url()->url()); 2699 search_engine->SetString("url", (*it)->url()->url());
2700 search_engine->SetString("host", (*it)->url()->GetHost()); 2700 search_engine->SetString("host", (*it)->url()->GetHost());
2701 search_engine->SetString("path", (*it)->url()->GetPath()); 2701 search_engine->SetString("path", (*it)->url()->GetPath());
2702 search_engine->SetString("display_url", 2702 search_engine->SetString("display_url",
2703 UTF16ToUTF8((*it)->url()->DisplayURL())); 2703 WideToUTF8((*it)->url()->DisplayURL()));
2704 search_engines->Append(search_engine); 2704 search_engines->Append(search_engine);
2705 } 2705 }
2706 return_value->Set("search_engines", search_engines); 2706 return_value->Set("search_engines", search_engines);
2707 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); 2707 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
2708 } 2708 }
2709 2709
2710 // Refer to pyauto.py for sample JSON input. 2710 // Refer to pyauto.py for sample JSON input.
2711 void TestingAutomationProvider::AddOrEditSearchEngine( 2711 void TestingAutomationProvider::AddOrEditSearchEngine(
2712 Browser* browser, 2712 Browser* browser,
2713 DictionaryValue* args, 2713 DictionaryValue* args,
2714 IPC::Message* reply_message) { 2714 IPC::Message* reply_message) {
2715 TemplateURLModel* url_model(profile_->GetTemplateURLModel()); 2715 TemplateURLModel* url_model(profile_->GetTemplateURLModel());
2716 const TemplateURL* template_url; 2716 const TemplateURL* template_url;
2717 string16 new_title; 2717 string16 new_title;
2718 string16 new_keyword; 2718 string16 new_keyword;
2719 std::string new_url; 2719 std::string new_url;
2720 std::string keyword; 2720 std::string keyword;
2721 if (!args->GetString("new_title", &new_title) || 2721 if (!args->GetString("new_title", &new_title) ||
2722 !args->GetString("new_keyword", &new_keyword) || 2722 !args->GetString("new_keyword", &new_keyword) ||
2723 !args->GetString("new_url", &new_url)) { 2723 !args->GetString("new_url", &new_url)) {
2724 AutomationJSONReply(this, reply_message).SendError( 2724 AutomationJSONReply(this, reply_message).SendError(
2725 "One or more inputs invalid"); 2725 "One or more inputs invalid");
2726 return; 2726 return;
2727 } 2727 }
2728 std::string new_ref_url = TemplateURLRef::DisplayURLToURLRef( 2728 std::string new_ref_url = TemplateURLRef::DisplayURLToURLRef(
2729 UTF8ToUTF16(new_url)); 2729 UTF8ToWide(new_url));
2730 scoped_ptr<KeywordEditorController> controller( 2730 scoped_ptr<KeywordEditorController> controller(
2731 new KeywordEditorController(profile_)); 2731 new KeywordEditorController(profile_));
2732 if (args->GetString("keyword", &keyword)) { 2732 if (args->GetString("keyword", &keyword)) {
2733 template_url = url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword)); 2733 template_url = url_model->GetTemplateURLForKeyword(UTF8ToWide(keyword));
2734 if (template_url == NULL) { 2734 if (template_url == NULL) {
2735 AutomationJSONReply(this, reply_message).SendError( 2735 AutomationJSONReply(this, reply_message).SendError(
2736 StringPrintf("No match for keyword: %s", keyword.c_str())); 2736 StringPrintf("No match for keyword: %s", keyword.c_str()));
2737 return; 2737 return;
2738 } 2738 }
2739 url_model->AddObserver(new AutomationProviderSearchEngineObserver( 2739 url_model->AddObserver(new AutomationProviderSearchEngineObserver(
2740 this, reply_message)); 2740 this, reply_message));
2741 controller->ModifyTemplateURL(template_url, new_title, new_keyword, 2741 controller->ModifyTemplateURL(template_url, new_title, new_keyword,
2742 new_ref_url); 2742 new_ref_url);
2743 } else { 2743 } else {
(...skipping 12 matching lines...) Expand all
2756 TemplateURLModel* url_model(profile_->GetTemplateURLModel()); 2756 TemplateURLModel* url_model(profile_->GetTemplateURLModel());
2757 std::string keyword; 2757 std::string keyword;
2758 std::string action; 2758 std::string action;
2759 if (!args->GetString("keyword", &keyword) || 2759 if (!args->GetString("keyword", &keyword) ||
2760 !args->GetString("action", &action)) { 2760 !args->GetString("action", &action)) {
2761 AutomationJSONReply(this, reply_message).SendError( 2761 AutomationJSONReply(this, reply_message).SendError(
2762 "One or more inputs invalid"); 2762 "One or more inputs invalid");
2763 return; 2763 return;
2764 } 2764 }
2765 const TemplateURL* template_url( 2765 const TemplateURL* template_url(
2766 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword))); 2766 url_model->GetTemplateURLForKeyword(UTF8ToWide(keyword)));
2767 if (template_url == NULL) { 2767 if (template_url == NULL) {
2768 AutomationJSONReply(this, reply_message).SendError( 2768 AutomationJSONReply(this, reply_message).SendError(
2769 StringPrintf("No match for keyword: %s", keyword.c_str())); 2769 StringPrintf("No match for keyword: %s", keyword.c_str()));
2770 return; 2770 return;
2771 } 2771 }
2772 if (action == "delete") { 2772 if (action == "delete") {
2773 url_model->AddObserver(new AutomationProviderSearchEngineObserver( 2773 url_model->AddObserver(new AutomationProviderSearchEngineObserver(
2774 this, reply_message)); 2774 this, reply_message));
2775 url_model->Remove(template_url); 2775 url_model->Remove(template_url);
2776 } else if (action == "default") { 2776 } else if (action == "default") {
(...skipping 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after
4517 // If you change this, update Observer for NotificationType::SESSION_END 4517 // If you change this, update Observer for NotificationType::SESSION_END
4518 // below. 4518 // below.
4519 MessageLoop::current()->PostTask(FROM_HERE, 4519 MessageLoop::current()->PostTask(FROM_HERE,
4520 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 4520 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
4521 } 4521 }
4522 } 4522 }
4523 4523
4524 void TestingAutomationProvider::OnRemoveProvider() { 4524 void TestingAutomationProvider::OnRemoveProvider() {
4525 AutomationProviderList::GetInstance()->RemoveProvider(this); 4525 AutomationProviderList::GetInstance()->RemoveProvider(this);
4526 } 4526 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider_unittest.cc ('k') | chrome/browser/dom_ui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698