OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 170 } |
171 | 171 |
172 virtual std::string GetHTMLContents() { return contents_; } | 172 virtual std::string GetHTMLContents() { return contents_; } |
173 | 173 |
174 private: | 174 private: |
175 const std::string contents_; | 175 const std::string contents_; |
176 | 176 |
177 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); | 177 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
178 }; | 178 }; |
179 | 179 |
| 180 // Helper function for nested Binds that resolves the overloading of |
| 181 // BrowserThread::PostTask, and ignores the return value. |
| 182 void PostTask(BrowserThread::ID id, const base::Closure& task) { |
| 183 BrowserThread::PostTask(id, FROM_HERE, task); |
| 184 } |
| 185 |
180 } // namespace | 186 } // namespace |
181 | 187 |
182 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) | 188 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
183 : AutomationProvider(profile), | 189 : AutomationProvider(profile), |
184 #if defined(TOOLKIT_VIEWS) | 190 #if defined(TOOLKIT_VIEWS) |
185 popup_menu_waiter_(NULL), | 191 popup_menu_waiter_(NULL), |
186 #endif | 192 #endif |
187 redirect_query_(0) { | 193 redirect_query_(0) { |
188 BrowserList::AddObserver(this); | 194 BrowserList::AddObserver(this); |
189 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, | 195 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, |
(...skipping 2525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2715 infobar_helper->RemoveInfoBar(infobar); | 2721 infobar_helper->RemoveInfoBar(infobar); |
2716 } | 2722 } |
2717 reply.SendSuccess(NULL); | 2723 reply.SendSuccess(NULL); |
2718 return; | 2724 return; |
2719 } | 2725 } |
2720 reply.SendError("Invalid action"); | 2726 reply.SendError("Invalid action"); |
2721 } | 2727 } |
2722 | 2728 |
2723 namespace { | 2729 namespace { |
2724 | 2730 |
2725 // Task to get info about BrowserChildProcessHost. Must run on IO thread to | 2731 // Gets info about BrowserChildProcessHost. Must run on IO thread to |
2726 // honor the semantics of BrowserChildProcessHost. | 2732 // honor the semantics of BrowserChildProcessHost. |
2727 // Used by AutomationProvider::GetBrowserInfo(). | 2733 // Used by AutomationProvider::GetBrowserInfo(). |
2728 class GetChildProcessHostInfoTask : public Task { | 2734 void GetChildProcessHostInfo(ListValue* child_processes) { |
2729 public: | 2735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2730 GetChildProcessHostInfoTask(base::WaitableEvent* event, | 2736 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
2731 ListValue* child_processes) | 2737 // Only add processes which are already started, |
2732 : event_(event), | 2738 // since we need their handle. |
2733 child_processes_(child_processes) {} | 2739 if ((*iter)->handle() == base::kNullProcessHandle) |
2734 | 2740 continue; |
2735 virtual void Run() { | 2741 ChildProcessInfo* info = *iter; |
2736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2742 DictionaryValue* item = new DictionaryValue; |
2737 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 2743 item->SetString("name", info->name()); |
2738 // Only add processes which are already started, | 2744 item->SetString("type", |
2739 // since we need their handle. | 2745 ChildProcessInfo::GetTypeNameInEnglish(info->type())); |
2740 if ((*iter)->handle() == base::kNullProcessHandle) { | 2746 item->SetInteger("pid", base::GetProcId(info->handle())); |
2741 continue; | 2747 child_processes->Append(item); |
2742 } | |
2743 ChildProcessInfo* info = *iter; | |
2744 DictionaryValue* item = new DictionaryValue; | |
2745 item->SetString("name", info->name()); | |
2746 item->SetString("type", | |
2747 ChildProcessInfo::GetTypeNameInEnglish(info->type())); | |
2748 item->SetInteger("pid", base::GetProcId(info->handle())); | |
2749 child_processes_->Append(item); | |
2750 } | |
2751 event_->Signal(); | |
2752 } | 2748 } |
2753 | 2749 } |
2754 private: | |
2755 base::WaitableEvent* const event_; // weak | |
2756 ListValue* child_processes_; | |
2757 | |
2758 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); | |
2759 }; | |
2760 | 2750 |
2761 } // namespace | 2751 } // namespace |
2762 | 2752 |
2763 // Sample json input: { "command": "GetBrowserInfo" } | 2753 // Sample json input: { "command": "GetBrowserInfo" } |
2764 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for | 2754 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
2765 // sample json output. | 2755 // sample json output. |
2766 void TestingAutomationProvider::GetBrowserInfo( | 2756 void TestingAutomationProvider::GetBrowserInfo( |
2767 DictionaryValue* args, | 2757 DictionaryValue* args, |
2768 IPC::Message* reply_message) { | 2758 IPC::Message* reply_message) { |
2769 base::ThreadRestrictions::ScopedAllowIO allow_io; // needed for PathService | 2759 base::ThreadRestrictions::ScopedAllowIO allow_io; // needed for PathService |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2861 windows->Append(browser_item); | 2851 windows->Append(browser_item); |
2862 } | 2852 } |
2863 return_value->Set("windows", windows); | 2853 return_value->Set("windows", windows); |
2864 | 2854 |
2865 #if defined(OS_LINUX) | 2855 #if defined(OS_LINUX) |
2866 int flags = ChildProcessHost::CHILD_ALLOW_SELF; | 2856 int flags = ChildProcessHost::CHILD_ALLOW_SELF; |
2867 #else | 2857 #else |
2868 int flags = ChildProcessHost::CHILD_NORMAL; | 2858 int flags = ChildProcessHost::CHILD_NORMAL; |
2869 #endif | 2859 #endif |
2870 | 2860 |
2871 return_value->SetString("child_process_path", | |
2872 ChildProcessHost::GetChildPath(flags).value()); | |
2873 // Child processes are the processes for plugins and other workers. | |
2874 // Add all child processes in a list of dictionaries, one dictionary item | |
2875 // per child process. | |
2876 ListValue* child_processes = new ListValue; | |
2877 base::WaitableEvent event(true /* manual reset */, | |
2878 false /* not initially signaled */); | |
2879 CHECK(BrowserThread::PostTask( | |
2880 BrowserThread::IO, FROM_HERE, | |
2881 new GetChildProcessHostInfoTask(&event, child_processes))); | |
2882 event.Wait(); | |
2883 return_value->Set("child_processes", child_processes); | |
2884 | |
2885 // Add all extension processes in a list of dictionaries, one dictionary | 2861 // Add all extension processes in a list of dictionaries, one dictionary |
2886 // item per extension process. | 2862 // item per extension process. |
2887 ListValue* extension_views = new ListValue; | 2863 ListValue* extension_views = new ListValue; |
2888 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 2864 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
2889 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 2865 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
2890 for (size_t i = 0; i < profiles.size(); ++i) { | 2866 for (size_t i = 0; i < profiles.size(); ++i) { |
2891 ExtensionProcessManager* process_manager = | 2867 ExtensionProcessManager* process_manager = |
2892 profiles[i]->GetExtensionProcessManager(); | 2868 profiles[i]->GetExtensionProcessManager(); |
2893 if (!process_manager) | 2869 if (!process_manager) |
2894 continue; | 2870 continue; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2930 type = "unknown"; | 2906 type = "unknown"; |
2931 break; | 2907 break; |
2932 } | 2908 } |
2933 item->SetString("view_type", type); | 2909 item->SetString("view_type", type); |
2934 item->SetString("url", ex_host->GetURL().spec()); | 2910 item->SetString("url", ex_host->GetURL().spec()); |
2935 item->SetBoolean("loaded", ex_host->did_stop_loading()); | 2911 item->SetBoolean("loaded", ex_host->did_stop_loading()); |
2936 extension_views->Append(item); | 2912 extension_views->Append(item); |
2937 } | 2913 } |
2938 } | 2914 } |
2939 return_value->Set("extension_views", extension_views); | 2915 return_value->Set("extension_views", extension_views); |
2940 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2916 |
| 2917 return_value->SetString("child_process_path", |
| 2918 ChildProcessHost::GetChildPath(flags).value()); |
| 2919 // Child processes are the processes for plugins and other workers. |
| 2920 // Add all child processes in a list of dictionaries, one dictionary item |
| 2921 // per child process. |
| 2922 ListValue* child_processes = new ListValue; |
| 2923 return_value->Set("child_processes", child_processes); |
| 2924 BrowserThread::PostTaskAndReply( |
| 2925 BrowserThread::IO, FROM_HERE, |
| 2926 base::Bind(&GetChildProcessHostInfo, child_processes), |
| 2927 base::Bind(&AutomationJSONReply::SendSuccess, |
| 2928 base::Owned(new AutomationJSONReply(this, reply_message)), |
| 2929 base::Owned(return_value.release()))); |
2941 } | 2930 } |
2942 | 2931 |
2943 // Sample json input: { "command": "GetProcessInfo" } | 2932 // Sample json input: { "command": "GetProcessInfo" } |
2944 // Refer to GetProcessInfo() in chrome/test/pyautolib/pyauto.py for | 2933 // Refer to GetProcessInfo() in chrome/test/pyautolib/pyauto.py for |
2945 // sample json output. | 2934 // sample json output. |
2946 void TestingAutomationProvider::GetProcessInfo( | 2935 void TestingAutomationProvider::GetProcessInfo( |
2947 DictionaryValue* args, | 2936 DictionaryValue* args, |
2948 IPC::Message* reply_message) { | 2937 IPC::Message* reply_message) { |
2949 scoped_refptr<ProcessInfoObserver> | 2938 scoped_refptr<ProcessInfoObserver> |
2950 proc_observer(new ProcessInfoObserver(this, reply_message)); | 2939 proc_observer(new ProcessInfoObserver(this, reply_message)); |
(...skipping 2905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5856 return; | 5845 return; |
5857 } | 5846 } |
5858 | 5847 |
5859 // This class will send the message immediately if no tab is loading. | 5848 // This class will send the message immediately if no tab is loading. |
5860 new AllTabsStoppedLoadingObserver(this, reply_message); | 5849 new AllTabsStoppedLoadingObserver(this, reply_message); |
5861 } | 5850 } |
5862 | 5851 |
5863 void TestingAutomationProvider::SetPolicies( | 5852 void TestingAutomationProvider::SetPolicies( |
5864 DictionaryValue* args, | 5853 DictionaryValue* args, |
5865 IPC::Message* reply_message) { | 5854 IPC::Message* reply_message) { |
5866 AutomationJSONReply reply(this, reply_message); | 5855 scoped_ptr<AutomationJSONReply> reply( |
| 5856 new AutomationJSONReply(this, reply_message)); |
5867 | 5857 |
5868 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) | 5858 #if !defined(ENABLE_CONFIGURATION_POLICY) || defined(OFFICIAL_BUILD) |
5869 reply.SendError("Configuration Policy disabled"); | 5859 reply->SendError("Configuration Policy disabled"); |
5870 #else | 5860 #else |
5871 const policy::PolicyDefinitionList* list = | 5861 const policy::PolicyDefinitionList* list = |
5872 policy::GetChromePolicyDefinitionList(); | 5862 policy::GetChromePolicyDefinitionList(); |
5873 policy::BrowserPolicyConnector* connector = | 5863 policy::BrowserPolicyConnector* connector = |
5874 g_browser_process->browser_policy_connector(); | 5864 g_browser_process->browser_policy_connector(); |
5875 struct { | 5865 struct { |
5876 std::string name; | 5866 std::string name; |
5877 policy::ConfigurationPolicyProvider* provider; | 5867 policy::ConfigurationPolicyProvider* provider; |
5878 } providers[] = { | 5868 } providers[] = { |
5879 { "managed_cloud", connector->GetManagedCloudProvider() }, | 5869 { "managed_cloud", connector->GetManagedCloudProvider() }, |
5880 { "managed_platform", connector->GetManagedPlatformProvider() }, | 5870 { "managed_platform", connector->GetManagedPlatformProvider() }, |
5881 { "recommended_cloud", connector->GetRecommendedCloudProvider() }, | 5871 { "recommended_cloud", connector->GetRecommendedCloudProvider() }, |
5882 { "recommended_platform", connector->GetRecommendedPlatformProvider() } | 5872 { "recommended_platform", connector->GetRecommendedPlatformProvider() } |
5883 }; | 5873 }; |
5884 // Verify if all the requested providers exist before changing anything. | 5874 // Verify if all the requested providers exist before changing anything. |
5885 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { | 5875 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { |
5886 DictionaryValue* policies = NULL; | 5876 DictionaryValue* policies = NULL; |
5887 if (args->GetDictionary(providers[i].name, &policies) && | 5877 if (args->GetDictionary(providers[i].name, &policies) && |
5888 policies && | 5878 policies && |
5889 !providers[i].provider) { | 5879 !providers[i].provider) { |
5890 reply.SendError("Provider not available: " + providers[i].name); | 5880 reply->SendError("Provider not available: " + providers[i].name); |
5891 return; | 5881 return; |
5892 } | 5882 } |
5893 } | 5883 } |
5894 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { | 5884 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { |
5895 DictionaryValue* policies = NULL; | 5885 DictionaryValue* policies = NULL; |
5896 if (args->GetDictionary(providers[i].name, &policies) && policies) { | 5886 if (args->GetDictionary(providers[i].name, &policies) && policies) { |
5897 policy::PolicyMap* map = new policy::PolicyMap; | 5887 policy::PolicyMap* map = new policy::PolicyMap; |
5898 map->LoadFrom(policies, list); | 5888 map->LoadFrom(policies, list); |
5899 providers[i].provider->OverridePolicies(map); | 5889 providers[i].provider->OverridePolicies(map); |
5900 } | 5890 } |
5901 } | 5891 } |
5902 | 5892 |
5903 reply.SendSuccess(NULL); | 5893 // OverridePolicies() triggers preference updates, which triggers preference |
| 5894 // listeners. Some policies (e.g. URLBlacklist) post tasks to other message |
| 5895 // loops before they start being enforced; make sure those tasks have |
| 5896 // finished. |
| 5897 // Updates of the URLBlacklist are done on IO, after building the blacklist |
| 5898 // on FILE, which is initiated from IO. |
| 5899 PostTask(BrowserThread::IO, |
| 5900 base::Bind(&PostTask, BrowserThread::FILE, |
| 5901 base::Bind(&PostTask, BrowserThread::IO, |
| 5902 base::Bind(&PostTask, BrowserThread::UI, |
| 5903 base::Bind(&AutomationJSONReply::SendSuccess, |
| 5904 base::Owned(reply.release()), |
| 5905 static_cast<const Value*>(NULL)))))); |
5904 #endif // defined(OFFICIAL_BUILD) | 5906 #endif // defined(OFFICIAL_BUILD) |
5905 } | 5907 } |
5906 | 5908 |
5907 void TestingAutomationProvider::GetPolicyDefinitionList( | 5909 void TestingAutomationProvider::GetPolicyDefinitionList( |
5908 DictionaryValue* args, | 5910 DictionaryValue* args, |
5909 IPC::Message* reply_message) { | 5911 IPC::Message* reply_message) { |
5910 AutomationJSONReply reply(this, reply_message); | 5912 AutomationJSONReply reply(this, reply_message); |
5911 | 5913 |
5912 #if !defined(ENABLE_CONFIGURATION_POLICY) | 5914 #if !defined(ENABLE_CONFIGURATION_POLICY) |
5913 reply.SendError("Configuration Policy disabled"); | 5915 reply.SendError("Configuration Policy disabled"); |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6527 | 6529 |
6528 Send(reply_message_); | 6530 Send(reply_message_); |
6529 redirect_query_ = 0; | 6531 redirect_query_ = 0; |
6530 reply_message_ = NULL; | 6532 reply_message_ = NULL; |
6531 } | 6533 } |
6532 | 6534 |
6533 void TestingAutomationProvider::OnRemoveProvider() { | 6535 void TestingAutomationProvider::OnRemoveProvider() { |
6534 if (g_browser_process) | 6536 if (g_browser_process) |
6535 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6537 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6536 } | 6538 } |
OLD | NEW |