Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 #include "platform/SharedBuffer.h" | 52 #include "platform/SharedBuffer.h" |
| 53 #include "platform/UserGestureIndicator.h" | 53 #include "platform/UserGestureIndicator.h" |
| 54 #include "platform/network/ResourceError.h" | 54 #include "platform/network/ResourceError.h" |
| 55 #include "platform/network/ResourceRequest.h" | 55 #include "platform/network/ResourceRequest.h" |
| 56 #include "platform/network/ResourceResponse.h" | 56 #include "platform/network/ResourceResponse.h" |
| 57 | 57 |
| 58 namespace blink { | 58 namespace blink { |
| 59 | 59 |
| 60 class FrontendMenuProvider final : public ContextMenuProvider { | 60 class FrontendMenuProvider final : public ContextMenuProvider { |
| 61 public: | 61 public: |
| 62 static PassRefPtr<FrontendMenuProvider> create(InspectorFrontendHost* fronte ndHost, ScriptValue frontendApiObject, const Vector<ContextMenuItem>& items) | 62 static PassRefPtrWillBeRawPtr<FrontendMenuProvider> create(InspectorFrontend Host* frontendHost, ScriptValue frontendApiObject, const Vector<ContextMenuItem> & items) |
| 63 { | 63 { |
| 64 return adoptRef(new FrontendMenuProvider(frontendHost, frontendApiObject , items)); | 64 return adoptRefWillBeNoop(new FrontendMenuProvider(frontendHost, fronten dApiObject, items)); |
| 65 } | |
| 66 | |
| 67 virtual ~FrontendMenuProvider() | |
| 68 { | |
| 69 // Verify that this menu provider has been detached. | |
| 70 ASSERT(!m_frontendHost); | |
| 71 } | |
| 72 | |
| 73 virtual void trace(Visitor* visitor) override | |
| 74 { | |
| 75 visitor->trace(m_frontendHost); | |
| 76 ContextMenuProvider::trace(visitor); | |
| 65 } | 77 } |
| 66 | 78 |
| 67 void disconnect() | 79 void disconnect() |
| 68 { | 80 { |
| 69 m_frontendApiObject = ScriptValue(); | 81 m_frontendApiObject = ScriptValue(); |
| 70 m_frontendHost = 0; | 82 m_frontendHost = nullptr; |
| 71 } | 83 } |
| 72 | 84 |
| 73 private: | 85 virtual void contextMenuCleared() override |
| 74 FrontendMenuProvider(InspectorFrontendHost* frontendHost, ScriptValue fronte ndApiObject, const Vector<ContextMenuItem>& items) | |
| 75 : m_frontendHost(frontendHost) | |
| 76 , m_frontendApiObject(frontendApiObject) | |
| 77 , m_items(items) | |
| 78 { | 86 { |
| 79 } | 87 if (m_frontendHost) { |
| 88 ScriptFunctionCall function(m_frontendApiObject, "contextMenuCleared "); | |
| 89 function.call(); | |
| 80 | 90 |
| 81 virtual ~FrontendMenuProvider() | 91 m_frontendHost->clearMenuProvider(); |
| 82 { | 92 m_frontendHost = nullptr; |
| 83 contextMenuCleared(); | 93 } |
| 94 m_items.clear(); | |
| 84 } | 95 } |
| 85 | 96 |
| 86 virtual void populateContextMenu(ContextMenu* menu) override | 97 virtual void populateContextMenu(ContextMenu* menu) override |
| 87 { | 98 { |
| 88 for (size_t i = 0; i < m_items.size(); ++i) | 99 for (size_t i = 0; i < m_items.size(); ++i) |
| 89 menu->appendItem(m_items[i]); | 100 menu->appendItem(m_items[i]); |
| 90 } | 101 } |
| 91 | 102 |
| 92 virtual void contextMenuItemSelected(const ContextMenuItem* item) override | 103 virtual void contextMenuItemSelected(const ContextMenuItem* item) override |
| 93 { | 104 { |
| 94 if (m_frontendHost) { | 105 if (!m_frontendHost) |
| 95 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGes ture); | 106 return; |
| 96 int itemNumber = item->action() - ContextMenuItemBaseCustomTag; | |
| 97 | 107 |
| 98 ScriptFunctionCall function(m_frontendApiObject, "contextMenuItemSel ected"); | 108 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture ); |
| 99 function.appendArgument(itemNumber); | 109 int itemNumber = item->action() - ContextMenuItemBaseCustomTag; |
| 100 function.call(); | 110 |
| 101 } | 111 ScriptFunctionCall function(m_frontendApiObject, "contextMenuItemSelecte d"); |
| 112 function.appendArgument(itemNumber); | |
| 113 function.call(); | |
| 102 } | 114 } |
| 103 | 115 |
| 104 virtual void contextMenuCleared() override | 116 private: |
| 117 FrontendMenuProvider(InspectorFrontendHost* frontendHost, ScriptValue fronte ndApiObject, const Vector<ContextMenuItem>& items) | |
| 118 : m_frontendHost(frontendHost) | |
| 119 , m_frontendApiObject(frontendApiObject) | |
| 120 , m_items(items) | |
| 105 { | 121 { |
| 106 if (m_frontendHost) { | |
| 107 ScriptFunctionCall function(m_frontendApiObject, "contextMenuCleared "); | |
| 108 function.call(); | |
| 109 | |
| 110 m_frontendHost->m_menuProvider = 0; | |
| 111 } | |
| 112 m_items.clear(); | |
| 113 m_frontendHost = 0; | |
| 114 } | 122 } |
| 115 | 123 |
| 116 InspectorFrontendHost* m_frontendHost; | 124 RawPtrWillBeMember<InspectorFrontendHost> m_frontendHost; |
| 117 ScriptValue m_frontendApiObject; | 125 ScriptValue m_frontendApiObject; |
| 126 | |
| 127 // FIXME: Oilpan: until http://crrev.com/666473003/ is used by the Blink | |
| 128 // GC plugin, turn off checking for GC roots for this field. ContextMenuItem | |
| 129 // triggers looping behavior. | |
| 130 GC_PLUGIN_IGNORE("") | |
|
sof
2014/10/19 19:36:55
Will update to refer to http://crbug.com/424962 be
| |
| 118 Vector<ContextMenuItem> m_items; | 131 Vector<ContextMenuItem> m_items; |
| 119 }; | 132 }; |
| 120 | 133 |
| 121 InspectorFrontendHost::InspectorFrontendHost(InspectorFrontendClient* client, Pa ge* frontendPage) | 134 InspectorFrontendHost::InspectorFrontendHost(InspectorFrontendClient* client, Pa ge* frontendPage) |
| 122 : m_client(client) | 135 : m_client(client) |
| 123 , m_frontendPage(frontendPage) | 136 , m_frontendPage(frontendPage) |
| 124 , m_menuProvider(0) | 137 , m_menuProvider(nullptr) |
| 125 { | 138 { |
| 126 } | 139 } |
| 127 | 140 |
| 128 InspectorFrontendHost::~InspectorFrontendHost() | 141 InspectorFrontendHost::~InspectorFrontendHost() |
| 129 { | 142 { |
| 130 ASSERT(!m_client); | 143 ASSERT(!m_client); |
| 131 } | 144 } |
| 132 | 145 |
| 133 void InspectorFrontendHost::trace(Visitor* visitor) | 146 void InspectorFrontendHost::trace(Visitor* visitor) |
| 134 { | 147 { |
| 135 visitor->trace(m_frontendPage); | 148 visitor->trace(m_frontendPage); |
| 149 visitor->trace(m_menuProvider); | |
| 136 } | 150 } |
| 137 | 151 |
| 138 void InspectorFrontendHost::disconnectClient() | 152 void InspectorFrontendHost::disconnectClient() |
| 139 { | 153 { |
| 140 m_client = 0; | 154 m_client = 0; |
| 141 if (m_menuProvider) | 155 if (m_menuProvider) { |
| 142 m_menuProvider->disconnect(); | 156 m_menuProvider->disconnect(); |
| 157 m_menuProvider = nullptr; | |
| 158 } | |
| 143 m_frontendPage = nullptr; | 159 m_frontendPage = nullptr; |
| 144 } | 160 } |
| 145 | 161 |
| 146 void InspectorFrontendHost::setZoomFactor(float zoom) | 162 void InspectorFrontendHost::setZoomFactor(float zoom) |
| 147 { | 163 { |
| 148 if (!m_frontendPage) | 164 if (!m_frontendPage) |
| 149 return; | 165 return; |
| 150 if (LocalFrame* frame = m_frontendPage->deprecatedLocalMainFrame()) | 166 if (LocalFrame* frame = m_frontendPage->deprecatedLocalMainFrame()) |
| 151 frame->setPageAndTextZoomFactors(zoom, 1); | 167 frame->setPageAndTextZoomFactors(zoom, 1); |
| 152 } | 168 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message)); | 225 m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message)); |
| 210 } | 226 } |
| 211 | 227 |
| 212 void InspectorFrontendHost::showContextMenu(Page* page, float x, float y, const Vector<ContextMenuItem>& items) | 228 void InspectorFrontendHost::showContextMenu(Page* page, float x, float y, const Vector<ContextMenuItem>& items) |
| 213 { | 229 { |
| 214 ASSERT(m_frontendPage); | 230 ASSERT(m_frontendPage); |
| 215 ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendPage- >deprecatedLocalMainFrame()); | 231 ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendPage- >deprecatedLocalMainFrame()); |
| 216 ScriptValue frontendApiObject = frontendScriptState->getFromGlobalObject("In spectorFrontendAPI"); | 232 ScriptValue frontendApiObject = frontendScriptState->getFromGlobalObject("In spectorFrontendAPI"); |
| 217 ASSERT(frontendApiObject.isObject()); | 233 ASSERT(frontendApiObject.isObject()); |
| 218 | 234 |
| 219 RefPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(thi s, frontendApiObject, items); | 235 RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider ::create(this, frontendApiObject, items); |
| 220 m_menuProvider = menuProvider.get(); | 236 m_menuProvider = menuProvider.get(); |
| 221 float zoom = page->deprecatedLocalMainFrame()->pageZoomFactor(); | 237 float zoom = page->deprecatedLocalMainFrame()->pageZoomFactor(); |
| 222 page->inspectorController().showContextMenu(x * zoom, y * zoom, menuProvider ); | 238 page->inspectorController().showContextMenu(x * zoom, y * zoom, menuProvider ); |
| 223 } | 239 } |
| 224 | 240 |
| 225 void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMe nuItem>& items) | 241 void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMe nuItem>& items) |
| 226 { | 242 { |
| 227 if (!event) | 243 if (!event) |
| 228 return; | 244 return; |
| 229 | 245 |
| 230 ASSERT(m_frontendPage); | 246 ASSERT(m_frontendPage); |
| 231 ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendPage- >deprecatedLocalMainFrame()); | 247 ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendPage- >deprecatedLocalMainFrame()); |
| 232 ScriptValue frontendApiObject = frontendScriptState->getFromGlobalObject("In spectorFrontendAPI"); | 248 ScriptValue frontendApiObject = frontendScriptState->getFromGlobalObject("In spectorFrontendAPI"); |
| 233 ASSERT(frontendApiObject.isObject()); | 249 ASSERT(frontendApiObject.isObject()); |
| 234 | 250 |
| 235 Page* targetPage = m_frontendPage; | 251 Page* targetPage = m_frontendPage; |
| 236 if (event->target() && event->target()->executionContext() && event->target( )->executionContext()->executingWindow()) { | 252 if (event->target() && event->target()->executionContext() && event->target( )->executionContext()->executingWindow()) { |
| 237 LocalDOMWindow* window = event->target()->executionContext()->executingW indow(); | 253 LocalDOMWindow* window = event->target()->executionContext()->executingW indow(); |
| 238 if (window->document() && window->document()->page()) | 254 if (window->document() && window->document()->page()) |
| 239 targetPage = window->document()->page(); | 255 targetPage = window->document()->page(); |
| 240 } | 256 } |
| 241 | 257 |
| 242 RefPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider::create(thi s, frontendApiObject, items); | 258 RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider ::create(this, frontendApiObject, items); |
| 243 targetPage->contextMenuController().showContextMenu(event, menuProvider); | 259 targetPage->contextMenuController().showContextMenu(event, menuProvider); |
| 244 m_menuProvider = menuProvider.get(); | 260 m_menuProvider = menuProvider.get(); |
| 245 } | 261 } |
| 246 | 262 |
| 247 String InspectorFrontendHost::getSelectionBackgroundColor() | 263 String InspectorFrontendHost::getSelectionBackgroundColor() |
| 248 { | 264 { |
| 249 return RenderTheme::theme().activeSelectionBackgroundColor().serialized(); | 265 return RenderTheme::theme().activeSelectionBackgroundColor().serialized(); |
| 250 } | 266 } |
| 251 | 267 |
| 252 String InspectorFrontendHost::getSelectionForegroundColor() | 268 String InspectorFrontendHost::getSelectionForegroundColor() |
| 253 { | 269 { |
| 254 return RenderTheme::theme().activeSelectionForegroundColor().serialized(); | 270 return RenderTheme::theme().activeSelectionForegroundColor().serialized(); |
| 255 } | 271 } |
| 256 | 272 |
| 257 bool InspectorFrontendHost::isUnderTest() | 273 bool InspectorFrontendHost::isUnderTest() |
| 258 { | 274 { |
| 259 return m_client && m_client->isUnderTest(); | 275 return m_client && m_client->isUnderTest(); |
| 260 } | 276 } |
| 261 | 277 |
| 262 bool InspectorFrontendHost::isHostedMode() | 278 bool InspectorFrontendHost::isHostedMode() |
| 263 { | 279 { |
| 264 return false; | 280 return false; |
| 265 } | 281 } |
| 266 | 282 |
| 267 } // namespace blink | 283 } // namespace blink |
| OLD | NEW |