Title: [138565] trunk/Source/WebKit/mac
Revision
138565
Author
[email protected]
Date
2012-12-29 08:14:21 -0800 (Sat, 29 Dec 2012)

Log Message

Web Inspector: Mac WK1 Inspector can't save/load timeline data
https://bugs.webkit.org/show_bug.cgi?id=105547

Reviewed by Pavel Feldman.

* WebCoreSupport/WebInspectorClient.h: Declared new overrides and
member variables necessary for save support.

* WebCoreSupport/WebInspectorClient.mm:
(WebInspectorFrontendClient::save):
(WebInspectorFrontendClient::append):
Implemented these to make saving timeline data work. (It seems to me
the InspectorFrontendClient API could be cleaned up a bit. I had to
look at Chromium source code to determine that I needed to call back
into the InspectorFrontendAPI JS object after saving/appending, and
that I needed to keep a map of passed URLs -> chosen URLs.)

(-[WebInspectorWindowController window:willPositionSheet:usingRect:]):
Tweaked the position of the sheet so that open/save sheets look a
little bette.r

(-[WebInspectorWindowController webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:]):
Implemented to make loading timeline data work.

Modified Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (138564 => 138565)


--- trunk/Source/WebKit/mac/ChangeLog	2012-12-29 12:41:05 UTC (rev 138564)
+++ trunk/Source/WebKit/mac/ChangeLog	2012-12-29 16:14:21 UTC (rev 138565)
@@ -1,3 +1,29 @@
+2012-12-29  Adam Roben  <[email protected]>
+
+        Web Inspector: Mac WK1 Inspector can't save/load timeline data
+        https://bugs.webkit.org/show_bug.cgi?id=105547
+
+        Reviewed by Pavel Feldman.
+
+        * WebCoreSupport/WebInspectorClient.h: Declared new overrides and
+        member variables necessary for save support.
+
+        * WebCoreSupport/WebInspectorClient.mm:
+        (WebInspectorFrontendClient::save):
+        (WebInspectorFrontendClient::append):
+        Implemented these to make saving timeline data work. (It seems to me
+        the InspectorFrontendClient API could be cleaned up a bit. I had to
+        look at Chromium source code to determine that I needed to call back
+        into the InspectorFrontendAPI JS object after saving/appending, and
+        that I needed to keep a map of passed URLs -> chosen URLs.)
+
+        (-[WebInspectorWindowController window:willPositionSheet:usingRect:]):
+        Tweaked the position of the sheet so that open/save sheets look a
+        little bette.r
+
+        (-[WebInspectorWindowController webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:]):
+        Implemented to make loading timeline data work.
+
 2012-12-28  Mark Rowe  <[email protected]>
 
         Move logic for extracting the OS X marketing version in to WebCore

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h (138564 => 138565)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h	2012-12-29 12:41:05 UTC (rev 138564)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h	2012-12-29 16:14:21 UTC (rev 138565)
@@ -37,10 +37,12 @@
 #import <wtf/text/WTFString.h>
 
 #ifdef __OBJC__
+@class NSURL;
 @class WebInspectorWindowController;
 @class WebNodeHighlighter;
 @class WebView;
 #else
+class NSURL;
 class WebInspectorWindowController;
 class WebNodeHighlighter;
 class WebView;
@@ -110,7 +112,12 @@
 private:
     void updateWindowTitle() const;
 
+    virtual bool canSave() OVERRIDE { return true; }
+    virtual void save(const String& url, const String& content, bool forceSaveAs) OVERRIDE;
+    virtual void append(const String& url, const String& content) OVERRIDE;
+
     WebView* m_inspectedWebView;
     RetainPtr<WebInspectorWindowController> m_windowController;
     String m_inspectedURL;
+    HashMap<String, RetainPtr<NSURL>> m_saveURLs;
 };

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm (138564 => 138565)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm	2012-12-29 12:41:05 UTC (rev 138564)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm	2012-12-29 16:14:21 UTC (rev 138565)
@@ -40,8 +40,10 @@
 #import "WebUIDelegate.h"
 #import "WebPolicyDelegate.h"
 #import "WebViewInternal.h"
+#import <WebCore/Frame.h>
 #import <WebCore/InspectorController.h>
 #import <WebCore/Page.h>
+#import <WebCore/ScriptValue.h>
 #import <WebCore/SoftLinking.h>
 #import <WebKit/DOMExtensions.h>
 #import <WebKitSystemInterface.h>
@@ -294,7 +296,51 @@
     [[m_windowController.get() window] setTitle:title];
 }
 
+void WebInspectorFrontendClient::save(const String& refURL, const String& refContent, bool forceSaveAs)
+{
+    String url = ""
+    String content = refContent;
+    auto saveToURL = ^(NSURL *URL) {
+        m_saveURLs.set(url, URL);
 
+        [content writeToURL:URL atomically:YES encoding:NSUTF8StringEncoding error:NULL];
+        core([m_windowController webView])->mainFrame()->script()->executeScript([NSString stringWithFormat:@"InspectorFrontendAPI.savedURL(\"%@\")", URL.absoluteString]);
+    };
+
+    NSURL *URL = ""
+    if (!URL)
+        URL = "" URLWithString:url];
+    else if (!forceSaveAs) {
+        saveToURL(URL);
+        return;
+    }
+
+    NSSavePanel *panel = [NSSavePanel savePanel];
+    panel.nameFieldStringValue = URL.lastPathComponent;
+    panel.directoryURL = [URL URLByDeletingLastPathComponent];
+
+    [panel beginSheetModalForWindow:[[m_windowController webView] window] completionHandler:^(NSInteger result) {
+        if (result == NSFileHandlingPanelCancelButton)
+            return;
+        ASSERT(result == NSFileHandlingPanelOKButton);
+        saveToURL(panel.URL);
+    }];
+}
+
+void WebInspectorFrontendClient::append(const String& url, const String& content)
+{
+    RetainPtr<NSURL> URL = ""
+    if (!URL)
+        URL = "" URLWithString:url];
+
+    NSFileHandle *handle = [NSFileHandle fileHandleForWritingToURL:URL.get() error:NULL];
+    [handle seekToEndOfFile];
+    [handle writeData:[content dataUsingEncoding:NSUTF8StringEncoding]];
+    [handle closeFile];
+
+    core([m_windowController webView])->mainFrame()->script()->executeScript([NSString stringWithFormat:@"InspectorFrontendAPI.appendedToURL(\"%@\")", [URL absoluteString]]);
+}
+
 // MARK: -
 
 @implementation WebInspectorWindowController
@@ -436,6 +482,14 @@
 
 // MARK: -
 
+- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect
+{
+    // AppKit doesn't know about our HTML toolbar, and places the sheet just a little bit too high.
+    // FIXME: It would be better to get the height of the toolbar and use it in this calculation.
+    rect.origin.y -= 1;
+    return rect;
+}
+
 - (BOOL)windowShouldClose:(id)sender
 {
     [self destroyInspectorView:true];
@@ -616,6 +670,29 @@
     return WebDragDestinationActionNone;
 }
 
+- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener allowMultipleFiles:(BOOL)allowMultipleFiles
+{
+    NSOpenPanel *panel = [NSOpenPanel openPanel];
+    panel.canChooseDirectories = NO;
+    panel.canChooseFiles = YES;
+    panel.allowsMultipleSelection = allowMultipleFiles;
+
+    [panel beginSheetModalForWindow:_webView.window completionHandler:^(NSInteger result) {
+        if (result == NSFileHandlingPanelCancelButton) {
+            [resultListener cancel];
+            return;
+        }
+        ASSERT(result == NSFileHandlingPanelOKButton);
+
+        NSArray *URLs = panel.URLs;
+        NSMutableArray *filenames = [NSMutableArray arrayWithCapacity:URLs.count];
+        for (NSURL *URL in URLs) {
+            [filenames addObject:URL.path];
+        }
+        [resultListener chooseFilenames:filenames];
+    }];
+}
+
 // MARK: -
 // MARK: Policy delegate
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to