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

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: 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 744
745 content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { 745 content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
746 RenderViewHostImpl* host = render_manager_.current_host(); 746 RenderViewHostImpl* host = render_manager_.current_host();
747 return host ? host->GetProcess() : NULL; 747 return host ? host->GetProcess() : NULL;
748 } 748 }
749 749
750 RenderViewHost* WebContentsImpl::GetRenderViewHost() const { 750 RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
751 return render_manager_.current_host(); 751 return render_manager_.current_host();
752 } 752 }
753 753
754 int WebContentsImpl::GetRoutingID() const {
755 if (!GetRenderViewHost())
756 return MSG_ROUTING_NONE;
757
758 return GetRenderViewHost()->GetRoutingID();
759 }
760
754 RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { 761 RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
755 return render_manager_.GetRenderWidgetHostView(); 762 return render_manager_.GetRenderWidgetHostView();
756 } 763 }
757 764
758 content::WebContentsView* WebContentsImpl::GetView() const { 765 content::WebContentsView* WebContentsImpl::GetView() const {
759 return view_.get(); 766 return view_.get();
760 } 767 }
761 768
762 content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) { 769 content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
763 WebUIControllerFactory* factory = 770 WebUIControllerFactory* factory =
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 return NULL; 1449 return NULL;
1443 1450
1444 WebContents* new_contents = delegate_->OpenURLFromTab(this, params); 1451 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1445 // Notify observers. 1452 // Notify observers.
1446 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 1453 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1447 DidOpenURL(params.url, params.referrer, 1454 DidOpenURL(params.url, params.referrer,
1448 params.disposition, params.transition)); 1455 params.disposition, params.transition));
1449 return new_contents; 1456 return new_contents;
1450 } 1457 }
1451 1458
1459 bool WebContentsImpl::Send(IPC::Message* message) {
1460 if (!GetRenderViewHost()) {
1461 delete message;
1462 return false;
1463 }
1464
1465 return GetRenderViewHost()->Send(message);
1466 }
1467
1452 bool WebContentsImpl::NavigateToPendingEntry( 1468 bool WebContentsImpl::NavigateToPendingEntry(
1453 NavigationController::ReloadType reload_type) { 1469 NavigationController::ReloadType reload_type) {
1454 return NavigateToEntry( 1470 return NavigateToEntry(
1455 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()), 1471 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
1456 reload_type); 1472 reload_type);
1457 } 1473 }
1458 1474
1459 void WebContentsImpl::RenderViewForInterstitialPageCreated( 1475 void WebContentsImpl::RenderViewForInterstitialPageCreated(
1460 content::RenderViewHost* render_view_host) { 1476 content::RenderViewHost* render_view_host) {
1461 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 1477 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } 1568 }
1553 RenderViewHostImpl* rvh = GetRenderViewHostImpl(); 1569 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
1554 if (!rvh) { 1570 if (!rvh) {
1555 NOTREACHED(); 1571 NOTREACHED();
1556 return; 1572 return;
1557 } 1573 }
1558 if (site_instance && rvh->GetSiteInstance() != site_instance) { 1574 if (site_instance && rvh->GetSiteInstance() != site_instance) {
1559 NOTREACHED(); 1575 NOTREACHED();
1560 return; 1576 return;
1561 } 1577 }
1562 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(), 1578 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1563 history_length, 1579 history_length,
1564 minimum_page_id)); 1580 minimum_page_id));
1565 } 1581 }
1566 1582
1567 void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { 1583 void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
1568 if (ShowingInterstitialPage()) { 1584 if (ShowingInterstitialPage()) {
1569 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); 1585 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1570 return; 1586 return;
1571 } 1587 }
1572 GetRenderViewHostImpl()->SetInitialFocus(reverse); 1588 GetRenderViewHostImpl()->SetInitialFocus(reverse);
1573 } 1589 }
1574 1590
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 const std::string& WebContentsImpl::GetContentsMimeType() const { 1655 const std::string& WebContentsImpl::GetContentsMimeType() const {
1640 return contents_mime_type_; 1656 return contents_mime_type_;
1641 } 1657 }
1642 1658
1643 bool WebContentsImpl::WillNotifyDisconnection() const { 1659 bool WebContentsImpl::WillNotifyDisconnection() const {
1644 return notify_disconnection_; 1660 return notify_disconnection_;
1645 } 1661 }
1646 1662
1647 void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { 1663 void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
1648 SetEncoding(encoding); 1664 SetEncoding(encoding);
1649 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding( 1665 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
1650 GetRenderViewHost()->GetRoutingID(), encoding));
1651 } 1666 }
1652 1667
1653 void WebContentsImpl::ResetOverrideEncoding() { 1668 void WebContentsImpl::ResetOverrideEncoding() {
1654 encoding_.clear(); 1669 encoding_.clear();
1655 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault( 1670 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
1656 GetRenderViewHost()->GetRoutingID()));
1657 } 1671 }
1658 1672
1659 content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { 1673 content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
1660 return &renderer_preferences_; 1674 return &renderer_preferences_;
1661 } 1675 }
1662 1676
1663 void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) { 1677 void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
1664 new_tab_start_time_ = time; 1678 new_tab_start_time_ = time;
1665 } 1679 }
1666 1680
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 return GetRenderViewHost() ? 1842 return GetRenderViewHost() ?
1829 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false; 1843 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
1830 } 1844 }
1831 1845
1832 bool WebContentsImpl::HasOpener() const { 1846 bool WebContentsImpl::HasOpener() const {
1833 return opener_ != NULL; 1847 return opener_ != NULL;
1834 } 1848 }
1835 1849
1836 void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id, 1850 void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
1837 SkColor color) { 1851 SkColor color) {
1838 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse( 1852 Send(new ViewMsg_DidChooseColorResponse(
1839 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color)); 1853 GetRoutingID(), color_chooser_id, color));
1840 } 1854 }
1841 1855
1842 void WebContentsImpl::DidEndColorChooser(int color_chooser_id) { 1856 void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
1843 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser( 1857 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(), color_chooser_id));
1844 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1845 if (delegate_) 1858 if (delegate_)
1846 delegate_->DidEndColorChooser(); 1859 delegate_->DidEndColorChooser();
1847 color_chooser_ = NULL; 1860 color_chooser_ = NULL;
1848 } 1861 }
1849 1862
1850 bool WebContentsImpl::FocusLocationBarByDefault() { 1863 bool WebContentsImpl::FocusLocationBarByDefault() {
1851 content::WebUI* web_ui = GetWebUIForCurrentState(); 1864 content::WebUI* web_ui = GetWebUIForCurrentState();
1852 if (web_ui) 1865 if (web_ui)
1853 return web_ui->ShouldFocusLocationBarByDefault(); 1866 return web_ui->ShouldFocusLocationBarByDefault();
1854 NavigationEntry* entry = controller_.GetActiveEntry(); 1867 NavigationEntry* entry = controller_.GetActiveEntry();
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 if (!entry) 2458 if (!entry)
2446 return; 2459 return;
2447 2460
2448 // When we're creating views, we're still doing initial setup, so we always 2461 // When we're creating views, we're still doing initial setup, so we always
2449 // use the pending Web UI rather than any possibly existing committed one. 2462 // use the pending Web UI rather than any possibly existing committed one.
2450 if (render_manager_.pending_web_ui()) 2463 if (render_manager_.pending_web_ui())
2451 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); 2464 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
2452 2465
2453 if (entry->IsViewSourceMode()) { 2466 if (entry->IsViewSourceMode()) {
2454 // Put the renderer in view source mode. 2467 // Put the renderer in view source mode.
2455 static_cast<RenderViewHostImpl*>(render_view_host)->Send( 2468 render_view_host->Send(
2456 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); 2469 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
2457 } 2470 }
2458 2471
2459 GetView()->RenderViewCreated(render_view_host); 2472 GetView()->RenderViewCreated(render_view_host);
2460 2473
2461 FOR_EACH_OBSERVER( 2474 FOR_EACH_OBSERVER(
2462 WebContentsObserver, observers_, RenderViewCreated(render_view_host)); 2475 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
2463 } 2476 }
2464 2477
2465 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { 2478 void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 source_contents->CreateOpenerRenderViews(GetSiteInstance()); 2852 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2840 } else { 2853 } else {
2841 // We couldn't find it, so don't pass a source frame. 2854 // We couldn't find it, so don't pass a source frame.
2842 new_params.source_routing_id = MSG_ROUTING_NONE; 2855 new_params.source_routing_id = MSG_ROUTING_NONE;
2843 } 2856 }
2844 } 2857 }
2845 2858
2846 // In most cases, we receive this from a swapped out RenderViewHost. 2859 // In most cases, we receive this from a swapped out RenderViewHost.
2847 // It is possible to receive it from one that has just been swapped in, 2860 // It is possible to receive it from one that has just been swapped in,
2848 // in which case we might as well deliver the message anyway. 2861 // in which case we might as well deliver the message anyway.
2849 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent( 2862 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
2850 GetRenderViewHost()->GetRoutingID(), new_params));
2851 } 2863 }
2852 2864
2853 void WebContentsImpl::RunJavaScriptMessage( 2865 void WebContentsImpl::RunJavaScriptMessage(
2854 RenderViewHost* rvh, 2866 RenderViewHost* rvh,
2855 const string16& message, 2867 const string16& message,
2856 const string16& default_prompt, 2868 const string16& default_prompt,
2857 const GURL& frame_url, 2869 const GURL& frame_url,
2858 content::JavaScriptMessageType javascript_message_type, 2870 content::JavaScriptMessageType javascript_message_type,
2859 IPC::Message* reply_msg, 2871 IPC::Message* reply_msg,
2860 bool* did_suppress_message) { 2872 bool* did_suppress_message) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
3192 old_browser_plugin_host()->embedder_render_process_host(); 3204 old_browser_plugin_host()->embedder_render_process_host();
3193 *embedder_container_id = old_browser_plugin_host()->instance_id(); 3205 *embedder_container_id = old_browser_plugin_host()->instance_id();
3194 int embedder_process_id = 3206 int embedder_process_id =
3195 embedder_render_process_host ? embedder_render_process_host->GetID() : -1; 3207 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3196 if (embedder_process_id != -1) { 3208 if (embedder_process_id != -1) {
3197 *embedder_channel_name = 3209 *embedder_channel_name =
3198 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), 3210 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3199 embedder_process_id); 3211 embedder_process_id);
3200 } 3212 }
3201 } 3213 }
OLDNEW
« 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