| 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/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 using WebKit::WebVector; | 52 using WebKit::WebVector; |
| 53 | 53 |
| 54 namespace content { | 54 namespace content { |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 static std::string GetInternalEventName(const char* event_name) { | 58 static std::string GetInternalEventName(const char* event_name) { |
| 59 return base::StringPrintf("-internal-%s", event_name); | 59 return base::StringPrintf("-internal-%s", event_name); |
| 60 } | 60 } |
| 61 | 61 |
| 62 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { | |
| 63 switch (type) { | |
| 64 case BrowserPluginPermissionTypeDownload: | |
| 65 return browser_plugin::kPermissionTypeDownload; | |
| 66 case BrowserPluginPermissionTypeGeolocation: | |
| 67 return browser_plugin::kPermissionTypeGeolocation; | |
| 68 case BrowserPluginPermissionTypeMedia: | |
| 69 return browser_plugin::kPermissionTypeMedia; | |
| 70 case BrowserPluginPermissionTypeNewWindow: | |
| 71 return browser_plugin::kPermissionTypeNewWindow; | |
| 72 case BrowserPluginPermissionTypePointerLock: | |
| 73 return browser_plugin::kPermissionTypePointerLock; | |
| 74 case BrowserPluginPermissionTypeJavaScriptDialog: | |
| 75 return browser_plugin::kPermissionTypeDialog; | |
| 76 case BrowserPluginPermissionTypeUnknown: | |
| 77 default: | |
| 78 NOTREACHED(); | |
| 79 break; | |
| 80 } | |
| 81 return std::string(); | |
| 82 } | |
| 83 | |
| 84 typedef std::map<WebKit::WebPluginContainer*, | 62 typedef std::map<WebKit::WebPluginContainer*, |
| 85 BrowserPlugin*> PluginContainerMap; | 63 BrowserPlugin*> PluginContainerMap; |
| 86 static base::LazyInstance<PluginContainerMap> g_plugin_container_map = | 64 static base::LazyInstance<PluginContainerMap> g_plugin_container_map = |
| 87 LAZY_INSTANCE_INITIALIZER; | 65 LAZY_INSTANCE_INITIALIZER; |
| 88 | 66 |
| 89 } // namespace | 67 } // namespace |
| 90 | 68 |
| 91 BrowserPlugin::BrowserPlugin( | 69 BrowserPlugin::BrowserPlugin( |
| 92 RenderViewImpl* render_view, | 70 RenderViewImpl* render_view, |
| 93 WebKit::WebFrame* frame, | 71 WebKit::WebFrame* frame, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 bool handled = true; | 117 bool handled = true; |
| 140 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 118 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
| 141 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 119 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
| 142 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) | 120 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) |
| 143 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 121 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
| 144 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, | 122 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, |
| 145 OnCompositorFrameSwapped(message)) | 123 OnCompositorFrameSwapped(message)) |
| 146 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 124 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
| 147 OnGuestContentWindowReady) | 125 OnGuestContentWindowReady) |
| 148 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 126 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
| 149 IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestPermission, OnRequestPermission) | |
| 150 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 127 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
| 151 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) | 128 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) |
| 152 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 129 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
| 153 OnShouldAcceptTouchEvents) | 130 OnShouldAcceptTouchEvents) |
| 154 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) | 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
| 155 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | 132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
| 156 IPC_MESSAGE_UNHANDLED(handled = false) | 133 IPC_MESSAGE_UNHANDLED(handled = false) |
| 157 IPC_END_MESSAGE_MAP() | 134 IPC_END_MESSAGE_MAP() |
| 158 return handled; | 135 return handled; |
| 159 } | 136 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // Queue up showing the sad graphic to give content embedders an opportunity | 450 // Queue up showing the sad graphic to give content embedders an opportunity |
| 474 // to fire their listeners and potentially overlay the webview with custom | 451 // to fire their listeners and potentially overlay the webview with custom |
| 475 // behavior. If the BrowserPlugin is destroyed in the meantime, then the | 452 // behavior. If the BrowserPlugin is destroyed in the meantime, then the |
| 476 // task will not be executed. | 453 // task will not be executed. |
| 477 base::MessageLoop::current()->PostTask( | 454 base::MessageLoop::current()->PostTask( |
| 478 FROM_HERE, | 455 FROM_HERE, |
| 479 base::Bind(&BrowserPlugin::ShowSadGraphic, | 456 base::Bind(&BrowserPlugin::ShowSadGraphic, |
| 480 weak_ptr_factory_.GetWeakPtr())); | 457 weak_ptr_factory_.GetWeakPtr())); |
| 481 } | 458 } |
| 482 | 459 |
| 483 void BrowserPlugin::OnRequestPermission( | |
| 484 int guest_instance_id, | |
| 485 BrowserPluginPermissionType permission_type, | |
| 486 int request_id, | |
| 487 const base::DictionaryValue& request_info) { | |
| 488 // The New Window API is very similiar to the permission API in structure, | |
| 489 // but exposes a slightly different interface to the developer and so we put | |
| 490 // it in a separate event. | |
| 491 const char* event_name = NULL; | |
| 492 if (permission_type == BrowserPluginPermissionTypeNewWindow) { | |
| 493 event_name = browser_plugin::kEventNewWindow; | |
| 494 } else if (permission_type == BrowserPluginPermissionTypeJavaScriptDialog) { | |
| 495 event_name = browser_plugin::kEventDialog; | |
| 496 } else { | |
| 497 event_name = browser_plugin::kEventRequestPermission; | |
| 498 } | |
| 499 AddPermissionRequestToSet(request_id); | |
| 500 | |
| 501 std::map<std::string, base::Value*> props; | |
| 502 props[browser_plugin::kPermission] = | |
| 503 base::Value::CreateStringValue(PermissionTypeToString(permission_type)); | |
| 504 props[browser_plugin::kRequestId] = | |
| 505 base::Value::CreateIntegerValue(request_id); | |
| 506 | |
| 507 // Fill in the info provided by the browser. | |
| 508 for (DictionaryValue::Iterator iter(request_info); !iter.IsAtEnd(); | |
| 509 iter.Advance()) { | |
| 510 props[iter.key()] = iter.value().DeepCopy(); | |
| 511 } | |
| 512 TriggerEvent(event_name, &props); | |
| 513 } | |
| 514 | |
| 515 void BrowserPlugin::OnSetCursor(int guest_instance_id, | 460 void BrowserPlugin::OnSetCursor(int guest_instance_id, |
| 516 const WebCursor& cursor) { | 461 const WebCursor& cursor) { |
| 517 cursor_ = cursor; | 462 cursor_ = cursor; |
| 518 } | 463 } |
| 519 | 464 |
| 520 void BrowserPlugin::OnSetMouseLock(int guest_instance_id, | 465 void BrowserPlugin::OnSetMouseLock(int guest_instance_id, |
| 521 bool enable) { | 466 bool enable) { |
| 522 if (enable) { | 467 if (enable) { |
| 523 if (mouse_locked_) | 468 if (mouse_locked_) |
| 524 return; | 469 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 539 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 484 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
| 540 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 485 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
| 541 } | 486 } |
| 542 } | 487 } |
| 543 | 488 |
| 544 void BrowserPlugin::OnUpdatedName(int guest_instance_id, | 489 void BrowserPlugin::OnUpdatedName(int guest_instance_id, |
| 545 const std::string& name) { | 490 const std::string& name) { |
| 546 UpdateDOMAttribute(browser_plugin::kAttributeName, name); | 491 UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
| 547 } | 492 } |
| 548 | 493 |
| 549 void BrowserPlugin::AddPermissionRequestToSet(int request_id) { | |
| 550 DCHECK(!pending_permission_requests_.count(request_id)); | |
| 551 pending_permission_requests_.insert(request_id); | |
| 552 } | |
| 553 | |
| 554 void BrowserPlugin::OnUpdateRect( | 494 void BrowserPlugin::OnUpdateRect( |
| 555 int guest_instance_id, | 495 int guest_instance_id, |
| 556 const BrowserPluginMsg_UpdateRect_Params& params) { | 496 const BrowserPluginMsg_UpdateRect_Params& params) { |
| 557 // If the guest has updated pixels then it is no longer crashed. | 497 // If the guest has updated pixels then it is no longer crashed. |
| 558 guest_crashed_ = false; | 498 guest_crashed_ = false; |
| 559 | 499 |
| 560 bool use_new_damage_buffer = !backing_store_; | 500 bool use_new_damage_buffer = !backing_store_; |
| 561 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 501 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
| 562 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 502 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
| 563 // If we have a pending damage buffer, and the guest has begun to use the | 503 // If we have a pending damage buffer, and the guest has begun to use the |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 bool embedder_focused = false; | 898 bool embedder_focused = false; |
| 959 if (render_view_.get()) | 899 if (render_view_.get()) |
| 960 embedder_focused = render_view_->has_focus(); | 900 embedder_focused = render_view_->has_focus(); |
| 961 return plugin_focused_ && embedder_focused; | 901 return plugin_focused_ && embedder_focused; |
| 962 } | 902 } |
| 963 | 903 |
| 964 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 904 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
| 965 return container_; | 905 return container_; |
| 966 } | 906 } |
| 967 | 907 |
| 968 void BrowserPlugin::RespondPermission( | |
| 969 int request_id, bool allow, const std::string& user_input) { | |
| 970 browser_plugin_manager()->Send( | |
| 971 new BrowserPluginHostMsg_RespondPermission( | |
| 972 render_view_routing_id_, guest_instance_id_, | |
| 973 request_id, allow, user_input)); | |
| 974 } | |
| 975 | |
| 976 bool BrowserPlugin::RespondPermissionIfRequestIsPending( | |
| 977 int request_id, bool allow, const std::string& user_input) { | |
| 978 PendingPermissionRequests::iterator iter = | |
| 979 pending_permission_requests_.find(request_id); | |
| 980 if (iter == pending_permission_requests_.end()) | |
| 981 return false; | |
| 982 | |
| 983 pending_permission_requests_.erase(iter); | |
| 984 RespondPermission(request_id, allow, user_input); | |
| 985 return true; | |
| 986 } | |
| 987 | |
| 988 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 908 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 989 if (!container) | 909 if (!container) |
| 990 return false; | 910 return false; |
| 991 | 911 |
| 992 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container)) | 912 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container)) |
| 993 return false; | 913 return false; |
| 994 | 914 |
| 995 // Tell |container| to allow this plugin to use script objects. | 915 // Tell |container| to allow this plugin to use script objects. |
| 996 npp_.reset(new NPP_t); | 916 npp_.reset(new NPP_t); |
| 997 container->allowScriptObjects(); | 917 container->allowScriptObjects(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 // static | 1062 // static |
| 1143 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 1063 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
| 1144 const IPC::Message& message) { | 1064 const IPC::Message& message) { |
| 1145 switch (message.type()) { | 1065 switch (message.type()) { |
| 1146 case BrowserPluginMsg_AdvanceFocus::ID: | 1066 case BrowserPluginMsg_AdvanceFocus::ID: |
| 1147 case BrowserPluginMsg_Attach_ACK::ID: | 1067 case BrowserPluginMsg_Attach_ACK::ID: |
| 1148 case BrowserPluginMsg_BuffersSwapped::ID: | 1068 case BrowserPluginMsg_BuffersSwapped::ID: |
| 1149 case BrowserPluginMsg_CompositorFrameSwapped::ID: | 1069 case BrowserPluginMsg_CompositorFrameSwapped::ID: |
| 1150 case BrowserPluginMsg_GuestContentWindowReady::ID: | 1070 case BrowserPluginMsg_GuestContentWindowReady::ID: |
| 1151 case BrowserPluginMsg_GuestGone::ID: | 1071 case BrowserPluginMsg_GuestGone::ID: |
| 1152 case BrowserPluginMsg_RequestPermission::ID: | |
| 1153 case BrowserPluginMsg_SetCursor::ID: | 1072 case BrowserPluginMsg_SetCursor::ID: |
| 1154 case BrowserPluginMsg_SetMouseLock::ID: | 1073 case BrowserPluginMsg_SetMouseLock::ID: |
| 1155 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: | 1074 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: |
| 1156 case BrowserPluginMsg_UpdatedName::ID: | 1075 case BrowserPluginMsg_UpdatedName::ID: |
| 1157 case BrowserPluginMsg_UpdateRect::ID: | 1076 case BrowserPluginMsg_UpdateRect::ID: |
| 1158 return true; | 1077 return true; |
| 1159 default: | 1078 default: |
| 1160 break; | 1079 break; |
| 1161 } | 1080 } |
| 1162 return false; | 1081 return false; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 const WebKit::WebMouseEvent& event) { | 1364 const WebKit::WebMouseEvent& event) { |
| 1446 browser_plugin_manager()->Send( | 1365 browser_plugin_manager()->Send( |
| 1447 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1366 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1448 guest_instance_id_, | 1367 guest_instance_id_, |
| 1449 plugin_rect_, | 1368 plugin_rect_, |
| 1450 &event)); | 1369 &event)); |
| 1451 return true; | 1370 return true; |
| 1452 } | 1371 } |
| 1453 | 1372 |
| 1454 } // namespace content | 1373 } // namespace content |
| OLD | NEW |