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

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

Issue 481003002: Introduce WebViewGuestDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2_extensions_render_frame_observer
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
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"
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
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
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
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 defined(OS_CHROMEOS)
Fady Samuel 2014/08/18 20:11:22 Remove this?
Xi Han 2014/08/18 22:23:57 Done.
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 312 #endif
356 313
357 AttachWebViewHelpers(guest_web_contents()); 314 AttachWebViewHelpers(guest_web_contents());
358 } 315 }
359 316
360 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { 317 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
361 // Create a zoom controller for the guest contents give it access to 318 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)); 319 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
381 } 320 }
382 321
383 void WebViewGuest::DidStopLoading() { 322 void WebViewGuest::DidStopLoading() {
384 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 323 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
385 DispatchEventToEmbedder( 324 DispatchEventToEmbedder(
386 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 325 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
387 } 326 }
388 327
389 void WebViewGuest::EmbedderDestroyed() { 328 void WebViewGuest::EmbedderDestroyed() {
390 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 329 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
391 // reparenting of a <webview> within a single embedder. Right now, we keep 330 // 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. 331 // 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 332 // 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 333 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
395 // the call to RemoveWebViewEventListenersOnIOThread back to 334 // the call to RemoveWebViewEventListenersOnIOThread back to
396 // WebViewGuest::WebContentsDestroyed. 335 // WebViewGuest::WebContentsDestroyed.
397 content::BrowserThread::PostTask( 336 content::BrowserThread::PostTask(
398 content::BrowserThread::IO, 337 content::BrowserThread::IO,
399 FROM_HERE, 338 FROM_HERE,
400 base::Bind( 339 base::Bind(
401 &RemoveWebViewEventListenersOnIOThread, 340 &RemoveWebViewEventListenersOnIOThread,
402 browser_context(), embedder_extension_id(), 341 browser_context(), embedder_extension_id(),
403 embedder_render_process_id(), 342 embedder_render_process_id(),
404 view_instance_id())); 343 view_instance_id()));
405 } 344 }
406 345
407 void WebViewGuest::GuestDestroyed() { 346 void WebViewGuest::GuestDestroyed() {
408 // Clean up custom context menu items for this guest. 347 // Clean up custom context menu items for this guest.
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
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_SetName(guest_web_contents()->GetRoutingID(), name_)); 355 Send(new ExtensionMsg_SetName(guest_web_contents()->GetRoutingID(), name_));
421 } 356 }
422 357
423 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, 358 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 int number_of_matches, 407 int number_of_matches,
473 const gfx::Rect& selection_rect, 408 const gfx::Rect& selection_rect,
474 int active_match_ordinal, 409 int active_match_ordinal,
475 bool final_update) { 410 bool final_update) {
476 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 411 find_helper_.FindReply(request_id, number_of_matches, selection_rect,
477 active_match_ordinal, final_update); 412 active_match_ordinal, final_update);
478 } 413 }
479 414
480 bool WebViewGuest::HandleContextMenu( 415 bool WebViewGuest::HandleContextMenu(
481 const content::ContextMenuParams& params) { 416 const content::ContextMenuParams& params) {
482 ContextMenuDelegate* menu_delegate = 417 GuestViewBase::Event* event =
483 ContextMenuDelegate::FromWebContents(guest_web_contents()); 418 web_view_guest_delegate_->OnHandleContextMenu(params);
484 DCHECK(menu_delegate); 419 DispatchEventToEmbedder(event);
485
486 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params);
487
488 // Pass it to embedder.
489 int request_id = ++pending_context_menu_request_id_;
490 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
491 scoped_ptr<base::ListValue> items =
492 MenuModelToValue(pending_menu_->menu_model());
493 args->Set(webview::kContextMenuItems, items.release());
494 args->SetInteger(webview::kRequestId, request_id);
495 DispatchEventToEmbedder(
496 new GuestViewBase::Event(webview::kEventContextMenu, args.Pass()));
497 return true; 420 return true;
498 } 421 }
499 422
500 void WebViewGuest::HandleKeyboardEvent( 423 void WebViewGuest::HandleKeyboardEvent(
501 WebContents* source, 424 WebContents* source,
502 const content::NativeWebKeyboardEvent& event) { 425 const content::NativeWebKeyboardEvent& event) {
503 if (!attached()) 426 if (!attached())
504 return; 427 return;
505 428
506 if (HandleKeyboardShortcuts(event)) 429 if (HandleKeyboardShortcuts(event))
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 content::StoragePartition::OriginMatcherFunction(), 624 content::StoragePartition::OriginMatcherFunction(),
702 remove_since, 625 remove_since,
703 base::Time::Now(), 626 base::Time::Now(),
704 callback); 627 callback);
705 return true; 628 return true;
706 } 629 }
707 630
708 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 631 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
709 int guest_instance_id) 632 int guest_instance_id)
710 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 633 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
711 pending_context_menu_request_id_(0),
712 is_overriding_user_agent_(false), 634 is_overriding_user_agent_(false),
713 chromevox_injected_(false),
714 current_zoom_factor_(1.0), 635 current_zoom_factor_(1.0),
715 find_helper_(this), 636 find_helper_(this),
716 javascript_dialog_helper_(this) { 637 javascript_dialog_helper_(this) {
638 web_view_guest_delegate_.reset(new ChromeWebViewGuestDelegate(*this));
717 } 639 }
718 640
719 WebViewGuest::~WebViewGuest() { 641 WebViewGuest::~WebViewGuest() {
720 } 642 }
721 643
722 void WebViewGuest::DidCommitProvisionalLoadForFrame( 644 void WebViewGuest::DidCommitProvisionalLoadForFrame(
723 content::RenderFrameHost* render_frame_host, 645 content::RenderFrameHost* render_frame_host,
724 const GURL& url, 646 const GURL& url,
725 content::PageTransition transition_type) { 647 content::PageTransition transition_type) {
726 find_helper_.CancelAllFindSessions(); 648 find_helper_.CancelAllFindSessions();
727 649
728 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 650 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
729 args->SetString(guestview::kUrl, url.spec()); 651 args->SetString(guestview::kUrl, url.spec());
730 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 652 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
731 args->SetInteger(webview::kInternalCurrentEntryIndex, 653 args->SetInteger(webview::kInternalCurrentEntryIndex,
732 guest_web_contents()->GetController().GetCurrentEntryIndex()); 654 guest_web_contents()->GetController().GetCurrentEntryIndex());
733 args->SetInteger(webview::kInternalEntryCount, 655 args->SetInteger(webview::kInternalEntryCount,
734 guest_web_contents()->GetController().GetEntryCount()); 656 guest_web_contents()->GetController().GetEntryCount());
735 args->SetInteger(webview::kInternalProcessId, 657 args->SetInteger(webview::kInternalProcessId,
736 guest_web_contents()->GetRenderProcessHost()->GetID()); 658 guest_web_contents()->GetRenderProcessHost()->GetID());
737 DispatchEventToEmbedder( 659 DispatchEventToEmbedder(
738 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); 660 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass()));
739 661
740 // Update the current zoom factor for the new page. 662 current_zoom_factor_ = web_view_guest_delegate_->GetZoomLevel();
Fady Samuel 2014/08/18 20:11:22 Let's move zoom entirely out until it is supported
Xi Han 2014/08/18 22:23:57 Done.
741 ZoomController* zoom_controller =
742 ZoomController::FromWebContents(guest_web_contents());
743 DCHECK(zoom_controller);
744 current_zoom_factor_ = zoom_controller->GetZoomLevel();
745 663
746 if (!render_frame_host->GetParent()) 664 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame(
747 chromevox_injected_ = false; 665 !render_frame_host->GetParent());
748 } 666 }
749 667
750 void WebViewGuest::DidFailProvisionalLoad( 668 void WebViewGuest::DidFailProvisionalLoad(
751 content::RenderFrameHost* render_frame_host, 669 content::RenderFrameHost* render_frame_host,
752 const GURL& validated_url, 670 const GURL& validated_url,
753 int error_code, 671 int error_code,
754 const base::string16& error_description) { 672 const base::string16& error_description) {
755 LoadAbort(!render_frame_host->GetParent(), validated_url, 673 LoadAbort(!render_frame_host->GetParent(), validated_url,
756 net::ErrorToShortString(error_code)); 674 net::ErrorToShortString(error_code));
757 } 675 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 // As guests do not swap processes on navigation, only navigations to 885 // As guests do not swap processes on navigation, only navigations to
968 // normal web URLs are supported. No protocol handlers are installed for 886 // normal web URLs are supported. No protocol handlers are installed for
969 // 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
970 // can be granted to the guest process. 888 // can be granted to the guest process.
971 LoadURLWithParams(validated_url, 889 LoadURLWithParams(validated_url,
972 content::Referrer(), 890 content::Referrer(),
973 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 891 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
974 guest_web_contents()); 892 guest_web_contents());
975 } 893 }
976 894
977 #if defined(OS_CHROMEOS)
978 void WebViewGuest::OnAccessibilityStatusChanged(
979 const chromeos::AccessibilityStatusEventDetails& details) {
980 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) {
981 accessibility_subscription_.reset();
982 } else if (details.notification_type ==
983 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) {
984 if (details.enabled)
985 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost());
986 else
987 chromevox_injected_ = false;
988 }
989 }
990 #endif
991
992 void WebViewGuest::InjectChromeVoxIfNeeded( 895 void WebViewGuest::InjectChromeVoxIfNeeded(
993 content::RenderViewHost* render_view_host) { 896 content::RenderViewHost* render_view_host) {
994 #if defined(OS_CHROMEOS) 897 #if defined(OS_CHROMEOS)
Fady Samuel 2014/08/18 20:11:22 Remove this. This is already decided on the other
Xi Han 2014/08/18 22:23:57 Done.
995 if (!chromevox_injected_) { 898 web_view_guest_delegate_->InjectChromeVoxIfNeeded(render_view_host);
996 chromeos::AccessibilityManager* manager =
997 chromeos::AccessibilityManager::Get();
998 if (manager && manager->IsSpokenFeedbackEnabled()) {
999 manager->InjectChromeVox(render_view_host);
1000 chromevox_injected_ = true;
1001 }
1002 }
1003 #endif 899 #endif
1004 } 900 }
1005 901
1006 bool WebViewGuest::HandleKeyboardShortcuts( 902 bool WebViewGuest::HandleKeyboardShortcuts(
1007 const content::NativeWebKeyboardEvent& event) { 903 const content::NativeWebKeyboardEvent& event) {
1008 if (event.type != blink::WebInputEvent::RawKeyDown) 904 if (event.type != blink::WebInputEvent::RawKeyDown)
1009 return false; 905 return false;
1010 906
1011 // If the user hits the escape key without any modifiers then unlock the 907 // If the user hits the escape key without any modifiers then unlock the
1012 // mouse if necessary. 908 // mouse if necessary.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height); 954 extra_params()->GetInteger(webview::kAttributeMinHeight, &min_height);
1059 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width); 955 extra_params()->GetInteger(webview::kAttributeMinWidth, &min_width);
1060 956
1061 // Call SetAutoSize to apply all the appropriate validation and clipping of 957 // Call SetAutoSize to apply all the appropriate validation and clipping of
1062 // values. 958 // values.
1063 SetAutoSize(auto_size_enabled, 959 SetAutoSize(auto_size_enabled,
1064 gfx::Size(min_width, min_height), 960 gfx::Size(min_width, min_height),
1065 gfx::Size(max_width, max_height)); 961 gfx::Size(max_width, max_height));
1066 } 962 }
1067 963
1068 void WebViewGuest::ShowContextMenu(int request_id, 964 void WebViewGuest::ShowContextMenu(
1069 const MenuItemVector* items) { 965 int request_id,
1070 if (!pending_menu_.get()) 966 const WebViewGuestDelegate::MenuItemVector* items) {
1071 return; 967 web_view_guest_delegate_->OnShowContextMenu(request_id, items);
1072
1073 // Make sure this was the correct request.
1074 if (request_id != pending_context_menu_request_id_)
1075 return;
1076
1077 // TODO(lazyboy): Implement.
1078 DCHECK(!items);
1079
1080 ContextMenuDelegate* menu_delegate =
1081 ContextMenuDelegate::FromWebContents(guest_web_contents());
1082 menu_delegate->ShowMenu(pending_menu_.Pass());
1083 } 968 }
1084 969
1085 void WebViewGuest::SetName(const std::string& name) { 970 void WebViewGuest::SetName(const std::string& name) {
1086 if (name_ == name) 971 if (name_ == name)
1087 return; 972 return;
1088 name_ = name; 973 name_ = name;
1089 974
1090 Send(new ExtensionMsg_SetName(routing_id(), name_)); 975 Send(new ExtensionMsg_SetName(routing_id(), name_));
1091 } 976 }
1092 977
1093 void WebViewGuest::SetZoom(double zoom_factor) { 978 void WebViewGuest::SetZoom(double zoom_factor) {
1094 ZoomController* zoom_controller = 979 web_view_guest_delegate_->OnSetZoom(zoom_factor);
Fady Samuel 2014/08/18 20:11:22 This conceptually to me is weird. Either zoom is a
Xi Han 2014/08/18 22:23:57 Done.
1095 ZoomController::FromWebContents(guest_web_contents());
1096 DCHECK(zoom_controller);
1097 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor);
1098 zoom_controller->SetZoomLevel(zoom_level);
1099 980
1100 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 981 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1101 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); 982 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_);
1102 args->SetDouble(webview::kNewZoomFactor, zoom_factor); 983 args->SetDouble(webview::kNewZoomFactor, zoom_factor);
1103 DispatchEventToEmbedder( 984 DispatchEventToEmbedder(
1104 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); 985 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass()));
1105 986
1106 current_zoom_factor_ = zoom_factor; 987 current_zoom_factor_ = zoom_factor;
1107 } 988 }
1108 989
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 WebViewGuest* guest = 1135 WebViewGuest* guest =
1255 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1136 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1256 if (!guest) 1137 if (!guest)
1257 return; 1138 return;
1258 1139
1259 if (!allow) 1140 if (!allow)
1260 guest->Destroy(); 1141 guest->Destroy();
1261 } 1142 }
1262 1143
1263 } // namespace extensions 1144 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698