Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 736
737 content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { 737 content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
738 RenderViewHostImpl* host = render_manager_.current_host(); 738 RenderViewHostImpl* host = render_manager_.current_host();
739 return host ? host->GetProcess() : NULL; 739 return host ? host->GetProcess() : NULL;
740 } 740 }
741 741
742 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { 742 RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
743 return render_manager_.current_host(); 743 return render_manager_.current_host();
744 } 744 }
745 745
746 int WebContentsImpl::GetRoutingID() const {
747 if (!GetRenderViewHost())
748 return MSG_ROUTING_NONE;
749
750 return GetRenderViewHost()->GetRoutingID();
751 }
752
746 RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { 753 RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
747 return render_manager_.GetRenderWidgetHostView(); 754 return render_manager_.GetRenderWidgetHostView();
748 } 755 }
749 756
750 content::WebContentsView* WebContentsImpl::GetView() const { 757 content::WebContentsView* WebContentsImpl::GetView() const {
751 return view_.get(); 758 return view_.get();
752 } 759 }
753 760
754 content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) { 761 content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
755 WebUIControllerFactory* factory = 762 WebUIControllerFactory* factory =
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 return NULL; 1441 return NULL;
1435 1442
1436 WebContents* new_contents = delegate_->OpenURLFromTab(this, params); 1443 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1437 // Notify observers. 1444 // Notify observers.
1438 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 1445 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1439 DidOpenURL(params.url, params.referrer, 1446 DidOpenURL(params.url, params.referrer,
1440 params.disposition, params.transition)); 1447 params.disposition, params.transition));
1441 return new_contents; 1448 return new_contents;
1442 } 1449 }
1443 1450
1451 bool WebContentsImpl::Send(IPC::Message* message) {
1452 if (!GetRenderViewHost()) {
1453 delete message;
1454 return false;
1455 }
1456
1457 return GetRenderViewHost()->Send(message);
1458 }
1459
1444 bool WebContentsImpl::NavigateToPendingEntry( 1460 bool WebContentsImpl::NavigateToPendingEntry(
1445 NavigationController::ReloadType reload_type) { 1461 NavigationController::ReloadType reload_type) {
1446 return NavigateToEntry( 1462 return NavigateToEntry(
1447 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()), 1463 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
1448 reload_type); 1464 reload_type);
1449 } 1465 }
1450 1466
1451 void WebContentsImpl::RenderViewForInterstitialPageCreated( 1467 void WebContentsImpl::RenderViewForInterstitialPageCreated(
1452 content::RenderViewHost* render_view_host) { 1468 content::RenderViewHost* render_view_host) {
1453 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 1469 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 } 1560 }
1545 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); 1561 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
1546 if (!rvh) { 1562 if (!rvh) {
1547 NOTREACHED(); 1563 NOTREACHED();
1548 return; 1564 return;
1549 } 1565 }
1550 if (site_instance && rvh->GetSiteInstance() != site_instance) { 1566 if (site_instance && rvh->GetSiteInstance() != site_instance) {
1551 NOTREACHED(); 1567 NOTREACHED();
1552 return; 1568 return;
1553 } 1569 }
1554 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(), 1570 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1555 history_length, 1571 history_length,
1556 minimum_page_id)); 1572 minimum_page_id));
1557 } 1573 }
1558 1574
1559 void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { 1575 void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
1560 if (ShowingInterstitialPage()) { 1576 if (ShowingInterstitialPage()) {
1561 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); 1577 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1562 return; 1578 return;
1563 } 1579 }
1564 GetRenderViewHostImpl()->SetInitialFocus(reverse); 1580 GetRenderViewHostImpl()->SetInitialFocus(reverse);
1565 } 1581 }
1566 1582
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 const std::string& WebContentsImpl::GetContentsMimeType() const { 1647 const std::string& WebContentsImpl::GetContentsMimeType() const {
1632 return contents_mime_type_; 1648 return contents_mime_type_;
1633 } 1649 }
1634 1650
1635 bool WebContentsImpl::WillNotifyDisconnection() const { 1651 bool WebContentsImpl::WillNotifyDisconnection() const {
1636 return notify_disconnection_; 1652 return notify_disconnection_;
1637 } 1653 }
1638 1654
1639 void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { 1655 void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
1640 SetEncoding(encoding); 1656 SetEncoding(encoding);
1641 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding( 1657 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
1642 GetRenderViewHost()->GetRoutingID(), encoding));
1643 } 1658 }
1644 1659
1645 void WebContentsImpl::ResetOverrideEncoding() { 1660 void WebContentsImpl::ResetOverrideEncoding() {
1646 encoding_.clear(); 1661 encoding_.clear();
1647 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault( 1662 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
1648 GetRenderViewHost()->GetRoutingID()));
1649 } 1663 }
1650 1664
1651 content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { 1665 content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
1652 return &renderer_preferences_; 1666 return &renderer_preferences_;
1653 } 1667 }
1654 1668
1655 void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) { 1669 void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
1656 new_tab_start_time_ = time; 1670 new_tab_start_time_ = time;
1657 } 1671 }
1658 1672
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 return GetRenderViewHost() ? 1834 return GetRenderViewHost() ?
1821 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false; 1835 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
1822 } 1836 }
1823 1837
1824 bool WebContentsImpl::HasOpener() const { 1838 bool WebContentsImpl::HasOpener() const {
1825 return opener_ != NULL; 1839 return opener_ != NULL;
1826 } 1840 }
1827 1841
1828 void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id, 1842 void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
1829 SkColor color) { 1843 SkColor color) {
1830 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse( 1844 Send(new ViewMsg_DidChooseColorResponse(
1831 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color)); 1845 GetRoutingID(), color_chooser_id, color));
1832 } 1846 }
1833 1847
1834 void WebContentsImpl::DidEndColorChooser(int color_chooser_id) { 1848 void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
1835 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser( 1849 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
1836 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1837 if (delegate_) 1850 if (delegate_)
1838 delegate_->DidEndColorChooser(); 1851 delegate_->DidEndColorChooser();
1839 color_chooser_ = NULL; 1852 color_chooser_ = NULL;
1840 } 1853 }
1841 1854
1842 bool WebContentsImpl::FocusLocationBarByDefault() { 1855 bool WebContentsImpl::FocusLocationBarByDefault() {
1843 content::WebUI* web_ui = GetWebUIForCurrentState(); 1856 content::WebUI* web_ui = GetWebUIForCurrentState();
1844 if (web_ui) 1857 if (web_ui)
1845 return web_ui->ShouldFocusLocationBarByDefault(); 1858 return web_ui->ShouldFocusLocationBarByDefault();
1846 NavigationEntry* entry = controller_.GetActiveEntry(); 1859 NavigationEntry* entry = controller_.GetActiveEntry();
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 if (!entry) 2450 if (!entry)
2438 return; 2451 return;
2439 2452
2440 // When we're creating views, we're still doing initial setup, so we always 2453 // When we're creating views, we're still doing initial setup, so we always
2441 // use the pending Web UI rather than any possibly existing committed one. 2454 // use the pending Web UI rather than any possibly existing committed one.
2442 if (render_manager_.pending_web_ui()) 2455 if (render_manager_.pending_web_ui())
2443 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); 2456 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
2444 2457
2445 if (entry->IsViewSourceMode()) { 2458 if (entry->IsViewSourceMode()) {
2446 // Put the renderer in view source mode. 2459 // Put the renderer in view source mode.
2447 static_cast<RenderViewHostImpl*>(render_view_host)->Send( 2460 Send(new ViewMsg_EnableViewSourceMode(GetRoutingID()));
jam 2012/08/15 16:22:02 I think you need to keep this as is. render_view_
Jói 2012/08/15 19:13:24 Phew, thanks for catching that!
2448 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
2449 } 2461 }
2450 2462
2451 GetView()->RenderViewCreated(render_view_host); 2463 GetView()->RenderViewCreated(render_view_host);
2452 2464
2453 FOR_EACH_OBSERVER( 2465 FOR_EACH_OBSERVER(
2454 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); 2466 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
2455 } 2467 }
2456 2468
2457 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { 2469 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
2458 if (rvh != GetRenderViewHost()) { 2470 if (rvh != GetRenderViewHost()) {
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 source_contents->CreateOpenerRenderViews(GetSiteInstance()); 2843 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2832 } else { 2844 } else {
2833 // We couldn't find it, so don't pass a source frame. 2845 // We couldn't find it, so don't pass a source frame.
2834 new_params.source_routing_id = MSG_ROUTING_NONE; 2846 new_params.source_routing_id = MSG_ROUTING_NONE;
2835 } 2847 }
2836 } 2848 }
2837 2849
2838 // In most cases, we receive this from a swapped out RenderViewHost. 2850 // In most cases, we receive this from a swapped out RenderViewHost.
2839 // It is possible to receive it from one that has just been swapped in, 2851 // It is possible to receive it from one that has just been swapped in,
2840 // in which case we might as well deliver the message anyway. 2852 // in which case we might as well deliver the message anyway.
2841 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent( 2853 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
2842 GetRenderViewHost()->GetRoutingID(), new_params));
2843 } 2854 }
2844 2855
2845 void WebContentsImpl::RunJavaScriptMessage( 2856 void WebContentsImpl::RunJavaScriptMessage(
2846 RenderViewHost* rvh, 2857 RenderViewHost* rvh,
2847 const string16& message, 2858 const string16& message,
2848 const string16& default_prompt, 2859 const string16& default_prompt,
2849 const GURL& frame_url, 2860 const GURL& frame_url,
2850 content::JavaScriptMessageType javascript_message_type, 2861 content::JavaScriptMessageType javascript_message_type,
2851 IPC::Message* reply_msg, 2862 IPC::Message* reply_msg,
2852 bool* did_suppress_message) { 2863 bool* did_suppress_message) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
3184 old_browser_plugin_host()->embedder_render_process_host(); 3195 old_browser_plugin_host()->embedder_render_process_host();
3185 *embedder_container_id = old_browser_plugin_host()->instance_id(); 3196 *embedder_container_id = old_browser_plugin_host()->instance_id();
3186 int embedder_process_id = 3197 int embedder_process_id =
3187 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; 3198 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3188 if (embedder_process_id != -1) { 3199 if (embedder_process_id != -1) {
3189 *embedder_channel_name = 3200 *embedder_channel_name =
3190 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), 3201 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3191 embedder_process_id); 3202 embedder_process_id);
3192 } 3203 }
3193 } 3204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698