| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 virtual ~PermissionRequest() {} | 81 virtual ~PermissionRequest() {} |
| 82 | 82 |
| 83 virtual void RespondImpl(bool should_allow, | 83 virtual void RespondImpl(bool should_allow, |
| 84 const std::string& user_input) = 0; | 84 const std::string& user_input) = 0; |
| 85 // Friend RefCounted so that the dtor can be non-public. | 85 // Friend RefCounted so that the dtor can be non-public. |
| 86 friend class base::RefCounted<BrowserPluginGuest::PermissionRequest>; | 86 friend class base::RefCounted<BrowserPluginGuest::PermissionRequest>; |
| 87 | 87 |
| 88 base::WeakPtr<BrowserPluginGuest> guest_; | 88 base::WeakPtr<BrowserPluginGuest> guest_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 class BrowserPluginGuest::DownloadRequest : public PermissionRequest { | |
| 92 public: | |
| 93 DownloadRequest(const base::WeakPtr<BrowserPluginGuest>& guest, | |
| 94 const base::Callback<void(bool)>& callback) | |
| 95 : PermissionRequest(guest), | |
| 96 callback_(callback) { | |
| 97 RecordAction( | |
| 98 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Download"
)); | |
| 99 } | |
| 100 virtual void RespondImpl(bool should_allow, | |
| 101 const std::string& user_input) OVERRIDE { | |
| 102 callback_.Run(should_allow); | |
| 103 } | |
| 104 | |
| 105 private: | |
| 106 virtual ~DownloadRequest() {} | |
| 107 base::Callback<void(bool)> callback_; | |
| 108 }; | |
| 109 | |
| 110 class BrowserPluginGuest::NewWindowRequest : public PermissionRequest { | 91 class BrowserPluginGuest::NewWindowRequest : public PermissionRequest { |
| 111 public: | 92 public: |
| 112 NewWindowRequest(const base::WeakPtr<BrowserPluginGuest>& guest, | 93 NewWindowRequest(const base::WeakPtr<BrowserPluginGuest>& guest, |
| 113 int instance_id) | 94 int instance_id) |
| 114 : PermissionRequest(guest), | 95 : PermissionRequest(guest), |
| 115 instance_id_(instance_id) { | 96 instance_id_(instance_id) { |
| 116 RecordAction( | 97 RecordAction( |
| 117 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.NewWindow
")); | 98 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.NewWindow
")); |
| 118 } | 99 } |
| 119 | 100 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return "confirm"; | 190 return "confirm"; |
| 210 case JAVASCRIPT_MESSAGE_TYPE_PROMPT: | 191 case JAVASCRIPT_MESSAGE_TYPE_PROMPT: |
| 211 return "prompt"; | 192 return "prompt"; |
| 212 default: | 193 default: |
| 213 NOTREACHED() << "Unknown JavaScript Message Type."; | 194 NOTREACHED() << "Unknown JavaScript Message Type."; |
| 214 return "unknown"; | 195 return "unknown"; |
| 215 } | 196 } |
| 216 } | 197 } |
| 217 | 198 |
| 218 // Called on IO thread. | 199 // Called on IO thread. |
| 219 static std::string RetrieveDownloadURLFromRequestId( | 200 static GURL RetrieveDownloadURLFromRequestId( |
| 220 RenderViewHost* render_view_host, | 201 int render_process_id, |
| 221 int url_request_id) { | 202 int url_request_id) { |
| 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 223 | 204 |
| 224 int render_process_id = render_view_host->GetProcess()->GetID(); | |
| 225 GlobalRequestID global_id(render_process_id, url_request_id); | 205 GlobalRequestID global_id(render_process_id, url_request_id); |
| 226 net::URLRequest* url_request = | 206 net::URLRequest* url_request = |
| 227 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); | 207 ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); |
| 228 if (url_request) | 208 if (url_request) |
| 229 return url_request->url().possibly_invalid_spec(); | 209 return url_request->url(); |
| 230 return ""; | 210 return GURL(); |
| 231 } | 211 } |
| 232 | 212 |
| 233 } // namespace | 213 } // namespace |
| 234 | 214 |
| 235 class BrowserPluginGuest::EmbedderWebContentsObserver | 215 class BrowserPluginGuest::EmbedderWebContentsObserver |
| 236 : public WebContentsObserver { | 216 : public WebContentsObserver { |
| 237 public: | 217 public: |
| 238 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) | 218 explicit EmbedderWebContentsObserver(BrowserPluginGuest* guest) |
| 239 : WebContentsObserver(guest->embedder_web_contents()), | 219 : WebContentsObserver(guest->embedder_web_contents()), |
| 240 browser_plugin_guest_(guest) { | 220 browser_plugin_guest_(guest) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 *was_blocked = false; | 650 *was_blocked = false; |
| 671 RequestNewWindowPermission(disposition, initial_pos, user_gesture, | 651 RequestNewWindowPermission(disposition, initial_pos, user_gesture, |
| 672 static_cast<WebContentsImpl*>(new_contents)); | 652 static_cast<WebContentsImpl*>(new_contents)); |
| 673 } | 653 } |
| 674 | 654 |
| 675 void BrowserPluginGuest::CanDownload( | 655 void BrowserPluginGuest::CanDownload( |
| 676 RenderViewHost* render_view_host, | 656 RenderViewHost* render_view_host, |
| 677 int request_id, | 657 int request_id, |
| 678 const std::string& request_method, | 658 const std::string& request_method, |
| 679 const base::Callback<void(bool)>& callback) { | 659 const base::Callback<void(bool)>& callback) { |
| 660 if (!delegate_) { |
| 661 callback.Run(false); |
| 662 return; |
| 663 } |
| 664 |
| 680 BrowserThread::PostTaskAndReplyWithResult( | 665 BrowserThread::PostTaskAndReplyWithResult( |
| 681 BrowserThread::IO, FROM_HERE, | 666 BrowserThread::IO, FROM_HERE, |
| 682 base::Bind(&RetrieveDownloadURLFromRequestId, | 667 base::Bind(&RetrieveDownloadURLFromRequestId, |
| 683 render_view_host, request_id), | 668 render_view_host->GetProcess()->GetID(), request_id), |
| 684 base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId, | 669 base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId, |
| 685 weak_ptr_factory_.GetWeakPtr(), | 670 weak_ptr_factory_.GetWeakPtr(), |
| 686 request_method, | 671 request_method, |
| 687 callback)); | 672 callback)); |
| 688 } | 673 } |
| 689 | 674 |
| 690 void BrowserPluginGuest::LoadProgressChanged(WebContents* contents, | 675 void BrowserPluginGuest::LoadProgressChanged(WebContents* contents, |
| 691 double progress) { | 676 double progress) { |
| 692 if (delegate_) | 677 if (delegate_) |
| 693 delegate_->LoadProgressed(progress); | 678 delegate_->LoadProgressed(progress); |
| (...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 const std::vector<gfx::Rect>& character_bounds) { | 1755 const std::vector<gfx::Rect>& character_bounds) { |
| 1771 RenderWidgetHostViewPort::FromRWHV( | 1756 RenderWidgetHostViewPort::FromRWHV( |
| 1772 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 1757 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
| 1773 range, character_bounds); | 1758 range, character_bounds); |
| 1774 } | 1759 } |
| 1775 #endif | 1760 #endif |
| 1776 | 1761 |
| 1777 void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( | 1762 void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( |
| 1778 const std::string& request_method, | 1763 const std::string& request_method, |
| 1779 const base::Callback<void(bool)>& callback, | 1764 const base::Callback<void(bool)>& callback, |
| 1780 const std::string& url) { | 1765 const GURL& url) { |
| 1781 if (url.empty()) { | 1766 if (!url.is_valid()) { |
| 1782 callback.Run(false); | 1767 callback.Run(false); |
| 1783 return; | 1768 return; |
| 1784 } | 1769 } |
| 1785 | 1770 |
| 1786 base::DictionaryValue request_info; | 1771 delegate_->CanDownload(request_method, url, callback); |
| 1787 request_info.Set(browser_plugin::kRequestMethod, | |
| 1788 base::Value::CreateStringValue(request_method)); | |
| 1789 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | |
| 1790 | |
| 1791 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | |
| 1792 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), | |
| 1793 callback), | |
| 1794 request_info); | |
| 1795 } | 1772 } |
| 1796 | 1773 |
| 1797 } // namespace content | 1774 } // namespace content |
| OLD | NEW |