Chromium Code Reviews| 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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
| 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 13 #include "chrome/browser/extensions/api/webview/webview_api.h" | 12 #include "chrome/browser/extensions/api/webview/webview_api.h" |
| 14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 15 #include "chrome/browser/extensions/extension_renderer_state.h" | 14 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 16 #include "chrome/browser/extensions/menu_manager.h" | 15 #include "chrome/browser/extensions/menu_manager.h" |
| 17 #include "chrome/browser/extensions/script_executor.h" | 16 #include "chrome/browser/extensions/script_executor.h" |
| 18 #include "chrome/browser/favicon/favicon_tab_helper.h" | 17 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 19 #include "chrome/browser/geolocation/geolocation_permission_context.h" | |
| 20 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | |
| 21 #include "chrome/browser/guest_view/guest_view_constants.h" | 18 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 22 #include "chrome/browser/guest_view/guest_view_manager.h" | 19 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 23 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 20 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| 21 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | |
| 24 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 22 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 25 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" | 23 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" |
| 26 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 24 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 27 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | 25 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" |
| 28 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
| 29 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
| 30 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/child_process_security_policy.h" | 29 #include "content/public/browser/child_process_security_policy.h" |
| 32 #include "content/public/browser/host_zoom_map.h" | 30 #include "content/public/browser/host_zoom_map.h" |
| 33 #include "content/public/browser/native_web_keyboard_event.h" | 31 #include "content/public/browser/native_web_keyboard_event.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 58 | 56 |
| 59 #if defined(ENABLE_PRINTING) | 57 #if defined(ENABLE_PRINTING) |
| 60 #if defined(ENABLE_FULL_PRINTING) | 58 #if defined(ENABLE_FULL_PRINTING) |
| 61 #include "chrome/browser/printing/print_preview_message_handler.h" | 59 #include "chrome/browser/printing/print_preview_message_handler.h" |
| 62 #include "chrome/browser/printing/print_view_manager.h" | 60 #include "chrome/browser/printing/print_view_manager.h" |
| 63 #else | 61 #else |
| 64 #include "chrome/browser/printing/print_view_manager_basic.h" | 62 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 65 #endif // defined(ENABLE_FULL_PRINTING) | 63 #endif // defined(ENABLE_FULL_PRINTING) |
| 66 #endif // defined(ENABLE_PRINTING) | 64 #endif // defined(ENABLE_PRINTING) |
| 67 | 65 |
| 68 #if defined(ENABLE_PLUGINS) | |
| 69 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" | |
| 70 #endif | |
| 71 | |
| 72 #if defined(OS_CHROMEOS) | 66 #if defined(OS_CHROMEOS) |
| 73 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 67 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 74 #endif | 68 #endif |
| 75 | 69 |
| 76 using base::UserMetricsAction; | 70 using base::UserMetricsAction; |
| 77 using content::RenderFrameHost; | 71 using content::RenderFrameHost; |
| 78 using content::WebContents; | 72 using content::WebContents; |
| 79 | 73 |
| 80 namespace { | 74 namespace { |
| 81 | 75 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 return "killed"; | 107 return "killed"; |
| 114 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 108 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 115 return "crashed"; | 109 return "crashed"; |
| 116 case base::TERMINATION_STATUS_MAX_ENUM: | 110 case base::TERMINATION_STATUS_MAX_ENUM: |
| 117 break; | 111 break; |
| 118 } | 112 } |
| 119 NOTREACHED() << "Unknown Termination Status."; | 113 NOTREACHED() << "Unknown Termination Status."; |
| 120 return "unknown"; | 114 return "unknown"; |
| 121 } | 115 } |
| 122 | 116 |
| 123 static std::string PermissionTypeToString(WebViewPermissionType type) { | |
| 124 switch (type) { | |
| 125 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | |
| 126 return webview::kPermissionTypeDownload; | |
| 127 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
| 128 return webview::kPermissionTypeFileSystem; | |
| 129 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | |
| 130 return webview::kPermissionTypeGeolocation; | |
| 131 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | |
| 132 return webview::kPermissionTypeDialog; | |
| 133 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | |
| 134 return webview::kPermissionTypeLoadPlugin; | |
| 135 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
| 136 return webview::kPermissionTypeMedia; | |
| 137 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | |
| 138 return webview::kPermissionTypeNewWindow; | |
| 139 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | |
| 140 return webview::kPermissionTypePointerLock; | |
| 141 default: | |
| 142 NOTREACHED(); | |
| 143 return std::string(); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { | 117 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { |
| 148 const std::string& partition_id = site_url.query(); | 118 const std::string& partition_id = site_url.query(); |
| 149 bool persist_storage = site_url.path().find("persist") != std::string::npos; | 119 bool persist_storage = site_url.path().find("persist") != std::string::npos; |
| 150 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; | 120 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; |
| 151 } | 121 } |
| 152 | 122 |
| 153 void RemoveWebViewEventListenersOnIOThread( | 123 void RemoveWebViewEventListenersOnIOThread( |
| 154 void* profile, | 124 void* profile, |
| 155 const std::string& extension_id, | 125 const std::string& extension_id, |
| 156 int embedder_process_id, | 126 int embedder_process_id, |
| 157 int view_instance_id) { | 127 int view_instance_id) { |
| 158 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 159 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( | 129 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( |
| 160 profile, | 130 profile, |
| 161 extension_id, | 131 extension_id, |
| 162 embedder_process_id, | 132 embedder_process_id, |
| 163 view_instance_id); | 133 view_instance_id); |
| 164 } | 134 } |
| 165 | 135 |
| 166 void AttachWebViewHelpers(WebContents* contents) { | 136 void AttachWebViewHelpers(WebContents* contents) { |
| 167 FaviconTabHelper::CreateForWebContents(contents); | 137 FaviconTabHelper::CreateForWebContents(contents); |
| 168 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 138 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 169 contents); | 139 contents); |
| 170 #if defined(ENABLE_PLUGINS) | |
| 171 PluginPermissionHelper::CreateForWebContents(contents); | |
| 172 #endif | |
| 173 #if defined(ENABLE_PRINTING) | 140 #if defined(ENABLE_PRINTING) |
| 174 #if defined(ENABLE_FULL_PRINTING) | 141 #if defined(ENABLE_FULL_PRINTING) |
| 175 printing::PrintViewManager::CreateForWebContents(contents); | 142 printing::PrintViewManager::CreateForWebContents(contents); |
| 176 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); | 143 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); |
| 177 #else | 144 #else |
| 178 printing::PrintViewManagerBasic::CreateForWebContents(contents); | 145 printing::PrintViewManagerBasic::CreateForWebContents(contents); |
| 179 #endif // defined(ENABLE_FULL_PRINTING) | 146 #endif // defined(ENABLE_FULL_PRINTING) |
| 180 #endif // defined(ENABLE_PRINTING) | 147 #endif // defined(ENABLE_PRINTING) |
| 181 PDFTabHelper::CreateForWebContents(contents); | 148 PDFTabHelper::CreateForWebContents(contents); |
| 182 } | 149 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 209 *persist_storage = false; | 176 *persist_storage = false; |
| 210 } | 177 } |
| 211 } | 178 } |
| 212 | 179 |
| 213 } // namespace | 180 } // namespace |
| 214 | 181 |
| 215 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, | 182 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, |
| 216 int guest_instance_id) | 183 int guest_instance_id) |
| 217 : GuestView<WebViewGuest>(browser_context, guest_instance_id), | 184 : GuestView<WebViewGuest>(browser_context, guest_instance_id), |
| 218 pending_context_menu_request_id_(0), | 185 pending_context_menu_request_id_(0), |
| 219 next_permission_request_id_(0), | |
| 220 is_overriding_user_agent_(false), | 186 is_overriding_user_agent_(false), |
| 221 main_frame_id_(0), | 187 main_frame_id_(0), |
| 222 chromevox_injected_(false), | 188 chromevox_injected_(false), |
| 223 find_helper_(this), | 189 find_helper_(this), |
| 224 javascript_dialog_helper_(this) { | 190 javascript_dialog_helper_(this) { |
| 225 } | 191 } |
| 226 | 192 |
| 227 // static | 193 // static |
| 228 bool WebViewGuest::GetGuestPartitionConfigForSite( | 194 bool WebViewGuest::GetGuestPartitionConfigForSite( |
| 229 const GURL& site, | 195 const GURL& site, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 253 // static | 219 // static |
| 254 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 220 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 255 WebViewGuest* guest = FromWebContents(contents); | 221 WebViewGuest* guest = FromWebContents(contents); |
| 256 if (!guest) | 222 if (!guest) |
| 257 return guestview::kInstanceIDNone; | 223 return guestview::kInstanceIDNone; |
| 258 | 224 |
| 259 return guest->view_instance_id(); | 225 return guest->view_instance_id(); |
| 260 } | 226 } |
| 261 | 227 |
| 262 // static | 228 // static |
| 263 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, | |
| 264 bool allow) { | |
| 265 if (allow) { | |
| 266 // Note that |allow| == true means the embedder explicitly allowed the | |
| 267 // request. For some requests they might still fail. An example of such | |
| 268 // scenario would be: an embedder allows geolocation request but doesn't | |
| 269 // have geolocation access on its own. | |
| 270 switch (info.permission_type) { | |
| 271 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | |
| 272 content::RecordAction( | |
| 273 UserMetricsAction("WebView.PermissionAllow.Download")); | |
| 274 break; | |
| 275 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
| 276 content::RecordAction( | |
| 277 UserMetricsAction("WebView.PermissionAllow.FileSystem")); | |
| 278 break; | |
| 279 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | |
| 280 content::RecordAction( | |
| 281 UserMetricsAction("WebView.PermissionAllow.Geolocation")); | |
| 282 break; | |
| 283 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | |
| 284 content::RecordAction( | |
| 285 UserMetricsAction("WebView.PermissionAllow.JSDialog")); | |
| 286 break; | |
| 287 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | |
| 288 content::RecordAction( | |
| 289 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); | |
| 290 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
| 291 content::RecordAction( | |
| 292 UserMetricsAction("WebView.PermissionAllow.Media")); | |
| 293 break; | |
| 294 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | |
| 295 content::RecordAction( | |
| 296 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); | |
| 297 break; | |
| 298 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | |
| 299 content::RecordAction( | |
| 300 UserMetricsAction("WebView.PermissionAllow.PointerLock")); | |
| 301 break; | |
| 302 default: | |
| 303 break; | |
| 304 } | |
| 305 } else { | |
| 306 switch (info.permission_type) { | |
| 307 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | |
| 308 content::RecordAction( | |
| 309 UserMetricsAction("WebView.PermissionDeny.Download")); | |
| 310 break; | |
| 311 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM: | |
| 312 content::RecordAction( | |
| 313 UserMetricsAction("WebView.PermissionDeny.FileSystem")); | |
| 314 break; | |
| 315 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: | |
| 316 content::RecordAction( | |
| 317 UserMetricsAction("WebView.PermissionDeny.Geolocation")); | |
| 318 break; | |
| 319 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: | |
| 320 content::RecordAction( | |
| 321 UserMetricsAction("WebView.PermissionDeny.JSDialog")); | |
| 322 break; | |
| 323 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: | |
| 324 content::RecordAction( | |
| 325 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); | |
| 326 break; | |
| 327 case WEB_VIEW_PERMISSION_TYPE_MEDIA: | |
| 328 content::RecordAction( | |
| 329 UserMetricsAction("WebView.PermissionDeny.Media")); | |
| 330 break; | |
| 331 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: | |
| 332 content::RecordAction( | |
| 333 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); | |
| 334 break; | |
| 335 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK: | |
| 336 content::RecordAction( | |
| 337 UserMetricsAction("WebView.PermissionDeny.PointerLock")); | |
| 338 break; | |
| 339 default: | |
| 340 break; | |
| 341 } | |
| 342 } | |
| 343 } | |
| 344 | |
| 345 // static | |
| 346 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( | 229 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( |
| 347 const ui::SimpleMenuModel& menu_model) { | 230 const ui::SimpleMenuModel& menu_model) { |
| 348 scoped_ptr<base::ListValue> items(new base::ListValue()); | 231 scoped_ptr<base::ListValue> items(new base::ListValue()); |
| 349 for (int i = 0; i < menu_model.GetItemCount(); ++i) { | 232 for (int i = 0; i < menu_model.GetItemCount(); ++i) { |
| 350 base::DictionaryValue* item_value = new base::DictionaryValue(); | 233 base::DictionaryValue* item_value = new base::DictionaryValue(); |
| 351 // TODO(lazyboy): We need to expose some kind of enum equivalent of | 234 // TODO(lazyboy): We need to expose some kind of enum equivalent of |
| 352 // |command_id| instead of plain integers. | 235 // |command_id| instead of plain integers. |
| 353 item_value->SetInteger(webview::kMenuItemCommandId, | 236 item_value->SetInteger(webview::kMenuItemCommandId, |
| 354 menu_model.GetCommandIdAt(i)); | 237 menu_model.GetCommandIdAt(i)); |
| 355 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 238 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 #if defined(OS_CHROMEOS) | 357 #if defined(OS_CHROMEOS) |
| 475 chromeos::AccessibilityManager* accessibility_manager = | 358 chromeos::AccessibilityManager* accessibility_manager = |
| 476 chromeos::AccessibilityManager::Get(); | 359 chromeos::AccessibilityManager::Get(); |
| 477 CHECK(accessibility_manager); | 360 CHECK(accessibility_manager); |
| 478 accessibility_subscription_ = accessibility_manager->RegisterCallback( | 361 accessibility_subscription_ = accessibility_manager->RegisterCallback( |
| 479 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, | 362 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, |
| 480 base::Unretained(this))); | 363 base::Unretained(this))); |
| 481 #endif | 364 #endif |
| 482 | 365 |
| 483 AttachWebViewHelpers(guest_web_contents()); | 366 AttachWebViewHelpers(guest_web_contents()); |
| 367 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | |
|
Fady Samuel
2014/06/27 18:46:07
Move this inside AttachWebViewHelpers.
Xi Han
2014/07/03 18:55:58
AttachWebViewHelpers is not a member function of W
| |
| 484 } | 368 } |
| 485 | 369 |
| 486 | 370 |
| 487 void WebViewGuest::DidStopLoading() { | 371 void WebViewGuest::DidStopLoading() { |
| 488 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 372 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 489 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 373 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 490 } | 374 } |
| 491 | 375 |
| 492 void WebViewGuest::EmbedderDestroyed() { | 376 void WebViewGuest::EmbedderDestroyed() { |
| 493 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | 377 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 guest_web_contents()->GetController().GoToOffset(relative_index); | 617 guest_web_contents()->GetController().GoToOffset(relative_index); |
| 734 } | 618 } |
| 735 | 619 |
| 736 void WebViewGuest::Reload() { | 620 void WebViewGuest::Reload() { |
| 737 // TODO(fsamuel): Don't check for repost because we don't want to show | 621 // TODO(fsamuel): Don't check for repost because we don't want to show |
| 738 // Chromium's repost warning. We might want to implement a separate API | 622 // Chromium's repost warning. We might want to implement a separate API |
| 739 // for registering a callback if a repost is about to happen. | 623 // for registering a callback if a repost is about to happen. |
| 740 guest_web_contents()->GetController().Reload(false); | 624 guest_web_contents()->GetController().Reload(false); |
| 741 } | 625 } |
| 742 | 626 |
| 743 void WebViewGuest::RequestFileSystemPermission( | 627 WebViewPermissionHelper::SetPermissionResult WebViewGuest::SetPermission( |
|
Fady Samuel
2014/06/27 18:46:07
Do we need this here at all? What if we remove it?
Xi Han
2014/07/03 18:55:58
Done.
| |
| 744 const GURL& url, | 628 int request_id, |
| 745 bool allowed_by_default, | 629 WebViewPermissionHelper::PermissionResponseAction action, |
| 746 const base::Callback<void(bool)>& callback) { | |
| 747 base::DictionaryValue request_info; | |
| 748 request_info.Set(guestview::kUrl, base::Value::CreateStringValue(url.spec())); | |
| 749 RequestPermission( | |
| 750 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM, | |
| 751 request_info, | |
| 752 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse, | |
| 753 base::Unretained(this), | |
| 754 callback), | |
| 755 allowed_by_default); | |
| 756 } | |
| 757 | |
| 758 void WebViewGuest::OnWebViewFileSystemPermissionResponse( | |
| 759 const base::Callback<void(bool)>& callback, | |
| 760 bool allow, | |
| 761 const std::string& user_input) { | 630 const std::string& user_input) { |
| 762 callback.Run(allow && attached()); | 631 return web_view_permission_helper_->SetPermission(request_id, |
| 763 } | 632 action, |
|
Fady Samuel
2014/06/27 18:46:07
Fix alignment.
Xi Han
2014/07/03 18:55:58
Done.
| |
| 764 | 633 user_input); |
| 765 void WebViewGuest::RequestGeolocationPermission( | |
| 766 int bridge_id, | |
| 767 const GURL& requesting_frame, | |
| 768 bool user_gesture, | |
| 769 const base::Callback<void(bool)>& callback) { | |
| 770 base::DictionaryValue request_info; | |
| 771 request_info.Set(guestview::kUrl, | |
| 772 base::Value::CreateStringValue(requesting_frame.spec())); | |
| 773 request_info.Set(guestview::kUserGesture, | |
| 774 base::Value::CreateBooleanValue(user_gesture)); | |
| 775 | |
| 776 // It is safe to hold an unretained pointer to WebViewGuest because this | |
| 777 // callback is called from WebViewGuest::SetPermission. | |
| 778 const PermissionResponseCallback permission_callback = | |
| 779 base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse, | |
| 780 base::Unretained(this), | |
| 781 bridge_id, | |
| 782 user_gesture, | |
| 783 callback); | |
| 784 int request_id = RequestPermission( | |
| 785 WEB_VIEW_PERMISSION_TYPE_GEOLOCATION, | |
| 786 request_info, | |
| 787 permission_callback, | |
| 788 false /* allowed_by_default */); | |
| 789 bridge_id_to_request_id_map_[bridge_id] = request_id; | |
| 790 } | |
| 791 | |
| 792 void WebViewGuest::OnWebViewGeolocationPermissionResponse( | |
| 793 int bridge_id, | |
| 794 bool user_gesture, | |
| 795 const base::Callback<void(bool)>& callback, | |
| 796 bool allow, | |
| 797 const std::string& user_input) { | |
| 798 // The <webview> embedder has allowed the permission. We now need to make sure | |
| 799 // that the embedder has geolocation permission. | |
| 800 RemoveBridgeID(bridge_id); | |
| 801 | |
| 802 if (!allow || !attached()) { | |
| 803 callback.Run(false); | |
| 804 return; | |
| 805 } | |
| 806 | |
| 807 Profile* profile = Profile::FromBrowserContext(browser_context()); | |
| 808 GeolocationPermissionContextFactory::GetForProfile(profile)-> | |
| 809 RequestGeolocationPermission( | |
| 810 embedder_web_contents(), | |
| 811 // The geolocation permission request here is not initiated | |
| 812 // through WebGeolocationPermissionRequest. We are only interested | |
| 813 // in the fact whether the embedder/app has geolocation | |
| 814 // permission. Therefore we use an invalid |bridge_id|. | |
| 815 -1, | |
| 816 embedder_web_contents()->GetLastCommittedURL(), | |
| 817 user_gesture, | |
| 818 callback, | |
| 819 NULL); | |
| 820 } | |
| 821 | |
| 822 void WebViewGuest::CancelGeolocationPermissionRequest(int bridge_id) { | |
| 823 int request_id = RemoveBridgeID(bridge_id); | |
| 824 RequestMap::iterator request_itr = | |
| 825 pending_permission_requests_.find(request_id); | |
| 826 | |
| 827 if (request_itr == pending_permission_requests_.end()) | |
| 828 return; | |
| 829 | |
| 830 pending_permission_requests_.erase(request_itr); | |
| 831 } | |
| 832 | |
| 833 void WebViewGuest::OnWebViewMediaPermissionResponse( | |
| 834 const content::MediaStreamRequest& request, | |
| 835 const content::MediaResponseCallback& callback, | |
| 836 bool allow, | |
| 837 const std::string& user_input) { | |
| 838 if (!allow || !attached()) { | |
| 839 // Deny the request. | |
| 840 callback.Run(content::MediaStreamDevices(), | |
| 841 content::MEDIA_DEVICE_INVALID_STATE, | |
| 842 scoped_ptr<content::MediaStreamUI>()); | |
| 843 return; | |
| 844 } | |
| 845 if (!embedder_web_contents()->GetDelegate()) | |
| 846 return; | |
| 847 | |
| 848 embedder_web_contents()->GetDelegate()-> | |
| 849 RequestMediaAccessPermission(embedder_web_contents(), request, callback); | |
| 850 } | |
| 851 | |
| 852 void WebViewGuest::OnWebViewDownloadPermissionResponse( | |
| 853 const base::Callback<void(bool)>& callback, | |
| 854 bool allow, | |
| 855 const std::string& user_input) { | |
| 856 callback.Run(allow && attached()); | |
| 857 } | |
| 858 | |
| 859 void WebViewGuest::OnWebViewPointerLockPermissionResponse( | |
| 860 const base::Callback<void(bool)>& callback, | |
| 861 bool allow, | |
| 862 const std::string& user_input) { | |
| 863 callback.Run(allow && attached()); | |
| 864 } | |
| 865 | |
| 866 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( | |
| 867 int request_id, | |
| 868 PermissionResponseAction action, | |
| 869 const std::string& user_input) { | |
| 870 RequestMap::iterator request_itr = | |
| 871 pending_permission_requests_.find(request_id); | |
| 872 | |
| 873 if (request_itr == pending_permission_requests_.end()) | |
| 874 return SET_PERMISSION_INVALID; | |
| 875 | |
| 876 const PermissionResponseInfo& info = request_itr->second; | |
| 877 bool allow = (action == ALLOW) || | |
| 878 ((action == DEFAULT) && info.allowed_by_default); | |
| 879 | |
| 880 info.callback.Run(allow, user_input); | |
| 881 | |
| 882 // Only record user initiated (i.e. non-default) actions. | |
| 883 if (action != DEFAULT) | |
| 884 RecordUserInitiatedUMA(info, allow); | |
| 885 | |
| 886 pending_permission_requests_.erase(request_itr); | |
| 887 | |
| 888 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED; | |
| 889 } | 634 } |
| 890 | 635 |
| 891 void WebViewGuest::SetUserAgentOverride( | 636 void WebViewGuest::SetUserAgentOverride( |
| 892 const std::string& user_agent_override) { | 637 const std::string& user_agent_override) { |
| 893 if (!attached()) | 638 if (!attached()) |
| 894 return; | 639 return; |
| 895 is_overriding_user_agent_ = !user_agent_override.empty(); | 640 is_overriding_user_agent_ = !user_agent_override.empty(); |
| 896 if (is_overriding_user_agent_) { | 641 if (is_overriding_user_agent_) { |
| 897 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); | 642 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); |
| 898 } | 643 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 928 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 673 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 929 GURL(), | 674 GURL(), |
| 930 content::StoragePartition::OriginMatcherFunction(), | 675 content::StoragePartition::OriginMatcherFunction(), |
| 931 remove_since, | 676 remove_since, |
| 932 base::Time::Now(), | 677 base::Time::Now(), |
| 933 callback); | 678 callback); |
| 934 return true; | 679 return true; |
| 935 } | 680 } |
| 936 | 681 |
| 937 // static | 682 // static |
| 938 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, | 683 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, |
|
Fady Samuel
2014/06/27 18:46:07
Do we need this at all? What if we simply move it
Xi Han
2014/07/03 18:55:58
I would like to keep this static function defined
| |
| 939 int render_frame_id, | 684 int render_frame_id, |
| 940 int request_id, | 685 int request_id, |
| 941 const GURL& url, | 686 const GURL& url, |
| 942 bool blocked_by_policy) { | 687 bool blocked_by_policy) { |
| 943 WebViewGuest* guest = | 688 WebViewPermissionHelper* web_view_permission_helper = |
| 944 WebViewGuest::FromFrameID(render_process_id, render_frame_id); | 689 WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id); |
| 945 DCHECK(guest); | 690 DCHECK(web_view_permission_helper); |
|
Fady Samuel
2014/06/27 18:46:07
This DCHECK is not necessary. It'll crash on the n
Xi Han
2014/07/03 18:55:58
Done.
| |
| 946 guest->RequestFileSystemPermission( | 691 web_view_permission_helper->FileSystemAccessedAsync(render_process_id, |
| 947 url, | 692 render_frame_id, |
| 948 !blocked_by_policy, | 693 request_id, |
| 949 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse, | 694 url, |
| 950 render_process_id, | 695 blocked_by_policy); |
| 951 render_frame_id, | |
| 952 request_id, | |
| 953 url)); | |
| 954 } | 696 } |
| 955 | 697 |
| 956 // static | 698 // static |
| 957 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id, | |
| 958 int render_frame_id, | |
| 959 int request_id, | |
| 960 const GURL& url, | |
| 961 bool allowed) { | |
| 962 TabSpecificContentSettings::FileSystemAccessed( | |
| 963 render_process_id, render_frame_id, url, !allowed); | |
| 964 content::RenderFrameHost* render_frame_host = | |
| 965 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
| 966 if (!render_frame_host) | |
| 967 return; | |
| 968 render_frame_host->Send( | |
| 969 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( | |
| 970 render_frame_id, request_id, allowed)); | |
| 971 } | |
| 972 | |
| 973 // static | |
| 974 void WebViewGuest::FileSystemAccessedSync(int render_process_id, | 699 void WebViewGuest::FileSystemAccessedSync(int render_process_id, |
|
Fady Samuel
2014/06/27 18:46:07
Do we need this here at all?
Xi Han
2014/07/03 18:55:58
Same as above.
| |
| 975 int render_frame_id, | 700 int render_frame_id, |
| 976 const GURL& url, | 701 const GURL& url, |
| 977 bool blocked_by_policy, | 702 bool blocked_by_policy, |
| 978 IPC::Message* reply_msg) { | 703 IPC::Message* reply_msg) { |
| 979 WebViewGuest* guest = | 704 WebViewPermissionHelper* web_view_permission_helper = |
| 980 WebViewGuest::FromFrameID(render_process_id, render_frame_id); | 705 WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id); |
| 981 DCHECK(guest); | 706 DCHECK(web_view_permission_helper); |
|
Fady Samuel
2014/06/27 18:46:07
This DCHECK isn't necessary.
Xi Han
2014/07/03 18:55:58
Done.
| |
| 982 guest->RequestFileSystemPermission( | 707 web_view_permission_helper->FileSystemAccessedSync(render_process_id, |
| 983 url, | 708 render_frame_id, |
| 984 !blocked_by_policy, | 709 url, |
| 985 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse, | 710 blocked_by_policy, |
| 986 render_process_id, | 711 reply_msg); |
| 987 render_frame_id, | |
| 988 url, | |
| 989 reply_msg)); | |
| 990 } | |
| 991 | |
| 992 // static | |
| 993 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id, | |
| 994 int render_frame_id, | |
| 995 const GURL& url, | |
| 996 IPC::Message* reply_msg, | |
| 997 bool allowed) { | |
| 998 TabSpecificContentSettings::FileSystemAccessed( | |
| 999 render_process_id, render_frame_id, url, !allowed); | |
| 1000 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, | |
| 1001 allowed); | |
| 1002 content::RenderFrameHost* render_frame_host = | |
| 1003 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
| 1004 if (!render_frame_id) | |
| 1005 return; | |
| 1006 render_frame_host->Send(reply_msg); | |
| 1007 } | 712 } |
| 1008 | 713 |
| 1009 WebViewGuest::~WebViewGuest() { | 714 WebViewGuest::~WebViewGuest() { |
| 1010 } | 715 } |
| 1011 | 716 |
| 1012 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 717 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 1013 int64 frame_id, | 718 int64 frame_id, |
| 1014 const base::string16& frame_unique_name, | 719 const base::string16& frame_unique_name, |
| 1015 bool is_main_frame, | 720 bool is_main_frame, |
| 1016 const GURL& url, | 721 const GURL& url, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1200 args->SetInteger(webview::kNewHeight, new_size.height()); | 905 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 1201 args->SetInteger(webview::kNewWidth, new_size.width()); | 906 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 1202 DispatchEvent( | 907 DispatchEvent( |
| 1203 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | 908 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
| 1204 } | 909 } |
| 1205 | 910 |
| 1206 void WebViewGuest::RequestMediaAccessPermission( | 911 void WebViewGuest::RequestMediaAccessPermission( |
| 1207 content::WebContents* source, | 912 content::WebContents* source, |
| 1208 const content::MediaStreamRequest& request, | 913 const content::MediaStreamRequest& request, |
| 1209 const content::MediaResponseCallback& callback) { | 914 const content::MediaResponseCallback& callback) { |
| 1210 base::DictionaryValue request_info; | 915 web_view_permission_helper_->RequestMediaAccessPermission(source, |
| 1211 request_info.Set( | 916 request, |
|
Fady Samuel
2014/06/27 18:46:07
alignment.
Xi Han
2014/07/03 18:55:58
Done.
| |
| 1212 guestview::kUrl, | 917 callback); |
| 1213 base::Value::CreateStringValue(request.security_origin.spec())); | |
| 1214 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, | |
| 1215 request_info, | |
| 1216 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, | |
| 1217 base::Unretained(this), | |
| 1218 request, | |
| 1219 callback), | |
| 1220 false /* allowed_by_default */); | |
| 1221 } | 918 } |
| 1222 | 919 |
| 1223 void WebViewGuest::CanDownload( | 920 void WebViewGuest::CanDownload( |
| 1224 content::RenderViewHost* render_view_host, | 921 content::RenderViewHost* render_view_host, |
| 1225 const GURL& url, | 922 const GURL& url, |
| 1226 const std::string& request_method, | 923 const std::string& request_method, |
| 1227 const base::Callback<void(bool)>& callback) { | 924 const base::Callback<void(bool)>& callback) { |
| 1228 base::DictionaryValue request_info; | 925 web_view_permission_helper_->CanDownload(render_view_host, |
| 1229 request_info.Set( | 926 url, |
| 1230 guestview::kUrl, | 927 request_method, |
| 1231 base::Value::CreateStringValue(url.spec())); | 928 callback); |
| 1232 RequestPermission( | |
| 1233 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, | |
| 1234 request_info, | |
| 1235 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, | |
| 1236 base::Unretained(this), | |
| 1237 callback), | |
| 1238 false /* allowed_by_default */); | |
| 1239 } | 929 } |
| 1240 | 930 |
| 1241 void WebViewGuest::RequestPointerLockPermission( | 931 void WebViewGuest::RequestPointerLockPermission( |
| 1242 bool user_gesture, | 932 bool user_gesture, |
| 1243 bool last_unlocked_by_target, | 933 bool last_unlocked_by_target, |
| 1244 const base::Callback<void(bool)>& callback) { | 934 const base::Callback<void(bool)>& callback) { |
| 1245 base::DictionaryValue request_info; | 935 web_view_permission_helper_->RequestPointerLockPermission( |
| 1246 request_info.Set(guestview::kUserGesture, | 936 user_gesture, |
| 1247 base::Value::CreateBooleanValue(user_gesture)); | 937 last_unlocked_by_target, |
| 1248 request_info.Set(webview::kLastUnlockedBySelf, | 938 callback); |
| 1249 base::Value::CreateBooleanValue(last_unlocked_by_target)); | |
| 1250 request_info.Set(guestview::kUrl, | |
| 1251 base::Value::CreateStringValue( | |
| 1252 guest_web_contents()->GetLastCommittedURL().spec())); | |
| 1253 | |
| 1254 RequestPermission( | |
| 1255 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK, | |
| 1256 request_info, | |
| 1257 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse, | |
| 1258 base::Unretained(this), | |
| 1259 callback), | |
| 1260 false /* allowed_by_default */); | |
| 1261 } | 939 } |
| 1262 | 940 |
| 1263 void WebViewGuest::WillAttachToEmbedder() { | 941 void WebViewGuest::WillAttachToEmbedder() { |
| 1264 // We must install the mapping from guests to WebViews prior to resuming | 942 // We must install the mapping from guests to WebViews prior to resuming |
| 1265 // suspended resource loads so that the WebRequest API will catch resource | 943 // suspended resource loads so that the WebRequest API will catch resource |
| 1266 // requests. | 944 // requests. |
| 1267 AddWebViewToExtensionRendererState(); | 945 AddWebViewToExtensionRendererState(); |
| 1268 } | 946 } |
| 1269 | 947 |
| 1270 content::JavaScriptDialogManager* | 948 content::JavaScriptDialogManager* |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1344 chromeos::AccessibilityManager* manager = | 1022 chromeos::AccessibilityManager* manager = |
| 1345 chromeos::AccessibilityManager::Get(); | 1023 chromeos::AccessibilityManager::Get(); |
| 1346 if (manager && manager->IsSpokenFeedbackEnabled()) { | 1024 if (manager && manager->IsSpokenFeedbackEnabled()) { |
| 1347 manager->InjectChromeVox(render_view_host); | 1025 manager->InjectChromeVox(render_view_host); |
| 1348 chromevox_injected_ = true; | 1026 chromevox_injected_ = true; |
| 1349 } | 1027 } |
| 1350 } | 1028 } |
| 1351 #endif | 1029 #endif |
| 1352 } | 1030 } |
| 1353 | 1031 |
| 1354 int WebViewGuest::RemoveBridgeID(int bridge_id) { | |
| 1355 std::map<int, int>::iterator bridge_itr = | |
| 1356 bridge_id_to_request_id_map_.find(bridge_id); | |
| 1357 if (bridge_itr == bridge_id_to_request_id_map_.end()) | |
| 1358 return webview::kInvalidPermissionRequestID; | |
| 1359 | |
| 1360 int request_id = bridge_itr->second; | |
| 1361 bridge_id_to_request_id_map_.erase(bridge_itr); | |
| 1362 return request_id; | |
| 1363 } | |
| 1364 | |
| 1365 int WebViewGuest::RequestPermission( | |
| 1366 WebViewPermissionType permission_type, | |
| 1367 const base::DictionaryValue& request_info, | |
| 1368 const PermissionResponseCallback& callback, | |
| 1369 bool allowed_by_default) { | |
| 1370 // If there are too many pending permission requests then reject this request. | |
| 1371 if (pending_permission_requests_.size() >= | |
| 1372 webview::kMaxOutstandingPermissionRequests) { | |
| 1373 // Let the stack unwind before we deny the permission request so that | |
| 1374 // objects held by the permission request are not destroyed immediately | |
| 1375 // after creation. This is to allow those same objects to be accessed again | |
| 1376 // in the same scope without fear of use after freeing. | |
| 1377 base::MessageLoop::current()->PostTask( | |
| 1378 FROM_HERE, | |
| 1379 base::Bind(&PermissionResponseCallback::Run, | |
| 1380 base::Owned(new PermissionResponseCallback(callback)), | |
| 1381 allowed_by_default, | |
| 1382 std::string())); | |
| 1383 return webview::kInvalidPermissionRequestID; | |
| 1384 } | |
| 1385 | |
| 1386 int request_id = next_permission_request_id_++; | |
| 1387 pending_permission_requests_[request_id] = | |
| 1388 PermissionResponseInfo(callback, permission_type, allowed_by_default); | |
| 1389 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); | |
| 1390 args->SetInteger(webview::kRequestId, request_id); | |
| 1391 switch (permission_type) { | |
| 1392 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: { | |
| 1393 DispatchEvent( | |
| 1394 new GuestViewBase::Event(webview::kEventNewWindow, args.Pass())); | |
| 1395 break; | |
| 1396 } | |
| 1397 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { | |
| 1398 DispatchEvent( | |
| 1399 new GuestViewBase::Event(webview::kEventDialog, args.Pass())); | |
| 1400 break; | |
| 1401 } | |
| 1402 default: { | |
| 1403 args->SetString(webview::kPermission, | |
| 1404 PermissionTypeToString(permission_type)); | |
| 1405 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest, | |
| 1406 args.Pass())); | |
| 1407 break; | |
| 1408 } | |
| 1409 } | |
| 1410 return request_id; | |
| 1411 } | |
| 1412 | |
| 1413 bool WebViewGuest::HandleKeyboardShortcuts( | 1032 bool WebViewGuest::HandleKeyboardShortcuts( |
| 1414 const content::NativeWebKeyboardEvent& event) { | 1033 const content::NativeWebKeyboardEvent& event) { |
| 1415 if (event.type != blink::WebInputEvent::RawKeyDown) | 1034 if (event.type != blink::WebInputEvent::RawKeyDown) |
| 1416 return false; | 1035 return false; |
| 1417 | 1036 |
| 1418 // If the user hits the escape key without any modifiers then unlock the | 1037 // If the user hits the escape key without any modifiers then unlock the |
| 1419 // mouse if necessary. | 1038 // mouse if necessary. |
| 1420 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && | 1039 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && |
| 1421 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { | 1040 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { |
| 1422 return guest_web_contents()->GotResponseToLockMouseRequest(false); | 1041 return guest_web_contents()->GotResponseToLockMouseRequest(false); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1443 | 1062 |
| 1444 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { | 1063 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { |
| 1445 Go(1); | 1064 Go(1); |
| 1446 return true; | 1065 return true; |
| 1447 } | 1066 } |
| 1448 #endif | 1067 #endif |
| 1449 | 1068 |
| 1450 return false; | 1069 return false; |
| 1451 } | 1070 } |
| 1452 | 1071 |
| 1453 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() | |
| 1454 : permission_type(WEB_VIEW_PERMISSION_TYPE_UNKNOWN), | |
| 1455 allowed_by_default(false) { | |
| 1456 } | |
| 1457 | |
| 1458 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( | |
| 1459 const PermissionResponseCallback& callback, | |
| 1460 WebViewPermissionType permission_type, | |
| 1461 bool allowed_by_default) | |
| 1462 : callback(callback), | |
| 1463 permission_type(permission_type), | |
| 1464 allowed_by_default(allowed_by_default) { | |
| 1465 } | |
| 1466 | |
| 1467 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | |
| 1468 } | |
| 1469 | |
| 1470 void WebViewGuest::ShowContextMenu(int request_id, | 1072 void WebViewGuest::ShowContextMenu(int request_id, |
| 1471 const MenuItemVector* items) { | 1073 const MenuItemVector* items) { |
| 1472 if (!pending_menu_.get()) | 1074 if (!pending_menu_.get()) |
| 1473 return; | 1075 return; |
| 1474 | 1076 |
| 1475 // Make sure this was the correct request. | 1077 // Make sure this was the correct request. |
| 1476 if (request_id != pending_context_menu_request_id_) | 1078 if (request_id != pending_context_menu_request_id_) |
| 1477 return; | 1079 return; |
| 1478 | 1080 |
| 1479 // TODO(lazyboy): Implement. | 1081 // TODO(lazyboy): Implement. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1608 base::Value::CreateIntegerValue( | 1210 base::Value::CreateIntegerValue( |
| 1609 guest->GetGuestInstanceID())); | 1211 guest->GetGuestInstanceID())); |
| 1610 // We pass in partition info so that window-s created through newwindow | 1212 // We pass in partition info so that window-s created through newwindow |
| 1611 // API can use it to set their partition attribute. | 1213 // API can use it to set their partition attribute. |
| 1612 request_info.Set(webview::kStoragePartitionId, | 1214 request_info.Set(webview::kStoragePartitionId, |
| 1613 base::Value::CreateStringValue(storage_partition_id)); | 1215 base::Value::CreateStringValue(storage_partition_id)); |
| 1614 request_info.Set(webview::kWindowOpenDisposition, | 1216 request_info.Set(webview::kWindowOpenDisposition, |
| 1615 base::Value::CreateStringValue( | 1217 base::Value::CreateStringValue( |
| 1616 WindowOpenDispositionToString(disposition))); | 1218 WindowOpenDispositionToString(disposition))); |
| 1617 | 1219 |
| 1618 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1220 web_view_permission_helper_-> |
| 1619 request_info, | 1221 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| 1620 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1222 request_info, |
| 1621 base::Unretained(this), | 1223 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| 1622 guest->GetGuestInstanceID()), | 1224 base::Unretained(this), |
| 1623 false /* allowed_by_default */); | 1225 guest->GetGuestInstanceID()), |
| 1226 false /* allowed_by_default */); | |
| 1624 } | 1227 } |
| 1625 | 1228 |
| 1626 void WebViewGuest::DestroyUnattachedWindows() { | 1229 void WebViewGuest::DestroyUnattachedWindows() { |
| 1627 // Destroy() reaches in and removes the WebViewGuest from its opener's | 1230 // Destroy() reaches in and removes the WebViewGuest from its opener's |
| 1628 // pending_new_windows_ set. To avoid mutating the set while iterating, we | 1231 // pending_new_windows_ set. To avoid mutating the set while iterating, we |
| 1629 // create a copy of the pending new windows set and iterate over the copy. | 1232 // create a copy of the pending new windows set and iterate over the copy. |
| 1630 PendingWindowMap pending_new_windows(pending_new_windows_); | 1233 PendingWindowMap pending_new_windows(pending_new_windows_); |
| 1631 // Clean up unattached new windows opened by this guest. | 1234 // Clean up unattached new windows opened by this guest. |
| 1632 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); | 1235 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); |
| 1633 it != pending_new_windows.end(); ++it) { | 1236 it != pending_new_windows.end(); ++it) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1655 bool allow, | 1258 bool allow, |
| 1656 const std::string& user_input) { | 1259 const std::string& user_input) { |
| 1657 WebViewGuest* guest = | 1260 WebViewGuest* guest = |
| 1658 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1261 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1659 if (!guest) | 1262 if (!guest) |
| 1660 return; | 1263 return; |
| 1661 | 1264 |
| 1662 if (!allow) | 1265 if (!allow) |
| 1663 guest->Destroy(); | 1266 guest->Destroy(); |
| 1664 } | 1267 } |
| OLD | NEW |