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

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: Rebased Created 8 years, 7 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 3545 matching lines...) Expand 10 before | Expand all | Expand 10 after
3744 return; 3756 return;
3745 } 3757 }
3746 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3758 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3747 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) { 3759 if (!plugin_prefs->CanEnablePlugin(true, FilePath(path))) {
3748 AutomationJSONReply(this, reply_message).SendError( 3760 AutomationJSONReply(this, reply_message).SendError(
3749 StringPrintf("Could not enable plugin for path %s.", path.c_str())); 3761 StringPrintf("Could not enable plugin for path %s.", path.c_str()));
3750 return; 3762 return;
3751 } 3763 }
3752 plugin_prefs->EnablePlugin( 3764 plugin_prefs->EnablePlugin(
3753 true, FilePath(path), 3765 true, FilePath(path),
3754 base::Bind(&TestingAutomationProvider::SendSuccessReply, this, 3766 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3755 reply_message));
3756 } 3767 }
3757 3768
3758 // Sample json input: 3769 // Sample json input:
3759 // { "command": "DisablePlugin", 3770 // { "command": "DisablePlugin",
3760 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } 3771 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
3761 void TestingAutomationProvider::DisablePlugin(Browser* browser, 3772 void TestingAutomationProvider::DisablePlugin(Browser* browser,
3762 DictionaryValue* args, 3773 DictionaryValue* args,
3763 IPC::Message* reply_message) { 3774 IPC::Message* reply_message) {
3764 FilePath::StringType path; 3775 FilePath::StringType path;
3765 if (!args->GetString("path", &path)) { 3776 if (!args->GetString("path", &path)) {
3766 AutomationJSONReply(this, reply_message).SendError("path not specified."); 3777 AutomationJSONReply(this, reply_message).SendError("path not specified.");
3767 return; 3778 return;
3768 } 3779 }
3769 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); 3780 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
3770 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) { 3781 if (!plugin_prefs->CanEnablePlugin(false, FilePath(path))) {
3771 AutomationJSONReply(this, reply_message).SendError( 3782 AutomationJSONReply(this, reply_message).SendError(
3772 StringPrintf("Could not disable plugin for path %s.", path.c_str())); 3783 StringPrintf("Could not disable plugin for path %s.", path.c_str()));
3773 return; 3784 return;
3774 } 3785 }
3775 plugin_prefs->EnablePlugin( 3786 plugin_prefs->EnablePlugin(
3776 false, FilePath(path), 3787 false, FilePath(path),
3777 base::Bind(&TestingAutomationProvider::SendSuccessReply, this, 3788 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message));
3778 reply_message));
3779 } 3789 }
3780 3790
3781 // Sample json input: 3791 // Sample json input:
3782 // { "command": "SaveTabContents", 3792 // { "command": "SaveTabContents",
3783 // "tab_index": 0, 3793 // "tab_index": 0,
3784 // "filename": <a full pathname> } 3794 // "filename": <a full pathname> }
3785 // Sample json output: 3795 // Sample json output:
3786 // {} 3796 // {}
3787 void TestingAutomationProvider::SaveTabContents( 3797 void TestingAutomationProvider::SaveTabContents(
3788 Browser* browser, 3798 Browser* browser,
(...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after
5887 return; 5897 return;
5888 } 5898 }
5889 5899
5890 bool control = !!(modifiers & automation::kControlKeyMask); 5900 bool control = !!(modifiers & automation::kControlKeyMask);
5891 bool shift = !!(modifiers & automation::kShiftKeyMask); 5901 bool shift = !!(modifiers & automation::kShiftKeyMask);
5892 bool alt = !!(modifiers & automation::kAltKeyMask); 5902 bool alt = !!(modifiers & automation::kAltKeyMask);
5893 bool meta = !!(modifiers & automation::kMetaKeyMask); 5903 bool meta = !!(modifiers & automation::kMetaKeyMask);
5894 if (!ui_controls::SendKeyPressNotifyWhenDone( 5904 if (!ui_controls::SendKeyPressNotifyWhenDone(
5895 window, static_cast<ui::KeyboardCode>(keycode), 5905 window, static_cast<ui::KeyboardCode>(keycode),
5896 control, shift, alt, meta, 5906 control, shift, alt, meta,
5897 base::Bind(&TestingAutomationProvider::SendSuccessReply, this, 5907 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message))) {
5898 reply_message))) {
5899 AutomationJSONReply(this, reply_message) 5908 AutomationJSONReply(this, reply_message)
5900 .SendError("Could not send the native key event"); 5909 .SendError("Could not send the native key event");
5901 } 5910 }
5902 } 5911 }
5903 5912
5904 void TestingAutomationProvider::SendSuccessReply(IPC::Message* reply_message) {
5905 AutomationJSONReply(this, reply_message).SendSuccess(NULL);
5906 }
5907
5908 void TestingAutomationProvider::ProcessWebMouseEvent( 5913 void TestingAutomationProvider::ProcessWebMouseEvent(
5909 DictionaryValue* args, 5914 DictionaryValue* args,
5910 IPC::Message* reply_message) { 5915 IPC::Message* reply_message) {
5911 if (SendErrorIfModalDialogActive(this, reply_message)) 5916 if (SendErrorIfModalDialogActive(this, reply_message))
5912 return; 5917 return;
5913 5918
5914 RenderViewHost* view; 5919 RenderViewHost* view;
5915 std::string error; 5920 std::string error;
5916 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { 5921 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) {
5917 AutomationJSONReply(this, reply_message).SendError(error); 5922 AutomationJSONReply(this, reply_message).SendError(error);
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
6355 #endif 6360 #endif
6356 } 6361 }
6357 6362
6358 void TestingAutomationProvider::RefreshPolicies( 6363 void TestingAutomationProvider::RefreshPolicies(
6359 base::DictionaryValue* args, 6364 base::DictionaryValue* args,
6360 IPC::Message* reply_message) { 6365 IPC::Message* reply_message) {
6361 #if !defined(ENABLE_CONFIGURATION_POLICY) 6366 #if !defined(ENABLE_CONFIGURATION_POLICY)
6362 AutomationJSONReply(this, reply_message).SendError( 6367 AutomationJSONReply(this, reply_message).SendError(
6363 "Configuration Policy disabled"); 6368 "Configuration Policy disabled");
6364 #else 6369 #else
6365 policy::BrowserPolicyConnector* connector = 6370 // Some policies (e.g. URLBlacklist) post tasks to other message loops
6366 g_browser_process->browser_policy_connector(); 6371 // before they start enforcing updated policy values; make sure those tasks
6367 new PolicyUpdatesObserver(this, reply_message, connector); 6372 // have finished after a policy update.
6368 connector->RefreshPolicies(); 6373 // Updates of the URLBlacklist are done on IO, after building the blacklist
6374 // on FILE, which is initiated from IO.
6375 base::Closure reply =
6376 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message);
6377 g_browser_process->policy_service()->RefreshPolicies(
6378 base::Bind(PostTask, BrowserThread::IO,
6379 base::Bind(PostTask, BrowserThread::FILE,
6380 base::Bind(PostTask, BrowserThread::IO,
6381 base::Bind(PostTask, BrowserThread::UI, reply)))));
6369 #endif 6382 #endif
6370 } 6383 }
6371 6384
6372 void TestingAutomationProvider::GetIndicesFromTab( 6385 void TestingAutomationProvider::GetIndicesFromTab(
6373 DictionaryValue* args, 6386 DictionaryValue* args,
6374 IPC::Message* reply_message) { 6387 IPC::Message* reply_message) {
6375 AutomationJSONReply reply(this, reply_message); 6388 AutomationJSONReply reply(this, reply_message);
6376 int id_or_handle = 0; 6389 int id_or_handle = 0;
6377 bool has_id = args->HasKey("tab_id"); 6390 bool has_id = args->HasKey("tab_id");
6378 bool has_handle = args->HasKey("tab_handle"); 6391 bool has_handle = args->HasKey("tab_handle");
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
7114 *browser_handle = browser_tracker_->Add(browser); 7127 *browser_handle = browser_tracker_->Add(browser);
7115 *success = true; 7128 *success = true;
7116 } 7129 }
7117 } 7130 }
7118 } 7131 }
7119 7132
7120 void TestingAutomationProvider::OnRemoveProvider() { 7133 void TestingAutomationProvider::OnRemoveProvider() {
7121 if (g_browser_process) 7134 if (g_browser_process)
7122 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7135 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
7123 } 7136 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/chromeos/login/existing_user_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698