summaryrefslogtreecommitdiffstats
path: root/chrome_frame/chrome_frame_npapi.cc
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-08 16:22:31 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-08 16:22:31 +0000
commit87258a289e1d0732af8716d0aa5e910fc8c955be (patch)
treed654d37c6d81a85f1f32e8c843bbc8d6cbd63832 /chrome_frame/chrome_frame_npapi.cc
parent4cfc1d9243eaf01a3b736fa13f55b7400a891fb4 (diff)
downloadchromium_src-87258a289e1d0732af8716d0aa5e910fc8c955be.zip
chromium_src-87258a289e1d0732af8716d0aa5e910fc8c955be.tar.gz
chromium_src-87258a289e1d0732af8716d0aa5e910fc8c955be.tar.bz2
Allowing JS to set/reset extension automation, this makes for more
flexible testing when you want to automate different sets of functions in different tests. Now instead of needing to destroy your CF and then create a new one with a different automation functions attribute, you can just call the function to reset on the existing one, then call it again to enable a different set. BUG=none TEST=none Review URL: http://codereview.chromium.org/375014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/chrome_frame_npapi.cc')
-rw-r--r--chrome_frame/chrome_frame_npapi.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/chrome_frame/chrome_frame_npapi.cc b/chrome_frame/chrome_frame_npapi.cc
index 343a46d..620db8d 100644
--- a/chrome_frame/chrome_frame_npapi.cc
+++ b/chrome_frame/chrome_frame_npapi.cc
@@ -57,6 +57,7 @@ const NPUTF8* ChromeFrameNPAPI::plugin_method_identifier_names_[] = {
"postPrivateMessage",
"installExtension",
"loadExtension",
+ "enableExtensionAutomation"
};
ChromeFrameNPAPI::PluginMethod ChromeFrameNPAPI::plugin_methods_[] = {
@@ -64,6 +65,7 @@ ChromeFrameNPAPI::PluginMethod ChromeFrameNPAPI::plugin_methods_[] = {
&ChromeFrameNPAPI::postPrivateMessage,
&ChromeFrameNPAPI::installExtension,
&ChromeFrameNPAPI::loadExtension,
+ &ChromeFrameNPAPI::enableExtensionAutomation,
};
NPIdentifier
@@ -1339,6 +1341,7 @@ bool ChromeFrameNPAPI::NavigateToURL(const NPVariant* args, uint32_t arg_count,
bool ChromeFrameNPAPI::postMessage(NPObject* npobject, const NPVariant* args,
uint32_t arg_count, NPVariant* result) {
+ // TODO(tommi) See if we can factor these checks out somehow.
if (arg_count < 1 || arg_count > 2 || !NPVARIANT_IS_STRING(args[0])) {
NOTREACHED();
return false;
@@ -1479,6 +1482,54 @@ bool ChromeFrameNPAPI::loadExtension(NPObject* npobject,
return true;
}
+bool ChromeFrameNPAPI::enableExtensionAutomation(NPObject* npobject,
+ const NPVariant* args,
+ uint32_t arg_count,
+ NPVariant* result) {
+ if (arg_count > 1 || (arg_count == 1 && !NPVARIANT_IS_STRING(args[0]))) {
+ NOTREACHED();
+ return false;
+ }
+
+ if (!is_privileged_) {
+ DLOG(WARNING) <<
+ "enableExtensionAutomation invoked in non-privileged mode";
+ return false;
+ }
+
+ if (!automation_client_.get()) {
+ DLOG(WARNING) <<
+ "enableExtensionAutomation invoked with no automaton client";
+ NOTREACHED();
+ return false;
+ }
+
+ if (!automation_client_->tab()) {
+ DLOG(WARNING) << "enableExtensionAutomation invoked with no hosted tab";
+ NOTREACHED();
+ return false;
+ }
+
+ // Empty by default e.g. if no arguments passed.
+ std::vector<std::string> functions;
+
+ if (arg_count == 1) {
+ const NPString& functions_str = args[0].value.stringValue;
+ std::string functions_a(functions_str.UTF8Characters,
+ functions_str.UTF8Length);
+
+ // SplitString writes one empty entry for blank strings, so we need this
+ // to allow specifying zero automation of API functions.
+ if (functions_a[0] != '\0')
+ SplitString(functions_a, ',', &functions);
+ }
+
+ automation_client_->tab()->SetEnableExtensionAutomation(functions);
+ // This function returns no result.
+
+ return true;
+}
+
void ChromeFrameNPAPI::FireEvent(const std::string& event_type,
const std::string& data) {
NPVariant arg;