| 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 "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/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 "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 266 |
| 267 if (GetOpener()) { | 267 if (GetOpener()) { |
| 268 // We need to do a navigation here if the target URL has changed between | 268 // We need to do a navigation here if the target URL has changed between |
| 269 // the time the WebContents was created and the time it was attached. | 269 // the time the WebContents was created and the time it was attached. |
| 270 // We also need to do an initial navigation if a RenderView was never | 270 // We also need to do an initial navigation if a RenderView was never |
| 271 // created for the new window in cases where there is no referrer. | 271 // created for the new window in cases where there is no referrer. |
| 272 PendingWindowMap::iterator it = | 272 PendingWindowMap::iterator it = |
| 273 GetOpener()->pending_new_windows_.find(this); | 273 GetOpener()->pending_new_windows_.find(this); |
| 274 if (it != GetOpener()->pending_new_windows_.end()) { | 274 if (it != GetOpener()->pending_new_windows_.end()) { |
| 275 const NewWindowInfo& new_window_info = it->second; | 275 const NewWindowInfo& new_window_info = it->second; |
| 276 if (new_window_info.changed || !guest_web_contents()->HasOpener()) | 276 if (new_window_info.changed || !web_contents()->HasOpener()) |
| 277 NavigateGuest(new_window_info.url.spec()); | 277 NavigateGuest(new_window_info.url.spec()); |
| 278 } else { | 278 } else { |
| 279 NOTREACHED(); | 279 NOTREACHED(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 // Once a new guest is attached to the DOM of the embedder page, then the | 282 // Once a new guest is attached to the DOM of the embedder page, then the |
| 283 // lifetime of the new guest is no longer managed by the opener guest. | 283 // lifetime of the new guest is no longer managed by the opener guest. |
| 284 GetOpener()->pending_new_windows_.erase(this); | 284 GetOpener()->pending_new_windows_.erase(this); |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 void WebViewGuest::DidInitialize() { | 288 void WebViewGuest::DidInitialize() { |
| 289 script_executor_.reset( | 289 script_executor_.reset( |
| 290 new ScriptExecutor(guest_web_contents(), &script_observers_)); | 290 new ScriptExecutor(web_contents(), &script_observers_)); |
| 291 | 291 |
| 292 notification_registrar_.Add( | 292 notification_registrar_.Add(this, |
| 293 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 293 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 294 content::Source<WebContents>(guest_web_contents())); | 294 content::Source<WebContents>(web_contents())); |
| 295 | 295 |
| 296 notification_registrar_.Add( | 296 notification_registrar_.Add(this, |
| 297 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 297 content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 298 content::Source<WebContents>(guest_web_contents())); | 298 content::Source<WebContents>(web_contents())); |
| 299 | 299 |
| 300 if (web_view_guest_delegate_) | 300 if (web_view_guest_delegate_) |
| 301 web_view_guest_delegate_->OnDidInitialize(); | 301 web_view_guest_delegate_->OnDidInitialize(); |
| 302 AttachWebViewHelpers(guest_web_contents()); | 302 AttachWebViewHelpers(web_contents()); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { | 305 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) { |
| 306 if (web_view_guest_delegate_) | 306 if (web_view_guest_delegate_) |
| 307 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); | 307 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); |
| 308 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 308 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void WebViewGuest::DidStopLoading() { | 311 void WebViewGuest::DidStopLoading() { |
| 312 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 312 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 313 DispatchEventToEmbedder( | 313 DispatchEventToEmbedder( |
| 314 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 314 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void WebViewGuest::EmbedderDestroyed() { | 317 void WebViewGuest::EmbedderDestroyed() { |
| 318 if (web_view_guest_delegate_) | 318 if (web_view_guest_delegate_) |
| 319 web_view_guest_delegate_->OnEmbedderDestroyed(); | 319 web_view_guest_delegate_->OnEmbedderDestroyed(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void WebViewGuest::GuestDestroyed() { | 322 void WebViewGuest::GuestDestroyed() { |
| 323 // Clean up custom context menu items for this guest. | 323 // Clean up custom context menu items for this guest. |
| 324 if (web_view_guest_delegate_) | 324 if (web_view_guest_delegate_) |
| 325 web_view_guest_delegate_->OnGuestDestroyed(); | 325 web_view_guest_delegate_->OnGuestDestroyed(); |
| 326 RemoveWebViewStateFromIOThread(web_contents()); | 326 RemoveWebViewStateFromIOThread(web_contents()); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void WebViewGuest::GuestReady() { | 329 void WebViewGuest::GuestReady() { |
| 330 // The guest RenderView should always live in an isolated guest process. | 330 // The guest RenderView should always live in an isolated guest process. |
| 331 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 331 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
| 332 Send(new ExtensionMsg_SetFrameName( | 332 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); |
| 333 guest_web_contents()->GetRoutingID(), name_)); | |
| 334 } | 333 } |
| 335 | 334 |
| 336 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, | 335 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, |
| 337 const gfx::Size& new_size) { | 336 const gfx::Size& new_size) { |
| 338 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 337 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 339 args->SetInteger(webview::kOldHeight, old_size.height()); | 338 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 340 args->SetInteger(webview::kOldWidth, old_size.width()); | 339 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 341 args->SetInteger(webview::kNewHeight, new_size.height()); | 340 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 342 args->SetInteger(webview::kNewWidth, new_size.width()); | 341 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 343 DispatchEventToEmbedder( | 342 DispatchEventToEmbedder( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 // keyboard events. In that time, the embedder may have received and processed | 418 // keyboard events. In that time, the embedder may have received and processed |
| 420 // additional key events. This needs to be fixed as soon as possible. | 419 // additional key events. This needs to be fixed as soon as possible. |
| 421 // See http://crbug.com/229882. | 420 // See http://crbug.com/229882. |
| 422 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( | 421 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( |
| 423 web_contents(), event); | 422 web_contents(), event); |
| 424 } | 423 } |
| 425 | 424 |
| 426 void WebViewGuest::LoadProgressChanged(content::WebContents* source, | 425 void WebViewGuest::LoadProgressChanged(content::WebContents* source, |
| 427 double progress) { | 426 double progress) { |
| 428 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 427 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 429 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); | 428 args->SetString(guestview::kUrl, web_contents()->GetURL().spec()); |
| 430 args->SetDouble(webview::kProgress, progress); | 429 args->SetDouble(webview::kProgress, progress); |
| 431 DispatchEventToEmbedder( | 430 DispatchEventToEmbedder( |
| 432 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); | 431 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); |
| 433 } | 432 } |
| 434 | 433 |
| 435 void WebViewGuest::LoadAbort(bool is_top_level, | 434 void WebViewGuest::LoadAbort(bool is_top_level, |
| 436 const GURL& url, | 435 const GURL& url, |
| 437 const std::string& error_type) { | 436 const std::string& error_type) { |
| 438 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 437 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 439 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 438 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 454 ReportFrameNameChange(name); | 453 ReportFrameNameChange(name); |
| 455 } | 454 } |
| 456 | 455 |
| 457 void WebViewGuest::CreateNewGuestWebViewWindow( | 456 void WebViewGuest::CreateNewGuestWebViewWindow( |
| 458 const content::OpenURLParams& params) { | 457 const content::OpenURLParams& params) { |
| 459 GuestViewManager* guest_manager = | 458 GuestViewManager* guest_manager = |
| 460 GuestViewManager::FromBrowserContext(browser_context()); | 459 GuestViewManager::FromBrowserContext(browser_context()); |
| 461 // Set the attach params to use the same partition as the opener. | 460 // Set the attach params to use the same partition as the opener. |
| 462 // We pull the partition information from the site's URL, which is of the | 461 // We pull the partition information from the site's URL, which is of the |
| 463 // form guest://site/{persist}?{partition_name}. | 462 // form guest://site/{persist}?{partition_name}. |
| 464 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 463 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
| 465 const std::string storage_partition_id = | 464 const std::string storage_partition_id = |
| 466 GetStoragePartitionIdFromSiteURL(site_url); | 465 GetStoragePartitionIdFromSiteURL(site_url); |
| 467 base::DictionaryValue create_params; | 466 base::DictionaryValue create_params; |
| 468 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); | 467 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); |
| 469 | 468 |
| 470 guest_manager->CreateGuest(WebViewGuest::Type, | 469 guest_manager->CreateGuest(WebViewGuest::Type, |
| 471 embedder_extension_id(), | 470 embedder_extension_id(), |
| 472 embedder_web_contents(), | 471 embedder_web_contents(), |
| 473 create_params, | 472 create_params, |
| 474 base::Bind(&WebViewGuest::NewGuestWebViewCallback, | 473 base::Bind(&WebViewGuest::NewGuestWebViewCallback, |
| 475 base::Unretained(this), | 474 base::Unretained(this), |
| 476 params)); | 475 params)); |
| 477 } | 476 } |
| 478 | 477 |
| 479 void WebViewGuest::NewGuestWebViewCallback( | 478 void WebViewGuest::NewGuestWebViewCallback( |
| 480 const content::OpenURLParams& params, | 479 const content::OpenURLParams& params, |
| 481 content::WebContents* guest_web_contents) { | 480 content::WebContents* guest_web_contents) { |
| 482 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); | 481 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); |
| 483 new_guest->SetOpener(this); | 482 new_guest->SetOpener(this); |
| 484 | 483 |
| 485 // Take ownership of |new_guest|. | 484 // Take ownership of |new_guest|. |
| 486 pending_new_windows_.insert( | 485 pending_new_windows_.insert( |
| 487 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); | 486 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); |
| 488 | 487 |
| 489 // Request permission to show the new window. | 488 // Request permission to show the new window. |
| 490 RequestNewWindowPermission(params.disposition, gfx::Rect(), | 489 RequestNewWindowPermission(params.disposition, |
| 490 gfx::Rect(), |
| 491 params.user_gesture, | 491 params.user_gesture, |
| 492 new_guest->guest_web_contents()); | 492 new_guest->web_contents()); |
| 493 } | 493 } |
| 494 | 494 |
| 495 // TODO(fsamuel): Find a reliable way to test the 'responsive' and | 495 // TODO(fsamuel): Find a reliable way to test the 'responsive' and |
| 496 // 'unresponsive' events. | 496 // 'unresponsive' events. |
| 497 void WebViewGuest::RendererResponsive(content::WebContents* source) { | 497 void WebViewGuest::RendererResponsive(content::WebContents* source) { |
| 498 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 498 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 499 args->SetInteger(webview::kProcessId, | 499 args->SetInteger(webview::kProcessId, |
| 500 guest_web_contents()->GetRenderProcessHost()->GetID()); | 500 web_contents()->GetRenderProcessHost()->GetID()); |
| 501 DispatchEventToEmbedder( | 501 DispatchEventToEmbedder( |
| 502 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); | 502 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { | 505 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { |
| 506 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 506 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 507 args->SetInteger(webview::kProcessId, | 507 args->SetInteger(webview::kProcessId, |
| 508 guest_web_contents()->GetRenderProcessHost()->GetID()); | 508 web_contents()->GetRenderProcessHost()->GetID()); |
| 509 DispatchEventToEmbedder( | 509 DispatchEventToEmbedder( |
| 510 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); | 510 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); |
| 511 } | 511 } |
| 512 | 512 |
| 513 void WebViewGuest::Observe(int type, | 513 void WebViewGuest::Observe(int type, |
| 514 const content::NotificationSource& source, | 514 const content::NotificationSource& source, |
| 515 const content::NotificationDetails& details) { | 515 const content::NotificationDetails& details) { |
| 516 switch (type) { | 516 switch (type) { |
| 517 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { | 517 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { |
| 518 DCHECK_EQ(content::Source<WebContents>(source).ptr(), | 518 DCHECK_EQ(content::Source<WebContents>(source).ptr(), web_contents()); |
| 519 guest_web_contents()); | 519 if (content::Source<WebContents>(source).ptr() == web_contents()) |
| 520 if (content::Source<WebContents>(source).ptr() == guest_web_contents()) | |
| 521 LoadHandlerCalled(); | 520 LoadHandlerCalled(); |
| 522 break; | 521 break; |
| 523 } | 522 } |
| 524 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { | 523 case content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT: { |
| 525 DCHECK_EQ(content::Source<WebContents>(source).ptr(), | 524 DCHECK_EQ(content::Source<WebContents>(source).ptr(), web_contents()); |
| 526 guest_web_contents()); | |
| 527 content::ResourceRedirectDetails* resource_redirect_details = | 525 content::ResourceRedirectDetails* resource_redirect_details = |
| 528 content::Details<content::ResourceRedirectDetails>(details).ptr(); | 526 content::Details<content::ResourceRedirectDetails>(details).ptr(); |
| 529 bool is_top_level = resource_redirect_details->resource_type == | 527 bool is_top_level = resource_redirect_details->resource_type == |
| 530 content::RESOURCE_TYPE_MAIN_FRAME; | 528 content::RESOURCE_TYPE_MAIN_FRAME; |
| 531 LoadRedirect(resource_redirect_details->url, | 529 LoadRedirect(resource_redirect_details->url, |
| 532 resource_redirect_details->new_url, | 530 resource_redirect_details->new_url, |
| 533 is_top_level); | 531 is_top_level); |
| 534 break; | 532 break; |
| 535 } | 533 } |
| 536 default: | 534 default: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 552 if (web_view_guest_delegate_) | 550 if (web_view_guest_delegate_) |
| 553 web_view_guest_delegate_->Find(search_text, options, find_function); | 551 web_view_guest_delegate_->Find(search_text, options, find_function); |
| 554 } | 552 } |
| 555 | 553 |
| 556 void WebViewGuest::StopFinding(content::StopFindAction action) { | 554 void WebViewGuest::StopFinding(content::StopFindAction action) { |
| 557 if (web_view_guest_delegate_) | 555 if (web_view_guest_delegate_) |
| 558 web_view_guest_delegate_->StopFinding(action); | 556 web_view_guest_delegate_->StopFinding(action); |
| 559 } | 557 } |
| 560 | 558 |
| 561 void WebViewGuest::Go(int relative_index) { | 559 void WebViewGuest::Go(int relative_index) { |
| 562 guest_web_contents()->GetController().GoToOffset(relative_index); | 560 web_contents()->GetController().GoToOffset(relative_index); |
| 563 } | 561 } |
| 564 | 562 |
| 565 void WebViewGuest::Reload() { | 563 void WebViewGuest::Reload() { |
| 566 // TODO(fsamuel): Don't check for repost because we don't want to show | 564 // TODO(fsamuel): Don't check for repost because we don't want to show |
| 567 // Chromium's repost warning. We might want to implement a separate API | 565 // Chromium's repost warning. We might want to implement a separate API |
| 568 // for registering a callback if a repost is about to happen. | 566 // for registering a callback if a repost is about to happen. |
| 569 guest_web_contents()->GetController().Reload(false); | 567 web_contents()->GetController().Reload(false); |
| 570 } | 568 } |
| 571 | 569 |
| 572 void WebViewGuest::SetUserAgentOverride( | 570 void WebViewGuest::SetUserAgentOverride( |
| 573 const std::string& user_agent_override) { | 571 const std::string& user_agent_override) { |
| 574 if (!attached()) | 572 if (!attached()) |
| 575 return; | 573 return; |
| 576 is_overriding_user_agent_ = !user_agent_override.empty(); | 574 is_overriding_user_agent_ = !user_agent_override.empty(); |
| 577 if (is_overriding_user_agent_) { | 575 if (is_overriding_user_agent_) { |
| 578 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); | 576 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); |
| 579 } | 577 } |
| 580 guest_web_contents()->SetUserAgentOverride(user_agent_override); | 578 web_contents()->SetUserAgentOverride(user_agent_override); |
| 581 } | 579 } |
| 582 | 580 |
| 583 void WebViewGuest::Stop() { | 581 void WebViewGuest::Stop() { |
| 584 guest_web_contents()->Stop(); | 582 web_contents()->Stop(); |
| 585 } | 583 } |
| 586 | 584 |
| 587 void WebViewGuest::Terminate() { | 585 void WebViewGuest::Terminate() { |
| 588 content::RecordAction(UserMetricsAction("WebView.Guest.Terminate")); | 586 content::RecordAction(UserMetricsAction("WebView.Guest.Terminate")); |
| 589 base::ProcessHandle process_handle = | 587 base::ProcessHandle process_handle = |
| 590 guest_web_contents()->GetRenderProcessHost()->GetHandle(); | 588 web_contents()->GetRenderProcessHost()->GetHandle(); |
| 591 if (process_handle) | 589 if (process_handle) |
| 592 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); | 590 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); |
| 593 } | 591 } |
| 594 | 592 |
| 595 bool WebViewGuest::ClearData(const base::Time remove_since, | 593 bool WebViewGuest::ClearData(const base::Time remove_since, |
| 596 uint32 removal_mask, | 594 uint32 removal_mask, |
| 597 const base::Closure& callback) { | 595 const base::Closure& callback) { |
| 598 content::RecordAction(UserMetricsAction("WebView.Guest.ClearData")); | 596 content::RecordAction(UserMetricsAction("WebView.Guest.ClearData")); |
| 599 content::StoragePartition* partition = | 597 content::StoragePartition* partition = |
| 600 content::BrowserContext::GetStoragePartition( | 598 content::BrowserContext::GetStoragePartition( |
| 601 guest_web_contents()->GetBrowserContext(), | 599 web_contents()->GetBrowserContext(), |
| 602 guest_web_contents()->GetSiteInstance()); | 600 web_contents()->GetSiteInstance()); |
| 603 | 601 |
| 604 if (!partition) | 602 if (!partition) |
| 605 return false; | 603 return false; |
| 606 | 604 |
| 607 partition->ClearData( | 605 partition->ClearData( |
| 608 removal_mask, | 606 removal_mask, |
| 609 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, | 607 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, |
| 610 GURL(), | 608 GURL(), |
| 611 content::StoragePartition::OriginMatcherFunction(), | 609 content::StoragePartition::OriginMatcherFunction(), |
| 612 remove_since, | 610 remove_since, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 628 } | 626 } |
| 629 | 627 |
| 630 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 628 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 631 content::RenderFrameHost* render_frame_host, | 629 content::RenderFrameHost* render_frame_host, |
| 632 const GURL& url, | 630 const GURL& url, |
| 633 content::PageTransition transition_type) { | 631 content::PageTransition transition_type) { |
| 634 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 632 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 635 args->SetString(guestview::kUrl, url.spec()); | 633 args->SetString(guestview::kUrl, url.spec()); |
| 636 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 634 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| 637 args->SetInteger(webview::kInternalCurrentEntryIndex, | 635 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| 638 guest_web_contents()->GetController().GetCurrentEntryIndex()); | 636 web_contents()->GetController().GetCurrentEntryIndex()); |
| 639 args->SetInteger(webview::kInternalEntryCount, | 637 args->SetInteger(webview::kInternalEntryCount, |
| 640 guest_web_contents()->GetController().GetEntryCount()); | 638 web_contents()->GetController().GetEntryCount()); |
| 641 args->SetInteger(webview::kInternalProcessId, | 639 args->SetInteger(webview::kInternalProcessId, |
| 642 guest_web_contents()->GetRenderProcessHost()->GetID()); | 640 web_contents()->GetRenderProcessHost()->GetID()); |
| 643 DispatchEventToEmbedder( | 641 DispatchEventToEmbedder( |
| 644 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); | 642 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); |
| 645 if (web_view_guest_delegate_) { | 643 if (web_view_guest_delegate_) { |
| 646 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( | 644 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( |
| 647 !render_frame_host->GetParent()); | 645 !render_frame_host->GetParent()); |
| 648 } | 646 } |
| 649 } | 647 } |
| 650 | 648 |
| 651 void WebViewGuest::DidFailProvisionalLoad( | 649 void WebViewGuest::DidFailProvisionalLoad( |
| 652 content::RenderFrameHost* render_frame_host, | 650 content::RenderFrameHost* render_frame_host, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 IPC_END_MESSAGE_MAP() | 682 IPC_END_MESSAGE_MAP() |
| 685 return handled; | 683 return handled; |
| 686 } | 684 } |
| 687 | 685 |
| 688 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { | 686 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { |
| 689 if (web_view_guest_delegate_) | 687 if (web_view_guest_delegate_) |
| 690 web_view_guest_delegate_->OnRenderProcessGone(); | 688 web_view_guest_delegate_->OnRenderProcessGone(); |
| 691 | 689 |
| 692 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 690 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 693 args->SetInteger(webview::kProcessId, | 691 args->SetInteger(webview::kProcessId, |
| 694 guest_web_contents()->GetRenderProcessHost()->GetID()); | 692 web_contents()->GetRenderProcessHost()->GetID()); |
| 695 args->SetString(webview::kReason, TerminationStatusToString(status)); | 693 args->SetString(webview::kReason, TerminationStatusToString(status)); |
| 696 DispatchEventToEmbedder( | 694 DispatchEventToEmbedder( |
| 697 new GuestViewBase::Event(webview::kEventExit, args.Pass())); | 695 new GuestViewBase::Event(webview::kEventExit, args.Pass())); |
| 698 } | 696 } |
| 699 | 697 |
| 700 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 698 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
| 701 if (!attached()) | 699 if (!attached()) |
| 702 return; | 700 return; |
| 703 content::NavigationController& controller = | 701 content::NavigationController& controller = web_contents()->GetController(); |
| 704 guest_web_contents()->GetController(); | |
| 705 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 702 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
| 706 if (!entry) | 703 if (!entry) |
| 707 return; | 704 return; |
| 708 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 705 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
| 709 guest_web_contents()->GetController().Reload(false); | 706 web_contents()->GetController().Reload(false); |
| 710 } | 707 } |
| 711 | 708 |
| 712 void WebViewGuest::ReportFrameNameChange(const std::string& name) { | 709 void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
| 713 name_ = name; | 710 name_ = name; |
| 714 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 711 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 715 args->SetString(webview::kName, name); | 712 args->SetString(webview::kName, name); |
| 716 DispatchEventToEmbedder( | 713 DispatchEventToEmbedder( |
| 717 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); | 714 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
| 718 } | 715 } |
| 719 | 716 |
| 720 void WebViewGuest::LoadHandlerCalled() { | 717 void WebViewGuest::LoadHandlerCalled() { |
| 721 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 718 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 722 DispatchEventToEmbedder( | 719 DispatchEventToEmbedder( |
| 723 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); | 720 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); |
| 724 } | 721 } |
| 725 | 722 |
| 726 void WebViewGuest::LoadRedirect(const GURL& old_url, | 723 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 727 const GURL& new_url, | 724 const GURL& new_url, |
| 728 bool is_top_level) { | 725 bool is_top_level) { |
| 729 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 726 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 730 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 727 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 731 args->SetString(webview::kNewURL, new_url.spec()); | 728 args->SetString(webview::kNewURL, new_url.spec()); |
| 732 args->SetString(webview::kOldURL, old_url.spec()); | 729 args->SetString(webview::kOldURL, old_url.spec()); |
| 733 DispatchEventToEmbedder( | 730 DispatchEventToEmbedder( |
| 734 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); | 731 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); |
| 735 } | 732 } |
| 736 | 733 |
| 737 void WebViewGuest::PushWebViewStateToIOThread() { | 734 void WebViewGuest::PushWebViewStateToIOThread() { |
| 738 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 735 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
| 739 std::string partition_domain; | 736 std::string partition_domain; |
| 740 std::string partition_id; | 737 std::string partition_id; |
| 741 bool in_memory; | 738 bool in_memory; |
| 742 if (!GetGuestPartitionConfigForSite( | 739 if (!GetGuestPartitionConfigForSite( |
| 743 site_url, &partition_domain, &partition_id, &in_memory)) { | 740 site_url, &partition_domain, &partition_id, &in_memory)) { |
| 744 NOTREACHED(); | 741 NOTREACHED(); |
| 745 return; | 742 return; |
| 746 } | 743 } |
| 747 DCHECK(embedder_extension_id() == partition_domain); | 744 DCHECK(embedder_extension_id() == partition_domain); |
| 748 | 745 |
| 749 WebViewRendererState::WebViewInfo web_view_info; | 746 WebViewRendererState::WebViewInfo web_view_info; |
| 750 web_view_info.embedder_process_id = embedder_render_process_id(); | 747 web_view_info.embedder_process_id = embedder_render_process_id(); |
| 751 web_view_info.instance_id = view_instance_id(); | 748 web_view_info.instance_id = view_instance_id(); |
| 752 web_view_info.partition_id = partition_id; | 749 web_view_info.partition_id = partition_id; |
| 753 web_view_info.embedder_extension_id = embedder_extension_id(); | 750 web_view_info.embedder_extension_id = embedder_extension_id(); |
| 754 | 751 |
| 755 content::BrowserThread::PostTask( | 752 content::BrowserThread::PostTask( |
| 756 content::BrowserThread::IO, | 753 content::BrowserThread::IO, |
| 757 FROM_HERE, | 754 FROM_HERE, |
| 758 base::Bind(&WebViewRendererState::AddGuest, | 755 base::Bind(&WebViewRendererState::AddGuest, |
| 759 base::Unretained(WebViewRendererState::GetInstance()), | 756 base::Unretained(WebViewRendererState::GetInstance()), |
| 760 guest_web_contents()->GetRenderProcessHost()->GetID(), | 757 web_contents()->GetRenderProcessHost()->GetID(), |
| 761 guest_web_contents()->GetRoutingID(), | 758 web_contents()->GetRoutingID(), |
| 762 web_view_info)); | 759 web_view_info)); |
| 763 } | 760 } |
| 764 | 761 |
| 765 // static | 762 // static |
| 766 void WebViewGuest::RemoveWebViewStateFromIOThread( | 763 void WebViewGuest::RemoveWebViewStateFromIOThread( |
| 767 WebContents* web_contents) { | 764 WebContents* web_contents) { |
| 768 content::BrowserThread::PostTask( | 765 content::BrowserThread::PostTask( |
| 769 content::BrowserThread::IO, FROM_HERE, | 766 content::BrowserThread::IO, FROM_HERE, |
| 770 base::Bind( | 767 base::Bind( |
| 771 &WebViewRendererState::RemoveGuest, | 768 &WebViewRendererState::RemoveGuest, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 url.scheme()) && | 853 url.scheme()) && |
| 857 !url.SchemeIs(url::kAboutScheme)) || | 854 !url.SchemeIs(url::kAboutScheme)) || |
| 858 url.SchemeIs(url::kJavaScriptScheme); | 855 url.SchemeIs(url::kJavaScriptScheme); |
| 859 if (scheme_is_blocked || !url.is_valid()) { | 856 if (scheme_is_blocked || !url.is_valid()) { |
| 860 LoadAbort(true /* is_top_level */, url, | 857 LoadAbort(true /* is_top_level */, url, |
| 861 net::ErrorToShortString(net::ERR_ABORTED)); | 858 net::ErrorToShortString(net::ERR_ABORTED)); |
| 862 return; | 859 return; |
| 863 } | 860 } |
| 864 | 861 |
| 865 GURL validated_url(url); | 862 GURL validated_url(url); |
| 866 guest_web_contents()->GetRenderProcessHost()-> | 863 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
| 867 FilterURL(false, &validated_url); | |
| 868 // As guests do not swap processes on navigation, only navigations to | 864 // As guests do not swap processes on navigation, only navigations to |
| 869 // normal web URLs are supported. No protocol handlers are installed for | 865 // normal web URLs are supported. No protocol handlers are installed for |
| 870 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 866 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 871 // can be granted to the guest process. | 867 // can be granted to the guest process. |
| 872 LoadURLWithParams(validated_url, | 868 LoadURLWithParams(validated_url, |
| 873 content::Referrer(), | 869 content::Referrer(), |
| 874 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 870 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 875 guest_web_contents()); | 871 web_contents()); |
| 876 } | 872 } |
| 877 | 873 |
| 878 bool WebViewGuest::HandleKeyboardShortcuts( | 874 bool WebViewGuest::HandleKeyboardShortcuts( |
| 879 const content::NativeWebKeyboardEvent& event) { | 875 const content::NativeWebKeyboardEvent& event) { |
| 880 if (event.type != blink::WebInputEvent::RawKeyDown) | 876 if (event.type != blink::WebInputEvent::RawKeyDown) |
| 881 return false; | 877 return false; |
| 882 | 878 |
| 883 // If the user hits the escape key without any modifiers then unlock the | 879 // If the user hits the escape key without any modifiers then unlock the |
| 884 // mouse if necessary. | 880 // mouse if necessary. |
| 885 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && | 881 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && |
| 886 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { | 882 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { |
| 887 return guest_web_contents()->GotResponseToLockMouseRequest(false); | 883 return web_contents()->GotResponseToLockMouseRequest(false); |
| 888 } | 884 } |
| 889 | 885 |
| 890 #if defined(OS_MACOSX) | 886 #if defined(OS_MACOSX) |
| 891 if (event.modifiers != blink::WebInputEvent::MetaKey) | 887 if (event.modifiers != blink::WebInputEvent::MetaKey) |
| 892 return false; | 888 return false; |
| 893 | 889 |
| 894 if (event.windowsKeyCode == ui::VKEY_OEM_4) { | 890 if (event.windowsKeyCode == ui::VKEY_OEM_4) { |
| 895 Go(-1); | 891 Go(-1); |
| 896 return true; | 892 return true; |
| 897 } | 893 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 WebViewGuest* guest = | 1101 WebViewGuest* guest = |
| 1106 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1102 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1107 if (!guest) | 1103 if (!guest) |
| 1108 return; | 1104 return; |
| 1109 | 1105 |
| 1110 if (!allow) | 1106 if (!allow) |
| 1111 guest->Destroy(); | 1107 guest->Destroy(); |
| 1112 } | 1108 } |
| 1113 | 1109 |
| 1114 } // namespace extensions | 1110 } // namespace extensions |
| OLD | NEW |