| 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/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 class BrowserPluginGuest::JavaScriptDialogRequest : public PermissionRequest { | 214 class BrowserPluginGuest::JavaScriptDialogRequest : public PermissionRequest { |
| 215 public: | 215 public: |
| 216 JavaScriptDialogRequest(const DialogClosedCallback& callback) | 216 JavaScriptDialogRequest(const DialogClosedCallback& callback) |
| 217 : callback_(callback) { | 217 : callback_(callback) { |
| 218 RecordAction( | 218 RecordAction( |
| 219 UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.JSDialog")); | 219 UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.JSDialog")); |
| 220 } | 220 } |
| 221 | 221 |
| 222 virtual void Respond(bool should_allow, | 222 virtual void Respond(bool should_allow, |
| 223 const std::string& user_input) OVERRIDE { | 223 const std::string& user_input) OVERRIDE { |
| 224 callback_.Run(should_allow, UTF8ToUTF16(user_input)); | 224 callback_.Run(should_allow, base::UTF8ToUTF16(user_input)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 private: | 227 private: |
| 228 virtual ~JavaScriptDialogRequest() {} | 228 virtual ~JavaScriptDialogRequest() {} |
| 229 DialogClosedCallback callback_; | 229 DialogClosedCallback callback_; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 class BrowserPluginGuest::PointerLockRequest : public PermissionRequest { | 232 class BrowserPluginGuest::PointerLockRequest : public PermissionRequest { |
| 233 public: | 233 public: |
| 234 PointerLockRequest(BrowserPluginGuest* guest) | 234 PointerLockRequest(BrowserPluginGuest* guest) |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 | 822 |
| 823 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 823 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
| 824 int64 source_frame_id, | 824 int64 source_frame_id, |
| 825 const base::string16& frame_name, | 825 const base::string16& frame_name, |
| 826 const GURL& target_url, | 826 const GURL& target_url, |
| 827 WebContents* new_contents) { | 827 WebContents* new_contents) { |
| 828 WebContentsImpl* new_contents_impl = | 828 WebContentsImpl* new_contents_impl = |
| 829 static_cast<WebContentsImpl*>(new_contents); | 829 static_cast<WebContentsImpl*>(new_contents); |
| 830 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); | 830 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); |
| 831 guest->opener_ = AsWeakPtr(); | 831 guest->opener_ = AsWeakPtr(); |
| 832 std::string guest_name = UTF16ToUTF8(frame_name); | 832 std::string guest_name = base::UTF16ToUTF8(frame_name); |
| 833 guest->name_ = guest_name; | 833 guest->name_ = guest_name; |
| 834 // Take ownership of the new guest until it is attached to the embedder's DOM | 834 // Take ownership of the new guest until it is attached to the embedder's DOM |
| 835 // tree to avoid leaking a guest if this guest is destroyed before attaching | 835 // tree to avoid leaking a guest if this guest is destroyed before attaching |
| 836 // the new guest. | 836 // the new guest. |
| 837 pending_new_windows_.insert( | 837 pending_new_windows_.insert( |
| 838 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); | 838 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); |
| 839 } | 839 } |
| 840 | 840 |
| 841 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { | 841 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { |
| 842 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Hung")); | 842 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Hung")); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 1071 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 1072 bool enable_dragdrop = delegate_ && delegate_->IsDragAndDropEnabled(); | 1072 bool enable_dragdrop = delegate_ && delegate_->IsDragAndDropEnabled(); |
| 1073 if (!enable_dragdrop) { | 1073 if (!enable_dragdrop) { |
| 1074 // Initiating a drag from inside a guest is currently not supported without | 1074 // Initiating a drag from inside a guest is currently not supported without |
| 1075 // the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some | 1075 // the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some |
| 1076 // JS to disable it. http://crbug.com/161112 | 1076 // JS to disable it. http://crbug.com/161112 |
| 1077 const char script[] = "window.addEventListener('dragstart', function() { " | 1077 const char script[] = "window.addEventListener('dragstart', function() { " |
| 1078 " window.event.preventDefault(); " | 1078 " window.event.preventDefault(); " |
| 1079 "});"; | 1079 "});"; |
| 1080 render_view_host->ExecuteJavascriptInWebFrame(base::string16(), | 1080 render_view_host->ExecuteJavascriptInWebFrame(base::string16(), |
| 1081 ASCIIToUTF16(script)); | 1081 base::ASCIIToUTF16(script)); |
| 1082 } | 1082 } |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 void BrowserPluginGuest::RenderViewReady() { | 1085 void BrowserPluginGuest::RenderViewReady() { |
| 1086 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 1086 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
| 1087 // The guest RenderView should always live in a guest process. | 1087 // The guest RenderView should always live in a guest process. |
| 1088 CHECK(rvh->GetProcess()->IsGuest()); | 1088 CHECK(rvh->GetProcess()->IsGuest()); |
| 1089 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 1089 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 1090 // here (see http://crbug.com/158151). | 1090 // here (see http://crbug.com/158151). |
| 1091 Send(new InputMsg_SetFocus(routing_id(), focused_)); | 1091 Send(new InputMsg_SetFocus(routing_id(), focused_)); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 Send(new InputMsg_ExecuteEditCommand(routing_id(), name, std::string())); | 1301 Send(new InputMsg_ExecuteEditCommand(routing_id(), name, std::string())); |
| 1302 } | 1302 } |
| 1303 | 1303 |
| 1304 void BrowserPluginGuest::OnImeSetComposition( | 1304 void BrowserPluginGuest::OnImeSetComposition( |
| 1305 int instance_id, | 1305 int instance_id, |
| 1306 const std::string& text, | 1306 const std::string& text, |
| 1307 const std::vector<blink::WebCompositionUnderline>& underlines, | 1307 const std::vector<blink::WebCompositionUnderline>& underlines, |
| 1308 int selection_start, | 1308 int selection_start, |
| 1309 int selection_end) { | 1309 int selection_end) { |
| 1310 Send(new ViewMsg_ImeSetComposition(routing_id(), | 1310 Send(new ViewMsg_ImeSetComposition(routing_id(), |
| 1311 UTF8ToUTF16(text), underlines, | 1311 base::UTF8ToUTF16(text), underlines, |
| 1312 selection_start, selection_end)); | 1312 selection_start, selection_end)); |
| 1313 } | 1313 } |
| 1314 | 1314 |
| 1315 void BrowserPluginGuest::OnImeConfirmComposition( | 1315 void BrowserPluginGuest::OnImeConfirmComposition( |
| 1316 int instance_id, | 1316 int instance_id, |
| 1317 const std::string& text, | 1317 const std::string& text, |
| 1318 bool keep_selection) { | 1318 bool keep_selection) { |
| 1319 Send(new ViewMsg_ImeConfirmComposition(routing_id(), | 1319 Send(new ViewMsg_ImeConfirmComposition(routing_id(), |
| 1320 UTF8ToUTF16(text), | 1320 base::UTF8ToUTF16(text), |
| 1321 gfx::Range::InvalidRange(), | 1321 gfx::Range::InvalidRange(), |
| 1322 keep_selection)); | 1322 keep_selection)); |
| 1323 } | 1323 } |
| 1324 | 1324 |
| 1325 void BrowserPluginGuest::OnExtendSelectionAndDelete( | 1325 void BrowserPluginGuest::OnExtendSelectionAndDelete( |
| 1326 int instance_id, | 1326 int instance_id, |
| 1327 int before, | 1327 int before, |
| 1328 int after) { | 1328 int after) { |
| 1329 Send(new ViewMsg_ExtendSelectionAndDelete(routing_id(), before, after)); | 1329 Send(new ViewMsg_ExtendSelectionAndDelete(routing_id(), before, after)); |
| 1330 } | 1330 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 const GURL& origin_url, | 1708 const GURL& origin_url, |
| 1709 const std::string& accept_lang, | 1709 const std::string& accept_lang, |
| 1710 JavaScriptMessageType javascript_message_type, | 1710 JavaScriptMessageType javascript_message_type, |
| 1711 const base::string16& message_text, | 1711 const base::string16& message_text, |
| 1712 const base::string16& default_prompt_text, | 1712 const base::string16& default_prompt_text, |
| 1713 const DialogClosedCallback& callback, | 1713 const DialogClosedCallback& callback, |
| 1714 bool* did_suppress_message) { | 1714 bool* did_suppress_message) { |
| 1715 base::DictionaryValue request_info; | 1715 base::DictionaryValue request_info; |
| 1716 request_info.Set( | 1716 request_info.Set( |
| 1717 browser_plugin::kDefaultPromptText, | 1717 browser_plugin::kDefaultPromptText, |
| 1718 base::Value::CreateStringValue(UTF16ToUTF8(default_prompt_text))); | 1718 base::Value::CreateStringValue(base::UTF16ToUTF8(default_prompt_text))); |
| 1719 request_info.Set( | 1719 request_info.Set( |
| 1720 browser_plugin::kMessageText, | 1720 browser_plugin::kMessageText, |
| 1721 base::Value::CreateStringValue(UTF16ToUTF8(message_text))); | 1721 base::Value::CreateStringValue(base::UTF16ToUTF8(message_text))); |
| 1722 request_info.Set( | 1722 request_info.Set( |
| 1723 browser_plugin::kMessageType, | 1723 browser_plugin::kMessageType, |
| 1724 base::Value::CreateStringValue( | 1724 base::Value::CreateStringValue( |
| 1725 JavaScriptMessageTypeToString(javascript_message_type))); | 1725 JavaScriptMessageTypeToString(javascript_message_type))); |
| 1726 request_info.Set( | 1726 request_info.Set( |
| 1727 browser_plugin::kURL, | 1727 browser_plugin::kURL, |
| 1728 base::Value::CreateStringValue(origin_url.spec())); | 1728 base::Value::CreateStringValue(origin_url.spec())); |
| 1729 | 1729 |
| 1730 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG, | 1730 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG, |
| 1731 new JavaScriptDialogRequest(callback), | 1731 new JavaScriptDialogRequest(callback), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 request_info.Set(browser_plugin::kRequestMethod, | 1856 request_info.Set(browser_plugin::kRequestMethod, |
| 1857 base::Value::CreateStringValue(request_method)); | 1857 base::Value::CreateStringValue(request_method)); |
| 1858 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1858 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1859 | 1859 |
| 1860 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1860 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
| 1861 new DownloadRequest(callback), | 1861 new DownloadRequest(callback), |
| 1862 request_info); | 1862 request_info); |
| 1863 } | 1863 } |
| 1864 | 1864 |
| 1865 } // namespace content | 1865 } // namespace content |
| OLD | NEW |