| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/extensions/extension_helper.h" | 5 #include "chrome/renderer/extensions/extension_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension_messages.h" | 12 #include "chrome/common/extensions/extension_messages.h" |
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" | 15 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" |
| 16 #include "chrome/renderer/extensions/event_bindings.h" | 16 #include "chrome/renderer/extensions/event_bindings.h" |
| 17 #include "chrome/renderer/extensions/extension_dispatcher.h" | 17 #include "chrome/renderer/extensions/extension_dispatcher.h" |
| 18 #include "chrome/renderer/extensions/extension_process_bindings.h" | 18 #include "chrome/renderer/extensions/extension_process_bindings.h" |
| 19 #include "chrome/renderer/extensions/renderer_extension_bindings.h" | |
| 20 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" | 19 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" |
| 21 #include "chrome/renderer/extensions/user_script_slave.h" | 20 #include "chrome/renderer/extensions/user_script_slave.h" |
| 22 #include "content/common/json_value_serializer.h" | 21 #include "content/common/json_value_serializer.h" |
| 23 #include "content/renderer/render_view.h" | 22 #include "content/renderer/render_view.h" |
| 24 #include "webkit/glue/image_resource_fetcher.h" | 23 #include "webkit/glue/image_resource_fetcher.h" |
| 25 #include "webkit/glue/resource_fetcher.h" | 24 #include "webkit/glue/resource_fetcher.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 bool success, | 114 bool success, |
| 116 const std::string& error) { | 115 const std::string& error) { |
| 117 ChromeWebstoreExtension::HandleInstallResponse(install_id, success, error); | 116 ChromeWebstoreExtension::HandleInstallResponse(install_id, success, error); |
| 118 } | 117 } |
| 119 | 118 |
| 120 bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { | 119 bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { |
| 121 bool handled = true; | 120 bool handled = true; |
| 122 IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message) | 121 IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message) |
| 123 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) | 122 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) |
| 124 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) | 123 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) |
| 125 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) | |
| 126 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) | 124 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) |
| 127 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) | 125 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) |
| 128 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, | 126 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, |
| 129 OnUpdateBrowserWindowId) | 127 OnUpdateBrowserWindowId) |
| 130 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, | 128 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, |
| 131 OnNotifyRendererViewType) | 129 OnNotifyRendererViewType) |
| 132 IPC_MESSAGE_HANDLER(ExtensionMsg_InlineWebstoreInstallResponse, | 130 IPC_MESSAGE_HANDLER(ExtensionMsg_InlineWebstoreInstallResponse, |
| 133 OnInlineWebstoreInstallResponse) | 131 OnInlineWebstoreInstallResponse) |
| 134 IPC_MESSAGE_UNHANDLED(handled = false) | 132 IPC_MESSAGE_UNHANDLED(handled = false) |
| 135 IPC_END_MESSAGE_MAP() | 133 IPC_END_MESSAGE_MAP() |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 197 } |
| 200 | 198 |
| 201 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, | 199 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, |
| 202 const std::string& function_name, | 200 const std::string& function_name, |
| 203 const ListValue& args, | 201 const ListValue& args, |
| 204 const GURL& event_url) { | 202 const GURL& event_url) { |
| 205 EventBindings::CallFunction( | 203 EventBindings::CallFunction( |
| 206 extension_id, function_name, args, render_view(), event_url); | 204 extension_id, function_name, args, render_view(), event_url); |
| 207 } | 205 } |
| 208 | 206 |
| 209 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, | |
| 210 const std::string& message) { | |
| 211 RendererExtensionBindings::DeliverMessage(target_id, message, render_view()); | |
| 212 } | |
| 213 | |
| 214 void ExtensionHelper::OnExecuteCode( | 207 void ExtensionHelper::OnExecuteCode( |
| 215 const ExtensionMsg_ExecuteCode_Params& params) { | 208 const ExtensionMsg_ExecuteCode_Params& params) { |
| 216 WebView* webview = render_view()->webview(); | 209 WebView* webview = render_view()->webview(); |
| 217 WebFrame* main_frame = webview->mainFrame(); | 210 WebFrame* main_frame = webview->mainFrame(); |
| 218 if (!main_frame) { | 211 if (!main_frame) { |
| 219 Send(new ExtensionHostMsg_ExecuteCodeFinished( | 212 Send(new ExtensionHostMsg_ExecuteCodeFinished( |
| 220 routing_id(), params.request_id, false, "")); | 213 routing_id(), params.request_id, false, "")); |
| 221 return; | 214 return; |
| 222 } | 215 } |
| 223 | 216 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 routing_id(), *pending_app_info_)); | 343 routing_id(), *pending_app_info_)); |
| 351 pending_app_info_.reset(NULL); | 344 pending_app_info_.reset(NULL); |
| 352 } | 345 } |
| 353 | 346 |
| 354 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { | 347 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { |
| 355 if (render_view()->webview() && render_view()->webview()->mainFrame()) { | 348 if (render_view()->webview() && render_view()->webview()->mainFrame()) { |
| 356 render_view()->webview()->mainFrame()->addMessageToConsole( | 349 render_view()->webview()->mainFrame()->addMessageToConsole( |
| 357 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 350 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
| 358 } | 351 } |
| 359 } | 352 } |
| OLD | NEW |