OLD | NEW |
---|---|
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 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1808 } | 1808 } |
1809 return new webkit_glue::WebMediaPlayerImpl(client, factory); | 1809 return new webkit_glue::WebMediaPlayerImpl(client, factory); |
1810 } | 1810 } |
1811 | 1811 |
1812 void RenderView::willClose(WebFrame* frame) { | 1812 void RenderView::willClose(WebFrame* frame) { |
1813 if (!frame->parent()) { | 1813 if (!frame->parent()) { |
1814 const GURL& url = frame->url(); | 1814 const GURL& url = frame->url(); |
1815 if (url.SchemeIs("http") || url.SchemeIs("https")) | 1815 if (url.SchemeIs("http") || url.SchemeIs("https")) |
1816 DumpLoadHistograms(); | 1816 DumpLoadHistograms(); |
1817 } | 1817 } |
1818 | |
1819 WebDataSource* ds = frame->dataSource(); | |
Matt Perry
2009/11/02 19:46:30
Can this ever be NULL?
Aaron Boodman
2009/11/03 05:03:11
No, it is created in didCreateDataSource(), and ma
darin (slow to review)
2009/11/03 05:11:00
Right, it cannot be null!
| |
1820 NavigationState* navigation_state = NavigationState::FromDataSource(ds); | |
1821 navigation_state->user_script_idle_scheduler()->Cancel(); | |
1818 } | 1822 } |
1819 | 1823 |
1820 void RenderView::loadURLExternally( | 1824 void RenderView::loadURLExternally( |
1821 WebFrame* frame, const WebURLRequest& request, | 1825 WebFrame* frame, const WebURLRequest& request, |
1822 WebNavigationPolicy policy) { | 1826 WebNavigationPolicy policy) { |
1823 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); | 1827 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
1824 if (policy == WebKit::WebNavigationPolicyDownload) { | 1828 if (policy == WebKit::WebNavigationPolicyDownload) { |
1825 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); | 1829 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
1826 } else { | 1830 } else { |
1827 OpenURL(request.url(), referrer, policy); | 1831 OpenURL(request.url(), referrer, policy); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2010 | 2014 |
2011 void RenderView::didCompleteClientRedirect( | 2015 void RenderView::didCompleteClientRedirect( |
2012 WebFrame* frame, const WebURL& from) { | 2016 WebFrame* frame, const WebURL& from) { |
2013 if (!frame->parent()) | 2017 if (!frame->parent()) |
2014 completed_client_redirect_src_ = from; | 2018 completed_client_redirect_src_ = from; |
2015 } | 2019 } |
2016 | 2020 |
2017 void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { | 2021 void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
2018 // The rest of RenderView assumes that a WebDataSource will always have a | 2022 // The rest of RenderView assumes that a WebDataSource will always have a |
2019 // non-null NavigationState. | 2023 // non-null NavigationState. |
2020 if (pending_navigation_state_.get()) { | 2024 NavigationState* state = pending_navigation_state_.get() ? |
2021 ds->setExtraData(pending_navigation_state_.release()); | 2025 pending_navigation_state_.release() : |
2022 } else { | 2026 NavigationState::CreateContentInitiated(); |
2023 ds->setExtraData(NavigationState::CreateContentInitiated()); | 2027 |
2024 } | 2028 state->set_user_script_idle_scheduler( |
2029 new UserScriptIdleScheduler(this, frame)); | |
2030 ds->setExtraData(state); | |
2025 } | 2031 } |
2026 | 2032 |
2027 void RenderView::didStartProvisionalLoad(WebFrame* frame) { | 2033 void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
2028 WebDataSource* ds = frame->provisionalDataSource(); | 2034 WebDataSource* ds = frame->provisionalDataSource(); |
2029 NavigationState* navigation_state = NavigationState::FromDataSource(ds); | 2035 NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
2030 | 2036 |
2031 navigation_state->set_start_load_time(Time::Now()); | 2037 navigation_state->set_start_load_time(Time::Now()); |
2032 | 2038 |
2033 // Update the request time if WebKit has better knowledge of it. | 2039 // Update the request time if WebKit has better knowledge of it. |
2034 if (navigation_state->request_time().is_null()) { | 2040 if (navigation_state->request_time().is_null()) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2229 if (RenderThread::current()) { // Will be NULL during unit tests. | 2235 if (RenderThread::current()) { // Will be NULL during unit tests. |
2230 RenderThread::current()->user_script_slave()->InjectScripts( | 2236 RenderThread::current()->user_script_slave()->InjectScripts( |
2231 frame, UserScript::DOCUMENT_START); | 2237 frame, UserScript::DOCUMENT_START); |
2232 } | 2238 } |
2233 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP || | 2239 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP || |
2234 view_type_ == ViewType::EXTENSION_MOLE) { | 2240 view_type_ == ViewType::EXTENSION_MOLE) { |
2235 InjectToolstripCSS(); | 2241 InjectToolstripCSS(); |
2236 ExtensionProcessBindings::SetViewType(webview(), view_type_); | 2242 ExtensionProcessBindings::SetViewType(webview(), view_type_); |
2237 } | 2243 } |
2238 | 2244 |
2239 while (!pending_code_execution_queue_.empty()) { | |
2240 scoped_refptr<CodeExecutionInfo> info = | |
2241 pending_code_execution_queue_.front(); | |
2242 OnExecuteCode(info->request_id, info->extension_id, info->is_js_code, | |
2243 info->code_string); | |
2244 pending_code_execution_queue_.pop(); | |
2245 } | |
2246 | |
2247 // Notify the browser about non-blank documents loading in the top frame. | 2245 // Notify the browser about non-blank documents loading in the top frame. |
2248 GURL url = frame->url(); | 2246 GURL url = frame->url(); |
2249 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { | 2247 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
2250 if (frame == webview()->mainFrame()) | 2248 if (frame == webview()->mainFrame()) |
2251 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); | 2249 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
2252 } | 2250 } |
2253 } | 2251 } |
2254 | 2252 |
2255 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { | 2253 void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
2256 UpdateTitle(frame, title); | 2254 UpdateTitle(frame, title); |
(...skipping 14 matching lines...) Expand all Loading... | |
2271 // sent up to the browser. | 2269 // sent up to the browser. |
2272 SendPasswordForms(frame); | 2270 SendPasswordForms(frame); |
2273 | 2271 |
2274 // Check whether we have new encoding name. | 2272 // Check whether we have new encoding name. |
2275 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); | 2273 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
2276 | 2274 |
2277 if (RenderThread::current()) { // Will be NULL during unit tests. | 2275 if (RenderThread::current()) { // Will be NULL during unit tests. |
2278 RenderThread::current()->user_script_slave()->InjectScripts( | 2276 RenderThread::current()->user_script_slave()->InjectScripts( |
2279 frame, UserScript::DOCUMENT_END); | 2277 frame, UserScript::DOCUMENT_END); |
2280 } | 2278 } |
2279 | |
2280 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); | |
2281 } | |
2282 | |
2283 void RenderView::OnUserScriptIdleLocation(WebFrame* frame) { | |
2284 if (RenderThread::current()) { // Will be NULL during unit tests. | |
2285 RenderThread::current()->user_script_slave()->InjectScripts( | |
2286 frame, UserScript::DOCUMENT_IDLE); | |
2287 } | |
2288 | |
2289 WebFrame* main_frame = webview()->mainFrame(); | |
2290 if (frame == main_frame) { | |
2291 while (!pending_code_execution_queue_.empty()) { | |
2292 scoped_refptr<CodeExecutionInfo> info = | |
2293 pending_code_execution_queue_.front(); | |
2294 ExecuteCodeImpl(main_frame, info->request_id, info->extension_id, | |
2295 info->is_js_code, info->code_string); | |
2296 pending_code_execution_queue_.pop(); | |
2297 } | |
2298 } | |
2281 } | 2299 } |
2282 | 2300 |
2283 void RenderView::didHandleOnloadEvents(WebFrame* frame) { | 2301 void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
2284 // Ignore | 2302 // Ignore |
2285 } | 2303 } |
2286 | 2304 |
2287 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { | 2305 void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
2288 // Ignore | 2306 // Ignore |
2289 } | 2307 } |
2290 | 2308 |
2291 void RenderView::didFinishLoad(WebFrame* frame) { | 2309 void RenderView::didFinishLoad(WebFrame* frame) { |
2292 WebDataSource* ds = frame->dataSource(); | 2310 WebDataSource* ds = frame->dataSource(); |
2293 NavigationState* navigation_state = NavigationState::FromDataSource(ds); | 2311 NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
2294 DCHECK(navigation_state); | 2312 DCHECK(navigation_state); |
2295 navigation_state->set_finish_load_time(Time::Now()); | 2313 navigation_state->set_finish_load_time(Time::Now()); |
2314 navigation_state->user_script_idle_scheduler()->DidFinishLoad(); | |
2296 } | 2315 } |
2297 | 2316 |
2298 void RenderView::didChangeLocationWithinPage( | 2317 void RenderView::didChangeLocationWithinPage( |
2299 WebFrame* frame, bool is_new_navigation) { | 2318 WebFrame* frame, bool is_new_navigation) { |
2300 // If this was a reference fragment navigation that we initiated, then we | 2319 // If this was a reference fragment navigation that we initiated, then we |
2301 // could end up having a non-null pending navigation state. We just need to | 2320 // could end up having a non-null pending navigation state. We just need to |
2302 // update the ExtraData on the datasource so that others who read the | 2321 // update the ExtraData on the datasource so that others who read the |
2303 // ExtraData will get the new NavigationState. Similarly, if we did not | 2322 // ExtraData will get the new NavigationState. Similarly, if we did not |
2304 // initiate this navigation, then we need to take care to reset any pre- | 2323 // initiate this navigation, then we need to take care to reset any pre- |
2305 // existing navigation state to a content-initiated navigation state. | 2324 // existing navigation state to a content-initiated navigation state. |
(...skipping 1335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3641 } | 3660 } |
3642 | 3661 |
3643 void RenderView::OnSetEditCommandsForNextKeyEvent( | 3662 void RenderView::OnSetEditCommandsForNextKeyEvent( |
3644 const EditCommands& edit_commands) { | 3663 const EditCommands& edit_commands) { |
3645 edit_commands_ = edit_commands; | 3664 edit_commands_ = edit_commands; |
3646 } | 3665 } |
3647 | 3666 |
3648 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id, | 3667 void RenderView::OnExecuteCode(int request_id, const std::string& extension_id, |
3649 bool is_js_code, | 3668 bool is_js_code, |
3650 const std::string& code_string) { | 3669 const std::string& code_string) { |
3651 if (is_loading_) { | |
3652 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo( | |
3653 request_id, extension_id, is_js_code, code_string); | |
3654 pending_code_execution_queue_.push(info); | |
3655 return; | |
3656 } | |
3657 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; | 3670 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
3658 if (!main_frame) { | 3671 if (!main_frame) { |
3659 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false)); | 3672 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, false)); |
3660 return; | 3673 return; |
3661 } | 3674 } |
3662 | 3675 |
3676 WebDataSource* ds = main_frame->dataSource(); | |
3677 NavigationState* navigation_state = NavigationState::FromDataSource(ds); | |
3678 if (!navigation_state->user_script_idle_scheduler()->has_run()) { | |
3679 scoped_refptr<CodeExecutionInfo> info = new CodeExecutionInfo( | |
3680 request_id, extension_id, is_js_code, code_string); | |
3681 pending_code_execution_queue_.push(info); | |
3682 return; | |
3683 } | |
3684 | |
3685 ExecuteCodeImpl(main_frame, request_id, extension_id, is_js_code, code_string) ; | |
Matt Perry
2009/11/02 19:46:30
line length
| |
3686 } | |
3687 | |
3688 void RenderView::ExecuteCodeImpl(WebFrame* frame, | |
3689 int request_id, | |
3690 const std::string& extension_id, | |
3691 bool is_js_code, | |
3692 const std::string& code_string) { | |
3663 if (is_js_code) { | 3693 if (is_js_code) { |
3664 std::vector<WebScriptSource> sources; | 3694 std::vector<WebScriptSource> sources; |
3665 sources.push_back( | 3695 sources.push_back( |
3666 WebScriptSource(WebString::fromUTF8(code_string))); | 3696 WebScriptSource(WebString::fromUTF8(code_string))); |
3667 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id); | 3697 UserScriptSlave::InsertInitExtensionCode(&sources, extension_id); |
3668 main_frame->executeScriptInIsolatedWorld( | 3698 frame->executeScriptInIsolatedWorld( |
3669 UserScriptSlave::GetIsolatedWorldId(extension_id), | 3699 UserScriptSlave::GetIsolatedWorldId(extension_id), |
3670 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); | 3700 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
3671 } else { | 3701 } else { |
3672 main_frame->insertStyleText(WebString::fromUTF8(code_string), WebString()); | 3702 frame->insertStyleText(WebString::fromUTF8(code_string), WebString()); |
3673 } | 3703 } |
3674 | 3704 |
3675 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true)); | 3705 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, request_id, true)); |
3676 } | 3706 } |
3677 | 3707 |
3678 void RenderView::Close() { | 3708 void RenderView::Close() { |
3679 // We need to grab a pointer to the doomed WebView before we destroy it. | 3709 // We need to grab a pointer to the doomed WebView before we destroy it. |
3680 WebView* doomed = webview(); | 3710 WebView* doomed = webview(); |
3681 RenderWidget::Close(); | 3711 RenderWidget::Close(); |
3682 Singleton<ViewMap>::get()->erase(doomed); | 3712 Singleton<ViewMap>::get()->erase(doomed); |
(...skipping 20 matching lines...) Expand all Loading... | |
3703 new PluginMsg_SignalModalDialogEvent(host_window_)); | 3733 new PluginMsg_SignalModalDialogEvent(host_window_)); |
3704 | 3734 |
3705 message->EnableMessagePumping(); // Runs a nested message loop. | 3735 message->EnableMessagePumping(); // Runs a nested message loop. |
3706 bool rv = Send(message); | 3736 bool rv = Send(message); |
3707 | 3737 |
3708 PluginChannelHost::Broadcast( | 3738 PluginChannelHost::Broadcast( |
3709 new PluginMsg_ResetModalDialogEvent(host_window_)); | 3739 new PluginMsg_ResetModalDialogEvent(host_window_)); |
3710 | 3740 |
3711 return rv; | 3741 return rv; |
3712 } | 3742 } |
OLD | NEW |