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

Side by Side Diff: content/browser/browser_plugin/test_browser_plugin_guest_delegate.cc

Issue 306003002: Move guest lifetime management to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed content_browsertests crash 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 "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h" 5 #include "content/browser/browser_plugin/test_browser_plugin_guest_delegate.h"
6 6
7 #include "content/browser/browser_plugin/browser_plugin_guest.h" 7 #include "content/browser/browser_plugin/browser_plugin_guest.h"
8 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/browser/navigation_controller.h" 9 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/common/referrer.h" 10 #include "content/public/common/referrer.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 // This observer ensures that the TestBrowserPluginGuestDelegate destroys itself
15 // when its embedder goes away.
16 class TestBrowserPluginGuestDelegate::EmbedderWebContentsObserver :
17 public WebContentsObserver {
18 public:
19 explicit EmbedderWebContentsObserver(TestBrowserPluginGuestDelegate* guest)
20 : WebContentsObserver(guest->GetEmbedderWebContents()),
21 guest_(guest) {
22 }
23
24 virtual ~EmbedderWebContentsObserver() {
25 }
26
27 // WebContentsObserver implementation.
28 virtual void WebContentsDestroyed() OVERRIDE {
29 guest_->Destroy();
30 }
31
32 private:
33 TestBrowserPluginGuestDelegate* guest_;
34
35 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver);
36 };
37
14 TestBrowserPluginGuestDelegate::TestBrowserPluginGuestDelegate( 38 TestBrowserPluginGuestDelegate::TestBrowserPluginGuestDelegate(
15 BrowserPluginGuest* guest) : 39 BrowserPluginGuest* guest) :
40 WebContentsObserver(guest->GetWebContents()),
16 guest_(guest) { 41 guest_(guest) {
17 } 42 }
18 43
19 TestBrowserPluginGuestDelegate::~TestBrowserPluginGuestDelegate() { 44 TestBrowserPluginGuestDelegate::~TestBrowserPluginGuestDelegate() {
20 } 45 }
21 46
47 WebContents* TestBrowserPluginGuestDelegate::GetEmbedderWebContents() const {
48 return guest_->embedder_web_contents();
49 }
50
22 void TestBrowserPluginGuestDelegate::LoadURLWithParams( 51 void TestBrowserPluginGuestDelegate::LoadURLWithParams(
23 const GURL& url, 52 const GURL& url,
24 const Referrer& referrer, 53 const Referrer& referrer,
25 PageTransition transition_type, 54 PageTransition transition_type,
26 WebContents* web_contents) { 55 WebContents* web_contents) {
27 NavigationController::LoadURLParams load_url_params(url); 56 NavigationController::LoadURLParams load_url_params(url);
28 load_url_params.referrer = referrer; 57 load_url_params.referrer = referrer;
29 load_url_params.transition_type = transition_type; 58 load_url_params.transition_type = transition_type;
30 load_url_params.extra_headers = std::string(); 59 load_url_params.extra_headers = std::string();
31 web_contents->GetController().LoadURLWithParams(load_url_params); 60 web_contents->GetController().LoadURLWithParams(load_url_params);
32 } 61 }
33 62
63 void TestBrowserPluginGuestDelegate::WebContentsDestroyed() {
64 delete this;
65 }
66
67 void TestBrowserPluginGuestDelegate::DidAttach() {
68 embedder_web_contents_observer_.reset(
69 new EmbedderWebContentsObserver(this));
70
71 }
72
34 void TestBrowserPluginGuestDelegate::Destroy() { 73 void TestBrowserPluginGuestDelegate::Destroy() {
35 if (!destruction_callback_.is_null()) 74 if (!destruction_callback_.is_null())
36 destruction_callback_.Run(guest_->GetWebContents()); 75 destruction_callback_.Run();
37 delete guest_->GetWebContents(); 76 delete guest_->GetWebContents();
38 } 77 }
39 78
40 void TestBrowserPluginGuestDelegate::NavigateGuest(const std::string& src) { 79 void TestBrowserPluginGuestDelegate::NavigateGuest(const std::string& src) {
41 GURL url(src); 80 GURL url(src);
42 LoadURLWithParams(url, 81 LoadURLWithParams(url,
43 Referrer(), 82 Referrer(),
44 PAGE_TRANSITION_AUTO_TOPLEVEL, 83 PAGE_TRANSITION_AUTO_TOPLEVEL,
45 guest_->GetWebContents()); 84 guest_->GetWebContents());
46 } 85 }
47 86
48 void TestBrowserPluginGuestDelegate::RegisterDestructionCallback( 87 void TestBrowserPluginGuestDelegate::RegisterDestructionCallback(
49 const DestructionCallback& callback) { 88 const DestructionCallback& callback) {
50 destruction_callback_ = callback; 89 destruction_callback_ = callback;
51 } 90 }
52 91
53 92
54 } // namespace content 93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698