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

Side by Side Diff: ios/web/web_state/ui/crw_debug_web_view.mm

Issue 1048613002: Upstream ios/web/web_state/ui support classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #if !defined(NDEBUG)
5 #import "ios/web/web_state/ui/crw_debug_web_view.h"
6
7 #include "base/mac/scoped_nsobject.h"
8
9 // These categories define private API in iOS, in reality part of WebKit.
10 @interface NSObject (CRWDebugWebView_WebScriptCallFrame_methods)
11 - (id)functionName;
12 - (id)caller;
13 - (id)exception;
14 @end
15
16 @interface NSObject (CRWDebugWebView_WebView_methods)
17 - (void)setScriptDebugDelegate:
18 (id<CRWDebugWebView_WebViewScriptDelegate>)delegate;
19 @end
20
21 @interface NSObject (CRWDebugWebView_WebScriptObject_methods)
22 - (id)callWebScriptMethod:(NSString*)name withArguments:(NSArray*)args;
23 @end
24
25 #pragma mark -
26
27 // The debug implementation of the webscript delegate.
28 @interface CRWDebugWebDelegate :
29 NSObject<CRWDebugWebView_WebViewScriptDelegate> {
30 base::scoped_nsobject<NSMutableDictionary> _sidsToURLs;
31 }
32 @end
33
34 @implementation CRWDebugWebDelegate
35
36 - (id)init {
37 if ((self = [super init])) {
38 _sidsToURLs.reset([[NSMutableDictionary alloc] init]);
39 }
40 return self;
41 }
42
43 - (void)webView:(WebView*)webView addMessageToConsole:(NSDictionary*)dict {
44 NSLog(@"JS: %@", dict);
45 }
46
47 - (void)webView:(WebView *)webView didParseSource:(NSString*)source
Eugene But (OOO till 7-30) 2015/03/30 05:03:58 NIT: No space before *
stuartmorgan 2015/03/30 14:17:57 Done.
48 baseLineNumber:(NSUInteger)lineNumber
49 fromURL:(NSURL*)url
50 sourceId:(int)sid
51 forWebFrame:(WebFrame*)webFrame {
52 if (url && sid)
53 [_sidsToURLs setObject:url forKey:[NSNumber numberWithInt:sid]];
54 }
55
56 - (void)webView:(WebView*)webView
57 failedToParseSource:(NSString*)source
58 baseLineNumber:(unsigned)lineNumber
59 fromURL:(NSURL*)url
60 withError:(NSError*)error
61 forWebFrame:(WebFrame*)webFrame {
62 NSLog(@"JS Failed to parse: url=%@ line=%d error=%@\nsource=%@",
63 url, lineNumber, error, source);
64 }
65
66 - (void)webView:(WebView*)webView
67 exceptionWasRaised:(WebScriptCallFrame*)frame
68 sourceId:(int)sid
69 line:(int)lineno
70 forWebFrame:(WebFrame*)webFrame {
71 NSURL* url = [_sidsToURLs objectForKey:[NSNumber numberWithInt:sid]];
72 id representation = [frame exception];
73 if ([representation isKindOfClass:NSClassFromString(@"WebScriptObject")]) {
74 representation = [representation callWebScriptMethod:@"toString"
75 withArguments:nil];
76 }
77 base::scoped_nsobject<NSMutableArray> message([[NSMutableArray alloc] init]);
78
79 [message addObject:
80 [NSString stringWithFormat:@"JS Exception: sid=%d url=%@ exception=%@",
81 sid, url, representation]];
82
83 if ([frame respondsToSelector:@selector(caller)]) {
84 while (frame) {
85 frame = [frame caller];
86 [message addObject:[NSString stringWithFormat:@"line=%d function=%@",
87 lineno, [frame functionName]]];
88 }
89 }
90
91 NSLog(@"%@", [message componentsJoinedByString:@"\n\t"]);
92 }
93
94 @end
95
96 #pragma mark -
97
98 @implementation CRWDebugWebView {
99 base::scoped_nsobject<CRWDebugWebDelegate> _webDelegate;
100 }
101
102 - (void)webView:(id)sender
103 didClearWindowObject:(id)windowObject
104 forFrame:(WebFrame*)frame {
105 if (!_webDelegate)
106 _webDelegate.reset([[CRWDebugWebDelegate alloc] init]);
107 [sender setScriptDebugDelegate:_webDelegate];
108 }
109
110 @end
111
112 #endif // !defined(NDEBUG)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698