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

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

Issue 269113002: Remove BrowserPluginGuestManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_createguest
Patch Set: Created 6 years, 7 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_guest_manager_delegate.h" 5 #include "content/browser/browser_plugin/test_guest_manager_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/site_instance.h" 12 #include "content/public/browser/site_instance.h"
12 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
16 #include "content/public/test/test_utils.h"
15 #include "net/base/escape.h" 17 #include "net/base/escape.h"
16 18
17 namespace content { 19 namespace content {
18 20
19 class GuestWebContentsObserver 21 class GuestWebContentsObserver
20 : public content::WebContentsObserver { 22 : public content::WebContentsObserver {
21 public: 23 public:
22 explicit GuestWebContentsObserver(WebContents* guest_web_contents) 24 explicit GuestWebContentsObserver(WebContents* guest_web_contents)
23 : WebContentsObserver(guest_web_contents), 25 : WebContentsObserver(guest_web_contents),
24 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()) { 26 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()) {
25 } 27 }
26 28
27 virtual ~GuestWebContentsObserver() { 29 virtual ~GuestWebContentsObserver() {
28 } 30 }
29 31
30 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE { 32 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
31 TestGuestManagerDelegate::GetInstance()->RemoveGuest(guest_instance_id_); 33 TestGuestManagerDelegate::GetInstance()->RemoveGuest(guest_instance_id_);
32 delete this; 34 delete this;
33 } 35 }
34 36
35 private: 37 private:
36 int guest_instance_id_; 38 int guest_instance_id_;
37 DISALLOW_COPY_AND_ASSIGN(GuestWebContentsObserver); 39 DISALLOW_COPY_AND_ASSIGN(GuestWebContentsObserver);
38 }; 40 };
39 41
40 TestGuestManagerDelegate::TestGuestManagerDelegate() 42 TestGuestManagerDelegate::TestGuestManagerDelegate()
41 : next_instance_id_(0) { 43 : last_guest_added_(NULL),
44 next_instance_id_(0) {
42 } 45 }
43 46
44 TestGuestManagerDelegate::~TestGuestManagerDelegate() { 47 TestGuestManagerDelegate::~TestGuestManagerDelegate() {
45 } 48 }
46 49
47 // static. 50 // static.
48 TestGuestManagerDelegate* TestGuestManagerDelegate::GetInstance() { 51 TestGuestManagerDelegate* TestGuestManagerDelegate::GetInstance() {
49 return Singleton<TestGuestManagerDelegate>::get(); 52 return Singleton<TestGuestManagerDelegate>::get();
50 } 53 }
51 54
55 WebContentsImpl* TestGuestManagerDelegate::WaitForGuestAdded() {
56 fprintf(stderr, ">>>%s\n", __PRETTY_FUNCTION__);
lazyboy 2014/05/05 21:40:54 Remove debug code.
Fady Samuel 2014/05/07 17:32:59 Done.
57 // Check if guests were already created.
58 if (last_guest_added_) {
59 WebContentsImpl* last_guest_added = last_guest_added_;
60 last_guest_added_ = NULL;
61 return last_guest_added;
62 }
63 // Wait otherwise.
64 message_loop_runner_ = new MessageLoopRunner();
65 message_loop_runner_->Run();
66 WebContentsImpl* last_guest_added = last_guest_added_;
67 last_guest_added_ = NULL;
68 return last_guest_added;
69 }
70
52 content::WebContents* TestGuestManagerDelegate::CreateGuest( 71 content::WebContents* TestGuestManagerDelegate::CreateGuest(
53 SiteInstance* embedder_site_instance, 72 SiteInstance* embedder_site_instance,
54 int instance_id, 73 int instance_id,
55 const StorageInfo& storage_info, 74 const StorageInfo& storage_info,
56 scoped_ptr<base::DictionaryValue> extra_params) { 75 scoped_ptr<base::DictionaryValue> extra_params) {
57 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL(); 76 const GURL& embedder_site_url = embedder_site_instance->GetSiteURL();
58 const std::string& host = embedder_site_url.host(); 77 const std::string& host = embedder_site_url.host();
59 78
60 std::string url_encoded_partition = net::EscapeQueryParamValue( 79 std::string url_encoded_partition = net::EscapeQueryParamValue(
61 storage_info.partition_id, false); 80 storage_info.partition_id, false);
(...skipping 28 matching lines...) Expand all
90 return ++next_instance_id_; 109 return ++next_instance_id_;
91 } 110 }
92 111
93 void TestGuestManagerDelegate::AddGuest( 112 void TestGuestManagerDelegate::AddGuest(
94 int guest_instance_id, 113 int guest_instance_id,
95 WebContents* guest_web_contents) { 114 WebContents* guest_web_contents) {
96 DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) == 115 DCHECK(guest_web_contents_by_instance_id_.find(guest_instance_id) ==
97 guest_web_contents_by_instance_id_.end()); 116 guest_web_contents_by_instance_id_.end());
98 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; 117 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
99 new GuestWebContentsObserver(guest_web_contents); 118 new GuestWebContentsObserver(guest_web_contents);
119 last_guest_added_ = static_cast<WebContentsImpl*>(guest_web_contents);
120 if (message_loop_runner_)
121 message_loop_runner_->Quit();
100 } 122 }
101 123
102 void TestGuestManagerDelegate::RemoveGuest( 124 void TestGuestManagerDelegate::RemoveGuest(
103 int guest_instance_id) { 125 int guest_instance_id) {
104 GuestInstanceMap::iterator it = 126 GuestInstanceMap::iterator it =
105 guest_web_contents_by_instance_id_.find(guest_instance_id); 127 guest_web_contents_by_instance_id_.find(guest_instance_id);
106 DCHECK(it != guest_web_contents_by_instance_id_.end()); 128 DCHECK(it != guest_web_contents_by_instance_id_.end());
107 guest_web_contents_by_instance_id_.erase(it); 129 guest_web_contents_by_instance_id_.erase(it);
108 } 130 }
109 131
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (embedder_web_contents != guest->GetEmbedderWebContents()) 163 if (embedder_web_contents != guest->GetEmbedderWebContents())
142 continue; 164 continue;
143 165
144 if (callback.Run(guest)) 166 if (callback.Run(guest))
145 return true; 167 return true;
146 } 168 }
147 return false; 169 return false;
148 } 170 }
149 171
150 } // namespace content 172 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698