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 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 paint_ack_received_(true), | 54 paint_ack_received_(true), |
54 last_device_scale_factor_(GetDeviceScaleFactor()), | 55 last_device_scale_factor_(GetDeviceScaleFactor()), |
55 sad_guest_(NULL), | 56 sad_guest_(NULL), |
56 guest_crashed_(false), | 57 guest_crashed_(false), |
57 content_window_routing_id_(MSG_ROUTING_NONE), | 58 content_window_routing_id_(MSG_ROUTING_NONE), |
58 plugin_focused_(false), | 59 plugin_focused_(false), |
59 visible_(true), | 60 visible_(true), |
60 auto_navigate_(auto_navigate), | |
61 mouse_locked_(false), | 61 mouse_locked_(false), |
62 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 62 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
63 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), | 63 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
| 64 delegate_(delegate), |
64 weak_ptr_factory_(this) { | 65 weak_ptr_factory_(this) { |
| 66 |
| 67 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); |
| 68 |
| 69 if (delegate) |
| 70 delegate->SetElementInstanceID(browser_plugin_instance_id_); |
65 } | 71 } |
66 | 72 |
67 BrowserPlugin::~BrowserPlugin() { | 73 BrowserPlugin::~BrowserPlugin() { |
68 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_); | 74 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_); |
69 | 75 |
70 if (!ready()) | 76 if (!ready()) |
71 return; | 77 return; |
72 | 78 |
73 browser_plugin_manager()->Send( | 79 browser_plugin_manager()->Send( |
74 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, | 80 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Tell |container| to allow this plugin to use script objects. | 395 // Tell |container| to allow this plugin to use script objects. |
390 npp_.reset(new NPP_t); | 396 npp_.reset(new NPP_t); |
391 container->allowScriptObjects(); | 397 container->allowScriptObjects(); |
392 | 398 |
393 bindings_.reset(new BrowserPluginBindings(this)); | 399 bindings_.reset(new BrowserPluginBindings(this)); |
394 container_ = container; | 400 container_ = container; |
395 container_->setWantsWheelEvents(true); | 401 container_->setWantsWheelEvents(true); |
396 | 402 |
397 // This is a way to notify observers of our attributes that this plugin is | 403 // This is a way to notify observers of our attributes that this plugin is |
398 // available in render tree. | 404 // available in render tree. |
399 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); | 405 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
| 406 // by firing an event from there. |
400 UpdateDOMAttribute("internalinstanceid", | 407 UpdateDOMAttribute("internalinstanceid", |
401 base::IntToString(browser_plugin_instance_id_)); | 408 base::IntToString(browser_plugin_instance_id_)); |
402 | 409 |
403 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); | 410 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); |
404 return true; | 411 return true; |
405 } | 412 } |
406 | 413 |
407 void BrowserPlugin::EnableCompositing(bool enable) { | 414 void BrowserPlugin::EnableCompositing(bool enable) { |
408 bool enabled = !!compositing_helper_.get(); | 415 bool enabled = !!compositing_helper_.get(); |
409 if (enabled == enable) | 416 if (enabled == enable) |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 mask, | 699 mask, |
693 position)); | 700 position)); |
694 return true; | 701 return true; |
695 } | 702 } |
696 | 703 |
697 void BrowserPlugin::didReceiveResponse( | 704 void BrowserPlugin::didReceiveResponse( |
698 const blink::WebURLResponse& response) { | 705 const blink::WebURLResponse& response) { |
699 } | 706 } |
700 | 707 |
701 void BrowserPlugin::didReceiveData(const char* data, int data_length) { | 708 void BrowserPlugin::didReceiveData(const char* data, int data_length) { |
702 if (auto_navigate_) { | 709 if (delegate_) |
703 std::string value(data, data_length); | 710 delegate_->DidReceiveData(data, data_length); |
704 html_string_ += value; | |
705 } | |
706 } | 711 } |
707 | 712 |
708 void BrowserPlugin::didFinishLoading() { | 713 void BrowserPlugin::didFinishLoading() { |
709 if (auto_navigate_) { | 714 if (delegate_) |
710 // TODO(lazyboy): Make |auto_navigate_| stuff work. | 715 delegate_->DidFinishLoading(); |
711 UpdateDOMAttribute(content::browser_plugin::kAttributeSrc, html_string_); | |
712 } | |
713 } | 716 } |
714 | 717 |
715 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { | 718 void BrowserPlugin::didFailLoading(const blink::WebURLError& error) { |
716 } | 719 } |
717 | 720 |
718 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, | 721 void BrowserPlugin::didFinishLoadingFrameRequest(const blink::WebURL& url, |
719 void* notify_data) { | 722 void* notify_data) { |
720 } | 723 } |
721 | 724 |
722 void BrowserPlugin::didFailLoadingFrameRequest( | 725 void BrowserPlugin::didFailLoadingFrameRequest( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 const blink::WebMouseEvent& event) { | 812 const blink::WebMouseEvent& event) { |
810 browser_plugin_manager()->Send( | 813 browser_plugin_manager()->Send( |
811 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 814 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
812 browser_plugin_instance_id_, | 815 browser_plugin_instance_id_, |
813 plugin_rect_, | 816 plugin_rect_, |
814 &event)); | 817 &event)); |
815 return true; | 818 return true; |
816 } | 819 } |
817 | 820 |
818 } // namespace content | 821 } // namespace content |
OLD | NEW |