1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef InspectorFrontendHost_h 30 #define InspectorFrontendHost_h 31 32 #include "Console.h" 33 #include "ContextMenu.h" 34 #include "ContextMenuProvider.h" 35 #include "InspectorController.h" 36 #include "PlatformString.h" 37 38 #include <wtf/RefCounted.h> 39 #include <wtf/Vector.h> 40 41 namespace WebCore { 42 43 class ContextMenuItem; 44 class Event; 45 class InspectorClient; 46 class Node; 47 48 class InspectorFrontendHost : public RefCounted<InspectorFrontendHost> 49 { 50 public: create(InspectorController * inspectorController,InspectorClient * client)51 static PassRefPtr<InspectorFrontendHost> create(InspectorController* inspectorController, InspectorClient* client) 52 { 53 return adoptRef(new InspectorFrontendHost(inspectorController, client)); 54 } 55 56 ~InspectorFrontendHost(); 57 inspectorController()58 InspectorController* inspectorController() { return m_inspectorController; } 59 disconnectController()60 void disconnectController() { m_inspectorController = 0; } 61 62 void loaded(); 63 void attach(); 64 void detach(); 65 void closeWindow(); 66 void windowUnloading(); 67 68 void setAttachedWindowHeight(unsigned height); 69 void moveWindowBy(float x, float y) const; 70 71 String localizedStringsURL(); 72 String hiddenPanels(); 73 const String& platform() const; 74 const String& port() const; 75 76 void copyText(const String& text); 77 78 // Called from [Custom] implementations. 79 void showContextMenu(Event*, const Vector<ContextMenuItem*>& items); 80 81 private: 82 class MenuProvider : public ContextMenuProvider { 83 public: create(InspectorFrontendHost * frontendHost,const Vector<ContextMenuItem * > & items)84 static PassRefPtr<MenuProvider> create(InspectorFrontendHost* frontendHost, const Vector<ContextMenuItem*>& items) 85 { 86 return adoptRef(new MenuProvider(frontendHost, items)); 87 } 88 ~MenuProvider()89 virtual ~MenuProvider() 90 { 91 contextMenuCleared(); 92 } 93 disconnect()94 void disconnect() 95 { 96 m_frontendHost = 0; 97 } 98 populateContextMenu(ContextMenu * menu)99 virtual void populateContextMenu(ContextMenu* menu) 100 { 101 for (size_t i = 0; i < m_items.size(); ++i) 102 menu->appendItem(*m_items[i]); 103 } 104 contextMenuItemSelected(ContextMenuItem * item)105 virtual void contextMenuItemSelected(ContextMenuItem* item) 106 { 107 if (m_frontendHost) 108 m_frontendHost->contextMenuItemSelected(item); 109 } 110 contextMenuCleared()111 virtual void contextMenuCleared() 112 { 113 if (m_frontendHost) 114 m_frontendHost->contextMenuCleared(); 115 deleteAllValues(m_items); 116 m_items.clear(); 117 } 118 119 private: MenuProvider(InspectorFrontendHost * frontendHost,const Vector<ContextMenuItem * > & items)120 MenuProvider(InspectorFrontendHost* frontendHost, const Vector<ContextMenuItem*>& items) 121 : m_frontendHost(frontendHost) 122 , m_items(items) { } 123 InspectorFrontendHost* m_frontendHost; 124 Vector<ContextMenuItem*> m_items; 125 }; 126 127 InspectorFrontendHost(InspectorController* inspectorController, InspectorClient* client); 128 129 void contextMenuItemSelected(ContextMenuItem*); 130 void contextMenuCleared(); 131 132 InspectorController* m_inspectorController; 133 InspectorClient* m_client; 134 RefPtr<MenuProvider> m_menuProvider; 135 }; 136 137 } // namespace WebCore 138 139 #endif // !defined(InspectorFrontendHost_h) 140