Fix <rdar://5192578> Inspect Element should not appear in context menu in non-debug...
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2007 02:00:40 +0000 (02:00 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 18 Aug 2007 02:00:40 +0000 (02:00 +0000)
        We now follow the same logic as Mac WebKit for displaying the Inspect Element item:
            1) If DisableWebKitDeveloperExtras is set to true, don't display it
            2) If not, and we're in a debug build, display it
            3) If not, and we're in a release build, display it if
               WebKitDeveloperExtras is set to true

        Reviewed by Ada.

        * Interfaces/IWebPreferencesPrivate.idl: Added.
        * WebKit.vcproj/Interfaces.vcproj: Add new IWebPreferencesPrivate.idl
        file to project.
        * WebKit.vcproj/WebKitGUID.vcproj: Added generated .c file for
        IWebPreferencesPrivate to project.
        * WebPreferenceKeysPrivate.h: Added new keys.
        * WebPreferences.cpp: Added IID_WebPreferences.
        (WebPreferences::postPreferencesChangesNotification): Added an explicit
        cast needed now that WebPreferences implements two interfaces.
        (WebPreferences::QueryInterface): Added new cases.
        (WebPreferences::setDeveloperExtrasEnabled): Added.
        (WebPreferences::developerExtrasEnabled): Added.
        (WebPreferences::developerExtrasDisabledByOverride): Added.
        * WebPreferences.h: Now implements IWebPreferencesPrivate.
        * WebView.cpp:
        (WebView::updateWebCoreSettingsFromPreferences): Call developerExtrasEnabled.
        (WebView::developerExtrasEnabled): Ported from -[WebView _developerExtrasEnabled].
        * WebView.h:

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

WebKit/win/ChangeLog
WebKit/win/Interfaces/IWebPreferencesPrivate.idl [new file with mode: 0644]
WebKit/win/WebKit.vcproj/Interfaces.vcproj
WebKit/win/WebKit.vcproj/WebKitGUID.vcproj
WebKit/win/WebPreferenceKeysPrivate.h
WebKit/win/WebPreferences.cpp
WebKit/win/WebPreferences.h
WebKit/win/WebView.cpp
WebKit/win/WebView.h

index 5171838..986e528 100644 (file)
@@ -1,5 +1,36 @@
 2007-08-17  Adam Roben  <aroben@apple.com>
 
+        Fix <rdar://5192578> Inspect Element should not appear in context menu in non-debug mode
+
+        We now follow the same logic as Mac WebKit for displaying the Inspect Element item:
+            1) If DisableWebKitDeveloperExtras is set to true, don't display it
+            2) If not, and we're in a debug build, display it
+            3) If not, and we're in a release build, display it if
+               WebKitDeveloperExtras is set to true
+
+        Reviewed by Ada.
+
+        * Interfaces/IWebPreferencesPrivate.idl: Added.
+        * WebKit.vcproj/Interfaces.vcproj: Add new IWebPreferencesPrivate.idl
+        file to project.
+        * WebKit.vcproj/WebKitGUID.vcproj: Added generated .c file for
+        IWebPreferencesPrivate to project.
+        * WebPreferenceKeysPrivate.h: Added new keys.
+        * WebPreferences.cpp: Added IID_WebPreferences.
+        (WebPreferences::postPreferencesChangesNotification): Added an explicit
+        cast needed now that WebPreferences implements two interfaces.
+        (WebPreferences::QueryInterface): Added new cases.
+        (WebPreferences::setDeveloperExtrasEnabled): Added.
+        (WebPreferences::developerExtrasEnabled): Added.
+        (WebPreferences::developerExtrasDisabledByOverride): Added.
+        * WebPreferences.h: Now implements IWebPreferencesPrivate.
+        * WebView.cpp:
+        (WebView::updateWebCoreSettingsFromPreferences): Call developerExtrasEnabled.
+        (WebView::developerExtrasEnabled): Ported from -[WebView _developerExtrasEnabled].
+        * WebView.h:
+
+2007-08-17  Adam Roben  <aroben@apple.com>
+
         Add WebPreferences::sharedStandardPreferences
 
         This is a convenience method to get the standard preferences object so
diff --git a/WebKit/win/Interfaces/IWebPreferencesPrivate.idl b/WebKit/win/Interfaces/IWebPreferencesPrivate.idl
new file mode 100644 (file)
index 0000000..676011a
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+cpp_quote("/*")
+cpp_quote(" * Copyright (C) 2007 Apple Inc.  All rights reserved.")
+cpp_quote(" *")
+cpp_quote(" * Redistribution and use in source and binary forms, with or without")
+cpp_quote(" * modification, are permitted provided that the following conditions")
+cpp_quote(" * are met:")
+cpp_quote(" *")
+cpp_quote(" * 1.  Redistributions of source code must retain the above copyright")
+cpp_quote(" *     notice, this list of conditions and the following disclaimer. ")
+cpp_quote(" * 2.  Redistributions in binary form must reproduce the above copyright")
+cpp_quote(" *     notice, this list of conditions and the following disclaimer in the")
+cpp_quote(" *     documentation and/or other materials provided with the distribution. ")
+cpp_quote(" * 3.  Neither the name of Apple Computer, Inc. (\"Apple\") nor the names of")
+cpp_quote(" *     its contributors may be used to endorse or promote products derived")
+cpp_quote(" *     from this software without specific prior written permission. ")
+cpp_quote(" *")
+cpp_quote(" * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS \"AS IS\" AND ANY")
+cpp_quote(" * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED")
+cpp_quote(" * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE")
+cpp_quote(" * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY")
+cpp_quote(" * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES")
+cpp_quote(" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;")
+cpp_quote(" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND")
+cpp_quote(" * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT")
+cpp_quote(" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF")
+cpp_quote(" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.")
+cpp_quote(" */")
+
+import "oaidl.idl";
+import "ocidl.idl";
+
+[
+    object,
+    oleautomation,
+    hidden,
+    uuid(1380DE41-42CF-4170-9D5D-7840EDE5B36C),
+    pointer_default(unique)
+]
+interface IWebPreferencesPrivate : IUnknown
+{
+    HRESULT setDeveloperExtrasEnabled([in] BOOL enabled);
+    HRESULT developerExtrasEnabled([out, retval] BOOL* enabled);
+}
index 2060cf8..6b4da1b 100644 (file)
                        >
                </File>
                <File
+                       RelativePath="..\Interfaces\IWebPreferencesPrivate.idl"
+                       >
+               </File>
+               <File
                        RelativePath="..\Interfaces\IWebResource.idl"
                        >
                </File>
index cb25608..cee7d1b 100644 (file)
                        RelativePath="$(WebKitOutputDir)\obj\WebKit\Interfaces\IWebDataSource_i.c"
                        >
                </File>
-    <File
+               <File
                        RelativePath="$(WebKitOutputDir)\obj\WebKit\Interfaces\IWebDebugProgram_i.c"
                        >
-    </File>
-    <File
+               </File>
+               <File
                        RelativePath="$(WebKitOutputDir)\obj\WebKit\Interfaces\IWebDocument_i.c"
                        >
                </File>
                        >
                </File>
                <File
+                       RelativePath="$(WebKitOutputDir)\obj\WebKit\Interfaces\IWebPreferencesPrivate_i.c"
+                       >
+               </File>
+               <File
                        RelativePath="$(WebKitOutputDir)\obj\WebKit\Interfaces\IWebResource_i.c"
                        >
                </File>
index 54caa7e..44d2789 100644 (file)
@@ -96,3 +96,6 @@
 
 // If this key is present and has a value of true, we have already removed the default values from the user's preferences <rdar://problem/5214504>
 #define WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey "WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey"
+
+#define WebKitDeveloperExtrasEnabledPreferenceKey "WebKitDeveloperExtras"
+#define DisableWebKitDeveloperExtrasPreferenceKey "DisableWebKitDeveloperExtras"
index a4f4c2c..afb1c70 100644 (file)
 #include <wtf/OwnPtr.h>
 #include <wtf/Vector.h>
 
+#include <initguid.h>
+// {A20B5645-692D-4147-BF80-E8CD84BE82A1}
+DEFINE_GUID(IID_WebPreferences, 0xa20b5645, 0x692d, 0x4147, 0xbf, 0x80, 0xe8, 0xcd, 0x84, 0xbe, 0x82, 0xa1);
+
 static unsigned long long WebSystemMainMemory()
 {
     MEMORYSTATUSEX statex;
@@ -96,7 +100,7 @@ WebPreferences* WebPreferences::createInstance()
 HRESULT WebPreferences::postPreferencesChangesNotification()
 {
     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
-    HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), this, 0);
+    HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), static_cast<IWebPreferences*>(this), 0);
     if (FAILED(hr))
         return hr;
 
@@ -550,6 +554,10 @@ HRESULT STDMETHODCALLTYPE WebPreferences::QueryInterface(REFIID riid, void** ppv
         *ppvObject = static_cast<IWebPreferences*>(this);
     else if (IsEqualGUID(riid, IID_IWebPreferences))
         *ppvObject = static_cast<IWebPreferences*>(this);
+    else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate))
+        *ppvObject = static_cast<IWebPreferencesPrivate*>(this);
+    else if (IsEqualGUID(riid, IID_WebPreferences))
+        *ppvObject = static_cast<WebPreferences*>(this);
     else
         return E_NOINTERFACE;
 
@@ -1148,3 +1156,23 @@ HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
     setBoolValue(CFSTR(WebKitDOMPasteAllowedPreferenceKey), enabled);
     return S_OK;
 }
+
+HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
+{
+    setBoolValue(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey), enabled);
+    return S_OK;
+}
+
+HRESULT WebPreferences::developerExtrasEnabled(BOOL* enabled)
+{
+    if (!enabled)
+        return E_POINTER;
+
+    *enabled = boolValueForKey(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey));
+    return S_OK;
+}
+
+bool WebPreferences::developerExtrasDisabledByOverride()
+{
+    return !!boolValueForKey(CFSTR(DisableWebKitDeveloperExtrasPreferenceKey));
+}
index 06528b2..20d4135 100644 (file)
 #define WebPreferences_H
 
 #include "IWebPreferences.h"
+#include "IWebPreferencesPrivate.h"
 #include <CoreFoundation/CoreFoundation.h>
 #include <WebCore/BString.h>
 #include <wtf/RetainPtr.h>
 
-class WebPreferences : public IWebPreferences {
+// {A20B5645-692D-4147-BF80-E8CD84BE82A1}
+DEFINE_GUID(IID_WebPreferences, 0xa20b5645, 0x692d, 0x4147, 0xbf, 0x80, 0xe8, 0xcd, 0x84, 0xbe, 0x82, 0xa1);
+
+class WebPreferences : public IWebPreferences, public IWebPreferencesPrivate {
 public:
     static WebPreferences* createInstance();
 protected:
@@ -271,7 +275,20 @@ public:
     virtual HRESULT STDMETHODCALLTYPE setDOMPasteAllowed( 
         /* [in] */ BOOL enabled);
 
+    // IWebPreferencesPrivate
+    virtual HRESULT STDMETHODCALLTYPE setDeveloperExtrasEnabled(
+        /* [in] */ BOOL);
+
+    virtual HRESULT STDMETHODCALLTYPE developerExtrasEnabled(
+        /* [retval][out] */ BOOL*);
+
+
     // WebPreferences
+
+    // This method accesses a different preference key than developerExtrasEnabled.
+    // See <rdar://5343767> for the justification.
+    bool developerExtrasDisabledByOverride();
+
     static BSTR webPreferencesChangedNotification();
     static void setInstance(WebPreferences* instance, BSTR identifier);
     static void removeReferenceForIdentifier(BSTR identifier);
index b444a2b..f95f21d 100644 (file)
@@ -1520,15 +1520,28 @@ HRESULT WebView::updateWebCoreSettingsFromPreferences(IWebPreferences* preferenc
 
     settings->setForceFTPDirectoryListings(true);
 
-    // FIXME: make this read a preference like the Mac's WebKitDeveloperExtras
-    // or when Safari's IncludeDebugMenu is set
-    settings->setDeveloperExtrasEnabled(true);
+    settings->setDeveloperExtrasEnabled(developerExtrasEnabled());
 
     m_mainFrame->invalidate(); // FIXME
 
     return S_OK;
 }
 
+bool WebView::developerExtrasEnabled() const
+{
+    COMPtr<WebPreferences> webPrefs;
+    if (SUCCEEDED(m_preferences->QueryInterface(IID_WebPreferences, (void**)&webPrefs)) && webPrefs->developerExtrasDisabledByOverride())
+        return false;
+
+#ifdef NDEBUG
+    BOOL enabled = FALSE;
+    COMPtr<IWebPreferencesPrivate> prefsPrivate;
+    return SUCCEEDED(m_preferences->QueryInterface(&prefsPrivate)) && SUCCEEDED(prefsPrivate->developerExtrasEnabled(&enabled)) && enabled;
+#else
+    return true;
+#endif
+}
+
 static String osVersion()
 {
     String osVersion;
index 059019e..12bdea0 100644 (file)
@@ -681,6 +681,7 @@ protected:
     void updateSelectionForIME();
     bool onIMERequestCharPosition(WebCore::Frame*, IMECHARPOSITION*, LRESULT*);
     bool onIMERequestReconvertString(WebCore::Frame*, RECONVERTSTRING*, LRESULT*);
+    bool developerExtrasEnabled() const;
 
     ULONG m_refCount;
     WebCore::String m_groupName;