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

Side by Side Diff: webkit/tools/test_shell/gtk/test_shell.cc

Issue 8670: Switch to using the message loop rather than gtk_main(). (Closed)
Patch Set: Addressing comments Created 12 years, 1 month 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
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 "webkit/tools/test_shell/test_shell.h" 5 #include "webkit/tools/test_shell/test_shell.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "net/base/mime_util.h" 12 #include "net/base/mime_util.h"
13 #include "webkit/glue/webframe.h"
13 #include "webkit/glue/webpreferences.h" 14 #include "webkit/glue/webpreferences.h"
15 #include "webkit/glue/webview.h"
14 #include "webkit/glue/plugins/plugin_list.h" 16 #include "webkit/glue/plugins/plugin_list.h"
15 #include "webkit/glue/resource_loader_bridge.h" 17 #include "webkit/glue/resource_loader_bridge.h"
16 #include "webkit/tools/test_shell/test_navigation_controller.h" 18 #include "webkit/tools/test_shell/test_navigation_controller.h"
19 #include "webkit/tools/test_shell/test_webview_delegate.h"
17 20
18 WebPreferences* TestShell::web_prefs_ = NULL; 21 WebPreferences* TestShell::web_prefs_ = NULL;
19 22
20 WindowList* TestShell::window_list_; 23 WindowList* TestShell::window_list_;
21 24
22 TestShell::TestShell() { 25 TestShell::TestShell()
26 : delegate_(new TestWebViewDelegate(this)) {
27 layout_test_controller_.reset(new LayoutTestController(this));
28 navigation_controller_.reset(new TestNavigationController(this));
23 } 29 }
24 30
25 TestShell::~TestShell() { 31 TestShell::~TestShell() {
26 } 32 }
27 33
34 bool TestShell::interactive_ = false;
35
28 // static 36 // static
29 void TestShell::InitializeTestShell(bool interactive) { 37 void TestShell::InitializeTestShell(bool interactive) {
30 window_list_ = new WindowList; 38 window_list_ = new WindowList;
31
32 web_prefs_ = new WebPreferences; 39 web_prefs_ = new WebPreferences;
40 interactive_ = interactive;
33 } 41 }
34 42
35 // static 43 // static
36 bool TestShell::CreateNewWindow(const std::wstring& startingURL, 44 bool TestShell::CreateNewWindow(const std::wstring& startingURL,
37 TestShell** result) { 45 TestShell** result) {
38 TestShell *shell = new TestShell(); 46 TestShell *shell = new TestShell();
39 if (!shell->Initialize(startingURL)) 47 if (!shell->Initialize(startingURL))
40 return false; 48 return false;
41 if (result) 49 if (result)
42 *result = shell; 50 *result = shell;
(...skipping 28 matching lines...) Expand all
71 GtkToolItem* tool_item = gtk_tool_item_new(); 79 GtkToolItem* tool_item = gtk_tool_item_new();
72 gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd); 80 gtk_container_add(GTK_CONTAINER(tool_item), m_editWnd);
73 gtk_tool_item_set_expand(tool_item, TRUE); 81 gtk_tool_item_set_expand(tool_item, TRUE);
74 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), 82 gtk_toolbar_insert(GTK_TOOLBAR(toolbar),
75 tool_item, 83 tool_item,
76 -1 /* append */); 84 -1 /* append */);
77 85
78 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); 86 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
79 m_webViewHost.reset(WebViewHost::Create(vbox, NULL, *TestShell::web_prefs_)); 87 m_webViewHost.reset(WebViewHost::Create(vbox, NULL, *TestShell::web_prefs_));
80 88
89 if (!startingURL.empty())
90 LoadURL(startingURL.c_str());
91
81 gtk_container_add(GTK_CONTAINER(m_mainWnd), vbox); 92 gtk_container_add(GTK_CONTAINER(m_mainWnd), vbox);
82 gtk_widget_show_all(m_mainWnd); 93 gtk_widget_show_all(m_mainWnd);
83 94
84 return true; 95 return true;
85 } 96 }
86 97
98 void TestShell::TestFinished() {
99 NOTIMPLEMENTED();
100 }
101
102 void TestShell::Show(WebView* webview, WindowOpenDisposition disposition) {
103 delegate_->Show(webview, disposition);
104 }
105
106 void TestShell::SetFocus(WebWidgetHost* host, bool enable) {
107 // TODO(agl): port the body of this function
108 NOTIMPLEMENTED();
109 }
110
87 void TestShell::BindJSObjectsToWindow(WebFrame* frame) { 111 void TestShell::BindJSObjectsToWindow(WebFrame* frame) {
88 NOTIMPLEMENTED(); 112 NOTIMPLEMENTED();
89 } 113 }
90 114
115 void TestShell::DestroyWindow(gfx::WindowHandle windowHandle) {
116 NOTIMPLEMENTED();
117 }
118
119 WebView* TestShell::CreateWebView(WebView* webview) {
120 NOTIMPLEMENTED();
121 return NULL;
122 }
123
124 WebWidget* TestShell::CreatePopupWidget(WebView* webview) {
125 NOTIMPLEMENTED();
126 return NULL;
127 }
128
129 void TestShell::LoadURL(const wchar_t* url)
130 {
131 LoadURLForFrame(url, NULL);
132 }
133
134 void TestShell::LoadURLForFrame(const wchar_t* url,
135 const wchar_t* frame_name) {
136 if (!url)
137 return;
138
139 std::wstring frame_string;
140 if (frame_name)
141 frame_string = frame_name;
142
143 navigation_controller_->LoadEntry(new TestNavigationEntry(
144 -1, GURL(WideToUTF8(url)), std::wstring(), frame_string));
145 }
146
91 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { 147 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) {
148 WebRequestCachePolicy cache_policy;
149 if (reload) {
150 cache_policy = WebRequestReloadIgnoringCacheData;
151 } else if (entry.GetPageID() != -1) {
152 cache_policy = WebRequestReturnCacheDataElseLoad;
153 } else {
154 cache_policy = WebRequestUseProtocolCachePolicy;
155 }
156
157 scoped_ptr<WebRequest> request(WebRequest::Create(entry.GetURL()));
158 request->SetCachePolicy(cache_policy);
159 // If we are reloading, then WebKit will use the state of the current page.
160 // Otherwise, we give it the state to navigate to.
161 if (!reload)
162 request->SetHistoryState(entry.GetContentState());
163
164 request->SetExtraData(
165 new TestShellExtraRequestData(entry.GetPageID()));
166
167 // Get the right target frame for the entry.
168 WebFrame* frame = webView()->GetMainFrame();
169 if (!entry.GetTargetFrame().empty())
170 frame = webView()->GetFrameWithName(entry.GetTargetFrame());
171 // TODO(mpcomplete): should we clear the target frame, or should
172 // back/forward navigations maintain the target frame?
173
174 frame->LoadRequest(request.get());
175 // Restore focus to the main frame prior to loading new request.
176 // This makes sure that we don't have a focused iframe. Otherwise, that
177 // iframe would keep focus when the SetFocus called immediately after
178 // LoadRequest, thus making some tests fail (see http://b/issue?id=845337
179 // for more details).
180 webView()->SetFocusedFrame(frame);
181 SetFocus(webViewHost(), true);
182
183 return true;
184 }
185
186 void TestShell::GoBackOrForward(int offset) {
187 navigation_controller_->GoToOffset(offset);
188 }
189
190 void TestShell::Reload() {
191 navigation_controller_->Reload();
192 }
193
194 std::string TestShell::RewriteLocalUrl(const std::string& url) {
92 NOTIMPLEMENTED(); 195 NOTIMPLEMENTED();
93 return true; 196 return "";
94 } 197 }
95 198
96 //----------------------------------------------------------------------------- 199 //-----------------------------------------------------------------------------
97 200
98 namespace webkit_glue { 201 namespace webkit_glue {
99 202
100 void PrefetchDns(const std::string& hostname) {} 203 void PrefetchDns(const std::string& hostname) {}
101 204
102 void PrecacheUrl(const char16* url, int url_length) {} 205 void PrecacheUrl(const char16* url, int url_length) {}
103 206
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 276
174 bool IsDefaultPluginEnabled() { 277 bool IsDefaultPluginEnabled() {
175 return false; 278 return false;
176 } 279 }
177 280
178 std::wstring GetWebKitLocale() { 281 std::wstring GetWebKitLocale() {
179 return L"en-US"; 282 return L"en-US";
180 } 283 }
181 284
182 } // namespace webkit_glue 285 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/SConscript ('k') | webkit/tools/test_shell/gtk/test_webview_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698