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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/atomic_sequence_num.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/debug/dump_without_crashing.h" | 15 #include "base/debug/dump_without_crashing.h" |
15 #include "base/feature_list.h" | 16 #include "base/feature_list.h" |
16 #include "base/i18n/character_encoding.h" | 17 #include "base/i18n/character_encoding.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
18 #include "base/location.h" | 19 #include "base/location.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/macros.h" | 21 #include "base/macros.h" |
21 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
22 #include "base/memory/ref_counted.h" | 23 #include "base/memory/ref_counted.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 #include "content/public/common/browser_side_navigation_policy.h" | 119 #include "content/public/common/browser_side_navigation_policy.h" |
119 #include "content/public/common/child_process_host.h" | 120 #include "content/public/common/child_process_host.h" |
120 #include "content/public/common/content_constants.h" | 121 #include "content/public/common/content_constants.h" |
121 #include "content/public/common/content_switches.h" | 122 #include "content/public/common/content_switches.h" |
122 #include "content/public/common/page_zoom.h" | 123 #include "content/public/common/page_zoom.h" |
123 #include "content/public/common/result_codes.h" | 124 #include "content/public/common/result_codes.h" |
124 #include "content/public/common/url_utils.h" | 125 #include "content/public/common/url_utils.h" |
125 #include "content/public/common/web_preferences.h" | 126 #include "content/public/common/web_preferences.h" |
126 #include "device/geolocation/geolocation_service_context.h" | 127 #include "device/geolocation/geolocation_service_context.h" |
127 #include "device/nfc/nfc.mojom.h" | 128 #include "device/nfc/nfc.mojom.h" |
128 #include "device/wake_lock/wake_lock_service_context.h" | |
129 #include "net/base/url_util.h" | 129 #include "net/base/url_util.h" |
130 #include "net/http/http_cache.h" | 130 #include "net/http/http_cache.h" |
131 #include "net/http/http_transaction_factory.h" | 131 #include "net/http/http_transaction_factory.h" |
132 #include "net/url_request/url_request_context.h" | 132 #include "net/url_request/url_request_context.h" |
133 #include "net/url_request/url_request_context_getter.h" | 133 #include "net/url_request/url_request_context_getter.h" |
134 #include "ppapi/features/features.h" | 134 #include "ppapi/features/features.h" |
| 135 #include "services/device/public/interfaces/constants.mojom.h" |
| 136 #include "services/service_manager/public/cpp/connector.h" |
135 #include "services/service_manager/public/cpp/interface_provider.h" | 137 #include "services/service_manager/public/cpp/interface_provider.h" |
136 #include "third_party/WebKit/public/platform/WebSecurityStyle.h" | 138 #include "third_party/WebKit/public/platform/WebSecurityStyle.h" |
137 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 139 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
138 #include "third_party/skia/include/core/SkBitmap.h" | 140 #include "third_party/skia/include/core/SkBitmap.h" |
139 #include "ui/accessibility/ax_tree_combiner.h" | 141 #include "ui/accessibility/ax_tree_combiner.h" |
140 #include "ui/base/layout.h" | 142 #include "ui/base/layout.h" |
141 #include "ui/events/blink/web_input_event_traits.h" | 143 #include "ui/events/blink/web_input_event_traits.h" |
142 #include "ui/gl/gl_switches.h" | 144 #include "ui/gl/gl_switches.h" |
143 | 145 |
144 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
(...skipping 24 matching lines...) Expand all Loading... |
169 namespace content { | 171 namespace content { |
170 namespace { | 172 namespace { |
171 | 173 |
172 const int kMinimumDelayBetweenLoadingUpdatesMS = 100; | 174 const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
173 const char kDotGoogleDotCom[] = ".google.com"; | 175 const char kDotGoogleDotCom[] = ".google.com"; |
174 | 176 |
175 #if defined(OS_ANDROID) | 177 #if defined(OS_ANDROID) |
176 const char kWebContentsAndroidKey[] = "web_contents_android"; | 178 const char kWebContentsAndroidKey[] = "web_contents_android"; |
177 #endif // OS_ANDROID | 179 #endif // OS_ANDROID |
178 | 180 |
| 181 base::StaticAtomicSequenceNumber g_unique_id; |
| 182 |
179 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > | 183 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
180 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; | 184 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
181 | 185 |
| 186 base::LazyInstance<std::map<int, WebContents*>> g_id_to_web_contents = |
| 187 LAZY_INSTANCE_INITIALIZER; |
| 188 |
182 void NotifyCacheOnIO( | 189 void NotifyCacheOnIO( |
183 scoped_refptr<net::URLRequestContextGetter> request_context, | 190 scoped_refptr<net::URLRequestContextGetter> request_context, |
184 const GURL& url, | 191 const GURL& url, |
185 const std::string& http_method) { | 192 const std::string& http_method) { |
186 net::HttpCache* cache = request_context->GetURLRequestContext()-> | 193 net::HttpCache* cache = request_context->GetURLRequestContext()-> |
187 http_transaction_factory()->GetCache(); | 194 http_transaction_factory()->GetCache(); |
188 if (cache) | 195 if (cache) |
189 cache->OnExternalCacheHit(url, http_method); | 196 cache->OnExternalCacheHit(url, http_method); |
190 } | 197 } |
191 | 198 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( | 302 void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( |
296 const CreatedCallback& callback) { | 303 const CreatedCallback& callback) { |
297 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { | 304 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
298 if (g_created_callbacks.Get().at(i).Equals(callback)) { | 305 if (g_created_callbacks.Get().at(i).Equals(callback)) { |
299 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); | 306 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
300 return; | 307 return; |
301 } | 308 } |
302 } | 309 } |
303 } | 310 } |
304 | 311 |
| 312 gfx::NativeView WebContentsImpl::GetNativeViewForWebContents( |
| 313 int web_contents_id) { |
| 314 WebContents* web_contents = WebContents::FromId(web_contents_id); |
| 315 if (web_contents) |
| 316 return web_contents->GetNativeView(); |
| 317 return nullptr; |
| 318 } |
| 319 |
| 320 WebContents* WebContents::FromId(int id) { |
| 321 auto it = g_id_to_web_contents.Get().find(id); |
| 322 return it != g_id_to_web_contents.Get().end() ? it->second : nullptr; |
| 323 } |
| 324 |
305 WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { | 325 WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
306 if (!rvh) | 326 if (!rvh) |
307 return nullptr; | 327 return nullptr; |
308 return rvh->GetDelegate()->GetAsWebContents(); | 328 return rvh->GetDelegate()->GetAsWebContents(); |
309 } | 329 } |
310 | 330 |
311 WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { | 331 WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
312 if (!rfh) | 332 if (!rfh) |
313 return nullptr; | 333 return nullptr; |
314 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); | 334 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( | 435 void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
416 WebContentsImpl* web_contents) { | 436 WebContentsImpl* web_contents) { |
417 DCHECK(!outer_web_contents()) | 437 DCHECK(!outer_web_contents()) |
418 << "Only the outermost WebContents tracks focus."; | 438 << "Only the outermost WebContents tracks focus."; |
419 focused_web_contents_ = web_contents; | 439 focused_web_contents_ = web_contents; |
420 } | 440 } |
421 | 441 |
422 // WebContentsImpl ------------------------------------------------------------- | 442 // WebContentsImpl ------------------------------------------------------------- |
423 | 443 |
424 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) | 444 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
425 : delegate_(NULL), | 445 : id_(g_unique_id.GetNext()), |
| 446 delegate_(NULL), |
426 controller_(this, browser_context), | 447 controller_(this, browser_context), |
427 render_view_host_delegate_view_(NULL), | 448 render_view_host_delegate_view_(NULL), |
428 created_with_opener_(false), | 449 created_with_opener_(false), |
429 frame_tree_(new NavigatorImpl(&controller_, this), | 450 frame_tree_(new NavigatorImpl(&controller_, this), |
430 this, | 451 this, |
431 this, | 452 this, |
432 this, | 453 this, |
433 this), | 454 this), |
434 is_load_to_different_document_(false), | 455 is_load_to_different_document_(false), |
435 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), | 456 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 base::Bind(&WebContentsImpl::OnFrameRemoved, | 498 base::Bind(&WebContentsImpl::OnFrameRemoved, |
478 base::Unretained(this))); | 499 base::Unretained(this))); |
479 #if defined(OS_ANDROID) | 500 #if defined(OS_ANDROID) |
480 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); | 501 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); |
481 #else | 502 #else |
482 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); | 503 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
483 #endif | 504 #endif |
484 #if BUILDFLAG(ENABLE_PLUGINS) | 505 #if BUILDFLAG(ENABLE_PLUGINS) |
485 pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); | 506 pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); |
486 #endif | 507 #endif |
| 508 |
| 509 if (ServiceManagerConnection::GetForProcess()) { |
| 510 service_manager::Connector* connector = |
| 511 ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 512 DCHECK(connector); |
| 513 connector->BindInterface(device::mojom::kServiceName, |
| 514 mojo::MakeRequest(&wake_lock_service_context_)); |
| 515 wake_lock_service_context_->SetContextID(GetId()); |
| 516 } |
| 517 |
487 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); | 518 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); |
488 wake_lock_service_context_.reset(new device::WakeLockServiceContext( | |
489 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), | |
490 base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this)))); | |
491 host_zoom_map_observer_.reset(new HostZoomMapObserver(this)); | 519 host_zoom_map_observer_.reset(new HostZoomMapObserver(this)); |
492 } | 520 } |
493 | 521 |
494 WebContentsImpl::~WebContentsImpl() { | 522 WebContentsImpl::~WebContentsImpl() { |
495 is_being_destroyed_ = true; | 523 is_being_destroyed_ = true; |
496 | 524 |
| 525 g_id_to_web_contents.Get()[id_] = nullptr; |
| 526 |
497 // A WebContents should never be deleted while it is notifying observers, | 527 // A WebContents should never be deleted while it is notifying observers, |
498 // since this will lead to a use-after-free as it continues to notfiy later | 528 // since this will lead to a use-after-free as it continues to notfiy later |
499 // observers. | 529 // observers. |
500 CHECK(!is_notifying_observers_); | 530 CHECK(!is_notifying_observers_); |
501 | 531 |
502 rwh_input_event_router_.reset(); | 532 rwh_input_event_router_.reset(); |
503 | 533 |
504 for (auto& entry : binding_sets_) | 534 for (auto& entry : binding_sets_) |
505 entry.second->CloseAllBindings(); | 535 entry.second->CloseAllBindings(); |
506 | 536 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 NavigationEntry* entry = controller_.GetVisibleEntry(); | 850 NavigationEntry* entry = controller_.GetVisibleEntry(); |
821 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 851 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
822 } | 852 } |
823 | 853 |
824 const GURL& WebContentsImpl::GetLastCommittedURL() const { | 854 const GURL& WebContentsImpl::GetLastCommittedURL() const { |
825 // We may not have a navigation entry yet. | 855 // We may not have a navigation entry yet. |
826 NavigationEntry* entry = controller_.GetLastCommittedEntry(); | 856 NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
827 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); | 857 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
828 } | 858 } |
829 | 859 |
| 860 int WebContentsImpl::GetId() { |
| 861 return id_; |
| 862 } |
| 863 |
830 WebContentsDelegate* WebContentsImpl::GetDelegate() { | 864 WebContentsDelegate* WebContentsImpl::GetDelegate() { |
831 return delegate_; | 865 return delegate_; |
832 } | 866 } |
833 | 867 |
834 void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { | 868 void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
835 // TODO(cbentzel): remove this debugging code? | 869 // TODO(cbentzel): remove this debugging code? |
836 if (delegate == delegate_) | 870 if (delegate == delegate_) |
837 return; | 871 return; |
838 if (delegate_) | 872 if (delegate_) |
839 delegate_->Detach(this); | 873 delegate_->Detach(this); |
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); | 1667 GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); |
1634 } | 1668 } |
1635 } | 1669 } |
1636 | 1670 |
1637 // Ensure that observers are notified of the creation of this WebContents's | 1671 // Ensure that observers are notified of the creation of this WebContents's |
1638 // main RenderFrameHost. It must be done here for main frames, since the | 1672 // main RenderFrameHost. It must be done here for main frames, since the |
1639 // NotifySwappedFromRenderManager expects view_ to already be created and that | 1673 // NotifySwappedFromRenderManager expects view_ to already be created and that |
1640 // happens after RenderFrameHostManager::Init. | 1674 // happens after RenderFrameHostManager::Init. |
1641 NotifySwappedFromRenderManager( | 1675 NotifySwappedFromRenderManager( |
1642 nullptr, GetRenderManager()->current_frame_host(), true); | 1676 nullptr, GetRenderManager()->current_frame_host(), true); |
| 1677 |
| 1678 g_id_to_web_contents.Get()[id_] = this; |
1643 } | 1679 } |
1644 | 1680 |
1645 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { | 1681 void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
1646 RemoveDestructionObserver(web_contents); | 1682 RemoveDestructionObserver(web_contents); |
1647 | 1683 |
1648 // Clear a pending contents that has been closed before being shown. | 1684 // Clear a pending contents that has been closed before being shown. |
1649 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); | 1685 for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
1650 ++iter) { | 1686 ++iter) { |
1651 if (iter->second != web_contents) | 1687 if (iter->second != web_contents) |
1652 continue; | 1688 continue; |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2458 return nullptr; | 2494 return nullptr; |
2459 | 2495 |
2460 return guest->GetMainFrame(); | 2496 return guest->GetMainFrame(); |
2461 } | 2497 } |
2462 | 2498 |
2463 device::GeolocationServiceContext* | 2499 device::GeolocationServiceContext* |
2464 WebContentsImpl::GetGeolocationServiceContext() { | 2500 WebContentsImpl::GetGeolocationServiceContext() { |
2465 return geolocation_service_context_.get(); | 2501 return geolocation_service_context_.get(); |
2466 } | 2502 } |
2467 | 2503 |
2468 device::WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() { | 2504 device::mojom::WakeLockServiceContext* |
| 2505 WebContentsImpl::GetWakeLockServiceContext() { |
2469 return wake_lock_service_context_.get(); | 2506 return wake_lock_service_context_.get(); |
2470 } | 2507 } |
2471 | 2508 |
2472 void WebContentsImpl::OnShowValidationMessage( | 2509 void WebContentsImpl::OnShowValidationMessage( |
2473 RenderViewHostImpl* source, | 2510 RenderViewHostImpl* source, |
2474 const gfx::Rect& anchor_in_root_view, | 2511 const gfx::Rect& anchor_in_root_view, |
2475 const base::string16& main_text, | 2512 const base::string16& main_text, |
2476 const base::string16& sub_text) { | 2513 const base::string16& sub_text) { |
2477 // TODO(nick): Should we consider |source| here or pass it to the delegate? | 2514 // TODO(nick): Should we consider |source| here or pass it to the delegate? |
2478 if (delegate_) | 2515 if (delegate_) |
(...skipping 2940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5419 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); | 5456 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); |
5420 if (!render_view_host) | 5457 if (!render_view_host) |
5421 continue; | 5458 continue; |
5422 render_view_host_set.insert(render_view_host); | 5459 render_view_host_set.insert(render_view_host); |
5423 } | 5460 } |
5424 for (RenderViewHost* render_view_host : render_view_host_set) | 5461 for (RenderViewHost* render_view_host : render_view_host_set) |
5425 render_view_host->OnWebkitPreferencesChanged(); | 5462 render_view_host->OnWebkitPreferencesChanged(); |
5426 } | 5463 } |
5427 | 5464 |
5428 } // namespace content | 5465 } // namespace content |
OLD | NEW |