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

Side by Side Diff: chrome/browser/guest_view/guest_view_base.cc

Issue 272573005: <webview>: Move NewWindow API to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_rename
Patch Set: Merge with ToT 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 "chrome/browser/guest_view/guest_view_base.h" 5 #include "chrome/browser/guest_view/guest_view_base.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "chrome/browser/guest_view/ad_view/ad_view_guest.h" 8 #include "chrome/browser/guest_view/ad_view/ad_view_guest.h"
9 #include "chrome/browser/guest_view/guest_view_constants.h" 9 #include "chrome/browser/guest_view/guest_view_constants.h"
10 #include "chrome/browser/guest_view/guest_view_manager.h" 10 #include "chrome/browser/guest_view/guest_view_manager.h"
(...skipping 21 matching lines...) Expand all
32 : name_(name), args_(args.Pass()) { 32 : name_(name), args_(args.Pass()) {
33 } 33 }
34 34
35 GuestViewBase::Event::~Event() { 35 GuestViewBase::Event::~Event() {
36 } 36 }
37 37
38 scoped_ptr<base::DictionaryValue> GuestViewBase::Event::GetArguments() { 38 scoped_ptr<base::DictionaryValue> GuestViewBase::Event::GetArguments() {
39 return args_.Pass(); 39 return args_.Pass();
40 } 40 }
41 41
42 GuestViewBase::GuestViewBase(WebContents* guest_web_contents, 42 GuestViewBase::GuestViewBase(int guest_instance_id,
43 const std::string& embedder_extension_id, 43 WebContents* guest_web_contents,
44 const base::WeakPtr<GuestViewBase>& opener) 44 const std::string& embedder_extension_id)
45 : guest_web_contents_(guest_web_contents), 45 : guest_web_contents_(guest_web_contents),
46 embedder_web_contents_(NULL), 46 embedder_web_contents_(NULL),
47 embedder_extension_id_(embedder_extension_id), 47 embedder_extension_id_(embedder_extension_id),
48 embedder_render_process_id_(0), 48 embedder_render_process_id_(0),
49 browser_context_(guest_web_contents->GetBrowserContext()), 49 browser_context_(guest_web_contents->GetBrowserContext()),
50 guest_instance_id_(guest_web_contents->GetEmbeddedInstanceID()), 50 guest_instance_id_(guest_instance_id),
51 view_instance_id_(guestview::kInstanceIDNone), 51 view_instance_id_(guestview::kInstanceIDNone),
52 opener_(opener),
53 weak_ptr_factory_(this) { 52 weak_ptr_factory_(this) {
54 webcontents_guestview_map.Get().insert( 53 webcontents_guestview_map.Get().insert(
55 std::make_pair(guest_web_contents, this)); 54 std::make_pair(guest_web_contents, this));
56 GuestViewManager::FromBrowserContext(browser_context_)-> 55 GuestViewManager::FromBrowserContext(browser_context_)->
57 AddGuest(guest_instance_id_, guest_web_contents); 56 AddGuest(guest_instance_id_, guest_web_contents);
58 } 57 }
59 58
60 // static 59 // static
61 GuestViewBase* GuestViewBase::Create( 60 GuestViewBase* GuestViewBase::Create(
61 int guest_instance_id,
62 WebContents* guest_web_contents, 62 WebContents* guest_web_contents,
63 const std::string& embedder_extension_id, 63 const std::string& embedder_extension_id,
64 const std::string& view_type, 64 const std::string& view_type) {
65 const base::WeakPtr<GuestViewBase>& opener) {
66 if (view_type == "webview") { 65 if (view_type == "webview") {
67 return new WebViewGuest(guest_web_contents, embedder_extension_id, opener); 66 return new WebViewGuest(guest_instance_id,
67 guest_web_contents,
68 embedder_extension_id);
68 } else if (view_type == "adview") { 69 } else if (view_type == "adview") {
69 return new AdViewGuest(guest_web_contents, embedder_extension_id); 70 return new AdViewGuest(guest_instance_id,
71 guest_web_contents,
72 embedder_extension_id);
70 } 73 }
71 NOTREACHED(); 74 NOTREACHED();
72 return NULL; 75 return NULL;
73 } 76 }
74 77
75 // static 78 // static
76 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) { 79 GuestViewBase* GuestViewBase::FromWebContents(WebContents* web_contents) {
77 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); 80 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer();
78 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents); 81 WebContentsGuestViewMap::iterator it = guest_map->find(web_contents);
79 return it == guest_map->end() ? NULL : it->second; 82 return it == guest_map->end() ? NULL : it->second;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() { 144 base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() {
142 return weak_ptr_factory_.GetWeakPtr(); 145 return weak_ptr_factory_.GetWeakPtr();
143 } 146 }
144 147
145 void GuestViewBase::Attach(content::WebContents* embedder_web_contents, 148 void GuestViewBase::Attach(content::WebContents* embedder_web_contents,
146 const base::DictionaryValue& args) { 149 const base::DictionaryValue& args) {
147 embedder_web_contents_ = embedder_web_contents; 150 embedder_web_contents_ = embedder_web_contents;
148 embedder_render_process_id_ = 151 embedder_render_process_id_ =
149 embedder_web_contents->GetRenderProcessHost()->GetID(); 152 embedder_web_contents->GetRenderProcessHost()->GetID();
150 args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_); 153 args.GetInteger(guestview::kParameterInstanceId, &view_instance_id_);
151 154 extra_params_.reset(args.DeepCopy());
152 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_);
153 155
154 // GuestViewBase::Attach is called prior to initialization (and initial 156 // GuestViewBase::Attach is called prior to initialization (and initial
155 // navigation) of the guest in the content layer in order to permit mapping 157 // navigation) of the guest in the content layer in order to permit mapping
156 // the necessary associations between the <*view> element and its guest. This 158 // the necessary associations between the <*view> element and its guest. This
157 // is needed by the <webview> WebRequest API to allow intercepting resource 159 // is needed by the <webview> WebRequest API to allow intercepting resource
158 // requests during navigation. However, queued events should be fired after 160 // requests during navigation. However, queued events should be fired after
159 // content layer initialization in order to ensure that load events (such as 161 // content layer initialization in order to ensure that load events (such as
160 // 'loadstop') fire in embedder after the contentWindow is available. 162 // 'loadstop') fire in embedder after the contentWindow is available.
161 if (!in_extension()) 163 if (!in_extension())
162 return; 164 return;
163 165
164 base::MessageLoop::current()->PostTask( 166 base::MessageLoop::current()->PostTask(
165 FROM_HERE, 167 FROM_HERE,
166 base::Bind(&GuestViewBase::SendQueuedEvents, 168 base::Bind(&GuestViewBase::SendQueuedEvents,
167 weak_ptr_factory_.GetWeakPtr())); 169 weak_ptr_factory_.GetWeakPtr()));
168 } 170 }
169 171
170 WebContents* GuestViewBase::GetOpener() const { 172 void GuestViewBase::Destroy() {
171 if (!opener_) 173 if (!destruction_callback_.is_null())
172 return NULL; 174 destruction_callback_.Run(guest_web_contents());
173 return opener_->guest_web_contents(); 175 delete guest_web_contents();
174 } 176 }
175 177
176 void GuestViewBase::SetOpener(WebContents* web_contents) { 178
177 GuestViewBase* guest = FromWebContents(web_contents); 179 void GuestViewBase::SetOpener(GuestViewBase* guest) {
178 if (guest && guest->IsViewType(GetViewType())) { 180 if (guest && guest->IsViewType(GetViewType())) {
179 opener_ = guest->AsWeakPtr(); 181 opener_ = guest->AsWeakPtr();
180 return; 182 return;
181 } 183 }
182 opener_ = base::WeakPtr<GuestViewBase>(); 184 opener_ = base::WeakPtr<GuestViewBase>();
183 } 185 }
184 186
187 void GuestViewBase::RegisterDestructionCallback(
188 const DestructionCallback& callback) {
189 destruction_callback_ = callback;
190 }
191
185 GuestViewBase::~GuestViewBase() { 192 GuestViewBase::~GuestViewBase() {
186 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_); 193 std::pair<int, int> key(embedder_render_process_id_, guest_instance_id_);
187 194
188 webcontents_guestview_map.Get().erase(guest_web_contents()); 195 webcontents_guestview_map.Get().erase(guest_web_contents());
189 196
190 GuestViewManager::FromBrowserContext(browser_context_)-> 197 GuestViewManager::FromBrowserContext(browser_context_)->
191 RemoveGuest(guest_instance_id_); 198 RemoveGuest(guest_instance_id_);
192 199
193 pending_events_.clear(); 200 pending_events_.clear();
194 } 201 }
(...skipping 24 matching lines...) Expand all
219 embedder_extension_id_, 226 embedder_extension_id_,
220 event->name(), 227 event->name(),
221 args.Pass(), 228 args.Pass(),
222 extensions::EventRouter::USER_GESTURE_UNKNOWN, 229 extensions::EventRouter::USER_GESTURE_UNKNOWN,
223 info); 230 info);
224 } 231 }
225 232
226 void GuestViewBase::SendQueuedEvents() { 233 void GuestViewBase::SendQueuedEvents() {
227 if (!attached()) 234 if (!attached())
228 return; 235 return;
229
230 while (!pending_events_.empty()) { 236 while (!pending_events_.empty()) {
231 linked_ptr<Event> event_ptr = pending_events_.front(); 237 linked_ptr<Event> event_ptr = pending_events_.front();
232 pending_events_.pop_front(); 238 pending_events_.pop_front();
233 DispatchEvent(event_ptr.release()); 239 DispatchEvent(event_ptr.release());
234 } 240 }
235 } 241 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/guest_view_base.h ('k') | chrome/browser/guest_view/guest_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698