OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( | 272 void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( |
273 const CreatedCallback& callback) { | 273 const CreatedCallback& callback) { |
274 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { | 274 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
275 if (g_created_callbacks.Get().at(i).Equals(callback)) { | 275 if (g_created_callbacks.Get().at(i).Equals(callback)) { |
276 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); | 276 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
277 return; | 277 return; |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { | 282 WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
283 if (!rvh) | |
284 return nullptr; | |
283 return rvh->GetDelegate()->GetAsWebContents(); | 285 return rvh->GetDelegate()->GetAsWebContents(); |
284 } | 286 } |
285 | 287 |
286 WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { | 288 WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
287 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh); | 289 if (!rfh) |
288 if (!rfh_impl) | 290 return nullptr; |
289 return NULL; | 291 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
290 return rfh_impl->delegate()->GetAsWebContents(); | |
291 } | 292 } |
292 | 293 |
293 // WebContentsImpl::DestructionObserver ---------------------------------------- | 294 // WebContentsImpl::DestructionObserver ---------------------------------------- |
294 | 295 |
295 class WebContentsImpl::DestructionObserver : public WebContentsObserver { | 296 class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
296 public: | 297 public: |
297 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) | 298 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
298 : WebContentsObserver(watched_contents), | 299 : WebContentsObserver(watched_contents), |
299 owner_(owner) { | 300 owner_(owner) { |
300 } | 301 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 // We are instantiating a WebContents for browser plugin. Set its subframe | 537 // We are instantiating a WebContents for browser plugin. Set its subframe |
537 // bit to true. | 538 // bit to true. |
538 new_contents->is_subframe_ = true; | 539 new_contents->is_subframe_ = true; |
539 } | 540 } |
540 new_contents->Init(params); | 541 new_contents->Init(params); |
541 return new_contents; | 542 return new_contents; |
542 } | 543 } |
543 | 544 |
544 // static | 545 // static |
545 std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { | 546 std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
546 std::vector<WebContentsImpl*> result; | |
547 scoped_ptr<RenderWidgetHostIterator> widgets( | 547 scoped_ptr<RenderWidgetHostIterator> widgets( |
548 RenderWidgetHostImpl::GetRenderWidgetHosts()); | 548 RenderWidgetHostImpl::GetRenderWidgetHosts()); |
549 std::set<WebContentsImpl*> web_contents_set; | 549 std::set<WebContentsImpl*> contentses; |
550 while (RenderWidgetHost* rwh = widgets->GetNextHost()) { | 550 while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
551 if (!rwh->IsRenderView()) | |
552 continue; | |
553 RenderViewHost* rvh = RenderViewHost::From(rwh); | 551 RenderViewHost* rvh = RenderViewHost::From(rwh); |
554 if (!rvh) | 552 if (!rvh) |
555 continue; | 553 continue; |
556 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 554 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
557 if (!web_contents) | 555 if (!web_contents) |
558 continue; | 556 continue; |
559 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents); | 557 contentses.insert(static_cast<WebContentsImpl*>(web_contents)); |
ncarter (slow)
2015/10/26 18:35:02
Random observation: We could build the vector dire
Avi (use Gerrit)
2015/10/26 19:41:28
Oh, that's clever/evil.
| |
560 if (web_contents_set.find(wci) == web_contents_set.end()) { | |
561 web_contents_set.insert(wci); | |
562 result.push_back(wci); | |
563 } | |
564 } | 558 } |
565 return result; | 559 return std::vector<WebContentsImpl*>(contentses.begin(), contentses.end()); |
566 } | 560 } |
567 | 561 |
568 // static | 562 // static |
569 WebContentsImpl* WebContentsImpl::FromFrameTreeNode( | 563 WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
570 FrameTreeNode* frame_tree_node) { | 564 FrameTreeNode* frame_tree_node) { |
571 return static_cast<WebContentsImpl*>( | 565 return static_cast<WebContentsImpl*>( |
572 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); | 566 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
573 } | 567 } |
574 | 568 |
575 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { | 569 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
(...skipping 4074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4650 return NULL; | 4644 return NULL; |
4651 } | 4645 } |
4652 | 4646 |
4653 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4647 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4654 force_disable_overscroll_content_ = force_disable; | 4648 force_disable_overscroll_content_ = force_disable; |
4655 if (view_) | 4649 if (view_) |
4656 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4650 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4657 } | 4651 } |
4658 | 4652 |
4659 } // namespace content | 4653 } // namespace content |
OLD | NEW |