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

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

Issue 611563002: GuestView: Use Weak Pointers Throughout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed bug where openers become NULL before WillDestroy Created 6 years, 2 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
« no previous file with comments | « extensions/browser/guest_view/web_view/web_view_guest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 const std::string storage_partition_id = 509 const std::string storage_partition_id =
510 GetStoragePartitionIdFromSiteURL(site_url); 510 GetStoragePartitionIdFromSiteURL(site_url);
511 base::DictionaryValue create_params; 511 base::DictionaryValue create_params;
512 create_params.SetString(webview::kStoragePartitionId, storage_partition_id); 512 create_params.SetString(webview::kStoragePartitionId, storage_partition_id);
513 513
514 guest_manager->CreateGuest(WebViewGuest::Type, 514 guest_manager->CreateGuest(WebViewGuest::Type,
515 embedder_extension_id(), 515 embedder_extension_id(),
516 embedder_web_contents(), 516 embedder_web_contents(),
517 create_params, 517 create_params,
518 base::Bind(&WebViewGuest::NewGuestWebViewCallback, 518 base::Bind(&WebViewGuest::NewGuestWebViewCallback,
519 base::Unretained(this), 519 weak_ptr_factory_.GetWeakPtr(),
520 params)); 520 params));
521 } 521 }
522 522
523 void WebViewGuest::NewGuestWebViewCallback( 523 void WebViewGuest::NewGuestWebViewCallback(
524 const content::OpenURLParams& params, 524 const content::OpenURLParams& params,
525 content::WebContents* guest_web_contents) { 525 content::WebContents* guest_web_contents) {
526 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents); 526 WebViewGuest* new_guest = WebViewGuest::FromWebContents(guest_web_contents);
527 new_guest->SetOpener(this); 527 new_guest->SetOpener(this);
528 528
529 // Take ownership of |new_guest|. 529 // Take ownership of |new_guest|.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 callback); 656 callback);
657 return true; 657 return true;
658 } 658 }
659 659
660 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 660 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
661 int guest_instance_id) 661 int guest_instance_id)
662 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 662 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
663 find_helper_(this), 663 find_helper_(this),
664 is_overriding_user_agent_(false), 664 is_overriding_user_agent_(false),
665 guest_opaque_(true), 665 guest_opaque_(true),
666 javascript_dialog_helper_(this) { 666 javascript_dialog_helper_(this),
667 weak_ptr_factory_(this) {
667 web_view_guest_delegate_.reset( 668 web_view_guest_delegate_.reset(
668 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 669 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
669 } 670 }
670 671
671 WebViewGuest::~WebViewGuest() { 672 WebViewGuest::~WebViewGuest() {
672 } 673 }
673 674
674 void WebViewGuest::DidCommitProvisionalLoadForFrame( 675 void WebViewGuest::DidCommitProvisionalLoadForFrame(
675 content::RenderFrameHost* render_frame_host, 676 content::RenderFrameHost* render_frame_host,
676 const GURL& url, 677 const GURL& url,
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 request_info.Set(webview::kStoragePartitionId, 1173 request_info.Set(webview::kStoragePartitionId,
1173 new base::StringValue(storage_partition_id)); 1174 new base::StringValue(storage_partition_id));
1174 request_info.Set( 1175 request_info.Set(
1175 webview::kWindowOpenDisposition, 1176 webview::kWindowOpenDisposition,
1176 new base::StringValue(WindowOpenDispositionToString(disposition))); 1177 new base::StringValue(WindowOpenDispositionToString(disposition)));
1177 1178
1178 web_view_permission_helper_-> 1179 web_view_permission_helper_->
1179 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, 1180 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW,
1180 request_info, 1181 request_info,
1181 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, 1182 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse,
1182 base::Unretained(this), 1183 weak_ptr_factory_.GetWeakPtr(),
1183 guest->guest_instance_id()), 1184 guest->guest_instance_id()),
1184 false /* allowed_by_default */); 1185 false /* allowed_by_default */);
1185 } 1186 }
1186 1187
1187 void WebViewGuest::DestroyUnattachedWindows() { 1188 void WebViewGuest::DestroyUnattachedWindows() {
1188 // Destroy() reaches in and removes the WebViewGuest from its opener's 1189 // Destroy() reaches in and removes the WebViewGuest from its opener's
1189 // pending_new_windows_ set. To avoid mutating the set while iterating, we 1190 // pending_new_windows_ set. To avoid mutating the set while iterating, we
1190 // create a copy of the pending new windows set and iterate over the copy. 1191 // create a copy of the pending new windows set and iterate over the copy.
1191 PendingWindowMap pending_new_windows(pending_new_windows_); 1192 PendingWindowMap pending_new_windows(pending_new_windows_);
1192 // Clean up unattached new windows opened by this guest. 1193 // Clean up unattached new windows opened by this guest.
(...skipping 24 matching lines...) Expand all
1217 WebViewGuest* guest = 1218 WebViewGuest* guest =
1218 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1219 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1219 if (!guest) 1220 if (!guest)
1220 return; 1221 return;
1221 1222
1222 if (!allow) 1223 if (!allow)
1223 guest->Destroy(); 1224 guest->Destroy();
1224 } 1225 }
1225 1226
1226 } // namespace extensions 1227 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/web_view/web_view_guest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698