Index: content/browser/browser_plugin/browser_plugin_guest.cc |
diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc |
index 4055cb7ab95f74aa7193e992db5ebfe9a9687740..c504abd04244e83a12880aec23909bb2092c1930 100644 |
--- a/content/browser/browser_plugin/browser_plugin_guest.cc |
+++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
@@ -61,8 +61,9 @@ BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
// should be able to handle the response to their permission request. |
class BrowserPluginGuest::PermissionRequest { |
public: |
- virtual void Respond(bool should_allow) = 0; |
+ virtual void Respond(bool should_allow, const std::string& user_input) = 0; |
virtual ~PermissionRequest() {} |
+ virtual BrowserPluginPermissionType GetType() const = 0; |
protected: |
PermissionRequest() { |
RecordAction(UserMetricsAction("BrowserPlugin.Guest.PermissionRequest")); |
@@ -76,9 +77,13 @@ class BrowserPluginGuest::DownloadRequest : public PermissionRequest { |
RecordAction( |
UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Download")); |
} |
- virtual void Respond(bool should_allow) OVERRIDE { |
+ virtual void Respond(bool should_allow, |
+ const std::string& user_input) OVERRIDE { |
callback_.Run(should_allow); |
} |
+ virtual BrowserPluginPermissionType GetType() const OVERRIDE { |
+ return BrowserPluginPermissionTypeDownload; |
+ } |
virtual ~DownloadRequest() {} |
private: |
base::Callback<void(bool)> callback_; |
@@ -98,7 +103,8 @@ class BrowserPluginGuest::GeolocationRequest : public PermissionRequest { |
UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Geolocation")); |
} |
- virtual void Respond(bool should_allow) OVERRIDE { |
+ virtual void Respond(bool should_allow, |
+ const std::string& user_input) OVERRIDE { |
WebContents* web_contents = guest_->embedder_web_contents(); |
if (should_allow && web_contents) { |
// If renderer side embedder decides to allow gelocation, we need to check |
@@ -129,6 +135,9 @@ class BrowserPluginGuest::GeolocationRequest : public PermissionRequest { |
} |
guest_->SetGeolocationPermission(callback_, bridge_id_, false); |
} |
+ virtual BrowserPluginPermissionType GetType() const OVERRIDE { |
+ return BrowserPluginPermissionTypeGeolocation; |
+ } |
virtual ~GeolocationRequest() {} |
private: |
base::Callback<void(bool)> callback_; |
@@ -149,7 +158,8 @@ class BrowserPluginGuest::MediaRequest : public PermissionRequest { |
UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Media")); |
} |
- virtual void Respond(bool should_allow) OVERRIDE { |
+ virtual void Respond(bool should_allow, |
+ const std::string& user_input) OVERRIDE { |
WebContentsImpl* web_contents = guest_->embedder_web_contents(); |
if (should_allow && web_contents) { |
// Re-route the request to the embedder's WebContents; the guest gets the |
@@ -159,7 +169,9 @@ class BrowserPluginGuest::MediaRequest : public PermissionRequest { |
// Deny the request. |
callback_.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>()); |
} |
- |
+ } |
+ virtual BrowserPluginPermissionType GetType() const OVERRIDE { |
+ return BrowserPluginPermissionTypeMedia; |
} |
virtual ~MediaRequest() {} |
private: |
@@ -177,7 +189,8 @@ class BrowserPluginGuest::NewWindowRequest : public PermissionRequest { |
UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.NewWindow")); |
} |
- virtual void Respond(bool should_allow) OVERRIDE { |
+ virtual void Respond(bool should_allow, |
+ const std::string& user_input) OVERRIDE { |
int embedder_render_process_id = |
guest_->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
BrowserPluginGuest* guest = |
@@ -192,12 +205,42 @@ class BrowserPluginGuest::NewWindowRequest : public PermissionRequest { |
if (!should_allow) |
guest->Destroy(); |
} |
+ virtual BrowserPluginPermissionType GetType() const OVERRIDE { |
+ return BrowserPluginPermissionTypeNewWindow; |
+ } |
virtual ~NewWindowRequest() {} |
private: |
int instance_id_; |
BrowserPluginGuest* guest_; |
}; |
+class BrowserPluginGuest::JavaScriptDialogRequest : public PermissionRequest { |
+ public: |
+ JavaScriptDialogRequest(const DialogClosedCallback& callback, |
+ BrowserPluginGuest* guest) |
+ : callback_(callback), |
+ guest_(guest) { |
+ RecordAction( |
+ UserMetricsAction( |
+ "BrowserPlugin.Guest.PermissionRequest.JavaScriptDialog")); |
+ } |
+ |
+ virtual void Respond(bool should_allow, |
+ const std::string& user_input) OVERRIDE { |
+ if (!guest_) |
lazyboy
2013/07/19 21:43:16
How could this turn to null?
Fady Samuel
2013/07/23 15:41:10
Hmm, with the cleanup I recently added for pointer
Fady Samuel
2013/07/23 15:41:10
Hmm, it can't removed.
|
+ return; |
+ callback_.Run(should_allow, UTF8ToUTF16(user_input)); |
+ } |
+ virtual BrowserPluginPermissionType GetType() const OVERRIDE { |
+ return BrowserPluginPermissionTypeJavaScriptDialog; |
+ } |
+ |
+ virtual ~JavaScriptDialogRequest() {} |
+ private: |
+ DialogClosedCallback callback_; |
+ BrowserPluginGuest* guest_; |
lazyboy
2013/07/19 21:43:16
A raw pointer is probably not ok here.
Also what
Fady Samuel
2013/07/23 15:41:10
Removed pointer. This request goes away when Brows
|
+}; |
+ |
namespace { |
const size_t kNumMaxOutstandingPermissionRequests = 1024; |
@@ -224,6 +267,21 @@ static std::string WindowOpenDispositionToString( |
} |
} |
+static std::string JavaScriptMessageTypeToString( |
+ JavaScriptMessageType message_type) { |
+ switch (message_type) { |
+ case JAVASCRIPT_MESSAGE_TYPE_ALERT: |
+ return "alert"; |
+ case JAVASCRIPT_MESSAGE_TYPE_CONFIRM: |
+ return "confirm"; |
+ case JAVASCRIPT_MESSAGE_TYPE_PROMPT: |
+ return "prompt"; |
+ default: |
+ NOTREACHED() << "Unknown JavaScript Message Type."; |
+ return "unknown"; |
+ } |
+} |
+ |
// Called on IO thread. |
static std::string RetrieveDownloadURLFromRequestId( |
RenderViewHost* render_view_host, |
@@ -563,6 +621,10 @@ void BrowserPluginGuest::CloseContents(WebContents* source) { |
delegate_->Close(); |
} |
+JavaScriptDialogManager* BrowserPluginGuest::GetJavaScriptDialogManager() { |
+ return this; |
+} |
+ |
bool BrowserPluginGuest::HandleContextMenu(const ContextMenuParams& params) { |
// TODO(fsamuel): We show the regular page context menu handler for now until |
// we implement the Apps Context Menu API for Browser Plugin (see |
@@ -1290,15 +1352,16 @@ void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) { |
void BrowserPluginGuest::OnRespondPermission( |
int instance_id, |
- BrowserPluginPermissionType permission_type, |
int request_id, |
- bool should_allow) { |
+ bool should_allow, |
+ const std::string& user_input) { |
RequestMap::iterator request_itr = permission_request_map_.find(request_id); |
if (request_itr == permission_request_map_.end()) { |
LOG(INFO) << "Not a valid request ID."; |
return; |
} |
- request_itr->second->Respond(should_allow); |
+ BrowserPluginPermissionType permission_type = request_itr->second->GetType(); |
+ request_itr->second->Respond(should_allow, user_input); |
// Geolocation requests have to hang around for a while, so we don't delete |
// them here. |
@@ -1425,6 +1488,61 @@ void BrowserPluginGuest::RequestMediaAccessPermission( |
request_id, request_info)); |
} |
+void BrowserPluginGuest::RunJavaScriptDialog( |
+ WebContents* web_contents, |
+ const GURL& origin_url, |
+ const std::string& accept_lang, |
+ JavaScriptMessageType javascript_message_type, |
+ const string16& message_text, |
+ const string16& default_prompt_text, |
+ const DialogClosedCallback& callback, |
+ bool* did_suppress_message) { |
+ if (permission_request_map_.size() >= kNumMaxOutstandingPermissionRequests) { |
+ // Cancel the dialog. |
+ callback.Run(false, string16()); |
+ return; |
+ } |
+ int request_id = next_permission_request_id_++; |
+ permission_request_map_[request_id] = |
+ new JavaScriptDialogRequest(callback, this); |
+ base::DictionaryValue request_info; |
+ request_info.Set( |
+ browser_plugin::kDefaultPromptText, |
+ base::Value::CreateStringValue(UTF16ToUTF8(default_prompt_text))); |
+ request_info.Set( |
+ browser_plugin::kMessageText, |
+ base::Value::CreateStringValue(UTF16ToUTF8(message_text))); |
+ request_info.Set( |
+ browser_plugin::kMessageType, |
+ base::Value::CreateStringValue( |
+ JavaScriptMessageTypeToString(javascript_message_type))); |
+ request_info.Set( |
+ browser_plugin::kURL, |
+ base::Value::CreateStringValue(origin_url.spec())); |
+ SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( |
+ instance_id(), BrowserPluginPermissionTypeJavaScriptDialog, |
+ request_id, request_info)); |
+} |
+ |
+void BrowserPluginGuest::RunBeforeUnloadDialog( |
+ WebContents* web_contents, |
+ const string16& message_text, |
+ bool is_reload, |
+ const DialogClosedCallback& callback) { |
+ callback.Run(true, string16()); |
lazyboy
2013/07/19 21:43:16
What does this do? Can you add a comment.
|
+} |
+ |
+bool BrowserPluginGuest::HandleJavaScriptDialog( |
+ WebContents* web_contents, |
lazyboy
2013/07/19 21:43:16
nit: can fit in previous line.
Fady Samuel
2013/07/23 15:41:10
The third line cannot.
|
+ bool accept, |
+ const string16* prompt_override) { |
+ return false; |
+} |
+ |
+void BrowserPluginGuest::ResetJavaScriptState( |
+ WebContents* web_contents) { |
lazyboy
2013/07/19 21:43:16
nit: can fit in previous line.
Fady Samuel
2013/07/23 15:41:10
Done.
|
+} |
+ |
void BrowserPluginGuest::OnUpdateRect( |
const ViewHostMsg_UpdateRect_Params& params) { |
@@ -1485,8 +1603,8 @@ void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( |
int permission_request_id, |
const std::string& url) { |
if (url.empty()) { |
- OnRespondPermission(instance_id(), BrowserPluginPermissionTypeDownload, |
- permission_request_id, false); |
+ OnRespondPermission(instance_id(), permission_request_id, |
+ false, std::string()); |
return; |
} |