Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: chrome/browser/guestview/webview/webview_guest.cc

Issue 21297005: <webview>: Refactor Permission API to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_permissions
Patch Set: Fixed some bugs Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/guestview/webview/webview_guest.cc
diff --git a/chrome/browser/guestview/webview/webview_guest.cc b/chrome/browser/guestview/webview/webview_guest.cc
index 9bd938950043abc7c591bc3bf080b1bc4bba0be4..d1c9bd8bd37d22e3ce65d532691cfbbcb561a86a 100644
--- a/chrome/browser/guestview/webview/webview_guest.cc
+++ b/chrome/browser/guestview/webview/webview_guest.cc
@@ -43,6 +43,28 @@ static std::string TerminationStatusToString(base::TerminationStatus status) {
return "unknown";
}
+static std::string PermissionTypeToString(BrowserPluginPermissionType type) {
+ switch (type) {
+ case BrowserPluginPermissionTypeDownload:
+ return webview::kPermissionTypeDownload;
+ case BrowserPluginPermissionTypeGeolocation:
+ return webview::kPermissionTypeGeolocation;
+ case BrowserPluginPermissionTypeMedia:
+ return webview::kPermissionTypeMedia;
+ case BrowserPluginPermissionTypeNewWindow:
+ return webview::kPermissionTypeNewWindow;
+ case BrowserPluginPermissionTypePointerLock:
+ return webview::kPermissionTypePointerLock;
+ case BrowserPluginPermissionTypeJavaScriptDialog:
+ return webview::kPermissionTypeDialog;
+ case BrowserPluginPermissionTypeUnknown:
+ default:
+ NOTREACHED();
+ break;
+ }
+ return std::string();
+}
+
void RemoveWebViewEventListenersOnIOThread(
void* profile,
const std::string& extension_id,
@@ -59,7 +81,8 @@ WebViewGuest::WebViewGuest(WebContents* guest_web_contents)
: GuestView(guest_web_contents),
WebContentsObserver(guest_web_contents),
script_executor_(new extensions::ScriptExecutor(guest_web_contents,
- &script_observers_)) {
+ &script_observers_)),
+ next_permission_request_id_(0) {
notification_registrar_.Add(
this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::Source<WebContents>(guest_web_contents));
@@ -176,6 +199,36 @@ void WebViewGuest::RendererUnresponsive() {
DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass()));
}
+bool WebViewGuest::RequestPermission(
+ BrowserPluginPermissionType permission_type,
+ const base::DictionaryValue& request_info,
+ const PermissionResponseCallback& callback) {
+ int request_id = next_permission_request_id_++;
+ pending_permission_requests_[request_id] = callback;
+ scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy());
+ args->SetInteger(webview::kRequestId, request_id);
+ switch (permission_type) {
+ case BrowserPluginPermissionTypeNewWindow: {
+ DispatchEvent(new GuestView::Event(webview::kEventNewWindow,
+ args.Pass()));
+ break;
+ }
+ case BrowserPluginPermissionTypeJavaScriptDialog: {
+ DispatchEvent(new GuestView::Event(webview::kEventDialog,
+ args.Pass()));
+ break;
+ }
+ default: {
+ args->SetString(webview::kPermission,
+ PermissionTypeToString(permission_type));
+ DispatchEvent(new GuestView::Event(webview::kEventPermissionRequest,
+ args.Pass()));
+ break;
+ }
+ }
+ return true;
+}
+
void WebViewGuest::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -216,6 +269,20 @@ void WebViewGuest::Reload() {
guest_web_contents()->GetController().Reload(false);
}
+bool WebViewGuest::SetPermission(int request_id,
+ bool should_allow,
+ const std::string& user_input) {
+ RequestMap::iterator request_itr =
+ pending_permission_requests_.find(request_id);
+
+ if (request_itr == pending_permission_requests_.end())
+ return false;
+
+ request_itr->second.Run(should_allow, user_input);
+ pending_permission_requests_.erase(request_itr);
+ return true;
+}
+
void WebViewGuest::Stop() {
guest_web_contents()->Stop();
}

Powered by Google App Engine
This is Rietveld 408576698