OLD | NEW |
1 // Copyright (c) 2010 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 <map> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
7 #include "app/message_box_flags.h" | 11 #include "app/message_box_flags.h" |
8 #include "base/command_line.h" | 12 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
11 #include "base/json/string_escape.h" | 15 #include "base/json/string_escape.h" |
12 #include "base/path_service.h" | 16 #include "base/path_service.h" |
13 #include "base/process.h" | 17 #include "base/process.h" |
14 #include "base/process_util.h" | 18 #include "base/process_util.h" |
15 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
16 #include "base/thread_restrictions.h" | 20 #include "base/thread_restrictions.h" |
(...skipping 2618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2635 it++) { | 2639 it++) { |
2636 DownloadItem* curr_item = *it; | 2640 DownloadItem* curr_item = *it; |
2637 if (curr_item->id() == id) { | 2641 if (curr_item->id() == id) { |
2638 selected_item = curr_item; | 2642 selected_item = curr_item; |
2639 break; | 2643 break; |
2640 } | 2644 } |
2641 } | 2645 } |
2642 return selected_item; | 2646 return selected_item; |
2643 } | 2647 } |
2644 | 2648 |
2645 } // namespace | 2649 } // namespace |
2646 | 2650 |
2647 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample | 2651 // See PerformActionOnDownload() in chrome/test/pyautolib/pyauto.py for sample |
2648 // json input and output. | 2652 // json input and output. |
2649 void TestingAutomationProvider::PerformActionOnDownload( | 2653 void TestingAutomationProvider::PerformActionOnDownload( |
2650 Browser* browser, | 2654 Browser* browser, |
2651 DictionaryValue* args, | 2655 DictionaryValue* args, |
2652 IPC::Message* reply_message) { | 2656 IPC::Message* reply_message) { |
2653 int id; | 2657 int id; |
2654 std::string action; | 2658 std::string action; |
2655 | 2659 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 items->Append(item); | 3035 items->Append(item); |
3032 } | 3036 } |
3033 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3037 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
3034 return_value->Set("plugins", items); // return_value owns items. | 3038 return_value->Set("plugins", items); // return_value owns items. |
3035 | 3039 |
3036 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 3040 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
3037 } | 3041 } |
3038 | 3042 |
3039 // Sample json input: | 3043 // Sample json input: |
3040 // { "command": "EnablePlugin", | 3044 // { "command": "EnablePlugin", |
| 3045 // "name": "Flash Player", |
3041 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 3046 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
3042 void TestingAutomationProvider::EnablePlugin(Browser* browser, | 3047 void TestingAutomationProvider::EnablePlugin(Browser* browser, |
3043 DictionaryValue* args, | 3048 DictionaryValue* args, |
3044 IPC::Message* reply_message) { | 3049 IPC::Message* reply_message) { |
3045 FilePath::StringType path; | 3050 FilePath::StringType path; |
| 3051 string16 name; |
3046 AutomationJSONReply reply(this, reply_message); | 3052 AutomationJSONReply reply(this, reply_message); |
3047 if (!args->GetString("path", &path)) { | 3053 if (!args->GetString("path", &path) || !args->GetString("name", &name)) { |
3048 reply.SendError("path not specified."); | 3054 reply.SendError("path or name not specified."); |
3049 return; | 3055 return; |
3050 } else if (!webkit::npapi::PluginList::Singleton()->EnablePlugin( | 3056 } else if (!webkit::npapi::PluginList::Singleton()->EnablePlugin( |
3051 FilePath(path))) { | 3057 FilePath(path), name)) { |
3052 reply.SendError(StringPrintf("Could not enable plugin for path %s.", | 3058 reply.SendError(StringPrintf("Could not enable plugin for path %s.", |
3053 path.c_str())); | 3059 path.c_str())); |
3054 return; | 3060 return; |
3055 } | 3061 } |
3056 reply.SendSuccess(NULL); | 3062 reply.SendSuccess(NULL); |
3057 } | 3063 } |
3058 | 3064 |
3059 // Sample json input: | 3065 // Sample json input: |
3060 // { "command": "DisablePlugin", | 3066 // { "command": "DisablePlugin", |
| 3067 // "name": "Flash Player", |
3061 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 3068 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
3062 void TestingAutomationProvider::DisablePlugin(Browser* browser, | 3069 void TestingAutomationProvider::DisablePlugin(Browser* browser, |
3063 DictionaryValue* args, | 3070 DictionaryValue* args, |
3064 IPC::Message* reply_message) { | 3071 IPC::Message* reply_message) { |
3065 FilePath::StringType path; | 3072 FilePath::StringType path; |
| 3073 string16 name; |
3066 AutomationJSONReply reply(this, reply_message); | 3074 AutomationJSONReply reply(this, reply_message); |
3067 if (!args->GetString("path", &path)) { | 3075 if (!args->GetString("path", &path) || !args->GetString("name", &name)) { |
3068 reply.SendError("path not specified."); | 3076 reply.SendError("path or name not specified."); |
3069 return; | 3077 return; |
3070 } else if (!webkit::npapi::PluginList::Singleton()->DisablePlugin( | 3078 } else if (!webkit::npapi::PluginList::Singleton()->DisablePlugin( |
3071 FilePath(path))) { | 3079 FilePath(path), name)) { |
3072 reply.SendError(StringPrintf("Could not disable plugin for path %s.", | 3080 reply.SendError(StringPrintf("Could not disable plugin for path %s.", |
3073 path.c_str())); | 3081 path.c_str())); |
3074 return; | 3082 return; |
3075 } | 3083 } |
3076 reply.SendSuccess(NULL); | 3084 reply.SendSuccess(NULL); |
3077 } | 3085 } |
3078 | 3086 |
3079 // Sample json input: | 3087 // Sample json input: |
3080 // { "command": "SaveTabContents", | 3088 // { "command": "SaveTabContents", |
3081 // "tab_index": 0, | 3089 // "tab_index": 0, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3216 password_form.username_element = username_element; | 3224 password_form.username_element = username_element; |
3217 password_form.password_element = password_element; | 3225 password_form.password_element = password_element; |
3218 password_form.submit_element = submit_element; | 3226 password_form.submit_element = submit_element; |
3219 password_form.action = action_target; | 3227 password_form.action = action_target; |
3220 password_form.blacklisted_by_user = blacklist; | 3228 password_form.blacklisted_by_user = blacklist; |
3221 password_form.date_created = time; | 3229 password_form.date_created = time; |
3222 | 3230 |
3223 return password_form; | 3231 return password_form; |
3224 } | 3232 } |
3225 | 3233 |
3226 } // namespace | 3234 } // namespace |
3227 | 3235 |
3228 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json | 3236 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json |
3229 // input. | 3237 // input. |
3230 // Sample json output: { "password_added": true } | 3238 // Sample json output: { "password_added": true } |
3231 void TestingAutomationProvider::AddSavedPassword( | 3239 void TestingAutomationProvider::AddSavedPassword( |
3232 Browser* browser, | 3240 Browser* browser, |
3233 DictionaryValue* args, | 3241 DictionaryValue* args, |
3234 IPC::Message* reply_message) { | 3242 IPC::Message* reply_message) { |
3235 AutomationJSONReply reply(this, reply_message); | 3243 AutomationJSONReply reply(this, reply_message); |
3236 DictionaryValue* password_dict = NULL; | 3244 DictionaryValue* password_dict = NULL; |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4523 // If you change this, update Observer for NotificationType::SESSION_END | 4531 // If you change this, update Observer for NotificationType::SESSION_END |
4524 // below. | 4532 // below. |
4525 MessageLoop::current()->PostTask(FROM_HERE, | 4533 MessageLoop::current()->PostTask(FROM_HERE, |
4526 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 4534 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
4527 } | 4535 } |
4528 } | 4536 } |
4529 | 4537 |
4530 void TestingAutomationProvider::OnRemoveProvider() { | 4538 void TestingAutomationProvider::OnRemoveProvider() { |
4531 AutomationProviderList::GetInstance()->RemoveProvider(this); | 4539 AutomationProviderList::GetInstance()->RemoveProvider(this); |
4532 } | 4540 } |
OLD | NEW |