| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view, | 64 WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view, |
| 65 WebViewPlugin::Delegate* delegate, | 65 WebViewPlugin::Delegate* delegate, |
| 66 const WebPreferences& preferences, | 66 const WebPreferences& preferences, |
| 67 const std::string& html_data, | 67 const std::string& html_data, |
| 68 const GURL& url) { | 68 const GURL& url) { |
| 69 DCHECK(url.is_valid()) << "Blink requires the WebView to have a valid URL."; | 69 DCHECK(url.is_valid()) << "Blink requires the WebView to have a valid URL."; |
| 70 WebViewPlugin* plugin = new WebViewPlugin(render_view, delegate, preferences); | 70 WebViewPlugin* plugin = new WebViewPlugin(render_view, delegate, preferences); |
| 71 plugin->web_view()->MainFrame()->LoadHTMLString(html_data, url); | 71 plugin->main_frame()->LoadHTMLString(html_data, url); |
| 72 return plugin; | 72 return plugin; |
| 73 } | 73 } |
| 74 | 74 |
| 75 WebViewPlugin::~WebViewPlugin() { | 75 WebViewPlugin::~WebViewPlugin() { |
| 76 DCHECK(!weak_factory_.HasWeakPtrs()); | 76 DCHECK(!weak_factory_.HasWeakPtrs()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) { | 79 void WebViewPlugin::ReplayReceivedData(WebPlugin* plugin) { |
| 80 if (!response_.IsNull()) { | 80 if (!response_.IsNull()) { |
| 81 plugin->DidReceiveResponse(response_); | 81 plugin->DidReceiveResponse(response_); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 web_view_->SetMainFrame(web_frame); | 264 web_view_->SetMainFrame(web_frame); |
| 265 // TODO(dcheng): The main frame widget currently has a special case. | 265 // TODO(dcheng): The main frame widget currently has a special case. |
| 266 // Eliminate this once WebView is no longer a WebWidget. | 266 // Eliminate this once WebView is no longer a WebWidget. |
| 267 WebFrameWidget::Create(this, web_view_, web_frame); | 267 WebFrameWidget::Create(this, web_view_, web_frame); |
| 268 } | 268 } |
| 269 | 269 |
| 270 WebViewPlugin::WebViewHelper::~WebViewHelper() { | 270 WebViewPlugin::WebViewHelper::~WebViewHelper() { |
| 271 web_view_->Close(); | 271 web_view_->Close(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 blink::WebLocalFrame* WebViewPlugin::WebViewHelper::main_frame() { |
| 275 // WebViewHelper doesn't support OOPIFs so the main frame will |
| 276 // always be local. |
| 277 DCHECK(web_view_->MainFrame()->IsWebLocalFrame()); |
| 278 return static_cast<WebLocalFrame*>(web_view_->MainFrame()); |
| 279 } |
| 280 |
| 274 bool WebViewPlugin::WebViewHelper::AcceptsLoadDrops() { | 281 bool WebViewPlugin::WebViewHelper::AcceptsLoadDrops() { |
| 275 return false; | 282 return false; |
| 276 } | 283 } |
| 277 | 284 |
| 278 bool WebViewPlugin::WebViewHelper::CanHandleGestureEvent() { | 285 bool WebViewPlugin::WebViewHelper::CanHandleGestureEvent() { |
| 279 return true; | 286 return true; |
| 280 } | 287 } |
| 281 | 288 |
| 282 bool WebViewPlugin::WebViewHelper::CanUpdateLayout() { | 289 bool WebViewPlugin::WebViewHelper::CanUpdateLayout() { |
| 283 return true; | 290 return true; |
| 284 } | 291 } |
| 285 | 292 |
| 286 void WebViewPlugin::WebViewHelper::SetToolTipText( | 293 void WebViewPlugin::WebViewHelper::SetToolTipText( |
| 287 const WebString& text, | 294 const WebString& text, |
| 288 blink::WebTextDirection hint) { | 295 blink::WebTextDirection hint) { |
| 289 if (plugin_->container_) | 296 if (plugin_->container_) |
| 290 plugin_->container_->GetElement().SetAttribute("title", text); | 297 plugin_->container_->GetElement().SetAttribute("title", text); |
| 291 } | 298 } |
| 292 | 299 |
| 293 void WebViewPlugin::WebViewHelper::StartDragging(blink::WebReferrerPolicy, | 300 void WebViewPlugin::WebViewHelper::StartDragging(blink::WebReferrerPolicy, |
| 294 const WebDragData&, | 301 const WebDragData&, |
| 295 WebDragOperationsMask, | 302 WebDragOperationsMask, |
| 296 const WebImage&, | 303 const WebImage&, |
| 297 const WebPoint&) { | 304 const WebPoint&) { |
| 298 // Immediately stop dragging. | 305 // Immediately stop dragging. |
| 299 DCHECK(web_view_->MainFrame()->IsWebLocalFrame()); | 306 main_frame()->FrameWidget()->DragSourceSystemDragEnded(); |
| 300 web_view_->MainFrame() | |
| 301 ->ToWebLocalFrame() | |
| 302 ->FrameWidget() | |
| 303 ->DragSourceSystemDragEnded(); | |
| 304 } | 307 } |
| 305 | 308 |
| 306 bool WebViewPlugin::WebViewHelper::AllowsBrokenNullLayerTreeView() const { | 309 bool WebViewPlugin::WebViewHelper::AllowsBrokenNullLayerTreeView() const { |
| 307 return true; | 310 return true; |
| 308 } | 311 } |
| 309 | 312 |
| 310 void WebViewPlugin::WebViewHelper::DidInvalidateRect(const WebRect& rect) { | 313 void WebViewPlugin::WebViewHelper::DidInvalidateRect(const WebRect& rect) { |
| 311 if (plugin_->container_) | 314 if (plugin_->container_) |
| 312 plugin_->container_->InvalidateRect(rect); | 315 plugin_->container_->InvalidateRect(rect); |
| 313 } | 316 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 338 // TODO(yhirano): Stop using Platform::CreateURLLoader() here. | 341 // TODO(yhirano): Stop using Platform::CreateURLLoader() here. |
| 339 return blink::Platform::Current()->CreateURLLoader(); | 342 return blink::Platform::Current()->CreateURLLoader(); |
| 340 } | 343 } |
| 341 | 344 |
| 342 void WebViewPlugin::WebViewHelper::DidClearWindowObject() { | 345 void WebViewPlugin::WebViewHelper::DidClearWindowObject() { |
| 343 if (!plugin_->delegate_) | 346 if (!plugin_->delegate_) |
| 344 return; | 347 return; |
| 345 | 348 |
| 346 v8::Isolate* isolate = blink::MainThreadIsolate(); | 349 v8::Isolate* isolate = blink::MainThreadIsolate(); |
| 347 v8::HandleScope handle_scope(isolate); | 350 v8::HandleScope handle_scope(isolate); |
| 348 v8::Local<v8::Context> context = | 351 v8::Local<v8::Context> context = main_frame()->MainWorldScriptContext(); |
| 349 web_view_->MainFrame()->MainWorldScriptContext(); | |
| 350 DCHECK(!context.IsEmpty()); | 352 DCHECK(!context.IsEmpty()); |
| 351 | 353 |
| 352 v8::Context::Scope context_scope(context); | 354 v8::Context::Scope context_scope(context); |
| 353 v8::Local<v8::Object> global = context->Global(); | 355 v8::Local<v8::Object> global = context->Global(); |
| 354 | 356 |
| 355 global->Set(gin::StringToV8(isolate, "plugin"), | 357 global->Set(gin::StringToV8(isolate, "plugin"), |
| 356 plugin_->delegate_->GetV8Handle(isolate)); | 358 plugin_->delegate_->GetV8Handle(isolate)); |
| 357 } | 359 } |
| 358 | 360 |
| 359 void WebViewPlugin::WebViewHelper::FrameDetached(blink::WebLocalFrame* frame, | 361 void WebViewPlugin::WebViewHelper::FrameDetached(blink::WebLocalFrame* frame, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 378 if (!delegate_) | 380 if (!delegate_) |
| 379 return; | 381 return; |
| 380 | 382 |
| 381 // The delegate may instantiate a new plugin. | 383 // The delegate may instantiate a new plugin. |
| 382 delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect)); | 384 delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect)); |
| 383 // The delegate may have dirtied style and layout of the WebView. | 385 // The delegate may have dirtied style and layout of the WebView. |
| 384 // See for example the resizePoster function in plugin_poster.html. | 386 // See for example the resizePoster function in plugin_poster.html. |
| 385 // Run the lifecycle now so that it is clean. | 387 // Run the lifecycle now so that it is clean. |
| 386 web_view()->UpdateAllLifecyclePhases(); | 388 web_view()->UpdateAllLifecyclePhases(); |
| 387 } | 389 } |
| OLD | NEW |