| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 #if defined(ENABLE_FULL_PRINTING) | 174 #if defined(ENABLE_FULL_PRINTING) |
| 175 printing::PrintViewManager::CreateForWebContents(contents); | 175 printing::PrintViewManager::CreateForWebContents(contents); |
| 176 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); | 176 printing::PrintPreviewMessageHandler::CreateForWebContents(contents); |
| 177 #else | 177 #else |
| 178 printing::PrintViewManagerBasic::CreateForWebContents(contents); | 178 printing::PrintViewManagerBasic::CreateForWebContents(contents); |
| 179 #endif // defined(ENABLE_FULL_PRINTING) | 179 #endif // defined(ENABLE_FULL_PRINTING) |
| 180 #endif // defined(ENABLE_PRINTING) | 180 #endif // defined(ENABLE_PRINTING) |
| 181 PDFTabHelper::CreateForWebContents(contents); | 181 PDFTabHelper::CreateForWebContents(contents); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ParsePartitionParam(const base::DictionaryValue& create_params, |
| 185 std::string* storage_partition_id, |
| 186 bool* persist_storage) { |
| 187 std::string partition_str; |
| 188 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { |
| 189 return; |
| 190 } |
| 191 |
| 192 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
| 193 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely |
| 194 // remove the prefix without splicing in the middle of a multi-byte codepoint. |
| 195 // We can use the rest of the string as UTF-8 encoded one. |
| 196 if (StartsWithASCII(partition_str, "persist:", true)) { |
| 197 size_t index = partition_str.find(":"); |
| 198 CHECK(index != std::string::npos); |
| 199 // It is safe to do index + 1, since we tested for the full prefix above. |
| 200 *storage_partition_id = partition_str.substr(index + 1); |
| 201 |
| 202 if (storage_partition_id->empty()) { |
| 203 // TODO(lazyboy): Better way to deal with this error. |
| 204 return; |
| 205 } |
| 206 *persist_storage = true; |
| 207 } else { |
| 208 *storage_partition_id = partition_str; |
| 209 *persist_storage = false; |
| 210 } |
| 211 } |
| 212 |
| 184 } // namespace | 213 } // namespace |
| 185 | 214 |
| 186 WebViewGuest::WebViewGuest(int guest_instance_id, | 215 WebViewGuest::WebViewGuest(int guest_instance_id) |
| 187 WebContents* guest_web_contents, | 216 : GuestView<WebViewGuest>(guest_instance_id), |
| 188 const std::string& embedder_extension_id) | |
| 189 : GuestView<WebViewGuest>(guest_instance_id), | |
| 190 script_executor_(new extensions::ScriptExecutor(guest_web_contents, | |
| 191 &script_observers_)), | |
| 192 pending_context_menu_request_id_(0), | 217 pending_context_menu_request_id_(0), |
| 193 next_permission_request_id_(0), | 218 next_permission_request_id_(0), |
| 194 is_overriding_user_agent_(false), | 219 is_overriding_user_agent_(false), |
| 195 main_frame_id_(0), | 220 main_frame_id_(0), |
| 196 chromevox_injected_(false), | 221 chromevox_injected_(false), |
| 197 find_helper_(this), | 222 find_helper_(this), |
| 198 javascript_dialog_helper_(this) { | 223 javascript_dialog_helper_(this) { |
| 199 Init(guest_web_contents, embedder_extension_id); | |
| 200 notification_registrar_.Add( | |
| 201 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 202 content::Source<WebContents>(guest_web_contents)); | |
| 203 | |
| 204 notification_registrar_.Add( | |
| 205 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | |
| 206 content::Source<WebContents>(guest_web_contents)); | |
| 207 | |
| 208 #if defined(OS_CHROMEOS) | |
| 209 chromeos::AccessibilityManager* accessibility_manager = | |
| 210 chromeos::AccessibilityManager::Get(); | |
| 211 CHECK(accessibility_manager); | |
| 212 accessibility_subscription_ = accessibility_manager->RegisterCallback( | |
| 213 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, | |
| 214 base::Unretained(this))); | |
| 215 #endif | |
| 216 | |
| 217 AttachWebViewHelpers(guest_web_contents); | |
| 218 } | 224 } |
| 219 | 225 |
| 220 // static | 226 // static |
| 221 bool WebViewGuest::GetGuestPartitionConfigForSite( | 227 bool WebViewGuest::GetGuestPartitionConfigForSite( |
| 222 const GURL& site, | 228 const GURL& site, |
| 223 std::string* partition_domain, | 229 std::string* partition_domain, |
| 224 std::string* partition_name, | 230 std::string* partition_name, |
| 225 bool* in_memory) { | 231 bool* in_memory) { |
| 226 if (!site.SchemeIs(content::kGuestScheme)) | 232 if (!site.SchemeIs(content::kGuestScheme)) |
| 227 return false; | 233 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 246 // static | 252 // static |
| 247 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 253 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 248 WebViewGuest* guest = FromWebContents(contents); | 254 WebViewGuest* guest = FromWebContents(contents); |
| 249 if (!guest) | 255 if (!guest) |
| 250 return guestview::kInstanceIDNone; | 256 return guestview::kInstanceIDNone; |
| 251 | 257 |
| 252 return guest->view_instance_id(); | 258 return guest->view_instance_id(); |
| 253 } | 259 } |
| 254 | 260 |
| 255 // static | 261 // static |
| 256 void WebViewGuest::ParsePartitionParam( | |
| 257 const base::DictionaryValue* extra_params, | |
| 258 std::string* storage_partition_id, | |
| 259 bool* persist_storage) { | |
| 260 std::string partition_str; | |
| 261 if (!extra_params->GetString(webview::kStoragePartitionId, &partition_str)) { | |
| 262 return; | |
| 263 } | |
| 264 | |
| 265 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | |
| 266 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | |
| 267 // remove the prefix without splicing in the middle of a multi-byte codepoint. | |
| 268 // We can use the rest of the string as UTF-8 encoded one. | |
| 269 if (StartsWithASCII(partition_str, "persist:", true)) { | |
| 270 size_t index = partition_str.find(":"); | |
| 271 CHECK(index != std::string::npos); | |
| 272 // It is safe to do index + 1, since we tested for the full prefix above. | |
| 273 *storage_partition_id = partition_str.substr(index + 1); | |
| 274 | |
| 275 if (storage_partition_id->empty()) { | |
| 276 // TODO(lazyboy): Better way to deal with this error. | |
| 277 return; | |
| 278 } | |
| 279 *persist_storage = true; | |
| 280 } else { | |
| 281 *storage_partition_id = partition_str; | |
| 282 *persist_storage = false; | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 // static | |
| 287 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, | 262 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, |
| 288 bool allow) { | 263 bool allow) { |
| 289 if (allow) { | 264 if (allow) { |
| 290 // Note that |allow| == true means the embedder explicitly allowed the | 265 // Note that |allow| == true means the embedder explicitly allowed the |
| 291 // request. For some requests they might still fail. An example of such | 266 // request. For some requests they might still fail. An example of such |
| 292 // scenario would be: an embedder allows geolocation request but doesn't | 267 // scenario would be: an embedder allows geolocation request but doesn't |
| 293 // have geolocation access on its own. | 268 // have geolocation access on its own. |
| 294 switch (info.permission_type) { | 269 switch (info.permission_type) { |
| 295 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: | 270 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: |
| 296 content::RecordAction( | 271 content::RecordAction( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 // TODO(lazyboy): We need to expose some kind of enum equivalent of | 350 // TODO(lazyboy): We need to expose some kind of enum equivalent of |
| 376 // |command_id| instead of plain integers. | 351 // |command_id| instead of plain integers. |
| 377 item_value->SetInteger(webview::kMenuItemCommandId, | 352 item_value->SetInteger(webview::kMenuItemCommandId, |
| 378 menu_model.GetCommandIdAt(i)); | 353 menu_model.GetCommandIdAt(i)); |
| 379 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 354 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
| 380 items->Append(item_value); | 355 items->Append(item_value); |
| 381 } | 356 } |
| 382 return items.Pass(); | 357 return items.Pass(); |
| 383 } | 358 } |
| 384 | 359 |
| 360 void WebViewGuest::CreateWebContents( |
| 361 const std::string& embedder_extension_id, |
| 362 int embedder_render_process_id, |
| 363 const base::DictionaryValue& create_params, |
| 364 const WebContentsCreatedCallback& callback) { |
| 365 content::RenderProcessHost* embedder_render_process_host = |
| 366 content::RenderProcessHost::FromID(embedder_render_process_id); |
| 367 std::string storage_partition_id; |
| 368 bool persist_storage = false; |
| 369 std::string storage_partition_string; |
| 370 ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); |
| 371 // Validate that the partition id coming from the renderer is valid UTF-8, |
| 372 // since we depend on this in other parts of the code, such as FilePath |
| 373 // creation. If the validation fails, treat it as a bad message and kill the |
| 374 // renderer process. |
| 375 if (!base::IsStringUTF8(storage_partition_id)) { |
| 376 content::RecordAction( |
| 377 base::UserMetricsAction("BadMessageTerminate_BPGM")); |
| 378 base::KillProcess( |
| 379 embedder_render_process_host->GetHandle(), |
| 380 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 381 return; |
| 382 } |
| 383 std::string url_encoded_partition = net::EscapeQueryParamValue( |
| 384 storage_partition_id, false); |
| 385 // The SiteInstance of a given webview tag is based on the fact that it's |
| 386 // a guest process in addition to which platform application the tag |
| 387 // belongs to and what storage partition is in use, rather than the URL |
| 388 // that the tag is being navigated to. |
| 389 GURL guest_site(base::StringPrintf("%s://%s/%s?%s", |
| 390 content::kGuestScheme, |
| 391 embedder_extension_id.c_str(), |
| 392 persist_storage ? "persist" : "", |
| 393 url_encoded_partition.c_str())); |
| 394 |
| 395 // If we already have a webview tag in the same app using the same storage |
| 396 // partition, we should use the same SiteInstance so the existing tag and |
| 397 // the new tag can script each other. |
| 398 GuestViewManager* guest_view_manager = |
| 399 GuestViewManager::FromBrowserContext( |
| 400 embedder_render_process_host->GetBrowserContext()); |
| 401 content::SiteInstance* guest_site_instance = |
| 402 guest_view_manager->GetGuestSiteInstance(guest_site); |
| 403 if (!guest_site_instance) { |
| 404 // Create the SiteInstance in a new BrowsingInstance, which will ensure |
| 405 // that webview tags are also not allowed to send messages across |
| 406 // different partitions. |
| 407 guest_site_instance = content::SiteInstance::CreateForURL( |
| 408 embedder_render_process_host->GetBrowserContext(), guest_site); |
| 409 } |
| 410 WebContents::CreateParams params( |
| 411 embedder_render_process_host->GetBrowserContext(), |
| 412 guest_site_instance); |
| 413 params.guest_delegate = this; |
| 414 callback.Run(WebContents::Create(params)); |
| 415 } |
| 416 |
| 385 void WebViewGuest::DidAttachToEmbedder() { | 417 void WebViewGuest::DidAttachToEmbedder() { |
| 386 std::string name; | 418 std::string name; |
| 387 if (extra_params()->GetString(webview::kName, &name)) { | 419 if (extra_params()->GetString(webview::kName, &name)) { |
| 388 // If the guest window's name is empty, then the WebView tag's name is | 420 // If the guest window's name is empty, then the WebView tag's name is |
| 389 // assigned. Otherwise, the guest window's name takes precedence over the | 421 // assigned. Otherwise, the guest window's name takes precedence over the |
| 390 // WebView tag's name. | 422 // WebView tag's name. |
| 391 if (name_.empty()) | 423 if (name_.empty()) |
| 392 name_ = name; | 424 name_ = name; |
| 393 } | 425 } |
| 394 ReportFrameNameChange(name_); | 426 ReportFrameNameChange(name_); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 419 } else { | 451 } else { |
| 420 NOTREACHED(); | 452 NOTREACHED(); |
| 421 } | 453 } |
| 422 | 454 |
| 423 // Once a new guest is attached to the DOM of the embedder page, then the | 455 // Once a new guest is attached to the DOM of the embedder page, then the |
| 424 // lifetime of the new guest is no longer managed by the opener guest. | 456 // lifetime of the new guest is no longer managed by the opener guest. |
| 425 GetOpener()->pending_new_windows_.erase(this); | 457 GetOpener()->pending_new_windows_.erase(this); |
| 426 } | 458 } |
| 427 } | 459 } |
| 428 | 460 |
| 461 void WebViewGuest::DidInitialize() { |
| 462 script_executor_.reset(new extensions::ScriptExecutor(guest_web_contents(), |
| 463 &script_observers_)); |
| 464 |
| 465 notification_registrar_.Add( |
| 466 this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 467 content::Source<WebContents>(guest_web_contents())); |
| 468 |
| 469 notification_registrar_.Add( |
| 470 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 471 content::Source<WebContents>(guest_web_contents())); |
| 472 |
| 473 #if defined(OS_CHROMEOS) |
| 474 chromeos::AccessibilityManager* accessibility_manager = |
| 475 chromeos::AccessibilityManager::Get(); |
| 476 CHECK(accessibility_manager); |
| 477 accessibility_subscription_ = accessibility_manager->RegisterCallback( |
| 478 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, |
| 479 base::Unretained(this))); |
| 480 #endif |
| 481 |
| 482 AttachWebViewHelpers(guest_web_contents()); |
| 483 } |
| 484 |
| 485 |
| 429 void WebViewGuest::DidStopLoading() { | 486 void WebViewGuest::DidStopLoading() { |
| 430 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 487 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 431 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 488 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 432 } | 489 } |
| 433 | 490 |
| 434 void WebViewGuest::EmbedderDestroyed() { | 491 void WebViewGuest::EmbedderDestroyed() { |
| 435 // TODO(fsamuel): WebRequest event listeners for <webview> should survive | 492 // TODO(fsamuel): WebRequest event listeners for <webview> should survive |
| 436 // reparenting of a <webview> within a single embedder. Right now, we keep | 493 // reparenting of a <webview> within a single embedder. Right now, we keep |
| 437 // around the browser state for the listener for the lifetime of the embedder. | 494 // around the browser state for the listener for the lifetime of the embedder. |
| 438 // Ideally, the lifetime of the listeners should match the lifetime of the | 495 // Ideally, the lifetime of the listeners should match the lifetime of the |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 const std::string& name) { | 620 const std::string& name) { |
| 564 if (!is_top_level) | 621 if (!is_top_level) |
| 565 return; | 622 return; |
| 566 | 623 |
| 567 if (name_ == name) | 624 if (name_ == name) |
| 568 return; | 625 return; |
| 569 | 626 |
| 570 ReportFrameNameChange(name); | 627 ReportFrameNameChange(name); |
| 571 } | 628 } |
| 572 | 629 |
| 573 WebViewGuest* WebViewGuest::CreateNewGuestWindow( | 630 WebViewGuest* WebViewGuest::CreateNewGuestWebViewWindow( |
| 574 const content::OpenURLParams& params) { | 631 const content::OpenURLParams& params) { |
| 575 GuestViewManager* guest_manager = | 632 GuestViewManager* guest_manager = |
| 576 GuestViewManager::FromBrowserContext(browser_context()); | 633 GuestViewManager::FromBrowserContext(browser_context()); |
| 577 // Allocate a new instance ID for the new guest. | |
| 578 int instance_id = guest_manager->GetNextInstanceID(); | |
| 579 | |
| 580 // Set the attach params to use the same partition as the opener. | 634 // Set the attach params to use the same partition as the opener. |
| 581 // We pull the partition information from the site's URL, which is of the | 635 // We pull the partition information from the site's URL, which is of the |
| 582 // form guest://site/{persist}?{partition_name}. | 636 // form guest://site/{persist}?{partition_name}. |
| 583 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 637 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
| 584 scoped_ptr<base::DictionaryValue> create_params(extra_params()->DeepCopy()); | |
| 585 const std::string storage_partition_id = | 638 const std::string storage_partition_id = |
| 586 GetStoragePartitionIdFromSiteURL(site_url); | 639 GetStoragePartitionIdFromSiteURL(site_url); |
| 587 create_params->SetString(webview::kStoragePartitionId, storage_partition_id); | 640 base::DictionaryValue create_params; |
| 641 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); |
| 588 | 642 |
| 589 WebContents* new_guest_web_contents = | 643 WebContents* new_guest_web_contents = |
| 590 guest_manager->CreateGuest(guest_web_contents()->GetSiteInstance(), | 644 guest_manager->CreateGuest( |
| 591 instance_id, | 645 WebViewGuest::Type, |
| 592 create_params.Pass()); | 646 embedder_extension_id(), |
| 647 embedder_web_contents()->GetRenderProcessHost()->GetID(), |
| 648 create_params); |
| 593 WebViewGuest* new_guest = | 649 WebViewGuest* new_guest = |
| 594 WebViewGuest::FromWebContents(new_guest_web_contents); | 650 WebViewGuest::FromWebContents(new_guest_web_contents); |
| 595 new_guest->SetOpener(this); | 651 new_guest->SetOpener(this); |
| 596 | 652 |
| 597 // Take ownership of |new_guest|. | 653 // Take ownership of |new_guest|. |
| 598 pending_new_windows_.insert( | 654 pending_new_windows_.insert( |
| 599 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); | 655 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); |
| 600 | 656 |
| 601 // Request permission to show the new window. | 657 // Request permission to show the new window. |
| 602 RequestNewWindowPermission(params.disposition, gfx::Rect(), | 658 RequestNewWindowPermission(params.disposition, gfx::Rect(), |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 WebContents* web_contents) { | 1170 WebContents* web_contents) { |
| 1115 content::BrowserThread::PostTask( | 1171 content::BrowserThread::PostTask( |
| 1116 content::BrowserThread::IO, FROM_HERE, | 1172 content::BrowserThread::IO, FROM_HERE, |
| 1117 base::Bind( | 1173 base::Bind( |
| 1118 &ExtensionRendererState::RemoveWebView, | 1174 &ExtensionRendererState::RemoveWebView, |
| 1119 base::Unretained(ExtensionRendererState::GetInstance()), | 1175 base::Unretained(ExtensionRendererState::GetInstance()), |
| 1120 web_contents->GetRenderProcessHost()->GetID(), | 1176 web_contents->GetRenderProcessHost()->GetID(), |
| 1121 web_contents->GetRoutingID())); | 1177 web_contents->GetRoutingID())); |
| 1122 } | 1178 } |
| 1123 | 1179 |
| 1180 content::WebContents* WebViewGuest::CreateNewGuestWindow( |
| 1181 const content::WebContents::CreateParams& create_params) { |
| 1182 GuestViewManager* guest_manager = |
| 1183 GuestViewManager::FromBrowserContext(browser_context()); |
| 1184 return guest_manager->CreateGuestWithWebContentsParams( |
| 1185 WebViewGuest::Type, |
| 1186 embedder_extension_id(), |
| 1187 embedder_web_contents()->GetRenderProcessHost()->GetID(), |
| 1188 create_params); |
| 1189 } |
| 1190 |
| 1124 void WebViewGuest::SizeChanged(const gfx::Size& old_size, | 1191 void WebViewGuest::SizeChanged(const gfx::Size& old_size, |
| 1125 const gfx::Size& new_size) { | 1192 const gfx::Size& new_size) { |
| 1126 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1193 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1127 args->SetInteger(webview::kOldHeight, old_size.height()); | 1194 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 1128 args->SetInteger(webview::kOldWidth, old_size.width()); | 1195 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 1129 args->SetInteger(webview::kNewHeight, new_size.height()); | 1196 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 1130 args->SetInteger(webview::kNewWidth, new_size.width()); | 1197 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 1131 DispatchEvent( | 1198 DispatchEvent( |
| 1132 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | 1199 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
| 1133 } | 1200 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 new_window_info.changed = new_window_info.url != info.url; | 1534 new_window_info.changed = new_window_info.url != info.url; |
| 1468 it->second = new_window_info; | 1535 it->second = new_window_info; |
| 1469 return NULL; | 1536 return NULL; |
| 1470 } | 1537 } |
| 1471 if (params.disposition == CURRENT_TAB) { | 1538 if (params.disposition == CURRENT_TAB) { |
| 1472 // This can happen for cross-site redirects. | 1539 // This can happen for cross-site redirects. |
| 1473 LoadURLWithParams(params.url, params.referrer, params.transition, source); | 1540 LoadURLWithParams(params.url, params.referrer, params.transition, source); |
| 1474 return source; | 1541 return source; |
| 1475 } | 1542 } |
| 1476 | 1543 |
| 1477 return CreateNewGuestWindow(params)->guest_web_contents(); | 1544 return CreateNewGuestWebViewWindow(params)->guest_web_contents(); |
| 1478 } | 1545 } |
| 1479 | 1546 |
| 1480 void WebViewGuest::WebContentsCreated(WebContents* source_contents, | 1547 void WebViewGuest::WebContentsCreated(WebContents* source_contents, |
| 1481 int opener_render_frame_id, | 1548 int opener_render_frame_id, |
| 1482 const base::string16& frame_name, | 1549 const base::string16& frame_name, |
| 1483 const GURL& target_url, | 1550 const GURL& target_url, |
| 1484 content::WebContents* new_contents) { | 1551 content::WebContents* new_contents) { |
| 1485 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); | 1552 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); |
| 1486 CHECK(guest); | 1553 CHECK(guest); |
| 1487 guest->SetOpener(this); | 1554 guest->SetOpener(this); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 base::DictionaryValue request_info; | 1593 base::DictionaryValue request_info; |
| 1527 request_info.Set(webview::kInitialHeight, | 1594 request_info.Set(webview::kInitialHeight, |
| 1528 base::Value::CreateIntegerValue(initial_bounds.height())); | 1595 base::Value::CreateIntegerValue(initial_bounds.height())); |
| 1529 request_info.Set(webview::kInitialWidth, | 1596 request_info.Set(webview::kInitialWidth, |
| 1530 base::Value::CreateIntegerValue(initial_bounds.width())); | 1597 base::Value::CreateIntegerValue(initial_bounds.width())); |
| 1531 request_info.Set(webview::kTargetURL, | 1598 request_info.Set(webview::kTargetURL, |
| 1532 base::Value::CreateStringValue(new_window_info.url.spec())); | 1599 base::Value::CreateStringValue(new_window_info.url.spec())); |
| 1533 request_info.Set(webview::kName, | 1600 request_info.Set(webview::kName, |
| 1534 base::Value::CreateStringValue(new_window_info.name)); | 1601 base::Value::CreateStringValue(new_window_info.name)); |
| 1535 request_info.Set(webview::kWindowID, | 1602 request_info.Set(webview::kWindowID, |
| 1536 base::Value::CreateIntegerValue(guest->guest_instance_id())); | 1603 base::Value::CreateIntegerValue( |
| 1604 guest->GetGuestInstanceID())); |
| 1537 // We pass in partition info so that window-s created through newwindow | 1605 // We pass in partition info so that window-s created through newwindow |
| 1538 // API can use it to set their partition attribute. | 1606 // API can use it to set their partition attribute. |
| 1539 request_info.Set(webview::kStoragePartitionId, | 1607 request_info.Set(webview::kStoragePartitionId, |
| 1540 base::Value::CreateStringValue(storage_partition_id)); | 1608 base::Value::CreateStringValue(storage_partition_id)); |
| 1541 request_info.Set(webview::kWindowOpenDisposition, | 1609 request_info.Set(webview::kWindowOpenDisposition, |
| 1542 base::Value::CreateStringValue( | 1610 base::Value::CreateStringValue( |
| 1543 WindowOpenDispositionToString(disposition))); | 1611 WindowOpenDispositionToString(disposition))); |
| 1544 | 1612 |
| 1545 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, | 1613 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, |
| 1546 request_info, | 1614 request_info, |
| 1547 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, | 1615 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, |
| 1548 base::Unretained(this), | 1616 base::Unretained(this), |
| 1549 guest->guest_instance_id()), | 1617 guest->GetGuestInstanceID()), |
| 1550 false /* allowed_by_default */); | 1618 false /* allowed_by_default */); |
| 1551 } | 1619 } |
| 1552 | 1620 |
| 1553 void WebViewGuest::DestroyUnattachedWindows() { | 1621 void WebViewGuest::DestroyUnattachedWindows() { |
| 1554 // Destroy() reaches in and removes the WebViewGuest from its opener's | 1622 // Destroy() reaches in and removes the WebViewGuest from its opener's |
| 1555 // pending_new_windows_ set. To avoid mutating the set while iterating, we | 1623 // pending_new_windows_ set. To avoid mutating the set while iterating, we |
| 1556 // create a copy of the pending new windows set and iterate over the copy. | 1624 // create a copy of the pending new windows set and iterate over the copy. |
| 1557 PendingWindowMap pending_new_windows(pending_new_windows_); | 1625 PendingWindowMap pending_new_windows(pending_new_windows_); |
| 1558 // Clean up unattached new windows opened by this guest. | 1626 // Clean up unattached new windows opened by this guest. |
| 1559 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); | 1627 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1582 bool allow, | 1650 bool allow, |
| 1583 const std::string& user_input) { | 1651 const std::string& user_input) { |
| 1584 WebViewGuest* guest = | 1652 WebViewGuest* guest = |
| 1585 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1653 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1586 if (!guest) | 1654 if (!guest) |
| 1587 return; | 1655 return; |
| 1588 | 1656 |
| 1589 if (!allow) | 1657 if (!allow) |
| 1590 guest->Destroy(); | 1658 guest->Destroy(); |
| 1591 } | 1659 } |
| OLD | NEW |