| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 std::vector<WebContentsImpl*> result; |
| 547 scoped_ptr<RenderWidgetHostIterator> widgets( | 548 scoped_ptr<RenderWidgetHostIterator> widgets( |
| 548 RenderWidgetHostImpl::GetRenderWidgetHosts()); | 549 RenderWidgetHostImpl::GetRenderWidgetHosts()); |
| 549 std::set<WebContentsImpl*> web_contents_set; | |
| 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 if (web_contents->GetRenderViewHost() != rvh) |
| 560 if (web_contents_set.find(wci) == web_contents_set.end()) { | 558 continue; |
| 561 web_contents_set.insert(wci); | 559 // Because a WebContents can only have one current RVH at a time, there will |
| 562 result.push_back(wci); | 560 // be no duplicate WebContents here. |
| 563 } | 561 result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
| 564 } | 562 } |
| 565 return result; | 563 return result; |
| 566 } | 564 } |
| 567 | 565 |
| 568 // static | 566 // static |
| 569 WebContentsImpl* WebContentsImpl::FromFrameTreeNode( | 567 WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
| 570 FrameTreeNode* frame_tree_node) { | 568 FrameTreeNode* frame_tree_node) { |
| 571 return static_cast<WebContentsImpl*>( | 569 return static_cast<WebContentsImpl*>( |
| 572 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); | 570 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 573 } | 571 } |
| (...skipping 4076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4650 return NULL; | 4648 return NULL; |
| 4651 } | 4649 } |
| 4652 | 4650 |
| 4653 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4651 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4654 force_disable_overscroll_content_ = force_disable; | 4652 force_disable_overscroll_content_ = force_disable; |
| 4655 if (view_) | 4653 if (view_) |
| 4656 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4654 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4657 } | 4655 } |
| 4658 | 4656 |
| 4659 } // namespace content | 4657 } // namespace content |
| OLD | NEW |