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

Side by Side Diff: webkit/tools/test_shell/test_webview_delegate.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
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 // This file contains the implementation of TestWebViewDelegate, which serves 5 // This file contains the implementation of TestWebViewDelegate, which serves
6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to 6 // as the WebViewDelegate for the TestShellWebHost. The host is expected to
7 // have initialized a MessageLoop before these methods are called. 7 // have initialized a MessageLoop before these methods are called.
8 8
9 #include "config.h" 9 #include "config.h"
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // TODO(port): make these files work everywhere. 49 // TODO(port): make these files work everywhere.
50 #include "webkit/tools/test_shell/drag_delegate.h" 50 #include "webkit/tools/test_shell/drag_delegate.h"
51 #include "webkit/tools/test_shell/drop_delegate.h" 51 #include "webkit/tools/test_shell/drop_delegate.h"
52 #endif 52 #endif
53 53
54 using WebKit::WebData; 54 using WebKit::WebData;
55 using WebKit::WebDataSource; 55 using WebKit::WebDataSource;
56 using WebKit::WebDragData; 56 using WebKit::WebDragData;
57 using WebKit::WebHistoryItem; 57 using WebKit::WebHistoryItem;
58 using WebKit::WebNavigationType; 58 using WebKit::WebNavigationType;
59 using WebKit::WebNavigationPolicy;
59 using WebKit::WebRect; 60 using WebKit::WebRect;
60 using WebKit::WebScreenInfo; 61 using WebKit::WebScreenInfo;
61 using WebKit::WebSize; 62 using WebKit::WebSize;
62 using WebKit::WebString; 63 using WebKit::WebString;
63 using WebKit::WebURL; 64 using WebKit::WebURL;
64 using WebKit::WebURLError; 65 using WebKit::WebURLError;
65 using WebKit::WebURLRequest; 66 using WebKit::WebURLRequest;
67 using WebKit::WebWidget;
66 using WebKit::WebWorker; 68 using WebKit::WebWorker;
67 using WebKit::WebWorkerClient; 69 using WebKit::WebWorkerClient;
68 70
69 namespace { 71 namespace {
70 72
71 // WebNavigationType debugging strings taken from PolicyDelegate.mm. 73 // WebNavigationType debugging strings taken from PolicyDelegate.mm.
72 const char* kLinkClickedString = "link clicked"; 74 const char* kLinkClickedString = "link clicked";
73 const char* kFormSubmittedString = "form submitted"; 75 const char* kFormSubmittedString = "form submitted";
74 const char* kBackForwardString = "back/forward"; 76 const char* kBackForwardString = "back/forward";
75 const char* kReloadString = "reload"; 77 const char* kReloadString = "reload";
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) { 156 WebWorker* TestWebViewDelegate::CreateWebWorker(WebWorkerClient* client) {
155 #if ENABLE(WORKERS) 157 #if ENABLE(WORKERS)
156 return TestWebWorkerHelper::CreateWebWorker(client); 158 return TestWebWorkerHelper::CreateWebWorker(client);
157 #else 159 #else
158 return NULL; 160 return NULL;
159 #endif 161 #endif
160 } 162 }
161 163
162 void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url, 164 void TestWebViewDelegate::OpenURL(WebView* webview, const GURL& url,
163 const GURL& referrer, 165 const GURL& referrer,
164 WindowOpenDisposition disposition) { 166 WebNavigationPolicy policy) {
165 DCHECK_NE(disposition, CURRENT_TAB); // No code for this 167 DCHECK_NE(policy, WebKit::WebNavigationPolicyCurrentTab);
166 if (disposition == SUPPRESS_OPEN)
167 return;
168 TestShell* shell = NULL; 168 TestShell* shell = NULL;
169 if (TestShell::CreateNewWindow(UTF8ToWide(url.spec()), &shell)) 169 if (TestShell::CreateNewWindow(UTF8ToWide(url.spec()), &shell))
170 shell->Show(shell->webView(), disposition); 170 shell->Show(policy);
171 } 171 }
172 172
173 void TestWebViewDelegate::DidStartLoading(WebView* webview) { 173 void TestWebViewDelegate::DidStartLoading(WebView* webview) {
174 // Ignored 174 // Ignored
175 } 175 }
176 176
177 void TestWebViewDelegate::DidStopLoading(WebView* webview) { 177 void TestWebViewDelegate::DidStopLoading(WebView* webview) {
178 // Ignored 178 // Ignored
179 } 179 }
180 180
181 void TestWebViewDelegate::WindowObjectCleared(WebFrame* webframe) { 181 void TestWebViewDelegate::WindowObjectCleared(WebFrame* webframe) {
182 shell_->BindJSObjectsToWindow(webframe); 182 shell_->BindJSObjectsToWindow(webframe);
183 } 183 }
184 184
185 WindowOpenDisposition TestWebViewDelegate::DispositionForNavigationAction( 185 WebNavigationPolicy TestWebViewDelegate::PolicyForNavigationAction(
186 WebView* webview, 186 WebView* webview,
187 WebFrame* frame, 187 WebFrame* frame,
188 const WebURLRequest& request, 188 const WebURLRequest& request,
189 WebNavigationType type, 189 WebNavigationType type,
190 WindowOpenDisposition disposition, 190 WebNavigationPolicy default_policy,
191 bool is_redirect) { 191 bool is_redirect) {
192 WindowOpenDisposition result; 192 WebNavigationPolicy result;
193 if (policy_delegate_enabled_) { 193 if (policy_delegate_enabled_) {
194 std::wstring frame_name = frame->GetName(); 194 std::wstring frame_name = frame->GetName();
195 std::string url_description; 195 std::string url_description;
196 GURL request_url = request.url(); 196 GURL request_url = request.url();
197 if (request_url.SchemeIs("file")) { 197 if (request_url.SchemeIs("file")) {
198 url_description = request_url.ExtractFileName(); 198 url_description = request_url.ExtractFileName();
199 } else { 199 } else {
200 url_description = request_url.spec(); 200 url_description = request_url.spec();
201 } 201 }
202 printf("Policy delegate: attempt to load %s with navigation type '%s'\n", 202 printf("Policy delegate: attempt to load %s with navigation type '%s'\n",
203 url_description.c_str(), WebNavigationTypeToString(type)); 203 url_description.c_str(), WebNavigationTypeToString(type));
204 result = policy_delegate_is_permissive_ ? CURRENT_TAB : IGNORE_ACTION; 204 if (policy_delegate_is_permissive_) {
205 result = WebKit::WebNavigationPolicyCurrentTab;
206 } else {
207 result = WebKit::WebNavigationPolicyIgnore;
208 }
205 if (policy_delegate_should_notify_done_) 209 if (policy_delegate_should_notify_done_)
206 shell_->layout_test_controller()->PolicyDelegateDone(); 210 shell_->layout_test_controller()->PolicyDelegateDone();
207 } else { 211 } else {
208 result = WebViewDelegate::DispositionForNavigationAction( 212 result = default_policy;
209 webview, frame, request, type, disposition, is_redirect);
210 } 213 }
211 return result; 214 return result;
212 } 215 }
213 216
214 void TestWebViewDelegate::AssignIdentifierToRequest( 217 void TestWebViewDelegate::AssignIdentifierToRequest(
215 WebView* webview, 218 WebView* webview,
216 uint32 identifier, 219 uint32 identifier,
217 const WebURLRequest& request) { 220 const WebURLRequest& request) {
218 if (shell_->ShouldDumpResourceLoadCallbacks()) 221 if (shell_->ShouldDumpResourceLoadCallbacks())
219 resource_identifier_map_[identifier] = request.url().spec(); 222 resource_identifier_map_[identifier] = request.url().spec();
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 740
738 void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) { 741 void TestWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
739 WebPreferences* prefs = shell_->GetWebPreferences(); 742 WebPreferences* prefs = shell_->GetWebPreferences();
740 prefs->user_style_sheet_enabled = true; 743 prefs->user_style_sheet_enabled = true;
741 prefs->user_style_sheet_location = location; 744 prefs->user_style_sheet_location = location;
742 shell_->webView()->SetPreferences(*prefs); 745 shell_->webView()->SetPreferences(*prefs);
743 } 746 }
744 747
745 // WebWidgetDelegate --------------------------------------------------------- 748 // WebWidgetDelegate ---------------------------------------------------------
746 749
747 void TestWebViewDelegate::DidInvalidateRect(WebWidget* webwidget, 750 void TestWebViewDelegate::didInvalidateRect(const WebRect& rect) {
748 const WebRect& rect) { 751 if (WebWidgetHost* host = GetWidgetHost())
749 if (WebWidgetHost* host = GetHostForWidget(webwidget))
750 host->DidInvalidateRect(rect); 752 host->DidInvalidateRect(rect);
751 } 753 }
752 754
753 void TestWebViewDelegate::DidScrollRect(WebWidget* webwidget, int dx, int dy, 755 void TestWebViewDelegate::didScrollRect(int dx, int dy,
754 const WebRect& clip_rect) { 756 const WebRect& clip_rect) {
755 if (WebWidgetHost* host = GetHostForWidget(webwidget)) 757 if (WebWidgetHost* host = GetWidgetHost())
756 host->DidScrollRect(dx, dy, clip_rect); 758 host->DidScrollRect(dx, dy, clip_rect);
757 } 759 }
758 760
759 void TestWebViewDelegate::Focus(WebWidget* webwidget) { 761 void TestWebViewDelegate::didFocus() {
760 if (WebWidgetHost* host = GetHostForWidget(webwidget)) 762 if (WebWidgetHost* host = GetWidgetHost())
761 shell_->SetFocus(host, true); 763 shell_->SetFocus(host, true);
762 } 764 }
763 765
764 void TestWebViewDelegate::Blur(WebWidget* webwidget) { 766 void TestWebViewDelegate::didBlur() {
765 if (WebWidgetHost* host = GetHostForWidget(webwidget)) 767 if (WebWidgetHost* host = GetWidgetHost())
766 shell_->SetFocus(host, false); 768 shell_->SetFocus(host, false);
767 } 769 }
768 770
769 bool TestWebViewDelegate::IsHidden(WebWidget* webwidget) { 771 WebScreenInfo TestWebViewDelegate::screenInfo() {
770 return false; 772 if (WebWidgetHost* host = GetWidgetHost())
771 }
772
773 WebScreenInfo TestWebViewDelegate::GetScreenInfo(WebWidget* webwidget) {
774 if (WebWidgetHost* host = GetHostForWidget(webwidget))
775 return host->GetScreenInfo(); 773 return host->GetScreenInfo();
776 774
777 return WebScreenInfo(); 775 return WebScreenInfo();
778 } 776 }
779 777
780 void TestWebViewDelegate::SetSmartInsertDeleteEnabled(bool enabled) { 778 void TestWebViewDelegate::SetSmartInsertDeleteEnabled(bool enabled) {
781 smart_insert_delete_enabled_ = enabled; 779 smart_insert_delete_enabled_ = enabled;
782 // In upstream WebKit, smart insert/delete is mutually exclusive with select 780 // In upstream WebKit, smart insert/delete is mutually exclusive with select
783 // trailing whitespace, however, we allow both because Chromium on Windows 781 // trailing whitespace, however, we allow both because Chromium on Windows
784 // allows both. 782 // allows both.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 826
829 void TestWebViewDelegate::LocationChangeDone(WebFrame* frame) { 827 void TestWebViewDelegate::LocationChangeDone(WebFrame* frame) {
830 if (frame == top_loading_frame_) { 828 if (frame == top_loading_frame_) {
831 top_loading_frame_ = NULL; 829 top_loading_frame_ = NULL;
832 830
833 if (shell_->layout_test_mode()) 831 if (shell_->layout_test_mode())
834 shell_->layout_test_controller()->LocationChangeDone(); 832 shell_->layout_test_controller()->LocationChangeDone();
835 } 833 }
836 } 834 }
837 835
838 WebWidgetHost* TestWebViewDelegate::GetHostForWidget(WebWidget* webwidget) { 836 WebWidgetHost* TestWebViewDelegate::GetWidgetHost() {
839 if (webwidget == shell_->webView()) 837 if (this == shell_->delegate())
840 return shell_->webViewHost(); 838 return shell_->webViewHost();
841 if (webwidget == shell_->popup()) 839 if (this == shell_->popup_delegate())
842 return shell_->popupHost(); 840 return shell_->popupHost();
843 return NULL; 841 return NULL;
844 } 842 }
845 843
846 void TestWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame, 844 void TestWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame,
847 bool is_new_navigation) { 845 bool is_new_navigation) {
848 // Code duplicated from RenderView::DidCommitLoadForFrame. 846 // Code duplicated from RenderView::DidCommitLoadForFrame.
849 TestShellExtraData* extra_data = static_cast<TestShellExtraData*>( 847 TestShellExtraData* extra_data = static_cast<TestShellExtraData*>(
850 frame->GetDataSource()->extraData()); 848 frame->GetDataSource()->extraData());
851 849
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 return L"main frame \"" + name + L"\""; 920 return L"main frame \"" + name + L"\"";
923 else 921 else
924 return L"main frame"; 922 return L"main frame";
925 } else { 923 } else {
926 if (name.length()) 924 if (name.length())
927 return L"frame \"" + name + L"\""; 925 return L"frame \"" + name + L"\"";
928 else 926 else
929 return L"frame (anonymous)"; 927 return L"frame (anonymous)";
930 } 928 }
931 } 929 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_webview_delegate.h ('k') | webkit/tools/test_shell/test_webview_delegate_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698