| 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" |
| 19 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" | 20 #include "chrome/renderer/extensions/user_script_idle_scheduler.h" |
| 20 #include "chrome/renderer/extensions/user_script_slave.h" | 21 #include "chrome/renderer/extensions/user_script_slave.h" |
| 21 #include "content/common/json_value_serializer.h" | 22 #include "content/common/json_value_serializer.h" |
| 22 #include "content/renderer/render_view.h" | 23 #include "content/renderer/render_view.h" |
| 23 #include "webkit/glue/image_resource_fetcher.h" | 24 #include "webkit/glue/image_resource_fetcher.h" |
| 24 #include "webkit/glue/resource_fetcher.h" | 25 #include "webkit/glue/resource_fetcher.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool success, | 115 bool success, |
| 115 const std::string& error) { | 116 const std::string& error) { |
| 116 ChromeWebstoreExtension::HandleInstallResponse(install_id, success, error); | 117 ChromeWebstoreExtension::HandleInstallResponse(install_id, success, error); |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { | 120 bool ExtensionHelper::OnMessageReceived(const IPC::Message& message) { |
| 120 bool handled = true; | 121 bool handled = true; |
| 121 IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message) | 122 IPC_BEGIN_MESSAGE_MAP(ExtensionHelper, message) |
| 122 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) | 123 IPC_MESSAGE_HANDLER(ExtensionMsg_Response, OnExtensionResponse) |
| 123 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) | 124 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnExtensionMessageInvoke) |
| 125 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnExtensionDeliverMessage) |
| 124 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) | 126 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) |
| 125 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) | 127 IPC_MESSAGE_HANDLER(ExtensionMsg_GetApplicationInfo, OnGetApplicationInfo) |
| 126 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, | 128 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateBrowserWindowId, |
| 127 OnUpdateBrowserWindowId) | 129 OnUpdateBrowserWindowId) |
| 128 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, | 130 IPC_MESSAGE_HANDLER(ExtensionMsg_NotifyRenderViewType, |
| 129 OnNotifyRendererViewType) | 131 OnNotifyRendererViewType) |
| 130 IPC_MESSAGE_HANDLER(ExtensionMsg_InlineWebstoreInstallResponse, | 132 IPC_MESSAGE_HANDLER(ExtensionMsg_InlineWebstoreInstallResponse, |
| 131 OnInlineWebstoreInstallResponse) | 133 OnInlineWebstoreInstallResponse) |
| 132 IPC_MESSAGE_UNHANDLED(handled = false) | 134 IPC_MESSAGE_UNHANDLED(handled = false) |
| 133 IPC_END_MESSAGE_MAP() | 135 IPC_END_MESSAGE_MAP() |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 199 } |
| 198 | 200 |
| 199 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, | 201 void ExtensionHelper::OnExtensionMessageInvoke(const std::string& extension_id, |
| 200 const std::string& function_name, | 202 const std::string& function_name, |
| 201 const ListValue& args, | 203 const ListValue& args, |
| 202 const GURL& event_url) { | 204 const GURL& event_url) { |
| 203 EventBindings::CallFunction( | 205 EventBindings::CallFunction( |
| 204 extension_id, function_name, args, render_view(), event_url); | 206 extension_id, function_name, args, render_view(), event_url); |
| 205 } | 207 } |
| 206 | 208 |
| 209 void ExtensionHelper::OnExtensionDeliverMessage(int target_id, |
| 210 const std::string& message) { |
| 211 RendererExtensionBindings::DeliverMessage(target_id, message, render_view()); |
| 212 } |
| 213 |
| 207 void ExtensionHelper::OnExecuteCode( | 214 void ExtensionHelper::OnExecuteCode( |
| 208 const ExtensionMsg_ExecuteCode_Params& params) { | 215 const ExtensionMsg_ExecuteCode_Params& params) { |
| 209 WebView* webview = render_view()->webview(); | 216 WebView* webview = render_view()->webview(); |
| 210 WebFrame* main_frame = webview->mainFrame(); | 217 WebFrame* main_frame = webview->mainFrame(); |
| 211 if (!main_frame) { | 218 if (!main_frame) { |
| 212 Send(new ExtensionHostMsg_ExecuteCodeFinished( | 219 Send(new ExtensionHostMsg_ExecuteCodeFinished( |
| 213 routing_id(), params.request_id, false, "")); | 220 routing_id(), params.request_id, false, "")); |
| 214 return; | 221 return; |
| 215 } | 222 } |
| 216 | 223 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 routing_id(), *pending_app_info_)); | 350 routing_id(), *pending_app_info_)); |
| 344 pending_app_info_.reset(NULL); | 351 pending_app_info_.reset(NULL); |
| 345 } | 352 } |
| 346 | 353 |
| 347 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { | 354 void ExtensionHelper::AddErrorToRootConsole(const string16& message) { |
| 348 if (render_view()->webview() && render_view()->webview()->mainFrame()) { | 355 if (render_view()->webview() && render_view()->webview()->mainFrame()) { |
| 349 render_view()->webview()->mainFrame()->addMessageToConsole( | 356 render_view()->webview()->mainFrame()->addMessageToConsole( |
| 350 WebConsoleMessage(WebConsoleMessage::LevelError, message)); | 357 WebConsoleMessage(WebConsoleMessage::LevelError, message)); |
| 351 } | 358 } |
| 352 } | 359 } |
| OLD | NEW |