Commit 90dba076 authored by mmenke@chromium.org's avatar mmenke@chromium.org

Don't load plugins on prerendered pages until the pages are displayed.

BUG=61745
TEST=in progress

Review URL: http://codereview.chromium.org/6247013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71992 0039d316-1c4b-4281-b951-d872f2087c98
parent 92e44ddd
......@@ -56,7 +56,12 @@ void PrerenderContents::StartPrerendering() {
registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
Source<Profile>(profile_));
render_view_host_->CreateRenderView(string16());
render_view_host_->NavigateToURL(prerender_url_);
ViewMsg_Navigate_Params params;
params.url = prerender_url_;
params.transition = PageTransition::LINK;
params.navigation_type = ViewMsg_Navigate_Params::PRERENDER;
render_view_host_->Navigate(params);
}
PrerenderContents::~PrerenderContents() {
......
......@@ -8,8 +8,10 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/prerender/prerender_contents.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/render_view_host_manager.h"
#include "chrome/common/render_messages.h"
struct PrerenderManager::PrerenderContentsData {
PrerenderContents* contents_;
......@@ -95,6 +97,7 @@ bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tc, const GURL& url) {
RenderViewHost* rvh = pc->render_view_host();
pc->set_render_view_host(NULL);
rvh->Send(new ViewMsg_DisplayPrerenderedPage(rvh->routing_id()));
tc->SwapInRenderViewHost(rvh);
ViewHostMsg_FrameNavigate_Params* p = pc->navigate_params();
......
......@@ -566,6 +566,9 @@ IPC_MESSAGE_CONTROL1(ViewMsg_PurgePluginListCache,
// Tells the render view to load all blocked plugins.
IPC_MESSAGE_ROUTED0(ViewMsg_LoadBlockedPlugins)
// Tells the render view a prerendered page is about to be displayed.
IPC_MESSAGE_ROUTED0(ViewMsg_DisplayPrerenderedPage)
IPC_MESSAGE_ROUTED1(ViewMsg_RunFileChooserResponse,
std::vector<FilePath> /* selected files */)
......
......@@ -316,6 +316,10 @@ struct ParamTraits<ViewMsg_Navigate_Params::NavigationType> {
event = "NavigationType_RESTORE";
break;
case ViewMsg_Navigate_Params::PRERENDER:
event = "NavigationType_PRERENDER";
break;
case ViewMsg_Navigate_Params::NORMAL:
event = "NavigationType_NORMA";
break;
......
......@@ -62,6 +62,9 @@ struct ViewMsg_Navigate_Params {
// the page's cache policy is ignored and we load from the cache.
RESTORE,
// Speculatively prerendering the page.
PRERENDER,
// Navigation type not categorized by the other types.
NORMAL
};
......
......@@ -53,10 +53,12 @@ BlockedPlugin::BlockedPlugin(RenderView* render_view,
const WebPluginParams& params,
const WebPreferences& preferences,
int template_id,
const string16& message)
const string16& message,
bool is_blocked_for_prerendering)
: RenderViewObserver(render_view),
frame_(frame),
plugin_params_(params) {
plugin_params_(params),
is_blocked_for_prerendering_(is_blocked_for_prerendering) {
const base::StringPiece template_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
......@@ -132,6 +134,9 @@ bool BlockedPlugin::OnMessageReceived(const IPC::Message& message) {
&message, this, this, &BlockedPlugin::OnMenuItemSelected);
} else if (message.type() == ViewMsg_LoadBlockedPlugins::ID) {
LoadPlugin();
} else if (message.type() == ViewMsg_DisplayPrerenderedPage::ID) {
if (is_blocked_for_prerendering_)
LoadPlugin();
}
return false;
......
......@@ -29,7 +29,8 @@ class BlockedPlugin : public RenderViewObserver,
const WebKit::WebPluginParams& params,
const WebPreferences& settings,
int template_id,
const string16& message);
const string16& message,
bool is_blocked_for_prerendering);
webkit::npapi::WebViewPlugin* plugin() { return plugin_; }
......@@ -66,6 +67,9 @@ class BlockedPlugin : public RenderViewObserver,
webkit::npapi::WebViewPlugin* plugin_;
// The name of the plugin that was blocked.
string16 name_;
// True iff the plugin was blocked because the page was being prerendered.
// Plugin will automatically be loaded when the page is displayed.
bool is_blocked_for_prerendering_;
};
#endif // CHROME_RENDERER_BLOCKED_PLUGIN_H_
......@@ -44,6 +44,7 @@ NavigationState::NavigationState(PageTransition::Type transition_type,
pending_page_id_(pending_page_id),
pending_history_list_offset_(pending_history_list_offset),
postpone_loading_data_(false),
is_prerendering_(false),
cache_policy_override_set_(false),
cache_policy_override_(WebKit::WebURLRequest::UseProtocolCachePolicy),
user_script_idle_scheduler_(NULL),
......
......@@ -32,6 +32,8 @@ class NavigationState : public WebKit::WebDataSource::ExtraData {
RELOAD, // User pressed reload.
HISTORY_LOAD, // Back or forward.
NORMAL_LOAD, // User entered URL, or omnibox search.
PRERENDER_LOAD, // Navigation started as the speculatively
// prendering of a linked page.
LINK_LOAD, // (deprecated) Included next 4 categories.
LINK_LOAD_NORMAL, // Commonly following of link.
LINK_LOAD_RELOAD, // JS/link directed reload.
......@@ -211,6 +213,11 @@ class NavigationState : public WebKit::WebDataSource::ExtraData {
postponed_data_.append(data, data_len);
}
bool is_prerendering() const { return is_prerendering_; }
void set_is_prerendering(bool is_prerendering) {
is_prerendering_ = is_prerendering;
}
int http_status_code() const { return http_status_code_; }
void set_http_status_code(int http_status_code) {
http_status_code_ = http_status_code;
......@@ -302,6 +309,10 @@ class NavigationState : public WebKit::WebDataSource::ExtraData {
bool postpone_loading_data_;
std::string postponed_data_;
// True if page is being prerendered. False once prerendered page is
// displayed.
bool is_prerendering_;
bool cache_policy_override_set_;
WebKit::WebURLRequest::CachePolicy cache_policy_override_;
......
......@@ -1025,6 +1025,8 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
OnDisplayPrerenderedPage)
IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
......@@ -1453,8 +1455,14 @@ void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
}
}
if (navigation_state)
navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
if (navigation_state) {
if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
} else {
navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
navigation_state->set_is_prerendering(true);
}
}
main_frame->loadRequest(request);
}
......@@ -2709,7 +2717,8 @@ WebPlugin* RenderView::createPlugin(WebFrame* frame,
params,
*group,
IDR_BLOCKED_PLUGIN_HTML,
IDS_PLUGIN_OUTDATED);
IDS_PLUGIN_OUTDATED,
false);
}
if (!info.enabled)
......@@ -2720,6 +2729,18 @@ WebPlugin* RenderView::createPlugin(WebFrame* frame,
if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
plugin_setting == CONTENT_SETTING_ALLOW ||
host_setting == CONTENT_SETTING_ALLOW) {
// Delay loading plugins if prerendering.
WebDataSource* ds = frame->dataSource();
NavigationState* navigation_state = NavigationState::FromDataSource(ds);
if (navigation_state->is_prerendering()) {
return CreatePluginPlaceholder(frame,
params,
*group,
IDR_CLICK_TO_PLAY_PLUGIN_HTML,
IDS_PLUGIN_LOAD,
true);
}
scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
pepper_delegate_.CreatePepperPlugin(info.path));
if (pepper_module)
......@@ -2735,13 +2756,15 @@ WebPlugin* RenderView::createPlugin(WebFrame* frame,
params,
*group,
IDR_CLICK_TO_PLAY_PLUGIN_HTML,
IDS_PLUGIN_LOAD);
IDS_PLUGIN_LOAD,
false);
} else {
return CreatePluginPlaceholder(frame,
params,
*group,
IDR_BLOCKED_PLUGIN_HTML,
IDS_PLUGIN_BLOCKED);
IDS_PLUGIN_BLOCKED,
false);
}
}
......@@ -4383,7 +4406,8 @@ WebPlugin* RenderView::CreatePluginPlaceholder(
const WebPluginParams& params,
const webkit::npapi::PluginGroup& group,
int resource_id,
int message_id) {
int message_id,
bool is_blocked_for_prerendering) {
// |blocked_plugin| will delete itself when the WebViewPlugin
// is destroyed.
BlockedPlugin* blocked_plugin =
......@@ -4394,7 +4418,8 @@ WebPlugin* RenderView::CreatePluginPlaceholder(
webkit_preferences_,
resource_id,
l10n_util::GetStringFUTF16(message_id,
group.GetGroupName()));
group.GetGroupName()),
is_blocked_for_prerendering);
return blocked_plugin->plugin();
}
......@@ -4686,6 +4711,17 @@ void RenderView::OnInstallMissingPlugin() {
first_default_plugin_->InstallMissingPlugin();
}
void RenderView::OnDisplayPrerenderedPage() {
NavigationState* navigation_state = pending_navigation_state_.get();
if (!navigation_state) {
WebDataSource* ds = webview()->mainFrame()->dataSource();
navigation_state = NavigationState::FromDataSource(ds);
}
DCHECK(navigation_state->is_prerendering());
navigation_state->set_is_prerendering(false);
}
void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
// This could happen if we navigated to a different page before the user
// closed the chooser.
......
......@@ -889,6 +889,7 @@ class RenderView : public RenderWidget,
const std::string& origin,
const std::string& target);
void OnInstallMissingPlugin();
void OnDisplayPrerenderedPage();
void OnMediaPlayerActionAt(const gfx::Point& location,
const WebKit::WebMediaPlayerAction& action);
void OnMoveOrResizeStarted();
......@@ -1000,7 +1001,8 @@ class RenderView : public RenderWidget,
const WebKit::WebPluginParams& params,
const webkit::npapi::PluginGroup& group,
int resource_id,
int message_id);
int message_id,
bool is_blocked_for_prerendering);
// Sends an IPC notification that the specified content type was blocked.
// If the content type requires it, |resource_identifier| names the specific
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment