OLD | NEW |
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 "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 2113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2124 NOTREACHED() << "unknown ErrorPageType"; | 2124 NOTREACHED() << "unknown ErrorPageType"; |
2125 } | 2125 } |
2126 | 2126 |
2127 // OK, build the final url to return. | 2127 // OK, build the final url to return. |
2128 GURL::Replacements link_doctor_params; | 2128 GURL::Replacements link_doctor_params; |
2129 link_doctor_params.SetQueryStr(params); | 2129 link_doctor_params.SetQueryStr(params); |
2130 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); | 2130 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
2131 return url; | 2131 return url; |
2132 } | 2132 } |
2133 | 2133 |
2134 void RenderView::OnFind(const WebKit::WebFindInPageRequest& request) { | 2134 void RenderView::OnFind(int request_id, |
| 2135 const string16& search_text, |
| 2136 const WebKit::WebFindOptions& options) { |
2135 WebFrame* main_frame = webview()->GetMainFrame(); | 2137 WebFrame* main_frame = webview()->GetMainFrame(); |
2136 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true); | 2138 WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true); |
2137 WebFrame* focused_frame = webview()->GetFocusedFrame(); | 2139 WebFrame* focused_frame = webview()->GetFocusedFrame(); |
2138 WebFrame* search_frame = focused_frame; // start searching focused frame. | 2140 WebFrame* search_frame = focused_frame; // start searching focused frame. |
2139 | 2141 |
2140 bool multi_frame = (frame_after_main != main_frame); | 2142 bool multi_frame = (frame_after_main != main_frame); |
2141 | 2143 |
2142 // If we have multiple frames, we don't want to wrap the search within the | 2144 // If we have multiple frames, we don't want to wrap the search within the |
2143 // frame, so we check here if we only have main_frame in the chain. | 2145 // frame, so we check here if we only have main_frame in the chain. |
2144 bool wrap_within_frame = !multi_frame; | 2146 bool wrap_within_frame = !multi_frame; |
2145 | 2147 |
2146 gfx::Rect selection_rect; | 2148 gfx::Rect selection_rect; |
2147 bool result = false; | 2149 bool result = false; |
2148 | 2150 |
2149 do { | 2151 do { |
2150 result = search_frame->Find(request, wrap_within_frame, &selection_rect); | 2152 result = search_frame->Find( |
| 2153 request_id, search_text, options, wrap_within_frame, &selection_rect); |
2151 | 2154 |
2152 if (!result) { | 2155 if (!result) { |
2153 // don't leave text selected as you move to the next frame. | 2156 // don't leave text selected as you move to the next frame. |
2154 search_frame->ClearSelection(); | 2157 search_frame->ClearSelection(); |
2155 | 2158 |
2156 // Find the next frame, but skip the invisible ones. | 2159 // Find the next frame, but skip the invisible ones. |
2157 do { | 2160 do { |
2158 // What is the next frame to search? (we might be going backwards). Note | 2161 // What is the next frame to search? (we might be going backwards). Note |
2159 // that we specify wrap=true so that search_frame never becomes NULL. | 2162 // that we specify wrap=true so that search_frame never becomes NULL. |
2160 search_frame = request.forward ? | 2163 search_frame = options.forward ? |
2161 webview()->GetNextFrameAfter(search_frame, true) : | 2164 webview()->GetNextFrameAfter(search_frame, true) : |
2162 webview()->GetPreviousFrameBefore(search_frame, true); | 2165 webview()->GetPreviousFrameBefore(search_frame, true); |
2163 } while (!search_frame->Visible() && search_frame != focused_frame); | 2166 } while (!search_frame->Visible() && search_frame != focused_frame); |
2164 | 2167 |
2165 // Make sure selection doesn't affect the search operation in new frame. | 2168 // Make sure selection doesn't affect the search operation in new frame. |
2166 search_frame->ClearSelection(); | 2169 search_frame->ClearSelection(); |
2167 | 2170 |
2168 // If we have multiple frames and we have wrapped back around to the | 2171 // If we have multiple frames and we have wrapped back around to the |
2169 // focused frame, we need to search it once more allowing wrap within | 2172 // focused frame, we need to search it once more allowing wrap within |
2170 // the frame, otherwise it will report 'no match' if the focused frame has | 2173 // the frame, otherwise it will report 'no match' if the focused frame has |
2171 // reported matches, but no frames after the focused_frame contain a | 2174 // reported matches, but no frames after the focused_frame contain a |
2172 // match for the search word(s). | 2175 // match for the search word(s). |
2173 if (multi_frame && search_frame == focused_frame) { | 2176 if (multi_frame && search_frame == focused_frame) { |
2174 result = search_frame->Find(request, true, // Force wrapping. | 2177 result = search_frame->Find( |
2175 &selection_rect); | 2178 request_id, search_text, options, true, // Force wrapping. |
| 2179 &selection_rect); |
2176 } | 2180 } |
2177 } | 2181 } |
2178 | 2182 |
2179 // TODO(jcampan): http://b/issue?id=1157486 Remove StoreForFocus call once | 2183 // TODO(jcampan): http://b/issue?id=1157486 Remove StoreForFocus call once |
2180 // we have the fix for 792423. | 2184 // we have the fix for 792423. |
2181 search_frame->GetView()->StoreFocusForFrame(search_frame); | 2185 search_frame->GetView()->StoreFocusForFrame(search_frame); |
2182 webview()->SetFocusedFrame(search_frame); | 2186 webview()->SetFocusedFrame(search_frame); |
2183 } while (!result && search_frame != focused_frame); | 2187 } while (!result && search_frame != focused_frame); |
2184 | 2188 |
2185 // Make sure we don't leave any frame focused or the focus won't be restored | 2189 // Make sure we don't leave any frame focused or the focus won't be restored |
2186 // properly in WebViewImpl::SetFocus(). Note that we are talking here about | 2190 // properly in WebViewImpl::SetFocus(). Note that we are talking here about |
2187 // focused on the SelectionController, not FocusController. | 2191 // focused on the SelectionController, not FocusController. |
2188 // webview()->GetFocusedFrame() will still return the last focused frame (as | 2192 // webview()->GetFocusedFrame() will still return the last focused frame (as |
2189 // it queries the FocusController). | 2193 // it queries the FocusController). |
2190 // TODO(jcampan): http://b/issue?id=1157486 Remove next line once we have the | 2194 // TODO(jcampan): http://b/issue?id=1157486 Remove next line once we have the |
2191 // fix for 792423. | 2195 // fix for 792423. |
2192 webview()->SetFocusedFrame(NULL); | 2196 webview()->SetFocusedFrame(NULL); |
2193 | 2197 |
2194 if (request.findNext) { | 2198 if (options.findNext) { |
2195 // Force the main_frame to report the actual count. | 2199 // Force the main_frame to report the actual count. |
2196 main_frame->IncreaseMatchCount(0, request.identifier); | 2200 main_frame->IncreaseMatchCount(0, request_id); |
2197 } else { | 2201 } else { |
2198 // If nothing is found, set result to "0 of 0", otherwise, set it to | 2202 // If nothing is found, set result to "0 of 0", otherwise, set it to |
2199 // "-1 of 1" to indicate that we found at least one item, but we don't know | 2203 // "-1 of 1" to indicate that we found at least one item, but we don't know |
2200 // yet what is active. | 2204 // yet what is active. |
2201 int ordinal = result ? -1 : 0; // -1 here means, we might know more later. | 2205 int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
2202 int match_count = result ? 1 : 0; // 1 here means possibly more coming. | 2206 int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
2203 | 2207 |
2204 // If we find no matches then this will be our last status update. | 2208 // If we find no matches then this will be our last status update. |
2205 // Otherwise the scoping effort will send more results. | 2209 // Otherwise the scoping effort will send more results. |
2206 bool final_status_update = !result; | 2210 bool final_status_update = !result; |
2207 | 2211 |
2208 // Send the search result over to the browser process. | 2212 // Send the search result over to the browser process. |
2209 Send(new ViewHostMsg_Find_Reply(routing_id_, | 2213 Send(new ViewHostMsg_Find_Reply(routing_id_, |
2210 request.identifier, | 2214 request_id, |
2211 match_count, | 2215 match_count, |
2212 selection_rect, | 2216 selection_rect, |
2213 ordinal, | 2217 ordinal, |
2214 final_status_update)); | 2218 final_status_update)); |
2215 | 2219 |
2216 // Scoping effort begins, starting with the mainframe. | 2220 // Scoping effort begins, starting with the mainframe. |
2217 search_frame = main_frame; | 2221 search_frame = main_frame; |
2218 | 2222 |
2219 main_frame->ResetMatchCount(); | 2223 main_frame->ResetMatchCount(); |
2220 | 2224 |
2221 do { | 2225 do { |
2222 // Cancel all old scoping requests before starting a new one. | 2226 // Cancel all old scoping requests before starting a new one. |
2223 search_frame->CancelPendingScopingEffort(); | 2227 search_frame->CancelPendingScopingEffort(); |
2224 | 2228 |
2225 // We don't start another scoping effort unless at least one match has | 2229 // We don't start another scoping effort unless at least one match has |
2226 // been found. | 2230 // been found. |
2227 if (result) { | 2231 if (result) { |
2228 // Start new scoping request. If the scoping function determines that it | 2232 // Start new scoping request. If the scoping function determines that it |
2229 // needs to scope, it will defer until later. | 2233 // needs to scope, it will defer until later. |
2230 search_frame->ScopeStringMatches(request, | 2234 search_frame->ScopeStringMatches(request_id, |
| 2235 search_text, |
| 2236 options, |
2231 true); // reset the tickmarks | 2237 true); // reset the tickmarks |
2232 } | 2238 } |
2233 | 2239 |
2234 // Iterate to the next frame. The frame will not necessarily scope, for | 2240 // Iterate to the next frame. The frame will not necessarily scope, for |
2235 // example if it is not visible. | 2241 // example if it is not visible. |
2236 search_frame = webview()->GetNextFrameAfter(search_frame, true); | 2242 search_frame = webview()->GetNextFrameAfter(search_frame, true); |
2237 } while (search_frame != main_frame); | 2243 } while (search_frame != main_frame); |
2238 } | 2244 } |
2239 } | 2245 } |
2240 | 2246 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2517 void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, | 2523 void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, |
2518 const std::wstring& jscript) { | 2524 const std::wstring& jscript) { |
2519 EvaluateScript(frame_xpath, jscript); | 2525 EvaluateScript(frame_xpath, jscript); |
2520 } | 2526 } |
2521 | 2527 |
2522 void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, | 2528 void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
2523 const std::string& css) { | 2529 const std::string& css) { |
2524 InsertCSS(frame_xpath, css); | 2530 InsertCSS(frame_xpath, css); |
2525 } | 2531 } |
2526 | 2532 |
2527 void RenderView::OnAddMessageToConsole(const std::wstring& frame_xpath, | 2533 void RenderView::OnAddMessageToConsole( |
2528 const WebConsoleMessage& message) { | 2534 const string16& frame_xpath, |
2529 WebFrame* web_frame = GetChildFrame(frame_xpath); | 2535 const string16& message, |
| 2536 const WebConsoleMessage::Level& level) { |
| 2537 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
2530 if (web_frame) | 2538 if (web_frame) |
2531 web_frame->AddMessageToConsole(message); | 2539 web_frame->AddMessageToConsole(WebConsoleMessage(level, message)); |
2532 } | 2540 } |
2533 | 2541 |
2534 #if defined(OS_WIN) | 2542 #if defined(OS_WIN) |
2535 void RenderView::OnDebugAttach() { | 2543 void RenderView::OnDebugAttach() { |
2536 Send(new ViewHostMsg_DidDebugAttach(routing_id_)); | 2544 Send(new ViewHostMsg_DidDebugAttach(routing_id_)); |
2537 // Tell the plugin host to stop accepting messages in order to avoid | 2545 // Tell the plugin host to stop accepting messages in order to avoid |
2538 // hangs while the renderer is paused. | 2546 // hangs while the renderer is paused. |
2539 // TODO(1243929): It might be an improvement to add more plumbing to do this | 2547 // TODO(1243929): It might be an improvement to add more plumbing to do this |
2540 // when the renderer is actually paused vs. just the debugger being attached. | 2548 // when the renderer is actually paused vs. just the debugger being attached. |
2541 PluginChannelHost::SetListening(false); | 2549 PluginChannelHost::SetListening(false); |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3128 "Renderer.Other.StartToFinishDoc", start_to_finish_doc); | 3136 "Renderer.Other.StartToFinishDoc", start_to_finish_doc); |
3129 UMA_HISTOGRAM_TIMES( | 3137 UMA_HISTOGRAM_TIMES( |
3130 "Renderer.Other.FinishDocToFinish", finish_doc_to_finish); | 3138 "Renderer.Other.FinishDocToFinish", finish_doc_to_finish); |
3131 UMA_HISTOGRAM_TIMES( | 3139 UMA_HISTOGRAM_TIMES( |
3132 "Renderer.Other.RequestToFinish", request_to_finish); | 3140 "Renderer.Other.RequestToFinish", request_to_finish); |
3133 UMA_HISTOGRAM_TIMES( | 3141 UMA_HISTOGRAM_TIMES( |
3134 "Renderer.Other.StartToFinish", start_to_finish); | 3142 "Renderer.Other.StartToFinish", start_to_finish); |
3135 break; | 3143 break; |
3136 } | 3144 } |
3137 } | 3145 } |
OLD | NEW |