OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "content/common/browser_plugin/browser_plugin_constants.h" | 11 #include "content/common/browser_plugin/browser_plugin_constants.h" |
12 #include "content/common/browser_plugin/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin/browser_plugin_messages.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
14 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "content/public/renderer/browser_plugin_delegate.h" |
16 #include "content/public/renderer/content_renderer_client.h" | 17 #include "content/public/renderer/content_renderer_client.h" |
17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
18 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 19 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
19 #include "content/renderer/child_frame_compositing_helper.h" | 20 #include "content/renderer/child_frame_compositing_helper.h" |
20 #include "content/renderer/cursor_utils.h" | 21 #include "content/renderer/cursor_utils.h" |
21 #include "content/renderer/drop_data_builder.h" | 22 #include "content/renderer/drop_data_builder.h" |
22 #include "content/renderer/render_thread_impl.h" | 23 #include "content/renderer/render_thread_impl.h" |
23 #include "content/renderer/sad_plugin.h" | 24 #include "content/renderer/sad_plugin.h" |
24 #include "third_party/WebKit/public/platform/WebRect.h" | 25 #include "third_party/WebKit/public/platform/WebRect.h" |
25 #include "third_party/WebKit/public/web/WebBindings.h" | 26 #include "third_party/WebKit/public/web/WebBindings.h" |
(...skipping 11 matching lines...) Expand all Loading... |
37 using blink::WebPluginParams; | 38 using blink::WebPluginParams; |
38 using blink::WebPoint; | 39 using blink::WebPoint; |
39 using blink::WebRect; | 40 using blink::WebRect; |
40 using blink::WebURL; | 41 using blink::WebURL; |
41 using blink::WebVector; | 42 using blink::WebVector; |
42 | 43 |
43 namespace content { | 44 namespace content { |
44 | 45 |
45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, | 46 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, |
46 blink::WebFrame* frame, | 47 blink::WebFrame* frame, |
47 bool auto_navigate) | 48 scoped_ptr<BrowserPluginDelegate> delegate) |
48 : attached_(false), | 49 : attached_(false), |
49 attach_pending_(false), | 50 attach_pending_(false), |
50 render_view_(render_view->AsWeakPtr()), | 51 render_view_(render_view->AsWeakPtr()), |
51 render_view_routing_id_(render_view->GetRoutingID()), | 52 render_view_routing_id_(render_view->GetRoutingID()), |
52 container_(NULL), | 53 container_(NULL), |
53 last_device_scale_factor_(GetDeviceScaleFactor()), | 54 last_device_scale_factor_(GetDeviceScaleFactor()), |
54 sad_guest_(NULL), | 55 sad_guest_(NULL), |
55 guest_crashed_(false), | 56 guest_crashed_(false), |
56 content_window_routing_id_(MSG_ROUTING_NONE), | 57 content_window_routing_id_(MSG_ROUTING_NONE), |
57 plugin_focused_(false), | 58 plugin_focused_(false), |
58 visible_(true), | 59 visible_(true), |
59 auto_navigate_(auto_navigate), | |
60 mouse_locked_(false), | 60 mouse_locked_(false), |
61 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 61 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
62 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), | 62 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
| 63 delegate_(delegate.Pass()), |
63 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
| 65 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); |
| 66 |
| 67 if (delegate_) |
| 68 delegate_->SetElementInstanceID(browser_plugin_instance_id_); |
64 } | 69 } |
65 | 70 |
66 BrowserPlugin::~BrowserPlugin() { | 71 BrowserPlugin::~BrowserPlugin() { |
67 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_); | 72 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_); |
68 | 73 |
69 if (!ready()) | 74 if (!ready()) |
70 return; | 75 return; |
71 | 76 |
72 browser_plugin_manager()->Send( | 77 browser_plugin_manager()->Send( |
73 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, | 78 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // Tell |container| to allow this plugin to use script objects. | 373 // Tell |container| to allow this plugin to use script objects. |
369 npp_.reset(new NPP_t); | 374 npp_.reset(new NPP_t); |
370 container->allowScriptObjects(); | 375 container->allowScriptObjects(); |
371 | 376 |
372 bindings_.reset(new BrowserPluginBindings(this)); | 377 bindings_.reset(new BrowserPluginBindings(this)); |
373 container_ = container; | 378 container_ = container; |
374 container_->setWantsWheelEvents(true); | 379 container_->setWantsWheelEvents(true); |
375 | 380 |
376 // This is a way to notify observers of our attributes that this plugin is | 381 // This is a way to notify observers of our attributes that this plugin is |
377 // available in render tree. | 382 // available in render tree. |
378 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); | 383 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
| 384 // by firing an event from there. |
379 UpdateDOMAttribute("internalinstanceid", | 385 UpdateDOMAttribute("internalinstanceid", |
380 base::IntToString(browser_plugin_instance_id_)); | 386 base::IntToString(browser_plugin_instance_id_)); |
381 | 387 |
382 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); | 388 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); |
383 return true; | 389 return true; |
384 } | 390 } |
385 | 391 |
386 void BrowserPlugin::EnableCompositing(bool enable) { | 392 void BrowserPlugin::EnableCompositing(bool enable) { |
387 bool enabled = !!compositing_helper_.get(); | 393 bool enabled = !!compositing_helper_.get(); |
388 if (enabled == enable) | 394 if (enabled == enable) |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 mask, | 655 mask, |
650 position)); | 656 position)); |
651 return true; | 657 return true; |
652 } | 658 } |
653 | 659 |
654 void BrowserPlugin::didReceiveResponse( | 660 void BrowserPlugin::didReceiveResponse( |
655 const blink::WebURLResponse& response) { | 661 const blink::WebURLResponse& response) { |
656 } | 662 } |
657 | 663 |
658 void BrowserPlugin::didReceiveData(const char* data, int data_length) { | 664 void BrowserPlugin::didReceiveData(const char* data, int data_length) { |
659 if (auto_navigate_) { | 665 if (delegate_) |
660 std::string value(data, data_length); | 666 delegate_->DidReceiveData(data, data_length); |
661 html_string_ += value; | |
662 } | |
663 } | 667 } |
664 | 668 |
665 void BrowserPlugin::didFinishLoading() { | 669 void BrowserPlugin::didFinishLoading() { |
666 if (auto_navigate_) { | 670 if (delegate_) |
667 // TODO(lazyboy): Make |auto_navigate_| stuff work. | 671 delegate_->DidFinishLoading(); |
668 UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_); | |
669 } | |
670 } | 672 } |
671 | 673 |
672 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { | 674 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { |
673 } | 675 } |
674 | 676 |
675 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, | 677 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, |
676 void* notify_data) { | 678 void* notify_data) { |
677 } | 679 } |
678 | 680 |
679 void BrowserPlugin::didFailLoadingFrameRequest( | 681 void BrowserPlugin::didFailLoadingFrameRequest( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 const blink::WebMouseEvent& event) { | 768 const blink::WebMouseEvent& event) { |
767 browser_plugin_manager()->Send( | 769 browser_plugin_manager()->Send( |
768 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 770 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
769 browser_plugin_instance_id_, | 771 browser_plugin_instance_id_, |
770 plugin_rect_, | 772 plugin_rect_, |
771 &event)); | 773 &event)); |
772 return true; | 774 return true; |
773 } | 775 } |
774 | 776 |
775 } // namespace content | 777 } // namespace content |
OLD | NEW |