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

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

Issue 150146: Add Reload and LoadData methods to WebFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | « chrome/renderer/navigation_state.h ('k') | webkit/api/public/WebData.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 #include "base/gfx/native_theme.h" 93 #include "base/gfx/native_theme.h"
94 #endif 94 #endif
95 95
96 using base::Time; 96 using base::Time;
97 using base::TimeDelta; 97 using base::TimeDelta;
98 using webkit_glue::AutofillForm; 98 using webkit_glue::AutofillForm;
99 using webkit_glue::PasswordForm; 99 using webkit_glue::PasswordForm;
100 using webkit_glue::PasswordFormDomManager; 100 using webkit_glue::PasswordFormDomManager;
101 using webkit_glue::SearchableFormData; 101 using webkit_glue::SearchableFormData;
102 using WebKit::WebConsoleMessage; 102 using WebKit::WebConsoleMessage;
103 using WebKit::WebData;
103 using WebKit::WebDataSource; 104 using WebKit::WebDataSource;
104 using WebKit::WebDragData; 105 using WebKit::WebDragData;
105 using WebKit::WebForm; 106 using WebKit::WebForm;
106 using WebKit::WebHistoryItem; 107 using WebKit::WebHistoryItem;
107 using WebKit::WebNavigationType; 108 using WebKit::WebNavigationType;
108 using WebKit::WebRect; 109 using WebKit::WebRect;
109 using WebKit::WebScriptSource; 110 using WebKit::WebScriptSource;
110 using WebKit::WebSize; 111 using WebKit::WebSize;
111 using WebKit::WebString; 112 using WebKit::WebString;
112 using WebKit::WebURL; 113 using WebKit::WebURL;
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 // initiated any load resulting from JS execution. 646 // initiated any load resulting from JS execution.
646 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { 647 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
647 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( 648 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
648 params.page_id, params.transition, params.request_time)); 649 params.page_id, params.transition, params.request_time));
649 } 650 }
650 651
651 // If we are reloading, then WebKit will use the history state of the current 652 // If we are reloading, then WebKit will use the history state of the current
652 // page, so we should just ignore any given history state. Otherwise, if we 653 // page, so we should just ignore any given history state. Otherwise, if we
653 // have history state, then we need to navigate to it, which corresponds to a 654 // have history state, then we need to navigate to it, which corresponds to a
654 // back/forward navigation event. 655 // back/forward navigation event.
655 if (!is_reload && !params.state.empty()) { 656 if (is_reload) {
657 main_frame->Reload();
658 } else if (!params.state.empty()) {
656 // We must know the page ID of the page we are navigating back to. 659 // We must know the page ID of the page we are navigating back to.
657 DCHECK_NE(params.page_id, -1); 660 DCHECK_NE(params.page_id, -1);
658 main_frame->LoadHistoryItem( 661 main_frame->LoadHistoryItem(
659 webkit_glue::HistoryItemFromString(params.state)); 662 webkit_glue::HistoryItemFromString(params.state));
660 } else { 663 } else {
661 // Navigate to the given URL. 664 // Navigate to the given URL.
662 WebURLRequest request(params.url); 665 WebURLRequest request(params.url);
663 666
664 // TODO(darin): WebFrame should just have a Reload method. 667 // A session history navigation should have been accompanied by state.
668 DCHECK_EQ(params.page_id, -1);
665 669
666 WebURLRequest::CachePolicy cache_policy; 670 if (main_frame->GetInViewSourceMode())
667 if (is_reload) { 671 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
668 cache_policy = WebURLRequest::ReloadIgnoringCacheData;
669 } else {
670 // A session history navigation should have been accompanied by state.
671 DCHECK_EQ(params.page_id, -1);
672 if (main_frame->GetInViewSourceMode()) {
673 cache_policy = WebURLRequest::ReturnCacheDataElseLoad;
674 } else {
675 cache_policy = WebURLRequest::UseProtocolCachePolicy;
676 }
677 }
678 request.setCachePolicy(cache_policy);
679 672
680 if (params.referrer.is_valid()) { 673 if (params.referrer.is_valid()) {
681 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), 674 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
682 WebString::fromUTF8(params.referrer.spec())); 675 WebString::fromUTF8(params.referrer.spec()));
683 } 676 }
684 677
685 main_frame->LoadRequest(request); 678 main_frame->LoadRequest(request);
686 } 679 }
687 680
688 // In case LoadRequest failed before DidCreateDataSource was called. 681 // In case LoadRequest failed before DidCreateDataSource was called.
689 pending_navigation_state_.reset(); 682 pending_navigation_state_.reset();
690 } 683 }
691 684
692 // Stop loading the current page 685 // Stop loading the current page
693 void RenderView::OnStop() { 686 void RenderView::OnStop() {
694 if (webview()) 687 if (webview())
695 webview()->StopLoading(); 688 webview()->StopLoading();
696 } 689 }
697 690
698 void RenderView::OnLoadAlternateHTMLText(const std::string& html_contents, 691 void RenderView::OnLoadAlternateHTMLText(const std::string& html,
699 bool new_navigation, 692 bool new_navigation,
700 const GURL& display_url, 693 const GURL& display_url,
701 const std::string& security_info) { 694 const std::string& security_info) {
702 if (!webview()) 695 if (!webview())
703 return; 696 return;
704 697
705 WebURLRequest request; 698 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
706 request.initialize(); 699 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
707 request.setURL(GURL(kUnreachableWebDataURL)); 700 pending_navigation_state_->set_security_info(security_info);
708 request.setSecurityInfo(security_info);
709 701
710 webview()->GetMainFrame()->LoadAlternateHTMLString(request, 702 webview()->GetMainFrame()->LoadHTMLString(html,
711 html_contents, 703 GURL(kUnreachableWebDataURL),
712 display_url, 704 display_url,
713 !new_navigation); 705 !new_navigation);
706
707 pending_navigation_state_.reset();
714 } 708 }
715 709
716 void RenderView::OnCopyImageAt(int x, int y) { 710 void RenderView::OnCopyImageAt(int x, int y) {
717 webview()->CopyImageAt(x, y); 711 webview()->CopyImageAt(x, y);
718 } 712 }
719 713
720 void RenderView::OnExecuteEditCommand(const std::string& name, 714 void RenderView::OnExecuteEditCommand(const std::string& name,
721 const std::string& value) { 715 const std::string& value) {
722 if (!webview() || !webview()->GetFocusedFrame()) 716 if (!webview() || !webview()->GetFocusedFrame())
723 return; 717 return;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 const WebURLResponse& response = ds->response(); 839 const WebURLResponse& response = ds->response();
846 840
847 NavigationState* navigation_state = NavigationState::FromDataSource(ds); 841 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
848 DCHECK(navigation_state); 842 DCHECK(navigation_state);
849 843
850 ViewHostMsg_FrameNavigate_Params params; 844 ViewHostMsg_FrameNavigate_Params params;
851 params.http_status_code = response.httpStatusCode(); 845 params.http_status_code = response.httpStatusCode();
852 params.is_post = false; 846 params.is_post = false;
853 params.page_id = page_id_; 847 params.page_id = page_id_;
854 params.is_content_filtered = response.isContentFiltered(); 848 params.is_content_filtered = response.isContentFiltered();
855 if (!request.securityInfo().isEmpty()) { 849 if (!navigation_state->security_info().empty()) {
856 // SSL state specified in the request takes precedence over the one in the 850 // SSL state specified in the request takes precedence over the one in the
857 // response. 851 // response.
858 // So far this is only intended for error pages that are not expected to be 852 // So far this is only intended for error pages that are not expected to be
859 // over ssl, so we should not get any clash. 853 // over ssl, so we should not get any clash.
860 DCHECK(response.securityInfo().isEmpty()); 854 DCHECK(response.securityInfo().isEmpty());
861 params.security_info = request.securityInfo(); 855 params.security_info = navigation_state->security_info();
862 } else { 856 } else {
863 params.security_info = response.securityInfo(); 857 params.security_info = response.securityInfo();
864 } 858 }
865 859
866 // Set the URL to be displayed in the browser UI to the user. 860 // Set the URL to be displayed in the browser UI to the user.
867 if (ds->hasUnreachableURL()) { 861 if (ds->hasUnreachableURL()) {
868 params.url = ds->unreachableURL(); 862 params.url = ds->unreachableURL();
869 } else { 863 } else {
870 params.url = request.url(); 864 params.url = request.url();
871 } 865 }
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 } 1238 }
1245 error_strings.SetString(L"textdirection", 1239 error_strings.SetString(L"textdirection",
1246 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? 1240 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1247 L"rtl" : L"ltr"); 1241 L"rtl" : L"ltr");
1248 1242
1249 alt_html = GetAltHTMLForTemplate(error_strings, resource_id); 1243 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1250 } else { 1244 } else {
1251 alt_html = html; 1245 alt_html = html;
1252 } 1246 }
1253 1247
1254 // Use a data: URL as the site URL to prevent against XSS attacks. 1248 frame->LoadHTMLString(alt_html,
1255 WebURLRequest request(failed_request); 1249 GURL(kUnreachableWebDataURL),
1256 request.setURL(GURL(kUnreachableWebDataURL)); 1250 failed_url,
1257 1251 replace);
1258 frame->LoadAlternateHTMLString(request, alt_html, failed_url, replace);
1259 } 1252 }
1260 1253
1261 void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame, 1254 void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame,
1262 bool is_new_navigation) { 1255 bool is_new_navigation) {
1263 NavigationState* navigation_state = 1256 NavigationState* navigation_state =
1264 NavigationState::FromDataSource(frame->GetDataSource()); 1257 NavigationState::FromDataSource(frame->GetDataSource());
1265 1258
1266 navigation_state->set_commit_load_time(Time::Now()); 1259 navigation_state->set_commit_load_time(Time::Now());
1267 if (is_new_navigation) { 1260 if (is_new_navigation) {
1268 // When we perform a new navigation, we need to update the previous session 1261 // When we perform a new navigation, we need to update the previous session
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms)); 2970 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
2978 } 2971 }
2979 2972
2980 void RenderView::Print(WebFrame* frame, bool script_initiated) { 2973 void RenderView::Print(WebFrame* frame, bool script_initiated) {
2981 DCHECK(frame); 2974 DCHECK(frame);
2982 if (print_helper_.get() == NULL) { 2975 if (print_helper_.get() == NULL) {
2983 print_helper_.reset(new PrintWebViewHelper(this)); 2976 print_helper_.reset(new PrintWebViewHelper(this));
2984 } 2977 }
2985 print_helper_->Print(frame, script_initiated); 2978 print_helper_->Print(frame, script_initiated);
2986 } 2979 }
OLDNEW
« no previous file with comments | « chrome/renderer/navigation_state.h ('k') | webkit/api/public/WebData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698