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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 bool handled = true; | 119 bool handled = true; |
142 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 120 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
143 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 121 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
144 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) | 122 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) |
145 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 123 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
146 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, | 124 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, |
147 OnCompositorFrameSwapped(message)) | 125 OnCompositorFrameSwapped(message)) |
148 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 126 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
149 OnGuestContentWindowReady) | 127 OnGuestContentWindowReady) |
150 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 128 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
151 IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestPermission, OnRequestPermission) | |
152 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 129 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
153 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) | 130 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) |
154 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
155 OnShouldAcceptTouchEvents) | 132 OnShouldAcceptTouchEvents) |
156 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) | 133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
157 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | 134 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
158 IPC_MESSAGE_UNHANDLED(handled = false) | 135 IPC_MESSAGE_UNHANDLED(handled = false) |
159 IPC_END_MESSAGE_MAP() | 136 IPC_END_MESSAGE_MAP() |
160 return handled; | 137 return handled; |
161 } | 138 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 // Queue up showing the sad graphic to give content embedders an opportunity | 453 // Queue up showing the sad graphic to give content embedders an opportunity |
477 // to fire their listeners and potentially overlay the webview with custom | 454 // to fire their listeners and potentially overlay the webview with custom |
478 // behavior. If the BrowserPlugin is destroyed in the meantime, then the | 455 // behavior. If the BrowserPlugin is destroyed in the meantime, then the |
479 // task will not be executed. | 456 // task will not be executed. |
480 base::MessageLoop::current()->PostTask( | 457 base::MessageLoop::current()->PostTask( |
481 FROM_HERE, | 458 FROM_HERE, |
482 base::Bind(&BrowserPlugin::ShowSadGraphic, | 459 base::Bind(&BrowserPlugin::ShowSadGraphic, |
483 weak_ptr_factory_.GetWeakPtr())); | 460 weak_ptr_factory_.GetWeakPtr())); |
484 } | 461 } |
485 | 462 |
486 void BrowserPlugin::OnRequestPermission( | |
487 int guest_instance_id, | |
488 BrowserPluginPermissionType permission_type, | |
489 int request_id, | |
490 const base::DictionaryValue& request_info) { | |
491 // The New Window API is very similiar to the permission API in structure, | |
492 // but exposes a slightly different interface to the developer and so we put | |
493 // it in a separate event. | |
494 const char* event_name = NULL; | |
495 if (permission_type == BrowserPluginPermissionTypeNewWindow) { | |
496 event_name = browser_plugin::kEventNewWindow; | |
497 } else if (permission_type == BrowserPluginPermissionTypeJavaScriptDialog) { | |
498 event_name = browser_plugin::kEventDialog; | |
499 } else { | |
500 event_name = browser_plugin::kEventRequestPermission; | |
501 } | |
502 AddPermissionRequestToSet(request_id); | |
503 | |
504 std::map<std::string, base::Value*> props; | |
505 props[browser_plugin::kPermission] = | |
506 base::Value::CreateStringValue(PermissionTypeToString(permission_type)); | |
507 props[browser_plugin::kRequestId] = | |
508 base::Value::CreateIntegerValue(request_id); | |
509 | |
510 // Fill in the info provided by the browser. | |
511 for (DictionaryValue::Iterator iter(request_info); !iter.IsAtEnd(); | |
512 iter.Advance()) { | |
513 props[iter.key()] = iter.value().DeepCopy(); | |
514 } | |
515 TriggerEvent(event_name, &props); | |
516 } | |
517 | |
518 void BrowserPlugin::OnSetCursor(int guest_instance_id, | 463 void BrowserPlugin::OnSetCursor(int guest_instance_id, |
519 const WebCursor& cursor) { | 464 const WebCursor& cursor) { |
520 cursor_ = cursor; | 465 cursor_ = cursor; |
521 } | 466 } |
522 | 467 |
523 void BrowserPlugin::OnSetMouseLock(int guest_instance_id, | 468 void BrowserPlugin::OnSetMouseLock(int guest_instance_id, |
524 bool enable) { | 469 bool enable) { |
525 if (enable) { | 470 if (enable) { |
526 if (mouse_locked_) | 471 if (mouse_locked_) |
527 return; | 472 return; |
(...skipping 14 matching lines...) Expand all Loading... |
542 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 487 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
543 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 488 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
544 } | 489 } |
545 } | 490 } |
546 | 491 |
547 void BrowserPlugin::OnUpdatedName(int guest_instance_id, | 492 void BrowserPlugin::OnUpdatedName(int guest_instance_id, |
548 const std::string& name) { | 493 const std::string& name) { |
549 UpdateDOMAttribute(browser_plugin::kAttributeName, name); | 494 UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
550 } | 495 } |
551 | 496 |
552 void BrowserPlugin::AddPermissionRequestToSet(int request_id) { | |
553 DCHECK(!pending_permission_requests_.count(request_id)); | |
554 pending_permission_requests_.insert(request_id); | |
555 } | |
556 | |
557 void BrowserPlugin::OnUpdateRect( | 497 void BrowserPlugin::OnUpdateRect( |
558 int guest_instance_id, | 498 int guest_instance_id, |
559 const BrowserPluginMsg_UpdateRect_Params& params) { | 499 const BrowserPluginMsg_UpdateRect_Params& params) { |
560 // If the guest has updated pixels then it is no longer crashed. | 500 // If the guest has updated pixels then it is no longer crashed. |
561 guest_crashed_ = false; | 501 guest_crashed_ = false; |
562 | 502 |
563 bool use_new_damage_buffer = !backing_store_; | 503 bool use_new_damage_buffer = !backing_store_; |
564 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 504 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
565 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 505 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
566 // If we have a pending damage buffer, and the guest has begun to use the | 506 // 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... |
961 bool embedder_focused = false; | 901 bool embedder_focused = false; |
962 if (render_view_.get()) | 902 if (render_view_.get()) |
963 embedder_focused = render_view_->has_focus(); | 903 embedder_focused = render_view_->has_focus(); |
964 return plugin_focused_ && embedder_focused; | 904 return plugin_focused_ && embedder_focused; |
965 } | 905 } |
966 | 906 |
967 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 907 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
968 return container_; | 908 return container_; |
969 } | 909 } |
970 | 910 |
971 void BrowserPlugin::RespondPermission( | |
972 int request_id, bool allow, const std::string& user_input) { | |
973 browser_plugin_manager()->Send( | |
974 new BrowserPluginHostMsg_RespondPermission( | |
975 render_view_routing_id_, guest_instance_id_, | |
976 request_id, allow, user_input)); | |
977 } | |
978 | |
979 bool BrowserPlugin::RespondPermissionIfRequestIsPending( | |
980 int request_id, bool allow, const std::string& user_input) { | |
981 PendingPermissionRequests::iterator iter = | |
982 pending_permission_requests_.find(request_id); | |
983 if (iter == pending_permission_requests_.end()) | |
984 return false; | |
985 | |
986 pending_permission_requests_.erase(iter); | |
987 RespondPermission(request_id, allow, user_input); | |
988 return true; | |
989 } | |
990 | |
991 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 911 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
992 if (!container) | 912 if (!container) |
993 return false; | 913 return false; |
994 | 914 |
995 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container)) | 915 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container)) |
996 return false; | 916 return false; |
997 | 917 |
998 // Tell |container| to allow this plugin to use script objects. | 918 // Tell |container| to allow this plugin to use script objects. |
999 npp_.reset(new NPP_t); | 919 npp_.reset(new NPP_t); |
1000 container->allowScriptObjects(); | 920 container->allowScriptObjects(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 // static | 1065 // static |
1146 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 1066 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
1147 const IPC::Message& message) { | 1067 const IPC::Message& message) { |
1148 switch (message.type()) { | 1068 switch (message.type()) { |
1149 case BrowserPluginMsg_AdvanceFocus::ID: | 1069 case BrowserPluginMsg_AdvanceFocus::ID: |
1150 case BrowserPluginMsg_Attach_ACK::ID: | 1070 case BrowserPluginMsg_Attach_ACK::ID: |
1151 case BrowserPluginMsg_BuffersSwapped::ID: | 1071 case BrowserPluginMsg_BuffersSwapped::ID: |
1152 case BrowserPluginMsg_CompositorFrameSwapped::ID: | 1072 case BrowserPluginMsg_CompositorFrameSwapped::ID: |
1153 case BrowserPluginMsg_GuestContentWindowReady::ID: | 1073 case BrowserPluginMsg_GuestContentWindowReady::ID: |
1154 case BrowserPluginMsg_GuestGone::ID: | 1074 case BrowserPluginMsg_GuestGone::ID: |
1155 case BrowserPluginMsg_RequestPermission::ID: | |
1156 case BrowserPluginMsg_SetCursor::ID: | 1075 case BrowserPluginMsg_SetCursor::ID: |
1157 case BrowserPluginMsg_SetMouseLock::ID: | 1076 case BrowserPluginMsg_SetMouseLock::ID: |
1158 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: | 1077 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: |
1159 case BrowserPluginMsg_UpdatedName::ID: | 1078 case BrowserPluginMsg_UpdatedName::ID: |
1160 case BrowserPluginMsg_UpdateRect::ID: | 1079 case BrowserPluginMsg_UpdateRect::ID: |
1161 return true; | 1080 return true; |
1162 default: | 1081 default: |
1163 break; | 1082 break; |
1164 } | 1083 } |
1165 return false; | 1084 return false; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 const WebKit::WebMouseEvent& event) { | 1367 const WebKit::WebMouseEvent& event) { |
1449 browser_plugin_manager()->Send( | 1368 browser_plugin_manager()->Send( |
1450 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1369 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
1451 guest_instance_id_, | 1370 guest_instance_id_, |
1452 plugin_rect_, | 1371 plugin_rect_, |
1453 &event)); | 1372 &event)); |
1454 return true; | 1373 return true; |
1455 } | 1374 } |
1456 | 1375 |
1457 } // namespace content | 1376 } // namespace content |
OLD | NEW |