OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/plugins/renderer/webview_plugin.h" | 5 #include "components/plugins/renderer/webview_plugin.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 WebViewPlugin::~WebViewPlugin() { | 90 WebViewPlugin::~WebViewPlugin() { |
91 DCHECK(!weak_factory_.HasWeakPtrs()); | 91 DCHECK(!weak_factory_.HasWeakPtrs()); |
92 web_frame_widget_->close(); | 92 web_frame_widget_->close(); |
93 web_view_->close(); | 93 web_view_->close(); |
94 web_frame_->close(); | 94 web_frame_->close(); |
95 } | 95 } |
96 | 96 |
97 void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) { | 97 void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) { |
98 if (!response_.isNull()) { | 98 const WebURLResponse& response = web_frame_->dataSource()->response(); |
99 plugin->didReceiveResponse(response_); | 99 if (!response.isNull()) { |
| 100 plugin->didReceiveResponse(response); |
100 size_t total_bytes = 0; | 101 size_t total_bytes = 0; |
101 for (std::list<std::string>::iterator it = data_.begin(); it != data_.end(); | 102 for (std::list<std::string>::iterator it = data_.begin(); it != data_.end(); |
102 ++it) { | 103 ++it) { |
103 plugin->didReceiveData( | 104 plugin->didReceiveData( |
104 it->c_str(), base::checked_cast<int, size_t>(it->length())); | 105 it->c_str(), base::checked_cast<int, size_t>(it->length())); |
105 total_bytes += it->length(); | 106 total_bytes += it->length(); |
106 } | 107 } |
107 UMA_HISTOGRAM_MEMORY_KB( | 108 UMA_HISTOGRAM_MEMORY_KB( |
108 "PluginDocument.Memory", | 109 "PluginDocument.Memory", |
109 (base::checked_cast<int, size_t>(total_bytes / 1024))); | 110 (base::checked_cast<int, size_t>(total_bytes / 1024))); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 250 } |
250 return blink::WebInputEventResult::HandledSuppressed; | 251 return blink::WebInputEventResult::HandledSuppressed; |
251 } | 252 } |
252 current_cursor_ = cursor; | 253 current_cursor_ = cursor; |
253 blink::WebInputEventResult handled = web_view_->handleInputEvent(event); | 254 blink::WebInputEventResult handled = web_view_->handleInputEvent(event); |
254 cursor = current_cursor_; | 255 cursor = current_cursor_; |
255 | 256 |
256 return handled; | 257 return handled; |
257 } | 258 } |
258 | 259 |
259 void WebViewPlugin::didReceiveResponse(const WebURLResponse& response) { | |
260 DCHECK(response_.isNull()); | |
261 response_ = response; | |
262 } | |
263 | |
264 void WebViewPlugin::didReceiveData(const char* data, int data_length) { | 260 void WebViewPlugin::didReceiveData(const char* data, int data_length) { |
265 data_.push_back(std::string(data, data_length)); | 261 data_.push_back(std::string(data, data_length)); |
266 } | 262 } |
267 | 263 |
268 void WebViewPlugin::didFinishLoading() { | 264 void WebViewPlugin::didFinishLoading() { |
269 DCHECK(!finished_loading_); | 265 DCHECK(!finished_loading_); |
270 finished_loading_ = true; | 266 finished_loading_ = true; |
271 } | 267 } |
272 | 268 |
273 void WebViewPlugin::didFailLoading(const WebURLError& error) { | 269 void WebViewPlugin::didFailLoading(const WebURLError& error) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 326 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
331 DCHECK(!context.IsEmpty()); | 327 DCHECK(!context.IsEmpty()); |
332 | 328 |
333 v8::Context::Scope context_scope(context); | 329 v8::Context::Scope context_scope(context); |
334 v8::Local<v8::Object> global = context->Global(); | 330 v8::Local<v8::Object> global = context->Global(); |
335 | 331 |
336 global->Set(gin::StringToV8(isolate, "plugin"), | 332 global->Set(gin::StringToV8(isolate, "plugin"), |
337 delegate_->GetV8Handle(isolate)); | 333 delegate_->GetV8Handle(isolate)); |
338 } | 334 } |
339 | 335 |
340 void WebViewPlugin::didReceiveResponse(unsigned identifier, | |
341 const WebURLResponse& response) { | |
342 WebFrameClient::didReceiveResponse(identifier, response); | |
343 } | |
344 | |
345 void WebViewPlugin::OnDestruct() {} | 336 void WebViewPlugin::OnDestruct() {} |
346 | 337 |
347 void WebViewPlugin::OnZoomLevelChanged() { | 338 void WebViewPlugin::OnZoomLevelChanged() { |
348 if (container_) { | 339 if (container_) { |
349 web_view_->setZoomLevel( | 340 web_view_->setZoomLevel( |
350 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); | 341 blink::WebView::zoomFactorToZoomLevel(container_->pageZoomFactor())); |
351 } | 342 } |
352 } | 343 } |
353 | 344 |
354 void WebViewPlugin::UpdatePluginForNewGeometry( | 345 void WebViewPlugin::UpdatePluginForNewGeometry( |
355 const blink::WebRect& window_rect, | 346 const blink::WebRect& window_rect, |
356 const blink::WebRect& unobscured_rect) { | 347 const blink::WebRect& unobscured_rect) { |
357 DCHECK(container_); | 348 DCHECK(container_); |
358 if (!delegate_) | 349 if (!delegate_) |
359 return; | 350 return; |
360 | 351 |
361 // The delegate may instantiate a new plugin. | 352 // The delegate may instantiate a new plugin. |
362 delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect)); | 353 delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect)); |
363 // The delegate may have dirtied style and layout of the WebView. | 354 // The delegate may have dirtied style and layout of the WebView. |
364 // See for example the resizePoster function in plugin_poster.html. | 355 // See for example the resizePoster function in plugin_poster.html. |
365 // Run the lifecycle now so that it is clean. | 356 // Run the lifecycle now so that it is clean. |
366 web_view_->updateAllLifecyclePhases(); | 357 web_view_->updateAllLifecyclePhases(); |
367 } | 358 } |
OLD | NEW |