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/web_view/web_view_internal_api.h" | 12 #include "chrome/browser/extensions/api/web_view/web_view_internal_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/menu_manager.h" | 14 #include "chrome/browser/extensions/menu_manager.h" |
| 16 #include "chrome/browser/extensions/script_executor.h" | 15 #include "chrome/browser/extensions/script_executor.h" |
| 17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 16 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 18 #include "chrome/browser/geolocation/geolocation_permission_context.h" | |
| 19 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | |
| 20 #include "chrome/browser/guest_view/guest_view_constants.h" | 17 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 21 #include "chrome/browser/guest_view/guest_view_manager.h" | 18 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 22 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 19 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| 20 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | |
| 23 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 21 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 24 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" | 22 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.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" |
| (...skipping 25 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 | 356 |
| 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()); |
|
Fady Samuel
2014/07/07 15:01:52
Make AttachWebViewHelpers a non-static method and
Xi Han
2014/07/08 15:59:13
Done.
| |
| 367 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | |
| 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 DispatchEventToEmbedder( |
| 374 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | |
| 490 } | 375 } |
| 491 | 376 |
| 492 void WebViewGuest::EmbedderDestroyed() { | 377 void WebViewGuest::EmbedderDestroyed() { |
| 493 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | 378 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| 494 // reparenting of a <webview> within a single embedder. Right now, we keep | 379 // reparenting of a <webview> within a single embedder. Right now, we keep |
| 495 // around the browser state for the listener for the lifetime of the embedder. | 380 // around the browser state for the listener for the lifetime of the embedder. |
| 496 // Ideally, the lifetime of the listeners should match the lifetime of the | 381 // Ideally, the lifetime of the listeners should match the lifetime of the |
| 497 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move | 382 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
| 498 // the call to RemoveWebViewEventListenersOnIOThread back to | 383 // the call to RemoveWebViewEventListenersOnIOThread back to |
| 499 // WebViewGuest::WebContentsDestroyed. | 384 // WebViewGuest::WebContentsDestroyed. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 int32 level, | 416 int32 level, |
| 532 const base::string16& message, | 417 const base::string16& message, |
| 533 int32 line_no, | 418 int32 line_no, |
| 534 const base::string16& source_id) { | 419 const base::string16& source_id) { |
| 535 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 420 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 536 // Log levels are from base/logging.h: LogSeverity. | 421 // Log levels are from base/logging.h: LogSeverity. |
| 537 args->SetInteger(webview::kLevel, level); | 422 args->SetInteger(webview::kLevel, level); |
| 538 args->SetString(webview::kMessage, message); | 423 args->SetString(webview::kMessage, message); |
| 539 args->SetInteger(webview::kLine, line_no); | 424 args->SetInteger(webview::kLine, line_no); |
| 540 args->SetString(webview::kSourceId, source_id); | 425 args->SetString(webview::kSourceId, source_id); |
| 541 DispatchEvent( | 426 DispatchEventToEmbedder( |
| 542 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); | 427 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); |
| 543 return true; | 428 return true; |
| 544 } | 429 } |
| 545 | 430 |
| 546 void WebViewGuest::CloseContents(WebContents* source) { | 431 void WebViewGuest::CloseContents(WebContents* source) { |
| 547 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 432 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 548 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); | 433 DispatchEventToEmbedder( |
| 434 new GuestViewBase::Event(webview::kEventClose, args.Pass())); | |
| 549 } | 435 } |
| 550 | 436 |
| 551 void WebViewGuest::FindReply(WebContents* source, | 437 void WebViewGuest::FindReply(WebContents* source, |
| 552 int request_id, | 438 int request_id, |
| 553 int number_of_matches, | 439 int number_of_matches, |
| 554 const gfx::Rect& selection_rect, | 440 const gfx::Rect& selection_rect, |
| 555 int active_match_ordinal, | 441 int active_match_ordinal, |
| 556 bool final_update) { | 442 bool final_update) { |
| 557 find_helper_.FindReply(request_id, number_of_matches, selection_rect, | 443 find_helper_.FindReply(request_id, number_of_matches, selection_rect, |
| 558 active_match_ordinal, final_update); | 444 active_match_ordinal, final_update); |
| 559 } | 445 } |
| 560 | 446 |
| 561 bool WebViewGuest::HandleContextMenu( | 447 bool WebViewGuest::HandleContextMenu( |
| 562 const content::ContextMenuParams& params) { | 448 const content::ContextMenuParams& params) { |
| 563 ContextMenuDelegate* menu_delegate = | 449 ContextMenuDelegate* menu_delegate = |
| 564 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 450 ContextMenuDelegate::FromWebContents(guest_web_contents()); |
| 565 DCHECK(menu_delegate); | 451 DCHECK(menu_delegate); |
| 566 | 452 |
| 567 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); | 453 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); |
| 568 | 454 |
| 569 // Pass it to embedder. | 455 // Pass it to embedder. |
| 570 int request_id = ++pending_context_menu_request_id_; | 456 int request_id = ++pending_context_menu_request_id_; |
| 571 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 457 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 572 scoped_ptr<base::ListValue> items = | 458 scoped_ptr<base::ListValue> items = |
| 573 MenuModelToValue(pending_menu_->menu_model()); | 459 MenuModelToValue(pending_menu_->menu_model()); |
| 574 args->Set(webview::kContextMenuItems, items.release()); | 460 args->Set(webview::kContextMenuItems, items.release()); |
| 575 args->SetInteger(webview::kRequestId, request_id); | 461 args->SetInteger(webview::kRequestId, request_id); |
| 576 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, | 462 DispatchEventToEmbedder( |
| 577 args.Pass())); | 463 new GuestViewBase::Event(webview::kEventContextMenu, args.Pass())); |
| 578 return true; | 464 return true; |
| 579 } | 465 } |
| 580 | 466 |
| 581 void WebViewGuest::HandleKeyboardEvent( | 467 void WebViewGuest::HandleKeyboardEvent( |
| 582 WebContents* source, | 468 WebContents* source, |
| 583 const content::NativeWebKeyboardEvent& event) { | 469 const content::NativeWebKeyboardEvent& event) { |
| 584 if (!attached()) | 470 if (!attached()) |
| 585 return; | 471 return; |
| 586 | 472 |
| 587 if (HandleKeyboardShortcuts(event)) | 473 if (HandleKeyboardShortcuts(event)) |
| 588 return; | 474 return; |
| 589 | 475 |
| 590 // Send the unhandled keyboard events back to the embedder to reprocess them. | 476 // Send the unhandled keyboard events back to the embedder to reprocess them. |
| 591 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard | 477 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard |
| 592 // events because the guest may be arbitrarily delayed when responding to | 478 // events because the guest may be arbitrarily delayed when responding to |
| 593 // keyboard events. In that time, the embedder may have received and processed | 479 // keyboard events. In that time, the embedder may have received and processed |
| 594 // additional key events. This needs to be fixed as soon as possible. | 480 // additional key events. This needs to be fixed as soon as possible. |
| 595 // See http://crbug.com/229882. | 481 // See http://crbug.com/229882. |
| 596 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( | 482 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( |
| 597 web_contents(), event); | 483 web_contents(), event); |
| 598 } | 484 } |
| 599 | 485 |
| 600 void WebViewGuest::LoadProgressChanged(content::WebContents* source, | 486 void WebViewGuest::LoadProgressChanged(content::WebContents* source, |
| 601 double progress) { | 487 double progress) { |
| 602 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 488 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 603 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); | 489 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); |
| 604 args->SetDouble(webview::kProgress, progress); | 490 args->SetDouble(webview::kProgress, progress); |
| 605 DispatchEvent( | 491 DispatchEventToEmbedder( |
| 606 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); | 492 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); |
| 607 } | 493 } |
| 608 | 494 |
| 609 void WebViewGuest::LoadAbort(bool is_top_level, | 495 void WebViewGuest::LoadAbort(bool is_top_level, |
| 610 const GURL& url, | 496 const GURL& url, |
| 611 const std::string& error_type) { | 497 const std::string& error_type) { |
| 612 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 498 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 613 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 499 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 614 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); | 500 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
| 615 args->SetString(guestview::kReason, error_type); | 501 args->SetString(guestview::kReason, error_type); |
| 616 DispatchEvent( | 502 DispatchEventToEmbedder( |
| 617 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); | 503 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); |
| 618 } | 504 } |
| 619 | 505 |
| 620 void WebViewGuest::OnUpdateFrameName(bool is_top_level, | 506 void WebViewGuest::OnUpdateFrameName(bool is_top_level, |
| 621 const std::string& name) { | 507 const std::string& name) { |
| 622 if (!is_top_level) | 508 if (!is_top_level) |
| 623 return; | 509 return; |
| 624 | 510 |
| 625 if (name_ == name) | 511 if (name_ == name) |
| 626 return; | 512 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 params.user_gesture, | 551 params.user_gesture, |
| 666 new_guest->guest_web_contents()); | 552 new_guest->guest_web_contents()); |
| 667 } | 553 } |
| 668 | 554 |
| 669 // TODO(fsamuel): Find a reliable way to test the 'responsive' and | 555 // TODO(fsamuel): Find a reliable way to test the 'responsive' and |
| 670 // 'unresponsive' events. | 556 // 'unresponsive' events. |
| 671 void WebViewGuest::RendererResponsive(content::WebContents* source) { | 557 void WebViewGuest::RendererResponsive(content::WebContents* source) { |
| 672 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 558 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 673 args->SetInteger(webview::kProcessId, | 559 args->SetInteger(webview::kProcessId, |
| 674 guest_web_contents()->GetRenderProcessHost()->GetID()); | 560 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 675 DispatchEvent( | 561 DispatchEventToEmbedder( |
| 676 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); | 562 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); |
| 677 } | 563 } |
| 678 | 564 |
| 679 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { | 565 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { |
| 680 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 566 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 681 args->SetInteger(webview::kProcessId, | 567 args->SetInteger(webview::kProcessId, |
| 682 guest_web_contents()->GetRenderProcessHost()->GetID()); | 568 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 683 DispatchEvent( | 569 DispatchEventToEmbedder( |
| 684 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); | 570 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); |
| 685 } | 571 } |
| 686 | 572 |
| 687 void WebViewGuest::Observe(int type, | 573 void WebViewGuest::Observe(int type, |
| 688 const content::NotificationSource& source, | 574 const content::NotificationSource& source, |
| 689 const content::NotificationDetails& details) { | 575 const content::NotificationDetails& details) { |
| 690 switch (type) { | 576 switch (type) { |
| 691 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 577 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
| 692 DCHECK_EQ(content::Source<WebContents>(source).ptr(), | 578 DCHECK_EQ(content::Source<WebContents>(source).ptr(), |
| 693 guest_web_contents()); | 579 guest_web_contents()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 guest_web_contents()->GetController().GoToOffset(relative_index); | 619 guest_web_contents()->GetController().GoToOffset(relative_index); |
| 734 } | 620 } |
| 735 | 621 |
| 736 void WebViewGuest::Reload() { | 622 void WebViewGuest::Reload() { |
| 737 // TODO(fsamuel): Don't check for repost because we don't want to show | 623 // 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 | 624 // Chromium's repost warning. We might want to implement a separate API |
| 739 // for registering a callback if a repost is about to happen. | 625 // for registering a callback if a repost is about to happen. |
| 740 guest_web_contents()->GetController().Reload(false); | 626 guest_web_contents()->GetController().Reload(false); |
| 741 } | 627 } |
| 742 | 628 |
| 743 void WebViewGuest::RequestFileSystemPermission( | |
| 744 const GURL& url, | |
| 745 bool allowed_by_default, | |
| 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) { | |
| 762 callback.Run(allow && attached()); | |
| 763 } | |
| 764 | |
| 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 } | |
| 890 | |
| 891 void WebViewGuest::SetUserAgentOverride( | 629 void WebViewGuest::SetUserAgentOverride( |
| 892 const std::string& user_agent_override) { | 630 const std::string& user_agent_override) { |
| 893 if (!attached()) | 631 if (!attached()) |
| 894 return; | 632 return; |
| 895 is_overriding_user_agent_ = !user_agent_override.empty(); | 633 is_overriding_user_agent_ = !user_agent_override.empty(); |
| 896 if (is_overriding_user_agent_) { | 634 if (is_overriding_user_agent_) { |
| 897 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); | 635 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); |
| 898 } | 636 } |
| 899 guest_web_contents()->SetUserAgentOverride(user_agent_override); | 637 guest_web_contents()->SetUserAgentOverride(user_agent_override); |
| 900 } | 638 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 928 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 666 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 929 GURL(), | 667 GURL(), |
| 930 content::StoragePartition::OriginMatcherFunction(), | 668 content::StoragePartition::OriginMatcherFunction(), |
| 931 remove_since, | 669 remove_since, |
| 932 base::Time::Now(), | 670 base::Time::Now(), |
| 933 callback); | 671 callback); |
| 934 return true; | 672 return true; |
| 935 } | 673 } |
| 936 | 674 |
| 937 // static | 675 // static |
| 938 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, | 676 void WebViewGuest::FileSystemAccessedAsync(int render_process_id, |
|
Fady Samuel
2014/07/07 15:01:52
Keeping this doesn't make sense to me. All it does
Xi Han
2014/07/08 15:59:13
Done.
| |
| 939 int render_frame_id, | 677 int render_frame_id, |
| 940 int request_id, | 678 int request_id, |
| 941 const GURL& url, | 679 const GURL& url, |
| 942 bool blocked_by_policy) { | 680 bool blocked_by_policy) { |
| 943 WebViewGuest* guest = | 681 WebViewPermissionHelper* web_view_permission_helper = |
| 944 WebViewGuest::FromFrameID(render_process_id, render_frame_id); | 682 WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id); |
| 945 DCHECK(guest); | 683 web_view_permission_helper->FileSystemAccessedAsync(render_process_id, |
| 946 guest->RequestFileSystemPermission( | 684 render_frame_id, |
| 947 url, | 685 request_id, |
| 948 !blocked_by_policy, | 686 url, |
| 949 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse, | 687 blocked_by_policy); |
| 950 render_process_id, | |
| 951 render_frame_id, | |
| 952 request_id, | |
| 953 url)); | |
| 954 } | 688 } |
| 955 | 689 |
| 956 // static | 690 // 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, | 691 void WebViewGuest::FileSystemAccessedSync(int render_process_id, |
|
Fady Samuel
2014/07/07 15:01:51
Keeping this doesn't make sense to me. All it does
Xi Han
2014/07/08 15:59:13
Done.
| |
| 975 int render_frame_id, | 692 int render_frame_id, |
| 976 const GURL& url, | 693 const GURL& url, |
| 977 bool blocked_by_policy, | 694 bool blocked_by_policy, |
| 978 IPC::Message* reply_msg) { | 695 IPC::Message* reply_msg) { |
| 979 WebViewGuest* guest = | 696 WebViewPermissionHelper* web_view_permission_helper = |
| 980 WebViewGuest::FromFrameID(render_process_id, render_frame_id); | 697 WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id); |
| 981 DCHECK(guest); | 698 web_view_permission_helper->FileSystemAccessedSync(render_process_id, |
| 982 guest->RequestFileSystemPermission( | 699 render_frame_id, |
| 983 url, | 700 url, |
| 984 !blocked_by_policy, | 701 blocked_by_policy, |
| 985 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse, | 702 reply_msg); |
| 986 render_process_id, | |
| 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 } | 703 } |
| 1008 | 704 |
| 1009 WebViewGuest::~WebViewGuest() { | 705 WebViewGuest::~WebViewGuest() { |
| 1010 } | 706 } |
| 1011 | 707 |
| 1012 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 708 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 1013 content::RenderFrameHost* render_frame_host, | 709 content::RenderFrameHost* render_frame_host, |
| 1014 const GURL& url, | 710 const GURL& url, |
| 1015 content::PageTransition transition_type) { | 711 content::PageTransition transition_type) { |
| 1016 find_helper_.CancelAllFindSessions(); | 712 find_helper_.CancelAllFindSessions(); |
| 1017 | 713 |
| 1018 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 714 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1019 args->SetString(guestview::kUrl, url.spec()); | 715 args->SetString(guestview::kUrl, url.spec()); |
| 1020 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 716 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| 1021 args->SetInteger(webview::kInternalCurrentEntryIndex, | 717 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| 1022 guest_web_contents()->GetController().GetCurrentEntryIndex()); | 718 guest_web_contents()->GetController().GetCurrentEntryIndex()); |
| 1023 args->SetInteger(webview::kInternalEntryCount, | 719 args->SetInteger(webview::kInternalEntryCount, |
| 1024 guest_web_contents()->GetController().GetEntryCount()); | 720 guest_web_contents()->GetController().GetEntryCount()); |
| 1025 args->SetInteger(webview::kInternalProcessId, | 721 args->SetInteger(webview::kInternalProcessId, |
| 1026 guest_web_contents()->GetRenderProcessHost()->GetID()); | 722 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 1027 DispatchEvent( | 723 DispatchEventToEmbedder( |
| 1028 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); | 724 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); |
| 1029 | 725 |
| 1030 // Update the current zoom factor for the new page. | 726 // Update the current zoom factor for the new page. |
| 1031 current_zoom_factor_ = content::ZoomLevelToZoomFactor( | 727 current_zoom_factor_ = content::ZoomLevelToZoomFactor( |
| 1032 content::HostZoomMap::GetZoomLevel(guest_web_contents())); | 728 content::HostZoomMap::GetZoomLevel(guest_web_contents())); |
| 1033 | 729 |
| 1034 if (!render_frame_host->GetParent()) { | 730 if (!render_frame_host->GetParent()) { |
| 1035 chromevox_injected_ = false; | 731 chromevox_injected_ = false; |
| 1036 main_frame_id_ = render_frame_host->GetRoutingID(); | 732 main_frame_id_ = render_frame_host->GetRoutingID(); |
| 1037 } | 733 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1050 } | 746 } |
| 1051 | 747 |
| 1052 void WebViewGuest::DidStartProvisionalLoadForFrame( | 748 void WebViewGuest::DidStartProvisionalLoadForFrame( |
| 1053 content::RenderFrameHost* render_frame_host, | 749 content::RenderFrameHost* render_frame_host, |
| 1054 const GURL& validated_url, | 750 const GURL& validated_url, |
| 1055 bool is_error_page, | 751 bool is_error_page, |
| 1056 bool is_iframe_srcdoc) { | 752 bool is_iframe_srcdoc) { |
| 1057 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 753 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1058 args->SetString(guestview::kUrl, validated_url.spec()); | 754 args->SetString(guestview::kUrl, validated_url.spec()); |
| 1059 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 755 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| 1060 DispatchEvent( | 756 DispatchEventToEmbedder( |
| 1061 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); | 757 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); |
| 1062 } | 758 } |
| 1063 | 759 |
| 1064 void WebViewGuest::DocumentLoadedInFrame( | 760 void WebViewGuest::DocumentLoadedInFrame( |
| 1065 int64 frame_id, | 761 int64 frame_id, |
| 1066 content::RenderViewHost* render_view_host) { | 762 content::RenderViewHost* render_view_host) { |
| 1067 if (frame_id == main_frame_id_) | 763 if (frame_id == main_frame_id_) |
| 1068 InjectChromeVoxIfNeeded(render_view_host); | 764 InjectChromeVoxIfNeeded(render_view_host); |
| 1069 } | 765 } |
| 1070 | 766 |
| 1071 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, | 767 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, |
| 1072 RenderFrameHost* render_frame_host) { | 768 RenderFrameHost* render_frame_host) { |
| 1073 bool handled = true; | 769 bool handled = true; |
| 1074 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) | 770 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) |
| 1075 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) | 771 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 1076 IPC_MESSAGE_UNHANDLED(handled = false) | 772 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1077 IPC_END_MESSAGE_MAP() | 773 IPC_END_MESSAGE_MAP() |
| 1078 return handled; | 774 return handled; |
| 1079 } | 775 } |
| 1080 | 776 |
| 1081 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { | 777 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { |
| 1082 // Cancel all find sessions in progress. | 778 // Cancel all find sessions in progress. |
| 1083 find_helper_.CancelAllFindSessions(); | 779 find_helper_.CancelAllFindSessions(); |
| 1084 | 780 |
| 1085 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 781 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1086 args->SetInteger(webview::kProcessId, | 782 args->SetInteger(webview::kProcessId, |
| 1087 guest_web_contents()->GetRenderProcessHost()->GetID()); | 783 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 1088 args->SetString(webview::kReason, TerminationStatusToString(status)); | 784 args->SetString(webview::kReason, TerminationStatusToString(status)); |
| 1089 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); | 785 DispatchEventToEmbedder( |
| 786 new GuestViewBase::Event(webview::kEventExit, args.Pass())); | |
| 1090 } | 787 } |
| 1091 | 788 |
| 1092 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 789 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
| 1093 if (!attached()) | 790 if (!attached()) |
| 1094 return; | 791 return; |
| 1095 content::NavigationController& controller = | 792 content::NavigationController& controller = |
| 1096 guest_web_contents()->GetController(); | 793 guest_web_contents()->GetController(); |
| 1097 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 794 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
| 1098 if (!entry) | 795 if (!entry) |
| 1099 return; | 796 return; |
| 1100 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 797 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
| 1101 guest_web_contents()->GetController().Reload(false); | 798 guest_web_contents()->GetController().Reload(false); |
| 1102 } | 799 } |
| 1103 | 800 |
| 1104 void WebViewGuest::RenderViewReady() { | 801 void WebViewGuest::RenderViewReady() { |
| 1105 // The guest RenderView should always live in an isolated guest process. | 802 // The guest RenderView should always live in an isolated guest process. |
| 1106 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 803 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
| 1107 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); | 804 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); |
| 1108 } | 805 } |
| 1109 | 806 |
| 1110 void WebViewGuest::ReportFrameNameChange(const std::string& name) { | 807 void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
| 1111 name_ = name; | 808 name_ = name; |
| 1112 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 809 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1113 args->SetString(webview::kName, name); | 810 args->SetString(webview::kName, name); |
| 1114 DispatchEvent( | 811 DispatchEventToEmbedder( |
| 1115 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); | 812 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
| 1116 } | 813 } |
| 1117 | 814 |
| 1118 void WebViewGuest::LoadHandlerCalled() { | 815 void WebViewGuest::LoadHandlerCalled() { |
| 1119 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 816 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1120 DispatchEvent( | 817 DispatchEventToEmbedder( |
| 1121 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); | 818 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); |
| 1122 } | 819 } |
| 1123 | 820 |
| 1124 void WebViewGuest::LoadRedirect(const GURL& old_url, | 821 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 1125 const GURL& new_url, | 822 const GURL& new_url, |
| 1126 bool is_top_level) { | 823 bool is_top_level) { |
| 1127 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 824 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1128 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 825 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 1129 args->SetString(webview::kNewURL, new_url.spec()); | 826 args->SetString(webview::kNewURL, new_url.spec()); |
| 1130 args->SetString(webview::kOldURL, old_url.spec()); | 827 args->SetString(webview::kOldURL, old_url.spec()); |
| 1131 DispatchEvent( | 828 DispatchEventToEmbedder( |
| 1132 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); | 829 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); |
| 1133 } | 830 } |
| 1134 | 831 |
| 1135 void WebViewGuest::PushWebViewStateToIOThread() { | 832 void WebViewGuest::PushWebViewStateToIOThread() { |
| 1136 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 833 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
| 1137 std::string partition_domain; | 834 std::string partition_domain; |
| 1138 std::string partition_id; | 835 std::string partition_id; |
| 1139 bool in_memory; | 836 bool in_memory; |
| 1140 if (!GetGuestPartitionConfigForSite( | 837 if (!GetGuestPartitionConfigForSite( |
| 1141 site_url, &partition_domain, &partition_id, &in_memory)) { | 838 site_url, &partition_domain, &partition_id, &in_memory)) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1183 create_params); | 880 create_params); |
| 1184 } | 881 } |
| 1185 | 882 |
| 1186 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 883 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 1187 const gfx::Size& new_size) { | 884 const gfx::Size& new_size) { |
| 1188 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 885 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1189 args->SetInteger(webview::kOldHeight, old_size.height()); | 886 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 1190 args->SetInteger(webview::kOldWidth, old_size.width()); | 887 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 1191 args->SetInteger(webview::kNewHeight, new_size.height()); | 888 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 1192 args->SetInteger(webview::kNewWidth, new_size.width()); | 889 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 1193 DispatchEvent( | 890 DispatchEventToEmbedder( |
| 1194 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | 891 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
| 1195 } | 892 } |
| 1196 | 893 |
| 1197 void WebViewGuest::RequestMediaAccessPermission( | 894 void WebViewGuest::RequestMediaAccessPermission( |
| 1198 content::WebContents* source, | 895 content::WebContents* source, |
| 1199 const content::MediaStreamRequest& request, | 896 const content::MediaStreamRequest& request, |
| 1200 const content::MediaResponseCallback& callback) { | 897 const content::MediaResponseCallback& callback) { |
| 1201 base::DictionaryValue request_info; | 898 web_view_permission_helper_->RequestMediaAccessPermission(source, |
| 1202 request_info.Set( | 899 request, |
| 1203 guestview::kUrl, | 900 callback); |
| 1204 base::Value::CreateStringValue(request.security_origin.spec())); | |
| 1205 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, | |
| 1206 request_info, | |
| 1207 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, | |
| 1208 base::Unretained(this), | |
| 1209 request, | |
| 1210 callback), | |
| 1211 false /* allowed_by_default */); | |
| 1212 } | 901 } |
| 1213 | 902 |
| 1214 void WebViewGuest::CanDownload( | 903 void WebViewGuest::CanDownload( |
| 1215 content::RenderViewHost* render_view_host, | 904 content::RenderViewHost* render_view_host, |
| 1216 const GURL& url, | 905 const GURL& url, |
| 1217 const std::string& request_method, | 906 const std::string& request_method, |
| 1218 const base::Callback<void(bool)>& callback) { | 907 const base::Callback<void(bool)>& callback) { |
| 1219 base::DictionaryValue request_info; | 908 web_view_permission_helper_->CanDownload(render_view_host, |
| 1220 request_info.Set( | 909 url, |
|
Fady Samuel
2014/07/07 15:01:52
Fix alignment.
Xi Han
2014/07/08 15:59:13
Done.
| |
| 1221 guestview::kUrl, | 910 request_method, |
| 1222 base::Value::CreateStringValue(url.spec())); | 911 callback); |
| 1223 RequestPermission( | |
| 1224 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, | |
| 1225 request_info, | |
| 1226 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, | |
| 1227 base::Unretained(this), | |
| 1228 callback), | |
| 1229 false /* allowed_by_default */); | |
| 1230 } | 912 } |
| 1231 | 913 |
| 1232 void WebViewGuest::RequestPointerLockPermission( | 914 void WebViewGuest::RequestPointerLockPermission( |
| 1233 bool user_gesture, | 915 bool user_gesture, |
| 1234 bool last_unlocked_by_target, | 916 bool last_unlocked_by_target, |
| 1235 const base::Callback<void(bool)>& callback) { | 917 const base::Callback<void(bool)>& callback) { |
| 1236 base::DictionaryValue request_info; | 918 web_view_permission_helper_->RequestPointerLockPermission( |
| 1237 request_info.Set(guestview::kUserGesture, | 919 user_gesture, |
| 1238 base::Value::CreateBooleanValue(user_gesture)); | 920 last_unlocked_by_target, |
| 1239 request_info.Set(webview::kLastUnlockedBySelf, | 921 callback); |
| 1240 base::Value::CreateBooleanValue(last_unlocked_by_target)); | |
| 1241 request_info.Set(guestview::kUrl, | |
| 1242 base::Value::CreateStringValue( | |
| 1243 guest_web_contents()->GetLastCommittedURL().spec())); | |
| 1244 | |
| 1245 RequestPermission( | |
| 1246 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK, | |
| 1247 request_info, | |
| 1248 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse, | |
| 1249 base::Unretained(this), | |
| 1250 callback), | |
| 1251 false /* allowed_by_default */); | |
| 1252 } | 922 } |
| 1253 | 923 |
| 1254 void WebViewGuest::WillAttachToEmbedder() { | 924 void WebViewGuest::WillAttachToEmbedder() { |
| 1255 // We must install the mapping from guests to WebViews prior to resuming | 925 // We must install the mapping from guests to WebViews prior to resuming |
| 1256 // suspended resource loads so that the WebRequest API will catch resource | 926 // suspended resource loads so that the WebRequest API will catch resource |
| 1257 // requests. | 927 // requests. |
| 1258 PushWebViewStateToIOThread(); | 928 PushWebViewStateToIOThread(); |
| 1259 } | 929 } |
| 1260 | 930 |
| 1261 content::JavaScriptDialogManager* | 931 content::JavaScriptDialogManager* |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 chromeos::AccessibilityManager* manager = | 1005 chromeos::AccessibilityManager* manager = |
| 1336 chromeos::AccessibilityManager::Get(); | 1006 chromeos::AccessibilityManager::Get(); |
| 1337 if (manager && manager->IsSpokenFeedbackEnabled()) { | 1007 if (manager && manager->IsSpokenFeedbackEnabled()) { |
| 1338 manager->InjectChromeVox(render_view_host); | 1008 manager->InjectChromeVox(render_view_host); |
| 1339 chromevox_injected_ = true; | 1009 chromevox_injected_ = true; |
| 1340 } | 1010 } |
| 1341 } | 1011 } |
| 1342 #endif | 1012 #endif |
| 1343 } | 1013 } |
| 1344 | 1014 |
| 1345 int WebViewGuest::RemoveBridgeID(int bridge_id) { | |
| 1346 std::map<int, int>::iterator bridge_itr = | |
| 1347 bridge_id_to_request_id_map_.find(bridge_id); | |
| 1348 if (bridge_itr == bridge_id_to_request_id_map_.end()) | |
| 1349 return webview::kInvalidPermissionRequestID; | |
| 1350 | |
| 1351 int request_id = bridge_itr->second; | |
| 1352 bridge_id_to_request_id_map_.erase(bridge_itr); | |
| 1353 return request_id; | |
| 1354 } | |
| 1355 | |
| 1356 int WebViewGuest::RequestPermission( | |
| 1357 WebViewPermissionType permission_type, | |
| 1358 const base::DictionaryValue& request_info, | |
| 1359 const PermissionResponseCallback& callback, | |
| 1360 bool allowed_by_default) { | |
| 1361 // If there are too many pending permission requests then reject this request. | |
| 1362 if (pending_permission_requests_.size() >= | |
| 1363 webview::kMaxOutstandingPermissionRequests) { | |
| 1364 // Let the stack unwind before we deny the permission request so that | |
| 1365 // objects held by the permission request are not destroyed immediately | |
| 1366 // after creation. This is to allow those same objects to be accessed again | |
| 1367 // in the same scope without fear of use after freeing. | |
| 1368 base::MessageLoop::current()->PostTask( | |
| 1369 FROM_HERE, | |
| 1370 base::Bind(&PermissionResponseCallback::Run, | |
| 1371 base::Owned(new PermissionResponseCallback(callback)), | |
| 1372 allowed_by_default, | |
| 1373 std::string())); | |
| 1374 return webview::kInvalidPermissionRequestID; | |
| 1375 } | |
| 1376 | |
| 1377 int request_id = next_permission_request_id_++; | |
| 1378 pending_permission_requests_[request_id] = | |
| 1379 PermissionResponseInfo(callback, permission_type, allowed_by_default); | |
| 1380 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy()); | |
| 1381 args->SetInteger(webview::kRequestId, request_id); | |
| 1382 switch (permission_type) { | |
| 1383 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: { | |
| 1384 DispatchEvent( | |
| 1385 new GuestViewBase::Event(webview::kEventNewWindow, args.Pass())); | |
| 1386 break; | |
| 1387 } | |
| 1388 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: { | |
| 1389 DispatchEvent( | |
| 1390 new GuestViewBase::Event(webview::kEventDialog, args.Pass())); | |
| 1391 break; | |
| 1392 } | |
| 1393 default: { | |
| 1394 args->SetString(webview::kPermission, | |
| 1395 PermissionTypeToString(permission_type)); | |
| 1396 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest, | |
| 1397 args.Pass())); | |
| 1398 break; | |
| 1399 } | |
| 1400 } | |
| 1401 return request_id; | |
| 1402 } | |
| 1403 | |
| 1404 bool WebViewGuest::HandleKeyboardShortcuts( | 1015 bool WebViewGuest::HandleKeyboardShortcuts( |
| 1405 const content::NativeWebKeyboardEvent& event) { | 1016 const content::NativeWebKeyboardEvent& event) { |
| 1406 if (event.type != blink::WebInputEvent::RawKeyDown) | 1017 if (event.type != blink::WebInputEvent::RawKeyDown) |
| 1407 return false; | 1018 return false; |
| 1408 | 1019 |
| 1409 // If the user hits the escape key without any modifiers then unlock the | 1020 // If the user hits the escape key without any modifiers then unlock the |
| 1410 // mouse if necessary. | 1021 // mouse if necessary. |
| 1411 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && | 1022 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && |
| 1412 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { | 1023 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { |
| 1413 return guest_web_contents()->GotResponseToLockMouseRequest(false); | 1024 return guest_web_contents()->GotResponseToLockMouseRequest(false); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1434 | 1045 |
| 1435 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { | 1046 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { |
| 1436 Go(1); | 1047 Go(1); |
| 1437 return true; | 1048 return true; |
| 1438 } | 1049 } |
| 1439 #endif | 1050 #endif |
| 1440 | 1051 |
| 1441 return false; | 1052 return false; |
| 1442 } | 1053 } |
| 1443 | 1054 |
| 1444 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() | |
| 1445 : permission_type(WEB_VIEW_PERMISSION_TYPE_UNKNOWN), | |
| 1446 allowed_by_default(false) { | |
| 1447 } | |
| 1448 | |
| 1449 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( | |
| 1450 const PermissionResponseCallback& callback, | |
| 1451 WebViewPermissionType permission_type, | |
| 1452 bool allowed_by_default) | |
| 1453 : callback(callback), | |
| 1454 permission_type(permission_type), | |
| 1455 allowed_by_default(allowed_by_default) { | |
| 1456 } | |
| 1457 | |
| 1458 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | |
| 1459 } | |
| 1460 | |
| 1461 void WebViewGuest::ShowContextMenu(int request_id, | 1055 void WebViewGuest::ShowContextMenu(int request_id, |
| 1462 const MenuItemVector* items) { | 1056 const MenuItemVector* items) { |
| 1463 if (!pending_menu_.get()) | 1057 if (!pending_menu_.get()) |
| 1464 return; | 1058 return; |
| 1465 | 1059 |
| 1466 // Make sure this was the correct request. | 1060 // Make sure this was the correct request. |
| 1467 if (request_id != pending_context_menu_request_id_) | 1061 if (request_id != pending_context_menu_request_id_) |
| 1468 return; | 1062 return; |
| 1469 | 1063 |
| 1470 // TODO(lazyboy): Implement. | 1064 // TODO(lazyboy): Implement. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1483 Send(new ChromeViewMsg_SetName(routing_id(), name_)); | 1077 Send(new ChromeViewMsg_SetName(routing_id(), name_)); |
| 1484 } | 1078 } |
| 1485 | 1079 |
| 1486 void WebViewGuest::SetZoom(double zoom_factor) { | 1080 void WebViewGuest::SetZoom(double zoom_factor) { |
| 1487 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 1081 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); |
| 1488 content::HostZoomMap::SetZoomLevel(guest_web_contents(), zoom_level); | 1082 content::HostZoomMap::SetZoomLevel(guest_web_contents(), zoom_level); |
| 1489 | 1083 |
| 1490 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1084 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1491 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | 1085 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); |
| 1492 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | 1086 args->SetDouble(webview::kNewZoomFactor, zoom_factor); |
| 1493 DispatchEvent( | 1087 DispatchEventToEmbedder( |
| 1494 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); | 1088 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); |
| 1495 | 1089 |
| 1496 current_zoom_factor_ = zoom_factor; | 1090 current_zoom_factor_ = zoom_factor; |
| 1497 } | 1091 } |
| 1498 | 1092 |
| 1499 void WebViewGuest::AddNewContents(content::WebContents* source, | 1093 void WebViewGuest::AddNewContents(content::WebContents* source, |
| 1500 content::WebContents* new_contents, | 1094 content::WebContents* new_contents, |
| 1501 WindowOpenDisposition disposition, | 1095 WindowOpenDisposition disposition, |
| 1502 const gfx::Rect& initial_pos, | 1096 const gfx::Rect& initial_pos, |
| 1503 bool user_gesture, | 1097 bool user_gesture, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 base::Value::CreateIntegerValue( | 1193 base::Value::CreateIntegerValue( |
| 1600 guest->GetGuestInstanceID())); | 1194 guest->GetGuestInstanceID())); |
| 1601 // We pass in partition info so that window-s created through newwindow | 1195 // We pass in partition info so that window-s created through newwindow |
| 1602 // API can use it to set their partition attribute. | 1196 // API can use it to set their partition attribute. |
| 1603 request_info.Set(webview::kStoragePartitionId, | 1197 request_info.Set(webview::kStoragePartitionId, |
| 1604 base::Value::CreateStringValue(storage_partition_id)); | 1198 base::Value::CreateStringValue(storage_partition_id)); |
| 1605 request_info.Set(webview::kWindowOpenDisposition, | 1199 request_info.Set(webview::kWindowOpenDisposition, |
| 1606 base::Value::CreateStringValue( | 1200 base::Value::CreateStringValue( |
| 1607 WindowOpenDispositionToString(disposition))); | 1201 WindowOpenDispositionToString(disposition))); |
| 1608 | 1202 |
| 1609 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1203 web_view_permission_helper_-> |
| 1610 request_info, | 1204 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| 1611 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1205 request_info, |
| 1612 base::Unretained(this), | 1206 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| 1613 guest->GetGuestInstanceID()), | 1207 base::Unretained(this), |
| 1614 false /* allowed_by_default */); | 1208 guest->GetGuestInstanceID()), |
| 1209 false /* allowed_by_default */); | |
| 1615 } | 1210 } |
| 1616 | 1211 |
| 1617 void WebViewGuest::DestroyUnattachedWindows() { | 1212 void WebViewGuest::DestroyUnattachedWindows() { |
| 1618 // Destroy() reaches in and removes the WebViewGuest from its opener's | 1213 // Destroy() reaches in and removes the WebViewGuest from its opener's |
| 1619 // pending_new_windows_ set. To avoid mutating the set while iterating, we | 1214 // pending_new_windows_ set. To avoid mutating the set while iterating, we |
| 1620 // create a copy of the pending new windows set and iterate over the copy. | 1215 // create a copy of the pending new windows set and iterate over the copy. |
| 1621 PendingWindowMap pending_new_windows(pending_new_windows_); | 1216 PendingWindowMap pending_new_windows(pending_new_windows_); |
| 1622 // Clean up unattached new windows opened by this guest. | 1217 // Clean up unattached new windows opened by this guest. |
| 1623 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); | 1218 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); |
| 1624 it != pending_new_windows.end(); ++it) { | 1219 it != pending_new_windows.end(); ++it) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1646 bool allow, | 1241 bool allow, |
| 1647 const std::string& user_input) { | 1242 const std::string& user_input) { |
| 1648 WebViewGuest* guest = | 1243 WebViewGuest* guest = |
| 1649 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1244 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1650 if (!guest) | 1245 if (!guest) |
| 1651 return; | 1246 return; |
| 1652 | 1247 |
| 1653 if (!allow) | 1248 if (!allow) |
| 1654 guest->Destroy(); | 1249 guest->Destroy(); |
| 1655 } | 1250 } |
| OLD | NEW |