Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / inspector / InspectorFrontendHost.h
blob3b6aeb7a65ddd231e3afee7b7ad5d4189ba8be34
1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
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.
29 #ifndef InspectorFrontendHost_h
30 #define InspectorFrontendHost_h
32 #include "Console.h"
33 #include "ContextMenu.h"
34 #include "ContextMenuProvider.h"
35 #include "InspectorController.h"
36 #include "PlatformString.h"
38 #include <wtf/RefCounted.h>
39 #include <wtf/Vector.h>
41 namespace WebCore {
43 class ContextMenuItem;
44 class Event;
45 class InspectorClient;
46 class Node;
48 class InspectorFrontendHost : public RefCounted<InspectorFrontendHost>
50 public:
51 static PassRefPtr<InspectorFrontendHost> create(InspectorController* inspectorController, InspectorClient* client)
53 return adoptRef(new InspectorFrontendHost(inspectorController, client));
56 ~InspectorFrontendHost();
58 InspectorController* inspectorController() { return m_inspectorController; }
60 void disconnectController() { m_inspectorController = 0; }
62 void loaded();
63 void attach();
64 void detach();
65 void closeWindow();
66 void windowUnloading();
68 void setAttachedWindowHeight(unsigned height);
69 void moveWindowBy(float x, float y) const;
71 String localizedStringsURL();
72 String hiddenPanels();
73 const String& platform() const;
74 const String& port() const;
76 void addResourceSourceToFrame(long identifier, Node* frame);
77 bool addSourceToFrame(const String& mimeType, const String& source, Node* frame);
79 String setting(const String& key);
80 void setSetting(const String& key, const String& value);
82 // Called from [Custom] implementations.
83 void showContextMenu(Event*, const Vector<ContextMenuItem*>& items);
85 private:
86 class MenuProvider : public ContextMenuProvider {
87 public:
88 static PassRefPtr<MenuProvider> create(InspectorFrontendHost* frontendHost, const Vector<ContextMenuItem*>& items)
90 return adoptRef(new MenuProvider(frontendHost, items));
93 virtual ~MenuProvider()
95 contextMenuCleared();
98 void disconnect()
100 m_frontendHost = 0;
103 virtual void populateContextMenu(ContextMenu* menu)
105 for (size_t i = 0; i < m_items.size(); ++i)
106 menu->appendItem(*m_items[i]);
109 virtual void contextMenuItemSelected(ContextMenuItem* item)
111 if (m_frontendHost)
112 m_frontendHost->contextMenuItemSelected(item);
115 virtual void contextMenuCleared()
117 if (m_frontendHost)
118 m_frontendHost->contextMenuCleared();
119 deleteAllValues(m_items);
120 m_items.clear();
123 private:
124 MenuProvider(InspectorFrontendHost* frontendHost, const Vector<ContextMenuItem*>& items)
125 : m_frontendHost(frontendHost)
126 , m_items(items) { }
127 InspectorFrontendHost* m_frontendHost;
128 Vector<ContextMenuItem*> m_items;
131 InspectorFrontendHost(InspectorController* inspectorController, InspectorClient* client);
133 void contextMenuItemSelected(ContextMenuItem*);
134 void contextMenuCleared();
136 InspectorController* m_inspectorController;
137 InspectorClient* m_client;
138 RefPtr<MenuProvider> m_menuProvider;
141 } // namespace WebCore
143 #endif // !defined(InspectorFrontendHost_h)