OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/guestview/webview/webview_guest.h" | 5 #include "chrome/browser/guestview/webview/webview_guest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 9 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
10 #include "chrome/browser/extensions/extension_renderer_state.h" | 10 #include "chrome/browser/extensions/extension_renderer_state.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 265 } |
266 | 266 |
267 AdViewGuest* WebViewGuest::AsAdView() { | 267 AdViewGuest* WebViewGuest::AsAdView() { |
268 return NULL; | 268 return NULL; |
269 } | 269 } |
270 | 270 |
271 void WebViewGuest::AddMessageToConsole(int32 level, | 271 void WebViewGuest::AddMessageToConsole(int32 level, |
272 const base::string16& message, | 272 const base::string16& message, |
273 int32 line_no, | 273 int32 line_no, |
274 const base::string16& source_id) { | 274 const base::string16& source_id) { |
275 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 275 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
276 // Log levels are from base/logging.h: LogSeverity. | 276 // Log levels are from base/logging.h: LogSeverity. |
277 args->SetInteger(webview::kLevel, level); | 277 args->SetInteger(webview::kLevel, level); |
278 args->SetString(webview::kMessage, message); | 278 args->SetString(webview::kMessage, message); |
279 args->SetInteger(webview::kLine, line_no); | 279 args->SetInteger(webview::kLine, line_no); |
280 args->SetString(webview::kSourceId, source_id); | 280 args->SetString(webview::kSourceId, source_id); |
281 DispatchEvent( | 281 DispatchEvent( |
282 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); | 282 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); |
283 } | 283 } |
284 | 284 |
285 void WebViewGuest::Close() { | 285 void WebViewGuest::Close() { |
286 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 286 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
287 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); | 287 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); |
288 } | 288 } |
289 | 289 |
290 void WebViewGuest::DidAttach() { | 290 void WebViewGuest::DidAttach() { |
291 if (pending_reload_on_attachment_) { | 291 if (pending_reload_on_attachment_) { |
292 pending_reload_on_attachment_ = false; | 292 pending_reload_on_attachment_ = false; |
293 guest_web_contents()->GetController().Reload(false); | 293 guest_web_contents()->GetController().Reload(false); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 void WebViewGuest::EmbedderDestroyed() { | 297 void WebViewGuest::EmbedderDestroyed() { |
298 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | 298 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
299 // reparenting of a <webview> within a single embedder. Right now, we keep | 299 // reparenting of a <webview> within a single embedder. Right now, we keep |
300 // around the browser state for the listener for the lifetime of the embedder. | 300 // around the browser state for the listener for the lifetime of the embedder. |
301 // Ideally, the lifetime of the listeners should match the lifetime of the | 301 // Ideally, the lifetime of the listeners should match the lifetime of the |
302 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move | 302 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move |
303 // the call to RemoveWebViewEventListenersOnIOThread back to | 303 // the call to RemoveWebViewEventListenersOnIOThread back to |
304 // WebViewGuest::WebContentsDestroyed. | 304 // WebViewGuest::WebContentsDestroyed. |
305 content::BrowserThread::PostTask( | 305 content::BrowserThread::PostTask( |
306 content::BrowserThread::IO, | 306 content::BrowserThread::IO, |
307 FROM_HERE, | 307 FROM_HERE, |
308 base::Bind( | 308 base::Bind( |
309 &RemoveWebViewEventListenersOnIOThread, | 309 &RemoveWebViewEventListenersOnIOThread, |
310 browser_context(), extension_id(), | 310 browser_context(), extension_id(), |
311 embedder_render_process_id(), | 311 embedder_render_process_id(), |
312 view_instance_id())); | 312 view_instance_id())); |
313 } | 313 } |
314 | 314 |
315 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { | 315 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { |
316 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 316 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
317 args->SetInteger(webview::kProcessId, | 317 args->SetInteger(webview::kProcessId, |
318 web_contents()->GetRenderProcessHost()->GetID()); | 318 web_contents()->GetRenderProcessHost()->GetID()); |
319 args->SetString(webview::kReason, TerminationStatusToString(status)); | 319 args->SetString(webview::kReason, TerminationStatusToString(status)); |
320 DispatchEvent( | 320 DispatchEvent( |
321 new GuestView::Event(webview::kEventExit, args.Pass())); | 321 new GuestView::Event(webview::kEventExit, args.Pass())); |
322 } | 322 } |
323 | 323 |
324 bool WebViewGuest::HandleKeyboardEvent( | 324 bool WebViewGuest::HandleKeyboardEvent( |
325 const content::NativeWebKeyboardEvent& event) { | 325 const content::NativeWebKeyboardEvent& event) { |
326 if (event.type != blink::WebInputEvent::RawKeyDown) | 326 if (event.type != blink::WebInputEvent::RawKeyDown) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 return CommandLine::ForCurrentProcess()->HasSwitch( | 367 return CommandLine::ForCurrentProcess()->HasSwitch( |
368 switches::kEnableBrowserPluginDragDrop); | 368 switches::kEnableBrowserPluginDragDrop); |
369 #endif | 369 #endif |
370 } | 370 } |
371 | 371 |
372 bool WebViewGuest::IsOverridingUserAgent() const { | 372 bool WebViewGuest::IsOverridingUserAgent() const { |
373 return is_overriding_user_agent_; | 373 return is_overriding_user_agent_; |
374 } | 374 } |
375 | 375 |
376 void WebViewGuest::LoadProgressed(double progress) { | 376 void WebViewGuest::LoadProgressed(double progress) { |
377 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 377 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
378 args->SetString(guestview::kUrl, web_contents()->GetURL().spec()); | 378 args->SetString(guestview::kUrl, web_contents()->GetURL().spec()); |
379 args->SetDouble(webview::kProgress, progress); | 379 args->SetDouble(webview::kProgress, progress); |
380 DispatchEvent(new GuestView::Event(webview::kEventLoadProgress, args.Pass())); | 380 DispatchEvent(new GuestView::Event(webview::kEventLoadProgress, args.Pass())); |
381 } | 381 } |
382 | 382 |
383 void WebViewGuest::LoadAbort(bool is_top_level, | 383 void WebViewGuest::LoadAbort(bool is_top_level, |
384 const GURL& url, | 384 const GURL& url, |
385 const std::string& error_type) { | 385 const std::string& error_type) { |
386 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 386 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
387 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 387 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
388 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); | 388 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
389 args->SetString(guestview::kReason, error_type); | 389 args->SetString(guestview::kReason, error_type); |
390 DispatchEvent(new GuestView::Event(webview::kEventLoadAbort, args.Pass())); | 390 DispatchEvent(new GuestView::Event(webview::kEventLoadAbort, args.Pass())); |
391 } | 391 } |
392 | 392 |
393 // TODO(fsamuel): Find a reliable way to test the 'responsive' and | 393 // TODO(fsamuel): Find a reliable way to test the 'responsive' and |
394 // 'unresponsive' events. | 394 // 'unresponsive' events. |
395 void WebViewGuest::RendererResponsive() { | 395 void WebViewGuest::RendererResponsive() { |
396 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 396 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
397 args->SetInteger(webview::kProcessId, | 397 args->SetInteger(webview::kProcessId, |
398 guest_web_contents()->GetRenderProcessHost()->GetID()); | 398 guest_web_contents()->GetRenderProcessHost()->GetID()); |
399 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); | 399 DispatchEvent(new GuestView::Event(webview::kEventResponsive, args.Pass())); |
400 } | 400 } |
401 | 401 |
402 void WebViewGuest::RendererUnresponsive() { | 402 void WebViewGuest::RendererUnresponsive() { |
403 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 403 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
404 args->SetInteger(webview::kProcessId, | 404 args->SetInteger(webview::kProcessId, |
405 guest_web_contents()->GetRenderProcessHost()->GetID()); | 405 guest_web_contents()->GetRenderProcessHost()->GetID()); |
406 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); | 406 DispatchEvent(new GuestView::Event(webview::kEventUnresponsive, args.Pass())); |
407 } | 407 } |
408 | 408 |
409 bool WebViewGuest::RequestPermission( | 409 bool WebViewGuest::RequestPermission( |
410 BrowserPluginPermissionType permission_type, | 410 BrowserPluginPermissionType permission_type, |
411 const base::DictionaryValue& request_info, | 411 const base::DictionaryValue& request_info, |
412 const PermissionResponseCallback& callback, | 412 const PermissionResponseCallback& callback, |
413 bool allowed_by_default) { | 413 bool allowed_by_default) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 WebViewGuest::~WebViewGuest() { | 563 WebViewGuest::~WebViewGuest() { |
564 } | 564 } |
565 | 565 |
566 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 566 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
567 int64 frame_id, | 567 int64 frame_id, |
568 const base::string16& frame_unique_name, | 568 const base::string16& frame_unique_name, |
569 bool is_main_frame, | 569 bool is_main_frame, |
570 const GURL& url, | 570 const GURL& url, |
571 content::PageTransition transition_type, | 571 content::PageTransition transition_type, |
572 content::RenderViewHost* render_view_host) { | 572 content::RenderViewHost* render_view_host) { |
573 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 573 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
574 args->SetString(guestview::kUrl, url.spec()); | 574 args->SetString(guestview::kUrl, url.spec()); |
575 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); | 575 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); |
576 args->SetInteger(webview::kInternalCurrentEntryIndex, | 576 args->SetInteger(webview::kInternalCurrentEntryIndex, |
577 web_contents()->GetController().GetCurrentEntryIndex()); | 577 web_contents()->GetController().GetCurrentEntryIndex()); |
578 args->SetInteger(webview::kInternalEntryCount, | 578 args->SetInteger(webview::kInternalEntryCount, |
579 web_contents()->GetController().GetEntryCount()); | 579 web_contents()->GetController().GetEntryCount()); |
580 args->SetInteger(webview::kInternalProcessId, | 580 args->SetInteger(webview::kInternalProcessId, |
581 web_contents()->GetRenderProcessHost()->GetID()); | 581 web_contents()->GetRenderProcessHost()->GetID()); |
582 DispatchEvent(new GuestView::Event(webview::kEventLoadCommit, args.Pass())); | 582 DispatchEvent(new GuestView::Event(webview::kEventLoadCommit, args.Pass())); |
583 } | 583 } |
(...skipping 13 matching lines...) Expand all Loading... |
597 } | 597 } |
598 | 598 |
599 void WebViewGuest::DidStartProvisionalLoadForFrame( | 599 void WebViewGuest::DidStartProvisionalLoadForFrame( |
600 int64 frame_id, | 600 int64 frame_id, |
601 int64 parent_frame_id, | 601 int64 parent_frame_id, |
602 bool is_main_frame, | 602 bool is_main_frame, |
603 const GURL& validated_url, | 603 const GURL& validated_url, |
604 bool is_error_page, | 604 bool is_error_page, |
605 bool is_iframe_srcdoc, | 605 bool is_iframe_srcdoc, |
606 content::RenderViewHost* render_view_host) { | 606 content::RenderViewHost* render_view_host) { |
607 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 607 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
608 args->SetString(guestview::kUrl, validated_url.spec()); | 608 args->SetString(guestview::kUrl, validated_url.spec()); |
609 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); | 609 args->SetBoolean(guestview::kIsTopLevel, is_main_frame); |
610 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); | 610 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); |
611 } | 611 } |
612 | 612 |
613 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 613 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
614 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 614 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
615 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); | 615 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); |
616 } | 616 } |
617 | 617 |
618 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { | 618 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { |
619 RemoveWebViewFromExtensionRendererState(web_contents); | 619 RemoveWebViewFromExtensionRendererState(web_contents); |
620 } | 620 } |
621 | 621 |
622 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 622 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
623 content::NavigationController& controller = | 623 content::NavigationController& controller = |
624 guest_web_contents()->GetController(); | 624 guest_web_contents()->GetController(); |
625 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 625 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
626 if (!entry) | 626 if (!entry) |
627 return; | 627 return; |
628 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 628 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
629 if (!attached()) { | 629 if (!attached()) { |
630 // We cannot reload now because all resource loads are suspended until | 630 // We cannot reload now because all resource loads are suspended until |
631 // attachment. | 631 // attachment. |
632 pending_reload_on_attachment_ = true; | 632 pending_reload_on_attachment_ = true; |
633 return; | 633 return; |
634 } | 634 } |
635 guest_web_contents()->GetController().Reload(false); | 635 guest_web_contents()->GetController().Reload(false); |
636 } | 636 } |
637 | 637 |
638 void WebViewGuest::LoadHandlerCalled() { | 638 void WebViewGuest::LoadHandlerCalled() { |
639 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 639 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
640 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); | 640 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); |
641 } | 641 } |
642 | 642 |
643 void WebViewGuest::LoadRedirect(const GURL& old_url, | 643 void WebViewGuest::LoadRedirect(const GURL& old_url, |
644 const GURL& new_url, | 644 const GURL& new_url, |
645 bool is_top_level) { | 645 bool is_top_level) { |
646 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 646 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
647 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 647 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
648 args->SetString(webview::kNewURL, new_url.spec()); | 648 args->SetString(webview::kNewURL, new_url.spec()); |
649 args->SetString(webview::kOldURL, old_url.spec()); | 649 args->SetString(webview::kOldURL, old_url.spec()); |
650 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); | 650 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); |
651 } | 651 } |
652 | 652 |
653 // static | 653 // static |
654 bool WebViewGuest::AllowChromeExtensionURLs() { | 654 bool WebViewGuest::AllowChromeExtensionURLs() { |
655 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 655 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
656 return channel <= chrome::VersionInfo::CHANNEL_DEV; | 656 return channel <= chrome::VersionInfo::CHANNEL_DEV; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 return GURL(src); | 708 return GURL(src); |
709 | 709 |
710 GURL default_url(base::StringPrintf("%s://%s/", | 710 GURL default_url(base::StringPrintf("%s://%s/", |
711 extensions::kExtensionScheme, | 711 extensions::kExtensionScheme, |
712 extension_id().c_str())); | 712 extension_id().c_str())); |
713 return default_url.Resolve(src); | 713 return default_url.Resolve(src); |
714 } | 714 } |
715 | 715 |
716 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 716 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
717 const gfx::Size& new_size) { | 717 const gfx::Size& new_size) { |
718 scoped_ptr<DictionaryValue> args(new DictionaryValue()); | 718 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
719 args->SetInteger(webview::kOldHeight, old_size.height()); | 719 args->SetInteger(webview::kOldHeight, old_size.height()); |
720 args->SetInteger(webview::kOldWidth, old_size.width()); | 720 args->SetInteger(webview::kOldWidth, old_size.width()); |
721 args->SetInteger(webview::kNewHeight, new_size.height()); | 721 args->SetInteger(webview::kNewHeight, new_size.height()); |
722 args->SetInteger(webview::kNewWidth, new_size.width()); | 722 args->SetInteger(webview::kNewWidth, new_size.width()); |
723 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); | 723 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); |
724 } | 724 } |
725 | 725 |
726 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() | 726 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo() |
727 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), | 727 : permission_type(BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN), |
728 allowed_by_default(false) { | 728 allowed_by_default(false) { |
729 } | 729 } |
730 | 730 |
731 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( | 731 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo( |
732 const PermissionResponseCallback& callback, | 732 const PermissionResponseCallback& callback, |
733 BrowserPluginPermissionType permission_type, | 733 BrowserPluginPermissionType permission_type, |
734 bool allowed_by_default) | 734 bool allowed_by_default) |
735 : callback(callback), | 735 : callback(callback), |
736 permission_type(permission_type), | 736 permission_type(permission_type), |
737 allowed_by_default(allowed_by_default) { | 737 allowed_by_default(allowed_by_default) { |
738 } | 738 } |
739 | 739 |
740 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { | 740 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { |
741 } | 741 } |
OLD | NEW |