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 if (web_view_guest_delegate_) |
349 chromeos::AccessibilityManager* accessibility_manager = | 311 web_view_guest_delegate_->OnDidInitialize(); |
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()); | 312 AttachWebViewHelpers(guest_web_contents()); |
358 } | 313 } |
359 | 314 |
360 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { | 315 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { |
361 // Create a zoom controller for the guest contents give it access to | 316 if (web_view_guest_delegate_) |
362 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest. | 317 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); |
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)); | 318 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
381 } | 319 } |
382 | 320 |
383 void WebViewGuest::DidStopLoading() { | 321 void WebViewGuest::DidStopLoading() { |
384 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 322 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
385 DispatchEventToEmbedder( | 323 DispatchEventToEmbedder( |
386 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 324 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
387 } | 325 } |
388 | 326 |
389 void WebViewGuest::EmbedderDestroyed() { | 327 void WebViewGuest::EmbedderDestroyed() { |
390 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | 328 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
391 // reparenting of a <webview> within a single embedder. Right now, we keep | 329 // 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. | 330 // 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 | 331 // 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 | 332 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
395 // the call to RemoveWebViewEventListenersOnIOThread back to | 333 // the call to RemoveWebViewEventListenersOnIOThread back to |
396 // WebViewGuest::WebContentsDestroyed. | 334 // WebViewGuest::WebContentsDestroyed. |
397 content::BrowserThread::PostTask( | 335 content::BrowserThread::PostTask( |
398 content::BrowserThread::IO, | 336 content::BrowserThread::IO, |
399 FROM_HERE, | 337 FROM_HERE, |
400 base::Bind( | 338 base::Bind( |
401 &RemoveWebViewEventListenersOnIOThread, | 339 &RemoveWebViewEventListenersOnIOThread, |
402 browser_context(), embedder_extension_id(), | 340 browser_context(), embedder_extension_id(), |
403 embedder_render_process_id(), | 341 embedder_render_process_id(), |
404 view_instance_id())); | 342 view_instance_id())); |
405 } | 343 } |
406 | 344 |
407 void WebViewGuest::GuestDestroyed() { | 345 void WebViewGuest::GuestDestroyed() { |
408 // Clean up custom context menu items for this guest. | 346 // Clean up custom context menu items for this guest. |
409 MenuManager* menu_manager = MenuManager::Get( | 347 if (web_view_guest_delegate_) |
410 Profile::FromBrowserContext(browser_context())); | 348 web_view_guest_delegate_->OnGuestDestroyed(); |
411 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey( | |
412 embedder_extension_id(), view_instance_id())); | |
413 | |
414 RemoveWebViewStateFromIOThread(web_contents()); | 349 RemoveWebViewStateFromIOThread(web_contents()); |
415 } | 350 } |
416 | 351 |
417 void WebViewGuest::GuestReady() { | 352 void WebViewGuest::GuestReady() { |
418 // The guest RenderView should always live in an isolated guest process. | 353 // The guest RenderView should always live in an isolated guest process. |
419 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 354 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
420 Send(new ExtensionMsg_SetFrameName( | 355 Send(new ExtensionMsg_SetFrameName( |
421 guest_web_contents()->GetRoutingID(), name_)); | 356 guest_web_contents()->GetRoutingID(), name_)); |
422 } | 357 } |
423 | 358 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 int number_of_matches, | 408 int number_of_matches, |
474 const gfx::Rect& selection_rect, | 409 const gfx::Rect& selection_rect, |
475 int active_match_ordinal, | 410 int active_match_ordinal, |
476 bool final_update) { | 411 bool final_update) { |
477 find_helper_.FindReply(request_id, number_of_matches, selection_rect, | 412 find_helper_.FindReply(request_id, number_of_matches, selection_rect, |
478 active_match_ordinal, final_update); | 413 active_match_ordinal, final_update); |
479 } | 414 } |
480 | 415 |
481 bool WebViewGuest::HandleContextMenu( | 416 bool WebViewGuest::HandleContextMenu( |
482 const content::ContextMenuParams& params) { | 417 const content::ContextMenuParams& params) { |
483 ContextMenuDelegate* menu_delegate = | 418 if (!web_view_guest_delegate_) |
484 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 419 return false; |
485 DCHECK(menu_delegate); | 420 return web_view_guest_delegate_->HandleContextMenu(params); |
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; | |
499 } | 421 } |
500 | 422 |
501 void WebViewGuest::HandleKeyboardEvent( | 423 void WebViewGuest::HandleKeyboardEvent( |
502 WebContents* source, | 424 WebContents* source, |
503 const content::NativeWebKeyboardEvent& event) { | 425 const content::NativeWebKeyboardEvent& event) { |
504 if (!attached()) | 426 if (!attached()) |
505 return; | 427 return; |
506 | 428 |
507 if (HandleKeyboardShortcuts(event)) | 429 if (HandleKeyboardShortcuts(event)) |
508 return; | 430 return; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 is_top_level); | 549 is_top_level); |
628 break; | 550 break; |
629 } | 551 } |
630 default: | 552 default: |
631 NOTREACHED() << "Unexpected notification sent."; | 553 NOTREACHED() << "Unexpected notification sent."; |
632 break; | 554 break; |
633 } | 555 } |
634 } | 556 } |
635 | 557 |
636 double WebViewGuest::GetZoom() { | 558 double WebViewGuest::GetZoom() { |
637 return current_zoom_factor_; | 559 if (!web_view_guest_delegate_) |
560 return 1.0; | |
561 return web_view_guest_delegate_->GetZoom(); | |
638 } | 562 } |
639 | 563 |
640 void WebViewGuest::Find( | 564 void WebViewGuest::Find( |
641 const base::string16& search_text, | 565 const base::string16& search_text, |
642 const blink::WebFindOptions& options, | 566 const blink::WebFindOptions& options, |
643 scoped_refptr<WebViewInternalFindFunction> find_function) { | 567 scoped_refptr<WebViewInternalFindFunction> find_function) { |
644 find_helper_.Find(guest_web_contents(), search_text, options, find_function); | 568 find_helper_.Find(guest_web_contents(), search_text, options, find_function); |
645 } | 569 } |
646 | 570 |
647 void WebViewGuest::StopFinding(content::StopFindAction action) { | 571 void WebViewGuest::StopFinding(content::StopFindAction action) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 content::StoragePartition::OriginMatcherFunction(), | 626 content::StoragePartition::OriginMatcherFunction(), |
703 remove_since, | 627 remove_since, |
704 base::Time::Now(), | 628 base::Time::Now(), |
705 callback); | 629 callback); |
706 return true; | 630 return true; |
707 } | 631 } |
708 | 632 |
709 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, | 633 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, |
710 int guest_instance_id) | 634 int guest_instance_id) |
711 : GuestView<WebViewGuest>(browser_context, guest_instance_id), | 635 : GuestView<WebViewGuest>(browser_context, guest_instance_id), |
712 pending_context_menu_request_id_(0), | |
713 is_overriding_user_agent_(false), | 636 is_overriding_user_agent_(false), |
714 chromevox_injected_(false), | |
715 current_zoom_factor_(1.0), | |
716 find_helper_(this), | 637 find_helper_(this), |
717 javascript_dialog_helper_(this) { | 638 javascript_dialog_helper_(this) { |
639 web_view_guest_delegate_.reset(new ChromeWebViewGuestDelegate(this)); | |
718 } | 640 } |
719 | 641 |
720 WebViewGuest::~WebViewGuest() { | 642 WebViewGuest::~WebViewGuest() { |
721 } | 643 } |
722 | 644 |
723 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 645 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
724 content::RenderFrameHost* render_frame_host, | 646 content::RenderFrameHost* render_frame_host, |
725 const GURL& url, | 647 const GURL& url, |
726 content::PageTransition transition_type) { | 648 content::PageTransition transition_type) { |
727 find_helper_.CancelAllFindSessions(); | 649 find_helper_.CancelAllFindSessions(); |
728 | 650 |
729 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 651 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
730 args->SetString(guestview::kUrl, url.spec()); | 652 args->SetString(guestview::kUrl, url.spec()); |
731 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 653 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
732 args->SetInteger(webview::kInternalCurrentEntryIndex, | 654 args->SetInteger(webview::kInternalCurrentEntryIndex, |
733 guest_web_contents()->GetController().GetCurrentEntryIndex()); | 655 guest_web_contents()->GetController().GetCurrentEntryIndex()); |
734 args->SetInteger(webview::kInternalEntryCount, | 656 args->SetInteger(webview::kInternalEntryCount, |
735 guest_web_contents()->GetController().GetEntryCount()); | 657 guest_web_contents()->GetController().GetEntryCount()); |
736 args->SetInteger(webview::kInternalProcessId, | 658 args->SetInteger(webview::kInternalProcessId, |
737 guest_web_contents()->GetRenderProcessHost()->GetID()); | 659 guest_web_contents()->GetRenderProcessHost()->GetID()); |
738 DispatchEventToEmbedder( | 660 DispatchEventToEmbedder( |
739 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); | 661 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); |
740 | 662 if (web_view_guest_delegate_) { |
741 // Update the current zoom factor for the new page. | 663 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( |
742 ZoomController* zoom_controller = | 664 !render_frame_host->GetParent()); |
743 ZoomController::FromWebContents(guest_web_contents()); | 665 } |
744 DCHECK(zoom_controller); | |
745 current_zoom_factor_ = zoom_controller->GetZoomLevel(); | |
746 | |
747 if (!render_frame_host->GetParent()) | |
748 chromevox_injected_ = false; | |
749 } | 666 } |
750 | 667 |
751 void WebViewGuest::DidFailProvisionalLoad( | 668 void WebViewGuest::DidFailProvisionalLoad( |
752 content::RenderFrameHost* render_frame_host, | 669 content::RenderFrameHost* render_frame_host, |
753 const GURL& validated_url, | 670 const GURL& validated_url, |
754 int error_code, | 671 int error_code, |
755 const base::string16& error_description) { | 672 const base::string16& error_description) { |
756 LoadAbort(!render_frame_host->GetParent(), validated_url, | 673 LoadAbort(!render_frame_host->GetParent(), validated_url, |
757 net::ErrorToShortString(error_code)); | 674 net::ErrorToShortString(error_code)); |
758 } | 675 } |
759 | 676 |
760 void WebViewGuest::DidStartProvisionalLoadForFrame( | 677 void WebViewGuest::DidStartProvisionalLoadForFrame( |
761 content::RenderFrameHost* render_frame_host, | 678 content::RenderFrameHost* render_frame_host, |
762 const GURL& validated_url, | 679 const GURL& validated_url, |
763 bool is_error_page, | 680 bool is_error_page, |
764 bool is_iframe_srcdoc) { | 681 bool is_iframe_srcdoc) { |
765 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 682 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
766 args->SetString(guestview::kUrl, validated_url.spec()); | 683 args->SetString(guestview::kUrl, validated_url.spec()); |
767 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 684 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
768 DispatchEventToEmbedder( | 685 DispatchEventToEmbedder( |
769 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); | 686 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); |
770 } | 687 } |
771 | 688 |
772 void WebViewGuest::DocumentLoadedInFrame( | 689 void WebViewGuest::DocumentLoadedInFrame( |
773 content::RenderFrameHost* render_frame_host) { | 690 content::RenderFrameHost* render_frame_host) { |
774 if (!render_frame_host->GetParent()) | 691 if (web_view_guest_delegate_) |
775 InjectChromeVoxIfNeeded(render_frame_host->GetRenderViewHost()); | 692 web_view_guest_delegate_->OnDocumentLoadedInFrame(render_frame_host); |
Fady Samuel
2014/08/20 22:06:43
Pass in the parameter verbatim.
Fady Samuel
2014/08/20 22:09:04
Nm misread
| |
776 } | 693 } |
777 | 694 |
778 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, | 695 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, |
779 RenderFrameHost* render_frame_host) { | 696 RenderFrameHost* render_frame_host) { |
780 bool handled = true; | 697 bool handled = true; |
781 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) | 698 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) |
782 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged) | 699 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged) |
783 IPC_MESSAGE_UNHANDLED(handled = false) | 700 IPC_MESSAGE_UNHANDLED(handled = false) |
784 IPC_END_MESSAGE_MAP() | 701 IPC_END_MESSAGE_MAP() |
785 return handled; | 702 return handled; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
968 // As guests do not swap processes on navigation, only navigations to | 885 // As guests do not swap processes on navigation, only navigations to |
969 // normal web URLs are supported. No protocol handlers are installed for | 886 // normal web URLs are supported. No protocol handlers are installed for |
970 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 887 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
971 // can be granted to the guest process. | 888 // can be granted to the guest process. |
972 LoadURLWithParams(validated_url, | 889 LoadURLWithParams(validated_url, |
973 content::Referrer(), | 890 content::Referrer(), |
974 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 891 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
975 guest_web_contents()); | 892 guest_web_contents()); |
976 } | 893 } |
977 | 894 |
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( | |
994 content::RenderViewHost* render_view_host) { | |
995 #if defined(OS_CHROMEOS) | |
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 } | |
1006 | |
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) && |
1015 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { | 903 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { |
1016 return guest_web_contents()->GotResponseToLockMouseRequest(false); | 904 return guest_web_contents()->GotResponseToLockMouseRequest(false); |
(...skipping 42 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 if (web_view_guest_delegate_) |
1073 | 961 web_view_guest_delegate_->OnShowContextMenu(request_id, items); |
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 } | 962 } |
1085 | 963 |
1086 void WebViewGuest::SetName(const std::string& name) { | 964 void WebViewGuest::SetName(const std::string& name) { |
1087 if (name_ == name) | 965 if (name_ == name) |
1088 return; | 966 return; |
1089 name_ = name; | 967 name_ = name; |
1090 | 968 |
1091 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); | 969 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); |
1092 } | 970 } |
1093 | 971 |
1094 void WebViewGuest::SetZoom(double zoom_factor) { | 972 void WebViewGuest::SetZoom(double zoom_factor) { |
1095 ZoomController* zoom_controller = | 973 if (web_view_guest_delegate_) |
1096 ZoomController::FromWebContents(guest_web_contents()); | 974 web_view_guest_delegate_->OnSetZoom(zoom_factor); |
1097 DCHECK(zoom_controller); | |
1098 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | |
1099 zoom_controller->SetZoomLevel(zoom_level); | |
1100 | |
1101 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
1102 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | |
1103 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | |
1104 DispatchEventToEmbedder( | |
1105 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); | |
1106 | |
1107 current_zoom_factor_ = zoom_factor; | |
1108 } | 975 } |
1109 | 976 |
1110 void WebViewGuest::AddNewContents(content::WebContents* source, | 977 void WebViewGuest::AddNewContents(content::WebContents* source, |
1111 content::WebContents* new_contents, | 978 content::WebContents* new_contents, |
1112 WindowOpenDisposition disposition, | 979 WindowOpenDisposition disposition, |
1113 const gfx::Rect& initial_pos, | 980 const gfx::Rect& initial_pos, |
1114 bool user_gesture, | 981 bool user_gesture, |
1115 bool* was_blocked) { | 982 bool* was_blocked) { |
1116 if (was_blocked) | 983 if (was_blocked) |
1117 *was_blocked = false; | 984 *was_blocked = false; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1255 WebViewGuest* guest = | 1122 WebViewGuest* guest = |
1256 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1123 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1257 if (!guest) | 1124 if (!guest) |
1258 return; | 1125 return; |
1259 | 1126 |
1260 if (!allow) | 1127 if (!allow) |
1261 guest->Destroy(); | 1128 guest->Destroy(); |
1262 } | 1129 } |
1263 | 1130 |
1264 } // namespace extensions | 1131 } // namespace extensions |
OLD | NEW |