Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: trunk/src/chrome/browser/guest_view/web_view/web_view_guest.cc

Issue 473263005: Revert 291002 "Introduce WebViewGuestDelegate." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extensions/api/web_request/web_request_api.h" 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
11 #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"
12 #include "chrome/browser/guest_view/web_view/chrome_web_view_guest_delegate.h" 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
14 #include "chrome/browser/extensions/menu_manager.h"
15 #include "chrome/browser/favicon/favicon_tab_helper.h"
13 #include "chrome/browser/guest_view/web_view/web_view_constants.h" 16 #include "chrome/browser/guest_view/web_view/web_view_constants.h"
14 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" 17 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" 18 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
16 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" 19 #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"
17 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/child_process_security_policy.h" 27 #include "content/public/browser/child_process_security_policy.h"
19 #include "content/public/browser/native_web_keyboard_event.h" 28 #include "content/public/browser/native_web_keyboard_event.h"
20 #include "content/public/browser/navigation_entry.h" 29 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_source.h" 32 #include "content/public/browser/notification_source.h"
24 #include "content/public/browser/notification_types.h" 33 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
(...skipping 12 matching lines...) Expand all
39 #include "extensions/browser/guest_view/guest_view_constants.h" 48 #include "extensions/browser/guest_view/guest_view_constants.h"
40 #include "extensions/browser/guest_view/guest_view_manager.h" 49 #include "extensions/browser/guest_view/guest_view_manager.h"
41 #include "extensions/common/constants.h" 50 #include "extensions/common/constants.h"
42 #include "extensions/common/extension_messages.h" 51 #include "extensions/common/extension_messages.h"
43 #include "ipc/ipc_message_macros.h" 52 #include "ipc/ipc_message_macros.h"
44 #include "net/base/escape.h" 53 #include "net/base/escape.h"
45 #include "net/base/net_errors.h" 54 #include "net/base/net_errors.h"
46 #include "third_party/WebKit/public/web/WebFindOptions.h" 55 #include "third_party/WebKit/public/web/WebFindOptions.h"
47 #include "ui/base/models/simple_menu_model.h" 56 #include "ui/base/models/simple_menu_model.h"
48 57
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
49 using base::UserMetricsAction; 71 using base::UserMetricsAction;
50 using content::RenderFrameHost; 72 using content::RenderFrameHost;
51 using content::ResourceType; 73 using content::ResourceType;
52 using content::WebContents; 74 using content::WebContents;
53 75
54 namespace extensions { 76 namespace extensions {
55 77
56 namespace { 78 namespace {
57 79
58 std::string WindowOpenDispositionToString( 80 std::string WindowOpenDispositionToString(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 202
181 // static 203 // static
182 int WebViewGuest::GetViewInstanceId(WebContents* contents) { 204 int WebViewGuest::GetViewInstanceId(WebContents* contents) {
183 WebViewGuest* guest = FromWebContents(contents); 205 WebViewGuest* guest = FromWebContents(contents);
184 if (!guest) 206 if (!guest)
185 return guestview::kInstanceIDNone; 207 return guestview::kInstanceIDNone;
186 208
187 return guest->view_instance_id(); 209 return guest->view_instance_id();
188 } 210 }
189 211
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
190 const char* WebViewGuest::GetAPINamespace() { 228 const char* WebViewGuest::GetAPINamespace() {
191 return webview::kAPINamespace; 229 return webview::kAPINamespace;
192 } 230 }
193 231
194 void WebViewGuest::CreateWebContents( 232 void WebViewGuest::CreateWebContents(
195 const std::string& embedder_extension_id, 233 const std::string& embedder_extension_id,
196 int embedder_render_process_id, 234 int embedder_render_process_id,
197 const base::DictionaryValue& create_params, 235 const base::DictionaryValue& create_params,
198 const WebContentsCreatedCallback& callback) { 236 const WebContentsCreatedCallback& callback) {
199 content::RenderProcessHost* embedder_render_process_host = 237 content::RenderProcessHost* embedder_render_process_host =
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 new ScriptExecutor(guest_web_contents(), &script_observers_)); 338 new ScriptExecutor(guest_web_contents(), &script_observers_));
301 339
302 notification_registrar_.Add( 340 notification_registrar_.Add(
303 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 341 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
304 content::Source<WebContents>(guest_web_contents())); 342 content::Source<WebContents>(guest_web_contents()));
305 343
306 notification_registrar_.Add( 344 notification_registrar_.Add(
307 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 345 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
308 content::Source<WebContents>(guest_web_contents())); 346 content::Source<WebContents>(guest_web_contents()));
309 347
310 if (web_view_guest_delegate_) 348 #if defined(OS_CHROMEOS)
311 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
312 AttachWebViewHelpers(guest_web_contents()); 357 AttachWebViewHelpers(guest_web_contents());
313 } 358 }
314 359
315 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { 360 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
316 if (web_view_guest_delegate_) 361 // Create a zoom controller for the guest contents give it access to
317 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);
318 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); 380 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
319 } 381 }
320 382
321 void WebViewGuest::DidStopLoading() { 383 void WebViewGuest::DidStopLoading() {
322 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 384 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
323 DispatchEventToEmbedder( 385 DispatchEventToEmbedder(
324 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 386 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
325 } 387 }
326 388
327 void WebViewGuest::EmbedderDestroyed() { 389 void WebViewGuest::EmbedderDestroyed() {
328 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 390 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
329 // reparenting of a <webview> within a single embedder. Right now, we keep 391 // reparenting of a <webview> within a single embedder. Right now, we keep
330 // around the browser state for the listener for the lifetime of the embedder. 392 // around the browser state for the listener for the lifetime of the embedder.
331 // Ideally, the lifetime of the listeners should match the lifetime of the 393 // Ideally, the lifetime of the listeners should match the lifetime of the
332 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move 394 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
333 // the call to RemoveWebViewEventListenersOnIOThread back to 395 // the call to RemoveWebViewEventListenersOnIOThread back to
334 // WebViewGuest::WebContentsDestroyed. 396 // WebViewGuest::WebContentsDestroyed.
335 content::BrowserThread::PostTask( 397 content::BrowserThread::PostTask(
336 content::BrowserThread::IO, 398 content::BrowserThread::IO,
337 FROM_HERE, 399 FROM_HERE,
338 base::Bind( 400 base::Bind(
339 &RemoveWebViewEventListenersOnIOThread, 401 &RemoveWebViewEventListenersOnIOThread,
340 browser_context(), embedder_extension_id(), 402 browser_context(), embedder_extension_id(),
341 embedder_render_process_id(), 403 embedder_render_process_id(),
342 view_instance_id())); 404 view_instance_id()));
343 } 405 }
344 406
345 void WebViewGuest::GuestDestroyed() { 407 void WebViewGuest::GuestDestroyed() {
346 // Clean up custom context menu items for this guest. 408 // Clean up custom context menu items for this guest.
347 if (web_view_guest_delegate_) 409 MenuManager* menu_manager = MenuManager::Get(
348 web_view_guest_delegate_->OnGuestDestroyed(); 410 Profile::FromBrowserContext(browser_context()));
411 menu_manager->RemoveAllContextItems(MenuItem::ExtensionKey(
412 embedder_extension_id(), view_instance_id()));
413
349 RemoveWebViewStateFromIOThread(web_contents()); 414 RemoveWebViewStateFromIOThread(web_contents());
350 } 415 }
351 416
352 void WebViewGuest::GuestReady() { 417 void WebViewGuest::GuestReady() {
353 // The guest RenderView should always live in an isolated guest process. 418 // The guest RenderView should always live in an isolated guest process.
354 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); 419 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
355 Send(new ExtensionMsg_SetFrameName( 420 Send(new ExtensionMsg_SetFrameName(
356 guest_web_contents()->GetRoutingID(), name_)); 421 guest_web_contents()->GetRoutingID(), name_));
357 } 422 }
358 423
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 int number_of_matches, 473 int number_of_matches,
409 const gfx::Rect& selection_rect, 474 const gfx::Rect& selection_rect,
410 int active_match_ordinal, 475 int active_match_ordinal,
411 bool final_update) { 476 bool final_update) {
412 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 477 find_helper_.FindReply(request_id, number_of_matches, selection_rect,
413 active_match_ordinal, final_update); 478 active_match_ordinal, final_update);
414 } 479 }
415 480
416 bool WebViewGuest::HandleContextMenu( 481 bool WebViewGuest::HandleContextMenu(
417 const content::ContextMenuParams& params) { 482 const content::ContextMenuParams& params) {
418 if (!web_view_guest_delegate_) 483 ContextMenuDelegate* menu_delegate =
419 return false; 484 ContextMenuDelegate::FromWebContents(guest_web_contents());
420 return web_view_guest_delegate_->HandleContextMenu(params); 485 DCHECK(menu_delegate);
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;
421 } 499 }
422 500
423 void WebViewGuest::HandleKeyboardEvent( 501 void WebViewGuest::HandleKeyboardEvent(
424 WebContents* source, 502 WebContents* source,
425 const content::NativeWebKeyboardEvent& event) { 503 const content::NativeWebKeyboardEvent& event) {
426 if (!attached()) 504 if (!attached())
427 return; 505 return;
428 506
429 if (HandleKeyboardShortcuts(event)) 507 if (HandleKeyboardShortcuts(event))
430 return; 508 return;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 is_top_level); 627 is_top_level);
550 break; 628 break;
551 } 629 }
552 default: 630 default:
553 NOTREACHED() << "Unexpected notification sent."; 631 NOTREACHED() << "Unexpected notification sent.";
554 break; 632 break;
555 } 633 }
556 } 634 }
557 635
558 double WebViewGuest::GetZoom() { 636 double WebViewGuest::GetZoom() {
559 if (!web_view_guest_delegate_) 637 return current_zoom_factor_;
560 return 1.0;
561 return web_view_guest_delegate_->GetZoom();
562 } 638 }
563 639
564 void WebViewGuest::Find( 640 void WebViewGuest::Find(
565 const base::string16& search_text, 641 const base::string16& search_text,
566 const blink::WebFindOptions& options, 642 const blink::WebFindOptions& options,
567 scoped_refptr<WebViewInternalFindFunction> find_function) { 643 scoped_refptr<WebViewInternalFindFunction> find_function) {
568 find_helper_.Find(guest_web_contents(), search_text, options, find_function); 644 find_helper_.Find(guest_web_contents(), search_text, options, find_function);
569 } 645 }
570 646
571 void WebViewGuest::StopFinding(content::StopFindAction action) { 647 void WebViewGuest::StopFinding(content::StopFindAction action) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 content::StoragePartition::OriginMatcherFunction(), 702 content::StoragePartition::OriginMatcherFunction(),
627 remove_since, 703 remove_since,
628 base::Time::Now(), 704 base::Time::Now(),
629 callback); 705 callback);
630 return true; 706 return true;
631 } 707 }
632 708
633 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 709 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
634 int guest_instance_id) 710 int guest_instance_id)
635 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 711 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
712 pending_context_menu_request_id_(0),
636 is_overriding_user_agent_(false), 713 is_overriding_user_agent_(false),
714 chromevox_injected_(false),
715 current_zoom_factor_(1.0),
637 find_helper_(this), 716 find_helper_(this),
638 javascript_dialog_helper_(this) { 717 javascript_dialog_helper_(this) {
639 web_view_guest_delegate_.reset(new ChromeWebViewGuestDelegate(this));
640 } 718 }
641 719
642 WebViewGuest::~WebViewGuest() { 720 WebViewGuest::~WebViewGuest() {
643 } 721 }
644 722
645 void WebViewGuest::DidCommitProvisionalLoadForFrame( 723 void WebViewGuest::DidCommitProvisionalLoadForFrame(
646 content::RenderFrameHost* render_frame_host, 724 content::RenderFrameHost* render_frame_host,
647 const GURL& url, 725 const GURL& url,
648 content::PageTransition transition_type) { 726 content::PageTransition transition_type) {
649 find_helper_.CancelAllFindSessions(); 727 find_helper_.CancelAllFindSessions();
650 728
651 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 729 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
652 args->SetString(guestview::kUrl, url.spec()); 730 args->SetString(guestview::kUrl, url.spec());
653 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 731 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
654 args->SetInteger(webview::kInternalCurrentEntryIndex, 732 args->SetInteger(webview::kInternalCurrentEntryIndex,
655 guest_web_contents()->GetController().GetCurrentEntryIndex()); 733 guest_web_contents()->GetController().GetCurrentEntryIndex());
656 args->SetInteger(webview::kInternalEntryCount, 734 args->SetInteger(webview::kInternalEntryCount,
657 guest_web_contents()->GetController().GetEntryCount()); 735 guest_web_contents()->GetController().GetEntryCount());
658 args->SetInteger(webview::kInternalProcessId, 736 args->SetInteger(webview::kInternalProcessId,
659 guest_web_contents()->GetRenderProcessHost()->GetID()); 737 guest_web_contents()->GetRenderProcessHost()->GetID());
660 DispatchEventToEmbedder( 738 DispatchEventToEmbedder(
661 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); 739 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass()));
662 if (web_view_guest_delegate_) { 740
663 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( 741 // Update the current zoom factor for the new page.
664 !render_frame_host->GetParent()); 742 ZoomController* zoom_controller =
665 } 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;
666 } 749 }
667 750
668 void WebViewGuest::DidFailProvisionalLoad( 751 void WebViewGuest::DidFailProvisionalLoad(
669 content::RenderFrameHost* render_frame_host, 752 content::RenderFrameHost* render_frame_host,
670 const GURL& validated_url, 753 const GURL& validated_url,
671 int error_code, 754 int error_code,
672 const base::string16& error_description) { 755 const base::string16& error_description) {
673 LoadAbort(!render_frame_host->GetParent(), validated_url, 756 LoadAbort(!render_frame_host->GetParent(), validated_url,
674 net::ErrorToShortString(error_code)); 757 net::ErrorToShortString(error_code));
675 } 758 }
676 759
677 void WebViewGuest::DidStartProvisionalLoadForFrame( 760 void WebViewGuest::DidStartProvisionalLoadForFrame(
678 content::RenderFrameHost* render_frame_host, 761 content::RenderFrameHost* render_frame_host,
679 const GURL& validated_url, 762 const GURL& validated_url,
680 bool is_error_page, 763 bool is_error_page,
681 bool is_iframe_srcdoc) { 764 bool is_iframe_srcdoc) {
682 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 765 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
683 args->SetString(guestview::kUrl, validated_url.spec()); 766 args->SetString(guestview::kUrl, validated_url.spec());
684 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 767 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
685 DispatchEventToEmbedder( 768 DispatchEventToEmbedder(
686 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); 769 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass()));
687 } 770 }
688 771
689 void WebViewGuest::DocumentLoadedInFrame( 772 void WebViewGuest::DocumentLoadedInFrame(
690 content::RenderFrameHost* render_frame_host) { 773 content::RenderFrameHost* render_frame_host) {
691 if (web_view_guest_delegate_) 774 if (!render_frame_host->GetParent())
692 web_view_guest_delegate_->OnDocumentLoadedInFrame(render_frame_host); 775 InjectChromeVoxIfNeeded(render_frame_host->GetRenderViewHost());
693 } 776 }
694 777
695 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, 778 bool WebViewGuest::OnMessageReceived(const IPC::Message& message,
696 RenderFrameHost* render_frame_host) { 779 RenderFrameHost* render_frame_host) {
697 bool handled = true; 780 bool handled = true;
698 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) 781 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message)
699 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged) 782 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged)
700 IPC_MESSAGE_UNHANDLED(handled = false) 783 IPC_MESSAGE_UNHANDLED(handled = false)
701 IPC_END_MESSAGE_MAP() 784 IPC_END_MESSAGE_MAP()
702 return handled; 785 return handled;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 // As guests do not swap processes on navigation, only navigations to 968 // As guests do not swap processes on navigation, only navigations to
886 // normal web URLs are supported. No protocol handlers are installed for 969 // normal web URLs are supported. No protocol handlers are installed for
887 // other schemes (e.g., WebUI or extensions), and no permissions or bindings 970 // other schemes (e.g., WebUI or extensions), and no permissions or bindings
888 // can be granted to the guest process. 971 // can be granted to the guest process.
889 LoadURLWithParams(validated_url, 972 LoadURLWithParams(validated_url,
890 content::Referrer(), 973 content::Referrer(),
891 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 974 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
892 guest_web_contents()); 975 guest_web_contents());
893 } 976 }
894 977
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
895 bool WebViewGuest::HandleKeyboardShortcuts( 1007 bool WebViewGuest::HandleKeyboardShortcuts(
896 const content::NativeWebKeyboardEvent& event) { 1008 const content::NativeWebKeyboardEvent& event) {
897 if (event.type != blink::WebInputEvent::RawKeyDown) 1009 if (event.type != blink::WebInputEvent::RawKeyDown)
898 return false; 1010 return false;
899 1011
900 // If the user hits the escape key without any modifiers then unlock the 1012 // If the user hits the escape key without any modifiers then unlock the
901 // mouse if necessary. 1013 // mouse if necessary.
902 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && 1014 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) &&
903 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { 1015 !(event.modifiers & blink::WebInputEvent::InputModifiers)) {
904 return guest_web_contents()->GotResponseToLockMouseRequest(false); 1016 return guest_web_contents()->GotResponseToLockMouseRequest(false);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height); 1059 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height);
948 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width); 1060 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width);
949 1061
950 // Call SetAutoSize to apply all the appropriate validation and clipping of 1062 // Call SetAutoSize to apply all the appropriate validation and clipping of
951 // values. 1063 // values.
952 SetAutoSize(auto_size_enabled, 1064 SetAutoSize(auto_size_enabled,
953 gfx::Size(min_width, min_height), 1065 gfx::Size(min_width, min_height),
954 gfx::Size(max_width, max_height)); 1066 gfx::Size(max_width, max_height));
955 } 1067 }
956 1068
957 void WebViewGuest::ShowContextMenu( 1069 void WebViewGuest::ShowContextMenu(int request_id,
958 int request_id, 1070 const MenuItemVector* items) {
959 const WebViewGuestDelegate::MenuItemVector* items) { 1071 if (!pending_menu_.get())
960 if (web_view_guest_delegate_) 1072 return;
961 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());
962 } 1084 }
963 1085
964 void WebViewGuest::SetName(const std::string& name) { 1086 void WebViewGuest::SetName(const std::string& name) {
965 if (name_ == name) 1087 if (name_ == name)
966 return; 1088 return;
967 name_ = name; 1089 name_ = name;
968 1090
969 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); 1091 Send(new ExtensionMsg_SetFrameName(routing_id(), name_));
970 } 1092 }
971 1093
972 void WebViewGuest::SetZoom(double zoom_factor) { 1094 void WebViewGuest::SetZoom(double zoom_factor) {
973 if (web_view_guest_delegate_) 1095 ZoomController* zoom_controller =
974 web_view_guest_delegate_->OnSetZoom(zoom_factor); 1096 ZoomController::FromWebContents(guest_web_contents());
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;
975 } 1108 }
976 1109
977 void WebViewGuest::AddNewContents(content::WebContents* source, 1110 void WebViewGuest::AddNewContents(content::WebContents* source,
978 content::WebContents* new_contents, 1111 content::WebContents* new_contents,
979 WindowOpenDisposition disposition, 1112 WindowOpenDisposition disposition,
980 const gfx::Rect& initial_pos, 1113 const gfx::Rect& initial_pos,
981 bool user_gesture, 1114 bool user_gesture,
982 bool* was_blocked) { 1115 bool* was_blocked) {
983 if (was_blocked) 1116 if (was_blocked)
984 *was_blocked = false; 1117 *was_blocked = false;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 WebViewGuest* guest = 1255 WebViewGuest* guest =
1123 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1256 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1124 if (!guest) 1257 if (!guest)
1125 return; 1258 return;
1126 1259
1127 if (!allow) 1260 if (!allow)
1128 guest->Destroy(); 1261 guest->Destroy();
1129 } 1262 }
1130 1263
1131 } // namespace extensions 1264 } // namespace extensions
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/guest_view/web_view/web_view_guest.h ('k') | trunk/src/chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698