OLD | NEW |
1 // Copyright (c) 2010 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_frame/chrome_frame_npapi.h" | 5 #include "chrome_frame/chrome_frame_npapi.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 const NPUTF8* ChromeFrameNPAPI::plugin_property_identifier_names_[] = { | 48 const NPUTF8* ChromeFrameNPAPI::plugin_property_identifier_names_[] = { |
49 "version", | 49 "version", |
50 "src", | 50 "src", |
51 "onload", | 51 "onload", |
52 "onloaderror", | 52 "onloaderror", |
53 "onmessage", | 53 "onmessage", |
54 "readystate", | 54 "readystate", |
55 "onprivatemessage", | 55 "onprivatemessage", |
56 "usechromenetwork", | 56 "usechromenetwork", |
57 "onclose", | 57 "onclose", |
58 "sessionid", | |
59 }; | 58 }; |
60 | 59 |
61 const NPUTF8* ChromeFrameNPAPI::plugin_method_identifier_names_[] = { | 60 const NPUTF8* ChromeFrameNPAPI::plugin_method_identifier_names_[] = { |
62 "postMessage", | 61 "postMessage", |
63 "postPrivateMessage", | 62 "postPrivateMessage", |
64 "installExtension", | |
65 "loadExtension", | |
66 "enableExtensionAutomation", | |
67 "getEnabledExtensions" | |
68 }; | 63 }; |
69 | 64 |
70 ChromeFrameNPAPI::PluginMethod ChromeFrameNPAPI::plugin_methods_[] = { | 65 ChromeFrameNPAPI::PluginMethod ChromeFrameNPAPI::plugin_methods_[] = { |
71 &ChromeFrameNPAPI::postMessage, | 66 &ChromeFrameNPAPI::postMessage, |
72 &ChromeFrameNPAPI::postPrivateMessage, | 67 &ChromeFrameNPAPI::postPrivateMessage, |
73 &ChromeFrameNPAPI::installExtension, | |
74 &ChromeFrameNPAPI::loadExtension, | |
75 &ChromeFrameNPAPI::enableExtensionAutomation, | |
76 &ChromeFrameNPAPI::getEnabledExtensions, | |
77 }; | 68 }; |
78 | 69 |
79 NPIdentifier | 70 NPIdentifier |
80 ChromeFrameNPAPI::plugin_method_identifiers_[arraysize(plugin_methods_)] | 71 ChromeFrameNPAPI::plugin_method_identifiers_[arraysize(plugin_methods_)] |
81 = {0}; | 72 = {0}; |
82 | 73 |
83 | 74 |
84 void ChromeFrameNPAPI::CompileAsserts() { | 75 void ChromeFrameNPAPI::CompileAsserts() { |
85 NOTREACHED(); // This function should never be invoked. | 76 NOTREACHED(); // This function should never be invoked. |
86 | 77 |
(...skipping 18 matching lines...) Expand all Loading... |
105 // When the privileged_mode property is provided and set to true, the control | 96 // When the privileged_mode property is provided and set to true, the control |
106 // will probe for whether its hosting document has the system principal, in | 97 // will probe for whether its hosting document has the system principal, in |
107 // which case privileged mode will be enabled. | 98 // which case privileged mode will be enabled. |
108 static const char kPluginPrivilegedModeAttribute[] = "privileged_mode"; | 99 static const char kPluginPrivilegedModeAttribute[] = "privileged_mode"; |
109 // If privileged mode is enabled, the string value of this argument will | 100 // If privileged mode is enabled, the string value of this argument will |
110 // be appended to the chrome.exe command line. | 101 // be appended to the chrome.exe command line. |
111 static const char kPluginChromeExtraArguments[] = "chrome_extra_arguments"; | 102 static const char kPluginChromeExtraArguments[] = "chrome_extra_arguments"; |
112 // If privileged mode is enabled, the string value of this argument will | 103 // If privileged mode is enabled, the string value of this argument will |
113 // be used as the profile name for our chrome.exe instance. | 104 // be used as the profile name for our chrome.exe instance. |
114 static const char kPluginChromeProfileName[] = "chrome_profile_name"; | 105 static const char kPluginChromeProfileName[] = "chrome_profile_name"; |
115 // If privileged mode is enabled, this argument will be taken as a | |
116 // comma-separated list of API function calls to automate. | |
117 static const char kPluginChromeFunctionsAutomatedAttribute[] = | |
118 "chrome_functions_automated"; | |
119 // If chrome network stack is to be used | 106 // If chrome network stack is to be used |
120 static const char kPluginUseChromeNetwork[] = "usechromenetwork"; | 107 static const char kPluginUseChromeNetwork[] = "usechromenetwork"; |
121 | 108 |
122 // ChromeFrameNPAPI member defines. | 109 // ChromeFrameNPAPI member defines. |
123 | 110 |
124 // TODO(tommi): remove ignore_setfocus_ since that's not how focus is | 111 // TODO(tommi): remove ignore_setfocus_ since that's not how focus is |
125 // handled anymore. | 112 // handled anymore. |
126 | 113 |
127 ChromeFrameNPAPI::ChromeFrameNPAPI() | 114 ChromeFrameNPAPI::ChromeFrameNPAPI() |
128 : instance_(NULL), | 115 : instance_(NULL), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // Test for the FireFox privileged mode if the user requests it | 195 // Test for the FireFox privileged mode if the user requests it |
209 // in initialization parameters. | 196 // in initialization parameters. |
210 wants_privileged = atoi(argv[i]) ? true : false; | 197 wants_privileged = atoi(argv[i]) ? true : false; |
211 } else if (LowerCaseEqualsASCII(argn[i], | 198 } else if (LowerCaseEqualsASCII(argn[i], |
212 kPluginOnPrivateMessageAttribute)) { | 199 kPluginOnPrivateMessageAttribute)) { |
213 onprivatemessage_arg = argv[i]; | 200 onprivatemessage_arg = argv[i]; |
214 } else if (LowerCaseEqualsASCII(argn[i], kPluginChromeExtraArguments)) { | 201 } else if (LowerCaseEqualsASCII(argn[i], kPluginChromeExtraArguments)) { |
215 chrome_extra_arguments_arg = argv[i]; | 202 chrome_extra_arguments_arg = argv[i]; |
216 } else if (LowerCaseEqualsASCII(argn[i], kPluginChromeProfileName)) { | 203 } else if (LowerCaseEqualsASCII(argn[i], kPluginChromeProfileName)) { |
217 chrome_profile_name_arg = argv[i]; | 204 chrome_profile_name_arg = argv[i]; |
218 } else if (LowerCaseEqualsASCII(argn[i], | |
219 kPluginChromeFunctionsAutomatedAttribute)) { | |
220 functions_enabled_.clear(); | |
221 // base::SplitString writes one empty entry for blank strings, so we need | |
222 // this to allow specifying zero automation of API functions. | |
223 if (argv[i][0] != '\0') | |
224 base::SplitString(argv[i], ',', &functions_enabled_); | |
225 } else if (LowerCaseEqualsASCII(argn[i], kPluginUseChromeNetwork)) { | 205 } else if (LowerCaseEqualsASCII(argn[i], kPluginUseChromeNetwork)) { |
226 chrome_network_arg_set = true; | 206 chrome_network_arg_set = true; |
227 chrome_network_arg = atoi(argv[i]) ? true : false; | 207 chrome_network_arg = atoi(argv[i]) ? true : false; |
228 } | 208 } |
229 } | 209 } |
230 | 210 |
231 // Is the privileged mode requested? | 211 // Is the privileged mode requested? |
232 if (wants_privileged) { | 212 if (wants_privileged) { |
233 set_is_privileged(IsFireFoxPrivilegedInvocation(instance)); | 213 set_is_privileged(IsFireFoxPrivilegedInvocation(instance)); |
234 if (!is_privileged()) { | 214 if (!is_privileged()) { |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 automation_client_->GetVersion(); | 639 automation_client_->GetVersion(); |
660 AllocateStringVariant(WideToUTF8(version), variant); | 640 AllocateStringVariant(WideToUTF8(version), variant); |
661 return true; | 641 return true; |
662 } else if (name == plugin_property_identifiers_[PLUGIN_PROPERTY_READYSTATE]) { | 642 } else if (name == plugin_property_identifiers_[PLUGIN_PROPERTY_READYSTATE]) { |
663 INT32_TO_NPVARIANT(ready_state_, *variant); | 643 INT32_TO_NPVARIANT(ready_state_, *variant); |
664 return true; | 644 return true; |
665 } else if (name == | 645 } else if (name == |
666 plugin_property_identifiers_[PLUGIN_PROPERTY_USECHROMENETWORK]) { | 646 plugin_property_identifiers_[PLUGIN_PROPERTY_USECHROMENETWORK]) { |
667 BOOLEAN_TO_NPVARIANT(automation_client_->use_chrome_network(), *variant); | 647 BOOLEAN_TO_NPVARIANT(automation_client_->use_chrome_network(), *variant); |
668 return true; | 648 return true; |
669 } else if (name == plugin_property_identifiers_[PLUGIN_PROPERTY_SESSIONID]) { | |
670 if (!is_privileged()) { | |
671 DLOG(WARNING) << "Attempt to read sessionid property while not " | |
672 "privileged"; | |
673 } else { | |
674 INT32_TO_NPVARIANT(automation_client_->GetSessionId(), *variant); | |
675 return true; | |
676 } | |
677 } | 649 } |
678 | 650 |
679 return false; | 651 return false; |
680 } | 652 } |
681 | 653 |
682 bool ChromeFrameNPAPI::GetProperty(NPObject* object, NPIdentifier name, | 654 bool ChromeFrameNPAPI::GetProperty(NPObject* object, NPIdentifier name, |
683 NPVariant* variant) { | 655 NPVariant* variant) { |
684 if (!object || !variant) { | 656 if (!object || !variant) { |
685 NOTREACHED(); | 657 NOTREACHED(); |
686 return false; | 658 return false; |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 const NPString& target_str = args[2].value.stringValue; | 1203 const NPString& target_str = args[2].value.stringValue; |
1232 std::string message(message_str.UTF8Characters, message_str.UTF8Length); | 1204 std::string message(message_str.UTF8Characters, message_str.UTF8Length); |
1233 std::string origin(origin_str.UTF8Characters, origin_str.UTF8Length); | 1205 std::string origin(origin_str.UTF8Characters, origin_str.UTF8Length); |
1234 std::string target(target_str.UTF8Characters, target_str.UTF8Length); | 1206 std::string target(target_str.UTF8Characters, target_str.UTF8Length); |
1235 | 1207 |
1236 automation_client_->ForwardMessageFromExternalHost(message, origin, target); | 1208 automation_client_->ForwardMessageFromExternalHost(message, origin, target); |
1237 | 1209 |
1238 return true; | 1210 return true; |
1239 } | 1211 } |
1240 | 1212 |
1241 bool ChromeFrameNPAPI::installExtension(NPObject* npobject, | |
1242 const NPVariant* args, | |
1243 uint32_t arg_count, | |
1244 NPVariant* result) { | |
1245 if (arg_count > 2 || !NPVARIANT_IS_STRING(args[0]) || | |
1246 (arg_count == 2 && !NPVARIANT_IS_OBJECT(args[1]))) { | |
1247 NOTREACHED(); | |
1248 return false; | |
1249 } | |
1250 | |
1251 if (!is_privileged()) { | |
1252 DLOG(WARNING) << "installExtension invoked in non-privileged mode"; | |
1253 return false; | |
1254 } | |
1255 | |
1256 if (!automation_client_.get()) { | |
1257 DLOG(WARNING) << "installExtension invoked with no automaton client"; | |
1258 NOTREACHED(); | |
1259 return false; | |
1260 } | |
1261 | |
1262 const NPString& crx_path_str = args[0].value.stringValue; | |
1263 std::string crx_path_a(crx_path_str.UTF8Characters, crx_path_str.UTF8Length); | |
1264 FilePath::StringType crx_path_u(UTF8ToWide(crx_path_a)); | |
1265 FilePath crx_path(crx_path_u); | |
1266 NPObject* retained_function = npapi::RetainObject(args[1].value.objectValue); | |
1267 | |
1268 automation_client_->InstallExtension(crx_path, retained_function); | |
1269 // The response to this command will be returned in the OnExtensionInstalled | |
1270 // delegate callback function. | |
1271 | |
1272 return true; | |
1273 } | |
1274 | |
1275 void ChromeFrameNPAPI::OnExtensionInstalled( | |
1276 const FilePath& path, | |
1277 void* user_data, | |
1278 AutomationMsg_ExtensionResponseValues res) { | |
1279 ScopedNpVariant result; | |
1280 NPVariant param; | |
1281 INT32_TO_NPVARIANT(res, param); | |
1282 NPObject* func = reinterpret_cast<NPObject*>(user_data); | |
1283 | |
1284 InvokeDefault(func, param, &result); | |
1285 npapi::ReleaseObject(func); | |
1286 } | |
1287 | |
1288 bool ChromeFrameNPAPI::loadExtension(NPObject* npobject, | |
1289 const NPVariant* args, | |
1290 uint32_t arg_count, | |
1291 NPVariant* result) { | |
1292 if (arg_count > 2 || !NPVARIANT_IS_STRING(args[0]) || | |
1293 (arg_count == 2 && !NPVARIANT_IS_OBJECT(args[1]))) { | |
1294 NOTREACHED(); | |
1295 return false; | |
1296 } | |
1297 | |
1298 if (!is_privileged()) { | |
1299 DLOG(WARNING) << "loadExtension invoked in non-privileged mode"; | |
1300 return false; | |
1301 } | |
1302 | |
1303 if (!automation_client_.get()) { | |
1304 DLOG(WARNING) << "loadExtension invoked with no automaton client"; | |
1305 NOTREACHED(); | |
1306 return false; | |
1307 } | |
1308 | |
1309 const NPString& path_str = args[0].value.stringValue; | |
1310 std::string path_a(path_str.UTF8Characters, path_str.UTF8Length); | |
1311 FilePath::StringType path_u(UTF8ToWide(path_a)); | |
1312 FilePath path(path_u); | |
1313 NPObject* retained_function = npapi::RetainObject(args[1].value.objectValue); | |
1314 | |
1315 automation_client_->LoadExpandedExtension(path, retained_function); | |
1316 // The response to this command will be returned in the OnExtensionInstalled | |
1317 // delegate callback function. | |
1318 | |
1319 return true; | |
1320 } | |
1321 | |
1322 bool ChromeFrameNPAPI::enableExtensionAutomation(NPObject* npobject, | |
1323 const NPVariant* args, | |
1324 uint32_t arg_count, | |
1325 NPVariant* result) { | |
1326 if (arg_count > 1 || (arg_count == 1 && !NPVARIANT_IS_STRING(args[0]))) { | |
1327 NOTREACHED(); | |
1328 return false; | |
1329 } | |
1330 | |
1331 if (!is_privileged()) { | |
1332 DLOG(WARNING) << | |
1333 "enableExtensionAutomation invoked in non-privileged mode"; | |
1334 return false; | |
1335 } | |
1336 | |
1337 if (!automation_client_.get()) { | |
1338 DLOG(WARNING) << | |
1339 "enableExtensionAutomation invoked with no automaton client"; | |
1340 NOTREACHED(); | |
1341 return false; | |
1342 } | |
1343 | |
1344 if (!automation_client_->tab()) { | |
1345 DLOG(WARNING) << "enableExtensionAutomation invoked with no hosted tab"; | |
1346 NOTREACHED(); | |
1347 return false; | |
1348 } | |
1349 | |
1350 // Empty by default e.g. if no arguments passed. | |
1351 std::vector<std::string> functions; | |
1352 | |
1353 if (arg_count == 1) { | |
1354 const NPString& functions_str = args[0].value.stringValue; | |
1355 std::string functions_a(functions_str.UTF8Characters, | |
1356 functions_str.UTF8Length); | |
1357 | |
1358 // base::SplitString writes one empty entry for blank strings, so we need | |
1359 // this to allow specifying zero automation of API functions. | |
1360 if (functions_a[0] != '\0') | |
1361 base::SplitString(functions_a, ',', &functions); | |
1362 } | |
1363 | |
1364 automation_client_->tab()->SetEnableExtensionAutomation(functions); | |
1365 // This function returns no result. | |
1366 | |
1367 return true; | |
1368 } | |
1369 | |
1370 bool ChromeFrameNPAPI::getEnabledExtensions(NPObject* npobject, | |
1371 const NPVariant* args, | |
1372 uint32_t arg_count, | |
1373 NPVariant* result) { | |
1374 if (arg_count > 1 || !NPVARIANT_IS_OBJECT(args[0])) { | |
1375 NOTREACHED(); | |
1376 return false; | |
1377 } | |
1378 | |
1379 if (!is_privileged()) { | |
1380 DLOG(WARNING) << "getEnabledExtensions invoked in non-privileged mode"; | |
1381 return false; | |
1382 } | |
1383 | |
1384 if (!automation_client_.get()) { | |
1385 DLOG(WARNING) << "getEnabledExtensions invoked with no automaton client"; | |
1386 NOTREACHED(); | |
1387 return false; | |
1388 } | |
1389 | |
1390 NPObject* retained_function = npapi::RetainObject(args[0].value.objectValue); | |
1391 | |
1392 automation_client_->GetEnabledExtensions(retained_function); | |
1393 // The response to this command will be returned in the | |
1394 // OnGetEnabledExtensionsCompleted delegate callback function. | |
1395 | |
1396 return true; | |
1397 } | |
1398 | |
1399 void ChromeFrameNPAPI::OnGetEnabledExtensionsComplete( | |
1400 void* user_data, | |
1401 const std::vector<FilePath>& extension_directories) { | |
1402 std::vector<std::wstring> extension_paths; | |
1403 for (size_t i = 0; i < extension_directories.size(); ++i) { | |
1404 extension_paths.push_back(extension_directories[i].value()); | |
1405 } | |
1406 std::wstring tab_delimited = JoinString(extension_paths, L'\t'); | |
1407 | |
1408 std::string res = WideToUTF8(tab_delimited); | |
1409 | |
1410 ScopedNpVariant result; | |
1411 NPVariant param; | |
1412 STRINGN_TO_NPVARIANT(res.c_str(), res.length(), param); | |
1413 | |
1414 NPObject* func = reinterpret_cast<NPObject*>(user_data); | |
1415 InvokeDefault(func, param, &result); | |
1416 npapi::ReleaseObject(func); | |
1417 } | |
1418 | |
1419 void ChromeFrameNPAPI::FireEvent(const std::string& event_type, | 1213 void ChromeFrameNPAPI::FireEvent(const std::string& event_type, |
1420 const std::string& data) { | 1214 const std::string& data) { |
1421 NPVariant arg; | 1215 NPVariant arg; |
1422 STRINGN_TO_NPVARIANT(data.c_str(), data.length(), arg); | 1216 STRINGN_TO_NPVARIANT(data.c_str(), data.length(), arg); |
1423 FireEvent(event_type, arg); | 1217 FireEvent(event_type, arg); |
1424 } | 1218 } |
1425 | 1219 |
1426 void ChromeFrameNPAPI::FireEvent(const std::string& event_type, | 1220 void ChromeFrameNPAPI::FireEvent(const std::string& event_type, |
1427 const NPVariant& data) { | 1221 const NPVariant& data) { |
1428 // Check that we're not bundling an event inside an event. | 1222 // Check that we're not bundling an event inside an event. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 void ChromeFrameNPAPI::URLRedirectNotify(const char* url, int status, | 1307 void ChromeFrameNPAPI::URLRedirectNotify(const char* url, int status, |
1514 void* notify_data) { | 1308 void* notify_data) { |
1515 DVLOG(1) << __FUNCTION__ | 1309 DVLOG(1) << __FUNCTION__ |
1516 << "Received redirect notification for url:" | 1310 << "Received redirect notification for url:" |
1517 << url; | 1311 << url; |
1518 // Inform chrome about the redirect and disallow the current redirect | 1312 // Inform chrome about the redirect and disallow the current redirect |
1519 // attempt. | 1313 // attempt. |
1520 url_fetcher_.UrlRedirectNotify(url, status, notify_data); | 1314 url_fetcher_.UrlRedirectNotify(url, status, notify_data); |
1521 npapi::URLRedirectResponse(instance_, notify_data, false); | 1315 npapi::URLRedirectResponse(instance_, notify_data, false); |
1522 } | 1316 } |
1523 | |
OLD | NEW |