Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 // Events. | 50 // Events. |
| 51 const char kEventExit[] = "exit"; | 51 const char kEventExit[] = "exit"; |
| 52 const char kEventLoadAbort[] = "loadabort"; | 52 const char kEventLoadAbort[] = "loadabort"; |
| 53 const char kEventLoadCommit[] = "loadcommit"; | 53 const char kEventLoadCommit[] = "loadcommit"; |
| 54 const char kEventLoadRedirect[] = "loadredirect"; | 54 const char kEventLoadRedirect[] = "loadredirect"; |
| 55 const char kEventLoadStart[] = "loadstart"; | 55 const char kEventLoadStart[] = "loadstart"; |
| 56 const char kEventLoadStop[] = "loadstop"; | 56 const char kEventLoadStop[] = "loadstop"; |
| 57 const char kEventRequestPermission[] = "permissionrequest"; | |
| 57 const char kEventResponsive[] = "responsive"; | 58 const char kEventResponsive[] = "responsive"; |
| 58 const char kEventSizeChanged[] = "sizechanged"; | 59 const char kEventSizeChanged[] = "sizechanged"; |
| 59 const char kEventUnresponsive[] = "unresponsive"; | 60 const char kEventUnresponsive[] = "unresponsive"; |
| 60 | 61 |
| 61 // Parameters/properties on events. | 62 // Parameters/properties on events. |
| 62 const char kIsTopLevel[] = "isTopLevel"; | 63 const char kIsTopLevel[] = "isTopLevel"; |
| 63 const char kNewURL[] = "newUrl"; | 64 const char kNewURL[] = "newUrl"; |
| 64 const char kNewHeight[] = "newHeight"; | 65 const char kNewHeight[] = "newHeight"; |
| 65 const char kNewWidth[] = "newWidth"; | 66 const char kNewWidth[] = "newWidth"; |
| 66 const char kOldURL[] = "oldUrl"; | 67 const char kOldURL[] = "oldUrl"; |
| 67 const char kOldHeight[] = "oldHeight"; | 68 const char kOldHeight[] = "oldHeight"; |
| 68 const char kOldWidth[] = "oldWidth"; | 69 const char kOldWidth[] = "oldWidth"; |
| 69 const char kPartition[] = "partition"; | 70 const char kPartition[] = "partition"; |
| 71 const char kPermission[] = "permission"; | |
| 72 const char kPermissionTypeMedia[] = "media"; | |
| 70 const char kPersistPrefix[] = "persist:"; | 73 const char kPersistPrefix[] = "persist:"; |
| 71 const char kProcessId[] = "processId"; | 74 const char kProcessId[] = "processId"; |
| 72 const char kReason[] = "reason"; | 75 const char kReason[] = "reason"; |
| 76 const char kRequestId[] = "request_id"; | |
| 73 const char kSrc[] = "src"; | 77 const char kSrc[] = "src"; |
| 74 const char kURL[] = "url"; | 78 const char kURL[] = "url"; |
| 75 | 79 |
| 76 // Error messages. | 80 // Error messages. |
| 77 const char kErrorAlreadyNavigated[] = | 81 const char kErrorAlreadyNavigated[] = |
| 78 "The object has already navigated, so its partition cannot be changed."; | 82 "The object has already navigated, so its partition cannot be changed."; |
| 79 const char kErrorInvalidPartition[] = | 83 const char kErrorInvalidPartition[] = |
| 80 "Invalid partition attribute."; | 84 "Invalid partition attribute."; |
| 81 | 85 |
| 82 static std::string TerminationStatusToString(base::TerminationStatus status) { | 86 static std::string TerminationStatusToString(base::TerminationStatus status) { |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 void BrowserPlugin::LoadAbort(const GURL& url, | 675 void BrowserPlugin::LoadAbort(const GURL& url, |
| 672 bool is_top_level, | 676 bool is_top_level, |
| 673 const std::string& type) { | 677 const std::string& type) { |
| 674 std::map<std::string, base::Value*> props; | 678 std::map<std::string, base::Value*> props; |
| 675 props[kURL] = base::Value::CreateStringValue(url.spec()); | 679 props[kURL] = base::Value::CreateStringValue(url.spec()); |
| 676 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | 680 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 677 props[kReason] = base::Value::CreateStringValue(type); | 681 props[kReason] = base::Value::CreateStringValue(type); |
| 678 TriggerEvent(kEventLoadAbort, &props); | 682 TriggerEvent(kEventLoadAbort, &props); |
| 679 } | 683 } |
| 680 | 684 |
| 685 void BrowserPlugin::RequestMediaAccess(int request_id, | |
| 686 const GURL& security_origin) { | |
| 687 size_t num_listeners = GetNumberOfEventListeners(kEventRequestPermission); | |
| 688 if (!num_listeners) { | |
| 689 // Automatically deny the request if there are no event listeners for | |
| 690 // permissionrequest. | |
| 691 RespondMediaAccess(request_id, false /* allow */); | |
| 692 return; | |
| 693 } | |
| 694 DCHECK(media_access_pending_counts_.find(request_id) == | |
| 695 media_access_pending_counts_.end()); | |
| 696 media_access_pending_counts_[request_id] = num_listeners; | |
| 697 | |
| 698 std::map<std::string, base::Value*> props; | |
| 699 props[kPermission] = base::Value::CreateStringValue(kPermissionTypeMedia); | |
| 700 props[kRequestId] = base::Value::CreateIntegerValue(request_id); | |
| 701 props[kURL] = base::Value::CreateStringValue(security_origin.spec()); | |
| 702 TriggerEvent(kEventRequestPermission, &props); | |
| 703 } | |
| 704 | |
| 705 size_t BrowserPlugin::GetNumberOfEventListeners(const std::string& event_name) { | |
| 706 if (!container()) | |
| 707 return 0; | |
| 708 | |
| 709 WebKit::WebNode parent = container()->element().parentNode(); | |
| 710 if (!parent.isNull() && parent.isShadowRoot()) { | |
| 711 WebKit::WebElement shadow_host = parent.shadowHost(); | |
| 712 if (!shadow_host.isNull()) { | |
| 713 return shadow_host.numberOfEventListeners( | |
| 714 WebKit::WebString::fromUTF8(event_name)); | |
| 715 } | |
| 716 } | |
| 717 return 0; | |
| 718 } | |
| 719 | |
| 681 void BrowserPlugin::LoadRedirect(const GURL& old_url, | 720 void BrowserPlugin::LoadRedirect(const GURL& old_url, |
| 682 const GURL& new_url, | 721 const GURL& new_url, |
| 683 bool is_top_level) { | 722 bool is_top_level) { |
| 684 std::map<std::string, base::Value*> props; | 723 std::map<std::string, base::Value*> props; |
| 685 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); | 724 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); |
| 686 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); | 725 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); |
| 687 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | 726 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 688 TriggerEvent(kEventLoadRedirect, &props); | 727 TriggerEvent(kEventLoadRedirect, &props); |
| 689 } | 728 } |
| 690 | 729 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 } | 763 } |
| 725 | 764 |
| 726 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 765 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
| 727 if (container()) { | 766 if (container()) { |
| 728 container()->requestTouchEventType(accept ? | 767 container()->requestTouchEventType(accept ? |
| 729 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 768 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
| 730 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 769 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
| 731 } | 770 } |
| 732 } | 771 } |
| 733 | 772 |
| 773 void BrowserPlugin::RespondMediaAccess(int request_id, bool allow) { | |
| 774 browser_plugin_manager()->Send( | |
| 775 new BrowserPluginHostMsg_AllowMediaAccess(render_view_->GetRoutingID(), | |
| 776 instance_id_, | |
| 777 request_id, | |
| 778 allow)); | |
| 779 } | |
| 780 | |
| 781 void BrowserPlugin::OnListenerCallMediaAccess(int request_id, bool allow) { | |
| 782 MediaAccessPendingCountsMap::iterator iter = | |
| 783 media_access_pending_counts_.find(request_id); | |
| 784 if (iter == media_access_pending_counts_.end()) | |
| 785 return; | |
| 786 DCHECK(iter->second > 0); | |
| 787 // If there were n listeners registered for media access permissionrequest, we | |
| 788 // require n allow() calls to allow the request. | |
| 789 // TODO(lazyboy): Figure out a way to track that each listener calls allow() | |
| 790 // at least once. Right now we only check for total number of allow() calls, | |
| 791 // which means a single listener calling allow() enough/multiple times can | |
| 792 // incorrectly allow the request. | |
|
Charlie Reis
2012/12/17 22:28:09
Yeah, that's no good. Ideally there would be some
| |
| 793 if (!allow || iter->second == 1) { | |
| 794 media_access_pending_counts_.erase(iter); | |
| 795 RespondMediaAccess(request_id, allow); | |
| 796 } else { | |
| 797 iter->second--; | |
| 798 } | |
| 799 } | |
| 800 | |
| 734 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 801 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
| 735 return container_; | 802 return container_; |
| 736 } | 803 } |
| 737 | 804 |
| 738 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 805 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 739 container_ = container; | 806 container_ = container; |
| 740 return true; | 807 return true; |
| 741 } | 808 } |
| 742 | 809 |
| 743 void BrowserPlugin::destroy() { | 810 void BrowserPlugin::destroy() { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 void* notify_data) { | 1082 void* notify_data) { |
| 1016 } | 1083 } |
| 1017 | 1084 |
| 1018 void BrowserPlugin::didFailLoadingFrameRequest( | 1085 void BrowserPlugin::didFailLoadingFrameRequest( |
| 1019 const WebKit::WebURL& url, | 1086 const WebKit::WebURL& url, |
| 1020 void* notify_data, | 1087 void* notify_data, |
| 1021 const WebKit::WebURLError& error) { | 1088 const WebKit::WebURLError& error) { |
| 1022 } | 1089 } |
| 1023 | 1090 |
| 1024 } // namespace content | 1091 } // namespace content |
| OLD | NEW |