diff options
-rw-r--r-- | chrome/browser/prerender/prerender_contents.cc | 7 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_manager.cc | 3 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 3 | ||||
-rw-r--r-- | chrome/common/render_messages_params.cc | 4 | ||||
-rw-r--r-- | chrome/common/render_messages_params.h | 3 | ||||
-rw-r--r-- | chrome/renderer/blocked_plugin.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/blocked_plugin.h | 6 | ||||
-rw-r--r-- | chrome/renderer/navigation_state.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/navigation_state.h | 11 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 50 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 4 |
11 files changed, 89 insertions, 12 deletions
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc index c5002f7..d3bac70 100644 --- a/chrome/browser/prerender/prerender_contents.cc +++ b/chrome/browser/prerender/prerender_contents.cc @@ -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() { diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 02a2ac5..1b75670 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -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(); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index f2c588c..867523a 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -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 */) diff --git a/chrome/common/render_messages_params.cc b/chrome/common/render_messages_params.cc index a05266c..91d7ba7 100644 --- a/chrome/common/render_messages_params.cc +++ b/chrome/common/render_messages_params.cc @@ -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; diff --git a/chrome/common/render_messages_params.h b/chrome/common/render_messages_params.h index 09d18e0..20d8470 100644 --- a/chrome/common/render_messages_params.h +++ b/chrome/common/render_messages_params.h @@ -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 }; diff --git a/chrome/renderer/blocked_plugin.cc b/chrome/renderer/blocked_plugin.cc index 7ec6eed..f85e2ed 100644 --- a/chrome/renderer/blocked_plugin.cc +++ b/chrome/renderer/blocked_plugin.cc @@ -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; diff --git a/chrome/renderer/blocked_plugin.h b/chrome/renderer/blocked_plugin.h index 39cfc54..40916e9 100644 --- a/chrome/renderer/blocked_plugin.h +++ b/chrome/renderer/blocked_plugin.h @@ -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_ diff --git a/chrome/renderer/navigation_state.cc b/chrome/renderer/navigation_state.cc index 47759f8..dff7ee4 100644 --- a/chrome/renderer/navigation_state.cc +++ b/chrome/renderer/navigation_state.cc @@ -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), diff --git a/chrome/renderer/navigation_state.h b/chrome/renderer/navigation_state.h index 6a4cdb5..cebd5a6 100644 --- a/chrome/renderer/navigation_state.h +++ b/chrome/renderer/navigation_state.h @@ -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_; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index e903c88..6c17b6d 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -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. diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 1b74d68..80f1bc49 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -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 |