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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3030 items->Append(item); | 3034 items->Append(item); |
3031 } | 3035 } |
3032 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3036 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
3033 return_value->Set("plugins", items); // return_value owns items. | 3037 return_value->Set("plugins", items); // return_value owns items. |
3034 | 3038 |
3035 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 3039 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
3036 } | 3040 } |
3037 | 3041 |
3038 // Sample json input: | 3042 // Sample json input: |
3039 // { "command": "EnablePlugin", | 3043 // { "command": "EnablePlugin", |
| 3044 // "name": "Flash Player", |
3040 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 3045 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
3041 void TestingAutomationProvider::EnablePlugin(Browser* browser, | 3046 void TestingAutomationProvider::EnablePlugin(Browser* browser, |
3042 DictionaryValue* args, | 3047 DictionaryValue* args, |
3043 IPC::Message* reply_message) { | 3048 IPC::Message* reply_message) { |
3044 FilePath::StringType path; | 3049 FilePath::StringType path; |
| 3050 string16 name; |
3045 AutomationJSONReply reply(this, reply_message); | 3051 AutomationJSONReply reply(this, reply_message); |
3046 if (!args->GetString("path", &path)) { | 3052 if (!args->GetString("path", &path) || !args->GetString("name", &name)) { |
3047 reply.SendError("path not specified."); | 3053 reply.SendError("path or name not specified."); |
3048 return; | 3054 return; |
3049 } else if (!NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(path))) { | 3055 } else if (!NPAPI::PluginList::Singleton()->EnablePlugin( |
| 3056 FilePath(path), name)) { |
3050 reply.SendError(StringPrintf("Could not enable plugin for path %s.", | 3057 reply.SendError(StringPrintf("Could not enable plugin for path %s.", |
3051 path.c_str())); | 3058 path.c_str())); |
3052 return; | 3059 return; |
3053 } | 3060 } |
3054 reply.SendSuccess(NULL); | 3061 reply.SendSuccess(NULL); |
3055 } | 3062 } |
3056 | 3063 |
3057 // Sample json input: | 3064 // Sample json input: |
3058 // { "command": "DisablePlugin", | 3065 // { "command": "DisablePlugin", |
| 3066 // "name": "Flash Player", |
3059 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 3067 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
3060 void TestingAutomationProvider::DisablePlugin(Browser* browser, | 3068 void TestingAutomationProvider::DisablePlugin(Browser* browser, |
3061 DictionaryValue* args, | 3069 DictionaryValue* args, |
3062 IPC::Message* reply_message) { | 3070 IPC::Message* reply_message) { |
3063 FilePath::StringType path; | 3071 FilePath::StringType path; |
| 3072 string16 name; |
3064 AutomationJSONReply reply(this, reply_message); | 3073 AutomationJSONReply reply(this, reply_message); |
3065 if (!args->GetString("path", &path)) { | 3074 if (!args->GetString("path", &path) || !args->GetString("name", &name)) { |
3066 reply.SendError("path not specified."); | 3075 reply.SendError("path or name not specified."); |
3067 return; | 3076 return; |
3068 } else if (!NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(path))) { | 3077 } else if (!NPAPI::PluginList::Singleton()->DisablePlugin( |
| 3078 FilePath(path), name)) { |
3069 reply.SendError(StringPrintf("Could not disable plugin for path %s.", | 3079 reply.SendError(StringPrintf("Could not disable plugin for path %s.", |
3070 path.c_str())); | 3080 path.c_str())); |
3071 return; | 3081 return; |
3072 } | 3082 } |
3073 reply.SendSuccess(NULL); | 3083 reply.SendSuccess(NULL); |
3074 } | 3084 } |
3075 | 3085 |
3076 // Sample json input: | 3086 // Sample json input: |
3077 // { "command": "SaveTabContents", | 3087 // { "command": "SaveTabContents", |
3078 // "tab_index": 0, | 3088 // "tab_index": 0, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3213 password_form.username_element = username_element; | 3223 password_form.username_element = username_element; |
3214 password_form.password_element = password_element; | 3224 password_form.password_element = password_element; |
3215 password_form.submit_element = submit_element; | 3225 password_form.submit_element = submit_element; |
3216 password_form.action = action_target; | 3226 password_form.action = action_target; |
3217 password_form.blacklisted_by_user = blacklist; | 3227 password_form.blacklisted_by_user = blacklist; |
3218 password_form.date_created = time; | 3228 password_form.date_created = time; |
3219 | 3229 |
3220 return password_form; | 3230 return password_form; |
3221 } | 3231 } |
3222 | 3232 |
3223 } // namespace | 3233 } // namespace |
3224 | 3234 |
3225 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json | 3235 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json |
3226 // input. | 3236 // input. |
3227 // Sample json output: { "password_added": true } | 3237 // Sample json output: { "password_added": true } |
3228 void TestingAutomationProvider::AddSavedPassword( | 3238 void TestingAutomationProvider::AddSavedPassword( |
3229 Browser* browser, | 3239 Browser* browser, |
3230 DictionaryValue* args, | 3240 DictionaryValue* args, |
3231 IPC::Message* reply_message) { | 3241 IPC::Message* reply_message) { |
3232 AutomationJSONReply reply(this, reply_message); | 3242 AutomationJSONReply reply(this, reply_message); |
3233 DictionaryValue* password_dict = NULL; | 3243 DictionaryValue* password_dict = NULL; |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4520 // If you change this, update Observer for NotificationType::SESSION_END | 4530 // If you change this, update Observer for NotificationType::SESSION_END |
4521 // below. | 4531 // below. |
4522 MessageLoop::current()->PostTask(FROM_HERE, | 4532 MessageLoop::current()->PostTask(FROM_HERE, |
4523 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 4533 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
4524 } | 4534 } |
4525 } | 4535 } |
4526 | 4536 |
4527 void TestingAutomationProvider::OnRemoveProvider() { | 4537 void TestingAutomationProvider::OnRemoveProvider() { |
4528 AutomationProviderList::GetInstance()->RemoveProvider(this); | 4538 AutomationProviderList::GetInstance()->RemoveProvider(this); |
4529 } | 4539 } |
OLD | NEW |