OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "Chrome.h" | 10 #include "Chrome.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "PluginData.h" | 24 #include "PluginData.h" |
25 #include "StringExtras.h" | 25 #include "StringExtras.h" |
26 #include "WindowFeatures.h" | 26 #include "WindowFeatures.h" |
27 #undef LOG | 27 #undef LOG |
28 | 28 |
29 #include "base/basictypes.h" | 29 #include "base/basictypes.h" |
30 #include "base/logging.h" | 30 #include "base/logging.h" |
31 #include "base/string_util.h" | 31 #include "base/string_util.h" |
32 #include "net/base/mime_util.h" | 32 #include "net/base/mime_util.h" |
33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
34 #if defined(OS_WIN) | |
35 #include "webkit/activex_shim/activex_shared.h" | |
36 #endif | |
37 #include "webkit/api/public/WebForm.h" | 34 #include "webkit/api/public/WebForm.h" |
| 35 #include "webkit/api/public/WebPlugin.h" |
| 36 #include "webkit/api/public/WebPluginParams.h" |
38 #include "webkit/api/public/WebURL.h" | 37 #include "webkit/api/public/WebURL.h" |
39 #include "webkit/api/public/WebURLError.h" | 38 #include "webkit/api/public/WebURLError.h" |
40 #include "webkit/api/public/WebVector.h" | 39 #include "webkit/api/public/WebVector.h" |
41 #include "webkit/api/src/WebDataSourceImpl.h" | 40 #include "webkit/api/src/WebDataSourceImpl.h" |
42 #include "webkit/api/src/WebPluginContainerImpl.h" | 41 #include "webkit/api/src/WebPluginContainerImpl.h" |
43 #include "webkit/api/src/WebPluginLoadObserver.h" | 42 #include "webkit/api/src/WebPluginLoadObserver.h" |
44 #include "webkit/api/src/WrappedResourceRequest.h" | 43 #include "webkit/api/src/WrappedResourceRequest.h" |
45 #include "webkit/api/src/WrappedResourceResponse.h" | 44 #include "webkit/api/src/WrappedResourceResponse.h" |
46 #include "webkit/glue/glue_util.h" | 45 #include "webkit/glue/glue_util.h" |
47 #include "webkit/glue/plugins/plugin_list.h" | 46 #include "webkit/glue/plugins/plugin_list.h" |
48 #include "webkit/glue/webdevtoolsagent_impl.h" | 47 #include "webkit/glue/webdevtoolsagent_impl.h" |
49 #include "webkit/glue/webframe_impl.h" | 48 #include "webkit/glue/webframe_impl.h" |
50 #include "webkit/glue/webframeloaderclient_impl.h" | 49 #include "webkit/glue/webframeloaderclient_impl.h" |
51 #include "webkit/glue/webkit_glue.h" | 50 #include "webkit/glue/webkit_glue.h" |
52 #include "webkit/glue/webplugin_delegate.h" | |
53 #include "webkit/glue/webplugin_impl.h" | |
54 #include "webkit/glue/webview_delegate.h" | 51 #include "webkit/glue/webview_delegate.h" |
55 #include "webkit/glue/webview_impl.h" | 52 #include "webkit/glue/webview_impl.h" |
56 | 53 |
57 using namespace WebCore; | 54 using namespace WebCore; |
58 | 55 |
59 using base::Time; | 56 using base::Time; |
60 using base::TimeDelta; | 57 using base::TimeDelta; |
61 | 58 |
62 using WebKit::WebData; | 59 using WebKit::WebData; |
63 using WebKit::WebDataSourceImpl; | 60 using WebKit::WebDataSourceImpl; |
64 using WebKit::WebNavigationType; | 61 using WebKit::WebNavigationType; |
65 using WebKit::WebNavigationPolicy; | 62 using WebKit::WebNavigationPolicy; |
| 63 using WebKit::WebPlugin; |
66 using WebKit::WebPluginContainerImpl; | 64 using WebKit::WebPluginContainerImpl; |
67 using WebKit::WebPluginLoadObserver; | 65 using WebKit::WebPluginLoadObserver; |
| 66 using WebKit::WebPluginParams; |
68 using WebKit::WebString; | 67 using WebKit::WebString; |
69 using WebKit::WebURL; | 68 using WebKit::WebURL; |
70 using WebKit::WebURLError; | 69 using WebKit::WebURLError; |
71 using WebKit::WebURLRequest; | 70 using WebKit::WebURLRequest; |
72 using WebKit::WebVector; | 71 using WebKit::WebVector; |
73 using WebKit::WrappedResourceRequest; | 72 using WebKit::WrappedResourceRequest; |
74 using WebKit::WrappedResourceResponse; | 73 using WebKit::WrappedResourceResponse; |
75 | 74 |
76 // Domain for internal error codes. | 75 // Domain for internal error codes. |
77 static const char kInternalErrorDomain[] = "webkit_glue"; | 76 static const char kInternalErrorDomain[] = "webkit_glue"; |
78 | 77 |
79 // An internal error code. Used to note a policy change error resulting from | 78 // An internal error code. Used to note a policy change error resulting from |
80 // dispatchDecidePolicyForMIMEType not passing the PolicyUse option. | 79 // dispatchDecidePolicyForMIMEType not passing the PolicyUse option. |
81 enum { | 80 enum { |
82 ERR_POLICY_CHANGE = -10000, | 81 ERR_POLICY_CHANGE = -10000, |
83 }; | 82 }; |
84 | 83 |
| 84 static void CopyStringVector( |
| 85 const Vector<String>& input, WebVector<WebString>* output) { |
| 86 WebVector<WebString> result(input.size()); |
| 87 for (size_t i = 0; i < input.size(); ++i) |
| 88 result[i] = webkit_glue::StringToWebString(input[i]); |
| 89 output->swap(result); |
| 90 } |
| 91 |
85 WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) | 92 WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) |
86 : webframe_(frame), | 93 : webframe_(frame), |
87 has_representation_(false), | 94 has_representation_(false), |
88 sent_initial_response_to_plugin_(false), | 95 sent_initial_response_to_plugin_(false), |
89 next_navigation_policy_(WebKit::WebNavigationPolicyIgnore) { | 96 next_navigation_policy_(WebKit::WebNavigationPolicyIgnore) { |
90 } | 97 } |
91 | 98 |
92 WebFrameLoaderClient::~WebFrameLoaderClient() { | 99 WebFrameLoaderClient::~WebFrameLoaderClient() { |
93 } | 100 } |
94 | 101 |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 const String& name, | 1212 const String& name, |
1206 HTMLFrameOwnerElement* owner_element, | 1213 HTMLFrameOwnerElement* owner_element, |
1207 const String& referrer, | 1214 const String& referrer, |
1208 bool allows_scrolling, | 1215 bool allows_scrolling, |
1209 int margin_width, | 1216 int margin_width, |
1210 int margin_height) { | 1217 int margin_height) { |
1211 FrameLoadRequest frame_request(ResourceRequest(url, referrer), name); | 1218 FrameLoadRequest frame_request(ResourceRequest(url, referrer), name); |
1212 return webframe_->CreateChildFrame(frame_request, owner_element); | 1219 return webframe_->CreateChildFrame(frame_request, owner_element); |
1213 } | 1220 } |
1214 | 1221 |
1215 // Utility function to convert a vector to an array of char*'s. | 1222 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin( |
1216 // Caller is responsible to free memory with DeleteToArray(). | 1223 const IntSize& size, // TODO(erikkay): how do we use this? |
1217 static char** ToArray(const Vector<WebCore::String> &vector) { | 1224 HTMLPlugInElement* element, |
1218 char **rv = new char *[vector.size()+1]; | 1225 const KURL& url, |
1219 unsigned int index = 0; | 1226 const Vector<String>& param_names, |
1220 for (index = 0; index < vector.size(); ++index) { | 1227 const Vector<String>& param_values, |
1221 WebCore::CString src = vector[index].utf8(); | 1228 const String& mime_type, |
1222 rv[index] = new char[src.length() + 1]; | 1229 bool load_manually) { |
1223 base::strlcpy(rv[index], src.data(), src.length() + 1); | |
1224 rv[index][src.length()] = '\0'; | |
1225 } | |
1226 rv[index] = 0; | |
1227 return rv; | |
1228 } | |
1229 | |
1230 static void DeleteToArray(char** arr) { | |
1231 char **ptr = arr; | |
1232 while (*ptr != 0) { | |
1233 delete [] *ptr; | |
1234 ++ptr; | |
1235 } | |
1236 delete [] arr; | |
1237 } | |
1238 | |
1239 PassRefPtr<Widget> WebFrameLoaderClient::createPlugin(const IntSize& size, // TO
DO(erikkay): how do we use this? | |
1240 HTMLPlugInElement* element, | |
1241 const KURL&url, | |
1242 const Vector<String>& param_names, | |
1243 const Vector<String>& param_values, | |
1244 const String& mime_type, | |
1245 bool load_manually) { | |
1246 WebViewImpl* webview = webframe_->GetWebViewImpl(); | |
1247 WebViewDelegate* d = webview->delegate(); | |
1248 if (!d) | |
1249 return NULL; | |
1250 | |
1251 GURL gurl = webkit_glue::KURLToGURL(url); | |
1252 std::string my_mime_type = | |
1253 webkit_glue::CStringToStdString(mime_type.latin1()); | |
1254 StringToLowerASCII(&my_mime_type); | |
1255 | |
1256 // Get the classid and version from attributes of the object. | |
1257 std::string combined_clsid; | |
1258 #if defined(OS_WIN) | |
1259 std::string clsid, version; | |
1260 if (activex_shim::IsMimeTypeActiveX(my_mime_type)) { | |
1261 GURL url = webframe_->url(); | |
1262 for (unsigned int i = 0; i < param_names.size(); i++) { | |
1263 String lowercase_param_name = param_names[i].lower(); | |
1264 if (lowercase_param_name == "classid") { | |
1265 activex_shim::GetClsidFromClassidAttribute( | |
1266 webkit_glue::CStringToStdString(param_values[i].latin1()), &clsid); | |
1267 } else if (lowercase_param_name == "codebase") { | |
1268 version = activex_shim::GetVersionFromCodebaseAttribute( | |
1269 webkit_glue::CStringToStdString(param_values[i].latin1())); | |
1270 } | |
1271 } | |
1272 | |
1273 // Attempt to map this clsid to a known NPAPI mime type if possible, failing | |
1274 // which we attempt to load the activex shim for the clsid. | |
1275 if (!activex_shim::GetMimeTypeForClsid(clsid, &my_mime_type)) { | |
1276 // We need to pass the combined clsid + version to PluginsList, so that it | |
1277 // would detect if the requested version is installed. If not, it needs | |
1278 // to use the default plugin to update the control. | |
1279 if (!version.empty()) | |
1280 combined_clsid = clsid + "#" + version; | |
1281 else | |
1282 combined_clsid = clsid; | |
1283 } | |
1284 } | |
1285 #endif | |
1286 | |
1287 #if defined(OS_POSIX) | 1230 #if defined(OS_POSIX) |
1288 // WebCore asks us to make a plugin even if we don't have a | 1231 // WebCore asks us to make a plugin even if we don't have a |
1289 // registered handler, with a comment saying it's so we can display | 1232 // registered handler, with a comment saying it's so we can display |
1290 // the broken plugin icon. In Chromium, we normally register a | 1233 // the broken plugin icon. In Chromium, we normally register a |
1291 // fallback plugin handler that allows you to install a missing | 1234 // fallback plugin handler that allows you to install a missing |
1292 // plugin. Since we don't yet have a default plugin handler, we | 1235 // plugin. Since we don't yet have a default plugin handler, we |
1293 // need to return NULL here rather than going through all the | 1236 // need to return NULL here rather than going through all the |
1294 // plugin-creation IPCs only to discover we don't have a plugin | 1237 // plugin-creation IPCs only to discover we don't have a plugin |
1295 // registered, which causes a crash. | 1238 // registered, which causes a crash. |
1296 // TODO(evanm): remove me once we have a default plugin. | 1239 // TODO(evanm): remove me once we have a default plugin. |
1297 if (objectContentType(url, mime_type) != ObjectContentNetscapePlugin) | 1240 if (objectContentType(url, mime_type) != ObjectContentNetscapePlugin) |
1298 return NULL; | 1241 return NULL; |
1299 #endif | 1242 #endif |
1300 | 1243 |
1301 std::string actual_mime_type; | 1244 WebViewImpl* webview = webframe_->GetWebViewImpl(); |
1302 WebPluginDelegate* plugin_delegate = | 1245 if (!webview->delegate()) |
1303 d->CreatePluginDelegate(webframe_->GetWebViewImpl(), gurl, my_mime_type, | |
1304 combined_clsid, &actual_mime_type); | |
1305 if (!plugin_delegate) | |
1306 return NULL; | 1246 return NULL; |
1307 | 1247 |
1308 if (!actual_mime_type.empty()) | 1248 WebPluginParams params; |
1309 my_mime_type = actual_mime_type; | 1249 params.url = webkit_glue::KURLToWebURL(url); |
| 1250 params.mimeType = webkit_glue::StringToWebString(mime_type); |
| 1251 CopyStringVector(param_names, ¶ms.attributeNames); |
| 1252 CopyStringVector(param_values, ¶ms.attributeValues); |
| 1253 params.loadManually = load_manually; |
1310 | 1254 |
1311 DCHECK(param_names.size() == param_values.size()); | 1255 WebPlugin* webplugin = webview->delegate()->CreatePlugin(webframe_, params); |
| 1256 if (!webplugin) |
| 1257 return NULL; |
1312 | 1258 |
1313 char **argn = ToArray(param_names); | 1259 // The container takes ownership of the WebPlugin. |
1314 char **argv = ToArray(param_values); | 1260 RefPtr<WebPluginContainerImpl> container = |
1315 int argc = static_cast<int>(param_names.size()); | 1261 WebPluginContainerImpl::create(element, webplugin); |
1316 RefPtr<Widget> result = WebPluginImpl::Create(gurl, argn, argv, argc, element, | |
1317 webframe_, plugin_delegate, | |
1318 load_manually, my_mime_type); | |
1319 | 1262 |
1320 DeleteToArray(argn); | 1263 if (!webplugin->initialize(container.get())) |
1321 DeleteToArray(argv); | 1264 return NULL; |
1322 | 1265 |
1323 return result; | 1266 return container; |
1324 } | 1267 } |
1325 | 1268 |
1326 // This method gets called when a plugin is put in place of html content | 1269 // This method gets called when a plugin is put in place of html content |
1327 // (e.g., acrobat reader). | 1270 // (e.g., acrobat reader). |
1328 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget) { | 1271 void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget) { |
1329 plugin_widget_ = static_cast<WebPluginContainerImpl*>(pluginWidget); | 1272 plugin_widget_ = static_cast<WebPluginContainerImpl*>(pluginWidget); |
1330 DCHECK(plugin_widget_.get()); | 1273 DCHECK(plugin_widget_.get()); |
1331 } | 1274 } |
1332 | 1275 |
1333 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget( | 1276 PassRefPtr<Widget> WebFrameLoaderClient::createJavaAppletWidget( |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); | 1377 WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); |
1435 if (d) | 1378 if (d) |
1436 d->NavigateBackForwardSoon(offset); | 1379 d->NavigateBackForwardSoon(offset); |
1437 } | 1380 } |
1438 | 1381 |
1439 PassOwnPtr<WebPluginLoadObserver> WebFrameLoaderClient::GetPluginLoadObserver()
{ | 1382 PassOwnPtr<WebPluginLoadObserver> WebFrameLoaderClient::GetPluginLoadObserver()
{ |
1440 WebDataSourceImpl* ds = WebDataSourceImpl::fromDocumentLoader( | 1383 WebDataSourceImpl* ds = WebDataSourceImpl::fromDocumentLoader( |
1441 webframe_->frame()->loader()->activeDocumentLoader()); | 1384 webframe_->frame()->loader()->activeDocumentLoader()); |
1442 return ds->releasePluginLoadObserver(); | 1385 return ds->releasePluginLoadObserver(); |
1443 } | 1386 } |
OLD | NEW |