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

Side by Side Diff: chrome/renderer/render_view.cc

Issue 6247013: Don't load plugins on prerendered pages until the pages are displayed.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 OnDragSourceEndedOrMoved) 1018 OnDragSourceEndedOrMoved)
1019 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, 1019 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1020 OnDragSourceSystemDragEnded) 1020 OnDragSourceSystemDragEnded)
1021 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) 1021 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
1022 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView, 1022 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1023 OnScrollFocusedEditableNodeIntoView) 1023 OnScrollFocusedEditableNodeIntoView)
1024 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) 1024 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1025 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) 1025 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1026 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) 1026 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1027 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) 1027 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
1028 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1029 OnDisplayPrerenderedPage)
1028 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) 1030 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1029 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) 1031 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
1030 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, 1032 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1031 OnGetAllSavableResourceLinksForCurrentPage) 1033 OnGetAllSavableResourceLinksForCurrentPage)
1032 IPC_MESSAGE_HANDLER( 1034 IPC_MESSAGE_HANDLER(
1033 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, 1035 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1034 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) 1036 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
1035 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) 1037 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
1036 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) 1038 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
1037 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) 1039 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 1448
1447 if (!params.extra_headers.empty()) { 1449 if (!params.extra_headers.empty()) {
1448 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), 1450 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1449 params.extra_headers.end(), "\n"); 1451 params.extra_headers.end(), "\n");
1450 i.GetNext(); ) { 1452 i.GetNext(); ) {
1451 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), 1453 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1452 WebString::fromUTF8(i.values())); 1454 WebString::fromUTF8(i.values()));
1453 } 1455 }
1454 } 1456 }
1455 1457
1456 if (navigation_state) 1458 if (navigation_state) {
1457 navigation_state->set_load_type(NavigationState::NORMAL_LOAD); 1459 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1460 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1461 } else {
1462 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
1463 navigation_state->set_is_prerendering(true);
1464 }
1465 }
1458 main_frame->loadRequest(request); 1466 main_frame->loadRequest(request);
1459 } 1467 }
1460 1468
1461 // In case LoadRequest failed before DidCreateDataSource was called. 1469 // In case LoadRequest failed before DidCreateDataSource was called.
1462 pending_navigation_state_.reset(); 1470 pending_navigation_state_.reset();
1463 } 1471 }
1464 1472
1465 // Stop loading the current page 1473 // Stop loading the current page
1466 void RenderView::OnStop() { 1474 void RenderView::OnStop() {
1467 if (webview()) 1475 if (webview())
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 2710
2703 if (group->IsVulnerable() && 2711 if (group->IsVulnerable() &&
2704 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) { 2712 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
2705 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_, 2713 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2706 group->GetGroupName(), 2714 group->GetGroupName(),
2707 GURL(group->GetUpdateURL()))); 2715 GURL(group->GetUpdateURL())));
2708 return CreatePluginPlaceholder(frame, 2716 return CreatePluginPlaceholder(frame,
2709 params, 2717 params,
2710 *group, 2718 *group,
2711 IDR_BLOCKED_PLUGIN_HTML, 2719 IDR_BLOCKED_PLUGIN_HTML,
2712 IDS_PLUGIN_OUTDATED); 2720 IDS_PLUGIN_OUTDATED,
2721 false);
2713 } 2722 }
2714 2723
2715 if (!info.enabled) 2724 if (!info.enabled)
2716 return NULL; 2725 return NULL;
2717 2726
2718 ContentSetting host_setting = 2727 ContentSetting host_setting =
2719 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS]; 2728 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
2720 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName || 2729 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
2721 plugin_setting == CONTENT_SETTING_ALLOW || 2730 plugin_setting == CONTENT_SETTING_ALLOW ||
2722 host_setting == CONTENT_SETTING_ALLOW) { 2731 host_setting == CONTENT_SETTING_ALLOW) {
2732 // Delay loading plugins if prerendering.
2733 WebDataSource* ds = frame->dataSource();
2734 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2735 if (navigation_state->is_prerendering()) {
2736 return CreatePluginPlaceholder(frame,
2737 params,
2738 *group,
2739 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2740 IDS_PLUGIN_LOAD,
2741 true);
2742 }
2743
2723 scoped_refptr<webkit::ppapi::PluginModule> pepper_module( 2744 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
2724 pepper_delegate_.CreatePepperPlugin(info.path)); 2745 pepper_delegate_.CreatePepperPlugin(info.path));
2725 if (pepper_module) 2746 if (pepper_module)
2726 return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); 2747 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
2727 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type); 2748 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
2728 } 2749 }
2729 std::string resource; 2750 std::string resource;
2730 if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) 2751 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2731 resource = group->identifier(); 2752 resource = group->identifier();
2732 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); 2753 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
2733 if (plugin_setting == CONTENT_SETTING_ASK) { 2754 if (plugin_setting == CONTENT_SETTING_ASK) {
2734 return CreatePluginPlaceholder(frame, 2755 return CreatePluginPlaceholder(frame,
2735 params, 2756 params,
2736 *group, 2757 *group,
2737 IDR_CLICK_TO_PLAY_PLUGIN_HTML, 2758 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2738 IDS_PLUGIN_LOAD); 2759 IDS_PLUGIN_LOAD,
2760 false);
2739 } else { 2761 } else {
2740 return CreatePluginPlaceholder(frame, 2762 return CreatePluginPlaceholder(frame,
2741 params, 2763 params,
2742 *group, 2764 *group,
2743 IDR_BLOCKED_PLUGIN_HTML, 2765 IDR_BLOCKED_PLUGIN_HTML,
2744 IDS_PLUGIN_BLOCKED); 2766 IDS_PLUGIN_BLOCKED,
2767 false);
2745 } 2768 }
2746 } 2769 }
2747 2770
2748 WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { 2771 WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2749 WebApplicationCacheHostImpl* appcache_host = 2772 WebApplicationCacheHostImpl* appcache_host =
2750 WebApplicationCacheHostImpl::FromFrame(frame); 2773 WebApplicationCacheHostImpl::FromFrame(frame);
2751 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; 2774 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2752 return new WebWorkerProxy(client, RenderThread::current(), routing_id_, 2775 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2753 appcache_host_id); 2776 appcache_host_id);
2754 } 2777 }
(...skipping 1614 matching lines...) Expand 10 before | Expand all | Expand 10 after
4369 const std::string& mime_type) { 4392 const std::string& mime_type) {
4370 return new webkit::npapi::WebPluginImpl( 4393 return new webkit::npapi::WebPluginImpl(
4371 frame, params, path, mime_type, AsWeakPtr()); 4394 frame, params, path, mime_type, AsWeakPtr());
4372 } 4395 }
4373 4396
4374 WebPlugin* RenderView::CreatePluginPlaceholder( 4397 WebPlugin* RenderView::CreatePluginPlaceholder(
4375 WebFrame* frame, 4398 WebFrame* frame,
4376 const WebPluginParams& params, 4399 const WebPluginParams& params,
4377 const webkit::npapi::PluginGroup& group, 4400 const webkit::npapi::PluginGroup& group,
4378 int resource_id, 4401 int resource_id,
4379 int message_id) { 4402 int message_id,
4403 bool is_blocked_for_prerendering) {
4380 // |blocked_plugin| will delete itself when the WebViewPlugin 4404 // |blocked_plugin| will delete itself when the WebViewPlugin
4381 // is destroyed. 4405 // is destroyed.
4382 BlockedPlugin* blocked_plugin = 4406 BlockedPlugin* blocked_plugin =
4383 new BlockedPlugin(this, 4407 new BlockedPlugin(this,
4384 frame, 4408 frame,
4385 group, 4409 group,
4386 params, 4410 params,
4387 webkit_preferences_, 4411 webkit_preferences_,
4388 resource_id, 4412 resource_id,
4389 l10n_util::GetStringFUTF16(message_id, 4413 l10n_util::GetStringFUTF16(message_id,
4390 group.GetGroupName())); 4414 group.GetGroupName()),
4415 is_blocked_for_prerendering);
4391 return blocked_plugin->plugin(); 4416 return blocked_plugin->plugin();
4392 } 4417 }
4393 4418
4394 void RenderView::OnZoom(PageZoom::Function function) { 4419 void RenderView::OnZoom(PageZoom::Function function) {
4395 if (!webview()) // Not sure if this can happen, but no harm in being safe. 4420 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4396 return; 4421 return;
4397 4422
4398 webview()->hidePopups(); 4423 webview()->hidePopups();
4399 4424
4400 double old_zoom_level = webview()->zoomLevel(); 4425 double old_zoom_level = webview()->zoomLevel();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
4672 void RenderView::OnRevertTranslation(int page_id) { 4697 void RenderView::OnRevertTranslation(int page_id) {
4673 translate_helper_.RevertTranslation(page_id); 4698 translate_helper_.RevertTranslation(page_id);
4674 } 4699 }
4675 4700
4676 void RenderView::OnInstallMissingPlugin() { 4701 void RenderView::OnInstallMissingPlugin() {
4677 // This could happen when the first default plugin is deleted. 4702 // This could happen when the first default plugin is deleted.
4678 if (first_default_plugin_) 4703 if (first_default_plugin_)
4679 first_default_plugin_->InstallMissingPlugin(); 4704 first_default_plugin_->InstallMissingPlugin();
4680 } 4705 }
4681 4706
4707 void RenderView::OnDisplayPrerenderedPage() {
4708 NavigationState* navigation_state = pending_navigation_state_.get();
4709 if (!navigation_state) {
4710 WebDataSource* ds = webview()->mainFrame()->dataSource();
4711 navigation_state = NavigationState::FromDataSource(ds);
4712 }
4713
4714 DCHECK(navigation_state->is_prerendering());
4715 navigation_state->set_is_prerendering(false);
4716 }
4717
4682 void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { 4718 void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
4683 // This could happen if we navigated to a different page before the user 4719 // This could happen if we navigated to a different page before the user
4684 // closed the chooser. 4720 // closed the chooser.
4685 if (file_chooser_completions_.empty()) 4721 if (file_chooser_completions_.empty())
4686 return; 4722 return;
4687 4723
4688 WebVector<WebString> ws_file_names(paths.size()); 4724 WebVector<WebString> ws_file_names(paths.size());
4689 for (size_t i = 0; i < paths.size(); ++i) 4725 for (size_t i = 0; i < paths.size(); ++i)
4690 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); 4726 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4691 4727
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
5686 if (cmd == kJavaScriptStressTestSetStressRunType) { 5722 if (cmd == kJavaScriptStressTestSetStressRunType) {
5687 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); 5723 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5688 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { 5724 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5689 v8::Testing::PrepareStressRun(param); 5725 v8::Testing::PrepareStressRun(param);
5690 } 5726 }
5691 } 5727 }
5692 5728
5693 void RenderView::OnContextMenuClosed() { 5729 void RenderView::OnContextMenuClosed() {
5694 context_menu_node_.reset(); 5730 context_menu_node_.reset();
5695 } 5731 }
OLDNEW
« chrome/renderer/blocked_plugin.h ('K') | « chrome/renderer/render_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698