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

Side by Side Diff: webkit/glue/webframeloaderclient_impl.cc

Issue 149620: Use WebWidget from the WebKit API. This change also makes... (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 | « webkit/glue/webframeloaderclient_impl.h ('k') | webkit/glue/webplugin_impl.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "config.h" 5 #include "config.h"
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "webkit/glue/webview_delegate.h" 66 #include "webkit/glue/webview_delegate.h"
67 #include "webkit/glue/webview_impl.h" 67 #include "webkit/glue/webview_impl.h"
68 68
69 using namespace WebCore; 69 using namespace WebCore;
70 70
71 using base::Time; 71 using base::Time;
72 using base::TimeDelta; 72 using base::TimeDelta;
73 73
74 using WebKit::WebData; 74 using WebKit::WebData;
75 using WebKit::WebNavigationType; 75 using WebKit::WebNavigationType;
76 using WebKit::WebNavigationPolicy;
76 using WebKit::WebString; 77 using WebKit::WebString;
77 using WebKit::WebURL; 78 using WebKit::WebURL;
78 using WebKit::WebVector; 79 using WebKit::WebVector;
79 using WebKit::WrappedResourceRequest; 80 using WebKit::WrappedResourceRequest;
80 using WebKit::WrappedResourceResponse; 81 using WebKit::WrappedResourceResponse;
81 82
82 using webkit_glue::Alt404PageResourceFetcher; 83 using webkit_glue::Alt404PageResourceFetcher;
83 84
84 // Domain for internal error codes. 85 // Domain for internal error codes.
85 static const char kInternalErrorDomain[] = "webkit_glue"; 86 static const char kInternalErrorDomain[] = "webkit_glue";
86 87
87 // An internal error code. Used to note a policy change error resulting from 88 // An internal error code. Used to note a policy change error resulting from
88 // dispatchDecidePolicyForMIMEType not passing the PolicyUse option. 89 // dispatchDecidePolicyForMIMEType not passing the PolicyUse option.
89 enum { 90 enum {
90 ERR_POLICY_CHANGE = -10000, 91 ERR_POLICY_CHANGE = -10000,
91 }; 92 };
92 93
93 WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) : 94 WebFrameLoaderClient::WebFrameLoaderClient(WebFrameImpl* frame) :
94 webframe_(frame), 95 webframe_(frame),
95 postpone_loading_data_(false), 96 postpone_loading_data_(false),
96 has_representation_(false), 97 has_representation_(false),
97 sent_initial_response_to_plugin_(false), 98 sent_initial_response_to_plugin_(false),
98 next_window_open_disposition_(IGNORE_ACTION) { 99 next_navigation_policy_(WebKit::WebNavigationPolicyIgnore) {
99 } 100 }
100 101
101 WebFrameLoaderClient::~WebFrameLoaderClient() { 102 WebFrameLoaderClient::~WebFrameLoaderClient() {
102 } 103 }
103 104
104 void WebFrameLoaderClient::frameLoaderDestroyed() { 105 void WebFrameLoaderClient::frameLoaderDestroyed() {
105 // When the WebFrame was created, it had an extra reference given to it on 106 // When the WebFrame was created, it had an extra reference given to it on
106 // behalf of the Frame. Since the WebFrame owns us, this extra ref also 107 // behalf of the Frame. Since the WebFrame owns us, this extra ref also
107 // serves to keep us alive until the FrameLoader is done with us. The 108 // serves to keep us alive until the FrameLoader is done with us. The
108 // FrameLoader calls this method when it's going away. Therefore, we balance 109 // FrameLoader calls this method when it's going away. Therefore, we balance
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 // All resources have not necessarily finished loading. 804 // All resources have not necessarily finished loading.
804 } 805 }
805 806
806 Frame* WebFrameLoaderClient::dispatchCreatePage() { 807 Frame* WebFrameLoaderClient::dispatchCreatePage() {
807 struct WebCore::WindowFeatures features; 808 struct WebCore::WindowFeatures features;
808 Page* new_page = webframe_->frame()->page()->chrome()->createWindow( 809 Page* new_page = webframe_->frame()->page()->chrome()->createWindow(
809 webframe_->frame(), FrameLoadRequest(), features); 810 webframe_->frame(), FrameLoadRequest(), features);
810 811
811 // Make sure that we have a valid disposition. This should have been set in 812 // Make sure that we have a valid disposition. This should have been set in
812 // the preceeding call to dispatchDecidePolicyForNewWindowAction. 813 // the preceeding call to dispatchDecidePolicyForNewWindowAction.
813 DCHECK(next_window_open_disposition_ != IGNORE_ACTION); 814 DCHECK(next_navigation_policy_ != WebKit::WebNavigationPolicyIgnore);
814 WindowOpenDisposition disp = next_window_open_disposition_; 815 WebNavigationPolicy policy = next_navigation_policy_;
815 next_window_open_disposition_ = IGNORE_ACTION; 816 next_navigation_policy_ = WebKit::WebNavigationPolicyIgnore;
816 817
817 // createWindow can return NULL (e.g., popup blocker denies the window). 818 // createWindow can return NULL (e.g., popup blocker denies the window).
818 if (!new_page) 819 if (!new_page)
819 return NULL; 820 return NULL;
820 821
821 WebViewImpl::FromPage(new_page)->set_window_open_disposition(disp); 822 WebViewImpl::FromPage(new_page)->set_initial_navigation_policy(policy);
822 return new_page->mainFrame(); 823 return new_page->mainFrame();
823 } 824 }
824 825
825 void WebFrameLoaderClient::dispatchShow() { 826 void WebFrameLoaderClient::dispatchShow() {
826 WebViewImpl* webview = webframe_->GetWebViewImpl(); 827 WebViewImpl* webview = webframe_->GetWebViewImpl();
827 WebViewDelegate* d = webview->delegate(); 828 WebViewDelegate* d = webview->delegate();
828 if (d) 829 if (d)
829 d->Show(webview, webview->window_open_disposition()); 830 d->show(webview->initial_navigation_policy());
830 } 831 }
831 832
832 static bool TreatAsAttachment(const ResourceResponse& response) { 833 static bool TreatAsAttachment(const ResourceResponse& response) {
833 const String& content_disposition = 834 const String& content_disposition =
834 response.httpHeaderField("Content-Disposition"); 835 response.httpHeaderField("Content-Disposition");
835 if (content_disposition.isEmpty()) 836 if (content_disposition.isEmpty())
836 return false; 837 return false;
837 838
838 // Some broken sites just send 839 // Some broken sites just send
839 // Content-Disposition: ; filename="file" 840 // Content-Disposition: ; filename="file"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 // NOTE: ERR_POLICY_CHANGE will be generated when action is not PolicyUse. 890 // NOTE: ERR_POLICY_CHANGE will be generated when action is not PolicyUse.
890 (webframe_->frame()->loader()->*function)(action); 891 (webframe_->frame()->loader()->*function)(action);
891 } 892 }
892 893
893 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction( 894 void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(
894 WebCore::FramePolicyFunction function, 895 WebCore::FramePolicyFunction function,
895 const WebCore::NavigationAction& action, 896 const WebCore::NavigationAction& action,
896 const WebCore::ResourceRequest& request, 897 const WebCore::ResourceRequest& request,
897 PassRefPtr<WebCore::FormState> form_state, 898 PassRefPtr<WebCore::FormState> form_state,
898 const WebCore::String& frame_name) { 899 const WebCore::String& frame_name) {
899 WindowOpenDisposition disposition; 900 WebNavigationPolicy navigation_policy;
900 if (!ActionSpecifiesDisposition(action, &disposition)) 901 if (!ActionSpecifiesNavigationPolicy(action, &navigation_policy))
901 disposition = NEW_FOREGROUND_TAB; 902 navigation_policy = WebKit::WebNavigationPolicyNewForegroundTab;
902 903
903 PolicyAction policy_action; 904 PolicyAction policy_action;
904 if (disposition == SAVE_TO_DISK) { 905 if (navigation_policy == WebKit::WebNavigationPolicyDownload) {
905 policy_action = PolicyDownload; 906 policy_action = PolicyDownload;
906 } else { 907 } else {
907 policy_action = PolicyUse; 908 policy_action = PolicyUse;
908 909
909 // Remember the disposition for when dispatchCreatePage is called. It is 910 // Remember the disposition for when dispatchCreatePage is called. It is
910 // unfortunate that WebCore does not provide us with any context when 911 // unfortunate that WebCore does not provide us with any context when
911 // creating or showing the new window that would allow us to avoid having 912 // creating or showing the new window that would allow us to avoid having
912 // to keep this state. 913 // to keep this state.
913 next_window_open_disposition_ = disposition; 914 next_navigation_policy_ = navigation_policy;
914 } 915 }
915 (webframe_->frame()->loader()->*function)(policy_action); 916 (webframe_->frame()->loader()->*function)(policy_action);
916 } 917 }
917 918
918 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction( 919 void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(
919 WebCore::FramePolicyFunction function, 920 WebCore::FramePolicyFunction function,
920 const WebCore::NavigationAction& action, 921 const WebCore::NavigationAction& action,
921 const WebCore::ResourceRequest& request, 922 const WebCore::ResourceRequest& request,
922 PassRefPtr<WebCore::FormState> form_state) { 923 PassRefPtr<WebCore::FormState> form_state) {
923 PolicyAction policy_action = PolicyUse; 924 PolicyAction policy_action = PolicyUse;
924 925
925 WebViewImpl* wv = webframe_->GetWebViewImpl(); 926 WebViewImpl* wv = webframe_->GetWebViewImpl();
926 WebViewDelegate* d = wv->delegate(); 927 WebViewDelegate* d = wv->delegate();
927 // It is valid for this function to be invoked in code paths where the 928 // It is valid for this function to be invoked in code paths where the
928 // the webview is closed. 929 // the webview is closed.
929 // The NULL check here is to fix a crash that seems strange 930 // The NULL check here is to fix a crash that seems strange
930 // (see - https://bugs.webkit.org/show_bug.cgi?id=23554). 931 // (see - https://bugs.webkit.org/show_bug.cgi?id=23554).
931 if (d && !request.url().isNull()) { 932 if (d && !request.url().isNull()) {
932 WindowOpenDisposition disposition = CURRENT_TAB; 933 WebNavigationPolicy navigation_policy =
933 ActionSpecifiesDisposition(action, &disposition); 934 WebKit::WebNavigationPolicyCurrentTab;
935 ActionSpecifiesNavigationPolicy(action, &navigation_policy);
934 936
935 // Give the delegate a chance to change the disposition. 937 // Give the delegate a chance to change the navigation policy.
936 const WebDataSourceImpl* ds = webframe_->GetProvisionalDataSourceImpl(); 938 const WebDataSourceImpl* ds = webframe_->GetProvisionalDataSourceImpl();
937 if (ds) { 939 if (ds) {
938 GURL url = ds->request().url(); 940 GURL url = ds->request().url();
939 if (url.SchemeIs(webkit_glue::kBackForwardNavigationScheme)) { 941 if (url.SchemeIs(webkit_glue::kBackForwardNavigationScheme)) {
940 HandleBackForwardNavigation(url); 942 HandleBackForwardNavigation(url);
941 disposition = IGNORE_ACTION; 943 navigation_policy = WebKit::WebNavigationPolicyIgnore;
942 } else { 944 } else {
943 bool is_redirect = ds->HasRedirectChain(); 945 bool is_redirect = ds->HasRedirectChain();
944 946
945 WebNavigationType webnav_type = 947 WebNavigationType webnav_type =
946 WebDataSourceImpl::NavigationTypeToWebNavigationType(action.type()); 948 WebDataSourceImpl::NavigationTypeToWebNavigationType(action.type());
947 949
948 disposition = d->DispositionForNavigationAction( 950 navigation_policy = d->PolicyForNavigationAction(
949 wv, webframe_, ds->request(), webnav_type, disposition, is_redirect) ; 951 wv, webframe_, ds->request(), webnav_type, navigation_policy,
952 is_redirect);
950 } 953 }
951 } 954 }
952 955
953 if (disposition == CURRENT_TAB) { 956 if (navigation_policy == WebKit::WebNavigationPolicyCurrentTab) {
954 policy_action = PolicyUse; 957 policy_action = PolicyUse;
955 } else if (disposition == SAVE_TO_DISK) { 958 } else if (navigation_policy == WebKit::WebNavigationPolicyDownload) {
956 policy_action = PolicyDownload; 959 policy_action = PolicyDownload;
957 } else { 960 } else {
958 if (disposition != IGNORE_ACTION) { 961 if (navigation_policy != WebKit::WebNavigationPolicyIgnore) {
959 GURL referrer = webkit_glue::StringToGURL( 962 GURL referrer = webkit_glue::StringToGURL(
960 request.httpHeaderField("Referer")); 963 request.httpHeaderField("Referer"));
961 964
962 d->OpenURL(webframe_->GetWebViewImpl(), 965 d->OpenURL(webframe_->GetWebViewImpl(),
963 webkit_glue::KURLToGURL(request.url()), 966 webkit_glue::KURLToGURL(request.url()),
964 referrer, 967 referrer,
965 disposition); 968 navigation_policy);
966 } 969 }
967 policy_action = PolicyIgnore; 970 policy_action = PolicyIgnore;
968 } 971 }
969 } 972 }
970 973
971 (webframe_->frame()->loader()->*function)(policy_action); 974 (webframe_->frame()->loader()->*function)(policy_action);
972 } 975 }
973 976
974 void WebFrameLoaderClient::cancelPolicyCheck() { 977 void WebFrameLoaderClient::cancelPolicyCheck() {
975 // FIXME 978 // FIXME
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 1471
1469 return ObjectContentNone; 1472 return ObjectContentNone;
1470 } 1473 }
1471 1474
1472 String WebFrameLoaderClient::overrideMediaType() const { 1475 String WebFrameLoaderClient::overrideMediaType() const {
1473 // FIXME 1476 // FIXME
1474 String rv; 1477 String rv;
1475 return rv; 1478 return rv;
1476 } 1479 }
1477 1480
1478 bool WebFrameLoaderClient::ActionSpecifiesDisposition( 1481 bool WebFrameLoaderClient::ActionSpecifiesNavigationPolicy(
1479 const WebCore::NavigationAction& action, 1482 const WebCore::NavigationAction& action,
1480 WindowOpenDisposition* disposition) { 1483 WebNavigationPolicy* policy) {
1481 if ((action.type() != NavigationTypeLinkClicked) || 1484 if ((action.type() != NavigationTypeLinkClicked) ||
1482 !action.event()->isMouseEvent()) 1485 !action.event()->isMouseEvent())
1483 return false; 1486 return false;
1484 1487
1485 const MouseEvent* event = static_cast<const MouseEvent*>(action.event()); 1488 const MouseEvent* event = static_cast<const MouseEvent*>(action.event());
1486 #if defined(OS_WIN) || defined(OS_LINUX) 1489 #if defined(OS_WIN) || defined(OS_LINUX)
1487 const bool new_tab_modifier = (event->button() == 1) || event->ctrlKey(); 1490 const bool new_tab_modifier = (event->button() == 1) || event->ctrlKey();
1488 #elif defined(OS_MACOSX) 1491 #elif defined(OS_MACOSX)
1489 const bool new_tab_modifier = (event->button() == 1) || event->metaKey(); 1492 const bool new_tab_modifier = (event->button() == 1) || event->metaKey();
1490 #endif 1493 #endif
1491 const bool shift = event->shiftKey(); 1494 const bool shift = event->shiftKey();
1492 const bool alt = event->altKey(); 1495 const bool alt = event->altKey();
1493 if (!new_tab_modifier && !shift && !alt) 1496 if (!new_tab_modifier && !shift && !alt)
1494 return false; 1497 return false;
1495 1498
1496 DCHECK(disposition); 1499 DCHECK(policy);
1497 if (new_tab_modifier) 1500 if (new_tab_modifier) {
1498 *disposition = shift ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; 1501 if (shift) {
1499 else 1502 *policy = WebKit::WebNavigationPolicyNewForegroundTab;
1500 *disposition = shift ? NEW_WINDOW : SAVE_TO_DISK; 1503 } else {
1504 *policy = WebKit::WebNavigationPolicyNewBackgroundTab;
1505 }
1506 } else {
1507 if (shift) {
1508 *policy = WebKit::WebNavigationPolicyNewWindow;
1509 } else {
1510 *policy = WebKit::WebNavigationPolicyDownload;
1511 }
1512 }
1501 return true; 1513 return true;
1502 } 1514 }
1503 1515
1504 NavigationGesture WebFrameLoaderClient::NavigationGestureForLastLoad() { 1516 NavigationGesture WebFrameLoaderClient::NavigationGestureForLastLoad() {
1505 // TODO(timsteele): isProcessingUserGesture() returns too many false positives 1517 // TODO(timsteele): isProcessingUserGesture() returns too many false positives
1506 // (see bug 1051891) to trust it and assign NavigationGestureUser, so 1518 // (see bug 1051891) to trust it and assign NavigationGestureUser, so
1507 // for now we assign Unknown in those cases and Auto otherwise. 1519 // for now we assign Unknown in those cases and Auto otherwise.
1508 // (Issue 874811 known false negative as well). 1520 // (Issue 874811 known false negative as well).
1509 return webframe_->frame()->loader()->isProcessingUserGesture() ? 1521 return webframe_->frame()->loader()->isProcessingUserGesture() ?
1510 NavigationGestureUnknown : 1522 NavigationGestureUnknown :
1511 NavigationGestureAuto; 1523 NavigationGestureAuto;
1512 } 1524 }
1513 1525
1514 void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) { 1526 void WebFrameLoaderClient::HandleBackForwardNavigation(const GURL& url) {
1515 DCHECK(url.SchemeIs(webkit_glue::kBackForwardNavigationScheme)); 1527 DCHECK(url.SchemeIs(webkit_glue::kBackForwardNavigationScheme));
1516 1528
1517 std::string offset_str = url.ExtractFileName(); 1529 std::string offset_str = url.ExtractFileName();
1518 int offset; 1530 int offset;
1519 if (!StringToInt(offset_str, &offset)) 1531 if (!StringToInt(offset_str, &offset))
1520 return; 1532 return;
1521 1533
1522 WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate(); 1534 WebViewDelegate* d = webframe_->GetWebViewImpl()->delegate();
1523 if (d) 1535 if (d)
1524 d->NavigateBackForwardSoon(offset); 1536 d->NavigateBackForwardSoon(offset);
1525 } 1537 }
OLDNEW
« no previous file with comments | « webkit/glue/webframeloaderclient_impl.h ('k') | webkit/glue/webplugin_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698