Skip to content

Commit

Permalink
Replace the GetAssociatedRenderView call with GetAssociatedRenderFram…
Browse files Browse the repository at this point in the history
…e in InterceptNavigationResourceThrottle.

BUG=304341

Review URL: https://codereview.chromium.org/106203003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242655 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jam@chromium.org committed Dec 28, 2013
1 parent c5eb493 commit 5dcaf8e
Show file tree
Hide file tree
Showing 31 changed files with 176 additions and 193 deletions.
8 changes: 2 additions & 6 deletions chrome/browser/apps/app_url_redirector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace {
bool LaunchAppWithUrl(
const scoped_refptr<const Extension> app,
const std::string& handler_id,
content::RenderViewHost* source,
content::WebContents* source,
const navigation_interception::NavigationParams& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

Expand All @@ -50,12 +50,8 @@ bool LaunchAppWithUrl(
DCHECK(!params.is_post());
DCHECK(UrlHandlers::CanExtensionHandleUrl(app, params.url()));

WebContents* web_contents = WebContents::FromRenderViewHost(source);
if (!web_contents)
return false;

Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
Profile::FromBrowserContext(source->GetBrowserContext());

DVLOG(1) << "Launching app handler with URL: "
<< params.url().spec() << " -> "
Expand Down
12 changes: 4 additions & 8 deletions chrome/browser/apps/ephemeral_app_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ namespace {

bool LaunchEphemeralApp(
const std::string& app_id,
content::RenderViewHost* source,
content::WebContents* source,
const navigation_interception::NavigationParams& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

// Redirect top-level navigations only.
if (source->IsSubframe())
return false;

WebContents* web_contents = WebContents::FromRenderViewHost(source);
if (!web_contents)
return false;

Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
Profile::FromBrowserContext(source->GetBrowserContext());
if (!profile)
return false;

Expand All @@ -56,15 +52,15 @@ bool LaunchEphemeralApp(
// If the app is already installed, launch it.
AppLaunchParams params(profile, extension, NEW_FOREGROUND_TAB);
params.desktop_type = chrome::GetHostDesktopTypeForNativeView(
web_contents->GetView()->GetNativeView());
source->GetView()->GetNativeView());
OpenApplication(params);
return true;
}

if (!extension) {
// Install ephemeral app and launch.
scoped_refptr<EphemeralAppLauncher> installer =
EphemeralAppLauncher::CreateForLink(app_id, web_contents);
EphemeralAppLauncher::CreateForLink(app_id, source);
installer->Start();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ TEST(WebRequestConditionAttributeTest, ResourceType) {
net::TestURLRequest url_request_ok(
GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(
&url_request_ok, ResourceType::SUB_FRAME, NULL, -1, -1, false);
&url_request_ok, ResourceType::SUB_FRAME, NULL, -1, -1, -1, false);
EXPECT_TRUE(attribute->IsFulfilled(WebRequestData(&url_request_ok,
ON_BEFORE_REQUEST)));

net::TestURLRequest url_request_fail(
GURL("http://www.example.com"), net::DEFAULT_PRIORITY, NULL, &context);
content::ResourceRequestInfo::AllocateForTesting(
&url_request_fail, ResourceType::MAIN_FRAME, NULL, -1, -1, false);
&url_request_fail, ResourceType::MAIN_FRAME, NULL, -1, -1, -1, false);
EXPECT_FALSE(attribute->IsFulfilled(WebRequestData(&url_request_fail,
ON_BEFORE_REQUEST)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST(WebRequestConditionTest, CreateCondition) {
request_data.url_match_ids = matcher.MatchURL(http_url);
EXPECT_EQ(1u, request_data.url_match_ids.size());
content::ResourceRequestInfo::AllocateForTesting(
&match_request, ResourceType::MAIN_FRAME, NULL, -1, -1, false);
&match_request, ResourceType::MAIN_FRAME, NULL, -1, -1, -1, false);
EXPECT_TRUE(result->IsFulfilled(request_data));

const GURL https_url("https://www.example.com");
Expand All @@ -95,7 +95,7 @@ TEST(WebRequestConditionTest, CreateCondition) {
// Make sure IsFulfilled does not fail because of URL matching.
EXPECT_EQ(1u, request_data.url_match_ids.size());
content::ResourceRequestInfo::AllocateForTesting(
&wrong_resource_type, ResourceType::SUB_FRAME, NULL, -1, -1, false);
&wrong_resource_type, ResourceType::SUB_FRAME, NULL, -1, -1, -1, false);
EXPECT_FALSE(result->IsFulfilled(request_data));
}

Expand Down Expand Up @@ -135,7 +135,7 @@ TEST(WebRequestConditionTest, CreateConditionFirstPartyForCookies) {
request_data.first_party_url_match_ids = matcher.MatchURL(first_party_url);
EXPECT_EQ(1u, request_data.first_party_url_match_ids.size());
content::ResourceRequestInfo::AllocateForTesting(
&match_request, ResourceType::MAIN_FRAME, NULL, -1, -1, false);
&match_request, ResourceType::MAIN_FRAME, NULL, -1, -1, -1, false);
EXPECT_TRUE(result->IsFulfilled(request_data));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "content/public/browser/resource_request_info.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/info_map.h"
#include "ipc/ipc_message.h"
#include "net/base/request_priority.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -128,7 +129,7 @@ TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, TestHideRequestForURL) {
non_sensitive_url, net::DEFAULT_PRIORITY, NULL, &context);
ResourceRequestInfo::AllocateForTesting(
&sensitive_request, ResourceType::SCRIPT, NULL,
process_id, frame_id, false);
process_id, frame_id, MSG_ROUTING_NONE, false);
extension_info_map_->RegisterExtensionProcess(
extension_misc::kWebStoreAppId, process_id, site_instance_id);
EXPECT_TRUE(WebRequestPermissions::HideRequest(extension_info_map_.get(),
Expand All @@ -142,7 +143,7 @@ TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, TestHideRequestForURL) {
non_sensitive_url, net::DEFAULT_PRIORITY, NULL, &context);
ResourceRequestInfo::AllocateForTesting(
&sensitive_request, ResourceType::SCRIPT, NULL,
process_id, frame_id, false);
process_id, frame_id, MSG_ROUTING_NONE, false);
EXPECT_TRUE(WebRequestPermissions::HideRequest(extension_info_map_.get(),
&sensitive_request));
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/extensions/extension_protocols_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class ExtensionProtocolTest : public testing::Test {
&resource_context_,
-1,
-1,
-1,
false);
request->Start();
base::MessageLoop::current()->Run();
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/prerender/prerender_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "content/public/browser/resource_request_info.h"
#include "content/public/test/test_browser_thread.h"
#include "content/test/net/url_request_mock_http_job.h"
#include "ipc/ipc_message.h"
#include "net/base/request_priority.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_test_util.h"
Expand Down Expand Up @@ -534,7 +535,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectResume) {
&url_request_context);
content::ResourceRequestInfo::AllocateForTesting(
&request, ResourceType::IMAGE, NULL,
kDefaultChildId, kDefaultRouteId, true);
kDefaultChildId, kDefaultRouteId, MSG_ROUTING_NONE, true);

// Install a prerender throttle.
PrerenderResourceThrottle throttle(&request, prerender_tracker());
Expand Down Expand Up @@ -574,7 +575,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectCancel) {
&url_request_context);
content::ResourceRequestInfo::AllocateForTesting(
&request, ResourceType::IMAGE, NULL,
kDefaultChildId, kDefaultRouteId, true);
kDefaultChildId, kDefaultRouteId, MSG_ROUTING_NONE, true);

// Install a prerender throttle.
PrerenderResourceThrottle throttle(&request, prerender_tracker());
Expand Down Expand Up @@ -614,7 +615,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectMainFrame) {
&url_request_context);
content::ResourceRequestInfo::AllocateForTesting(
&request, ResourceType::MAIN_FRAME, NULL,
kDefaultChildId, kDefaultRouteId, true);
kDefaultChildId, kDefaultRouteId, MSG_ROUTING_NONE, true);

// Install a prerender throttle.
PrerenderResourceThrottle throttle(&request, prerender_tracker());
Expand Down Expand Up @@ -653,7 +654,7 @@ TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectSyncXHR) {
&url_request_context);
content::ResourceRequestInfo::AllocateForTesting(
&request, ResourceType::XHR, NULL,
kDefaultChildId, kDefaultRouteId, false);
kDefaultChildId, kDefaultRouteId, MSG_ROUTING_NONE, false);

// Install a prerender throttle.
PrerenderResourceThrottle throttle(&request, prerender_tracker());
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/search/iframe_source_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "content/public/test/mock_resource_context.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "grit/browser_resources.h"
#include "ipc/ipc_message.h"
#include "net/base/request_priority.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ class IframeSourceTest : public testing::Test {
&resource_context_,
render_process_id,
render_view_id,
MSG_ROUTING_NONE,
false);
}
return request;
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/task_manager/guest_resource_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ void GuestResourceProvider::StartUpdating() {
while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
if (widget->IsRenderView()) {
RenderViewHost* rvh = RenderViewHost::From(widget);
if (rvh->IsSubframe())
WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
if (web_contents->IsSubframe())
Add(rvh);
}
}
Expand Down Expand Up @@ -190,7 +191,7 @@ void GuestResourceProvider::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
WebContents* web_contents = content::Source<WebContents>(source).ptr();
if (!web_contents || !web_contents->GetRenderViewHost()->IsSubframe())
if (!web_contents || !web_contents->IsSubframe())
return;

switch (type) {
Expand Down
5 changes: 2 additions & 3 deletions chrome/browser/ui/blocked_content/blocked_window_params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
Expand Down Expand Up @@ -34,8 +34,7 @@ BlockedWindowParams::BlockedWindowParams(
chrome::NavigateParams BlockedWindowParams::CreateNavigateParams(
content::WebContents* web_contents) const {
GURL popup_url(target_url_);
content::RenderViewHost::FilterURL(
web_contents->GetRenderProcessHost(), false, &popup_url);
web_contents->GetRenderProcessHost()->FilterURL(false, &popup_url);
chrome::NavigateParams nav_params(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
popup_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ namespace {
const void* kInterceptNavigationDelegateUserDataKey =
&kInterceptNavigationDelegateUserDataKey;

bool CheckIfShouldIgnoreNavigationOnUIThread(RenderViewHost* source,
bool CheckIfShouldIgnoreNavigationOnUIThread(WebContents* source,
const NavigationParams& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(source);

WebContents* web_contents = WebContents::FromRenderViewHost(source);
if (!web_contents)
return false;
InterceptNavigationDelegate* intercept_navigation_delegate =
InterceptNavigationDelegate::Get(web_contents);
InterceptNavigationDelegate::Get(source);
if (!intercept_navigation_delegate)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "components/navigation_interception/navigation_params.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_controller.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/common/referrer.h"
#include "net/http/http_response_headers.h"
Expand All @@ -20,7 +21,7 @@ using content::BrowserThread;
using content::ChildProcessSecurityPolicy;
using content::PageTransition;
using content::Referrer;
using content::RenderViewHost;
using content::RenderProcessHost;
using content::ResourceRequestInfo;

namespace navigation_interception {
Expand All @@ -29,22 +30,23 @@ namespace {

void CheckIfShouldIgnoreNavigationOnUIThread(
int render_process_id,
int render_view_id,
int render_frame_id,
const NavigationParams& navigation_params,
InterceptNavigationResourceThrottle::CheckOnUIThreadCallback
should_ignore_callback,
base::Callback<void(bool)> callback) {

bool should_ignore_navigation = false;
RenderViewHost* rvh =
RenderViewHost::FromID(render_process_id, render_view_id);

if (rvh) {
RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
if (rph) {
NavigationParams validated_params(navigation_params);
RenderViewHost::FilterURL(
rvh->GetProcess(), false, &validated_params.url());
rph->FilterURL(false, &validated_params.url());

content::RenderFrameHost* render_frame_host =
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);

should_ignore_navigation = should_ignore_callback.Run(rvh,
should_ignore_navigation = should_ignore_callback.Run(web_contents,
validated_params);
}

Expand Down Expand Up @@ -100,8 +102,8 @@ bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation(
if (!info)
return false;

int render_process_id, render_view_id;
if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id))
int render_process_id, render_frame_id;
if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
return false;

NavigationParams navigation_params(url,
Expand All @@ -118,7 +120,7 @@ bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation(
base::Bind(
&CheckIfShouldIgnoreNavigationOnUIThread,
render_process_id,
render_view_id,
render_frame_id,
navigation_params,
should_ignore_callback_,
base::Bind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class GURL;

namespace content {
class RenderViewHost;
class WebContents;
}

namespace net {
Expand All @@ -30,7 +30,7 @@ class NavigationParams;
class InterceptNavigationResourceThrottle : public content::ResourceThrottle {
public:
typedef base::Callback<bool(
content::RenderViewHost* /* source */,
content::WebContents* /* source */,
const NavigationParams& /* navigation_params */)>
CheckOnUIThreadCallback;

Expand Down
Loading

0 comments on commit 5dcaf8e

Please sign in to comment.