Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 10236003: Added RefreshPolicies to PolicyService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simpler test setup using an uninitialized store Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 #include "net/cookies/cookie_store.h" 143 #include "net/cookies/cookie_store.h"
144 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 144 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
145 #include "ui/base/events.h" 145 #include "ui/base/events.h"
146 #include "ui/base/keycodes/keyboard_codes.h" 146 #include "ui/base/keycodes/keyboard_codes.h"
147 #include "ui/base/ui_base_types.h" 147 #include "ui/base/ui_base_types.h"
148 #include "ui/ui_controls/ui_controls.h" 148 #include "ui/ui_controls/ui_controls.h"
149 #include "webkit/glue/webdropdata.h" 149 #include "webkit/glue/webdropdata.h"
150 #include "webkit/plugins/webplugininfo.h" 150 #include "webkit/plugins/webplugininfo.h"
151 151
152 #if defined(ENABLE_CONFIGURATION_POLICY) 152 #if defined(ENABLE_CONFIGURATION_POLICY)
153 #include "chrome/browser/policy/browser_policy_connector.h" 153 #include "chrome/browser/policy/policy_service.h"
154 #include "policy/policy_constants.h" 154 #include "policy/policy_constants.h"
155 #endif 155 #endif
156 156
157 #if defined(OS_CHROMEOS) 157 #if defined(OS_CHROMEOS)
158 #include "chromeos/dbus/dbus_thread_manager.h" 158 #include "chromeos/dbus/dbus_thread_manager.h"
159 #endif 159 #endif
160 160
161 #if defined(OS_MACOSX) 161 #if defined(OS_MACOSX)
162 #include "base/mach_ipc_mac.h" 162 #include "base/mach_ipc_mac.h"
163 #endif 163 #endif
(...skipping 15 matching lines...) Expand all
179 using content::NavigationEntry; 179 using content::NavigationEntry;
180 using content::PluginService; 180 using content::PluginService;
181 using content::OpenURLParams; 181 using content::OpenURLParams;
182 using content::Referrer; 182 using content::Referrer;
183 using content::RenderViewHost; 183 using content::RenderViewHost;
184 using content::SSLStatus; 184 using content::SSLStatus;
185 using content::WebContents; 185 using content::WebContents;
186 186
187 namespace { 187 namespace {
188 188
189 // Helper to reply asynchronously if |automation| is still valid.
190 void SendSuccessReply(base::WeakPtr<AutomationProvider> automation,
191 IPC::Message* reply_message) {
192 if (automation)
193 AutomationJSONReply(automation.get(), reply_message).SendSuccess(NULL);
194 }
195
196 // Helper to resolve the overloading of PostTask.
197 void PostTask(BrowserThread::ID id, const base::Closure& callback) {
198 BrowserThread::PostTask(id, FROM_HERE, callback);
199 }
200
189 void SendMouseClick(int flags) { 201 void SendMouseClick(int flags) {
190 ui_controls::MouseButton button = ui_controls::LEFT; 202 ui_controls::MouseButton button = ui_controls::LEFT;
191 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) == 203 if ((flags & ui::EF_LEFT_MOUSE_BUTTON) ==
192 ui::EF_LEFT_MOUSE_BUTTON) { 204 ui::EF_LEFT_MOUSE_BUTTON) {
193 button = ui_controls::LEFT; 205 button = ui_controls::LEFT;
194 } else if ((flags & ui::EF_RIGHT_MOUSE_BUTTON) == 206 } else if ((flags & ui::EF_RIGHT_MOUSE_BUTTON) ==
195 ui::EF_RIGHT_MOUSE_BUTTON) { 207 ui::EF_RIGHT_MOUSE_BUTTON) {
196 button = ui_controls::RIGHT; 208 button = ui_controls::RIGHT;
197 } else if ((flags & ui::EF_MIDDLE_MOUSE_BUTTON) == 209 } else if ((flags & ui::EF_MIDDLE_MOUSE_BUTTON) ==
198 ui::EF_MIDDLE_MOUSE_BUTTON) { 210 ui::EF_MIDDLE_MOUSE_BUTTON) {
(...skipping 3541 matching lines...) Expand 10 before | Expand all | Expand 10 after
3740 return; 3752 return;
3741 } 3753 }
3742 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3754 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3743 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) { 3755 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) {
3744 AutomationJSONReply(this, reply_message).SendError( 3756 AutomationJSONReply(this, reply_message).SendError(
3745 StringPrintf("Could not enable plugin for path %s.", path.c_str())); 3757 StringPrintf("Could not enable plugin for path %s.", path.c_str()));
3746 return; 3758 return;
3747 } 3759 }
3748 plugin_prefs->EnablePlugin( 3760 plugin_prefs->EnablePlugin(
3749 true, FilePath(path), 3761 true, FilePath(path),
3750 base::Bind(&TestingAutomationProvider::SendSuccessReply, this, 3762 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3751 reply_message));
3752 } 3763 }
3753 3764
3754 // Sample json input: 3765 // Sample json input:
3755 // { "command": "DisablePlugin", 3766 // { "command": "DisablePlugin",
3756 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3767 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3757 void TestingAutomationProvider::DisablePlugin(Browser* browser, 3768 void TestingAutomationProvider::DisablePlugin(Browser* browser,
3758 DictionaryValue* args, 3769 DictionaryValue* args,
3759 IPC::Message* reply_message) { 3770 IPC::Message* reply_message) {
3760 FilePath::StringType path; 3771 FilePath::StringType path;
3761 if (!args->GetString("path", &path)) { 3772 if (!args->GetString("path", &path)) {
3762 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3773 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3763 return; 3774 return;
3764 } 3775 }
3765 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3776 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3766 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) { 3777 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) {
3767 AutomationJSONReply(this, reply_message).SendError( 3778 AutomationJSONReply(this, reply_message).SendError(
3768 StringPrintf("Could not disable plugin for path %s.", path.c_str())); 3779 StringPrintf("Could not disable plugin for path %s.", path.c_str()));
3769 return; 3780 return;
3770 } 3781 }
3771 plugin_prefs->EnablePlugin( 3782 plugin_prefs->EnablePlugin(
3772 false, FilePath(path), 3783 false, FilePath(path),
3773 base::Bind(&TestingAutomationProvider::SendSuccessReply, this, 3784 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3774 reply_message));
3775 } 3785 }
3776 3786
3777 // Sample json input: 3787 // Sample json input:
3778 // { "command": "SaveTabContents", 3788 // { "command": "SaveTabContents",
3779 // "tab_index": 0, 3789 // "tab_index": 0,
3780 // "filename": <a full pathname> } 3790 // "filename": <a full pathname> }
3781 // Sample json output: 3791 // Sample json output:
3782 // {} 3792 // {}
3783 void TestingAutomationProvider::SaveTabContents( 3793 void TestingAutomationProvider::SaveTabContents(
3784 Browser* browser, 3794 Browser* browser,
(...skipping 2065 matching lines...) Expand 10 before | Expand all | Expand 10 after
5850 return; 5860 return;
5851 } 5861 }
5852 5862
5853 bool control = !!(modifiers & automation::kControlKeyMask); 5863 bool control = !!(modifiers & automation::kControlKeyMask);
5854 bool shift = !!(modifiers & automation::kShiftKeyMask); 5864 bool shift = !!(modifiers & automation::kShiftKeyMask);
5855 bool alt = !!(modifiers & automation::kAltKeyMask); 5865 bool alt = !!(modifiers & automation::kAltKeyMask);
5856 bool meta = !!(modifiers & automation::kMetaKeyMask); 5866 bool meta = !!(modifiers & automation::kMetaKeyMask);
5857 if (!ui_controls::SendKeyPressNotifyWhenDone( 5867 if (!ui_controls::SendKeyPressNotifyWhenDone(
5858 window, static_cast<ui::KeyboardCode>(keycode), 5868 window, static_cast<ui::KeyboardCode>(keycode),
5859 control, shift, alt, meta, 5869 control, shift, alt, meta,
5860 base::Bind(&TestingAutomationProvider::SendSuccessReply, this, 5870 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message))) {
5861 reply_message))) {
5862 AutomationJSONReply(this, reply_message) 5871 AutomationJSONReply(this, reply_message)
5863 .SendError("Could not send the native key event"); 5872 .SendError("Could not send the native key event");
5864 } 5873 }
5865 } 5874 }
5866 5875
5867 void TestingAutomationProvider::SendSuccessReply(IPC::Message* reply_message) {
5868 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
5869 }
5870
5871 void TestingAutomationProvider::ProcessWebMouseEvent( 5876 void TestingAutomationProvider::ProcessWebMouseEvent(
5872 DictionaryValue* args, 5877 DictionaryValue* args,
5873 IPC::Message* reply_message) { 5878 IPC::Message* reply_message) {
5874 if (SendErrorIfModalDialogActive(this, reply_message)) 5879 if (SendErrorIfModalDialogActive(this, reply_message))
5875 return; 5880 return;
5876 5881
5877 RenderViewHost* view; 5882 RenderViewHost* view;
5878 std::string error; 5883 std::string error;
5879 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { 5884 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) {
5880 AutomationJSONReply(this, reply_message).SendError(error); 5885 AutomationJSONReply(this, reply_message).SendError(error);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
6318 #endif 6323 #endif
6319 } 6324 }
6320 6325
6321 void TestingAutomationProvider::RefreshPolicies( 6326 void TestingAutomationProvider::RefreshPolicies(
6322 base::DictionaryValue* args, 6327 base::DictionaryValue* args,
6323 IPC::Message* reply_message) { 6328 IPC::Message* reply_message) {
6324 #if !defined(ENABLE_CONFIGURATION_POLICY) 6329 #if !defined(ENABLE_CONFIGURATION_POLICY)
6325 AutomationJSONReply(this, reply_message).SendError( 6330 AutomationJSONReply(this, reply_message).SendError(
6326 "Configuration Policy disabled"); 6331 "Configuration Policy disabled");
6327 #else 6332 #else
6328 policy::BrowserPolicyConnector* connector = 6333 // Some policies (e.g. URLBlacklist) post tasks to other message loops
6329 g_browser_process->browser_policy_connector(); 6334 // before they start enforcing updated policy values; make sure those tasks
6330 new PolicyUpdatesObserver(this, reply_message, connector); 6335 // have finished after a policy update.
6331 connector->RefreshPolicies(); 6336 // Updates of the URLBlacklist are done on IO, after building the blacklist
6337 // on FILE, which is initiated from IO.
6338 base::Closure reply =
6339 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message);
6340 g_browser_process->policy_service()->RefreshPolicies(
6341 base::Bind(PostTask, BrowserThread::IO,
6342 base::Bind(PostTask, BrowserThread::FILE,
6343 base::Bind(PostTask, BrowserThread::IO,
6344 base::Bind(PostTask, BrowserThread::UI, reply)))));
6332 #endif 6345 #endif
6333 } 6346 }
6334 6347
6335 void TestingAutomationProvider::GetIndicesFromTab( 6348 void TestingAutomationProvider::GetIndicesFromTab(
6336 DictionaryValue* args, 6349 DictionaryValue* args,
6337 IPC::Message* reply_message) { 6350 IPC::Message* reply_message) {
6338 AutomationJSONReply reply(this, reply_message); 6351 AutomationJSONReply reply(this, reply_message);
6339 int id_or_handle = 0; 6352 int id_or_handle = 0;
6340 bool has_id = args->HasKey("tab_id"); 6353 bool has_id = args->HasKey("tab_id");
6341 bool has_handle = args->HasKey("tab_handle"); 6354 bool has_handle = args->HasKey("tab_handle");
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
7077 *browser_handle = browser_tracker_->Add(browser); 7090 *browser_handle = browser_tracker_->Add(browser);
7078 *success = true; 7091 *success = true;
7079 } 7092 }
7080 } 7093 }
7081 } 7094 }
7082 7095
7083 void TestingAutomationProvider::OnRemoveProvider() { 7096 void TestingAutomationProvider::OnRemoveProvider() {
7084 if (g_browser_process) 7097 if (g_browser_process)
7085 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7098 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
7086 } 7099 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698