diff options
author | avi <avi@chromium.org> | 2015-10-27 06:45:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-27 13:46:00 +0000 |
commit | df38c95ae1ae5677cc9ed6f98872c45210109b5d (patch) | |
tree | 25c4f4452e1cb4dfc8d9c94fd2acfecc582ef217 | |
parent | 9c3cc3ee55271f5f5425e315c2e332dc05235668 (diff) | |
download | chromium_src-df38c95ae1ae5677cc9ed6f98872c45210109b5d.zip chromium_src-df38c95ae1ae5677cc9ed6f98872c45210109b5d.tar.gz chromium_src-df38c95ae1ae5677cc9ed6f98872c45210109b5d.tar.bz2 |
Separate RenderViewHost from RenderWidgetHost, part 4: delegate
This makes a delegate interface between the RenderViewHost and the RenderWidgetHost, which will eventually be used for their communication.
This also allows the removal of the horrible terrible no-good RenderWidgetHost::IsRenderView().
BUG=542477
TEST=all green
Review URL: https://codereview.chromium.org/1411203010
Cr-Commit-Position: refs/heads/master@{#356286}
27 files changed, 175 insertions, 155 deletions
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 8065d2c..6a46d1d 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -153,7 +153,7 @@ AwContents* AwContents::FromWebContents(WebContents* web_contents) { // static AwContents* AwContents::FromID(int render_process_id, int render_view_id) { - const content::RenderViewHost* rvh = + content::RenderViewHost* rvh = content::RenderViewHost::FromID(render_process_id, render_view_id); if (!rvh) return NULL; content::WebContents* web_contents = diff --git a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc index d6f491a..d29204f 100644 --- a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc +++ b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc @@ -353,7 +353,7 @@ class WebViewInteractiveTest content::RenderWidgetHost::GetRenderWidgetHosts()); size_t num_widgets = 0; while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { - if (widget->IsRenderView()) + if (content::RenderViewHost::From(widget)) continue; ++num_widgets; last_render_widget_host_ = widget; diff --git a/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc b/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc index 082e54b..18401c9 100644 --- a/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc +++ b/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc @@ -99,15 +99,12 @@ content::RenderViewHost* VirtualKeyboardBrowserTest::GetKeyboardRenderViewHost( scoped_ptr<content::RenderWidgetHostIterator> widgets( content::RenderWidgetHost::GetRenderWidgetHosts()); while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { - if (widget->IsRenderView()) { - content::RenderViewHost* view = content::RenderViewHost::From(widget); - if (url == view->GetSiteInstance()->GetSiteURL()) { - content::WebContents* wc = - content::WebContents::FromRenderViewHost(view); - // Waits for virtual keyboard to load. - EXPECT_TRUE(content::WaitForLoadStop(wc)); - return view; - } + content::RenderViewHost* view = content::RenderViewHost::From(widget); + if (view && url == view->GetSiteInstance()->GetSiteURL()) { + content::WebContents* wc = content::WebContents::FromRenderViewHost(view); + // Waits for virtual keyboard to load. + EXPECT_TRUE(content::WaitForLoadStop(wc)); + return view; } } LOG(ERROR) << "Extension not found:" << url; diff --git a/chrome/browser/extensions/api/processes/processes_api.cc b/chrome/browser/extensions/api/processes/processes_api.cc index 4d33c33..b7d2b81 100644 --- a/chrome/browser/extensions/api/processes/processes_api.cc +++ b/chrome/browser/extensions/api/processes/processes_api.cc @@ -119,8 +119,6 @@ base::ListValue* GetTabsForProcess(int process_id) { while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { if (widget->GetProcess()->GetID() != process_id) continue; - if (!widget->IsRenderView()) - continue; content::RenderViewHost* host = content::RenderViewHost::From(widget); content::WebContents* contents = diff --git a/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc b/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc index 4275c8c..aa4f27d 100644 --- a/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc +++ b/chrome/browser/media_galleries/fileapi/media_file_system_backend.cc @@ -60,7 +60,7 @@ namespace { const char kMediaGalleryMountPrefix[] = "media_galleries-"; void OnPreferencesInit( - const content::RenderViewHost* rvh, + content::RenderViewHost* rvh, const extensions::Extension* extension, MediaGalleryPrefId pref_id, const base::Callback<void(base::File::Error result)>& callback) { diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index c6e057b..fbf669d 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -240,12 +240,12 @@ void MemoryDetails::CollectChildInfoOnUIThread() { // The RenderProcessHost may host multiple WebContentses. Any // of them which contain diagnostics information make the whole // process be considered a diagnostics process. - if (!widget->IsRenderView()) + RenderViewHost* host = RenderViewHost::From(widget); + if (!host) continue; process.process_type = content::PROCESS_TYPE_RENDERER; bool is_extension = false; - RenderViewHost* host = RenderViewHost::From(widget); #if defined(ENABLE_EXTENSIONS) content::BrowserContext* context = render_process_host->GetBrowserContext(); diff --git a/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm b/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm index f320ff6..7d1bbcb 100644 --- a/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm +++ b/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm @@ -74,10 +74,11 @@ class SpellCheckObserver : public content::WebContentsObserver { self = [super init]; if (self) { renderWidgetHost_ = renderWidgetHost; - if (renderWidgetHost_->IsRenderView()) { + RenderViewHost* rvh = RenderViewHost::From(renderWidgetHost_); + if (rvh) { spellingObserver_.reset( new ChromeRenderWidgetHostViewMacDelegateInternal::SpellCheckObserver( - RenderViewHost::From(renderWidgetHost_), self)); + rvh, self)); } historySwiper_.reset([[HistorySwiper alloc] initWithDelegate:self]); @@ -137,10 +138,13 @@ class SpellCheckObserver : public content::WebContentsObserver { // HistorySwiperDelegate methods - (BOOL)shouldAllowHistorySwiping { - if (!renderWidgetHost_ || !renderWidgetHost_->IsRenderView()) + if (!renderWidgetHost_) return NO; - content::WebContents* webContents = content::WebContents::FromRenderViewHost( - RenderViewHost::From(renderWidgetHost_)); + RenderViewHost* renderViewHost = RenderViewHost::From(renderWidgetHost_); + if (!renderViewHost) + return NO; + content::WebContents* webContents = + content::WebContents::FromRenderViewHost(renderViewHost); if (webContents && DevToolsWindow::IsDevToolsWindow(webContents)) { return NO; } @@ -160,7 +164,7 @@ class SpellCheckObserver : public content::WebContentsObserver { // this is sub-optimal. // TODO(suzhe): Plumb the "can*" methods up from WebCore. if (action == @selector(checkSpelling:)) { - *valid = renderWidgetHost_->IsRenderView(); + *valid = RenderViewHost::From(renderWidgetHost_) != nullptr; return YES; } diff --git a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc index 68a9ba6..af6a727 100644 --- a/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc +++ b/chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc @@ -54,10 +54,10 @@ WebContents* FindFirstDevToolsContents() { while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { if (!widget->GetProcess()->HasConnection()) continue; - if (!widget->IsRenderView()) + RenderViewHost* view_host = RenderViewHost::From(widget); + if (!view_host) continue; - RenderViewHost* host = RenderViewHost::From(widget); - WebContents* contents = WebContents::FromRenderViewHost(host); + WebContents* contents = WebContents::FromRenderViewHost(view_host); GURL url = contents->GetURL(); if (url.SchemeIs(content::kChromeDevToolsScheme)) return contents; diff --git a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc index caf1bcd..99b336e 100644 --- a/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc +++ b/chrome/browser/speech/chrome_speech_recognition_manager_delegate.cc @@ -400,7 +400,7 @@ void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( int render_process_id, int render_view_id) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - const content::RenderViewHost* render_view_host = + content::RenderViewHost* render_view_host = content::RenderViewHost::FromID(render_process_id, render_view_id); bool allowed = false; diff --git a/chrome/browser/task_manager/guest_information.cc b/chrome/browser/task_manager/guest_information.cc index a71fe8b..63f1f7b 100644 --- a/chrome/browser/task_manager/guest_information.cc +++ b/chrome/browser/task_manager/guest_information.cc @@ -108,12 +108,10 @@ void GuestInformation::GetAll(const NewWebContentsCallback& callback) { scoped_ptr<content::RenderWidgetHostIterator> widgets( content::RenderWidgetHost::GetRenderWidgetHosts()); while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { - if (widget->IsRenderView()) { - content::RenderViewHost* rvh = content::RenderViewHost::From(widget); - WebContents* web_contents = WebContents::FromRenderViewHost(rvh); - if (web_contents && GuestViewBase::IsGuest(web_contents)) - callback.Run(web_contents); - } + content::RenderViewHost* rvh = content::RenderViewHost::From(widget); + WebContents* web_contents = WebContents::FromRenderViewHost(rvh); + if (web_contents && GuestViewBase::IsGuest(web_contents)) + callback.Run(web_contents); } } diff --git a/content/browser/accessibility/accessibility_ui.cc b/content/browser/accessibility/accessibility_ui.cc index 1a46646..7384552 100644 --- a/content/browser/accessibility/accessibility_ui.cc +++ b/content/browser/accessibility/accessibility_ui.cc @@ -105,14 +105,13 @@ bool HandleRequestCallback(BrowserContext* current_context, // Ignore processes that don't have a connection, such as crashed tabs. if (!widget->GetProcess()->HasConnection()) continue; - if (!widget->IsRenderView()) - continue; - RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); - BrowserContext* context = rwhi->GetProcess()->GetBrowserContext(); + RenderViewHost* rvh = RenderViewHost::From(widget); + if (!rvh) + continue; + BrowserContext* context = rvh->GetProcess()->GetBrowserContext(); if (context != current_context) continue; - RenderViewHost* rvh = RenderViewHost::From(widget); rvh_list->Append(BuildTargetDescriptor(rvh)); } diff --git a/content/browser/frame_host/render_frame_host_manager.cc b/content/browser/frame_host/render_frame_host_manager.cc index 00719e3..1133311 100644 --- a/content/browser/frame_host/render_frame_host_manager.cc +++ b/content/browser/frame_host/render_frame_host_manager.cc @@ -2313,10 +2313,9 @@ void RenderFrameHostManager::ShutdownProxiesIfLastActiveFrameInSiteInstance( scoped_ptr<RenderWidgetHostIterator> widgets( RenderWidgetHostImpl::GetAllRenderWidgetHosts()); while (RenderWidgetHost* widget = widgets->GetNextHost()) { - if (!widget->IsRenderView()) + RenderViewHost* rvh = RenderViewHost::From(widget); + if (!rvh) continue; - RenderViewHostImpl* rvh = - static_cast<RenderViewHostImpl*>(RenderViewHost::From(widget)); if (site_instance_id == rvh->GetSiteInstance()->GetId()) { // This deletes all RenderFrameHosts using the |rvh|, which then causes // |rvh| to Shutdown. diff --git a/content/browser/renderer_host/ime_adapter_android.cc b/content/browser/renderer_host/ime_adapter_android.cc index dbad05c..7fe8485 100644 --- a/content/browser/renderer_host/ime_adapter_android.cc +++ b/content/browser/renderer_host/ime_adapter_android.cc @@ -281,7 +281,7 @@ RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { DCHECK(rwhva_); RenderWidgetHost* rwh = rwhva_->GetRenderWidgetHost(); if (!rwh) - return NULL; + return nullptr; return RenderWidgetHostImpl::From(rwh); } @@ -289,14 +289,14 @@ RenderWidgetHostImpl* ImeAdapterAndroid::GetRenderWidgetHostImpl() { RenderFrameHost* ImeAdapterAndroid::GetFocusedFrame() { RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); if (!rwh) - return NULL; - if (!rwh->IsRenderView()) - return NULL; + return nullptr; RenderViewHost* rvh = RenderViewHost::From(rwh); + if (!rvh) + return nullptr; FrameTreeNode* focused_frame = rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); if (!focused_frame) - return NULL; + return nullptr; return focused_frame->current_frame_host(); } @@ -304,9 +304,7 @@ RenderFrameHost* ImeAdapterAndroid::GetFocusedFrame() { WebContents* ImeAdapterAndroid::GetWebContents() { RenderWidgetHostImpl* rwh = GetRenderWidgetHostImpl(); if (!rwh) - return NULL; - if (!rwh->IsRenderView()) - return NULL; + return nullptr; return WebContents::FromRenderViewHost(RenderViewHost::From(rwh)); } diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 21aa0ae..daab269 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2526,14 +2526,14 @@ void RenderProcessHostImpl::OnGpuSwitched() { scoped_ptr<RenderWidgetHostIterator> widgets( RenderWidgetHostImpl::GetAllRenderWidgetHosts()); while (RenderWidgetHost* widget = widgets->GetNextHost()) { - if (!widget->IsRenderView()) + RenderViewHost* rvh = RenderViewHost::From(widget); + if (!rvh) continue; // Skip widgets in other processes. - if (widget->GetProcess()->GetID() != GetID()) + if (rvh->GetProcess()->GetID() != GetID()) continue; - RenderViewHost* rvh = RenderViewHost::From(widget); rvh->OnWebkitPreferencesChanged(); } } diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 877062c..5f3afe1 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -188,15 +188,21 @@ RenderViewHostImpl* RenderViewHostImpl::FromID(int render_process_id, int render_view_id) { RenderWidgetHost* widget = RenderWidgetHost::FromID(render_process_id, render_view_id); - if (!widget || !widget->IsRenderView()) - return NULL; - return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(widget)); + if (!widget) + return nullptr; + return From(widget); } // static RenderViewHostImpl* RenderViewHostImpl::From(RenderWidgetHost* rwh) { - DCHECK(rwh->IsRenderView()); - return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh)); + DCHECK(rwh); + RenderWidgetHostOwnerDelegate* owner_delegate = + RenderWidgetHostImpl::From(rwh)->owner_delegate(); + if (!owner_delegate) + return nullptr; + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(owner_delegate); + DCHECK_EQ(rwh, rvh->GetWidget()); + return rvh; } RenderViewHostImpl::RenderViewHostImpl( @@ -234,6 +240,8 @@ RenderViewHostImpl::RenderViewHostImpl( DCHECK(instance_.get()); CHECK(delegate_); // http://crbug.com/82827 + GetWidget()->set_owner_delegate(this); + GetProcess()->AddObserver(this); GetProcess()->EnableSendQueue(); @@ -1011,10 +1019,6 @@ void RenderViewHostImpl::WasShown(const ui::LatencyInfo& latency_info) { RenderWidgetHostImpl::WasShown(latency_info); } -bool RenderViewHostImpl::IsRenderView() const { - return true; -} - void RenderViewHostImpl::CreateNewWindow( int32_t route_id, int32_t main_frame_route_id, diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index 83211f1..ecdfc3c 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -16,6 +16,7 @@ #include "base/memory/scoped_ptr.h" #include "base/process/kill.h" #include "content/browser/renderer_host/render_widget_host_impl.h" +#include "content/browser/renderer_host/render_widget_host_owner_delegate.h" #include "content/browser/site_instance_impl.h" #include "content/common/drag_event_source_info.h" #include "content/public/browser/notification_observer.h" @@ -49,8 +50,8 @@ class AXTree; namespace content { -class MediaWebContentsObserver; class ChildProcessSecurityPolicyImpl; +class MediaWebContentsObserver; class PageState; class RenderWidgetHostDelegate; class SessionStorageNamespace; @@ -95,6 +96,7 @@ struct FrameReplicationState; // http://www.chromium.org/developers/design-documents/site-isolation. class CONTENT_EXPORT RenderViewHostImpl : public RenderViewHost, RenderWidgetHostImpl, + public RenderWidgetHostOwnerDelegate, public RenderProcessHostObserver { public: // Convenience function, just like RenderViewHost::FromID. @@ -280,7 +282,6 @@ class CONTENT_EXPORT RenderViewHostImpl : public RenderViewHost, void Shutdown() override; void WasHidden() override; void WasShown(const ui::LatencyInfo& latency_info) override; - bool IsRenderView() const override; bool OnMessageReceived(const IPC::Message& msg) override; void GotFocus() override; void LostCapture() override; diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index c835063..77ebb59 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -173,6 +173,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, : view_(NULL), renderer_initialized_(false), delegate_(delegate), + owner_delegate_(nullptr), process_(process), routing_id_(routing_id), is_loading_(false), @@ -225,10 +226,7 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, touch_emulator_.reset(); - RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( - IsRenderView() ? RenderViewHost::From(this) : NULL); - if (BrowserPluginGuest::IsGuest(rvh) || - !base::CommandLine::ForCurrentProcess()->HasSwitch( + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableHangMonitor)) { hang_monitor_timeout_.reset(new TimeoutMonitor( base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, @@ -273,39 +271,34 @@ RenderWidgetHostImpl* RenderWidgetHostImpl::FromID( // static scoped_ptr<RenderWidgetHostIterator> RenderWidgetHost::GetRenderWidgetHosts() { - RenderWidgetHostIteratorImpl* hosts = new RenderWidgetHostIteratorImpl(); - RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); - for (RoutingIDWidgetMap::const_iterator it = widgets->begin(); - it != widgets->end(); - ++it) { - RenderWidgetHost* widget = it->second; + scoped_ptr<RenderWidgetHostIteratorImpl> hosts( + new RenderWidgetHostIteratorImpl()); + for (auto& it : g_routing_id_widget_map.Get()) { + RenderWidgetHost* widget = it.second; - if (!widget->IsRenderView()) { + RenderViewHost* rvh = RenderViewHost::From(widget); + if (!rvh) { hosts->Add(widget); continue; } - // Add only active RenderViewHosts. - RenderViewHost* rvh = RenderViewHost::From(widget); + // For RenderViewHosts, add only active ones. if (static_cast<RenderViewHostImpl*>(rvh)->is_active()) hosts->Add(widget); } - return scoped_ptr<RenderWidgetHostIterator>(hosts); + return hosts.Pass(); } // static scoped_ptr<RenderWidgetHostIterator> RenderWidgetHostImpl::GetAllRenderWidgetHosts() { - RenderWidgetHostIteratorImpl* hosts = new RenderWidgetHostIteratorImpl(); - RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); - for (RoutingIDWidgetMap::const_iterator it = widgets->begin(); - it != widgets->end(); - ++it) { - hosts->Add(it->second); - } + scoped_ptr<RenderWidgetHostIteratorImpl> hosts( + new RenderWidgetHostIteratorImpl()); + for (auto& it : g_routing_id_widget_map.Get()) + hosts->Add(it.second); - return scoped_ptr<RenderWidgetHostIterator>(hosts); + return hosts.Pass(); } // static @@ -435,10 +428,6 @@ bool RenderWidgetHostImpl::IsLoading() const { return is_loading_; } -bool RenderWidgetHostImpl::IsRenderView() const { - return false; -} - bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostImpl, msg) @@ -708,7 +697,7 @@ void RenderWidgetHostImpl::Focus() { // Also send page-level focus state to other SiteInstances involved in // rendering the current FrameTree. - if (IsRenderView() && delegate_) + if (RenderViewHost::From(this) && delegate_) delegate_->ReplicatePageFocus(true); } @@ -728,7 +717,7 @@ void RenderWidgetHostImpl::Blur() { // Also send page-level focus state to other SiteInstances involved in // rendering the current FrameTree. - if (IsRenderView() && delegate_) + if (RenderViewHost::From(this) && delegate_) delegate_->ReplicatePageFocus(false); } diff --git a/content/browser/renderer_host/render_widget_host_impl.h b/content/browser/renderer_host/render_widget_host_impl.h index 240eec1..bde1d83 100644 --- a/content/browser/renderer_host/render_widget_host_impl.h +++ b/content/browser/renderer_host/render_widget_host_impl.h @@ -71,6 +71,7 @@ class BrowserAccessibilityManager; class InputRouter; class MockRenderWidgetHost; class RenderWidgetHostDelegate; +class RenderWidgetHostOwnerDelegate; class SyntheticGestureController; class TimeoutMonitor; class TouchEmulator; @@ -99,12 +100,11 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost, // Returns all RenderWidgetHosts including swapped out ones for // internal use. The public interface - // RendgerWidgetHost::GetRenderWidgetHosts only returns active ones. + // RenderWidgetHost::GetRenderWidgetHosts only returns active ones. static scoped_ptr<RenderWidgetHostIterator> GetAllRenderWidgetHosts(); - // Use RenderWidgetHostImpl::From(rwh) to downcast a - // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this - // uses RenderWidgetHost::AsRenderWidgetHostImpl(). + // Use RenderWidgetHostImpl::From(rwh) to downcast a RenderWidgetHost to a + // RenderWidgetHostImpl. static RenderWidgetHostImpl* From(RenderWidgetHost* rwh); void set_hung_renderer_delay(const base::TimeDelta& delay) { @@ -121,6 +121,13 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost, base::TimeDelta new_content_rendering_delay() { return new_content_rendering_delay_; } + + void set_owner_delegate(RenderWidgetHostOwnerDelegate* owner_delegate) { + owner_delegate_ = owner_delegate; + } + + RenderWidgetHostOwnerDelegate* owner_delegate() { return owner_delegate_; } + // RenderWidgetHost implementation. void UpdateTextDirection(blink::WebTextDirection direction) override; void NotifyTextDirection() override; @@ -143,7 +150,6 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost, int GetRoutingID() const override; RenderWidgetHostViewBase* GetView() const override; bool IsLoading() const override; - bool IsRenderView() const override; void ResizeRectChanged(const gfx::Rect& new_rect) override; void RestartHangMonitorTimeout() override; void SetIgnoreInputEvents(bool ignore_input_events) override; @@ -683,6 +689,9 @@ class CONTENT_EXPORT RenderWidgetHostImpl : public RenderWidgetHost, // It will remain non-NULL until DetachDelegate() is called. RenderWidgetHostDelegate* delegate_; + // The delegate of the owner of this object. + RenderWidgetHostOwnerDelegate* owner_delegate_; + // Created during construction and guaranteed never to be NULL, but its // channel may be NULL if the renderer crashed, so one must always check that. RenderProcessHost* const process_; diff --git a/content/browser/renderer_host/render_widget_host_owner_delegate.h b/content/browser/renderer_host/render_widget_host_owner_delegate.h new file mode 100644 index 0000000..9da6463 --- /dev/null +++ b/content/browser/renderer_host/render_widget_host_owner_delegate.h @@ -0,0 +1,26 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_OWNER_DELEGATE_H_ +#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_OWNER_DELEGATE_H_ + +#include "content/common/content_export.h" + +namespace content { + +// +// RenderWidgetHostOwnerDelegate +// +// An interface implemented by an object owning a RenderWidgetHost. This is +// intended to be temporary until the RenderViewHostImpl and +// RenderWidgetHostImpl classes are disentangled; see http://crbug.com/542477 +// and http://crbug.com/478281. +class CONTENT_EXPORT RenderWidgetHostOwnerDelegate { + protected: + virtual ~RenderWidgetHostOwnerDelegate() {} +}; + +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_OWNER_DELEGATE_H_ diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index 3ced095e..3b697b1 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -1354,9 +1354,8 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( frame_metadata.location_bar_content_translation, is_mobile_optimized); #if defined(VIDEO_HOLE) - if (host_ && host_->IsRenderView()) { - RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( - RenderViewHost::From(host_)); + if (host_) { + RenderViewHostImpl* rvhi = RenderViewHostImpl::From(host_); WebContentsImpl* web_contents_impl = static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvhi)); if (web_contents_impl) diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 1de892f2..2bd8271 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -765,13 +765,13 @@ void RenderWidgetHostViewAura::SetKeyboardFocus() { } RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() { - if (!host_->IsRenderView()) - return NULL; RenderViewHost* rvh = RenderViewHost::From(host_); + if (!rvh) + return nullptr; FrameTreeNode* focused_frame = rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame(); if (!focused_frame) - return NULL; + return nullptr; return focused_frame->current_frame_host(); } @@ -1403,13 +1403,14 @@ RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() { void RenderWidgetHostViewAura::ShowDisambiguationPopup( const gfx::Rect& rect_pixels, const SkBitmap& zoomed_bitmap) { - RenderViewHostDelegate* delegate = NULL; - if (host_->IsRenderView()) - delegate = RenderViewHost::From(host_)->GetDelegate(); - // Suppress the link disambiguation popup if the virtual keyboard is currently - // requested, as it doesn't interact well with the keyboard. - if (delegate && delegate->IsVirtualKeyboardRequested()) - return; + RenderViewHost* rvh = RenderViewHost::From(host_); + if (rvh) { + RenderViewHostDelegate* delegate = rvh->GetDelegate(); + // Suppress the link disambiguation popup if the virtual keyboard is + // currently requested, as it doesn't interact well with the keyboard. + if (delegate && delegate->IsVirtualKeyboardRequested()) + return; + } // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs // by scaling it by the inverse of the device scale factor. @@ -1443,15 +1444,18 @@ void RenderWidgetHostViewAura::DisambiguationPopupRendered( // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will // actually show the disambiguation popup. - RenderViewHostDelegate* delegate = NULL; - if (host_->IsRenderView()) - delegate = RenderViewHost::From(host_)->GetDelegate(); - RenderViewHostDelegateView* delegate_view = NULL; - if (delegate) { - delegate_view = delegate->GetDelegateView(); - if (delegate->IsVirtualKeyboardRequested()) - return; - } + RenderViewHost* rvh = RenderViewHost::From(host_); + if (!rvh) + return; + + RenderViewHostDelegate* delegate = rvh->GetDelegate(); + if (!delegate) + return; + + if (delegate->IsVirtualKeyboardRequested()) + return; + + RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView(); if (delegate_view) { delegate_view->ShowDisambiguationPopup( disambiguation_target_rect_, @@ -1464,12 +1468,15 @@ void RenderWidgetHostViewAura::DisambiguationPopupRendered( } void RenderWidgetHostViewAura::HideDisambiguationPopup() { - RenderViewHostDelegate* delegate = NULL; - if (host_->IsRenderView()) - delegate = RenderViewHost::From(host_)->GetDelegate(); - RenderViewHostDelegateView* delegate_view = NULL; - if (delegate) - delegate_view = delegate->GetDelegateView(); + RenderViewHost* rvh = RenderViewHost::From(host_); + if (!rvh) + return; + + RenderViewHostDelegate* delegate = rvh->GetDelegate(); + if (!delegate) + return; + + RenderViewHostDelegateView* delegate_view = delegate->GetDelegateView(); if (delegate_view) delegate_view->HideDisambiguationPopup(); } diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index 4764e5f..aee3432 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -1461,9 +1461,6 @@ gfx::Range RenderWidgetHostViewMac::ConvertCharacterRangeToCompositionRange( } WebContents* RenderWidgetHostViewMac::GetWebContents() { - if (!render_widget_host_->IsRenderView()) - return NULL; - return WebContents::FromRenderViewHost( RenderViewHost::From(render_widget_host_)); } @@ -2749,15 +2746,15 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( } SEL action = [item action]; + BOOL is_render_view = + RenderViewHost::From(renderWidgetHostView_->render_widget_host_) != + nullptr; - if (action == @selector(stopSpeaking:)) { - return renderWidgetHostView_->render_widget_host_->IsRenderView() && - renderWidgetHostView_->IsSpeaking(); - } - if (action == @selector(startSpeaking:)) { - return renderWidgetHostView_->render_widget_host_->IsRenderView() && - renderWidgetHostView_->SupportsSpeech(); - } + if (action == @selector(stopSpeaking:)) + return is_render_view && renderWidgetHostView_->IsSpeaking(); + + if (action == @selector(startSpeaking:)) + return is_render_view && renderWidgetHostView_->SupportsSpeech(); // For now, these actions are always enabled for render view, // this is sub-optimal. @@ -2769,7 +2766,7 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( action == @selector(copyToFindPboard:) || action == @selector(paste:) || action == @selector(pasteAndMatchStyle:)) { - return renderWidgetHostView_->render_widget_host_->IsRenderView(); + return is_render_view; } return editCommand_helper_->IsMenuItemEnabled(action, self); diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 5dce2b3..fa61d69 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -279,15 +279,16 @@ void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( } } -WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { +WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { + if (!rvh) + return nullptr; return rvh->GetDelegate()->GetAsWebContents(); } WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { - RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh); - if (!rfh_impl) - return NULL; - return rfh_impl->delegate()->GetAsWebContents(); + if (!rfh) + return nullptr; + return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); } // WebContentsImpl::DestructionObserver ---------------------------------------- @@ -546,21 +547,18 @@ std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { std::vector<WebContentsImpl*> result; scoped_ptr<RenderWidgetHostIterator> widgets( RenderWidgetHostImpl::GetRenderWidgetHosts()); - std::set<WebContentsImpl*> web_contents_set; while (RenderWidgetHost* rwh = widgets->GetNextHost()) { - if (!rwh->IsRenderView()) - continue; RenderViewHost* rvh = RenderViewHost::From(rwh); if (!rvh) continue; WebContents* web_contents = WebContents::FromRenderViewHost(rvh); if (!web_contents) continue; - WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents); - if (web_contents_set.find(wci) == web_contents_set.end()) { - web_contents_set.insert(wci); - result.push_back(wci); - } + if (web_contents->GetRenderViewHost() != rvh) + continue; + // Because a WebContents can only have one current RVH at a time, there will + // be no duplicate WebContents here. + result.push_back(static_cast<WebContentsImpl*>(web_contents)); } return result; } diff --git a/content/content_browser.gypi b/content/content_browser.gypi index be0d346..b645c11 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -1298,6 +1298,7 @@ 'browser/renderer_host/render_widget_host_impl.h', 'browser/renderer_host/render_widget_host_input_event_router.cc', 'browser/renderer_host/render_widget_host_input_event_router.h', + 'browser/renderer_host/render_widget_host_owner_delegate.h', 'browser/renderer_host/render_widget_host_view_android.cc', 'browser/renderer_host/render_widget_host_view_android.h', 'browser/renderer_host/render_widget_host_view_aura.cc', diff --git a/content/public/browser/render_widget_host.h b/content/public/browser/render_widget_host.h index 47af770..d7d3983 100644 --- a/content/public/browser/render_widget_host.h +++ b/content/public/browser/render_widget_host.h @@ -211,9 +211,6 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Sender { // Returns true if the renderer is loading, false if not. virtual bool IsLoading() const = 0; - // Returns true if this is a RenderViewHost, false if not. - virtual bool IsRenderView() const = 0; - // Called to notify the RenderWidget that the resize rect has changed without // the size of the RenderWidget itself changing. virtual void ResizeRectChanged(const gfx::Rect& new_rect) = 0; diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 46918e5..a991d90 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -163,10 +163,9 @@ class WebContents : public PageNavigator, const CreateParams& params, const SessionStorageNamespaceMap& session_storage_namespace_map); - // Returns a WebContents that wraps the RenderViewHost, or nullptr if the + // Returns the WebContents that owns the RenderViewHost, or nullptr if the // render view host's delegate isn't a WebContents. - CONTENT_EXPORT static WebContents* FromRenderViewHost( - const RenderViewHost* rvh); + CONTENT_EXPORT static WebContents* FromRenderViewHost(RenderViewHost* rvh); CONTENT_EXPORT static WebContents* FromRenderFrameHost(RenderFrameHost* rfh); diff --git a/extensions/shell/browser/shell_speech_recognition_manager_delegate.cc b/extensions/shell/browser/shell_speech_recognition_manager_delegate.cc index 9fc2f65..c4ce068c 100644 --- a/extensions/shell/browser/shell_speech_recognition_manager_delegate.cc +++ b/extensions/shell/browser/shell_speech_recognition_manager_delegate.cc @@ -105,7 +105,7 @@ void ShellSpeechRecognitionManagerDelegate::CheckRenderViewType( int render_process_id, int render_view_id) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - const content::RenderViewHost* render_view_host = + content::RenderViewHost* render_view_host = content::RenderViewHost::FromID(render_process_id, render_view_id); bool allowed = false; bool check_permission = false; |