| 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" | |
| 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 12 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" | 11 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" |
| 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 12 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h" |
| 14 #include "chrome/browser/extensions/menu_manager.h" | |
| 15 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
| 16 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 13 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| 17 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" | 14 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" |
| 18 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 19 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" | 16 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" |
| 20 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | |
| 21 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" | |
| 22 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
| 23 #include "chrome/common/chrome_version_info.h" | |
| 24 #include "chrome/common/render_messages.h" | |
| 25 #include "components/renderer_context_menu/context_menu_delegate.h" | |
| 26 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/child_process_security_policy.h" | 18 #include "content/public/browser/child_process_security_policy.h" |
| 28 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
| 29 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 30 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 31 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 34 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 #include "extensions/browser/guest_view/guest_view_constants.h" | 39 #include "extensions/browser/guest_view/guest_view_constants.h" |
| 49 #include "extensions/browser/guest_view/guest_view_manager.h" | 40 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 50 #include "extensions/common/constants.h" | 41 #include "extensions/common/constants.h" |
| 51 #include "extensions/common/extension_messages.h" | 42 #include "extensions/common/extension_messages.h" |
| 52 #include "ipc/ipc_message_macros.h" | 43 #include "ipc/ipc_message_macros.h" |
| 53 #include "net/base/escape.h" | 44 #include "net/base/escape.h" |
| 54 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 55 #include "third_party/WebKit/public/web/WebFindOptions.h" | 46 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 56 #include "ui/base/models/simple_menu_model.h" | 47 #include "ui/base/models/simple_menu_model.h" |
| 57 | 48 |
| 58 #if defined(ENABLE_PRINTING) | |
| 59 #if defined(ENABLE_FULL_PRINTING) | |
| 60 #include "chrome/browser/printing/print_preview_message_handler.h" | |
| 61 #include "chrome/browser/printing/print_view_manager.h" | |
| 62 #else | |
| 63 #include "chrome/browser/printing/print_view_manager_basic.h" | |
| 64 #endif // defined(ENABLE_FULL_PRINTING) | |
| 65 #endif // defined(ENABLE_PRINTING) | |
| 66 | |
| 67 #if defined(OS_CHROMEOS) | |
| 68 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 69 #endif | |
| 70 | |
| 71 using base::UserMetricsAction; | 49 using base::UserMetricsAction; |
| 72 using content::RenderFrameHost; | 50 using content::RenderFrameHost; |
| 73 using content::ResourceType; | 51 using content::ResourceType; |
| 74 using content::WebContents; | 52 using content::WebContents; |
| 75 | 53 |
| 76 namespace extensions { | 54 namespace extensions { |
| 77 | 55 |
| 78 namespace { | 56 namespace { |
| 79 | 57 |
| 80 std::string WindowOpenDispositionToString( | 58 std::string WindowOpenDispositionToString( |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 180 |
| 203 // static | 181 // static |
| 204 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 182 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 205 WebViewGuest* guest = FromWebContents(contents); | 183 WebViewGuest* guest = FromWebContents(contents); |
| 206 if (!guest) | 184 if (!guest) |
| 207 return guestview::kInstanceIDNone; | 185 return guestview::kInstanceIDNone; |
| 208 | 186 |
| 209 return guest->view_instance_id(); | 187 return guest->view_instance_id(); |
| 210 } | 188 } |
| 211 | 189 |
| 212 // static | |
| 213 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( | |
| 214 const ui::SimpleMenuModel& menu_model) { | |
| 215 scoped_ptr<base::ListValue> items(new base::ListValue()); | |
| 216 for (int i = 0; i < menu_model.GetItemCount(); ++i) { | |
| 217 base::DictionaryValue* item_value = new base::DictionaryValue(); | |
| 218 // TODO(lazyboy): We need to expose some kind of enum equivalent of | |
| 219 // |command_id| instead of plain integers. | |
| 220 item_value->SetInteger(webview::kMenuItemCommandId, | |
| 221 menu_model.GetCommandIdAt(i)); | |
| 222 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | |
| 223 items->Append(item_value); | |
| 224 } | |
| 225 return items.Pass(); | |
| 226 } | |
| 227 | |
| 228 const char* WebViewGuest::GetAPINamespace() { | 190 const char* WebViewGuest::GetAPINamespace() { |
| 229 return webview::kAPINamespace; | 191 return webview::kAPINamespace; |
| 230 } | 192 } |
| 231 | 193 |
| 232 void WebViewGuest::CreateWebContents( | 194 void WebViewGuest::CreateWebContents( |
| 233 const std::string& embedder_extension_id, | 195 const std::string& embedder_extension_id, |
| 234 int embedder_render_process_id, | 196 int embedder_render_process_id, |
| 235 const base::DictionaryValue& create_params, | 197 const base::DictionaryValue& create_params, |
| 236 const WebContentsCreatedCallback& callback) { | 198 const WebContentsCreatedCallback& callback) { |
| 237 content::RenderProcessHost* embedder_render_process_host = | 199 content::RenderProcessHost* embedder_render_process_host = |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 new ScriptExecutor(guest_web_contents(), &script_observers_)); | 300 new ScriptExecutor(guest_web_contents(), &script_observers_)); |
| 339 | 301 |
| 340 notification_registrar_.Add( | 302 notification_registrar_.Add( |
| 341 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 303 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 342 content::Source<WebContents>(guest_web_contents())); | 304 content::Source<WebContents>(guest_web_contents())); |
| 343 | 305 |
| 344 notification_registrar_.Add( | 306 notification_registrar_.Add( |
| 345 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 307 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 346 content::Source<WebContents>(guest_web_contents())); | 308 content::Source<WebContents>(guest_web_contents())); |
| 347 | 309 |
| 348 #if defined(OS_CHROMEOS) | 310 web_view_guest_delegate_->OnDidInitialize(); |
| 349 chromeos::AccessibilityManager* accessibility_manager = | |
| 350 chromeos::AccessibilityManager::Get(); | |
| 351 CHECK(accessibility_manager); | |
| 352 accessibility_subscription_ = accessibility_manager->RegisterCallback( | |
| 353 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, | |
| 354 base::Unretained(this))); | |
| 355 #endif | |
| 356 | |
| 357 AttachWebViewHelpers(guest_web_contents()); | 311 AttachWebViewHelpers(guest_web_contents()); |
| 358 } | 312 } |
| 359 | 313 |
| 360 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { | 314 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { |
| 361 // Create a zoom controller for the guest contents give it access to | 315 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); |
| 362 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest. | |
| 363 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser | |
| 364 // context, but we eventually want to isolate the guest contents from zoom | |
| 365 // changes outside the guest (e.g. in the main browser), so we should | |
| 366 // create a separate HostZoomMap for the guest. | |
| 367 ZoomController::CreateForWebContents(contents); | |
| 368 | |
| 369 FaviconTabHelper::CreateForWebContents(contents); | |
| 370 ChromeExtensionWebContentsObserver::CreateForWebContents(contents); | |
| 371 #if defined(ENABLE_PRINTING) | |
| 372 #if defined(ENABLE_FULL_PRINTING) | |
| 373 printing::PrintViewManager::CreateForWebContents(contents); | |
| 374 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); | |
| 375 #else | |
| 376 printing::PrintViewManagerBasic::CreateForWebContents(contents); | |
| 377 #endif // defined(ENABLE_FULL_PRINTING) | |
| 378 #endif // defined(ENABLE_PRINTING) | |
| 379 PDFTabHelper::CreateForWebContents(contents); | |
| 380 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 316 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
| 381 } | 317 } |
| 382 | 318 |
| 383 void WebViewGuest::DidStopLoading() { | 319 void WebViewGuest::DidStopLoading() { |
| 384 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 320 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 385 DispatchEventToEmbedder( | 321 DispatchEventToEmbedder( |
| 386 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 322 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 387 } | 323 } |
| 388 | 324 |
| 389 void WebViewGuest::EmbedderDestroyed() { | 325 void WebViewGuest::EmbedderDestroyed() { |
| 390 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | 326 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| 391 // reparenting of a <webview> within a single embedder. Right now, we keep | 327 // reparenting of a <webview> within a single embedder. Right now, we keep |
| 392 // around the browser state for the listener for the lifetime of the embedder. | 328 // around the browser state for the listener for the lifetime of the embedder. |
| 393 // Ideally, the lifetime of the listeners should match the lifetime of the | 329 // Ideally, the lifetime of the listeners should match the lifetime of the |
| 394 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move | 330 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
| 395 // the call to RemoveWebViewEventListenersOnIOThread back to | 331 // the call to RemoveWebViewEventListenersOnIOThread back to |
| 396 // WebViewGuest::WebContentsDestroyed. | 332 // WebViewGuest::WebContentsDestroyed. |
| 397 content::BrowserThread::PostTask( | 333 content::BrowserThread::PostTask( |
| 398 content::BrowserThread::IO, | 334 content::BrowserThread::IO, |
| 399 FROM_HERE, | 335 FROM_HERE, |
| 400 base::Bind( | 336 base::Bind( |
| 401 &RemoveWebViewEventListenersOnIOThread, | 337 &RemoveWebViewEventListenersOnIOThread, |
| 402 browser_context(), embedder_extension_id(), | 338 browser_context(), embedder_extension_id(), |
| 403 embedder_render_process_id(), | 339 embedder_render_process_id(), |
| 404 view_instance_id())); | 340 view_instance_id())); |
| 405 } | 341 } |
| 406 | 342 |
| 407 void WebViewGuest::GuestDestroyed() { | 343 void WebViewGuest::GuestDestroyed() { |
| 408 // Clean up custom context menu items for this guest. | 344 // Clean up custom context menu items for this guest. |
| 409 MenuManager* menu_manager = MenuManager::Get( | 345 web_view_guest_delegate_->OnGuestDestroyed(); |
| 410 Profile::FromBrowserContext(browser_context())); | |
| 411 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( | |
| 412 embedder_extension_id(), view_instance_id())); | |
| 413 | |
| 414 RemoveWebViewStateFromIOThread(web_contents()); | 346 RemoveWebViewStateFromIOThread(web_contents()); |
| 415 } | 347 } |
| 416 | 348 |
| 417 void WebViewGuest::GuestReady() { | 349 void WebViewGuest::GuestReady() { |
| 418 // The guest RenderView should always live in an isolated guest process. | 350 // The guest RenderView should always live in an isolated guest process. |
| 419 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 351 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
| 420 Send(new ExtensionMsg_SetFrameName( | 352 Send(new ExtensionMsg_SetFrameName( |
| 421 guest_web_contents()->GetRoutingID(), name_)); | 353 guest_web_contents()->GetRoutingID(), name_)); |
| 422 } | 354 } |
| 423 | 355 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 int number_of_matches, | 405 int number_of_matches, |
| 474 const gfx::Rect& selection_rect, | 406 const gfx::Rect& selection_rect, |
| 475 int active_match_ordinal, | 407 int active_match_ordinal, |
| 476 bool final_update) { | 408 bool final_update) { |
| 477 find_helper_.FindReply(request_id, number_of_matches, selection_rect, | 409 find_helper_.FindReply(request_id, number_of_matches, selection_rect, |
| 478 active_match_ordinal, final_update); | 410 active_match_ordinal, final_update); |
| 479 } | 411 } |
| 480 | 412 |
| 481 bool WebViewGuest::HandleContextMenu( | 413 bool WebViewGuest::HandleContextMenu( |
| 482 const content::ContextMenuParams& params) { | 414 const content::ContextMenuParams& params) { |
| 483 ContextMenuDelegate* menu_delegate = | 415 GuestViewBase::Event* event = |
| 484 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 416 web_view_guest_delegate_->OnHandleContextMenu(params); |
| 485 DCHECK(menu_delegate); | 417 DispatchEventToEmbedder(event); |
| 486 | |
| 487 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); | |
| 488 | |
| 489 // Pass it to embedder. | |
| 490 int request_id = ++pending_context_menu_request_id_; | |
| 491 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 492 scoped_ptr<base::ListValue> items = | |
| 493 MenuModelToValue(pending_menu_->menu_model()); | |
| 494 args->Set(webview::kContextMenuItems, items.release()); | |
| 495 args->SetInteger(webview::kRequestId, request_id); | |
| 496 DispatchEventToEmbedder( | |
| 497 new GuestViewBase::Event(webview::kEventContextMenu, args.Pass())); | |
| 498 return true; | 418 return true; |
| 499 } | 419 } |
| 500 | 420 |
| 501 void WebViewGuest::HandleKeyboardEvent( | 421 void WebViewGuest::HandleKeyboardEvent( |
| 502 WebContents* source, | 422 WebContents* source, |
| 503 const content::NativeWebKeyboardEvent& event) { | 423 const content::NativeWebKeyboardEvent& event) { |
| 504 if (!attached()) | 424 if (!attached()) |
| 505 return; | 425 return; |
| 506 | 426 |
| 507 if (HandleKeyboardShortcuts(event)) | 427 if (HandleKeyboardShortcuts(event)) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 is_top_level); | 547 is_top_level); |
| 628 break; | 548 break; |
| 629 } | 549 } |
| 630 default: | 550 default: |
| 631 NOTREACHED() << "Unexpected notification sent."; | 551 NOTREACHED() << "Unexpected notification sent."; |
| 632 break; | 552 break; |
| 633 } | 553 } |
| 634 } | 554 } |
| 635 | 555 |
| 636 double WebViewGuest::GetZoom() { | 556 double WebViewGuest::GetZoom() { |
| 637 return current_zoom_factor_; | 557 return web_view_guest_delegate_->GetZoom(); |
| 638 } | 558 } |
| 639 | 559 |
| 640 void WebViewGuest::Find( | 560 void WebViewGuest::Find( |
| 641 const base::string16& search_text, | 561 const base::string16& search_text, |
| 642 const blink::WebFindOptions& options, | 562 const blink::WebFindOptions& options, |
| 643 scoped_refptr<WebViewInternalFindFunction> find_function) { | 563 scoped_refptr<WebViewInternalFindFunction> find_function) { |
| 644 find_helper_.Find(guest_web_contents(), search_text, options, find_function); | 564 find_helper_.Find(guest_web_contents(), search_text, options, find_function); |
| 645 } | 565 } |
| 646 | 566 |
| 647 void WebViewGuest::StopFinding(content::StopFindAction action) { | 567 void WebViewGuest::StopFinding(content::StopFindAction action) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 content::StoragePartition::OriginMatcherFunction(), | 622 content::StoragePartition::OriginMatcherFunction(), |
| 703 remove_since, | 623 remove_since, |
| 704 base::Time::Now(), | 624 base::Time::Now(), |
| 705 callback); | 625 callback); |
| 706 return true; | 626 return true; |
| 707 } | 627 } |
| 708 | 628 |
| 709 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, | 629 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, |
| 710 int guest_instance_id) | 630 int guest_instance_id) |
| 711 : GuestView<WebViewGuest>(browser_context, guest_instance_id), | 631 : GuestView<WebViewGuest>(browser_context, guest_instance_id), |
| 712 pending_context_menu_request_id_(0), | |
| 713 is_overriding_user_agent_(false), | 632 is_overriding_user_agent_(false), |
| 714 chromevox_injected_(false), | |
| 715 current_zoom_factor_(1.0), | |
| 716 find_helper_(this), | 633 find_helper_(this), |
| 717 javascript_dialog_helper_(this) { | 634 javascript_dialog_helper_(this) { |
| 635 web_view_guest_delegate_.reset(new ChromeWebViewGuestDelegate(this)); |
| 718 } | 636 } |
| 719 | 637 |
| 720 WebViewGuest::~WebViewGuest() { | 638 WebViewGuest::~WebViewGuest() { |
| 721 } | 639 } |
| 722 | 640 |
| 723 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 641 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 724 content::RenderFrameHost* render_frame_host, | 642 content::RenderFrameHost* render_frame_host, |
| 725 const GURL& url, | 643 const GURL& url, |
| 726 content::PageTransition transition_type) { | 644 content::PageTransition transition_type) { |
| 727 find_helper_.CancelAllFindSessions(); | 645 find_helper_.CancelAllFindSessions(); |
| 728 | 646 |
| 729 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 647 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 730 args->SetString(guestview::kUrl, url.spec()); | 648 args->SetString(guestview::kUrl, url.spec()); |
| 731 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 649 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| 732 args->SetInteger(webview::kInternalCurrentEntryIndex, | 650 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| 733 guest_web_contents()->GetController().GetCurrentEntryIndex()); | 651 guest_web_contents()->GetController().GetCurrentEntryIndex()); |
| 734 args->SetInteger(webview::kInternalEntryCount, | 652 args->SetInteger(webview::kInternalEntryCount, |
| 735 guest_web_contents()->GetController().GetEntryCount()); | 653 guest_web_contents()->GetController().GetEntryCount()); |
| 736 args->SetInteger(webview::kInternalProcessId, | 654 args->SetInteger(webview::kInternalProcessId, |
| 737 guest_web_contents()->GetRenderProcessHost()->GetID()); | 655 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 738 DispatchEventToEmbedder( | 656 DispatchEventToEmbedder( |
| 739 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); | 657 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); |
| 740 | 658 |
| 741 // Update the current zoom factor for the new page. | 659 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( |
| 742 ZoomController* zoom_controller = | 660 !render_frame_host->GetParent()); |
| 743 ZoomController::FromWebContents(guest_web_contents()); | |
| 744 DCHECK(zoom_controller); | |
| 745 current_zoom_factor_ = zoom_controller->GetZoomLevel(); | |
| 746 | |
| 747 if (!render_frame_host->GetParent()) | |
| 748 chromevox_injected_ = false; | |
| 749 } | 661 } |
| 750 | 662 |
| 751 void WebViewGuest::DidFailProvisionalLoad( | 663 void WebViewGuest::DidFailProvisionalLoad( |
| 752 content::RenderFrameHost* render_frame_host, | 664 content::RenderFrameHost* render_frame_host, |
| 753 const GURL& validated_url, | 665 const GURL& validated_url, |
| 754 int error_code, | 666 int error_code, |
| 755 const base::string16& error_description) { | 667 const base::string16& error_description) { |
| 756 LoadAbort(!render_frame_host->GetParent(), validated_url, | 668 LoadAbort(!render_frame_host->GetParent(), validated_url, |
| 757 net::ErrorToShortString(error_code)); | 669 net::ErrorToShortString(error_code)); |
| 758 } | 670 } |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 // As guests do not swap processes on navigation, only navigations to | 880 // As guests do not swap processes on navigation, only navigations to |
| 969 // normal web URLs are supported. No protocol handlers are installed for | 881 // normal web URLs are supported. No protocol handlers are installed for |
| 970 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 882 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 971 // can be granted to the guest process. | 883 // can be granted to the guest process. |
| 972 LoadURLWithParams(validated_url, | 884 LoadURLWithParams(validated_url, |
| 973 content::Referrer(), | 885 content::Referrer(), |
| 974 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 886 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 975 guest_web_contents()); | 887 guest_web_contents()); |
| 976 } | 888 } |
| 977 | 889 |
| 978 #if defined(OS_CHROMEOS) | |
| 979 void WebViewGuest::OnAccessibilityStatusChanged( | |
| 980 const chromeos::AccessibilityStatusEventDetails& details) { | |
| 981 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) { | |
| 982 accessibility_subscription_.reset(); | |
| 983 } else if (details.notification_type == | |
| 984 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { | |
| 985 if (details.enabled) | |
| 986 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); | |
| 987 else | |
| 988 chromevox_injected_ = false; | |
| 989 } | |
| 990 } | |
| 991 #endif | |
| 992 | |
| 993 void WebViewGuest::InjectChromeVoxIfNeeded( | 890 void WebViewGuest::InjectChromeVoxIfNeeded( |
| 994 content::RenderViewHost* render_view_host) { | 891 content::RenderViewHost* render_view_host) { |
| 995 #if defined(OS_CHROMEOS) | 892 web_view_guest_delegate_->InjectChromeVoxIfNeeded(render_view_host); |
| 996 if (!chromevox_injected_) { | |
| 997 chromeos::AccessibilityManager* manager = | |
| 998 chromeos::AccessibilityManager::Get(); | |
| 999 if (manager && manager->IsSpokenFeedbackEnabled()) { | |
| 1000 manager->InjectChromeVox(render_view_host); | |
| 1001 chromevox_injected_ = true; | |
| 1002 } | |
| 1003 } | |
| 1004 #endif | |
| 1005 } | 893 } |
| 1006 | 894 |
| 1007 bool WebViewGuest::HandleKeyboardShortcuts( | 895 bool WebViewGuest::HandleKeyboardShortcuts( |
| 1008 const content::NativeWebKeyboardEvent& event) { | 896 const content::NativeWebKeyboardEvent& event) { |
| 1009 if (event.type != blink::WebInputEvent::RawKeyDown) | 897 if (event.type != blink::WebInputEvent::RawKeyDown) |
| 1010 return false; | 898 return false; |
| 1011 | 899 |
| 1012 // If the user hits the escape key without any modifiers then unlock the | 900 // If the user hits the escape key without any modifiers then unlock the |
| 1013 // mouse if necessary. | 901 // mouse if necessary. |
| 1014 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && | 902 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height); | 947 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height); |
| 1060 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width); | 948 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width); |
| 1061 | 949 |
| 1062 // Call SetAutoSize to apply all the appropriate validation and clipping of | 950 // Call SetAutoSize to apply all the appropriate validation and clipping of |
| 1063 // values. | 951 // values. |
| 1064 SetAutoSize(auto_size_enabled, | 952 SetAutoSize(auto_size_enabled, |
| 1065 gfx::Size(min_width, min_height), | 953 gfx::Size(min_width, min_height), |
| 1066 gfx::Size(max_width, max_height)); | 954 gfx::Size(max_width, max_height)); |
| 1067 } | 955 } |
| 1068 | 956 |
| 1069 void WebViewGuest::ShowContextMenu(int request_id, | 957 void WebViewGuest::ShowContextMenu( |
| 1070 const MenuItemVector* items) { | 958 int request_id, |
| 1071 if (!pending_menu_.get()) | 959 const WebViewGuestDelegate::MenuItemVector* items) { |
| 1072 return; | 960 web_view_guest_delegate_->OnShowContextMenu(request_id, items); |
| 1073 | |
| 1074 // Make sure this was the correct request. | |
| 1075 if (request_id != pending_context_menu_request_id_) | |
| 1076 return; | |
| 1077 | |
| 1078 // TODO(lazyboy): Implement. | |
| 1079 DCHECK(!items); | |
| 1080 | |
| 1081 ContextMenuDelegate* menu_delegate = | |
| 1082 ContextMenuDelegate::FromWebContents(guest_web_contents()); | |
| 1083 menu_delegate->ShowMenu(pending_menu_.Pass()); | |
| 1084 } | 961 } |
| 1085 | 962 |
| 1086 void WebViewGuest::SetName(const std::string& name) { | 963 void WebViewGuest::SetName(const std::string& name) { |
| 1087 if (name_ == name) | 964 if (name_ == name) |
| 1088 return; | 965 return; |
| 1089 name_ = name; | 966 name_ = name; |
| 1090 | 967 |
| 1091 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); | 968 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); |
| 1092 } | 969 } |
| 1093 | 970 |
| 1094 void WebViewGuest::SetZoom(double zoom_factor) { | 971 void WebViewGuest::SetZoom(double zoom_factor) { |
| 1095 ZoomController* zoom_controller = | 972 GuestViewBase::Event* event = web_view_guest_delegate_->OnSetZoom( |
| 1096 ZoomController::FromWebContents(guest_web_contents()); | 973 zoom_factor, |
| 1097 DCHECK(zoom_controller); | 974 webview::kOldZoomFactor, |
| 1098 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 975 webview::kNewZoomFactor, |
| 1099 zoom_controller->SetZoomLevel(zoom_level); | 976 webview::kEventZoomChange); |
| 1100 | 977 if (!event) |
| 1101 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 978 return; |
| 1102 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | 979 DispatchEventToEmbedder(event); |
| 1103 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | 980 web_view_guest_delegate_->SetCurrentZoomFactor(zoom_factor); |
| 1104 DispatchEventToEmbedder( | |
| 1105 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); | |
| 1106 | |
| 1107 current_zoom_factor_ = zoom_factor; | |
| 1108 } | 981 } |
| 1109 | 982 |
| 1110 void WebViewGuest::AddNewContents(content::WebContents* source, | 983 void WebViewGuest::AddNewContents(content::WebContents* source, |
| 1111 content::WebContents* new_contents, | 984 content::WebContents* new_contents, |
| 1112 WindowOpenDisposition disposition, | 985 WindowOpenDisposition disposition, |
| 1113 const gfx::Rect& initial_pos, | 986 const gfx::Rect& initial_pos, |
| 1114 bool user_gesture, | 987 bool user_gesture, |
| 1115 bool* was_blocked) { | 988 bool* was_blocked) { |
| 1116 if (was_blocked) | 989 if (was_blocked) |
| 1117 *was_blocked = false; | 990 *was_blocked = false; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 WebViewGuest* guest = | 1128 WebViewGuest* guest = |
| 1256 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1129 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1257 if (!guest) | 1130 if (!guest) |
| 1258 return; | 1131 return; |
| 1259 | 1132 |
| 1260 if (!allow) | 1133 if (!allow) |
| 1261 guest->Destroy(); | 1134 guest->Destroy(); |
| 1262 } | 1135 } |
| 1263 | 1136 |
| 1264 } // namespace extensions | 1137 } // namespace extensions |
| OLD | NEW |