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

Side by Side Diff: chrome/renderer/chrome_render_view_observer.cc

Issue 307623004: Move DetailedConsoleMessageAdded from ChromeRVO to ChromeRFO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make tests pass Created 6 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_render_view_observer.h" 5 #include "chrome/renderer/chrome_render_view_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/common/chrome_constants.h" 15 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/prerender_messages.h" 17 #include "chrome/common/prerender_messages.h"
19 #include "chrome/common/render_messages.h" 18 #include "chrome/common/render_messages.h"
20 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
21 #include "chrome/renderer/chrome_render_process_observer.h" 20 #include "chrome/renderer/chrome_render_process_observer.h"
22 #include "chrome/renderer/prerender/prerender_helper.h" 21 #include "chrome/renderer/prerender/prerender_helper.h"
23 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" 22 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
24 #include "chrome/renderer/translate/translate_helper.h" 23 #include "chrome/renderer/translate/translate_helper.h"
25 #include "chrome/renderer/webview_color_overlay.h" 24 #include "chrome/renderer/webview_color_overlay.h"
26 #include "content/public/common/bindings_policy.h" 25 #include "content/public/common/bindings_policy.h"
27 #include "content/public/renderer/content_renderer_client.h" 26 #include "content/public/renderer/content_renderer_client.h"
28 #include "content/public/renderer/render_frame.h" 27 #include "content/public/renderer/render_frame.h"
29 #include "content/public/renderer/render_view.h" 28 #include "content/public/renderer/render_view.h"
30 #include "extensions/common/constants.h" 29 #include "extensions/common/constants.h"
31 #include "extensions/common/stack_frame.h"
32 #include "net/base/data_url.h" 30 #include "net/base/data_url.h"
33 #include "skia/ext/platform_canvas.h" 31 #include "skia/ext/platform_canvas.h"
34 #include "third_party/WebKit/public/platform/WebCString.h" 32 #include "third_party/WebKit/public/platform/WebCString.h"
35 #include "third_party/WebKit/public/platform/WebRect.h" 33 #include "third_party/WebKit/public/platform/WebRect.h"
36 #include "third_party/WebKit/public/platform/WebSize.h" 34 #include "third_party/WebKit/public/platform/WebSize.h"
37 #include "third_party/WebKit/public/platform/WebString.h" 35 #include "third_party/WebKit/public/platform/WebString.h"
38 #include "third_party/WebKit/public/platform/WebURLRequest.h" 36 #include "third_party/WebKit/public/platform/WebURLRequest.h"
39 #include "third_party/WebKit/public/platform/WebVector.h" 37 #include "third_party/WebKit/public/platform/WebVector.h"
40 #include "third_party/WebKit/public/web/WebAXObject.h" 38 #include "third_party/WebKit/public/web/WebAXObject.h"
41 #include "third_party/WebKit/public/web/WebDataSource.h" 39 #include "third_party/WebKit/public/web/WebDataSource.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 static const char kTranslateCaptureText[] = "Translate.CaptureText"; 95 static const char kTranslateCaptureText[] = "Translate.CaptureText";
98 96
99 namespace { 97 namespace {
100 98
101 GURL StripRef(const GURL& url) { 99 GURL StripRef(const GURL& url) {
102 GURL::Replacements replacements; 100 GURL::Replacements replacements;
103 replacements.ClearRef(); 101 replacements.ClearRef();
104 return url.ReplaceComponents(replacements); 102 return url.ReplaceComponents(replacements);
105 } 103 }
106 104
107 // The delimiter for a stack trace provided by WebKit.
108 const char kStackFrameDelimiter[] = "\n at ";
109
110 // Get a stack trace from a WebKit console message.
111 // There are three possible scenarios:
112 // 1. WebKit gives us a stack trace in |stack_trace|.
113 // 2. The stack trace is embedded in the error |message| by an internal
114 // script. This will be more useful than |stack_trace|, since |stack_trace|
115 // will include the internal bindings trace, instead of a developer's code.
116 // 3. No stack trace is included. In this case, we should mock one up from
117 // the given line number and source.
118 // |message| will be populated with the error message only (i.e., will not
119 // include any stack trace).
120 extensions::StackTrace GetStackTraceFromMessage(
121 base::string16* message,
122 const base::string16& source,
123 const base::string16& stack_trace,
124 int32 line_number) {
125 extensions::StackTrace result;
126 std::vector<base::string16> pieces;
127 size_t index = 0;
128
129 if (message->find(base::UTF8ToUTF16(kStackFrameDelimiter)) !=
130 base::string16::npos) {
131 base::SplitStringUsingSubstr(*message,
132 base::UTF8ToUTF16(kStackFrameDelimiter),
133 &pieces);
134 *message = pieces[0];
135 index = 1;
136 } else if (!stack_trace.empty()) {
137 base::SplitStringUsingSubstr(stack_trace,
138 base::UTF8ToUTF16(kStackFrameDelimiter),
139 &pieces);
140 }
141
142 // If we got a stack trace, parse each frame from the text.
143 if (index < pieces.size()) {
144 for (; index < pieces.size(); ++index) {
145 scoped_ptr<extensions::StackFrame> frame =
146 extensions::StackFrame::CreateFromText(pieces[index]);
147 if (frame.get())
148 result.push_back(*frame);
149 }
150 }
151
152 if (result.empty()) { // If we don't have a stack trace, mock one up.
153 result.push_back(
154 extensions::StackFrame(line_number,
155 1u, // column number
156 source,
157 base::string16() /* no function name */ ));
158 }
159
160 return result;
161 }
162
163 #if defined(OS_ANDROID) 105 #if defined(OS_ANDROID)
164 // Parses the DOM for a <meta> tag with a particular name. 106 // Parses the DOM for a <meta> tag with a particular name.
165 // |meta_tag_content| is set to the contents of the 'content' attribute. 107 // |meta_tag_content| is set to the contents of the 'content' attribute.
166 // |found_tag| is set to true if the tag was successfully found. 108 // |found_tag| is set to true if the tag was successfully found.
167 // Returns true if the document was parsed without errors. 109 // Returns true if the document was parsed without errors.
168 bool RetrieveMetaTagContent(const WebFrame* main_frame, 110 bool RetrieveMetaTagContent(const WebFrame* main_frame,
169 const GURL& expected_url, 111 const GURL& expected_url,
170 const std::string& meta_tag_name, 112 const std::string& meta_tag_name,
171 bool* found_tag, 113 bool* found_tag,
172 std::string* meta_tag_content) { 114 std::string* meta_tag_content) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // Don't capture pages being not new, or including refresh meta tag. 363 // Don't capture pages being not new, or including refresh meta tag.
422 if (!is_new_navigation || HasRefreshMetaTag(frame)) 364 if (!is_new_navigation || HasRefreshMetaTag(frame))
423 return; 365 return;
424 366
425 CapturePageInfoLater( 367 CapturePageInfoLater(
426 render_view()->GetPageId(), 368 render_view()->GetPageId(),
427 true, // preliminary_capture 369 true, // preliminary_capture
428 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); 370 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs));
429 } 371 }
430 372
431 void ChromeRenderViewObserver::DetailedConsoleMessageAdded(
432 const base::string16& message,
433 const base::string16& source,
434 const base::string16& stack_trace_string,
435 int32 line_number,
436 int32 severity_level) {
437 base::string16 trimmed_message = message;
438 extensions::StackTrace stack_trace = GetStackTraceFromMessage(
439 &trimmed_message,
440 source,
441 stack_trace_string,
442 line_number);
443 Send(new ChromeViewHostMsg_DetailedConsoleMessageAdded(routing_id(),
444 trimmed_message,
445 source,
446 stack_trace,
447 severity_level));
448 }
449
450 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id, 373 void ChromeRenderViewObserver::CapturePageInfoLater(int page_id,
451 bool preliminary_capture, 374 bool preliminary_capture,
452 base::TimeDelta delay) { 375 base::TimeDelta delay) {
453 capture_timer_.Start( 376 capture_timer_.Start(
454 FROM_HERE, 377 FROM_HERE,
455 delay, 378 delay,
456 base::Bind(&ChromeRenderViewObserver::CapturePageInfo, 379 base::Bind(&ChromeRenderViewObserver::CapturePageInfo,
457 base::Unretained(this), 380 base::Unretained(this),
458 page_id, 381 page_id,
459 preliminary_capture)); 382 preliminary_capture));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 WebElement element = node.to<WebElement>(); 513 WebElement element = node.to<WebElement>();
591 if (!element.hasTagName(tag_name)) 514 if (!element.hasTagName(tag_name))
592 continue; 515 continue;
593 WebString value = element.getAttribute(attribute_name); 516 WebString value = element.getAttribute(attribute_name);
594 if (value.isNull() || !LowerCaseEqualsASCII(value, "refresh")) 517 if (value.isNull() || !LowerCaseEqualsASCII(value, "refresh"))
595 continue; 518 continue;
596 return true; 519 return true;
597 } 520 }
598 return false; 521 return false;
599 } 522 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_render_view_observer.h ('k') | content/public/renderer/render_view_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698