Web Inspector: introduce UserAgent override setting.
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Nov 2011 13:22:09 +0000 (13:22 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Nov 2011 13:22:09 +0000 (13:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=71627

Patch by Pavel Feldman <pfeldman@chromium.org> on 2011-11-07
Reviewed by Yury Semikhatsky.

* English.lproj/localizedStrings.js:
* inspector/InspectorResourceAgent.cpp:
(WebCore::InspectorResourceAgent::clearFrontend):
(WebCore::InspectorResourceAgent::applyUserAgentOverride):
(WebCore::InspectorResourceAgent::setUserAgentOverride):
* inspector/front-end/HelpScreen.js:
(WebInspector.HelpScreen):
(WebInspector.HelpScreen.prototype.show):
(WebInspector.HelpScreen.prototype._onBlur):
* inspector/front-end/NetworkManager.js:
(WebInspector.NetworkManager.prototype._cacheDisabledSettingChanged):
(WebInspector.NetworkManager.prototype._userAgentSettingChanged):
* inspector/front-end/Settings.js:
(WebInspector.Settings):
* inspector/front-end/SettingsScreen.js:
(WebInspector.SettingsScreen):
(WebInspector.SettingsScreen.prototype._createSelectSetting.get for):
(WebInspector.SettingsScreen.prototype._createCustomSetting):
(WebInspector.SettingsScreen.prototype._createUserActionControl.checkboxClicked):
(WebInspector.SettingsScreen.prototype._createUserAgentSelectRowElement.get const):
(WebInspector.SettingsScreen.prototype._createUserAgentSelectRowElement.textDoubleClicked):
(WebInspector.SettingsScreen.prototype._createUserAgentSelectRowElement.textChanged):
* inspector/front-end/helpScreen.css:
(.help-table td):
(.help-content fieldset label):

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

Source/WebCore/ChangeLog
Source/WebCore/English.lproj/localizedStrings.js
Source/WebCore/inspector/InspectorResourceAgent.cpp
Source/WebCore/inspector/front-end/HelpScreen.js
Source/WebCore/inspector/front-end/NetworkManager.js
Source/WebCore/inspector/front-end/Settings.js
Source/WebCore/inspector/front-end/SettingsScreen.js
Source/WebCore/inspector/front-end/helpScreen.css

index ffde93d..7e2ecb4 100644 (file)
@@ -1,3 +1,36 @@
+2011-11-07  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: introduce UserAgent override setting.
+        https://bugs.webkit.org/show_bug.cgi?id=71627
+
+        Reviewed by Yury Semikhatsky.
+
+        * English.lproj/localizedStrings.js:
+        * inspector/InspectorResourceAgent.cpp:
+        (WebCore::InspectorResourceAgent::clearFrontend):
+        (WebCore::InspectorResourceAgent::applyUserAgentOverride):
+        (WebCore::InspectorResourceAgent::setUserAgentOverride):
+        * inspector/front-end/HelpScreen.js:
+        (WebInspector.HelpScreen):
+        (WebInspector.HelpScreen.prototype.show):
+        (WebInspector.HelpScreen.prototype._onBlur):
+        * inspector/front-end/NetworkManager.js:
+        (WebInspector.NetworkManager.prototype._cacheDisabledSettingChanged):
+        (WebInspector.NetworkManager.prototype._userAgentSettingChanged):
+        * inspector/front-end/Settings.js:
+        (WebInspector.Settings):
+        * inspector/front-end/SettingsScreen.js:
+        (WebInspector.SettingsScreen):
+        (WebInspector.SettingsScreen.prototype._createSelectSetting.get for):
+        (WebInspector.SettingsScreen.prototype._createCustomSetting):
+        (WebInspector.SettingsScreen.prototype._createUserActionControl.checkboxClicked):
+        (WebInspector.SettingsScreen.prototype._createUserAgentSelectRowElement.get const):
+        (WebInspector.SettingsScreen.prototype._createUserAgentSelectRowElement.textDoubleClicked):
+        (WebInspector.SettingsScreen.prototype._createUserAgentSelectRowElement.textChanged):
+        * inspector/front-end/helpScreen.css:
+        (.help-table td):
+        (.help-content fieldset label):
+
 2011-11-07  Alexander Pavlov  <apavlov@chromium.org>
 
         Web Inspector: autocomplete combobox for Styles sidebar and Console.
index c713f8d..6927fdb 100644 (file)
Binary files a/Source/WebCore/English.lproj/localizedStrings.js and b/Source/WebCore/English.lproj/localizedStrings.js differ
index a793630..fb21e73 100644 (file)
@@ -73,6 +73,7 @@ namespace ResourceAgentState {
 static const char resourceAgentEnabled[] = "resourceAgentEnabled";
 static const char extraRequestHeaders[] = "extraRequestHeaders";
 static const char cacheDisabled[] = "cacheDisabled";
+static const char userAgentOverride[] = "userAgentOverride";
 }
 
 void InspectorResourceAgent::setFrontend(InspectorFrontend* frontend)
@@ -85,7 +86,6 @@ void InspectorResourceAgent::clearFrontend()
     m_frontend = 0;
     ErrorString error;
     disable(&error);
-    m_userAgentOverride = "";
 }
 
 void InspectorResourceAgent::restore()
@@ -348,8 +348,9 @@ void InspectorResourceAgent::didLoadXHRSynchronously()
 
 void InspectorResourceAgent::applyUserAgentOverride(String* userAgent)
 {
-    if (!m_userAgentOverride.isEmpty())
-        *userAgent = m_userAgentOverride;
+    String userAgentOverride = m_state->getString(ResourceAgentState::userAgentOverride);
+    if (!userAgentOverride.isEmpty())
+        *userAgent = userAgentOverride;
 }
 
 void InspectorResourceAgent::willRecalculateStyle()
@@ -469,7 +470,7 @@ void InspectorResourceAgent::disable(ErrorString*)
 
 void InspectorResourceAgent::setUserAgentOverride(ErrorString*, const String& userAgent)
 {
-    m_userAgentOverride = userAgent;
+    m_state->setString(ResourceAgentState::userAgentOverride, userAgent);
 }
 
 void InspectorResourceAgent::setExtraHTTPHeaders(ErrorString*, PassRefPtr<InspectorObject> headers)
index 8f9b586..71ad221 100644 (file)
@@ -36,13 +36,13 @@ WebInspector.HelpScreen = function(title)
     this._element = document.createElement("div");
     this._element.className = "help-window-outer";
     this._element.addEventListener("keydown", this._onKeyDown.bind(this), false);
+    this._element.tabIndex = 0;
+    this._element.addEventListener("focus", this._onBlur.bind(this), false);
 
     var mainWindow = this._element.createChild("div", "help-window-main");
     var captionWindow = mainWindow.createChild("div", "help-window-caption");
     var closeButton = captionWindow.createChild("button", "help-close-button");
     this.contentElement = mainWindow.createChild("div", "help-content");
-    this.contentElement.tabIndex = 0;
-    this.contentElement.addEventListener("blur", this._onBlur.bind(this), false);
     captionWindow.createChild("h1", "help-window-title").textContent = title;
 
     closeButton.textContent = "\u2716"; // Code stands for HEAVY MULTIPLICATION X.
@@ -64,7 +64,7 @@ WebInspector.HelpScreen.prototype = {
         this._isShown = true;
         this._onHide = onHide;
         this._previousFocusElement = WebInspector.currentFocusElement();
-        WebInspector.setCurrentFocusElement(this.contentElement);
+        WebInspector.setCurrentFocusElement(this._element);
     },
 
     hide: function()
@@ -89,10 +89,10 @@ WebInspector.HelpScreen.prototype = {
         }
     },
 
-    _onBlur: function()
+    _onBlur: function(event)
     {
-         // Pretend we're modal, grab focus back if we're still shown.
-        if (this._isShown)
-            WebInspector.setCurrentFocusElement(this.contentElement);
+        // Pretend we're modal, grab focus back if we're still shown.
+        if (this._isShown && event.target !== this._element && !this._element.isAncestor(event.target))
+            WebInspector.setCurrentFocusElement(this._element);
     }
 }
index 45944bf..71f46a6 100644 (file)
@@ -40,7 +40,11 @@ WebInspector.NetworkManager = function()
         NetworkAgent.setCacheDisabled(true);
     NetworkAgent.enable();
 
-    WebInspector.settings.cacheDisabled.addChangeListener(this._cacheDisabledSettingChanged.bind(this));
+    WebInspector.settings.cacheDisabled.addChangeListener(this._cacheDisabledSettingChanged, this);
+
+    if (WebInspector.settings.userAgent.get())
+        this._userAgentSettingChanged();
+    WebInspector.settings.userAgent.addChangeListener(this._userAgentSettingChanged, this);
 }
 
 WebInspector.NetworkManager.EventTypes = {
@@ -75,6 +79,11 @@ WebInspector.NetworkManager.prototype = {
     _cacheDisabledSettingChanged: function(event)
     {
         NetworkAgent.setCacheDisabled(event.data);
+    },
+
+    _userAgentSettingChanged: function()
+    {
+        NetworkAgent.setUserAgentOverride(WebInspector.settings.userAgent.get());
     }
 }
 
index b2abadf..d6ad8d2 100644 (file)
@@ -90,6 +90,8 @@ WebInspector.Settings = function()
     this.xhrBreakpoints = this.createSetting("xhrBreakpoints", []);
     this.workerInspectionEnabled = this.createSetting("workerInspectionEnabled", []);
     this.cacheDisabled = this.createSetting("cacheDisabled", false);
+    this.overrideUserAgent = this.createSetting("overrideUserAgent", "");
+    this.userAgent = this.createSetting("userAgent", "");
     this.showScriptFolders = this.createSetting("showScriptFolders", true);
 
     // If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
index 7d9bfa1..4ecda02 100644 (file)
@@ -52,15 +52,16 @@ WebInspector.SettingsScreen = function()
 
     p = this._appendSection(WebInspector.UIString("Text editor"));
     p.appendChild(this._createSelectSetting(WebInspector.UIString("Indent"), [
-        [ WebInspector.TextEditorModel.Indent.TwoSpaces, WebInspector.UIString("2 spaces") ],
-        [ WebInspector.TextEditorModel.Indent.FourSpaces, WebInspector.UIString("4 spaces") ],
-        [ WebInspector.TextEditorModel.Indent.EightSpaces, WebInspector.UIString("8 spaces") ],
-        [ WebInspector.TextEditorModel.Indent.TabCharacter, WebInspector.UIString("Tab character") ] ], WebInspector.settings.textEditorIndent));
+            [ WebInspector.UIString("2 spaces"), WebInspector.TextEditorModel.Indent.TwoSpaces ],
+            [ WebInspector.UIString("4 spaces"), WebInspector.TextEditorModel.Indent.FourSpaces ],
+            [ WebInspector.UIString("8 spaces"), WebInspector.TextEditorModel.Indent.EightSpaces ],
+            [ WebInspector.UIString("Tab character"), WebInspector.TextEditorModel.Indent.TabCharacter ]
+        ], WebInspector.settings.textEditorIndent));
 
-    if (Preferences.canDisableCache) {
-        p = this._appendSection(WebInspector.UIString("Network"), true);
+    p = this._appendSection(WebInspector.UIString("Network"), true);
+    if (Preferences.canDisableCache)
         p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Disable cache"), WebInspector.settings.cacheDisabled));
-    }
+    p.appendChild(this._createUserActionControl());
 
     p = this._appendSection(WebInspector.UIString("Scripts"), true);
     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show script folders"), WebInspector.settings.showScriptFolders));
@@ -129,17 +130,16 @@ WebInspector.SettingsScreen.prototype = {
     _createSelectSetting: function(name, options, setting)
     {
         var fieldsetElement = document.createElement("fieldset");
-        fieldsetElement.textContent = name;
+        fieldsetElement.createChild("label").textContent = name;
 
         var select = document.createElement("select");
         var settingValue = setting.get();
 
         for (var i = 0; i < options.length; ++i) {
             var option = options[i];
-            select.add(new Option(option[1], option[0]));
-            if (settingValue === option[0])
+            select.add(new Option(option[0], option[1]));
+            if (settingValue === option[1])
                 select.selectedIndex = i;
-
         }
 
         function changeListener(e)
@@ -196,11 +196,121 @@ WebInspector.SettingsScreen.prototype = {
     {
         var p = document.createElement("p");
         var fieldsetElement = document.createElement("fieldset");
-        fieldsetElement.textContent = name;
+        fieldsetElement.createChild("label").textContent = name;
         fieldsetElement.appendChild(element);
         p.appendChild(fieldsetElement);
         return p;
+    },
+
+    _createUserActionControl: function()
+    {
+        var userAgent = WebInspector.settings.userAgent.get();
+
+        var p = document.createElement("p");
+        var labelElement = p.createChild("label");
+        var checkboxElement = labelElement.createChild("input");
+        checkboxElement.type = "checkbox";
+        checkboxElement.checked = !!userAgent;
+        checkboxElement.addEventListener("click", checkboxClicked.bind(this), false);
+        labelElement.appendChild(document.createTextNode("Override User Agent"));
+
+        var selectSectionElement;
+        function checkboxClicked()
+        {
+            if (checkboxElement.checked) {
+                selectSectionElement = this._createUserAgentSelectRowElement();
+                p.appendChild(selectSectionElement);
+            } else {
+                if (selectSectionElement) {
+                    p.removeChild(selectSectionElement);
+                    selectSectionElement = null;
+                }
+                WebInspector.settings.userAgent.set("");
+            }
+        }
+
+        checkboxClicked.call(this);
+        return p;
+    },
+
+    _createUserAgentSelectRowElement: function()
+    {
+        var userAgent = WebInspector.settings.userAgent.get();
+        const userAgents = [
+            ["Internet Explorer 9", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0"],
+            ["Internet Explorer 8", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0"],
+            ["Internet Explorer 7", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0"],
+
+            ["Firefox 7 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"],
+            ["Firefox 7 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"],
+            ["Firefox 4 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"],
+            ["Firefox 4 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"],
+
+            ["iPhone \u2014 iOS 5", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"],
+            ["iPhone \u2014 iOS 4", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5"],
+            ["iPad \u2014 iOS 5", "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"],
+            ["iPad \u2014 iOS 4", "Mozilla/5.0 (iPad; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5"],
+
+            ["Android 2.3 \u2014 Nexus S", "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"],
+            [WebInspector.UIString("Other..."), "Other"]
+        ];
+
+        var fieldsetElement = document.createElement("fieldset");
+        var selectElement = fieldsetElement.createChild("select");
+        var otherUserAgentElement = fieldsetElement.createChild("input");
+        otherUserAgentElement.value = userAgent;
+        otherUserAgentElement.title = userAgent;
+
+        var selectionRestored = false;
+        for (var i = 0; i < userAgents.length; ++i) {
+            var agent = userAgents[i];
+            selectElement.add(new Option(agent[0], agent[1]));
+            if (userAgent === agent[1]) {
+                selectElement.selectedIndex = i;
+                selectionRestored = true;
+            }
+        }
+
+        if (!selectionRestored) {
+            if (!userAgent)
+                selectElement.selectedIndex = 0;
+            else
+                selectElement.selectedIndex = userAgents.length - 1;
+        }
+
+        selectElement.addEventListener("change", selectionChanged.bind(this), false);
+
+        function selectionChanged()
+        {
+            var value = selectElement.options[selectElement.selectedIndex].value;
+            if (value !== "Other") {
+                WebInspector.settings.userAgent.set(value);
+                otherUserAgentElement.value = value;
+                otherUserAgentElement.title = value;
+                otherUserAgentElement.disabled = true;
+            } else {
+                otherUserAgentElement.disabled = false;
+                otherUserAgentElement.focus();
+            }
+        }
+
+        fieldsetElement.addEventListener("dblclick", textDoubleClicked.bind(this), false);
+        otherUserAgentElement.addEventListener("blur", textChanged.bind(this), false);
+
+        function textDoubleClicked()
+        {
+            selectElement.selectedIndex = userAgents.length - 1;
+            selectionChanged.call(this);
+        }
+
+        function textChanged()
+        {
+            WebInspector.settings.userAgent.set(otherUserAgentElement.value);
+        }
+
+        selectionChanged.call(this);
+        return fieldsetElement;
     }
-};
+}
 
 WebInspector.SettingsScreen.prototype.__proto__ = WebInspector.HelpScreen.prototype;
index f69cd21..948f0ef 100644 (file)
@@ -130,6 +130,7 @@ body:not(.platform-mac) .help-close-button {
 .help-table td {
     white-space: nowrap;
     vertical-align: top;
+    width: 50%;
 }
 
 .help-key-cell {
@@ -174,6 +175,11 @@ body.platform-mac .help-key {
     padding-left: 3px;
 }
 
+
+.help-content fieldset label {
+    padding-right: 4px;
+}
+
 .help-content p.help-section {
     margin-bottom: 15px;
 }
@@ -190,7 +196,6 @@ body.platform-mac .help-key {
 }
 
 .help-content select {
-    margin-left: 1em;
     background-color: rgb(64, 64, 64);
     color: white;
     border-color: black;