MiniBrowser window title is just "Window" when page has no <title>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Jul 2015 03:37:47 +0000 (03:37 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Jul 2015 03:37:47 +0000 (03:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147076

Reviewed by Tim Horton.

Make MiniBrowser windows show the filename from the URL if we never get a title changed
notification.

* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController updateTitle:]):
(-[WK1BrowserWindowController webView:didCommitLoadForFrame:]):
(-[WK1BrowserWindowController webView:didReceiveTitle:forFrame:]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController updateTitle:]):
(-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]):
(-[WK2BrowserWindowController webView:didCommitNavigation:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187007 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/MiniBrowser/mac/WK1BrowserWindowController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m

index 653bf2b..9b23184 100644 (file)
@@ -1,3 +1,22 @@
+2015-07-18  Simon Fraser  <simon.fraser@apple.com>
+
+        MiniBrowser window title is just "Window" when page has no <title>
+        https://bugs.webkit.org/show_bug.cgi?id=147076
+
+        Reviewed by Tim Horton.
+        
+        Make MiniBrowser windows show the filename from the URL if we never get a title changed
+        notification.
+
+        * MiniBrowser/mac/WK1BrowserWindowController.m:
+        (-[WK1BrowserWindowController updateTitle:]):
+        (-[WK1BrowserWindowController webView:didCommitLoadForFrame:]):
+        (-[WK1BrowserWindowController webView:didReceiveTitle:forFrame:]):
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController updateTitle:]):
+        (-[WK2BrowserWindowController observeValueForKeyPath:ofObject:change:context:]):
+        (-[WK2BrowserWindowController webView:didCommitNavigation:]):
+
 2015-07-17  Andy Estes  <aestes@apple.com>
 
         [iOS] Further tighten the sandbox around pages fetched with Content-Disposition: attachment
index 103d626..cffd7fb 100644 (file)
 {
 }
 
+- (void)updateTitle:(NSString *)title
+{
+    if (!title) {
+        NSURL *url = _webView.mainFrame.dataSource.request.URL;
+        title = url.lastPathComponent;
+    }
+    
+    [self.window setTitle:[title stringByAppendingString:@" [WK1]"]];
+}
+
 - (void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
 {
     if (frame != [sender mainFrame])
 
     NSURL *committedURL = [[[frame dataSource] request] URL];
     [urlText setStringValue:[committedURL absoluteString]];
+
+    [self updateTitle:nil];
 }
 
 - (void)webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame
     if (frame != [sender mainFrame])
         return;
 
-    [self.window setTitle:[title stringByAppendingString:@" [WK1]"]];
+    [self updateTitle:title];
 }
 
 - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
index c8e8f95..7d29eeb 100644 (file)
@@ -371,13 +371,21 @@ static CGFloat viewScaleForMenuItemTag(NSInteger tag)
     preferences._visibleDebugOverlayRegions = visibleOverlayRegions;
 }
 
+- (void)updateTitle:(NSString *)title
+{
+    if (!title)
+        title = _webView.URL.lastPathComponent;
+    
+    self.window.title = [NSString stringWithFormat:@"%@%@ [WK2 %d]", _isPrivateBrowsingWindow ? @"🙈 " : @"", title, _webView._webProcessIdentifier];
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
     if (context != keyValueObservingContext || object != _webView)
         return;
 
     if ([keyPath isEqualToString:@"title"])
-        self.window.title = [NSString stringWithFormat:@"%@%@ [WK2 %d]", _isPrivateBrowsingWindow ? @"🙈 " : @"", _webView.title, _webView._webProcessIdentifier];
+        [self updateTitle:_webView.title];
     else if ([keyPath isEqualToString:@"URL"])
         [self updateTextFieldFromURL:_webView.URL];
 }
@@ -516,6 +524,7 @@ static NSSet *dataTypes()
 - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
 {
     LOG(@"didCommitNavigation: %@", navigation);
+    [self updateTitle:nil];
 }
 
 - (void)webView:(WKWebView *)webView didFinishLoadingNavigation:(WKNavigation *)navigation