| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | 127 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: |
| 128 return webview::kPermissionTypeDialog; | 128 return webview::kPermissionTypeDialog; |
| 129 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | 129 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: |
| 130 return webview::kPermissionTypeLoadPlugin; | 130 return webview::kPermissionTypeLoadPlugin; |
| 131 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | 131 case WEB_VIEW_PERMISSION_TYPE_MEDIA: |
| 132 return webview::kPermissionTypeMedia; | 132 return webview::kPermissionTypeMedia; |
| 133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 133 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| 134 return webview::kPermissionTypeNewWindow; | 134 return webview::kPermissionTypeNewWindow; |
| 135 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 135 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
| 136 return webview::kPermissionTypePointerLock; | 136 return webview::kPermissionTypePointerLock; |
| 137 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 138 return webview::kPermissionTypeFileSystem; |
| 137 default: | 139 default: |
| 138 NOTREACHED(); | 140 NOTREACHED(); |
| 139 return std::string(); | 141 return std::string(); |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 | 144 |
| 143 void RemoveWebViewEventListenersOnIOThread( | 145 void RemoveWebViewEventListenersOnIOThread( |
| 144 void* profile, | 146 void* profile, |
| 145 const std::string& extension_id, | 147 const std::string& extension_id, |
| 146 int embedder_process_id, | 148 int embedder_process_id, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 UserMetricsAction("WebView.PermissionAllow.Media")); | 252 UserMetricsAction("WebView.PermissionAllow.Media")); |
| 251 break; | 253 break; |
| 252 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 254 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| 253 content::RecordAction( | 255 content::RecordAction( |
| 254 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); | 256 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); |
| 255 break; | 257 break; |
| 256 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 258 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
| 257 content::RecordAction( | 259 content::RecordAction( |
| 258 UserMetricsAction("WebView.PermissionAllow.PointerLock")); | 260 UserMetricsAction("WebView.PermissionAllow.PointerLock")); |
| 259 break; | 261 break; |
| 262 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 263 content::RecordAction( |
| 264 UserMetricsAction("WebView.PermissionAllow.FileSystem")); |
| 260 default: | 265 default: |
| 261 break; | 266 break; |
| 262 } | 267 } |
| 263 } else { | 268 } else { |
| 264 switch (info.permission_type) { | 269 switch (info.permission_type) { |
| 265 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 270 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| 266 content::RecordAction( | 271 content::RecordAction( |
| 267 UserMetricsAction("WebView.PermissionDeny.Download")); | 272 UserMetricsAction("WebView.PermissionDeny.Download")); |
| 268 break; | 273 break; |
| 269 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | 274 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 282 UserMetricsAction("WebView.PermissionDeny.Media")); | 287 UserMetricsAction("WebView.PermissionDeny.Media")); |
| 283 break; | 288 break; |
| 284 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | 289 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: |
| 285 content::RecordAction( | 290 content::RecordAction( |
| 286 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); | 291 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); |
| 287 break; | 292 break; |
| 288 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | 293 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: |
| 289 content::RecordAction( | 294 content::RecordAction( |
| 290 UserMetricsAction("WebView.PermissionDeny.PointerLock")); | 295 UserMetricsAction("WebView.PermissionDeny.PointerLock")); |
| 291 break; | 296 break; |
| 297 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: |
| 298 content::RecordAction( |
| 299 UserMetricsAction("WebView.PermissionDeny.FileSystem")); |
| 300 break; |
| 292 default: | 301 default: |
| 293 break; | 302 break; |
| 294 } | 303 } |
| 295 } | 304 } |
| 296 } | 305 } |
| 297 | 306 |
| 298 // static | 307 // static |
| 299 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( | 308 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( |
| 300 const ui::SimpleMenuModel& menu_model) { | 309 const ui::SimpleMenuModel& menu_model) { |
| 301 scoped_ptr<base::ListValue> items(new base::ListValue()); | 310 scoped_ptr<base::ListValue> items(new base::ListValue()); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 guest_web_contents()->GetController().GoToOffset(relative_index); | 618 guest_web_contents()->GetController().GoToOffset(relative_index); |
| 610 } | 619 } |
| 611 | 620 |
| 612 void WebViewGuest::Reload() { | 621 void WebViewGuest::Reload() { |
| 613 // TODO(fsamuel): Don't check for repost because we don't want to show | 622 // TODO(fsamuel): Don't check for repost because we don't want to show |
| 614 // Chromium's repost warning. We might want to implement a separate API | 623 // Chromium's repost warning. We might want to implement a separate API |
| 615 // for registering a callback if a repost is about to happen. | 624 // for registering a callback if a repost is about to happen. |
| 616 guest_web_contents()->GetController().Reload(false); | 625 guest_web_contents()->GetController().Reload(false); |
| 617 } | 626 } |
| 618 | 627 |
| 628 void WebViewGuest::RequestFileSystemPermission( |
| 629 const GURL& url, |
| 630 const base::Callback<void(bool)>& callback) { |
| 631 base::DictionaryValue request_info; |
| 632 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); |
| 633 RequestPermission( |
| 634 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, |
| 635 request_info, |
| 636 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, |
| 637 base::Unretained(this), |
| 638 callback), |
| 639 false /* allowed_by_default */); |
| 640 } |
| 641 |
| 642 void WebViewGuest::OnWebViewFileSystemPermissionResponse( |
| 643 const base::Callback<void(bool)>& callback, |
| 644 bool allow, |
| 645 const std::string& user_input) { |
| 646 callback.Run(!allow || !attached()); |
| 647 } |
| 648 |
| 619 void WebViewGuest::RequestGeolocationPermission( | 649 void WebViewGuest::RequestGeolocationPermission( |
| 620 int bridge_id, | 650 int bridge_id, |
| 621 const GURL& requesting_frame, | 651 const GURL& requesting_frame, |
| 622 bool user_gesture, | 652 bool user_gesture, |
| 623 const base::Callback<void(bool)>& callback) { | 653 const base::Callback<void(bool)>& callback) { |
| 624 base::DictionaryValue request_info; | 654 base::DictionaryValue request_info; |
| 625 request_info.Set(guestview::kUrl, | 655 request_info.Set(guestview::kUrl, |
| 626 base::Value::CreateStringValue(requesting_frame.spec())); | 656 base::Value::CreateStringValue(requesting_frame.spec())); |
| 627 request_info.Set(guestview::kUserGesture, | 657 request_info.Set(guestview::kUserGesture, |
| 628 base::Value::CreateBooleanValue(user_gesture)); | 658 base::Value::CreateBooleanValue(user_gesture)); |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 bool allow, | 1434 bool allow, |
| 1405 const std::string& user_input) { | 1435 const std::string& user_input) { |
| 1406 WebViewGuest* guest = | 1436 WebViewGuest* guest = |
| 1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1437 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1408 if (!guest) | 1438 if (!guest) |
| 1409 return; | 1439 return; |
| 1410 | 1440 |
| 1411 if (!allow) | 1441 if (!allow) |
| 1412 guest->Destroy(); | 1442 guest->Destroy(); |
| 1413 } | 1443 } |
| OLD | NEW |