OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3254 Browser* browser, | 3254 Browser* browser, |
3255 DictionaryValue* args, | 3255 DictionaryValue* args, |
3256 IPC::Message* reply_message) { | 3256 IPC::Message* reply_message) { |
3257 TemplateURLService* url_model = | 3257 TemplateURLService* url_model = |
3258 TemplateURLServiceFactory::GetForProfile(browser->profile()); | 3258 TemplateURLServiceFactory::GetForProfile(browser->profile()); |
3259 if (url_model->loaded()) { | 3259 if (url_model->loaded()) { |
3260 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 3260 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
3261 return; | 3261 return; |
3262 } | 3262 } |
3263 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 3263 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
3264 this, reply_message)); | 3264 this, browser->profile(), reply_message)); |
3265 url_model->Load(); | 3265 url_model->Load(); |
3266 } | 3266 } |
3267 | 3267 |
3268 // Sample JSON input { "command": "GetSearchEngineInfo" } | 3268 // Sample JSON input { "command": "GetSearchEngineInfo" } |
3269 // Refer to pyauto.py for sample output. | 3269 // Refer to pyauto.py for sample output. |
3270 void TestingAutomationProvider::GetSearchEngineInfo( | 3270 void TestingAutomationProvider::GetSearchEngineInfo( |
3271 Browser* browser, | 3271 Browser* browser, |
3272 DictionaryValue* args, | 3272 DictionaryValue* args, |
3273 IPC::Message* reply_message) { | 3273 IPC::Message* reply_message) { |
3274 TemplateURLService* url_model = | 3274 TemplateURLService* url_model = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3323 new KeywordEditorController(browser->profile())); | 3323 new KeywordEditorController(browser->profile())); |
3324 if (args->GetString("keyword", &keyword)) { | 3324 if (args->GetString("keyword", &keyword)) { |
3325 const TemplateURL* template_url( | 3325 const TemplateURL* template_url( |
3326 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword))); | 3326 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword))); |
3327 if (template_url == NULL) { | 3327 if (template_url == NULL) { |
3328 AutomationJSONReply(this, reply_message).SendError( | 3328 AutomationJSONReply(this, reply_message).SendError( |
3329 "No match for keyword: " + keyword); | 3329 "No match for keyword: " + keyword); |
3330 return; | 3330 return; |
3331 } | 3331 } |
3332 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 3332 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
3333 this, reply_message)); | 3333 this, browser->profile(), reply_message)); |
3334 controller->ModifyTemplateURL(template_url, new_title, new_keyword, | 3334 controller->ModifyTemplateURL(template_url, new_title, new_keyword, |
3335 new_ref_url); | 3335 new_ref_url); |
3336 } else { | 3336 } else { |
3337 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 3337 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
3338 this, reply_message)); | 3338 this, browser->profile(), reply_message)); |
3339 controller->AddTemplateURL(new_title, new_keyword, new_ref_url); | 3339 controller->AddTemplateURL(new_title, new_keyword, new_ref_url); |
3340 } | 3340 } |
3341 } | 3341 } |
3342 | 3342 |
3343 // Sample json input: { "command": "PerformActionOnSearchEngine", | 3343 // Sample json input: { "command": "PerformActionOnSearchEngine", |
3344 // "keyword": keyword, "action": action } | 3344 // "keyword": keyword, "action": action } |
3345 void TestingAutomationProvider::PerformActionOnSearchEngine( | 3345 void TestingAutomationProvider::PerformActionOnSearchEngine( |
3346 Browser* browser, | 3346 Browser* browser, |
3347 DictionaryValue* args, | 3347 DictionaryValue* args, |
3348 IPC::Message* reply_message) { | 3348 IPC::Message* reply_message) { |
3349 TemplateURLService* url_model = | 3349 TemplateURLService* url_model = |
3350 TemplateURLServiceFactory::GetForProfile(browser->profile()); | 3350 TemplateURLServiceFactory::GetForProfile(browser->profile()); |
3351 std::string keyword; | 3351 std::string keyword; |
3352 std::string action; | 3352 std::string action; |
3353 if (!args->GetString("keyword", &keyword) || | 3353 if (!args->GetString("keyword", &keyword) || |
3354 !args->GetString("action", &action)) { | 3354 !args->GetString("action", &action)) { |
3355 AutomationJSONReply(this, reply_message).SendError( | 3355 AutomationJSONReply(this, reply_message).SendError( |
3356 "One or more inputs invalid"); | 3356 "One or more inputs invalid"); |
3357 return; | 3357 return; |
3358 } | 3358 } |
3359 const TemplateURL* template_url( | 3359 const TemplateURL* template_url( |
3360 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword))); | 3360 url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword))); |
3361 if (template_url == NULL) { | 3361 if (template_url == NULL) { |
3362 AutomationJSONReply(this, reply_message).SendError( | 3362 AutomationJSONReply(this, reply_message).SendError( |
3363 "No match for keyword: " + keyword); | 3363 "No match for keyword: " + keyword); |
3364 return; | 3364 return; |
3365 } | 3365 } |
3366 if (action == "delete") { | 3366 if (action == "delete") { |
3367 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 3367 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
3368 this, reply_message)); | 3368 this, browser->profile(), reply_message)); |
3369 url_model->Remove(template_url); | 3369 url_model->Remove(template_url); |
3370 } else if (action == "default") { | 3370 } else if (action == "default") { |
3371 url_model->AddObserver(new AutomationProviderSearchEngineObserver( | 3371 url_model->AddObserver(new AutomationProviderSearchEngineObserver( |
3372 this, reply_message)); | 3372 this, browser->profile(), reply_message)); |
3373 url_model->SetDefaultSearchProvider(template_url); | 3373 url_model->SetDefaultSearchProvider(template_url); |
3374 } else { | 3374 } else { |
3375 AutomationJSONReply(this, reply_message).SendError( | 3375 AutomationJSONReply(this, reply_message).SendError( |
3376 "Invalid action: " + action); | 3376 "Invalid action: " + action); |
3377 } | 3377 } |
3378 } | 3378 } |
3379 | 3379 |
3380 #if defined(ENABLE_PROTECTOR_SERVICE) | 3380 #if defined(ENABLE_PROTECTOR_SERVICE) |
3381 // Sample json output: { "enabled": true, | 3381 // Sample json output: { "enabled": true, |
3382 // "showing_change": false } | 3382 // "showing_change": false } |
(...skipping 3694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7077 *browser_handle = browser_tracker_->Add(browser); | 7077 *browser_handle = browser_tracker_->Add(browser); |
7078 *success = true; | 7078 *success = true; |
7079 } | 7079 } |
7080 } | 7080 } |
7081 } | 7081 } |
7082 | 7082 |
7083 void TestingAutomationProvider::OnRemoveProvider() { | 7083 void TestingAutomationProvider::OnRemoveProvider() { |
7084 if (g_browser_process) | 7084 if (g_browser_process) |
7085 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7085 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
7086 } | 7086 } |
OLD | NEW |