| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 DCHECK(web_contents); | 358 DCHECK(web_contents); |
| 359 web_contents->SetDelegate(this); | 359 web_contents->SetDelegate(this); |
| 360 if (opener) | 360 if (opener) |
| 361 opener_ = opener->AsWeakPtr(); | 361 opener_ = opener->AsWeakPtr(); |
| 362 GetWebContents()->GetBrowserPluginGuestManager()->AddGuest(instance_id_, | 362 GetWebContents()->GetBrowserPluginGuestManager()->AddGuest(instance_id_, |
| 363 GetWebContents()); | 363 GetWebContents()); |
| 364 } | 364 } |
| 365 | 365 |
| 366 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, | 366 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, |
| 367 int32 level, | 367 int32 level, |
| 368 const string16& message, | 368 const base::string16& message, |
| 369 int32 line_no, | 369 int32 line_no, |
| 370 const string16& source_id) { | 370 const base::string16& source_id) { |
| 371 if (!delegate_) | 371 if (!delegate_) |
| 372 return false; | 372 return false; |
| 373 | 373 |
| 374 delegate_->AddMessageToConsole(level, message, line_no, source_id); | 374 delegate_->AddMessageToConsole(level, message, line_no, source_id); |
| 375 return true; | 375 return true; |
| 376 } | 376 } |
| 377 | 377 |
| 378 void BrowserPluginGuest::DestroyUnattachedWindows() { | 378 void BrowserPluginGuest::DestroyUnattachedWindows() { |
| 379 // Destroy() reaches in and removes the BrowserPluginGuest from its opener's | 379 // Destroy() reaches in and removes the BrowserPluginGuest from its opener's |
| 380 // pending_new_windows_ set. To avoid mutating the set while iterating, we | 380 // pending_new_windows_ set. To avoid mutating the set while iterating, we |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 // This can happen for cross-site redirects. | 789 // This can happen for cross-site redirects. |
| 790 LoadURLWithParams(params.url, params.referrer, params.transition, source); | 790 LoadURLWithParams(params.url, params.referrer, params.transition, source); |
| 791 return source; | 791 return source; |
| 792 } | 792 } |
| 793 | 793 |
| 794 return CreateNewGuestWindow(params)->GetWebContents(); | 794 return CreateNewGuestWindow(params)->GetWebContents(); |
| 795 } | 795 } |
| 796 | 796 |
| 797 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 797 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
| 798 int64 source_frame_id, | 798 int64 source_frame_id, |
| 799 const string16& frame_name, | 799 const base::string16& frame_name, |
| 800 const GURL& target_url, | 800 const GURL& target_url, |
| 801 WebContents* new_contents) { | 801 WebContents* new_contents) { |
| 802 WebContentsImpl* new_contents_impl = | 802 WebContentsImpl* new_contents_impl = |
| 803 static_cast<WebContentsImpl*>(new_contents); | 803 static_cast<WebContentsImpl*>(new_contents); |
| 804 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); | 804 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); |
| 805 guest->opener_ = AsWeakPtr(); | 805 guest->opener_ = AsWeakPtr(); |
| 806 std::string guest_name = UTF16ToUTF8(frame_name); | 806 std::string guest_name = UTF16ToUTF8(frame_name); |
| 807 guest->name_ = guest_name; | 807 guest->name_ = guest_name; |
| 808 // Take ownership of the new guest until it is attached to the embedder's DOM | 808 // Take ownership of the new guest until it is attached to the embedder's DOM |
| 809 // tree to avoid leaking a guest if this guest is destroyed before attaching | 809 // tree to avoid leaking a guest if this guest is destroyed before attaching |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1021 |
| 1022 while (!pending_messages_.empty()) { | 1022 while (!pending_messages_.empty()) { |
| 1023 IPC::Message* message = pending_messages_.front(); | 1023 IPC::Message* message = pending_messages_.front(); |
| 1024 pending_messages_.pop(); | 1024 pending_messages_.pop(); |
| 1025 SendMessageToEmbedder(message); | 1025 SendMessageToEmbedder(message); |
| 1026 } | 1026 } |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( | 1029 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( |
| 1030 int64 frame_id, | 1030 int64 frame_id, |
| 1031 const string16& frame_unique_name, | 1031 const base::string16& frame_unique_name, |
| 1032 bool is_main_frame, | 1032 bool is_main_frame, |
| 1033 const GURL& url, | 1033 const GURL& url, |
| 1034 PageTransition transition_type, | 1034 PageTransition transition_type, |
| 1035 RenderViewHost* render_view_host) { | 1035 RenderViewHost* render_view_host) { |
| 1036 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 1036 RecordAction(UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
| 1037 } | 1037 } |
| 1038 | 1038 |
| 1039 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 1039 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 1040 bool enable_dragdrop = delegate_ && delegate_->IsDragAndDropEnabled(); | 1040 bool enable_dragdrop = delegate_ && delegate_->IsDragAndDropEnabled(); |
| 1041 if (!enable_dragdrop) { | 1041 if (!enable_dragdrop) { |
| 1042 // Initiating a drag from inside a guest is currently not supported without | 1042 // Initiating a drag from inside a guest is currently not supported without |
| 1043 // the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some | 1043 // the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some |
| 1044 // JS to disable it. http://crbug.com/161112 | 1044 // JS to disable it. http://crbug.com/161112 |
| 1045 const char script[] = "window.addEventListener('dragstart', function() { " | 1045 const char script[] = "window.addEventListener('dragstart', function() { " |
| 1046 " window.event.preventDefault(); " | 1046 " window.event.preventDefault(); " |
| 1047 "});"; | 1047 "});"; |
| 1048 render_view_host->ExecuteJavascriptInWebFrame(string16(), | 1048 render_view_host->ExecuteJavascriptInWebFrame(base::string16(), |
| 1049 ASCIIToUTF16(script)); | 1049 ASCIIToUTF16(script)); |
| 1050 } | 1050 } |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 void BrowserPluginGuest::RenderViewReady() { | 1053 void BrowserPluginGuest::RenderViewReady() { |
| 1054 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 1054 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 1055 // here (see http://crbug.com/158151). | 1055 // here (see http://crbug.com/158151). |
| 1056 Send(new InputMsg_SetFocus(routing_id(), focused_)); | 1056 Send(new InputMsg_SetFocus(routing_id(), focused_)); |
| 1057 UpdateVisibility(); | 1057 UpdateVisibility(); |
| 1058 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 1058 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA, | 1626 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA, |
| 1627 new MediaRequest(request, callback, this), | 1627 new MediaRequest(request, callback, this), |
| 1628 request_info); | 1628 request_info); |
| 1629 } | 1629 } |
| 1630 | 1630 |
| 1631 void BrowserPluginGuest::RunJavaScriptDialog( | 1631 void BrowserPluginGuest::RunJavaScriptDialog( |
| 1632 WebContents* web_contents, | 1632 WebContents* web_contents, |
| 1633 const GURL& origin_url, | 1633 const GURL& origin_url, |
| 1634 const std::string& accept_lang, | 1634 const std::string& accept_lang, |
| 1635 JavaScriptMessageType javascript_message_type, | 1635 JavaScriptMessageType javascript_message_type, |
| 1636 const string16& message_text, | 1636 const base::string16& message_text, |
| 1637 const string16& default_prompt_text, | 1637 const base::string16& default_prompt_text, |
| 1638 const DialogClosedCallback& callback, | 1638 const DialogClosedCallback& callback, |
| 1639 bool* did_suppress_message) { | 1639 bool* did_suppress_message) { |
| 1640 base::DictionaryValue request_info; | 1640 base::DictionaryValue request_info; |
| 1641 request_info.Set( | 1641 request_info.Set( |
| 1642 browser_plugin::kDefaultPromptText, | 1642 browser_plugin::kDefaultPromptText, |
| 1643 base::Value::CreateStringValue(UTF16ToUTF8(default_prompt_text))); | 1643 base::Value::CreateStringValue(UTF16ToUTF8(default_prompt_text))); |
| 1644 request_info.Set( | 1644 request_info.Set( |
| 1645 browser_plugin::kMessageText, | 1645 browser_plugin::kMessageText, |
| 1646 base::Value::CreateStringValue(UTF16ToUTF8(message_text))); | 1646 base::Value::CreateStringValue(UTF16ToUTF8(message_text))); |
| 1647 request_info.Set( | 1647 request_info.Set( |
| 1648 browser_plugin::kMessageType, | 1648 browser_plugin::kMessageType, |
| 1649 base::Value::CreateStringValue( | 1649 base::Value::CreateStringValue( |
| 1650 JavaScriptMessageTypeToString(javascript_message_type))); | 1650 JavaScriptMessageTypeToString(javascript_message_type))); |
| 1651 request_info.Set( | 1651 request_info.Set( |
| 1652 browser_plugin::kURL, | 1652 browser_plugin::kURL, |
| 1653 base::Value::CreateStringValue(origin_url.spec())); | 1653 base::Value::CreateStringValue(origin_url.spec())); |
| 1654 | 1654 |
| 1655 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG, | 1655 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG, |
| 1656 new JavaScriptDialogRequest(callback), | 1656 new JavaScriptDialogRequest(callback), |
| 1657 request_info); | 1657 request_info); |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 void BrowserPluginGuest::RunBeforeUnloadDialog( | 1660 void BrowserPluginGuest::RunBeforeUnloadDialog( |
| 1661 WebContents* web_contents, | 1661 WebContents* web_contents, |
| 1662 const string16& message_text, | 1662 const base::string16& message_text, |
| 1663 bool is_reload, | 1663 bool is_reload, |
| 1664 const DialogClosedCallback& callback) { | 1664 const DialogClosedCallback& callback) { |
| 1665 // This is called if the guest has a beforeunload event handler. | 1665 // This is called if the guest has a beforeunload event handler. |
| 1666 // This callback allows navigation to proceed. | 1666 // This callback allows navigation to proceed. |
| 1667 callback.Run(true, string16()); | 1667 callback.Run(true, base::string16()); |
| 1668 } | 1668 } |
| 1669 | 1669 |
| 1670 bool BrowserPluginGuest::HandleJavaScriptDialog( | 1670 bool BrowserPluginGuest::HandleJavaScriptDialog( |
| 1671 WebContents* web_contents, | 1671 WebContents* web_contents, |
| 1672 bool accept, | 1672 bool accept, |
| 1673 const string16* prompt_override) { | 1673 const base::string16* prompt_override) { |
| 1674 return false; | 1674 return false; |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 void BrowserPluginGuest::CancelActiveAndPendingDialogs( | 1677 void BrowserPluginGuest::CancelActiveAndPendingDialogs( |
| 1678 WebContents* web_contents) { | 1678 WebContents* web_contents) { |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 void BrowserPluginGuest::WebContentsDestroyed(WebContents* web_contents) { | 1681 void BrowserPluginGuest::WebContentsDestroyed(WebContents* web_contents) { |
| 1682 } | 1682 } |
| 1683 | 1683 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 request_info.Set(browser_plugin::kRequestMethod, | 1758 request_info.Set(browser_plugin::kRequestMethod, |
| 1759 base::Value::CreateStringValue(request_method)); | 1759 base::Value::CreateStringValue(request_method)); |
| 1760 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | 1760 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); |
| 1761 | 1761 |
| 1762 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | 1762 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, |
| 1763 new DownloadRequest(callback), | 1763 new DownloadRequest(callback), |
| 1764 request_info); | 1764 request_info); |
| 1765 } | 1765 } |
| 1766 | 1766 |
| 1767 } // namespace content | 1767 } // namespace content |
| OLD | NEW |