Chromium Code Reviews| 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/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "app/message_box_flags.h" | 9 #include "app/message_box_flags.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 #include "chrome/browser/net/url_request_mock_util.h" | 75 #include "chrome/browser/net/url_request_mock_util.h" |
| 76 #include "chrome/browser/platform_util.h" | 76 #include "chrome/browser/platform_util.h" |
| 77 #include "chrome/browser/prefs/pref_service.h" | 77 #include "chrome/browser/prefs/pref_service.h" |
| 78 #include "chrome/browser/printing/print_job.h" | 78 #include "chrome/browser/printing/print_job.h" |
| 79 #include "chrome/browser/profile_manager.h" | 79 #include "chrome/browser/profile_manager.h" |
| 80 #include "chrome/browser/renderer_host/render_process_host.h" | 80 #include "chrome/browser/renderer_host/render_process_host.h" |
| 81 #include "chrome/browser/renderer_host/render_view_host.h" | 81 #include "chrome/browser/renderer_host/render_view_host.h" |
| 82 #include "chrome/browser/ssl/ssl_manager.h" | 82 #include "chrome/browser/ssl/ssl_manager.h" |
| 83 #include "chrome/browser/ssl/ssl_blocking_page.h" | 83 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 84 #include "chrome/browser/tab_contents/infobar_delegate.h" | 84 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 85 #include "chrome/browser/tab_contents/navigation_entry.h" | |
| 85 #include "chrome/browser/tab_contents/tab_contents.h" | 86 #include "chrome/browser/tab_contents/tab_contents.h" |
| 86 #include "chrome/browser/tab_contents/tab_contents_view.h" | 87 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 87 #include "chrome/browser/translate/translate_infobar_delegate.h" | 88 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 88 #include "chrome/common/automation_constants.h" | 89 #include "chrome/common/automation_constants.h" |
| 89 #include "chrome/common/chrome_constants.h" | 90 #include "chrome/common/chrome_constants.h" |
| 90 #include "chrome/common/chrome_paths.h" | 91 #include "chrome/common/chrome_paths.h" |
| 91 #include "chrome/common/chrome_switches.h" | 92 #include "chrome/common/chrome_switches.h" |
| 92 #include "chrome/common/chrome_version_info.h" | 93 #include "chrome/common/chrome_version_info.h" |
| 93 #include "chrome/common/extensions/extension.h" | 94 #include "chrome/common/extensions/extension.h" |
| 94 #include "chrome/common/json_value_serializer.h" | 95 #include "chrome/common/json_value_serializer.h" |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 item->SetInteger( | 727 item->SetInteger( |
| 727 "pid", | 728 "pid", |
| 728 base::GetProcId(ex_host->render_process_host()->GetHandle())); | 729 base::GetProcId(ex_host->render_process_host()->GetHandle())); |
| 729 extension_processes->Append(item); | 730 extension_processes->Append(item); |
| 730 } | 731 } |
| 731 } | 732 } |
| 732 return_value->Set("extension_processes", extension_processes); | 733 return_value->Set("extension_processes", extension_processes); |
| 733 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 734 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 734 } | 735 } |
| 735 | 736 |
| 737 // Sample json input: { "command": "GetNavigationInfo" } | |
| 738 // Refer to GetNavigationInfo() in chrome/test/pyautolib/pyauto.py for | |
| 739 // sample json output. | |
| 740 void AutomationProvider::GetNavigationInfo(Browser* browser, | |
| 741 DictionaryValue* args, | |
| 742 IPC::Message* reply_message) { | |
| 743 AutomationJSONReply reply(this, reply_message); | |
| 744 int tab_index; | |
| 745 TabContents* tab_contents = NULL; | |
| 746 if (!args->GetInteger("tab_index", &tab_index) || | |
| 747 !(tab_contents = browser->GetTabContentsAt(tab_index))) { | |
| 748 reply.SendError("tab_index missing or invalid."); | |
| 749 return; | |
| 750 } | |
| 751 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
| 752 const NavigationController& controller = tab_contents->controller(); | |
| 753 NavigationEntry* nav_entry = controller.GetActiveEntry(); | |
| 754 DCHECK(nav_entry); | |
| 755 | |
| 756 // Security info. | |
| 757 DictionaryValue* ssl = new DictionaryValue; | |
| 758 std::map<SecurityStyle, std::string> style_to_string; | |
| 759 style_to_string[SECURITY_STYLE_UNKNOWN] = "SECURITY_STYLE_UNKNOWN"; | |
| 760 style_to_string[SECURITY_STYLE_UNAUTHENTICATED] = | |
| 761 "SECURITY_STYLE_UNAUTHENTICATED"; | |
| 762 style_to_string[SECURITY_STYLE_AUTHENTICATION_BROKEN] = | |
| 763 "SECURITY_STYLE_AUTHENTICATION_BROKEN"; | |
| 764 style_to_string[SECURITY_STYLE_AUTHENTICATED] = | |
| 765 "SECURITY_STYLE_AUTHENTICATED"; | |
| 766 | |
| 767 NavigationEntry::SSLStatus ssl_status = nav_entry->ssl(); | |
| 768 ssl->SetString("security_style", | |
| 769 style_to_string[ssl_status.security_style()]); | |
| 770 ssl->SetBoolean("ran_insecure_content", ssl_status.ran_insecure_content()); | |
| 771 ssl->SetBoolean("displayed_insecure_content", | |
| 772 ssl_status.displayed_insecure_content()); | |
| 773 return_value->Set("ssl", ssl); | |
| 774 | |
| 775 // Page type. | |
| 776 std::map<NavigationEntry::PageType, std::string> pagetype_to_string; | |
| 777 pagetype_to_string[NavigationEntry::NORMAL_PAGE] = "NORMAL_PAGE"; | |
| 778 pagetype_to_string[NavigationEntry::ERROR_PAGE] = "ERROR_PAGE"; | |
| 779 pagetype_to_string[NavigationEntry::INTERSTITIAL_PAGE] = "INTERSTITIAL_PAGE"; | |
| 780 return_value->SetString("page_type", | |
| 781 pagetype_to_string[nav_entry->page_type()]); | |
| 782 | |
| 783 return_value->SetString("favicon_url", nav_entry->favicon().url().spec()); | |
| 784 reply.SendSuccess(return_value.get()); | |
| 785 } | |
| 786 | |
| 736 // Sample json input: { "command": "GetHistoryInfo", | 787 // Sample json input: { "command": "GetHistoryInfo", |
| 737 // "search_text": "some text" } | 788 // "search_text": "some text" } |
| 738 // Refer chrome/test/pyautolib/history_info.py for sample json output. | 789 // Refer chrome/test/pyautolib/history_info.py for sample json output. |
| 739 void AutomationProvider::GetHistoryInfo(Browser* browser, | 790 void AutomationProvider::GetHistoryInfo(Browser* browser, |
| 740 DictionaryValue* args, | 791 DictionaryValue* args, |
| 741 IPC::Message* reply_message) { | 792 IPC::Message* reply_message) { |
| 742 consumer_.CancelAllRequests(); | 793 consumer_.CancelAllRequests(); |
| 743 | 794 |
| 744 string16 search_text; | 795 string16 search_text; |
| 745 args->GetString("search_text", &search_text); | 796 args->GetString("search_text", &search_text); |
| (...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2071 } | 2122 } |
| 2072 // Ownership remains with "values" variable. | 2123 // Ownership remains with "values" variable. |
| 2073 dict_value = static_cast<DictionaryValue*>(values.get()); | 2124 dict_value = static_cast<DictionaryValue*>(values.get()); |
| 2074 if (!dict_value->GetStringASCII(std::string("command"), &command)) { | 2125 if (!dict_value->GetStringASCII(std::string("command"), &command)) { |
| 2075 AutomationJSONReply(this, reply_message).SendError( | 2126 AutomationJSONReply(this, reply_message).SendError( |
| 2076 "no command key in dict or not a string command"); | 2127 "no command key in dict or not a string command"); |
| 2077 return; | 2128 return; |
| 2078 } | 2129 } |
| 2079 | 2130 |
| 2080 // Map json commands to their handlers. | 2131 // Map json commands to their handlers. |
| 2081 std::map<std::string, JsonHandler> handler_map; | 2132 std::map<std::string, JsonHandler> handler_map; |
|
John Grabowski
2010/08/31 05:51:16
We're starting to get a lot of these. Perhaps (no
| |
| 2082 handler_map["DisablePlugin"] = &AutomationProvider::DisablePlugin; | 2133 handler_map["DisablePlugin"] = &AutomationProvider::DisablePlugin; |
| 2083 handler_map["EnablePlugin"] = &AutomationProvider::EnablePlugin; | 2134 handler_map["EnablePlugin"] = &AutomationProvider::EnablePlugin; |
| 2084 handler_map["GetPluginsInfo"] = &AutomationProvider::GetPluginsInfo; | 2135 handler_map["GetPluginsInfo"] = &AutomationProvider::GetPluginsInfo; |
| 2085 | 2136 |
| 2086 handler_map["GetBrowserInfo"] = &AutomationProvider::GetBrowserInfo; | 2137 handler_map["GetBrowserInfo"] = &AutomationProvider::GetBrowserInfo; |
| 2087 | 2138 |
| 2139 handler_map["GetNavigationInfo"] = &AutomationProvider::GetNavigationInfo; | |
| 2140 | |
| 2088 handler_map["PerformActionOnInfobar"] = | 2141 handler_map["PerformActionOnInfobar"] = |
| 2089 &AutomationProvider::PerformActionOnInfobar; | 2142 &AutomationProvider::PerformActionOnInfobar; |
| 2090 | 2143 |
| 2091 handler_map["GetHistoryInfo"] = &AutomationProvider::GetHistoryInfo; | 2144 handler_map["GetHistoryInfo"] = &AutomationProvider::GetHistoryInfo; |
| 2092 handler_map["AddHistoryItem"] = &AutomationProvider::AddHistoryItem; | 2145 handler_map["AddHistoryItem"] = &AutomationProvider::AddHistoryItem; |
| 2093 | 2146 |
| 2094 handler_map["GetOmniboxInfo"] = &AutomationProvider::GetOmniboxInfo; | 2147 handler_map["GetOmniboxInfo"] = &AutomationProvider::GetOmniboxInfo; |
| 2095 handler_map["SetOmniboxText"] = &AutomationProvider::SetOmniboxText; | 2148 handler_map["SetOmniboxText"] = &AutomationProvider::SetOmniboxText; |
| 2096 handler_map["OmniboxAcceptInput"] = &AutomationProvider::OmniboxAcceptInput; | 2149 handler_map["OmniboxAcceptInput"] = &AutomationProvider::OmniboxAcceptInput; |
| 2097 handler_map["OmniboxMovePopupSelection"] = | 2150 handler_map["OmniboxMovePopupSelection"] = |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2668 map->SetContentSetting(HostContentSettingsMap::Pattern(host), | 2721 map->SetContentSetting(HostContentSettingsMap::Pattern(host), |
| 2669 content_type, "", setting); | 2722 content_type, "", setting); |
| 2670 } | 2723 } |
| 2671 *success = true; | 2724 *success = true; |
| 2672 } | 2725 } |
| 2673 } | 2726 } |
| 2674 | 2727 |
| 2675 void AutomationProvider::ResetToDefaultTheme() { | 2728 void AutomationProvider::ResetToDefaultTheme() { |
| 2676 profile_->ClearTheme(); | 2729 profile_->ClearTheme(); |
| 2677 } | 2730 } |
| OLD | NEW |