Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1349)

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 10830337: Add IPC::Sender and GetRoutingID() to WebContents for convenience and safety. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/web_contents.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 32ff95d3a7c8740dbd9612da83c5626552c0b4ea..cee3043ec6c0f9d39b64d34c1fbab5f98f3d9b5f 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(
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/web_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698