| OLD | NEW |
| 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 "content/renderer/npapi/webplugin_impl.h" | 5 #include "content/renderer/npapi/webplugin_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 bool WebPluginImpl::initialize(WebPluginContainer* container) { | 237 bool WebPluginImpl::initialize(WebPluginContainer* container) { |
| 238 if (!render_view_.get()) { | 238 if (!render_view_.get()) { |
| 239 LOG(ERROR) << "No RenderView"; | 239 LOG(ERROR) << "No RenderView"; |
| 240 return false; | 240 return false; |
| 241 } | 241 } |
| 242 | 242 |
| 243 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( | 243 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( |
| 244 this, mime_type_, render_view_, render_frame_); | 244 this, mime_type_, render_view_, render_frame_); |
| 245 | 245 |
| 246 // Store the plugin's unique identifier, used by the container to track its | |
| 247 // script objects. | |
| 248 npp_ = plugin_delegate->GetPluginNPP(); | |
| 249 | |
| 250 // Set the container before Initialize because the plugin may | 246 // Set the container before Initialize because the plugin may |
| 251 // synchronously call NPN_GetValue to get its container, or make calls | 247 // synchronously call NPN_GetValue to get its container, or make calls |
| 252 // passing script objects that need to be tracked, during initialization. | 248 // passing script objects that need to be tracked, during initialization. |
| 253 SetContainer(container); | 249 SetContainer(container); |
| 254 | 250 |
| 255 bool ok = plugin_delegate->Initialize( | 251 bool ok = plugin_delegate->Initialize( |
| 256 plugin_url_, arg_names_, arg_values_, load_manually_); | 252 plugin_url_, arg_names_, arg_values_, load_manually_); |
| 257 if (!ok) { | 253 if (!ok) { |
| 258 plugin_delegate->PluginDestroyed(); | 254 plugin_delegate->PluginDestroyed(); |
| 259 | 255 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 280 delegate_ = plugin_delegate; | 276 delegate_ = plugin_delegate; |
| 281 | 277 |
| 282 return true; | 278 return true; |
| 283 } | 279 } |
| 284 | 280 |
| 285 void WebPluginImpl::destroy() { | 281 void WebPluginImpl::destroy() { |
| 286 SetContainer(NULL); | 282 SetContainer(NULL); |
| 287 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 283 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 288 } | 284 } |
| 289 | 285 |
| 290 NPObject* WebPluginImpl::scriptableObject() { | |
| 291 if (!delegate_) | |
| 292 return NULL; | |
| 293 | |
| 294 return delegate_->GetPluginScriptableObject(); | |
| 295 } | |
| 296 | |
| 297 NPP WebPluginImpl::pluginNPP() { | |
| 298 return npp_; | |
| 299 } | |
| 300 | |
| 301 bool WebPluginImpl::getFormValue(blink::WebString& value) { | 286 bool WebPluginImpl::getFormValue(blink::WebString& value) { |
| 302 if (!delegate_) | 287 if (!delegate_) |
| 303 return false; | 288 return false; |
| 304 base::string16 form_value; | 289 base::string16 form_value; |
| 305 if (!delegate_->GetFormValue(&form_value)) | 290 if (!delegate_->GetFormValue(&form_value)) |
| 306 return false; | 291 return false; |
| 307 value = form_value; | 292 value = form_value; |
| 308 return true; | 293 return true; |
| 309 } | 294 } |
| 310 | 295 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 const base::WeakPtr<RenderViewImpl>& render_view, | 466 const base::WeakPtr<RenderViewImpl>& render_view, |
| 482 RenderFrameImpl* render_frame) | 467 RenderFrameImpl* render_frame) |
| 483 : windowless_(false), | 468 : windowless_(false), |
| 484 window_(gfx::kNullPluginWindow), | 469 window_(gfx::kNullPluginWindow), |
| 485 accepts_input_events_(false), | 470 accepts_input_events_(false), |
| 486 render_frame_(render_frame), | 471 render_frame_(render_frame), |
| 487 render_view_(render_view), | 472 render_view_(render_view), |
| 488 webframe_(webframe), | 473 webframe_(webframe), |
| 489 delegate_(NULL), | 474 delegate_(NULL), |
| 490 container_(NULL), | 475 container_(NULL), |
| 491 npp_(NULL), | |
| 492 plugin_url_(params.url), | 476 plugin_url_(params.url), |
| 493 load_manually_(params.loadManually), | 477 load_manually_(params.loadManually), |
| 494 first_geometry_update_(true), | 478 first_geometry_update_(true), |
| 495 ignore_response_error_(false), | 479 ignore_response_error_(false), |
| 496 file_path_(file_path), | 480 file_path_(file_path), |
| 497 mime_type_(base::ToLowerASCII(base::UTF16ToASCII( | 481 mime_type_(base::ToLowerASCII(base::UTF16ToASCII( |
| 498 base::StringPiece16(params.mimeType)))), | 482 base::StringPiece16(params.mimeType)))), |
| 499 loader_client_(this) { | 483 loader_client_(this) { |
| 500 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | 484 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); |
| 501 | 485 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 // to recover at this point. Break out. | 675 // to recover at this point. Break out. |
| 692 NOTREACHED(); | 676 NOTREACHED(); |
| 693 return ROUTED; | 677 return ROUTED; |
| 694 } | 678 } |
| 695 } | 679 } |
| 696 | 680 |
| 697 container_->loadFrameRequest(request, target_str); | 681 container_->loadFrameRequest(request, target_str); |
| 698 return ROUTED; | 682 return ROUTED; |
| 699 } | 683 } |
| 700 | 684 |
| 701 NPObject* WebPluginImpl::GetWindowScriptNPObject() { | |
| 702 if (!webframe_) { | |
| 703 NOTREACHED(); | |
| 704 return NULL; | |
| 705 } | |
| 706 return webframe_->windowObject(); | |
| 707 } | |
| 708 | |
| 709 NPObject* WebPluginImpl::GetPluginElement() { | |
| 710 return container_->scriptableObjectForElement(); | |
| 711 } | |
| 712 | |
| 713 bool WebPluginImpl::FindProxyForUrl(const GURL& url, std::string* proxy_list) { | 685 bool WebPluginImpl::FindProxyForUrl(const GURL& url, std::string* proxy_list) { |
| 714 // Proxy resolving doesn't work in single-process mode. | 686 // Proxy resolving doesn't work in single-process mode. |
| 715 return false; | 687 return false; |
| 716 } | 688 } |
| 717 | 689 |
| 718 void WebPluginImpl::SetCookie(const GURL& url, | 690 void WebPluginImpl::SetCookie(const GURL& url, |
| 719 const GURL& first_party_for_cookies, | 691 const GURL& first_party_for_cookies, |
| 720 const std::string& cookie) { | 692 const std::string& cookie) { |
| 721 if (!render_view_.get()) | 693 if (!render_view_.get()) |
| 722 return; | 694 return; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 RemoveClient(i); | 985 RemoveClient(i); |
| 1014 return; | 986 return; |
| 1015 } | 987 } |
| 1016 } | 988 } |
| 1017 } | 989 } |
| 1018 | 990 |
| 1019 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 991 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
| 1020 if (!container) | 992 if (!container) |
| 1021 TearDownPluginInstance(NULL); | 993 TearDownPluginInstance(NULL); |
| 1022 container_ = container; | 994 container_ = container; |
| 1023 if (container_) | |
| 1024 container_->allowScriptObjects(); | |
| 1025 } | 995 } |
| 1026 | 996 |
| 1027 unsigned long WebPluginImpl::GetNextResourceId() { | 997 unsigned long WebPluginImpl::GetNextResourceId() { |
| 1028 if (!webframe_) | 998 if (!webframe_) |
| 1029 return 0; | 999 return 0; |
| 1030 WebView* view = webframe_->view(); | 1000 WebView* view = webframe_->view(); |
| 1031 if (!view) | 1001 if (!view) |
| 1032 return 0; | 1002 return 0; |
| 1033 return view->createUniqueIdentifierForRequest(); | 1003 return view->createUniqueIdentifierForRequest(); |
| 1034 } | 1004 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 | 1091 |
| 1122 // Destroy the current plugin instance. | 1092 // Destroy the current plugin instance. |
| 1123 TearDownPluginInstance(loader); | 1093 TearDownPluginInstance(loader); |
| 1124 | 1094 |
| 1125 container_ = container_widget; | 1095 container_ = container_widget; |
| 1126 webframe_ = webframe; | 1096 webframe_ = webframe; |
| 1127 | 1097 |
| 1128 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( | 1098 WebPluginDelegateProxy* plugin_delegate = new WebPluginDelegateProxy( |
| 1129 this, mime_type_, render_view_, render_frame_); | 1099 this, mime_type_, render_view_, render_frame_); |
| 1130 | 1100 |
| 1131 // Store the plugin's unique identifier, used by the container to track its | |
| 1132 // script objects, and enable script objects (since Initialize may use them | |
| 1133 // even if it fails). | |
| 1134 npp_ = plugin_delegate->GetPluginNPP(); | |
| 1135 container_->allowScriptObjects(); | |
| 1136 | |
| 1137 bool ok = plugin_delegate && plugin_delegate->Initialize( | 1101 bool ok = plugin_delegate && plugin_delegate->Initialize( |
| 1138 plugin_url_, arg_names_, arg_values_, load_manually_); | 1102 plugin_url_, arg_names_, arg_values_, load_manually_); |
| 1139 | 1103 |
| 1140 if (!ok) { | 1104 if (!ok) { |
| 1141 container_->clearScriptObjects(); | |
| 1142 container_ = NULL; | 1105 container_ = NULL; |
| 1143 // TODO(iyengar) Should we delete the current plugin instance here? | 1106 // TODO(iyengar) Should we delete the current plugin instance here? |
| 1144 return false; | 1107 return false; |
| 1145 } | 1108 } |
| 1146 | 1109 |
| 1147 delegate_ = plugin_delegate; | 1110 delegate_ = plugin_delegate; |
| 1148 | 1111 |
| 1149 // Force a geometry update to occur to ensure that the plugin becomes | 1112 // Force a geometry update to occur to ensure that the plugin becomes |
| 1150 // visible. | 1113 // visible. |
| 1151 container_->reportGeometry(); | 1114 container_->reportGeometry(); |
| 1152 | 1115 |
| 1153 // The plugin move sequences accumulated via DidMove are sent to the browser | 1116 // The plugin move sequences accumulated via DidMove are sent to the browser |
| 1154 // whenever the renderer paints. Force a paint here to ensure that changes | 1117 // whenever the renderer paints. Force a paint here to ensure that changes |
| 1155 // to the plugin window are propagated to the browser. | 1118 // to the plugin window are propagated to the browser. |
| 1156 container_->invalidate(); | 1119 container_->invalidate(); |
| 1157 return true; | 1120 return true; |
| 1158 } | 1121 } |
| 1159 | 1122 |
| 1160 void WebPluginImpl::TearDownPluginInstance( | 1123 void WebPluginImpl::TearDownPluginInstance( |
| 1161 WebURLLoader* loader_to_ignore) { | 1124 WebURLLoader* loader_to_ignore) { |
| 1162 // JavaScript garbage collection may cause plugin script object references to | 1125 // JavaScript garbage collection may cause plugin script object references to |
| 1163 // be retained long after the plugin is destroyed. Some plugins won't cope | 1126 // be retained long after the plugin is destroyed. Some plugins won't cope |
| 1164 // with their objects being released after they've been destroyed, and once | 1127 // with their objects being released after they've been destroyed, and once |
| 1165 // we've actually unloaded the plugin the object's releaseobject() code may | 1128 // we've actually unloaded the plugin the object's releaseobject() code may |
| 1166 // no longer be in memory. The container tracks the plugin's objects and lets | 1129 // no longer be in memory. The container tracks the plugin's objects and lets |
| 1167 // us invalidate them, releasing the references to them held by the JavaScript | 1130 // us invalidate them, releasing the references to them held by the JavaScript |
| 1168 // runtime. | 1131 // runtime. |
| 1169 if (container_) { | 1132 if (container_) { |
| 1170 container_->clearScriptObjects(); | |
| 1171 container_->setWebLayer(NULL); | 1133 container_->setWebLayer(NULL); |
| 1172 } | 1134 } |
| 1173 | 1135 |
| 1174 // Call PluginDestroyed() first to prevent the plugin from calling us back | 1136 // Call PluginDestroyed() first to prevent the plugin from calling us back |
| 1175 // in the middle of tearing down the render tree. | 1137 // in the middle of tearing down the render tree. |
| 1176 if (delegate_) { | 1138 if (delegate_) { |
| 1177 // The plugin may call into the browser and pass script objects even during | 1139 // The plugin may call into the browser and pass script objects even during |
| 1178 // teardown, so temporarily re-enable plugin script objects. | 1140 // teardown, so temporarily re-enable plugin script objects. |
| 1179 DCHECK(container_); | 1141 DCHECK(container_); |
| 1180 container_->allowScriptObjects(); | |
| 1181 | 1142 |
| 1182 delegate_->PluginDestroyed(); | 1143 delegate_->PluginDestroyed(); |
| 1183 delegate_ = NULL; | 1144 delegate_ = NULL; |
| 1184 | |
| 1185 // Invalidate any script objects created during teardown here, before the | |
| 1186 // plugin might actually be unloaded. | |
| 1187 container_->clearScriptObjects(); | |
| 1188 } | 1145 } |
| 1189 | 1146 |
| 1190 // Cancel any pending requests because otherwise this deleted object will | 1147 // Cancel any pending requests because otherwise this deleted object will |
| 1191 // be called by the ResourceDispatcher. | 1148 // be called by the ResourceDispatcher. |
| 1192 std::vector<ClientInfo>::iterator client_index = clients_.begin(); | 1149 std::vector<ClientInfo>::iterator client_index = clients_.begin(); |
| 1193 while (client_index != clients_.end()) { | 1150 while (client_index != clients_.end()) { |
| 1194 ClientInfo& client_info = *client_index; | 1151 ClientInfo& client_info = *client_index; |
| 1195 | 1152 |
| 1196 if (loader_to_ignore == client_info.loader) { | 1153 if (loader_to_ignore == client_info.loader) { |
| 1197 client_index++; | 1154 client_index++; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1219 case PLUGIN_SRC: | 1176 case PLUGIN_SRC: |
| 1220 webframe_->setReferrerForRequest(*request, plugin_url_); | 1177 webframe_->setReferrerForRequest(*request, plugin_url_); |
| 1221 break; | 1178 break; |
| 1222 | 1179 |
| 1223 default: | 1180 default: |
| 1224 break; | 1181 break; |
| 1225 } | 1182 } |
| 1226 } | 1183 } |
| 1227 | 1184 |
| 1228 } // namespace content | 1185 } // namespace content |
| OLD | NEW |