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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 *was_blocked = false; | 645 *was_blocked = false; |
666 RequestNewWindowPermission(disposition, initial_pos, user_gesture, | 646 RequestNewWindowPermission(disposition, initial_pos, user_gesture, |
667 static_cast<WebContentsImpl*>(new_contents)); | 647 static_cast<WebContentsImpl*>(new_contents)); |
668 } | 648 } |
669 | 649 |
670 void BrowserPluginGuest::CanDownload( | 650 void BrowserPluginGuest::CanDownload( |
671 RenderViewHost* render_view_host, | 651 RenderViewHost* render_view_host, |
672 int request_id, | 652 int request_id, |
673 const std::string& request_method, | 653 const std::string& request_method, |
674 const base::Callback<void(bool)>& callback) { | 654 const base::Callback<void(bool)>& callback) { |
| 655 if (!delegate_) { |
| 656 callback.Run(false); |
| 657 return; |
| 658 } |
| 659 |
675 BrowserThread::PostTaskAndReplyWithResult( | 660 BrowserThread::PostTaskAndReplyWithResult( |
676 BrowserThread::IO, FROM_HERE, | 661 BrowserThread::IO, FROM_HERE, |
677 base::Bind(&RetrieveDownloadURLFromRequestId, | 662 base::Bind(&RetrieveDownloadURLFromRequestId, |
678 render_view_host, request_id), | 663 render_view_host->GetProcess()->GetID(), request_id), |
679 base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId, | 664 base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId, |
680 weak_ptr_factory_.GetWeakPtr(), | 665 weak_ptr_factory_.GetWeakPtr(), |
681 request_method, | 666 request_method, |
682 callback)); | 667 callback)); |
683 } | 668 } |
684 | 669 |
685 void BrowserPluginGuest::LoadProgressChanged(WebContents* contents, | 670 void BrowserPluginGuest::LoadProgressChanged(WebContents* contents, |
686 double progress) { | 671 double progress) { |
687 if (delegate_) | 672 if (delegate_) |
688 delegate_->LoadProgressed(progress); | 673 delegate_->LoadProgressed(progress); |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 const std::vector<gfx::Rect>& character_bounds) { | 1720 const std::vector<gfx::Rect>& character_bounds) { |
1736 RenderWidgetHostViewPort::FromRWHV( | 1721 RenderWidgetHostViewPort::FromRWHV( |
1737 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 1722 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
1738 range, character_bounds); | 1723 range, character_bounds); |
1739 } | 1724 } |
1740 #endif | 1725 #endif |
1741 | 1726 |
1742 void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( | 1727 void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( |
1743 const std::string& request_method, | 1728 const std::string& request_method, |
1744 const base::Callback<void(bool)>& callback, | 1729 const base::Callback<void(bool)>& callback, |
1745 const std::string& url) { | 1730 const GURL& url) { |
1746 if (url.empty()) { | 1731 if (!url.is_valid()) { |
1747 callback.Run(false); | 1732 callback.Run(false); |
1748 return; | 1733 return; |
1749 } | 1734 } |
1750 | 1735 |
1751 base::DictionaryValue request_info; | 1736 delegate_->CanDownload(request_method, url, callback); |
1752 request_info.Set(browser_plugin::kRequestMethod, | |
1753 base::Value::CreateStringValue(request_method)); | |
1754 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); | |
1755 | |
1756 RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, | |
1757 new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), | |
1758 callback), | |
1759 request_info); | |
1760 } | 1737 } |
1761 | 1738 |
1762 } // namespace content | 1739 } // namespace content |
OLD | NEW |