diff options
author | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-16 12:59:18 +0000 |
---|---|---|
committer | joi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-16 12:59:18 +0000 |
commit | 6b618e62ab66de3e8a923368d2a41b078218d0ed (patch) | |
tree | 42145ad803d108116aee4915853d88334392a594 /content/browser | |
parent | 414c90e876a361a7233afe03b1cebf208a733a74 (diff) | |
download | chromium_src-6b618e62ab66de3e8a923368d2a41b078218d0ed.zip chromium_src-6b618e62ab66de3e8a923368d2a41b078218d0ed.tar.gz chromium_src-6b618e62ab66de3e8a923368d2a41b078218d0ed.tar.bz2 |
Add IPC::Sender and GetRoutingID() to WebContents for convenience and safety.
Code that is or has a WebContentsObserver can already use safe
versions of Send() and GetRoutingID() that perform NULL checks and
delete the Message object and return MSG_ROUTING_NONE when
appropriate. This brings the same thing to code that has just a
WebContents.
BUG=none
Review URL: https://chromiumcodereview.appspot.com/10830337
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/web_contents/web_contents_impl.cc | 40 | ||||
-rw-r--r-- | content/browser/web_contents/web_contents_impl.h | 4 |
2 files changed, 30 insertions, 14 deletions
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 32ff95d..cee3043 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -751,6 +751,13 @@ RenderViewHost* WebContentsImpl::GetRenderViewHost() const { return render_manager_.current_host(); } +int WebContentsImpl::GetRoutingID() const { + if (!GetRenderViewHost()) + return MSG_ROUTING_NONE; + + return GetRenderViewHost()->GetRoutingID(); +} + RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { return render_manager_.GetRenderWidgetHostView(); } @@ -1449,6 +1456,15 @@ WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { return new_contents; } +bool WebContentsImpl::Send(IPC::Message* message) { + if (!GetRenderViewHost()) { + delete message; + return false; + } + + return GetRenderViewHost()->Send(message); +} + bool WebContentsImpl::NavigateToPendingEntry( NavigationController::ReloadType reload_type) { return NavigateToEntry( @@ -1559,9 +1575,9 @@ void WebContentsImpl::SetHistoryLengthAndPrune( NOTREACHED(); return; } - rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(), - history_length, - minimum_page_id)); + Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(), + history_length, + minimum_page_id)); } void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { @@ -1646,14 +1662,12 @@ bool WebContentsImpl::WillNotifyDisconnection() const { void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { SetEncoding(encoding); - GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding( - GetRenderViewHost()->GetRoutingID(), encoding)); + Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding)); } void WebContentsImpl::ResetOverrideEncoding() { encoding_.clear(); - GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault( - GetRenderViewHost()->GetRoutingID())); + Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID())); } content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { @@ -1835,13 +1849,12 @@ bool WebContentsImpl::HasOpener() const { void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id, SkColor color) { - GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse( - GetRenderViewHost()->GetRoutingID(), color_chooser_id, color)); + Send(new ViewMsg_DidChooseColorResponse( + GetRoutingID(), color_chooser_id, color)); } void WebContentsImpl::DidEndColorChooser(int color_chooser_id) { - GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser( - GetRenderViewHost()->GetRoutingID(), color_chooser_id)); + Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id)); if (delegate_) delegate_->DidEndColorChooser(); color_chooser_ = NULL; @@ -2452,7 +2465,7 @@ void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { if (entry->IsViewSourceMode()) { // Put the renderer in view source mode. - static_cast<RenderViewHostImpl*>(render_view_host)->Send( + render_view_host->Send( new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); } @@ -2846,8 +2859,7 @@ void WebContentsImpl::RouteMessageEvent( // In most cases, we receive this from a swapped out RenderViewHost. // It is possible to receive it from one that has just been swapped in, // in which case we might as well deliver the message anyway. - GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent( - GetRenderViewHost()->GetRoutingID(), new_params)); + Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); } void WebContentsImpl::RunJavaScriptMessage( diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 8d55043..b9320ae 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -172,6 +172,7 @@ class CONTENT_EXPORT WebContentsImpl virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; virtual content::RenderProcessHost* GetRenderProcessHost() const OVERRIDE; virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE; + virtual int GetRoutingID() const OVERRIDE; virtual content::RenderWidgetHostView* GetRenderWidgetHostView() const OVERRIDE; virtual content::WebContentsView* GetView() const OVERRIDE; @@ -264,6 +265,9 @@ class CONTENT_EXPORT WebContentsImpl virtual content::WebContents* OpenURL( const content::OpenURLParams& params) OVERRIDE; + // Implementation of IPC::Sender. + virtual bool Send(IPC::Message* message) OVERRIDE; + // RenderViewHostDelegate ---------------------------------------------------- virtual content::RenderViewHostDelegateView* GetDelegateView() OVERRIDE; |