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

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

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

Powered by Google App Engine
This is Rietveld 408576698